YL
2021-11-01 059997285ebbcc0c223130b1b5df236e1a7577f7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebAPI.Models;
 
namespace WebAPI
{
    [HubName("chatHub")]
    public class MyHub : Hub
    {
        SQLHelper.ClsCNSRM oCn = new SQLHelper.ClsCNSRM();
        public void Send(string title, string message)
        {
            this.InsertMsg(title, message);
            // 调用所有客户端的sendMessage方法
            Clients.All.sendMessage(message);
        }
 
        private void InsertMsg(string title, string message)
        {
            Message msg = new Message();
            msg.Title = title;
            msg.MsgContent = message;
            oCn.BeginTran();
            oCn.RunProc("Insert into Gy_Message " +
                " (Title,MsgContent) " +
                " Values('" + msg.Title + "','" + msg.MsgContent + "')", ref DBUtility.ClsPub.sExeReturnInfo);
            oCn.Commit();
        }
    }
}