Esempio n. 1
0
        /// <summary>
        /// Generuje klientów losowo dobierając wartości pól i dodaje ich do bazy.
        /// </summary>
        static void GenerateCustomers()
        {
            Random rnd = new Random();
            string[] nameAndLastName;
            string[] postalCodeAndCity;
            int tpmGender = 0;
            Customer customer;

            for (int i = 0; i < numberOfCustomers; i++)
            {
                customer = new Customer();
                tpmGender = rnd.Next(0, 9);
                customer.CustomerId = GenerateRandomPesel("Customer", tpmGender);
                nameAndLastName = GenerateNameAndLastName(tpmGender);
                customer.Name = nameAndLastName[0];
                customer.LastName = nameAndLastName[1];
                postalCodeAndCity = GeneratePostalCodeAndCity();
                customer.PostalCode = postalCodeAndCity[0];
                customer.City = postalCodeAndCity[1];
                customer.Address = SampleDataSource.streets[rnd.Next(0, SampleDataSource.streets.Length - 1)] + ' ' + rnd.Next(1, 100).ToString();
                customer.PhoneNumber = GeneratePhoneNumber();

                customer.InsertIntoDB();
            }
        }
Esempio n. 2
0
        private bool InsertCustomer()
        {
            Customer c = new Customer();
            c.CustomerId = tbCustomerID.Text;
            c.Name = tbCustomerFirstName.Text;
            c.LastName = tbCustomerLastName.Text;
            c.PostalCode = tbCustomerPostalCode.Text;
            c.City = tbCustomerCity.Text;
            c.Address = tbCustomerAddress.Text;
            c.PhoneNumber = tbCustomerPhoneNumber.Text;

            if (Auxiliary.IsCurrentValueOK(Current_ControlToBool_Dict))
            {
                c.InsertIntoDB();
                modified = true;
                InsertedTo = Tables.Customers;
                return true;
            }
            else
            {
                MessageBox.Show(LangPL.InsertFormLang["Fill in all fields"]);
                return false;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Wywoływana po naciśnięciu przycisku "Zapisz". Zapisuje zmiany i zamyka formularz, jeśli wprowadzone zmiany są poprawnie.
        /// </summary>
        /// <param name="sender">Przycisk "Zapisz".</param>
        /// <param name="e">Argumenty zdarzenia.</param>
        private void btSave_Click(object sender, EventArgs e)
        {
            int Parse;

            switch (Table)
            {
                case Tables.Collectors:
                    if (Auxiliary.IsCurrentValueOK(ControlToBool_Dict))
                    {
                        Collector modifiedCollector = new Collector();
                        modifiedCollector.CollectorId = this.Controls.Find("CollectorId", true)[0].Text;
                        modifiedCollector.Name = this.Controls.Find("Name", true)[0].Text;
                        modifiedCollector.LastName = this.Controls.Find("LastName", true)[0].Text;
                        modifiedCollector.PostalCode = this.Controls.Find("PostalCode", true)[0].Text;
                        modifiedCollector.City = this.Controls.Find("City", true)[0].Text;
                        modifiedCollector.Address = this.Controls.Find("Address", true)[0].Text;
                        modifiedCollector.PhoneNumber = this.Controls.Find("PhoneNumber", true)[0].Text;
                        modifiedCollector.ModifyRecord(ids.ElementAt(0));
                        modified = true;
                        this.Close();
                    }
                    else
                        MessageBox.Show(LangPL.InsertFormLang["Fill in all fields"]);
                    break;

                case Tables.Customers:
                    if (Auxiliary.IsCurrentValueOK(ControlToBool_Dict))
                    {
                        Customer modifiedCustomer = new Customer();
                        modifiedCustomer.CustomerId = this.Controls.Find("CustomerId", true)[0].Text;
                        modifiedCustomer.Name = this.Controls.Find("Name", true)[0].Text;
                        modifiedCustomer.LastName = this.Controls.Find("LastName", true)[0].Text;
                        modifiedCustomer.PostalCode = this.Controls.Find("PostalCode", true)[0].Text;
                        modifiedCustomer.City = this.Controls.Find("City", true)[0].Text;
                        modifiedCustomer.Address = this.Controls.Find("Address", true)[0].Text;
                        modifiedCustomer.PhoneNumber = this.Controls.Find("PhoneNumber", true)[0].Text;
                        modifiedCustomer.ModifyRecord(ids.ElementAt(0));
                        modified = true;
                        this.Close();
                    }
                    else
                        MessageBox.Show(LangPL.InsertFormLang["Fill in all fields"]);
                    break;

                case Tables.Areas:
                    if (Auxiliary.IsCurrentValueOK(ControlToBool_Dict))
                    {
                        Area modifiedArea = new Area();
                        modifiedArea.AreaId = new Guid(this.Controls.Find("AreaId", true)[0].Text);
                        modifiedArea.Street = this.Controls.Find("Street", true)[0].Text;
                        if (CBConfigs[0].ReturnForeignKey() == "")
                            modifiedArea.CollectorId = "";
                        else
                            modifiedArea.CollectorId = CBConfigs[0].ReturnForeignKey();
                        modifiedArea.ModifyRecord(ids.ElementAt(0));
                        modified = true;
                        this.Close();
                    }
                    else
                        MessageBox.Show(LangPL.InsertFormLang["Fill in all fields"]);
                    break;

                case Tables.Counters:
                    if (Auxiliary.IsCurrentValueOK(ControlToBool_Dict))
                    {
                        Counter modifiedCounter = new Counter();

                        modifiedCounter.CounterNo = Convert.ToInt32(this.Controls.Find("CounterNo", true)[0].Text);
                        Int32.TryParse(this.Controls.Find("CircuitNo", true)[0].Text, out Parse);
                        modifiedCounter.CircuitNo = Parse;

                        if (CBConfigs[0].comboBox.SelectedIndex != 0) //jeśli w jednym comboboxie index jest różny od 0, to w drugim też
                        {
                            modifiedCounter.AddressId = new Guid(CBConfigs[0].ReturnForeignKey());
                            modifiedCounter.CustomerId = CBConfigs[1].ReturnForeignKey();
                        }
                        else
                        {
                            modifiedCounter.AddressId = null;
                            modifiedCounter.CustomerId = null;
                        }

                        modifiedCounter.ModifyRecord(ids.ElementAt(0));
                        modified = true;
                        this.Close();
                    }
                    else
                        MessageBox.Show(LangPL.InsertFormLang["Fill in all fields"]);
                    break;

                case Tables.Addresses:
                    if (Auxiliary.IsCurrentValueOK(ControlToBool_Dict))
                    {
                        Address modifiedAddress = new Address();
                        modifiedAddress.AddressId = new Guid(this.Controls.Find("AddressId", true)[0].Text);
                        Int32.TryParse(this.Controls.Find("HouseNo", true)[0].Text, out Parse);
                        modifiedAddress.HouseNo = Parse;
                        Int32.TryParse(this.Controls.Find("FlatNo", true)[0].Text, out Parse);
                        if (Parse > 0)
                            modifiedAddress.FlatNo = Parse;
                        else
                            modifiedAddress.FlatNo = null;
                        modifiedAddress.AreaId = new Guid(CBConfigs[0].ReturnForeignKey());
                        modifiedAddress.ModifyRecord(ids.ElementAt(0));
                        modified = true;
                        this.Close();
                    }
                    else
                        MessageBox.Show(LangPL.InsertFormLang["Fill in all fields"]);
                    break;
            }
        }
Esempio n. 4
0
        public static string CustomerValidateString(Customer customer)
        {
            string checkBug = String.Empty;
            bool IsOK;

            if (!ContainsLetters(customer.CustomerId))
                checkBug += (IdentityValidation.CheckId(customer.CustomerId)) ? LangPL.InsertFormLang["textBoxCCID"] : String.Empty;
            else
                checkBug += LangPL.InsertFormLang["textBoxCCID"];

            checkBug += (IsOK = CityNameValidation(customer.Name)) ? String.Empty : LangPL.InsertFormLang["textBoxName"];
            if (IsOK)
                customer.Name = UppercaseFirst(customer.Name);

            checkBug += (IsOK = CityNameValidation(customer.LastName)) ? String.Empty : LangPL.InsertFormLang["textBoxLastName"];
            if (IsOK)
                customer.LastName = UppercaseFirst(customer.LastName);

            checkBug += PostalCodeValidation(customer.PostalCode) ? String.Empty : LangPL.InsertFormLang["textBoxPostalCode"];

            checkBug += (IsOK = CityNameValidation(customer.City)) ? String.Empty : LangPL.InsertFormLang["textBoxCity"];
            if (IsOK)
                customer.City = UppercaseFirst(customer.City);

            checkBug += (EmptyString(customer.Address)) ?String.Empty : LangPL.InsertFormLang["textBoxAddress"];
            checkBug += PhoneValidation(customer.PhoneNumber) ? String.Empty : LangPL.InsertFormLang["textBoxPhoneNumber"];

            return checkBug;
        }