private void btn_M添加_Click(object sender, EventArgs e) { 场景模块添加界面 frm = new 场景模块添加界面(); if (frm.ShowDialog() == DialogResult.OK) { if (tmp场景子模块.场景调试模块列表2 == null) { tmp场景子模块.场景调试模块列表2 = new List <场景调试模块>(); } foreach (var v in frm.模块编号) { if (tmp场景子模块.场景调试模块列表2.FindIndex(t => t.模块编号 == v) != -1) { continue; } 场景调试模块 tmp = new 场景调试模块(); tmp.场景开关信息列表 = new List <场景开关信息>(); while (tmp.场景开关信息列表.Count < 16) { var vmsg = new 场景开关信息(); vmsg.开关通道 = (tmp.场景开关信息列表.Count + 1).ToString(); vmsg.开关状态 = "是"; vmsg.开关亮度 = "0"; tmp.场景开关信息列表.Add(vmsg); } tmp.模块编号 = v; var v1 = ModelsOperate.GetModel(int.Parse(tmp.模块编号)); tmp场景子模块.场景调试模块列表2.Add(tmp); } RefreshForm_场景模块(tmp场景子模块.场景调试模块列表2); } }
private void btn_Delete_Click(object sender, EventArgs e) { if (num_addr1.Value == 0 || num_addr2.Value == 0) { tip_Lable.Text = "地址必须大于0"; return; } if (num_addr1.Value > num_addr2.Value) { tip_Lable.Text = "前个地址必须大于后个地址"; return; } if (num_addr2.Value != ModelsOperate.ModelsList.Count) { tip_Lable.Text = "最后地址必须是最大地址!"; return; } if (MessageBox.Show("请问是否删除数据", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { for (int i = (int)num_addr1.Value; i < (int)(num_addr2.Value) + 1; i++) { ModelsOperate.Delete(i); tip_Lable.Text = ""; } ModelsOperate.ModelsList = ModelsOperate.AllModelsList.FindAll(t => !t.IsRemove); ModelsOperate.Display(dataGridView1); } }
private void dgv_调试模块_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1 || e.ColumnIndex == -1) { dgv_开关模块.Rows.Clear(); return; } if (dgv_场景模块.SelectedRows.Count == 0) { dgv_调试模块.Rows.Clear(); dgv_开关模块.Rows.Clear(); MessageBox.Show("请先选择场景模块!"); return; } if (dgv_调试模块.SelectedRows.Count == 0) { dgv_开关模块.Rows.Clear(); MessageBox.Show("请先选择产品模块模块!"); return; } string name = Convert.ToString(dgv_场景模块.SelectedRows[0].Cells[0].Value); int index = -1; if ((index = 当前场景模块.FindIndex(t => t.场景名称 == name)) == -1) { dgv_调试模块.Rows.Clear(); dgv_开关模块.Rows.Clear(); return; } if (当前场景模块[index] == null) { 当前场景模块[index].场景调试模块列表 = new List <场景调试模块>(); } 场景调试模块 tmp = 当前场景模块[index].场景调试模块列表.Find(t => t.模块编号 == Convert.ToString(dgv_调试模块.Rows[e.RowIndex].Cells[0].Value)); if (tmp == null) { MessageBox.Show("该地址模块不存在!"); return; } if (tmp.场景开关信息列表 == null) { tmp.场景开关信息列表 = new List <场景开关信息>(); } while (tmp.场景开关信息列表.Count < 16) { var v = new 场景开关信息(); v.开关通道 = (tmp.场景开关信息列表.Count + 1).ToString(); v.开关状态 = "是"; v.开关亮度 = "0"; tmp.场景开关信息列表.Add(v); } var tmp1 = ModelsOperate.GetModel(int.Parse(tmp.模块编号)); //for (int i = 0; i < tmp1.开关列表.Count; i++) //{ // tmp.场景开关信息列表.Find(t=>t.开关通道 == tmp1.开关列表[i].模块编号).开关名称 = tmp1.开关列表[i].开关名称; //} Refresh_dgv_开关模块(tmp.场景开关信息列表, tmp1); }
public static void LoadSwitch(int 模块地址) { string sql = string.Format(@" select * from 开关信息 where 模块地址 = '{0}' ", 模块地址.ToString()); 调试模块 tmp = ModelsOperate.GetModel(模块地址); //if (tmp.开关列表 == null) // tmp.开关列表 = new List<开关模块>(); DataTable dt = AccessLib.GetData(sql); foreach (DataRow v in dt.Rows) { 开关模块 swit = new 开关模块() { 模块编号 = 模块地址.ToString(), 开关编号 = Convert.ToString(v["开关编号"]), 开关名称 = Convert.ToString(v["开关名称"]), 开关位置 = Convert.ToString(v["开关位置"]) }; //int index = -1; //if ((index = tmp.开关列表.FindIndex(t => t.开关编号 == swit.开关编号)) != -1) //{ // //tmp.开关列表[index] = swit; // tmp.开关列表[index].开关位置 = swit.开关位置; // tmp.开关列表[index].开关名称 = swit.开关名称; //} //else //{ // tmp.开关列表.Add(swit); //} } }
private void button1_Click(object sender, EventArgs e) { if (MessageBox.Show("是否清空数据", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ModelsOperate.ClearModelMsg(); ModelsOperate.Display(dataGridView1); } }
private void Panel_Click(object sender, EventArgs e) { var tmp = ModelsOperate.GetModel(int.Parse(AddrNumber)); if (ButtonClick != null) { ButtonClick(sender, tmp); } }
private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { if (e.ClickedItem.Name == "开关编辑") { 开关管理 frm = new 开关管理(); frm.tmp = ModelsOperate.GetModel(Convert.ToInt32(dataGridView1.Rows[Editindex].Cells[0].Value)); frm.ShowDialog(); Editindex = -1; } }
private void btn_Save_Click(object sender, EventArgs e) { if (txt_模块地址.Text.Trim().Length == 0) { tip_Lable.Text = "模块地址不能为空!"; } ModelsOperate.Modify(int.Parse(txt_模块地址.Text), txt_模块名称.Text, txt_安装位置.Text, "", check_为空.Checked); ModelsOperate.OnlyDisplay(dataGridView1); MessageBox.Show("保存成功!"); tip_Lable.Text = ""; }
private void RefreshForm_场景模块(List <场景调试模块> tmp) { dgv_调试模块.Rows.Clear(); var vv = tmp.OrderBy(t => int.Parse(t.模块编号)).ToList(); foreach (var v in vv) { var v1 = ModelsOperate.GetModel(int.Parse(v.模块编号)); dgv_调试模块.Rows.Add(v.模块编号, v1.模块名称); } }
public void RefreshPanel1() { int max = ModelsOperate.GetMaxAddr(); //if (max == 0) //{ // max = 16; // for (int i = 0; i < max; i++) // ModelsOperate.Add(i+1,1); //} if (max > 0) { PanelLayout(200, 140, max); } }
private void btn_M添加_Click(object sender, EventArgs e) { try { if (dgv_场景模块.SelectedRows.Count == 0) { MessageBox.Show("请先选择一项场景!"); return; } 场景模块添加界面 frm = new 场景模块添加界面(); if (frm.ShowDialog() == DialogResult.OK) { int index = -1; string name = Convert.ToString(dgv_场景模块.SelectedRows[0].Cells[0].Value); if ((index = 当前场景模块.FindIndex(t => t.场景名称 == name)) == -1) { dgv_调试模块.Rows.Clear(); dgv_开关模块.Rows.Clear(); return; } if (当前场景模块[index].场景调试模块列表 == null) { 当前场景模块[index].场景调试模块列表 = new List <场景调试模块>(); } foreach (var v in frm.模块编号) { if (当前场景模块[index].场景调试模块列表.FindIndex(t => t.模块编号 == v) != -1) { //MessageBox.Show("该地址已存在"); continue; } 场景调试模块 tmp = new 场景调试模块(); tmp.场景开关信息列表 = new List <场景开关信息>(); tmp.模块编号 = v; var v1 = ModelsOperate.GetModel(int.Parse(tmp.模块编号)); 当前场景模块[index].场景调试模块列表.Add(tmp); } ConfigClass.SaveCookie_List(场景设置.当前场景模块, "场景模块.dat"); RefreshForm_场景模块(当前场景模块[index].场景调试模块列表); MessageBox.Show("添加成功"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void RefreshPanel(开关模块 tmp, string modelsType) { ModelsType = modelsType; switchButton.ButtonDisplay(tmp.flag); ModelsNumber = tmp.模块编号; numLable.Text = tmp.开关编号; nameLable.Text = tmp.开关名称; nameLable.Location = new Point((this.Width - nameLable.PreferredWidth) / 2, nameLable.Location.Y); if (ModelsType == "开关模块") { trackBar.Visible = false; numTrackBar.Visible = false; } else { trackBar.Visible = true; numTrackBar.Visible = true; numTrackBar.Text = "亮度:" + tmp.亮度.ToString(); } var tmp1 = ModelsOperate.GetModel(int.Parse(tmp.模块编号)); //if (tmp1.开关路数 == null) // tmp1.开关路数 = "16"; //int channel = int.Parse(tmp1.开关路数); //if (channel < int.Parse(PanleNumber)) // this.Visible = false; //else // this.Visible = true; trackBar.Value = tmp.亮度; if (!switchButton.flag) { pictureBox.Image = Properties.Resources.灯泡关; } else { pictureBox.Image = Properties.Resources.灯泡开; } LightValue = tmp.亮度; Flag = tmp.flag; LightValue = tmp.亮度; }
private void dgv_调试模块_SelectionChanged(object sender, EventArgs e) { if (dgv_调试模块.SelectedRows.Count != 1) { dgv_开关模块.Rows.Clear(); //MessageBox.Show("请先选择产品模块!"); return; } dgv_开关模块.Rows.Clear(); int index = dgv_调试模块.SelectedRows[0].Index; 场景调试模块 tmp = tmp场景子模块.场景调试模块列表2.Find(t => t.模块编号 == Convert.ToString(dgv_调试模块.Rows[index].Cells[0].Value)); if (tmp == null) { MessageBox.Show("该地址模块不存在!"); return; } if (tmp.场景开关信息列表 == null) { tmp.场景开关信息列表 = new List <场景开关信息>(); } while (tmp.场景开关信息列表.Count < 16) { var v = new 场景开关信息(); v.开关通道 = (tmp.场景开关信息列表.Count + 1).ToString(); v.开关状态 = "是"; v.开关亮度 = "0"; tmp.场景开关信息列表.Add(v); } var tmp1 = ModelsOperate.GetModel(int.Parse(tmp.模块编号)); //for (int i = 0; i < tmp1.开关列表.Count; i++) //{ // tmp.场景开关信息列表.Find(t => t.开关通道 == tmp1.开关列表[i].模块编号).开关名称 = tmp1.开关列表[i].开关名称; //} Refresh_dgv_开关模块(tmp.场景开关信息列表, tmp1); }
public void RefreshPanel(string addrNumber, string modlesType, int state, int falut) { //string s = ""; //if (modlesType == "开关模块") // s = "开关型"; //else if (modlesType == "调光模块") // s = "调光型"; //else // s = "未获取"; numLable.Text = addrNumber + ":" + modlesType; numLable.BackColor = Color.Transparent; var v = ModelsOperate.GetModel(int.Parse(addrNumber)); typeLable.Text = v.模块名称; numLable.Location = new Point((this.Width - numLable.PreferredWidth - 13), (17)); typeLable.Location = new Point((this.Width - typeLable.PreferredWidth) / 2, (this.Height - 2 * numLable.Height) / 2 + numLable.Height); if (State != state) { if (state == 0) { drawColor = SystemColors.ControlLight; } else if (state == 2) { drawColor = Color.PaleTurquoise; } else if (state == 3) { drawColor = Color.Khaki; } this.Refresh(); } State = state; FaultState = falut; AddrNumber = addrNumber; ModlesType = modlesType; }
private void timer1_Tick(object sender, EventArgs e) { timer1.Stop(); if ((DateTime.Now - LastInquireDatetime).TotalMilliseconds > 300 && Communication.GetDoCommState() != 1 && UpWriteDic.Count == 0) { if (ModelsOperate.ModelsList.Count > 0) { if (CurreentInquireindex >= ModelsOperate.ModelsList.Count) { CurreentInquireindex = 0; } DOInquire(ModelsOperate.ModelsList[CurreentInquireindex]); CurreentInquireindex++; } //LastInquireDatetime = DateTime.Now; } if (!isRegex) { btn_场景设置.Enabled = false; } else { if (MainForm.UserName == "管理员") { btn_场景设置.Enabled = true; } } DateTime tmpDate = DateTime.Now; 当前时间.Text = tmpDate.ToString("yyyy/MM/dd HH:mm:ss"); if (frm_主模块 != null) { frm_主模块.RefreshForm(Communication.RoutInspecting || Communication.EachRoutInspecting); } if (frm_开关模块界面 != null) { frm_开关模块界面.RefreshForm(Communication.RoutInspecting || Communication.EachRoutInspecting); } if (Communication.GetDoCommState() == 2) { int index = 0; CommState state = Communication.GetCommState(); OperateResult result = Communication.EndDoCommunication(); if (result.IsSuccess == false) { switch (state) { #region "数据处理" case CommState.GetModlesMsg: if ((index = ModelsOperate.ModelsList.FindIndex(t => t.模块编号 == Communication.CurrentAddr.ToString())) != -1) { ModelsOperate.ModelsList[index].State = 3; ModelsOperate.ModelsList[index].FalutState = 3; if (OpenModel) { OpenModel = false; } } frm_主模块.RefreshPanel(); if (frm_开关模块界面 != null) { frm_开关模块界面.RefreshPanel(); } break; case CommState.GetModlesAllMsg: if ((index = ModelsOperate.ModelsList.FindIndex(t => t.模块编号 == Communication.CurrentAddr.ToString())) != -1) { ModelsOperate.ModelsList[index].State = 3; ModelsOperate.ModelsList[index].FalutState = 3; if (OpenModel) { OpenModel = false; } } break; case CommState.SetModles_TK: break; case CommState.SetModles_Reset: //通信状态 = 3; break; #endregion } } else { index = 0; if (result.IsSuccess) { List <byte[]> tmpList = new List <byte[]>(); switch (state) { #region "数据处理" case CommState.GetModlesMsg: 通信状态 = 2; for (int i = 0; i < result.ResultData.Length; i += 13) { if (result.ResultData.Length < i + 13) { continue; } if ((result.ResultData[i] & 0x80) > 0 && result.ResultData[i + 1] == 0 && result.ResultData[i + 2] == 0) { continue; } byte[] b = new byte[13]; Array.Copy(result.ResultData, i, b, 0, 13); tmpList.Add(b); } tmpList = tmpList.OrderBy(t => (t[3] << 8 | t[4])).ToList(); ModelsOperate.RefreshModel(tmpList); frm_主模块.RefreshPanel(); if (frm_开关模块界面 != null) { frm_开关模块界面.RefreshPanel(); } LastInquireDatetime = DateTime.Now; break; case CommState.GetModlesAllMsg: if ((index = ModelsOperate.ModelsList.FindIndex(t => t.模块编号 == Communication.CurrentAddr.ToString())) != -1) { if (OpenModel == true) { frm_开关模块界面 = New_Form <开关模块界面>(frm_开关模块界面); frm_开关模块界面.tmp = ModelsOperate.ModelsList[index]; OpenModel = false; } } for (int i = 0; i < result.ResultData.Length; i += 13) { byte[] b = new byte[13]; Array.Copy(result.ResultData, i, b, 0, 13); tmpList.Add(b); } if (tmpList.Count > 0) { tmpList = tmpList.OrderBy(t => (t[4] << 8 | t[5])).ToList(); } ModelsOperate.RefreshModel(tmpList); if (frm_开关模块界面 != null) { frm_开关模块界面.RefreshPanel(); } break; case CommState.SetModles_TK: break; case CommState.SetModles_Reset: break; #endregion } } } } if ((DateTime.Now - LastReadDatetime).TotalMilliseconds > currentParam.接收速度 && MainForm.CommMaster != null) { LastReadDatetime = DateTime.Now; OperateResult operateResult; byte[] tmp = Communication.CommReadData(out operateResult); if (operateResult.IsSuccess) { List <byte[]> tmpList = new List <byte[]>(); for (int i = 0; i < operateResult.ResultData.Length; i += 13) { if (operateResult.ResultData.Length < i + 13) { continue; } if ((operateResult.ResultData[i] & 0x80) > 0 && operateResult.ResultData[i + 1] == 0 && operateResult.ResultData[i + 2] == 0) { continue; } byte[] b = new byte[13]; Array.Copy(operateResult.ResultData, i, b, 0, 13); tmpList.Add(b); } tmpList = tmpList.OrderBy(t => (t[4] << 8 | t[5])).ToList(); ModelsOperate.RefreshModel(tmpList); if (frm_开关模块界面 != null) { frm_开关模块界面.RefreshPanel(); } } } if ((DateTime.Now - LastWriteDatetime).TotalMilliseconds > currentParam.发送速度 && (MainForm.WriteDic.Count() > 0 || MainForm.UpWriteDic.Count() > 0) && Communication.GetDoCommState() != 1 && !Communication.RoutInspecting && !Communication.EachRoutInspecting) { LastWriteDatetime = DateTime.Now; ModlesMsg v; if (MainForm.UpWriteDic.Count > 0) { MainForm.UpWriteDic.TryRemove(MainForm.UpWriteDic.ElementAt(0).Key, out v); } else { MainForm.WriteDic.TryRemove(MainForm.WriteDic.ElementAt(0).Key, out v); } if (v.模块类型 == "模块查询") { v.Function = CommState.GetModlesMsg; Communication.BeginDoCommunication(v); } else if (v.模块类型 == "信息查询") { v.Function = CommState.GetModlesAllMsg; Communication.BeginDoCommunication(v); } else { switch (v.action) { case ActionState.脱扣: v.Function = CommState.SetModles_TK; Communication.BeginDoCommunication(v); break; case ActionState.位: v.Function = CommState.SetModles_Reset; Communication.BeginDoCommunication(v); break; } } } timer1.Start(); label2.Text = (DateTime.Now - tmpDate).TotalMilliseconds.ToString(); InitMsg(); }
private void 模块管理界面_Load(object sender, EventArgs e) { tip_Lable.Text = ""; ModelsOperate.Display(dataGridView1); }
public static void FroeachScene() { DateTime dt1 = DateTime.Now; DateTime dt2 = DateTime.Now; bool bSure = false; DateTime currentDt = DateTime.Now; if (lastCheckDatetime >= currentDt) { lastCheckDatetime = currentDt; return; } try { dt1 = 计算日出日落.计算日出时间(MainForm.currentParam.经度, MainForm.currentParam.维度, DateTime.Now); dt2 = 计算日出日落.计算日落时间(MainForm.currentParam.经度, MainForm.currentParam.维度, DateTime.Now); MainForm.日出日落时间 = string.Format("日出:{0} 日落:{1}", dt1.ToString("HH:mm:ss"), dt2.ToString("HH:mm:ss")); MainForm.日出时间 = dt1.ToString("HH:mm:ss"); MainForm.日落时间 = dt2.ToString("HH:mm:ss"); bSure = true; } catch (Exception ex) { bSure = false; } //for (int i = 0; i < ModelsOperate.ModelsList.Count; i++) //{ //var v = ModelsOperate.ModelsList[i]; //} var tmp = 场景设置.当前场景模块.Where((t, b) => { if (t.启用标志) { return(true); } else { return(false); } }).ToList(); foreach (var v1 in tmp) { if (tmp.FindIndex(t => t.模式 == SceneModel.国家公休日) != -1) { string currentd = DateTime.Now.ToString("yyyyMMdd"); if (MainForm.国家公休日列表.FindIndex(t => t.日期 == currentd) != -1) { if (v1.模式 == SceneModel.工作日模式) { continue; } } else { if (v1.模式 == SceneModel.国家公休日) { continue; } if (DateTime.Now.DayOfWeek == DayOfWeek.Monday && ((v1.星期数据 >> 0) & 0x01) == 1 || DateTime.Now.DayOfWeek == DayOfWeek.Tuesday && ((v1.星期数据 >> 1) & 0x01) == 1 || DateTime.Now.DayOfWeek == DayOfWeek.Wednesday && ((v1.星期数据 >> 2) & 0x01) == 1 || DateTime.Now.DayOfWeek == DayOfWeek.Thursday && ((v1.星期数据 >> 3) & 0x01) == 1 || DateTime.Now.DayOfWeek == DayOfWeek.Friday && ((v1.星期数据 >> 4) & 0x01) == 1 || DateTime.Now.DayOfWeek == DayOfWeek.Saturday && ((v1.星期数据 >> 5) & 0x01) == 1 || DateTime.Now.DayOfWeek == DayOfWeek.Sunday && ((v1.星期数据 >> 6) & 0x01) == 1) { } else { continue; } } } else { if (DateTime.Now.DayOfWeek == DayOfWeek.Monday && ((v1.星期数据 >> 0) & 0x01) == 1 || DateTime.Now.DayOfWeek == DayOfWeek.Tuesday && ((v1.星期数据 >> 1) & 0x01) == 1 || DateTime.Now.DayOfWeek == DayOfWeek.Wednesday && ((v1.星期数据 >> 2) & 0x01) == 1 || DateTime.Now.DayOfWeek == DayOfWeek.Thursday && ((v1.星期数据 >> 3) & 0x01) == 1 || DateTime.Now.DayOfWeek == DayOfWeek.Friday && ((v1.星期数据 >> 4) & 0x01) == 1 || DateTime.Now.DayOfWeek == DayOfWeek.Saturday && ((v1.星期数据 >> 5) & 0x01) == 1 || DateTime.Now.DayOfWeek == DayOfWeek.Sunday && ((v1.星期数据 >> 6) & 0x01) == 1) { } else { continue; } } if (DateTime.Now.Date >= v1.开始时间.Date && v1.结束时间.Date >= DateTime.Now.Date) { foreach (var v2 in v1.场景子名称列表) { if (v2.定时方式 != SetTimeType.普通定时 && !bSure) { continue; } DateTime dt3; if (v2.定时方式 == SetTimeType.普通定时) { dt3 = v2.动作时间; } else if (v2.定时方式 == SetTimeType.日出时间) { dt3 = dt1; } else { dt3 = dt2; } var Msg1 = 获取场景模块信息(v2); if (lastCheckDatetime.TimeOfDay < dt3.TimeOfDay && dt3.TimeOfDay <= DateTime.Now.TimeOfDay) { var Msg = 获取场景模块信息(v2); if (Msg != null) { foreach (var tmpMsg in Msg) { List <ushort> tmpl = new List <ushort>(); foreach (var ii in tmpMsg.channel) { tmpl.Add((ushort)ii); } var tmpModel = ModelsOperate.GetModel(int.Parse(tmpMsg.addr)); if (tmpModel == null) { continue; } if (tmpModel.模块类型 == "开关模块") { ModlesMsg modlesMsg = new ModlesMsg() { addr = int.Parse(tmpMsg.addr), //action = v2.动作 ? ActionState.Open : ActionState.Close, bitArray = tmpl.ToArray(), valueArray = tmpMsg.value, 模块类型 = tmpModel.模块类型, bit = 0xf1 }; MainForm.WriteDic.AddOrUpdate(tmpMsg.addr + "," + "场景", modlesMsg, (key, value) => value); } else if (tmpModel.模块类型 == "调光模块") { ModlesMsg modlesMsg = new ModlesMsg() { addr = int.Parse(tmpMsg.addr), //action = v2.动作 ? ActionState.Open : ActionState.Close, bitArray = tmpl.ToArray(), valueArray = tmpMsg.value, 模块类型 = tmpModel.模块类型, bit = 0xf1 }; MainForm.WriteDic.AddOrUpdate(tmpMsg.addr + "," + "场景_1", modlesMsg, (key, value) => value); ModlesMsg modlesMsg1 = new ModlesMsg() { addr = int.Parse(tmpMsg.addr), //action = v2.动作 ? ActionState.Open : ActionState.Close, bitArray = tmpl.ToArray(), valueArray = tmpMsg.value, 模块类型 = tmpModel.模块类型, bit = 0xf2 }; MainForm.WriteDic.AddOrUpdate(tmpMsg.addr + "," + "场景_2", modlesMsg1, (key, value) => value); } } } } } } } lastCheckDatetime = currentDt; }