/// <summary> /// 设置参考点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SetBt_Click(object sender, EventArgs e) { #region 获取设置的参考点及节点讯息 string StrID1, StrID2, StrName, StrArea; StrID1 = RID_1TB.Text.ToUpper(); StrID2 = RID_2TB.Text.ToUpper(); //参考点名称 StrName = ReferNameTB.Text.ToUpper(); //判断区域是否存在 StrArea = Ps.ShowAreaCB.Text; //取出区域的ID Area are = SysParam.GetArea_IDName(StrArea); int index = NodeTypeCB.SelectedIndex; #endregion #region 檢查ID是否有误 if ("".Equals(StrID1) || "".Equals(StrID2)) { MessageBox.Show("對不起,ID不能为空!"); return; } if (StrID1.Length != 2 || StrID2.Length != 2) { MessageBox.Show("對不起,ID格式有誤,正常格式為ID1和ID2的長度都為2!"); return; } byte[] ID = new byte[2]; try { ID[0] = Convert.ToByte(StrID1, 16); ID[1] = Convert.ToByte(StrID2, 16); }catch (Exception) { MessageBox.Show("對不起,ID格式有误!"); return; } if (0 == ID[0] && 0 == ID[1]) { MessageBox.Show("對不起,參考點和數據節點的ID不能為0000!"); return; } if (0xFF == ID[0] && 0xFF == ID[1]) { MessageBox.Show("對不起,參考點和數據節點的ID不能為FFFF!"); return; } #endregion #region 检查添加或修改的参考点或数据节点是否已经存在 Area marea = null; Group mygroup = null; string strarea = "", strgrpid = "", strgroup = ""; int res = IsAreaContainNodeOrRefer(StrID1 + StrID2, out marea); if (null != marea) { if ("".Equals(marea.Name) || null == marea.Name) { strarea = marea.ID[0].ToString("X2") + marea.ID[1].ToString("X2"); } else { strarea = marea.Name; } strgrpid = marea.GroupID[0].ToString("X2") + marea.GroupID[1].ToString("X2"); } if (CommonCollection.Groups.TryGetValue(strgrpid, out mygroup)) {//获取到组别讯息 if ("".Equals(mygroup.Name) || null == mygroup.Name) { strgroup = mygroup.ID[0].ToString("X2") + mygroup.ID[1].ToString("X2"); } else { strgroup = mygroup.Name; } } #endregion if (StrRouterID != null && !"".Equals(StrRouterID)) { #region 修改参考点和数据节点讯息 if (!StrRouterID.Equals(StrID1 + StrID2)) { MessageBox.Show("對不起,參考點及數據節點的ID不能修改!"); return; } if (type != index) { //说明修改了节点的类型 if (index == 1) { //从参考点修改为数据节点 if (res == 1) { //包含数据节点 MessageBox.Show("在" + strgroup + "組別的" + strarea + "區域中" + "已經存在數據節點" + (StrID1 + StrID2) + "..."); return; } else { if (area.AreaRouter.Remove(StrRouterID)) { BasicNode Bn = new BasicNode(); Bn.ID = ID; Bn.Name = StrName; Bn.isVisible = true; Bn.x = ex.X; Bn.y = ex.Y; Bn.isVisible = RouterVisibleCB.Checked; are.AreaNode.Add(StrID1 + StrID2, Bn); this.Close(); return; } } } else {//从数据节点修改为参考点 if (res == 2) { MessageBox.Show("在" + strgroup + "組別的" + strarea + "區域中" + "已經存在參考點" + (StrID1 + StrID2) + "..."); return; } else { if (area.AreaNode.Remove(StrRouterID)) { BasicRouter BR = new BasicRouter(); BR.ID = ID; BR.Name = StrName; BR.isVisible = true; BR.x = ex.X; BR.y = ex.Y; BR.isVisible = RouterVisibleCB.Checked; are.AreaRouter.Add(StrID1 + StrID2, BR); this.Close(); return; } } } return; } //没有修改数据节点类型 if (index == 1) {//设置数据节点 BasicNode MyBasicNode = null; area.AreaNode.TryGetValue(StrRouterID, out MyBasicNode); if (null != MyBasicNode) { MyBasicNode.Name = StrName; MyBasicNode.isVisible = RouterVisibleCB.Checked; this.Close(); return; } } else {//设置参考点 BasicRouter MyBasicRouter = null; area.AreaRouter.TryGetValue(StrRouterID, out MyBasicRouter); if (null != MyBasicRouter) { MyBasicRouter.Name = StrName; MyBasicRouter.isVisible = RouterVisibleCB.Checked; this.Close(); return; } } #endregion } #region 添加参考点及节点 if (res == 1) { //包含节点 if (index == 1) { //数据节点 MessageBox.Show("在" + strgroup + "組別的" + strarea + "區域中" + "已經存在數據節點" + (StrID1 + StrID2) + "..."); } else {//参考点 MessageBox.Show("對不起,參考點ID與數據節點ID不能相同,在組別" + strgroup + "的" + strarea + "區域中" + "已經存在數據節點" + (StrID1 + StrID2) + "..."); } return; } else if (res == 2) { //包含参考点 if (index == 1) { //数据节点 MessageBox.Show("對不起,參考點ID與數據節點ID不能相同,在組別" + strgroup + "的" + strarea + "區域中" + "已經存在參考點" + (StrID1 + StrID2) + "..."); } else {//参考点 MessageBox.Show("對不起,在組別" + strgroup + "的" + strarea + "區域中" + "已經存在參考點" + (StrID1 + StrID2) + "..."); } return; } else if (res < 0) { //添加参考点与数据节点 if (index == 1) { //数据节点 BasicNode Bn = new BasicNode(); Bn.ID = ID; Bn.Name = StrName; Bn.isVisible = true; Bn.x = ex.X; Bn.y = ex.Y; Bn.isVisible = RouterVisibleCB.Checked; if (are.AreaNode.ContainsKey(StrID1 + StrID2)) { MessageBox.Show("Sorry,該區域上已經包含了" + StrID1 + StrID2 + "數據節點!"); return; } are.AreaNode.Add(StrID1 + StrID2, Bn); } else {//参考点 BasicRouter BR = new BasicRouter(); BR.ID = ID; BR.Name = StrName; BR.isVisible = true; BR.x = ex.X; BR.y = ex.Y; BR.isVisible = RouterVisibleCB.Checked; if (are.AreaRouter.ContainsKey(StrID1 + StrID2)) { MessageBox.Show("Sorry,該區域上已經包含了" + StrID1 + StrID2 + "參考點!"); return; } are.AreaRouter.Add(StrID1 + StrID2, BR); } SysParam.RestoreShow(); this.Close(); return; } #endregion }