private void btn_Save_Customer_Click(object sender, EventArgs e)
        {
            BLCustomer blC = new BLCustomer();

            if (SaveStatus == 1)
            {
                blC.CreateCustomer(txt_Customer_CustomerName.Text,
                                   txt_Customer_IdentityCard.Text,
                                   txt_Customer_PhoneNumber.Text,
                                   txt_Customer_CustomerAddress.Text);
            }
            else if (SaveStatus == 2)
            {
                blC.UpdateCustomer(txt_Customer_CustomerID.Text,
                                   txt_Customer_CustomerName.Text,
                                   txt_Customer_IdentityCard.Text,
                                   txt_Customer_PhoneNumber.Text,
                                   txt_Customer_CustomerAddress.Text);
            }
            SaveStatus = 0;
            dgv_Customer.DataSource = blC.LoadCustomer();
            dgv_Customer_CellClick(null, null);
            btn_Update_Customer.Enabled = true;
            btn_Create_Customer.Enabled = true;
            btn_Save_Customer.Enabled   = false;
        }
Exemple #2
0
        public void CreateCustomerTest()
        {
            int      customer_id = 0;
            int      age         = 0;
            int      zip         = 0;
            char     gender      = 'T';
            int      income      = -1;
            int      children    = -1;
            string   degree      = "Elementary School Diploma";
            int      ownHouse    = -1;
            Customer customer;

            List <string> errors = new List <string>();

            BLCustomer.CreateCustomer(null, ref errors);
            Assert.AreEqual(1, errors.Count);
            AsynchLog.LogNow(errors);

            //customer_id = 0
            errors   = new List <string>();
            customer = new Customer(customer_id, "first", "last", "address1", "city1", "CA", 92037, 20,
                                    'M', "None", 80000, 2, "None", 1);
            BLCustomer.CreateCustomer(customer, ref errors);
            Assert.AreEqual(1, errors.Count);
            AsynchLog.LogNow(errors);

            //age = 0
            errors   = new List <string>();
            customer = new Customer(1, "first", "last", "address1", "city1", "CA", 92037, age,
                                    'M', "None", 80000, 2, "None", 1);
            BLCustomer.CreateCustomer(customer, ref errors);
            Assert.AreEqual(1, errors.Count);
            AsynchLog.LogNow(errors);

            //zip = 0
            errors   = new List <string>();
            customer = new Customer(1, "first", "last", "address1", "city1", "CA", zip, 20,
                                    'M', "None", 80000, 2, "None", 1);
            BLCustomer.CreateCustomer(customer, ref errors);
            Assert.AreEqual(1, errors.Count);
            AsynchLog.LogNow(errors);

            //gender = T
            errors   = new List <string>();
            customer = new Customer(1, "first", "last", "address1", "city1", "CA", 92037, 20,
                                    gender, "None", 80000, 2, "None", 1);
            BLCustomer.CreateCustomer(customer, ref errors);
            Assert.AreEqual(1, errors.Count);
            AsynchLog.LogNow(errors);

            //income = -1
            errors   = new List <string>();
            customer = new Customer(1, "first", "last", "address1", "city1", "CA", 92037, 20,
                                    'M', "None", income, 2, "None", 1);
            BLCustomer.CreateCustomer(customer, ref errors);
            Assert.AreEqual(1, errors.Count);
            AsynchLog.LogNow(errors);

            //children = -1
            errors   = new List <string>();
            customer = new Customer(1, "first", "last", "address1", "city1", "CA", 92037, 20,
                                    'M', "None", 80000, children, "None", 1);
            BLCustomer.CreateCustomer(customer, ref errors);
            Assert.AreEqual(1, errors.Count);
            AsynchLog.LogNow(errors);

            //degree = Elementary School Diploma
            errors   = new List <string>();
            customer = new Customer(1, "first", "last", "address1", "city1", "CA", 92037, 20,
                                    'M', "None", 80000, 2, degree, 1);
            BLCustomer.CreateCustomer(customer, ref errors);
            Assert.AreEqual(1, errors.Count);
            AsynchLog.LogNow(errors);

            //ownHouse = -1
            errors   = new List <string>();
            customer = new Customer(1, "first", "last", "address1", "city1", "CA", 92037, 20,
                                    'M', "None", 80000, 2, "None", ownHouse);
            BLCustomer.CreateCustomer(customer, ref errors);
            Assert.AreEqual(1, errors.Count);
            AsynchLog.LogNow(errors);
            //ownHouse = -1

            //all 8 errors
            errors   = new List <string>();
            customer = new Customer(customer_id, "first", "last", "address1", "city1", "CA", zip, age,
                                    gender, "None", income, children, degree, ownHouse);
            BLCustomer.CreateCustomer(customer, ref errors);
            Assert.AreEqual(8, errors.Count);
            AsynchLog.LogNow(errors);

            //no errors
            errors   = new List <string>();
            customer = new Customer(1, "first", "last", "address1", "city1", "CA", 92037, 20,
                                    'M', "None", 80000, 2, "None", 1);
            BLCustomer.CreateCustomer(customer, ref errors);
            Assert.AreEqual(0, errors.Count);
            AsynchLog.LogNow(errors);
        }
 public void CreateCustomer(Customer users, ref List <string> errors)
 {
     BLCustomer.CreateCustomer(users, ref errors);
 }