예제 #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();
        }
예제 #2
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Confirm delete?", "Delete", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            // 删除控制器
            Button powerBtn  = (Button)sender;
            int    groupId   = 0;
            int    addressId = 0;

            HelperTool.GetControllerAddressId(powerBtn.Tag.ToString(), out groupId, out addressId);
            controllerItems.RemoveAll(c => c.GroupId == groupId && c.AddressId == addressId);

            HelperTool.WriteControllersToFile <ControllerItem>(controllerItems.ToArray());

            ReLoadControllerItems();
        }