示例#1
0
        void getDownLandFile(tcpDataCommunication tcpComm, stringMsg msg)
        {
            string sendFileFullPath = msg.value["sendFileFullPath"];
            string saveFileFullPath = msg.value["saveFileFullPath"];

            stringMsg returnMsg = new stringMsg();

            returnMsg.name = msgEnum.fileUpload;

            if (File.Exists(sendFileFullPath))
            {
                returnMsg.value.Add("sendFileFullPath", sendFileFullPath); //全路径
                returnMsg.value.Add("saveFileFullPath", saveFileFullPath); //全路径
                // returnMsg.value.Add("fileDirFullPath", System.IO.Path.GetDirectoryName( clientPath));
                //    byte[] data = myWebClient.DownloadData(filepath);
                //    string endPath = path + "\\" + CheckFileName(path, folder);//含重名验证,如重名覆盖则改成:path+"\\"+folder
                //    FileStream fs = new FileStream(endPath, FileMode.Create);
                //    fs.Write(data, 0, data.Length);
                //    fs.Close();
                //    MessageBox.Show("下载成功!", "提示");
                //    user.UpdateDownLand(filepath);
                //    user.Add_Log_Opera(CurrUser.currUser.ID, CurrUser.currUser.Account, string.Format("下载文件{0}", folder));
            }
            else
            {
                returnMsg.value.Add("saveFileFullPath", "");
                returnMsg.value.Add("sendFileFullPath", "");
                //MessageBox.Show("文件不存在!", "提示");
                //user.Add_Log_Error(CurrUser.currUser.ID, CurrUser.currUser.Account, string.Format("下载文件{0}出现问题", folder));
            }
            tcpComm.addSendBle(returnMsg);
            user.UpdateDownLand(sendFileFullPath);
        }
示例#2
0
        /// <summary>
        /// 消息接收事件处理程序
        /// </summary>
        /// <param name="tcpComm"></param>
        /// <param name="msg"></param>
        void newBlemessageEventFun(tcpDataCommunication tcpComm, stringMsg msg)
        {
            switch (msg.name)
            {
            case msgEnum.liaotian:
                liaotian(tcpComm, msg);
                break;

            case msgEnum.fileUpload:
                showMsg(string.Format("收到文件{0}", System.IO.Path.GetFileName(msg.value["saveFileFullPath"])));
                bool bl = AddFileInfo(msg);
                break;

            case msgEnum.dengru:
                denglu(tcpComm, msg);
                break;

            case msgEnum.getUserFileList:
                getUserFileList(tcpComm, msg);
                break;

            case msgEnum.getDownLandFile:
                getDownLandFile(tcpComm, msg);
                break;

            default:
                break;
            }
        }
示例#3
0
        //新消息事件
        void newBlemessageEventFun(tcpDataCommunication tcpComm, BLEData ble)
        {
            //string jsonText = ((BLE.bleClass.t11)ble).msg;
            //JObject jo = (JObject)JsonConvert.DeserializeObject(jsonText);

            stringMsg msg = stringMsg.jsonToModel(ble.ToString());

            switch (msg.name)
            {
            case msgEnum.dengru:
                //bool bl = Convert.ToBoolean(jo["value"]["return"]);
                bool bl = Convert.ToBoolean(msg.value["return"]);
                if (bl)
                {
                    RetUser    curr        = JsonConvert.DeserializeObject <RetUser>(msg.value["jsonCurr"]);
                    ConfigInfo ConfigInfo1 = JsonConvert.DeserializeObject <ConfigInfo>(msg.value["ConfigInfo"]);
                    //RetUser curr = user.Login(login.textBox1.Text, login.textBox2.Text);
                    CurrUser.currUser = curr.User;
                    CurrUser.config   = ConfigInfo1;
                    CloseFrom2();
                    ShowFile(curr.User.ID);
                }
                else
                {
                    //   zTcpClient1.tcpComm.stop();
                    MessageBox.Show("账号或密码错误!");
                }
                break;

            case msgEnum.liaotian:
                //string groupSendingMsg = jo["value"]["groupSending"].ToString();
                string reciveMsg = "";
                if (msg.value.Keys.Contains("groupSending"))
                {
                    reciveMsg = msg.value["groupSending"];
                }
                else if (msg.value.Keys.Contains("singleSending"))
                {
                    reciveMsg = msg.value["singleSending"];
                }
                showMsg(reciveMsg);
                break;

            case msgEnum.returnUserFileList:
                ResetList(msg);
                break;

            case msgEnum.fileUpload:
                fileUpload(tcpComm, ble);
                break;

            default:
                break;
            }
        }
示例#4
0
        public void connectionDisconnectionEventFun(tcpDataCommunication comm)
        {
            if (comm.user == null)
            {
                return;
            }

            UserView u1 = Common.UserViewList.Find(o => o.Address == comm.tcpClientId.Split('&')[2]);

            Common.UserViewList.Remove(u1);
            BindDataGridView(Common.UserViewList);
            //  setStartOrEnd(0);
        }
示例#5
0
        //群发消息
        private void button6_Click(object sender, EventArgs e)
        {
            ConcurrentDictionary <string, tcpDataCommunication> tcpList = tcpConnection.tcpList;

            foreach (KeyValuePair <string, tcpDataCommunication> tcp in tcpList)
            {
                tcpDataCommunication tcpComm = tcp.Value;
                BLE.stringMsg        m1      = new BLE.stringMsg();
                m1.name = BLE.msgEnum.liaotian;
                m1.value.Add("groupSending", this.richTextBox1.Text);
                tcpComm.sendData(m1);
            }
            this.richTextBox1.Text = String.Empty;
        }
示例#6
0
        void getUserFileList(tcpDataCommunication tcpComm, stringMsg msg)
        {
            if (tcpComm.user == null)
            {
                return;
            }
            List <DB.FileInfo> list = user.GetFileListByUserId(tcpComm.user.ID);
            stringMsg          ret  = new stringMsg();

            ret.name           = msgEnum.returnUserFileList;
            ret.value["value"] = JsonConvert.SerializeObject(list);

            tcpComm.addSendBle(ret);
        }
示例#7
0
        void denglu(tcpDataCommunication tcpComm, stringMsg msg)
        {
            string account = msg.value["account"];
            string pwd     = msg.value["pwd"];
            bool   bl      = user.Login(account, pwd);

            BLE.stringMsg m1 = new BLE.stringMsg();
            m1.name = BLE.msgEnum.dengru;
            m1.value.Add("return", bl.ToString());



            tcpComm.sendData(m1);
        }
示例#8
0
 private void isReading(tcpDataCommunication comm, bool b)
 {
     if (this.InvokeRequired)
     {
         this.BeginInvoke(new Action <tcpDataCommunication, bool>(isReading), comm, b);
         return;
     }
     if (b)
     {
         this.label2.Text = "正在接收数据";
     }
     else
     {
         this.label2.Text = "";
     }
 }
示例#9
0
        void newBlemessageEventFun(tcpDataCommunication tcpComm, BLEData ble)
        {
            string  jsonText = ((BLE.bleClass.t11)ble).msg;
            JObject jo       = (JObject)JsonConvert.DeserializeObject(jsonText);
            bool    bl       = Convert.ToBoolean(jo["value"]["return"]);

            if (bl)
            {
                MessageBox.Show("登陆成功!");
                // ff.Controls["button5"].Enabled = false;
                //button5.Enabled = true;
            }
            else
            {
                MessageBox.Show("账号或密码错误!");
            }
        }
示例#10
0
        void fileUpload(tcpDataCommunication tcpComm, BLEData msg)
        {
            stringMsg m1 = stringMsg.jsonToModel(msg.ToString());

            if (m1.value["saveFileFullPath"].Trim() == "")
            {
                showMsg("<下载失败,服务端文件不存在>");
                // MessageBox.Show("下载失败,服务端文件不存在", "提示");
                return;
            }

            string fileName = System.IO.Path.GetFileName(m1.value["saveFileFullPath"]);


            showMsg(string.Format("<{0} 下载完成>", fileName));
            //MessageBox.Show("下载完成", "提示");
        }
示例#11
0
        //指定用户发送消息
        private void button5_Click_1(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection rows = this.dataGridView1.SelectedRows;

            if (rows.Count > 0)
            {
                foreach (DataGridViewRow item in rows)
                {
                    DataGridViewRow itemx   = item;
                    string          address = item.Cells[2].Value.ToString();

                    ConcurrentDictionary <string, tcpDataCommunication> tcpList = tcpConnection.tcpList;
                    List <string> keyList = tcpList.Keys.ToList();
                    string        key     = "";
                    foreach (string keyAddress in keyList)
                    {
                        string k = keyAddress.Substring(keyAddress.LastIndexOf("&") + 1, keyAddress.Length - keyAddress.LastIndexOf('&') - 1);
                        if (k.Equals(address))
                        {
                            key = keyAddress;
                        }
                    }
                    tcpDataCommunication tcpComm = tcpList[key];
                    BLE.stringMsg        m1      = new BLE.stringMsg();
                    m1.name = BLE.msgEnum.liaotian;
                    m1.value.Add("singleSending", this.richTextBox1.Text);
                    tcpComm.sendData(m1);
                    //foreach (KeyValuePair<string, tcpDataCommunication> tcp in tcpList)
                    //{
                    //    tcpDataCommunication tcpComm = tcp.Value;



                    //}
                    this.richTextBox1.Text = String.Empty;
                }
            }
            else
            {
                MessageBox.Show("至少选择一个用户");
            }
        }
示例#12
0
        /// <summary>
        /// 消息接收事件处理程序
        /// </summary>
        /// <param name="tcpComm"></param>
        /// <param name="msg"></param>
        void newBlemessageEventFun(tcpDataCommunication tcpComm, stringMsg msg)
        {
            switch (msg.name)
            {
            case msgEnum.liaotian:
                liaotian(tcpComm, msg);
                break;

            case msgEnum.fileUpload:
                showMsg(string.Format("收到文件", msg.value["value"]));
                break;

            case msgEnum.dengru:
                denglu(tcpComm, msg);
                break;

            default:
                break;
            }
        }
示例#13
0
        void denglu(tcpDataCommunication tcpComm, stringMsg msg)
        {
            string address = tcpComm.tcpClientId.Split('&')[2];
            string account = msg.value["account"];
            string pwd     = msg.value["pwd"];

            RetUser curr = user.Login(account, pwd);

            BLE.stringMsg m1 = new BLE.stringMsg();
            m1.name = BLE.msgEnum.dengru;
            m1.value.Add("return", curr.Success.ToString());


            if (curr.Success)
            {
                tcpComm.user = curr.User;
                if (Common.UserViewList == null)
                {
                    Common.UserViewList = new List <UserView>();
                }
                Common.UserViewList.Add(new UserView()
                {
                    ID = curr.User.ID, Name = curr.User.Account, Address = address
                });
                BindDataGridView(Common.UserViewList);
                m1.value.Add("ID", curr.User.ID.ToString());

                string jsonCurr = JsonConvert.SerializeObject(curr);
                m1.value.Add("jsonCurr", jsonCurr);

                ConfigInfo config     = user.GetSave();
                string     jsonConfig = JsonConvert.SerializeObject(config);
                m1.value.Add("ConfigInfo", jsonConfig);
            }



            tcpComm.sendData(m1);

            // UserService user = new UserService();
        }
示例#14
0
        void denglu(tcpDataCommunication tcpComm, stringMsg msg)
        {
            string value = msg.value["return"];

            MessageBox.Show(value);
        }
示例#15
0
 void liaotian(tcpDataCommunication tcpComm, stringMsg msg)
 {
     showMsg(tcpComm.tcpClient1.Client.RemoteEndPoint.ToString() + "---" + msg.value["value"]);
 }
示例#16
0
 public void connectionDisconnectionEventFun(tcpDataCommunication comm)
 {
     setStartOrEnd(0);
 }