private void btnCloseDeviceList_Click(object sender, EventArgs e)
        {
            bool IsDirtyOrEmptyPath = (DeviceDataManager.IsDirty || string.IsNullOrEmpty(DeviceDataManager.DeviceListFilePath));

            if (IsDirtyOrEmptyPath)

            {
                var dlgResult = MessageBox.Show("Do you want to save the content?", "Want to Save", buttons: MessageBoxButtons.YesNoCancel);
                if (dlgResult == DialogResult.Yes)
                {
                    DeviceDataManager.SaveDataToCSV();
                    ClearDeviceList();
                }
                else if (dlgResult == DialogResult.No)
                {
                    ClearDeviceList();
                }
                else if (dlgResult == DialogResult.Cancel)
                {
                    // Dont do anything, Cancelling Out...........
                }
            }
            else if (!IsDirtyOrEmptyPath)
            {
                var dlgResult = MessageBox.Show("Do you want to proceed? It will clear the current list.", "Want to Proceed", buttons: MessageBoxButtons.YesNo);
                if (dlgResult == DialogResult.Yes)
                {
                    ClearDeviceList();
                }
                else if (dlgResult == DialogResult.No)
                {
                    // Dont do anything, Cancelling Out...........
                }
            }
        }
 private void ClearDeviceList()
 {
     pnlDeviceList.Controls.Clear();
     DeviceDataManager.DeviceDataUI.Clear();
     DeviceDataManager.ResetDirtyFlag();
     this.Invalidate();
 }
        public void DeleteDeviceFromList(object sender, EventArgs e)
        {
            int SerialNumber = ((DeviceData)((Control)sender).Parent).deviceDataModel.SerialNumber;

            DeviceDataManager.DeleteDeviceData(SerialNumber);
            UpdateDeviceListUI();
        }
        private void OpenDeviceListFile()
        {
            string filePath = String.Empty;
            // List<DeviceDataModel> deviceDataList = new List<DeviceDataModel>();
            List <DeviceData> dataUI   = new List <DeviceData>();
            OpenFileDialog    OFDialog = new OpenFileDialog();

            DialogResult result = OFDialog.ShowDialog(); // Show the dialog.

            OFDialog.DefaultExt = BellConstants.BellCSVExtention;
            if (result == DialogResult.OK) // Test result.
            {
                filePath = OFDialog.FileName;
                DeviceDataManager.DeviceListFilePath = filePath;
                DeviceDataManager.LoadData();
            }
            dataUI = DeviceDataManager.DeviceDataUI;
            pnlDeviceList.Controls.Clear();
            for (int i = 0; i < dataUI.Count; i++)
            {
                DeviceData      TempDataUi = dataUI[i];
                DeviceDataModel DDM        = new DeviceDataModel();
                DDM = TempDataUi.deviceDataModel;
                DDM.SerialNumber                          = i + 1;
                TempDataUi.deviceDataModel                = DDM;
                TempDataUi.Location                       = new Point(0, (i * 33));
                TempDataUi.Controls["btnDelete"].Click   += DeleteDeviceFromList;
                TempDataUi.Controls["chkDownload"].Click += SelectDownloadFromList;
                TempDataUi.MakeDirty                     += DeviceDataManager.ActionMakeDirty;

                pnlDeviceList.Controls.Add(TempDataUi);
            }
        }
        public void SelectDownloadFromList(object sender, EventArgs e)
        {
            int SerialNumber = ((DeviceData)((Control)sender).Parent).deviceDataModel.SerialNumber;

            if (((CheckBox)((Control)sender)).Checked)
            {
                DeviceDataManager.SelectDownloadDevice(SerialNumber);
            }
        }
        private void btnOpenDeviceList_Click(object sender, EventArgs e)
        {
            if (DeviceDataManager.IsDirty)
            {
                var dlgResult = MessageBox.Show("Do you want to save the content?", "Want to Save", MessageBoxButtons.YesNoCancel);

                if (dlgResult == DialogResult.Yes)
                {
                    DeviceDataManager.SaveDataToCSV();
                    OpenDeviceListFile();
                }
                else if (dlgResult == DialogResult.No)
                {
                    OpenDeviceListFile();
                }
                else if (dlgResult == DialogResult.Cancel)
                {
                    // Do nothing, Cancelling out the Open file
                }
            }
            else if (!DeviceDataManager.IsDirty)
            {
                //var dlgResult = MessageBox.Show("Do you want to proceed? It will clear the current list.", "Want to Proceed", buttons: MessageBoxButtons.YesNo);
                //if (dlgResult == DialogResult.Yes)
                //{
                //    ClearDeviceList();
                //}
                //else if (dlgResult == DialogResult.No)
                //{
                //    // Dont do anything, Cancelling Out...........
                //}   // Not required As of now......

                OpenDeviceListFile();
            }

            // OpenDeviceListFile();
        }
 private void btnSaveAsDeviceList_Click(object sender, EventArgs e)
 {
     DeviceDataManager.SaveDataToCSV(SaveAs: true);
 }
 private void btnAddDevice_Click(object sender, EventArgs e)
 {
     pnlDeviceList.Controls.Add(DeviceDataManager.AddEmptyDeviceData(DeleteDeviceFromList, SelectDownloadFromList));
 }