private void addGroupButton_Click(object sender, EventArgs e) { string orgin = "填写或选择分组"; bool divCal = false; int DBNameID = 0; if (filOrChoGroupComboBox.Text != orgin) { if (!filOrChoGroupComboBox.Items.Contains(filOrChoGroupComboBox.Text) && filOrChoGroupComboBox.Text != "") { using (DbConnection conn = new DbConnection()) { DataBaseNameDic.GetDataBaseNameDic(); List <DataBaseName> dataBaseNameList = DataBaseNameDic.GetDataBaseNameDic().GetAllBaseNames(); for (int i = 0; i < dataBaseNameList.Count; i++) { if (DBLocation == dataBaseNameList[i].Location) { DBNameID = Convert.ToInt32(dataBaseNameList[i].ID); } } int safetypeid = -1; foreach (IDandName idandName in IdName) { if (idandName.Name == safeTypeComboBox.Text) { safetypeid = idandName.ID; } } if (divCalCheckBox.Checked) { divCal = true; } GroupInfo group = new GroupInfo() { GroupName = filOrChoGroupComboBox.Text, DataBaseID = DBNameID, Safetyfactortypeid = safetypeid, CombinationCalculate = divCal }; int groupId = GroupInfosDic.GetGroupInfoDic().CheckAdd(group); if (AddSensorToGroup(groupId)) { MessageBox.Show("添加成功"); } } } } InitlizeFilOrChoGroupComboBox(); }
private void btnRemoveGroup_Click(object sender, EventArgs e) { if (filOrChoGroupComboBox.Text != "") { int groupId = 0; using (DbConnection conn = new DbConnection()) { List <GroupInfo> groupList = GroupInfosDic.GetGroupInfosDic().GetDic().Values.ToList(); for (int i = 0; i < groupList.Count; i++) { if (filOrChoGroupComboBox.Text == groupList[i].GroupName) { groupId = Convert.ToInt32(groupList[i].GroupID); if (GroupInfosDic.GetGroupInfoDic().Delete(Convert.ToInt32(groupList[i].GroupID))) { MessageBox.Show(@"组删除成功"); } break; } if (i == groupList.Count) { MessageBox.Show(@"组不存在"); } } if (groupList.Count == 0) { MessageBox.Show(@"还未添加组"); } } //组删除的同时删除掉组中的传感器 List <GroupSensors> sensorsList = GroupSensorInfoDic.GetGroupInfosDic().GetDic().Values.ToList(); bool ret = false; foreach (GroupSensors sensors in sensorsList) { if (sensors.GroupID == groupId) { ret = GroupSensorInfoDic.GetGroupInfosDic().Delete(Convert.ToInt32(sensors.ID)); } } if (ret) { MessageBox.Show(@"传感器删除成功"); } } else { MessageBox.Show(@"请选择组名"); } InitlizeFilOrChoGroupComboBox(); }
public void InitlizeFilOrChoGroupComboBox() { filOrChoList.Clear(); using (DbConnection conn = new DbConnection()) { List <GroupInfo> list = GroupInfosDic.GetGroupInfoDic().GetAllGroups(); for (int i = 0; i < list.Count; i++) { filOrChoList.Add(list[i].GroupName); } } filOrChoSorSource.DataSource = filOrChoList; filOrChoGroupComboBox.DataSource = filOrChoSorSource; filOrChoSorSource.ResetBindings(true); filOrChoGroupComboBox.SelectedIndex = -1; }
private void divCalCheckBox_CheckedChanged(object sender, EventArgs e) { if (divCalCheckBox.Checked) { using (DbConnection conn = new DbConnection()) { List <GroupInfo> groupList = GroupInfosDic.GetGroupInfosDic().GetDic().Values.ToList(); for (int i = 0; i < groupList.Count; i++) { if (filOrChoGroupComboBox.Text == groupList[i].GroupName && groupList[i].CombinationCalculate == false) { GroupInfo group = groupList[i]; group.CombinationCalculate = true; GroupInfosDic.GetGroupInfosDic().UpdateSensorGroupInfo(group); } } } } else { using (DbConnection conn = new DbConnection()) { List <GroupInfo> groupList = GroupInfosDic.GetGroupInfosDic().GetDic().Values.ToList(); for (int i = 0; i < groupList.Count; i++) { if (filOrChoGroupComboBox.Text == groupList[i].GroupName && groupList[i].CombinationCalculate == true) { GroupInfo group = groupList[i]; group.CombinationCalculate = false; GroupInfosDic.GetGroupInfosDic().UpdateSensorGroupInfo(group); } } } } }
private void filOrChoGroupComboBox_TextChanged(object sender, EventArgs e) { if (filOrChoGroupComboBox.Text != "" && filOrChoGroupComboBox.Text != "\r" && choSensorListBox.Items.Count > 0) { addGroupButton.Enabled = true; if (EnableAddButton && sensorListBox.Items.Count != 0) { addButton.Enabled = true; } //查找组名是否存在 int groupId = 0; List <GroupInfo> groupList = GroupInfosDic.GetGroupInfosDic().GetAllGroups(); //根据组的名字找到组的ID for (int i = 0; i < groupList.Count; i++) { if (filOrChoGroupComboBox.Text == groupList[i].GroupName) { groupId = Convert.ToInt32(groupList[i].GroupID); break; } } List <GroupSensors> groupSensorList = GroupSensorInfoDic.GetGroupInfosDic().GetDic().Values.ToList(); //根据组的ID,找到组中的传感器的Id int sensorId = 0; choSensorList.Clear(); for (int i = 0; i < groupSensorList.Count; i++) { if (groupId == groupSensorList[i].GroupID) { sensorId = groupSensorList[i].SensorID; for (int j = 0; j < sensorInfoList.Count; j++) { if (sensorInfoList[j].SensorId == sensorId.ToString()) { choSensorList.Add("模块号:" + sensorInfoList[j].MoudleId + " 通道号:" + sensorInfoList[j].ChannelId); break; } } } } choSensoSource.ResetBindings(true); } else { addGroupButton.Enabled = false; } //当Text发生变化时,可以根据用户的输入产看组名是否存在,并显示组中传感器 choSensorList.Clear(); InitlizeDic(); string groupName = filOrChoGroupComboBox.Text; int sensorId1 = 0; foreach (KeyValuePair <int, GroupInfo> pair in groupInfoDic) { if (pair.Value.GroupName == groupName) { foreach (KeyValuePair <int, GroupSensors> valuePair in groupSensorsesDic) { if (pair.Value.GroupID == valuePair.Value.GroupID) { sensorId1 = valuePair.Value.SensorID; for (int i = 0; i < sensorInfoList.Count; i++) { if (sensorId1.ToString() == sensorInfoList[i].SensorId) { choSensorList.Add("模块号:" + sensorInfoList[i].MoudleId + " 通道号:" + sensorInfoList[i].ChannelId); } } } } } } choSensoSource.ResetBindings(true); }
public void InitlizeDic() { groupInfoDic = GroupInfosDic.GetGroupInfoDic().GetDic(); groupSensorsesDic = GroupSensorInfoDic.GetGroupInfosDic().GetDic(); }