using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using Aitex.Core.RT.IOCore; namespace Aitex.Core.Backend { public partial class SwInterlock : UserControl { private List _di = new List(); private List _do = new List(); private bool _loaded = false; private bool _editable; Dictionary> _limit = new Dictionary>(); private List> _diList; private List> _doList; public SwInterlock() { InitializeComponent(); _diList = IO.GetIONameList(IOType.DI); _doList = IO.GetIONameList(IOType.DO); foreach (var tuple in _diList) { _di.Add(string.Format("DI-{0} {1}", tuple.Item1, tuple.Item3)); } Random _rd = new Random(); for(int i=0; i<_doList.Count; i++) { _do.Add(string.Format("DO-{0}", i)); _limit[_do[i]] = new Dictionary(); for (int k=0; k<_di.Count; k++) { int mod = _rd.Next(100) % 3; _limit[_do[i]][_di[k]] = mod==0 ? "*" : (mod==1 ? true.ToString() : false.ToString()); } } } /// /// 重新读取PmInterlock.cfg文件 /// /// /// private void buttonReRead_Click(object sender, EventArgs e) { if (MessageBox.Show(string.Format("是否重新读取互锁配置文件?"), "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string reason; if (IO.ReloadInterlockConfig(out reason)) { MessageBox.Show("读取互锁文件成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("读取互锁文件失败:\n" + reason, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void btnSave_Click(object sender, EventArgs e) { } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { var sel = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; if (!checkBox1.Checked) { sel.Style.SelectionBackColor = sel.Style.BackColor; sel.Style.SelectionForeColor = Color.Black; return; } if (e.RowIndex < 0 || e.ColumnIndex < 1) return; string value = _limit[_do[e.ColumnIndex-1]][_di[e.RowIndex]]; //MessageBox.Show(value); if (value.ToLower() == "true") { var cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; cell.Value = "False"; cell.Style.BackColor = Color.Tomato; cell.Style.SelectionBackColor = Color.Tomato; cell.Style.SelectionForeColor = Color.Black; _limit[_do[e.ColumnIndex - 1]][_di[e.RowIndex]] = "False"; }else if (value.ToLower() == "false") { var cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; cell.Value = "*"; cell.Style.BackColor = Color.GhostWhite; cell.Style.SelectionBackColor = Color.GhostWhite; cell.Style.SelectionForeColor = Color.Black; _limit[_do[e.ColumnIndex - 1]][_di[e.RowIndex]] = "*"; }else if (value.ToLower() == "*") { var cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; cell.Value = "True"; cell.Style.BackColor = Color.GreenYellow; cell.Style.SelectionBackColor = Color.GreenYellow; cell.Style.SelectionForeColor = Color.Black; _limit[_do[e.ColumnIndex - 1]][_di[e.RowIndex]] = "True"; } } private void dataGridView1_SelectionChanged(object sender, EventArgs e) { for (int i=0; i1\r\n关->开\r\nFalse->True", _do[i]); col.Width = 100; col.Tag = _limit[_do[i]]; this.dataGridView1.Columns.Add(col); } for (int j = 0; j < _di.Count; j++) { int rowIndex = this.dataGridView1.Rows.Add(_di[j]); this.dataGridView1.Rows[rowIndex].Height = 30; } for (int i = 0; i < dataGridView1.RowCount; i++) { for (int j = 1; j < dataGridView1.Rows[i].Cells.Count; j++) { var cell = dataGridView1.Rows[i].Cells[j]; var text = _limit[_do[j - 1]][_di[i]]; cell.Value = text.ToLower()=="true" ? "True" : (text.ToLower()=="false" ? "False" : "*") ; if (text == "*") cell.Style.BackColor = Color.GhostWhite; else if (text.ToLower() == "true") cell.Style.BackColor = Color.GreenYellow; else if (text.ToLower() == "false") cell.Style.BackColor = Color.Tomato; } } } private void checkBox1_CheckedChanged(object sender, EventArgs e) { _editable = checkBox1.Checked; } } }