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 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_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请确保数据库连接正确。", "基站管理"); } } }