Ejemplo n.º 1
0
        /// <summary>
        /// 删除控制器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteControllerButton_Click(object sender, EventArgs e)
        {
            var controllerItems = HelperTool.ReadControllersFromFile <ControllerItem>().ToList();

            if (currentControllerItem == null)
            {
                return;
            }

            if (controllerItems == null || controllerItems.Count <= 0)
            {
                MessageBox.Show("没有可以删除的项!");
                return;
            }

            if (MessageBox.Show("确认删除?", "确认删除项?", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            List <ControllerItem> items = new List <ControllerItem>();

            foreach (var item in controllerItems)
            {
                if (item.GroupId != currentControllerItem.GroupId || item.AddressId != currentControllerItem.AddressId)
                {
                    items.Add(item);
                }
            }

            HelperTool.WriteControllersToFile <ControllerItem>(items.ToArray());
            LoadControllerItems();
        }
Ejemplo n.º 2
0
        private void ReLoadControllerItems()
        {
            controllerItems.Clear();
            // 读取控制器列表
            controllerItems.AddRange(HelperTool.ReadControllersFromFile <ControllerItem>().OrderBy(m => m.GroupId));

            // 创建控制器列表
            LoadControllerItems(controllerItems.ToArray(), currentPageIndex * pageControllerNum);
        }
Ejemplo n.º 3
0
        private void LoadControllerItems()
        {
            var items = HelperTool.ReadControllersFromFile <ControllerItem>();

            if (items != null)
            {
                controllersDataGridView.DataSource = items;
            }

            controllersDataGridView.Columns["GroupName"].Visible = false;

            if (items.Count() > 0)
            {
                currentControllerItem = items[0];
            }
        }
Ejemplo n.º 4
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            AddControllerFrom addControllerFrom = new AddControllerFrom();

            addControllerFrom.PassGroupAddressId = (int groupId, int addressId, string name, string zone) =>
            {
                ControllerItem controllerItem = new ControllerItem()
                {
                    Name      = name,
                    Zone      = zone,
                    GroupId   = groupId,
                    AddressId = addressId
                };

                var items = HelperTool.ReadControllersFromFile <ControllerItem>().ToList();

                foreach (var item in items)
                {
                    if (item.GroupId == groupId && item.AddressId == addressId)
                    {
                        MessageBox.Show("已经添加,不能重复添加!");
                        return(false);
                    }
                }

                items.Add(controllerItem);

                Stream          stream          = File.Open("controllers.dat", FileMode.Open);
                BinaryFormatter binaryFormatter = new BinaryFormatter();

                binaryFormatter.Serialize(stream, items.ToArray());

                stream.Close();

                currentPageIndex = 0;
                controllerItems.Add(controllerItem);
                LoadControllerItems(controllerItems.ToArray(), 0);

                return(true);
            };

            addControllerFrom.StartPosition = FormStartPosition.CenterParent;
            addControllerFrom.ShowDialog();
        }
Ejemplo n.º 5
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            Button saveBtn = (Button)sender;

            saveBtn.Visible = false;

            channelGroupBox.Visible = false;

            // 设置修改时间
            timePointLabel.Visible         = false;
            timPointDateTimePicker.Visible = false;

            var items = HelperTool.ReadControllersFromFile <ControllerItem>().ToList();

            foreach (var item in items)
            {
                if (item.GroupId == currentControllerItem.GroupId)
                {
                    item.Zone = zoneTextBox.Text;
                    if (item.AddressId == currentControllerItem.AddressId)
                    {
                        item.Name = nameTextBox.Text;
                    }
                }
            }

            Stream          stream          = File.Open("controllers.dat", FileMode.Open);
            BinaryFormatter binaryFormatter = new BinaryFormatter();

            binaryFormatter.Serialize(stream, items.ToArray());

            stream.Close();

            // 发送命令
            if (enableCheckBox.Checked)
            {
                SendSettingToDevice(currentControllerItem);
            }

            saveSetting?.Invoke();
        }
Ejemplo n.º 6
0
        public SettingControllerForm(SerialPort serialPort, ControllerItem controllerItem, ControllerItem[] controllerItems)
        {
            InitializeComponent();

            refreshSettingDisplay = RefreshSettingDisplay;

            this.serialPort            = serialPort;
            this.currentControllerItem = controllerItem;
            this.controllerItems       = controllerItems;

            this.trackBars = new TrackBar[] { trackBar1, trackBar2, trackBar3, trackBar4, trackBar5 };
            this.labels    = new Label[] { label8, label9, label10, label11, label12 };

            // 控制器列表
            foreach (var item in HelperTool.ReadControllersFromFile <ControllerItem>().OrderBy(m => m.GroupId))
            {
                comboBox1.Items.Add(item.GroupId + "," + item.AddressId);
            }

            comboBox1.Text = currentControllerItem.GroupId + "," + currentControllerItem.AddressId;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 选择控制器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void controllersDataGridView_CurrentCellChanged(object sender, EventArgs e)
        {
            DataGridView dataGridView = (DataGridView)sender;
            var          items        = HelperTool.ReadControllersFromFile <ControllerItem>();

            if (items == null || items.Count() == 0)
            {
                return;
            }

            if (dataGridView.CurrentRow == null)
            {
                return;
            }

            Console.WriteLine("选择了第 {0} 行!", dataGridView.CurrentRow.Index);
            currentControllerItem = items[dataGridView.CurrentRow.Index];

            // 读取当前设备的设置
            ReadCurrentControllerAllData(currentControllerItem);
        }