//public CRLConveryControl(string ip) //{ // _ip = ip; // mPLC = new RWLOPCServerl(_ip); //} //public bool InitOPCData(DataSet ds) //{ // if (ds != null) // { // DataTable dt = ds.Tables[0]; // for (int i = 0; i < dt.Rows.Count; i++) // { // if (dt.Rows[i]["userid"].ToString() == _ip) // { // if (dt.Rows[i]["groupname"].ToString() == "Convery") // { // CRLStationInfo si = new CRLStationInfo(); // si.stationno = int.Parse(dt.Rows[i]["stationno"].ToString()); // si.stationtype = int.Parse(dt.Rows[i]["stationtype"].ToString()); // si.LocationX = int.Parse(dt.Rows[i]["field1"].ToString()); // si.LocationY = int.Parse(dt.Rows[i]["field2"].ToString()); // si.Width = SplitWidth(dt.Rows[i]["remark"].ToString())[0]; // si.Height = SplitWidth(dt.Rows[i]["remark"].ToString())[1]; // si.value = int.Parse(dt.Rows[i]["value"].ToString()); // si.config = dt.Rows[i]["field3"].ToString(); // StationInfo.Add(si); // CRLOPCItem findco = ItemInfo.Find( // delegate(CRLOPCItem ii) // { // return ii.groupname == "Convery"; // } // ); // if (findco == null) // { // CRLOPCItem coi = new CRLOPCItem(); // coi.groupname = dt.Rows[i]["groupname"].ToString(); // coi.ipaddress = dt.Rows[i]["userid"].ToString(); // coi.DBAddress = int.Parse(dt.Rows[i]["objects"].ToString()); // coi.start = int.Parse(dt.Rows[i]["value"].ToString()); // coi.length = int.Parse(dt.Rows[i]["signaltype"].ToString()); // ItemInfo.Add(coi); // } // else // findco.length += 20;//leo 30 to 20 // } // else // { // CRLOPCItem co = new CRLOPCItem(); // co.groupname = dt.Rows[i]["groupname"].ToString(); // co.ipaddress = dt.Rows[i]["userid"].ToString(); // co.DBAddress = int.Parse(dt.Rows[i]["objects"].ToString()); // co.start = int.Parse(dt.Rows[i]["value"].ToString()); // co.length = int.Parse(dt.Rows[i]["stationno"].ToString()); // ItemInfo.Add(co); // } // } // } // return true; // } // return false; //} public bool InitOPCData(DataSet ds) { if (ds != null) { DataTable dt = ds.Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { _ip = dt.Rows[i]["userid"].ToString(); if (!PLCList.ContainsKey(_ip)) { PLCList.Add(_ip, new RWLOPCServerl(_ip)); PLCFlag.Add(_ip, false); PLCList[_ip].Connect(); } switch (dt.Rows[i]["groupname"].ToString()) { case "Convery": ConveryInit(dt.Rows[i]); break; //case "OutPick": OutPickInit(dt.Rows[i]); break; //case "InPick": InPickInit(dt.Rows[i]); break; default: OtherInit(dt.Rows[i]); break; } //if (dt.Rows[i]["groupname"].ToString() == "Convery") //{ // CRLOPCItem findco = ItemInfo.Find( // delegate(CRLOPCItem ii) // { // return ii.groupname == "Convery"; // } // ); // if (findco == null) // { // CRLOPCItem coi = new CRLOPCItem(); // coi.groupname = dt.Rows[i]["groupname"].ToString(); // coi.ipaddress = dt.Rows[i]["userid"].ToString(); // coi.DBAddress = int.Parse(dt.Rows[i]["objects"].ToString()); // coi.start = int.Parse(dt.Rows[i]["value"].ToString()); // coi.length = int.Parse(dt.Rows[i]["signaltype"].ToString()); // ItemInfo.Add(coi); // } // else // findco.length += 20;//leo 30 to 20 //} //else //{ // CRLOPCItem co = new CRLOPCItem(); // co.groupname = dt.Rows[i]["groupname"].ToString(); // co.ipaddress = dt.Rows[i]["userid"].ToString(); // co.DBAddress = int.Parse(dt.Rows[i]["objects"].ToString()); // co.start = int.Parse(dt.Rows[i]["value"].ToString()); // co.length = int.Parse(dt.Rows[i]["stationno"].ToString()); // ItemInfo.Add(co); //} } return(true); } return(false); }
/// <summary> /// 初始化输送机对应参数 /// </summary> /// <returns></returns> public bool TransDeviceInit() { DataSet ds = DataTrans.D_GetDeviceSSJ(); if (ds != null && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { //获取设备编号第一个字母,用于与绑定IP地址 _SSJDhead = ds.Tables[0].Rows[i]["VAR1"].ToString().Substring(0, 1); string _ip = ConfigurationManager.AppSettings[_SSJDhead].ToString(); //需要改进,将端口,DB块,端口等也进行构造函数初始化l if (!PLCList.ContainsKey(_SSJDhead)) { PLCList.Add(_SSJDhead, new RWLOPCServerl(_ip)); PLCFlag.Add(_SSJDhead, false); PLCList[_SSJDhead].Connect(); } if (!HsPLCList.ContainsKey(_SSJDhead)) { HsPLCList.Add(_SSJDhead, new HsControlServer(_ip)); bool flag = HsPLCList[_SSJDhead].HsServerConnect(); string res = flag ? "成功" : "失败"; NotifyEvent?.Invoke($"PLC{_ip}连接{res}"); } TransportStr tp = new TransportStr(); tp.SSJID = ds.Tables[0].Rows[i]["SSJID"].ToString(); tp.BTID = ds.Tables[0].Rows[i]["BTID"].ToString(); tp.DTYPE = ds.Tables[0].Rows[i]["DTYPE"].ToString(); tp.ZXRWH = ds.Tables[0].Rows[i]["ZXRWH"].ToString(); tp.DWXH = ds.Tables[0].Rows[i]["DWXH"].ToString(); tp.KXBZ = ds.Tables[0].Rows[i]["KXBZ"].ToString(); tp.TRAYCODE = ds.Tables[0].Rows[i]["TRAYCODE"].ToString(); tp.JYM = ds.Tables[0].Rows[i]["JYM"].ToString(); tp.BFLAG = ds.Tables[0].Rows[i]["BFLAG"].ToString(); tp.ALLEYID = ds.Tables[0].Rows[i]["ALLEYID"].ToString(); //tp.ALLEYID = ""; tp.VAR1 = ds.Tables[0].Rows[i]["VAR1"].ToString(); tp.VAR2 = ds.Tables[0].Rows[i]["VAR2"].ToString(); tp.VAR3 = ds.Tables[0].Rows[i]["VAR3"].ToString(); tp.VAR4 = ds.Tables[0].Rows[i]["VAR4"].ToString(); tp.VAR5 = ds.Tables[0].Rows[i]["VAR5"].ToString(); tp.SSRWLX = ds.Tables[0].Rows[i]["SSRWLX"].ToString(); tp.SSJIDhead = _SSJDhead; lsTransport.Add(tp); } return(true); } return(false); }
public PLCErrorEnum ValidatePLC() { bool result = true; bool atLeastOnePLC = false; _AddUpdatePLCList.Clear(); _UnchangedPLCList.Clear(); foreach (UltraGridRow ur in dg.Rows) { foreach (UltraGridCell c in ur.Cells) { c.Style.BackColor = Color.Empty; } if (ur.Cells.FromKey("RegionType").Text == "C") //country { UltraGridCell resultCell = ur.Cells.FromKey("Err"); resultCell.Text = string.Empty; DateTime?blind = (DateTime?)ur.Cells.FromKey("Blind").Value; DateTime?full = (DateTime?)ur.Cells.FromKey("PID").Value; DateTime?obsolete = (DateTime?)ur.Cells.FromKey("POD").Value; DateTime?announcement = (DateTime?)ur.Cells.FromKey("Announcement").Value; DateTime?removal = (DateTime?)ur.Cells.FromKey("Removal").Value; DateTime?endSupport = (DateTime?)ur.Cells.FromKey("EndOfSupport").Value; DateTime?discontinue = (DateTime?)ur.Cells.FromKey("Discontinue").Value; DateTime?endoflife = (DateTime?)ur.Cells.FromKey("EndOfLife").Value; if (blind.HasValue || full.HasValue || obsolete.HasValue || announcement.HasValue || removal.HasValue) { Trace.Write("Validating " + ur.Cells.FromKey("RegionCode").Text + " starts", ""); atLeastOnePLC = true; int excludeModifierId = (ur.Cells.FromKey("ExcludeModifierId").Value) != null ? (int)(ur.Cells.FromKey("ExcludeModifierId").Value) : 0; bool bExcluded = Convert.ToBoolean(ur.Cells.FromKey("Excluded").Value); bool blindLocked = (bool)(ur.Cells.FromKey("BlindLocked").Value); char?blindDateType = (Char?)(ur.Cells.FromKey("BlindDateType").Value); bool fullLocked = (bool)(ur.Cells.FromKey("FullLocked").Value); char?fullDateType = (Char?)(ur.Cells.FromKey("FullDateType").Value); bool obsoleteLocked = (bool)(ur.Cells.FromKey("ObsoleteLocked").Value); char?obsoleteDateType = (Char?)(ur.Cells.FromKey("ObsoleteDateType").Value); bool announcementLocked = (bool)(ur.Cells.FromKey("AnnouncementLocked").Value); char?announcementDateType = (Char?)(ur.Cells.FromKey("AnnouncementDateType").Value); bool removalLocked = (bool)(ur.Cells.FromKey("RemovalLocked").Value); char?removalDateType = (Char?)(ur.Cells.FromKey("RemovalDateType").Value); bool endOfSupportLocked = (bool)(ur.Cells.FromKey("EndOfSupportLocked").Value); char?endOfSupportDateType = (Char?)(ur.Cells.FromKey("EndOfSupportDateType").Value); bool discontinueLocked = (bool)(ur.Cells.FromKey("DiscontinueLocked").Value); char?discontinueDateType = (Char?)(ur.Cells.FromKey("DiscontinueDateType").Value); bool endOfLifeLocked = (bool)(ur.Cells.FromKey("DiscontinueLocked").Value); char?endOfLifeDateType = (Char?)(ur.Cells.FromKey("DiscontinueDateType").Value); string m = string.Empty; if (ur.Cells.FromKey("Upd").Text == "u") { if (!full.HasValue) { m = LongNamePID + " (" + ShortNamePID + ") " + " cannot be null"; Trace.Warn(m); resultCell.Text = AddErrorToolTip(m); ur.Cells.FromKey("PID").Style.BackColor = Color.Red; result = false; continue; } if (!obsolete.HasValue) { m = LongNamePOD + " (" + ShortNamePOD + ") " + " Date cannot be null"; Trace.Warn(m); resultCell.Text = AddErrorToolTip(m); ur.Cells.FromKey("POD").Style.BackColor = Color.Red; result = false; continue; } if (blind >= full) { m = LongNamePID + " (" + ShortNamePID + ") " + " must occur after " + LongNameBlind + " (" + ShortNameBlind + ")"; Trace.Warn(m); resultCell.Text = AddErrorToolTip(m); ur.Cells.FromKey("Blind").Style.BackColor = Color.Red; ur.Cells.FromKey("PID").Style.BackColor = Color.Red; result = false; continue; } if (full >= obsolete) { m = LongNamePOD + " (" + ShortNamePOD + ") " + " must occur after " + LongNamePID + " (" + ShortNamePID + ")"; Trace.Warn(m); resultCell.Text = AddErrorToolTip(m); ur.Cells.FromKey("POD").Style.BackColor = Color.Red; ur.Cells.FromKey("PID").Style.BackColor = Color.Red; result = false; continue; } if (announcement >= obsolete) { m = LongNameAnnouncement + " (" + ShortNameAnnouncement + ") " + " must occur before " + LongNamePOD + " (" + ShortNamePOD + ")"; Trace.Warn(m); resultCell.Text = AddErrorToolTip(m); ur.Cells.FromKey("Announcement").Style.BackColor = Color.Red; ur.Cells.FromKey("POD").Style.BackColor = Color.Red; result = false; continue; } if (removal <= announcement) { m = LongNameRemoval + " (" + ShortNameRemoval + ") " + " must occur after " + LongNameAnnouncement + " (" + ShortNameAnnouncement + ")"; Trace.Warn(m); resultCell.Text = AddErrorToolTip(m); ur.Cells.FromKey("Removal").Style.BackColor = Color.Red; ur.Cells.FromKey("POD").Style.BackColor = Color.Red; result = false; continue; } if (result) { _AddUpdatePLCList.Add(new PLC(-1, ur.Cells.FromKey("RegionCode").Text, blind, null, blindLocked, _PLCUserId, blindDateType, full, null, fullLocked, _PLCUserId, fullDateType, obsolete, null, obsoleteLocked, _PLCUserId, obsoleteDateType, announcement, null, announcementLocked, _PLCUserId, announcementDateType, removal, null, removalLocked, _PLCUserId, removalDateType, bExcluded, null, excludeModifierId, endSupport, null, endOfSupportLocked, _PLCUserId, endOfSupportDateType, discontinue, null, discontinueLocked, _PLCUserId, discontinueDateType, endoflife, null, endOfLifeLocked, _PLCUserId, endOfLifeDateType)); } } else { _UnchangedPLCList.Add(new PLC(-1, ur.Cells.FromKey("RegionCode").Text, blind, null, blindLocked, _PLCUserId, blindDateType, full, null, fullLocked, _PLCUserId, fullDateType, obsolete, null, obsoleteLocked, _PLCUserId, obsoleteDateType, announcement, null, announcementLocked, _PLCUserId, announcementDateType, removal, null, removalLocked, _PLCUserId, removalDateType, bExcluded, null, excludeModifierId, endSupport, null, endOfSupportLocked, _PLCUserId, endOfSupportDateType, discontinue, null, discontinueLocked, _PLCUserId, discontinueDateType, endoflife, null, endOfLifeLocked, _PLCUserId, endOfLifeDateType)); } } else { if (ur.DataChanged == DataChanged.Modified || ur.Cells.FromKey("Upd").Text == "u") { _DeletedPLCList.Add(new PLC(-1, ur.Cells.FromKey("RegionCode").Text, null, null, false, _PLCUserId, (Char?)null, null, null, false, _PLCUserId, (Char?)null, null, null, false, _PLCUserId, (Char?)null, null, null, false, _PLCUserId, (Char?)null, null, null, false, _PLCUserId, (Char?)null, false, null, 0)); } } Trace.Write("Validating " + ur.Cells.FromKey("RegionCode").Text + " Ends", "Data Changed= [" + ur.Cells.FromKey("Upd").Text + "] and result = " + result.ToString()); } } if (result) { if (atLeastOnePLC) { return(PLCErrorEnum.None); } return(PLCErrorEnum.NoDates); } dg.Columns.FromKey("Err").ServerOnly = false; return(PLCErrorEnum.CorruptedData); }