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("请输入完整信息."); } }
private void FrmTemp_Load(object sender, EventArgs e) { Socket_Service.GiveMainfrom(mainform); //开始循环轮询 LoopThread = new Thread(new ThreadStart(SendLoop)); LoopThread.Start(); }
private void btn_HandCheckOut_Click(object sender, EventArgs e) { if (DataGrid_AlarmMaxHour.SelectedRows.Count > 0) { if (MessageBox.Show("您确定要强制使 " + DataGrid_AlarmMaxHour.SelectedRows[0].Cells["姓名"].Value.ToString() + " 这位员工离开吗?", "强制离开", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //启动特殊区域监控方案 if (!Socket_Service.SendMessage_Safe(Socket_Service.Command_C2S_HandCheckOut, DataGrid_AlarmMaxHour.SelectedRows[0].Cells["卡号"].Value.ToString(), "", "", "", "", "", "", "", "")) { MessageBox.Show("强制离开失败。", "强制离开", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } }
private void btn_Refresh_Click(object sender, EventArgs e) { CopyPositionTable = DB_Service.MainDataSet.Tables["PositionTable"].Copy(); //修改原表会导致DataSource失效,故再赋值一次 dataGV_Table.DataSource = CopyPositionTable; if (this.Text == "特殊区域内人员") { Socket_Service.SendMessage(Socket_Service.Command_C2S_RequestInArea, "", "", "", "", "", "", "", "", ""); } else { CopyPositionTable.DefaultView.RowFilter = this.RowFilter; label_AllNum.Text = this.Text + "数:" + dataGV_Table.Rows.Count.ToString() + " 人"; } }
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(); } }
private void button1_Click(object sender, EventArgs e) { Socket_Service.SendMessage(Socket_Service.Command_C2S_SetInfo, com_StationID.Text, com_ShowInfoStyle.SelectedIndex.ToString(), com_ShowInfoIndex.SelectedIndex.ToString(), text_ShowInfo.Text.Trim(), "", "", "", "", ""); this.Close(); }
private void btn_Login_Click(object sender, EventArgs e) { if (com_ServerList.Text == "") { MessageBox.Show("对不起,请先选择连接服务器后再登录。", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (texUserName.Text.Trim() == "") { MessageBox.Show("请输入登录用户名。", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } try { //初始化全局数据库缓存MainDataSet DB_Service.InitMainDataSet(); DataRow[] rows = DB_Service.MainDataSet.Tables["UserTable"].Select("UserName = '******'"); if (rows.Length == 1) { if (rows[0]["Password"].ToString().CompareTo(texPassword.Text) == 0 || Global.AutoLogin) { if (Convert.ToBoolean(rows[0]["IsAlive"])) { if (Socket_Service.ConnectServer(Global.ServerIP, Global.ServerPort)) { if (Socket_Service.SendMessage_Safe(Socket_Service.Command_C2S_Reg, texUserName.Text.Trim(), "", "", "", "", "", "", "", "")) { this.Tag = true; Global.PresentUser = texUserName.Text.Trim(); this.Close(); } else { try { Socket_Service.DisconnectServer(); } catch { } MessageBox.Show("对不起,您的帐户已经在别处登陆或者连接数目超限,请联系管理员。", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("与服务器的连接失败,请确保服务器已经启动后重新运行。", "服务器通信失败", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("对不起,您的帐户已停用,请联系管理员。", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return; } else { MessageBox.Show("请输入正确的用户名和密码。", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Warning); texPassword.Text = ""; } } else { MessageBox.Show("请输入正确的用户名和密码。", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Warning); texPassword.Text = ""; } } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName + (Global.IsTempVersion ? "(演示版)" : "")); } }
private void btn_Save_Click(object sender, EventArgs e) { if (text_StationID.Text.Trim() == "" || text_Name.Text.Trim() == "" || com_Map.SelectedIndex == -1 || com_Type.SelectedIndex == -1 || com_StationFunction.SelectedIndex == -1 || text_X.Text.Trim() == "" || text_Y.Text.Trim() == "" || text_RepairRSSI.Text.Trim() == "") { MessageBox.Show("请输入完整的基站信息后再进行保存。\n至少包含:所属地图、基站ID、基站名称、基站类型、基站功能、信号修正、基站位置坐标", "基站设置", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { //如果是新建基站,则判断基站ID的唯一性并初始化StationRow if (StationRow == null) { if (DB_Service.MainDataSet.Tables["StationTable"].Select("ID = " + text_StationID.Text.Trim()).Length > 0) { MessageBox.Show("对不起,您所输入的这个基站ID已经存在,请重新输入一个未被占用的基站ID。", "新增基站", MessageBoxButtons.OK, MessageBoxIcon.Warning); text_StationID.Text = ""; return; } else if (com_Type.SelectedIndex == 2 && text_Father.Text == "" && com_StationFunction.SelectedIndex == 0) { MessageBox.Show("对不起,人员定位的无线基站必须要有父基站。请输入父基站ID后继续。", "新增基站", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { //初始化StationRow StationRow = DB_Service.MainDataSet.Tables["StationTable"].NewRow(); DB_Service.MainDataSet.Tables["StationTable"].Rows.Add(StationRow); } } //修改StationRow的值 StationRow["ID"] = Convert.ToInt32(text_StationID.Text.Trim());//不用约束用户输入。因为 StationRow["Name"] = text_Name.Text.Trim(); StationRow["MapName"] = com_Map.Text; if (com_Area.SelectedIndex == 0) { StationRow["Area"] = ""; } else { StationRow["Area"] = com_Area.Text.Trim(); } try { StationRow["RepairRSSI"] = Convert.ToInt32(text_RepairRSSI.Text.Trim()); } catch { MessageBox.Show("对不起,信号修正必须是数字。可以带负号。"); text_RepairRSSI.Text = ""; return; } StationRow["Geo_X"] = text_X.Text.Trim(); StationRow["Geo_Y"] = text_Y.Text.Trim(); StationRow["StationType"] = com_Type.Text; switch (com_Type.Text) { case "Can基站": StationRow["IP"] = ""; StationRow["Port"] = DBNull.Value; StationRow["FatherStationID"] = DBNull.Value; break; case "网关基站": StationRow["FatherStationID"] = DBNull.Value; if (text_IP.Text.Trim() != "") { StationRow["IP"] = text_IP.Text.Trim(); } if (text_Port.Text.Trim() != "") { StationRow["Port"] = text_Port.Text.Trim(); } break; case "无线基站": StationRow["IP"] = ""; StationRow["Port"] = DBNull.Value; StationRow["SonStationIDs"] = ""; //判断父是否有更改 if (OldFatherStationID != text_Father.Text.Trim()) { //原来没有,现在新添加了 if (OldFatherStationID == "") { DataRow[] tempFather = DB_Service.MainDataSet.Tables["StationTable"].Select("ID = " + text_Father.Text.Trim()); if (tempFather.Length > 0) { //其父存在 //在其父添加自己的ID string tempStr = tempFather[0]["SonStationIDs"].ToString(); tempStr += StationRow["ID"].ToString() + "-"; tempFather[0]["SonStationIDs"] = tempStr; //保存SonStationIDs StationRow["FatherStationID"] = text_Father.Text; //发送命令 Socket_Service.SendMessage(Socket_Service.Command_C2S_AddRelation, text_Father.Text.Trim(), text_StationID.Text.Trim(), "", "", "", "", "", "", ""); } else { //其父不存在 MessageBox.Show("您输入的这个父基站不存在,请核对父基站ID是否输入正确。", "添加父基站", MessageBoxButtons.OK, MessageBoxIcon.Information); text_Father.Text = ""; return; } } else { //原来有,现在没有了 if (text_Father.Text == "") { DataRow[] tempFather = DB_Service.MainDataSet.Tables["StationTable"].Select("ID = " + OldFatherStationID); if (tempFather.Length > 0) { //其父存在 //在其父删除自己的ID string tempStr = tempFather[0]["SonStationIDs"].ToString(); string[] tempArray = System.Text.RegularExpressions.Regex.Split(tempStr, "-"); tempStr = ""; for (int i = 0; i < tempArray.Length; i++) { if (tempArray[i] != "") { if (tempArray[i] != StationRow["ID"].ToString()) { tempStr += tempArray[i].ToString() + "-"; } } } tempFather[0]["SonStationIDs"] = tempStr; //保存FatherStationID StationRow["FatherStationID"] = DBNull.Value; //发送命令 Socket_Service.SendMessage(Socket_Service.Command_C2S_DelRelation, OldFatherStationID, text_StationID.Text.Trim(), "", "", "", "", "", "", ""); } } else { //现在有,原来也有 MessageBox.Show("您不能将此基站直接转移给另一个父基站,因为他目前已经属于一个父基站了。\n若要转移,请先将此基站的父基站设置为空,然后再设置其父基站。", "设置父基站", MessageBoxButtons.OK, MessageBoxIcon.Information); text_Father.Text = OldFatherStationID; return; } } } break; } StationRow["StationFunction"] = com_StationFunction.Text; switch (com_StationFunction.Text) { case "人员定位": if (check_IsDutyStation.Checked) { StationRow["DutyOrder"] = com_Duty.Text.Split(':')[0]; } else { StationRow["DutyOrder"] = DBNull.Value; } StationRow["MaxChannelNum"] = DBNull.Value; StationRow["CollectChannelIDStr"] = ""; break; case "信息采集": StationRow["MaxChannelNum"] = Convert.ToInt32(com_MaxChannel.Text); string tempCollectChannelIDStr = ""; foreach (ListViewItem item in listView_Channel.Items) { tempCollectChannelIDStr += item.SubItems[0].Text + ":" + item.Tag.ToString() + "-"; } //只有当通道字串改变时才更新。这里ListView是按通道号排序的。所以这样比较没有问题 if (OldCollectChannelIDStr != tempCollectChannelIDStr) { StationRow["CollectChannelIDStr"] = tempCollectChannelIDStr; } StationRow["DutyOrder"] = DBNull.Value; break; } //将StationTable中的更新提交至数据库 if (DB_Service.UpdateDBFromTable(DB_Service.MainDataSet.Tables["StationTable"]) > 0) { //更新监控窗体上的显示 this.mainform.UpdateLayerDataSource("StationTable" + Global.SplitKey + "StationType" + Global.SplitKey + "Can基站", 0); this.mainform.UpdateLayerDataSource("StationTable" + Global.SplitKey + "StationType" + Global.SplitKey + "网关基站", 0); this.mainform.UpdateLayerDataSource("StationTable" + Global.SplitKey + "StationType" + Global.SplitKey + "无线基站", 1); this.Close(); } else { MessageBox.Show("保存基站信息失败!\n请确保数据库连接正确。", "基站管理"); } } }