//删除测点 private void DeletePoint(object sender, RoutedEventArgs e) { SHHOPCItem node = tree.SelectedItem as SHHOPCItem; if (node != null) { OPCManager.RemovePoint(node.Group, node); } }
public static void UpdatePoints(SHHOPCItem opcItem) { SqlParameter[] parameterList = new SqlParameter[6] { new SqlParameter("OPCGroupID", opcItem.Group.ID), new SqlParameter("PointID", opcItem.ID), new SqlParameter("PointName", opcItem.PointName), new SqlParameter("EquipID", (short)opcItem.Equipment.Id), new SqlParameter("EquipPlace", opcItem.PointPlace), new SqlParameter("PointAddress ", opcItem.OPCItemID) }; SqlHelper.ExecuteReader(Database.sqlConStr, CommandType.StoredProcedure, "TF_UpdatePoints", parameterList); }
//加载参数 public static void Load() { SqlDataReader opcserver = TB_TF_OPCServer.GetServer(); while (opcserver.Read()) { SHHOPCServer server = new SHHOPCServer(new Guid(opcserver["OPCServerID"].ToString()), IPAddress.Parse(opcserver["MachineIP"].ToString()), opcserver["OPCServerName"].ToString(), opcserver["Name"].ToString()); SqlDataReader opcgroup = TB_TF_OPCGroups.GetGroups(); while (opcgroup.Read()) { if (opcserver["OPCServerID"].ToString() == opcgroup["OPCServerID"].ToString()) { SHHOPCGroup group = new SHHOPCGroup(new Guid(opcgroup["OPCGroupID"].ToString()), opcgroup["Name"].ToString(), Int32.Parse(opcgroup["UpdateRate"].ToString()), float.Parse(opcgroup["DeadBend"].ToString()), Int32.Parse(opcgroup["TimeBias"].ToString()), (bool)opcgroup["IsActive"], (bool)opcgroup["IsSubscribed"]); SqlDataReader opcpoint = TB_TF_Points.GetPoints(); while (opcpoint.Read()) { if (opcgroup["OPCGroupID"].ToString() == opcpoint["OPCGroupID"].ToString()) { SHHOPCItem item = new SHHOPCItem(new Guid(opcpoint["PointID"].ToString()), new SHHEquipment((SHHEquipmentID)Int32.Parse(opcpoint["EquipID"].ToString()), SHHEquipmentType.Analog, opcpoint["PointName"].ToString(), "MPa"), opcpoint["PointName"].ToString(), opcpoint["EquipPlace"].ToString(), opcpoint["PointAddress"].ToString()); group.AddItem(item); /**********删除测试数据*******/ //RemovePoint(group, item); /***************************/ } } //**********添加测试数据 * *********/ //for (int i = 0; i < 5; ++i) //{ // string s = group.Name.Substring(group.Name.Length - 1, 1); // SHHOPCItem testPoint = new SHHOPCItem(Guid.NewGuid(), new SHHEquipment((SHHEquipmentID)i, SHHEquipmentType.Analog, "测点" + i, "kpa"), "测点" + i, "地点" + i, "Channel_" + s + ".Device_" + 0 + ".Tag_" + i); // AddPoint(group, testPoint); //} ///****************************** server.AddGroup(group); } } ServerList.Add(server); } }
//修改测点 private void ModifyPoint(object sender, RoutedEventArgs e) { SHHOPCItem node = tree.SelectedItem as SHHOPCItem; FormPoint form = new FormPoint(); //载入参数 form.cbx_EquipID.SelectedIndex = (int)node.Equipment.Id; form.tbx_Name.Text = node.PointName; form.tbx_Place.Text = node.PointPlace; form.tbx_Id.Text = node.OPCItemID; form.Owner = this; if ((bool)form.ShowDialog()) { node.PointName = form.PointName; node.PointPlace = form.Place; node.Equipment.Id = (SHHEquipmentID)form.EquipID; //确定修改 OPCManager.ModifyPoint(node); } }
//修改测点 public static void ModifyPoint(SHHOPCItem point) { TB_TF_Points.UpdatePoints(point); }
//删除测点 public static void RemovePoint(SHHOPCGroup group, SHHOPCItem point) { group.RemoveItem(point); TB_TF_Points.DeletePoints(point.ID); }
//添加测点 public static void AddPoint(SHHOPCGroup group, SHHOPCItem point) { group.AddItem(point); TB_TF_Points.AddPoints(point); }