Exemple #1
0
        //将choSensorListBox内的传感器添加到分组的传感器表中
        public bool AddSensorToGroup(int groupId)
        {
            bool ret = false;

            string[] sensorGroup = new string[choSensorListBox.Items.Count];//通道号在sensorGroup[1],模块号在sensorGroup[3]

            for (int i = 0; i < choSensorListBox.Items.Count; i++)
            {
                sensorGroup[i] = choSensorListBox.Items[i].ToString();
            }
            for (int i = 0; i < sensorGroup.Count(); i++)
            {
                string[] sensorInfo = sensorGroup[i].Split(new char[2] {
                    ':', ' '
                });
                string channelId = sensorInfo[3];
                string moudleId  = sensorInfo[1];

                foreach (MoChaSenId v in moChaSenIdsList)
                {
                    if (v.ChannelId == channelId && v.MoudleId == moudleId)
                    {
                        GroupSensors groupSensor = new GroupSensors()
                        {
                            GroupID  = groupId,
                            SensorID = Convert.ToInt32(v.SensorId),
                        };
                        ret = GroupSensorInfoDic.GetGroupInfosDic().Add(groupSensor);
                    }
                }
            }
            return(ret);
        }
Exemple #2
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();
        }
Exemple #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);
        }
Exemple #4
0
 public void InitlizeDic()
 {
     groupInfoDic      = GroupInfosDic.GetGroupInfoDic().GetDic();
     groupSensorsesDic = GroupSensorInfoDic.GetGroupInfosDic().GetDic();
 }