/// <summary>
        /// Wypełnia otwarty w danym momencie ListView i dopisuje go do tablicy IDataBase.
        /// </summary>
        public static void ComplementListView(ConfigManagementForm MainForm)
        {
            switch (ConfigManagementForm.selectedTab)
            {
                case Tables.Collectors:
                    ConfigManagementForm.dataBase[(int)Tables.Collectors] = new Collectors();
                    ListViewConfig.ListViewRefresh(ConfigManagementForm.listView[(int)Tables.Collectors], ConfigManagementForm.dataBase[(int)Tables.Collectors].itemList);
                    break;

                case Tables.Customers:
                    ConfigManagementForm.dataBase[(int)Tables.Customers] = new Customers();
                    ListViewConfig.ListViewRefresh(ConfigManagementForm.listView[(int)Tables.Customers], ConfigManagementForm.dataBase[(int)Tables.Customers].itemList);
                    break;

                case Tables.Areas:
                    ConfigManagementForm.dataBase[(int)Tables.Areas] = new Areas();
                    ListViewConfig.ListViewRefresh(ConfigManagementForm.listView[(int)Tables.Areas], ConfigManagementForm.dataBase[(int)Tables.Areas].itemList);
                    break;

                case Tables.Counters:
                    ConfigManagementForm.dataBase[(int)Tables.Counters] = new Counters();
                    ListViewConfig.ListViewRefresh(ConfigManagementForm.listView[(int)Tables.Counters], ConfigManagementForm.dataBase[(int)Tables.Counters].itemList);
                    break;

                case Tables.Addresses:
                   ConfigManagementForm.dataBase[(int)Tables.Addresses] = new Addresses();
                   ListViewConfig.ListViewRefresh(ConfigManagementForm.listView[(int)Tables.Addresses], ConfigManagementForm.dataBase[(int)Tables.Addresses].itemList);
                   break;

                default:
                    break;
            }
        }
示例#2
0
文件: ModifyForm.cs 项目: nacss/main
        /// <summary>
        /// Umieszcza kontrolki na formularzu i inicjalizuje je oraz wybiera dla nich metody walidujące.
        /// </summary>
        /// <param name="ids">Identyfikatory rekordów zaznaczonych w momencie tworzenia formularza.</param>
        /// <param name="selectedTab">Karta, z której otwarto formularz.</param>
        public ModifyForm(List<string> ids, Tables Table, ConfigManagementForm configManagementForm)
        {
            InitializeComponent();
            mainForm = configManagementForm;
            dataBase = new CollectorsManagementSystemEntities();
            ErrorProvider ep;
            int i;

            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Text = "Modyfikacja rekordu";
            this.ids = ids;
            this.Table = Table;

            switch (Table)
            {
                case Tables.Collectors:
                    labelsTexts = new string[] { "Id inkasenta: ", "Imię: ", "Nazwisko: ", "Kod pocztowy: ", "Miasto: ", "Ulica: ", "Telefon kontaktowy: " };
                    textBoxesNames = new string[] { "CollectorId", "Name", "LastName", "PostalCode", "City", "Address", "PhoneNumber" };
                    Collector modifiedCollector = dataBase.Collectors.SqlQuery("SELECT * FROM Collector WHERE CollectorId={0}", ids.ElementAt(0)).SingleOrDefault();
                    textBoxesTexts = new string[] { modifiedCollector.CollectorId, modifiedCollector.Name, modifiedCollector.LastName, Regex.Replace(modifiedCollector.PostalCode, "([0-9]{2})([0-9]{3})", "${1}-${2}"), modifiedCollector.City, modifiedCollector.Address, modifiedCollector.PhoneNumber };
                    break;
                case Tables.Customers:
                    labelsTexts = new string[] { "Id klienta: ", "Imię: ", "Nazwisko: ", "Kod pocztowy: ", "Miasto: ", "Ulica: ", "Telefon kontaktowy: " };
                    textBoxesNames = new string[] { "CustomerId", "Name", "LastName", "PostalCode", "City", "Address", "PhoneNumber" };
                    Customer modifiedCustomer = dataBase.Customers.SqlQuery("SELECT * FROM Customer WHERE CustomerId={0}", ids.ElementAt(0)).SingleOrDefault();
                    textBoxesTexts = new string[] { modifiedCustomer.CustomerId, modifiedCustomer.Name, modifiedCustomer.LastName, Regex.Replace(modifiedCustomer.PostalCode, "([0-9]{2})([0-9]{3})", "${1}-${2}"), modifiedCustomer.City, modifiedCustomer.Address, modifiedCustomer.PhoneNumber };
                    break;
                case Tables.Areas:
                    labelsTexts = new string[] { "Id terenu: ", "Ulica: ", "Id inkasenta: " };
                    textBoxesNames = new string[] { "AreaId", "Street"};
                    Area modifiedArea = dataBase.Areas.SqlQuery("SELECT * FROM Area WHERE AreaId={0}", ids.ElementAt(0)).SingleOrDefault();
                    textBoxesTexts = new string[] { modifiedArea.AreaId.ToString(), modifiedArea.Street};

                    comboBoxesNames = new string[] { "cbCollector" };
                    comboBoxesKeys = new string[] { modifiedArea.CollectorId };
                    TableNames = new string[] {"Collector"};
                    break;
                case Tables.Counters:
                    labelsTexts = new string[] { "Numer licznika: ", "Numer układu: ", "Id adresu: ", "Id klienta: " };
                    textBoxesNames = new string[] { "CounterNo", "CircuitNo" };
                    Counter modifiedCounter = dataBase.Counters.SqlQuery("SELECT * FROM Counter WHERE CounterNo={0}", ids.ElementAt(0)).SingleOrDefault();
                    textBoxesTexts = new string[] { modifiedCounter.CounterNo.ToString(), modifiedCounter.CircuitNo.ToString() };

                    comboBoxesNames = new string[] { "cbAddress", "cbCustomer" };
                    comboBoxesKeys = new string[] { modifiedCounter.AddressId.ToString(), modifiedCounter.CustomerId };
                    TableNames = new string[] {"Address", "Customer"};

                    break;
                case Tables.Addresses:
                    labelsTexts = new string[] { "Id adresu: ", "Numer domu: ", "Numer mieszkania: ", "Id terenu: " };
                    textBoxesNames = new string[] { "AddressId", "HouseNo", "FlatNo" };
                    Address modifiedAddress = dataBase.Addresses.SqlQuery("SELECT * FROM Address WHERE AddressId={0}", ids.ElementAt(0)).SingleOrDefault();
                    textBoxesTexts = new string[] { modifiedAddress.AddressId.ToString(), modifiedAddress.HouseNo.ToString(), modifiedAddress.FlatNo.ToString()};

                    comboBoxesNames = new string[] { "cbArea" };
                    comboBoxesKeys = new string[] { modifiedAddress.AreaId.ToString() };
                    TableNames = new string[] {"Area"};

                    break;
                default:
                    break;
            }

            NameToMethod_Dict = Auxiliary.Modify_CreateNameToMethodDict();
            Label[] labels = InitializeLabels();
            TextBox[] textBoxes = InitializeTextAndCBConfigs();
            ControlToEP_Dict = new Dictionary<Control, ErrorProvider>();
            ControlToBool_Dict = new Dictionary<Control, bool>();

            for (i = 0; i < textBoxesNames.Length; i++) //inicjowanie labeli które opisują textboxy
            {
                this.Controls.Add(labels[i]);
                this.Controls.Add(textBoxes[i]);
                if (i != 0)
                {
                    ep = Auxiliary.InitializeErrorProvider(textBoxes[i]);
                    ControlToEP_Dict.Add(textBoxes[i], ep);
                    ControlToBool_Dict.Add(textBoxes[i], true);
                    textBoxes[i].Validating += Validation;
                }
            }

            if (comboBoxesNames!=null)
                for (int j = 0; j < comboBoxesNames.Length; j++)
                {
                    this.Controls.Add(labels[i + j]);
                    this.Controls.Add(CBConfigs[j].comboBox);
                    ep = Auxiliary.InitializeErrorProvider(CBConfigs[j].comboBox);
                    ControlToEP_Dict.Add(CBConfigs[j].comboBox, ep);
                    ControlToBool_Dict.Add(CBConfigs[j].comboBox, true);
                    if ((int)Table != 3)
                        CBConfigs[j].comboBox.Validating += ComboBoxValidation;
                    else //jeśli modyfikowany jest wpis w Counters
                        CBConfigs[j].comboBox.Validating += CountersValidation;
                }
        }
 private static void UpdateProgressStatus(ConfigManagementForm MainForm, int i, int max)
 {
     String ProgressStatusName = "progressStatusMain";
     ProgressStatusStrip progressStatus = MainForm.Controls.Find(ProgressStatusName, true)[0] as ProgressStatusStrip;
     if (progressStatus.InvokeRequired)
     {
         UpdateProgressStatusDelegate del = new UpdateProgressStatusDelegate(UpdateProgressStatus);
         progressStatus.Invoke(del, progressStatus, i, max);
         return;
     }
     progressStatus.Value = (i / (float)max) * 100;
     Application.DoEvents();
 }
        /// <summary>
        /// Odświeża wszystkie ListView, które były wcześniej wypełnione.
        /// </summary>
        private static void RefreshFilledListViews(ConfigManagementForm MainForm)
        {
            int ListViewsToUpdate = 0;

            for (int i = 0; i < ConfigManagementForm.ListViewFilled.Count(); i++)
                if (ConfigManagementForm.ListViewFilled[i] == true)
                    ListViewsToUpdate++;

            for (int i = 0; i < ConfigManagementForm.ListViewFilled.Count(); i++)
            {
                MainForm.UpdateStatusLabel(i);
                UpdateProgressStatus(MainForm, i, ListViewsToUpdate);
                if (ConfigManagementForm.dataBase[i] != null)
                {
                    ConfigManagementForm.dataBase[i].RefreshList();
                    ListViewConfig.ListViewRefresh(ConfigManagementForm.listView[i], ConfigManagementForm.dataBase[i].itemList);
                }
            }
            MainForm.UpdateStatusLabel(-1);
            UpdateProgressStatus(MainForm, 0, ListViewsToUpdate);
        }
        /// <summary>
        /// Wypełnia otwarty w danym momencie ListView i tworzy tablicę IDataBase.
        /// </summary>
        private static void FillListView(ConfigManagementForm MainForm)
        {
            switch (ConfigManagementForm.selectedTab)
            {
                case Tables.Collectors:
                    ConfigManagementForm.dataBase = new IDataBase[5] { new Collectors(), null, null, null, null };
                    ListViewConfig.ListViewRefresh(ConfigManagementForm.listView[(int)Tables.Collectors], ConfigManagementForm.dataBase[(int)Tables.Collectors].itemList);
                    break;

                case Tables.Customers:
                    ConfigManagementForm.dataBase = new IDataBase[5] { null, new Customers(), null, null, null };
                    ListViewConfig.ListViewRefresh(ConfigManagementForm.listView[(int)Tables.Customers], ConfigManagementForm.dataBase[(int)Tables.Customers].itemList);
                    break;

                case Tables.Areas:
                    ConfigManagementForm.dataBase = new IDataBase[5] { null, null, new Areas(), null, null };
                    ListViewConfig.ListViewRefresh(ConfigManagementForm.listView[(int)Tables.Areas], ConfigManagementForm.dataBase[(int)Tables.Areas].itemList);
                    break;

                case Tables.Counters:
                    ConfigManagementForm.dataBase = new IDataBase[5] { null, null, null, new Counters(), null };
                    ListViewConfig.ListViewRefresh(ConfigManagementForm.listView[(int)Tables.Counters], ConfigManagementForm.dataBase[(int)Tables.Counters].itemList);
                    break;

                case Tables.Addresses:
                    ConfigManagementForm.dataBase = new IDataBase[5] { null, null, null, null, new Addresses() };
                    ListViewConfig.ListViewRefresh(ConfigManagementForm.listView[(int)Tables.Addresses], ConfigManagementForm.dataBase[(int)Tables.Addresses].itemList);
                    break;

                default:
                    break;
            }
            ConfigManagementForm.ListViewFilled[(int)ConfigManagementForm.selectedTab] = true;
        }