private void button_delete_Click(object sender, EventArgs e)
        {
            if (currentListOfCustomers.Count != 0)
            {
                if (currentListOfCustomers.Count <= currentIndex)
                {
                    currentIndex = 0;
                }
                DataGridViewRow selectedRow = dataGridView1.Rows[currentIndex];
                Customer        currentCustomer;
                currentCustomer = currentCustomer = (Customer)dataGridView1.CurrentRow.DataBoundItem;

                var confirmResult = MessageBox.Show("Are you sure to delete ID: " + currentCustomer.ID + " : " + currentCustomer.FirstName + " " + currentCustomer.LastName + " ?",
                                                    "Delete Confirmation",
                                                    MessageBoxButtons.YesNo);
                if (confirmResult == DialogResult.Yes)
                {
                    CustomersData.deleteCustomer(currentCustomer);
                    currentListOfCustomers.Remove(currentCustomer);
                }
                else
                {
                    // If 'No', do something here.
                }

                reloadList();
            }
            else
            {
                MessageBox.Show("There is no more user");
            }
        }
        private void button_save_Click(object sender, EventArgs e)
        {
            Customer newCustomer;

            firstName   = textBox_newFirstName.Text;
            lastName    = textBox_newLastName.Text;
            address     = textBox_newAddress.Text;
            phoneNumber = textBox_newPhoneNumber.Text;

            if (string.IsNullOrWhiteSpace(firstName))
            {
                MessageBox.Show("Invalid or empty first name", "First Name is Required");
                return;
            }

            if (string.IsNullOrWhiteSpace(lastName))
            {
                MessageBox.Show("Invalid or empty last name", "Last Name is Required");
                return;
            }

            if (string.IsNullOrWhiteSpace(address))
            {
                MessageBox.Show("Invalid or empty address", "Address is Required");
                return;
            }

            if (string.IsNullOrWhiteSpace(phoneNumber))
            {
                MessageBox.Show("Invalid or empty phone number", "Phone Number is Required");
                return;
            }

            if (comboBox_customerType.Text.Equals("Premium") && string.IsNullOrWhiteSpace(richTextBox_creditLimit.Text))
            {
                MessageBox.Show("Invalid or empty credit limit", "Credit linit is Required");
                return;
            }

            if (customerType.Equals("Premium"))
            {
                newCustomer = new PremiumCustomer(firstName, lastName, address, customerType, phoneNumber, Int32.Parse(richTextBox_creditLimit.Text));
            }
            else
            {
                newCustomer = new NormalCustomer(firstName, lastName, address, customerType, phoneNumber);
            }

            CustomersData.addNewCustomer(newCustomer);
            Form         mainForm  = Application.OpenForms["CustomerForm"];
            CustomerForm salesForm = (CustomerForm)mainForm;

            salesForm.reloadList();
            this.Close();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            List <UserAccount> currentUserAccounts = new List <UserAccount>();

            currentUserAccounts = UserAccountsData.initializeAccount();
            List <Customer> currentListOfCustomers = new List <Customer>();

            currentListOfCustomers = CustomersData.initializeData();
            List <Sales> currentListOfSales = new List <Sales>();

            currentListOfSales = SalesData.initializeData();
        }
Example #4
0
        private void button_save_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(richTextBox_firstName.Text))
            {
                MessageBox.Show("Invalid or empty first name", "First Name is Required");
                return;
            }

            if (string.IsNullOrWhiteSpace(richTextBox_lastName.Text))
            {
                MessageBox.Show("Invalid or empty last name", "Last Name is Required");
                return;
            }

            if (string.IsNullOrWhiteSpace(richTextBox_address.Text))
            {
                MessageBox.Show("Invalid or empty address", "Address is Required");
                return;
            }

            if (string.IsNullOrWhiteSpace(richTextBox_phoneNumber.Text))
            {
                MessageBox.Show("Invalid or empty phone number", "Phone Number is Required");
                return;
            }

            if (comboBox_customerType.Text.Equals("Premium") && string.IsNullOrWhiteSpace(richTextBox_creditLimit.Text))
            {
                MessageBox.Show("Invalid or empty credit limit", "Credit linit is Required");
                return;
            }



            if (comboBox_customerType.Text.Equals("Premium"))
            {
                PremiumCustomer currentPremiumCustomer = new PremiumCustomer();
                currentPremiumCustomer.ID           = CurrentCustomer.ID;
                currentPremiumCustomer.FirstName    = richTextBox_firstName.Text;
                currentPremiumCustomer.LastName     = richTextBox_lastName.Text;
                currentPremiumCustomer.CustomerType = comboBox_customerType.Text;
                currentPremiumCustomer.Address      = richTextBox_address.Text;;
                currentPremiumCustomer.PhoneNumber  = richTextBox_phoneNumber.Text;
                try
                {
                    currentPremiumCustomer.CreditLimit = Int32.Parse(richTextBox_creditLimit.Text);
                }catch (FormatException fe)
                {
                    MessageBox.Show("Invalid Format", "Invalid Credit Limit Format is Required");
                    return;
                }

                CurrentCustomer = currentPremiumCustomer;
            }
            else
            {
                NormalCustomer currentNormalCustomer = new NormalCustomer();
                currentNormalCustomer.ID           = CurrentCustomer.ID;
                currentNormalCustomer.FirstName    = richTextBox_firstName.Text;
                currentNormalCustomer.LastName     = richTextBox_lastName.Text;
                currentNormalCustomer.CustomerType = comboBox_customerType.Text;
                currentNormalCustomer.Address      = richTextBox_address.Text;;
                currentNormalCustomer.PhoneNumber  = richTextBox_phoneNumber.Text;
                CurrentCustomer = currentNormalCustomer;
            }


            CustomersData.updateInformation(CurrentCustomer);
            Form         mainForm  = Application.OpenForms["CustomerForm"];
            CustomerForm salesForm = (CustomerForm)mainForm;

            salesForm.currentListOfCustomers[salesForm.currentIndex] = CurrentCustomer;
            salesForm.reloadList();
            this.Close();
        }
 public void populateList()
 {
     currentListOfCustomers   = CustomersData.getCurrentList();
     dataGridView1.DataSource = currentListOfCustomers;
 }