Example #1
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     try
     {
         clientSocket = new ClientSocket(GetLX_IP(IP.Text), Convert.ToInt32(Port.Text));
         clientSocket.Connect(true);
         clientSocket.ReciveMsg -= clientSocket_ReciveMsg;
         clientSocket.ReciveMsg += clientSocket_ReciveMsg;
         clientSocket.Send("SubSrv-#1", "0", txtGroup.Text, "mac", "SUB", Guid.NewGuid().ToString().ToString().Replace("-", "").ToUpper());
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            try
            {
                string SrvNOs = "";

                ListViewItem lvi = listSubSrvs.SelectedItems[0];
                //foreach (ListViewItem lvi in listSubSrvs.Items)
                //{
                    if (lvi.SubItems[1].Text == "0")
                    {
                        ClientSocket clientSocket = new ClientSocket(GetLX_IP(IP.Text), Convert.ToInt32(Port.Text));
                        clientSocket.Connect(true);
                        clientSocket.ReciveMsg -= subSrv_ReciveMsg;
                        clientSocket.ReciveMsg += subSrv_ReciveMsg;
                        clientSocket.GroupID = lvi.SubItems[0].Text;
                        clientSocket.Send("SubSrv logged in", "0", clientSocket.GroupID, "mac", "SUB", Guid.NewGuid().ToString().ToString().Replace("-", "").ToUpper());

                        if (SubServices.Contains(clientSocket.GroupID))
                        {
                            //斷開原來的連接
                            try
                            {
                                ClientSocket oldClientSocket = SubServices[clientSocket.GroupID] as ClientSocket;
                                oldClientSocket.Disconnect();
                                oldClientSocket.Dispose();
                            }
                            catch
                            { }
                            SubServices.Remove(clientSocket.GroupID);
                        }
                        SubServices.Add(clientSocket.GroupID, clientSocket);
                        //記錄已開啟的訂閱呺 
                        SrvNOs +=  "'" + lvi.SubItems[0].Text + "',";
                    }
                //}
                //更新訂閱號狀態
                if (SrvNOs.Length > 0)
                {
                    using (SQLHelper conn = new SQLHelper(DBAlias))
                    {
                        conn.OpenConnection();
                        try
                        {
                            SrvNOs = SrvNOs.Substring(0, SrvNOs.Length - 1);
                            // 標記為已讀                    
                            DateTime now = DateTime.Now;
                            string ymd = now.ToString("yyyy/MM/dd");
                            string time = now.ToString("HH:mm:ss");
                            conn.ExecuteSQL("update a set a.srv_state='1',a.ie_lymd='" + ymd + "',a.ie_ltime='" + time + "' from lxsubsrvs a where a.srv_no in (" + SrvNOs + ")");

                            conn.CloseConnection();
                        }
                        catch
                        {
                            conn.CloseConnection();
                        }
                    }
                }
                //刷新列表
                btnRefresh_Click(sender, e);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }