public static void LoadDeviceList()
 {
     string data;
     if (!File.Exists("config/device_list.dat"))
     {
         _NullDevice = new Device()
         {
             ID = -3,
             Name = null,
             BlockList = new List<long>()
         };
         DeviceList = new List<Device>();
         data = SaveDeviceList();
     }
     else
     {
         data = File.ReadAllText("config/device_list.dat");
     }
     DeviceList = (List<Device>)G.DeserializeBase64(data);
     DeviceList.Sort((dev1, dev2) => (dev1.ID.CompareTo(dev2.ID)));
     _NullDevice = DeviceList[0];
     DeviceList.RemoveAt(0);
 }
Esempio n. 2
0
        private void RadialDevice_ItemClick(object sender, EventArgs e)
        {
            if (((BaseItem)sender).Tag != null)
            {
                RadialAction action = (RadialAction)((BaseItem)sender).Tag;
                GridPanel panel = gridDevice.PrimaryGrid;
                SelectedElementCollection selectedRows = gridDevice.GetSelectedRows();
                if (selectedRows.Count != 0)
                {
                    int rowIndex = ((GridRow)selectedRows[0]).RowIndex;
                    if (action == RadialAction.Delete)
                    {
                        string act = isAddingRow ? "HỦY</font> thiết bị vừa tạo" : "XÓA</font> thiết bị";
                        if (MessageBoxEx.Show(this, "<font size='18'><b>Bạn có thật sự muốn <font color='#B02B2C'>" + act + " ?</b></font>",
                            "<font size='15'><b>Xác nhận</b></font>", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            if (isAddingRow && rowIndex == (panel.Rows.Count - 1))
                            {
                                isAddingRow = false;
                                gridDevice.PrimaryGrid.ShowInsertRow = false;
                                gridDevice.PrimaryGrid.ShowInsertRow = true;
                            }
                            else
                            {
                                int ID = (int)((GridRow)panel.Rows[rowIndex]).Cells[0].Value;
                                DeviceManager.getByID(ID).IsDeleted = true;
                            }
                            panel.Rows.RemoveAt(rowIndex);
                            gridBlockInit();
                        }
                    }
                    else if (action == RadialAction.Accept)
                    {
                        GridRow row = (GridRow)panel.Rows[rowIndex];
                        if (isAddingRow && rowIndex == (panel.Rows.Count - 1))
                        {
                            Device dev = new Device()
                            {
                                ID = DeviceManager.GetNewId(),
                                ImageKey = (string)row.Cells[1].Value,
                                Name = (string)row.Cells[2].Value,
                                IsDeleted = false,
                                BlockList = new List<long>()
                            };
                            row.Cells[0].Value = dev.ID;
                            DeviceManager.DeviceList.Add(dev);
                            DeviceManager.SaveDeviceList();

                            isAddingRow = false;
                            gridDevice.PrimaryGrid.ShowInsertRow = true;
                        }
                        else
                        {
                            int ID = (int)row.Cells[0].Value;
                            Device dev = DeviceManager.getByID(ID);
                            dev.ImageKey = (string)row.Cells[1].Value;
                            dev.Name = (string)row.Cells[2].Value;
                            DeviceManager.SaveDeviceList();
                        }
                        row.RowDirty = false;
                        gridBlockInit();
                    }
                    cbDeviceHisStatisCompareInit();
                }
            }
        }