private void btn_MakeCollectOnce_Click(object sender, EventArgs e)
 {
     if (com_CollectStationID.Text != "" && com_CollectChannelNum.Text != "" && text_CollectValueMin.Text != "" && text_CollectValueMax.Text != "" && text_CollectChannel_ID.Text != "")
     {
         try
         {
             Random ran   = new Random(DateTime.Now.Second);
             int    value = ran.Next(Convert.ToInt32(text_CollectValueMin.Text), Convert.ToInt32(text_CollectValueMax.Text));
             //给所有客户端发送服务器采集器通道信息更新消息
             Socket_Service.BroadcastMessage(Socket_Service.Command_S2C_UpdateCollectChannel, com_CollectStationID.Text, com_CollectChannelNum.Text, value.ToString(), text_CollectChannel_ID.Text, "", "", "", "", "");
             label_CollectResult.Text = Convert.ToString(++CollectResult) + " 条";
         }
         catch
         {
             if (timer1.Enabled)
             {
                 btn_MakeCollectLoop_Click(sender, e);
             }
         }
     }
     else
     {
         if (timer1.Enabled)
         {
             btn_MakeCollectLoop_Click(sender, e);
         }
         MessageBox.Show("请输入完整信息.");
     }
 }
Esempio n. 2
0
 private void btn_Start_Click(object sender, EventArgs e)
 {
     if (btn_Start.Text == "启动服务器")
     {
         try
         {
             //刷新硬件配置参数
             if (CommonFun.RefreshHardConfig())
             {
                 //检查并更新数据库
                 DB_Service.CheckDBAndUpdate();
                 //初始化5个常用表
                 BasicData.InitALLTable();
                 //初始化定位信息表和数据采集表中最后一条记录的时间
                 if (DB_Service.InitLastInsertHistory_Position())
                 {
                     //监听本地端口
                     Socket_Service.StartListenConnectOfClient(Global.ServerPort);
                     //连接完毕,锁定UI
                     UI_OnConn();
                     //开始轮询前删除底层数据区文件,不存在不引发异常
                     File.Delete(@"X:\TAG.TXT");
                     //从上次的临时数据文件重载Protocol_Service.Position的数据
                     CommonFun.ReloadPositionFromFile();
                     //开始循环轮询
                     LoopKey = true;
                     //发送服务器状态
                     Socket_Service.BroadcastMessage(Socket_Service.Command_S2C_UpdatePosition, "True", "", "", "", Protocol_Service.AlarmAreaName + "!0!False", "False", "False", "False", "!");
                 }
                 else
                 {
                     MessageBox.Show("无法取得定位信息历史表或采集信息历史表中最新的时间。请检查数据库连接是否正常后重试。", "连接数据库");
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message + "\n" + ex.TargetSite + "\n" + ex.StackTrace, "启动服务器异常");
             //关闭循环轮询
             LoopKey = false;
             //恢复协议类变量为初始值
             Protocol_Service.ResumeALL();
             //清空所有表
             BasicData.DisableALLTable();
             //连接关闭,解锁UI
             UI_OffConn();
         }
     }
     else
     {
         //关闭循环轮询
         LoopKey = false;
         //发送服务器状态
         Socket_Service.BroadcastMessage(Socket_Service.Command_S2C_UpdatePosition, "False", "", "", "", Protocol_Service.AlarmAreaName + "!0!False", "False", "False", "False", "!");
         //停止监听
         Socket_Service.StopListenConnectOfClient();
         //恢复协议类变量为初始值
         Protocol_Service.ResumeALL();
         //清空所有表
         BasicData.DisableALLTable();
         //连接关闭,解锁UI
         UI_OffConn();
     }
 }