Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
 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);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
        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);
        }