void DeleteRow() { foreach (DataGridView dgv in dgvList) { if (dgv.Visible) { DialogResult dr = MessageBox.Show("确定删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (DialogResult.Yes == dr) { List <DataGridViewRow> rl = new List <DataGridViewRow>(); foreach (DataGridViewCell cell in dgv.SelectedCells) { DataGridViewRow row = cell.OwningRow; dgv.Rows.Remove(row); } string cname = controllerDropList.SelectedValue as string; string IOType = IOTab.SelectedTab.Text; IODataCollection.dataTableType dtt = (IODataCollection.dataTableType)Array.IndexOf( Enum.GetNames(typeof(IODataCollection.dataTableType)), IOType); if (dgv.Rows.Count <= 0) { IODataCollection.FillEmptyTable(cname, dtt); } System.Data.DataTable table = dgv.DataSource as System.Data.DataTable; table.AcceptChanges(); } } } }
public static string SendInitialJSONFromDataCollection(out DateTime lastModifiedTimeutc) { Dictionary <string, DataSet> tdd = new Dictionary <string, DataSet>(IODataCollection.dataDict); lastModifiedTimeutc = DateTime.Now; IODataUpdater.AddChangeEventForIODataCollection(); string JSON = ""; JObject o = new JObject(from tt in tdd where IODataCollection.FindNameListItemByName(tt.Key) != null let ds = tt.Value.Tables select new JProperty(tt.Key, new JObject(from DataTable table in ds select new JProperty(table.TableName, new JObject((from DataRow rr in table.Rows let rs = rr["IOName"] as string where rs != "" let rss = GetIOName(tt.Key, rs) group rss by rss into rsg orderby rsg.Key ascending select new JProperty(rsg.Key, GenJSONJArrayFromDataCollection(tdd, tt.Key, table.TableName, rsg.Key) )).OrderBy(k => k.Name, new CustomCompare())))))); JSON = o.ToString(); return(JSON); }
private static void IODataUpdate() { while (true) { Thread.Sleep(10); IODataCollection.UpdateDataSetIOFromQueryList(); IODataCollection.RemoveOldFromChangeDict(); } }
public static bool CreateQuery() { IODataCollection.GenerateQueryList("ACS"); if ((IODataCollection.queryList.FindAll(c => c.name.StartsWith("ACS-")).Count() == 0) && (IODataCollection.controllerNameList.ToList().FindAll(c => c.name.StartsWith("ACS-")).Count() != 0)) { return(false); } return(true); }
void FillTable() { DataTable table = limitDGV.DataSource as DataTable; table.RejectChanges(); Dictionary <string, string> ta = new Dictionary <string, string>(); int max = Convert.ToInt32(axisNumberBox.Value) - 1; int i, j; for (j = 0; j <= max; j++) { if (axisDesp.ContainsKey(j)) { for (i = 0; i < 2; i++) { ta.Add(preFix + j + '.' + i, axisDesp[j] + sChar + LimitStr[i]); } } else { for (i = 0; i < 2; i++) { ta.Add(preFix + j + '.' + i, "$$$ " + j + "号轴" + sChar + LimitStr[i]); } } } string name; foreach (DataRow row in table.Rows) { name = row["IOName"] as string; if (ta.ContainsKey(name)) { if (!ta[name].StartsWith("$$$")) { row["IOAlias"] = ta[name]; } else if (IsStringEmpty(row["IOAlias"] as string)) { row["IOAlias"] = ta[name].TrimStart('$', ' '); } ta.Remove(name); } } foreach (var v in ta) { table.Rows.Add(v.Key, v.Value.TrimStart('$', ' '), "OFF", IODataCollection.checkStatusType.Uncheck); } IODataCollection.ClearEmptyRowFromTable(table); table.DefaultView.Sort = "IOName ASC"; }
private void PasteData() { if (controllerDropList.Items.Count > 0) { string pasteText = Clipboard.GetText(); string IOType = IOTab.SelectedTab.Text; IODataCollection.dataTableType dtt = (IODataCollection.dataTableType)Array.IndexOf( Enum.GetNames(typeof(IODataCollection.dataTableType)), IOType); DataGridView dgv = new DataGridView(); switch (dtt) { case IODataCollection.dataTableType.Input: dgv = inputDGV; break; case IODataCollection.dataTableType.Output: dgv = outputDGV; break; case IODataCollection.dataTableType.Limit: dgv = limitDGV; break; } string controllerName = controllerDropList.SelectedValue as string; PasteFormPreviewWindow pfp = new PasteFormPreviewWindow(pasteText, dgv, dgvList, controllerName.Split('-')[0]); pfp.ShowDialog(); if (pfp.result) { DataTable ct = pfp.pTable; IODataCollection.AddTable(dtt, controllerName, ct); switch (dtt) { case IODataCollection.dataTableType.Input: inputDGV.Sort(inputDGV.Columns["IOName"], ListSortDirection.Ascending); break; case IODataCollection.dataTableType.Output: outputDGV.Sort(outputDGV.Columns["IOName"], ListSortDirection.Ascending); break; case IODataCollection.dataTableType.Limit: limitDGV.Sort(limitDGV.Columns["IOName"], ListSortDirection.Ascending); break; } } } else { MessageBox.Show("请先添加控制器", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); childItemManageControllers.PerformClick(); } }
private bool CheckControllerNameLegal(string cn, int rowIndex, int colIndex) { if (cn.Contains(' ')) { MessageBox.Show("名称不能带有空格", "名称格式错误", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } if (IODataCollection.controllerDict.ContainsKey(IODataCollection.MergeTypeNameAndControllerName(selectControllerTypeName, cn))) { MessageBox.Show("名称重复!", "名称错误", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } return(true); }
private static void OnTransaction(IAsyncResult ar) { object[] os = (object[])ar.AsyncState; string cname = (string)os[0]; ACSControllerUtilities _acsu = (ACSControllerUtilities)os[1]; string queryStr = ACSQueryUtilities.GenACSSimQueryStr(IODataCollection.queryList.Find(cls => cls.name == cname).IOList); try { string transStr = _acsu.EndTransaction(ar); List <int> tl = ACSQueryUtilities.ConvertACSTransStr(transStr, out bool result); if (!result) { string err = $"变量名错误或未定义:{cname}@{queryStr}=>{transStr}"; IOInterface.updateError = true; RunningTransaction.Remove(cname); IOInterface.ShowError(err); return; } IODataCollection.UpdateIOQueryList(cname, tl); if (!ACSThreadAbort) { Thread.Sleep(50); _acsu.BeginTransaction(cname, queryStr, new AsyncCallback(OnTransaction), _acsu); } else { RunningTransaction.Remove(cname); if (RunningTransaction.Count == 0) { ACSThreadAborted = true; } } } catch (Exception e) { string err = $"{e.Message}:{cname}@{queryStr}"; IOInterface.updateError = true; RunningTransaction.Remove(cname); if (RunningTransaction.Count == 0) { ACSThreadAborted = true; } IOInterface.ShowError(err); } GC.Collect(); }
private void RebuildBindingList() { UncheckBadRow(); Dictionary <string, string> d = new Dictionary <string, string>(); d = (from DataRow dr1 in IODataCollection.ControllerTypeTable.Rows where (bool)dr1["Update"] == true let ct = (string)dr1["Controller Type"] select new { key = ct, Rows = IODataCollection.ControllerDataTableList.Find(t => t.TableName == ct).Rows } into dts from DataRow dr in dts.Rows // from DataGridViewRow dgv in controllerDGV.Rows where dr["Update"] != null where (bool)dr["Update"] == true select new { key = dts.key + "-" + (string)dr["Controller Name"], value = (string)dr[GetAddressName(dts.key)] }).ToDictionary(k => k.key, k => k.value); Invoke(new Action(() => { IODataCollection.RebuildBindList(d); })); }
static void ACSConnectTask(string cname, string IP, CancellationToken ct) { bool exception = false; string eMessage = ""; int i = 0; ManualResetEvent mre = new ManualResetEvent(false); Thread t = new Thread(() => { try { if (IODataCollection.GetControllerName(cname) == ACSBaseConfig.sim) { acsu.SimConnect(); } else { acsu.TCPConnect(cname, IP); } } catch (Exception e) { exception = true; eMessage = e.Message; } mre.Set(); } ); t.IsBackground = true; t.Start(); while (!mre.WaitOne(100)) { i++; if (i > 50 || ct.IsCancellationRequested) { t.Abort(); if (i > 50) { throw new Exception($"ACS连接超时,IP:{IP}"); } return; } } if (exception) { throw new Exception($"ACS连接错误,IP:{IP},代码:{eMessage}"); } }
public void CheckRowValueLegal(int rowIndex, int colIndex) { string cn, address; List <string> checkList = (from DataGridViewRow dgvr in controllerDGV.Rows let s = dgvr.Cells[colIndex].Value as string where s != "" select s).ToList(); cn = GetCellValueAndChange(rowIndex, "Controller Name"); address = GetCellValueAndChange(rowIndex, GetAddressName()); illegalRowIndex = -1; illegalColumnIndex = -1; if (colIndex == controllerDGV.Columns["Controller Name"].Index) { if (!CheckControllerName(cn, rowIndex, colIndex, checkList)) { return; } } else if (colIndex == controllerDGV.Columns[GetAddressName()].Index) { if (!CheckControllerAddress(address, rowIndex, colIndex, checkList)) { return; } } switch (editControllerType) { case EditType.Add: IODataCollection.AddController(selectControllerTypeName, cn, address); break; case EditType.UpdateName: IODataCollection.UpdateControllerName(selectControllerTypeName, oldStr, cn); break; case EditType.UpdateAddress: IODataCollection.UpdateControllerAddress(selectControllerTypeName, address, cn); break; default: break; } }
private void tableAddButton_Click(object sender, EventArgs e) { if (CheckTableEmpty()) { MessageBox.Show("没有限位定义", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } else { DialogResult r = MessageBox.Show("将覆盖原有IO表,是否继续", "提示" , MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (DialogResult.Yes == r) { DataTable table = limitDGV.DataSource as DataTable; table.AcceptChanges(); Invoke(new Action(() => { IODataCollection.AddTable(IODataCollection.dataTableType.Limit, controllerName, table); })); } } }
private void InitializeControllerTable() { if (!hasStorageData) { ACSBaseConfig.dac = ACSBaseConfig.DefaultACSChoice.Simulator; IODataCollection.AddController("ACS", ACSBaseConfig.sim, "", ACSBaseConfig.dac == ACSBaseConfig.DefaultACSChoice.Simulator); IODataCollection.AddController("ACS", "Default", "10.0.0.100", ACSBaseConfig.dac == ACSBaseConfig.DefaultACSChoice.Default); IODataCollection.AddControllerTable("ACS", ACSBaseConfig.dac == ACSBaseConfig.DefaultACSChoice.Simulator, ACSBaseConfig.sim, ""); IODataCollection.AddControllerTable("ACS", ACSBaseConfig.dac == ACSBaseConfig.DefaultACSChoice.Default, "Default", "10.0.0.100"); IODataCollection.DuplicateControllerTable("ACS"); IODataCollection.AddController("QPLC", ACSBaseConfig.sim, ""); IODataCollection.AddControllerTable("QPLC", false, ACSBaseConfig.sim, ""); IODataCollection.DuplicateControllerTable("QPLC"); IODataCollection.DuplicateControllerTable("LS"); } RetrieveSelectController(); }
void ClearTable() { foreach (DataGridView dgv in dgvList) { if (dgv.Visible) { DialogResult dr = MessageBox.Show("确定清空?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (DialogResult.Yes == dr) { System.Data.DataTable table = dgv.DataSource as System.Data.DataTable; table.Clear(); string cname = controllerDropList.SelectedValue as string; string IOType = IOTab.SelectedTab.Text; IODataCollection.dataTableType dtt = (IODataCollection.dataTableType)Array.IndexOf( Enum.GetNames(typeof(IODataCollection.dataTableType)), IOType); IODataCollection.FillEmptyTable(cname, dtt); } } } }
private void InitializeTable() { bool result; if (CheckText()) { pTable = IODataCollection.CreateTableFromClipboardText(pText, out result); if (result) { pDGV.DataSource = pTable; //pDGV.ReadOnly = true; pDGV.Columns[IODataCollection.colTypeDict[IODataCollection.colType.IOName]].ReadOnly = false; pDGV.Columns[IODataCollection.colTypeDict[IODataCollection.colType.IOAlias]].ReadOnly = false; pDGV.Columns[IODataCollection.colTypeDict[IODataCollection.colType.ONOFF]].ReadOnly = true; pDGV.Columns[IODataCollection.colTypeDict[IODataCollection.colType.CheckStatus]].ReadOnly = true; confirmButton.Enabled = true; pDGV.CellValueChanged += PDGV_CellValueChanged; } else { MessageBox.Show("数据有错,请更正", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private static void Update(string cname, List <string> queryList) { while (true) { try { Thread.Sleep(50); List <int> tl = LSu.ReadDevice(cname, queryList); IODataCollection.UpdateIOQueryList(cname, tl); } catch (Exception e) { string queryStr = string.Join(",", queryList); string err = $"{e.Message} {cname}@{queryStr}"; IOInterface.updateError = true; RunningTransaction.Remove(cname); if (RunningTransaction.Count == 0) { LSThreadAborted = true; } IOInterface.ShowError(err); return; } if (LSThreadAbort) { RunningTransaction.Remove(cname); if (RunningTransaction.Count == 0) { LSThreadAborted = true; } return; } } }
private void DataManagementInitialize() { cm = new ACSMaster(); DataManager dm = cm.dm; try { if (dm.HasStorage()) { dm.FillData(); hasStorageData = true; } else { hasStorageData = false; } } catch (Exception e) { MessageBox.Show(e.Message); hasStorageData = false; } IODataCollection.RebuildControllerTableList(); }
public void SimConnect() { simApi = new Api(); simApi.OpenCommSimulator(); aList.Add(IODataCollection.MergeTypeNameAndControllerName("ACS", ACSBaseConfig.sim), simApi); }
public void ChangeCheckStatus(string cName, string IOName, string checkStatus) { Invoke(new Action(() => { IODataCollection.ChangeCheckStatus(cName, IOName, checkStatus); })); }
private void RemoveController(string cname) { IODataCollection.RemoveController(selectControllerTypeName, cname); }
private static void StopThreadIODataUpdate() { IODataCollection.initJsonSent = false; IODataCollection.ClearChangeDict(); IODataUpdateThread.Abort(); }