private void DoJob(object sender, EventArgs e) { if (_isRunning) { string[] equipnums = existChannelInfos.Keys.ToArray(); for (int i = 0; i < equipnums.Length; i++) { List <SectorInfo> sectors = channelZoneInfos[equipnums[i]]; if (existChannelInfos[equipnums[i]].autoFlag) { for (int j = 0; j < sectors.Count; j++) { if (sectors[j].touchFlag) { existChannelInfos[equipnums[i]].udpClient.SendAlarmMessage(Int16.Parse(equipnums[i]), Int16.Parse(sectors[j].sectorNum), AlarmType.Touch); } if (sectors[j].intrudeFlag) { existChannelInfos[equipnums[i]].udpClient.SendAlarmMessage(Int16.Parse(equipnums[i]), Int16.Parse(sectors[j].sectorNum), AlarmType.Intrude); } if (sectors[j].breakFlag) { existChannelInfos[equipnums[i]].udpClient.SendAlarmMessage(Int16.Parse(equipnums[i]), Int16.Parse(sectors[j].sectorNum), AlarmType.Break); } } } } existChannelInfos = ReadChannelCfg.Create().ExistChannels; channelZoneInfos = ReadSectorCfg.Create().ChannelSectorInfos; // Thread.Sleep(30000); } }
private void Manul(object sender, EventArgs e) { CheckBox cb = sender as CheckBox; if (cb.Checked) { string equipnum = ((TabControlPanel)(cb.Parent.Parent)).TabItem.Name; int index = equipnum.IndexOf(":"); equipnum = equipnum.Substring(index + 1); Dictionary <string, FPMS> existChannelInfos = ReadChannelCfg.Create().ExistChannels; if (existChannelInfos.Keys.Contains(equipnum)) { existChannelInfos[equipnum].manulFlag = true; existChannelInfos[equipnum].autoFlag = false; } ReadChannelCfg.Create().ExistChannels = existChannelInfos; ((CheckBox)cb.Parent.Controls[3]).Checked = false; } }
private void Bt_Start_Click(object sender, EventArgs e) { int count = 0; existChannelInfos = ReadChannelCfg.Create().ExistChannels; channelZoneInfos = ReadSectorCfg.Create().ChannelSectorInfos; string ip = ipAddressInput.Value; if (Bt_Start.Text == "启 动") { RefreshTableControl(existChannelInfos, channelZoneInfos); foreach (KeyValuePair <string, FPMS> kvp in existChannelInfos) { if (kvp.Value.serverPort != -1) { kvp.Value.udpClient = new UDP(ip, kvp.Value.serverPort, kvp.Key); kvp.Value.udpClient.StartThread(); //启动线程发送心跳包 count++; } } _isRunning = true; sendTimer.Start(); Bt_Start.Text = "停 止"; label_chanelNums.Text = count.ToString(); } else { foreach (KeyValuePair <string, FPMS> kvp in existChannelInfos) { if (kvp.Value.serverPort != -1 && kvp.Value.udpClient != null) { kvp.Value.udpClient.Disconnect(); } } _isRunning = false; sendTimer.Stop(); Bt_Start.Text = "启 动"; } }
private void RefreshTableControl(Dictionary <string, FPMS> ExistChannels, Dictionary <string, List <SectorInfo> > channelZoneInfos) { Size size = tabControl.Tabs[0].AttachedControl.Size; DataGridViewX dgvx = (DataGridViewX)(tabControl.Tabs[0].AttachedControl.Controls[0]); tabControl.SuspendLayout(); this.SuspendLayout(); tabControl.Tabs.Clear(); tabControl.TabAlignment = eTabStripAlignment.Top; List <int> channelNums = new List <int>(); foreach (KeyValuePair <string, FPMS> kvp in ReadChannelCfg.Create().ExistChannels) { if (kvp.Value.serverPort != -1) { channelNums.Add(int.Parse(kvp.Key)); } } if (channelNums.Count == 0) { TabItem ti = tabControl.CreateTab("FPMS:1"); ti.Name = "FPMS:1"; ti.AttachedControl.Size = size; ti.AttachedControl.Dock = DockStyle.Fill; ti.AttachedControl.Controls.Add(dgvx); } else { int[] num = channelNums.ToArray(); Array.Sort(num); for (int i = 0; i < channelNums.Count; i++) { TabItem ti = tabControl.CreateTab("FPMS:" + num[i]); ti.Name = "FPMS:" + num[i]; ti.AttachedControl.Size = size; ti.AttachedControl.Dock = DockStyle.Fill; DataGridViewX dgv = new DataGridViewX(); dgv.AllowUserToAddRows = false; dgv.Dock = DockStyle.Fill; dgv.BackgroundColor = dgvx.BackgroundColor; for (int j = 0; j < dgvx.ColumnCount - 2; j++) { dgv.Columns.Add(dgvx.Columns[j].Clone() as DataGridViewColumn); } dgv.Columns.Add("4", "手动"); dgv.Columns.Add("5", "自动"); //更新DataGridView中的行内容 List <SectorInfo> sectorinfos = new List <SectorInfo>(); if (channelZoneInfos.TryGetValue(num[i].ToString(), out sectorinfos)) { sectorinfos.Sort((x, y) => int.Parse(x.sectorNum).CompareTo(int.Parse(y.sectorNum))); for (int j = 0; j < sectorinfos.Count; j++) { DataGridViewRow row = new DataGridViewRow(); dgv.Rows.Add(row); dgv.Rows[j].Cells[0].Value = sectorinfos[j].sectorNum; dgv.Rows[j].Cells[4].Value = ""; dgv.Rows[j].Cells[5].Value = ""; } //合并单元格 CheckBox cb = new CheckBox(); cb.Parent = dgv; cb.CheckedChanged += Manul; cb.Checked = false; cb.Text = ""; cb.BackColor = Color.Transparent; cb.Width = dgv.Columns[4].Width / 2; cb.Location = new Point(480 + dgv.Columns[4].Width / 2, (dgv.Rows[0].Height * dgv.RowCount) / 2 + dgv.Location.Y + 25 / 2); dgv.Controls.Add(cb); CheckBox cb1 = new CheckBox(); cb1.Parent = dgv; cb1.CheckedChanged += Auto; cb1.Checked = false; cb1.BackColor = Color.Transparent; cb1.Text = ""; cb1.Width = dgv.Columns[5].Width / 2; cb1.Location = new Point(580 + dgv.Columns[5].Width / 2, (dgv.Rows[0].Height * dgv.RowCount) / 2 + dgv.Location.Y + 25 / 2); dgv.Controls.Add(cb1); } dgv.CellContentClick += Dgv_CellContentClick; dgv.CurrentCellDirtyStateChanged += Dgv_CurrentCellDirtyStateChanged; dgv.CellValueChanged += Dgv_CellValueChanged; dgv.RowPostPaint += RowPostPaint; dgv.CellPainting += CellPainting; ti.AttachedControl.Controls.Add(dgv); } } tabControl.ResumeLayout(true); this.ResumeLayout(true); }