Example #1
0
        public void UpdateCustomer(int customerID, out int custID)
        {
            custID = customerID;
            CreateCustomer();
            Customer c = CustomerContainer.S.Find(customerID);

            Text_CreateName.Text     = c.Name;
            Text_Create_Address.Text = c.Address;
            DateTime temp = new DateTime(c.dob.Year, c.dob.Month, c.dob.Day);

            Date_Create_DOB.Value = temp;
            if (c is VipCustomer)
            {
                VipCustomer v = c as VipCustomer;
                CheckBox_Create_isVIP.Checked = true;
                CheckBox_Create_isVIP.Enabled = false;
                CreateCustomer_Discount_Input.SelectedIndex = (int)(Math.Round(v.Discount * 10));
                CreateCustomer_RegScore_ComboBox.Enabled    = false;
                Lable_Score.Enabled = false;
            }
            else if (c is RegCustomer)
            {
                RegCustomer r = c as RegCustomer;
                CheckBox_Create_isVIP.Checked = false;
                CheckBox_Create_isVIP.Enabled = false;
                CreateCustomer_RegScore_ComboBox.SelectedIndex = (int)r.RegType;
                CreateCustomer_Discount_Input.SelectedIndex    = 0;
                CreateCustomer_Discount_Input.Enabled          = false;
                CreateCustomer_RegScore_ComboBox.Enabled       = true;
            }
        }
Example #2
0
        public void ViewCustomer(int customerID)
        {
            currentMode = Mode.View;
            EnableAll(true);
            Customer c = CustomerContainer.S.Find(customerID);

            Group_CreateCustomer.Visible = false;
            Group_CreateCustomer.SendToBack();
            Group_Cust_Properties.Visible = true;
            Group_Cust_Properties.BringToFront();
            Button_DeleteCustomer.Enabled = false;
            Button_DeleteCustomer.Visible = false;
            try
            {
                Label_Num_Cust_ID.Text  = c.CustomerID.ToString();
                Label_TextName.Text     = c.Name;
                Label_Text_Address.Text = c.Address;
                Label_Date_Dob.Text     = c.dob.ToString();
                Label_Date_DOR.Text     = c.dor.ToString();
                listView1.Enabled       = true;
                InitItemList();
                SetCustomerItemList(c);
                label_text_highestPrice.Text = c.GetHighestPrice().ToString();
                label_text_Total.Text        = c.GetTotalAmount().ToString();
                Button_AddToPayment.Enabled  = true;

                if (c is VipCustomer)
                {
                    Label_Customer_isVIP.Text = "Yes";
                    VipCustomer v = c as VipCustomer;
                    Label_Discount.Enabled = true;
                    Combo_Discount.Enabled = false;
                    Console.WriteLine("Discount: " + v.Discount);
                    Combo_Discount.SelectedIndex         = (int)(v.Discount * 10);
                    Input_RegCustomerScore.SelectedIndex = 3;
                    Input_RegCustomerScore.Enabled       = false;
                }

                else if (c is RegCustomer)
                {
                    Label_Customer_isVIP.Text    = "No";
                    Label_Discount.Enabled       = false;
                    Combo_Discount.Enabled       = false;
                    Combo_Discount.SelectedIndex = 0;
                    RegCustomer r = c as RegCustomer;
                    Console.WriteLine(((int)r.RegType).ToString());
                    Input_RegCustomerScore.SelectedIndex = (int)r.RegType;
                    Input_RegCustomerScore.Enabled       = false;
                }
            }
            catch (NullReferenceException e)
            {
                DialogResult d = MessageBox.Show("Customer not found", "No ID found", MessageBoxButtons.OK);
            }
        }
        public void Update()
        {
            List <Customer> customerList = new List <Customer>();

            customerList.AddRange(CustomerContainer.S.customers);
            dataGridView1.DataSource = customerList;
            Console.WriteLine("Update Customer count: " + customerList.Count);
            try
            {
                for (int i = 0; i < CustomerContainer.S.customers.Count; i++)
                {
                    if (dataGridView1.Rows[i].Cells[0].Value == null)
                    {
                        dataGridView1.Rows[i].Cells[0].Value = CustomerContainer.S.customers[i].CustomerID;
                        dataGridView1.Rows[i].Cells[1].Value = CustomerContainer.S.customers[i].Name;
                        dataGridView1.Rows[i].Cells[2].Value = CustomerContainer.S.customers[i].Address;
                        dataGridView1.Rows[i].Cells[3].Value = CustomerContainer.S.customers[i].dob.ToString();
                        dataGridView1.Rows[i].Cells[4].Value = CustomerContainer.S.customers[i].dor.ToString();
                        if (CustomerContainer.S.customers[i] is VipCustomer)
                        {
                            VipCustomer v = CustomerContainer.S.customers[i] as VipCustomer;
                            Console.WriteLine("CellFormatting Discount: " + v.Discount);
                            dataGridView1.Rows[i].Cells[5].Value = (v.Discount * 100).ToString() + "%";
                            dataGridView1.Rows[i].Cells[6].Value = "N/A";
                        }
                        else
                        {
                            RegCustomer r = CustomerContainer.S.customers[i] as RegCustomer;
                            dataGridView1.Rows[i].Cells[5].Value = "N/A";
                            dataGridView1.Rows[i].Cells[6].Value = r.RegType.ToString();
                        }
                        dataGridView1.Rows[i].Cells[7].Value = CustomerContainer.S.customers[i].TotalAmount;
                    }
                }
            }
            catch (Exception h)
            {
                Console.WriteLine(h.Message + "\nTest Count: " + CustomerContainer.S.customers.Count + "\nrows count: " + dataGridView1.Rows.Count);
            }
        }
Example #4
0
        public void SaveCustomer(Customer c)
        {
            if (currentMode == Mode.Create)
            {
                if (CheckBox_Create_isVIP.Checked)
                {
                    double discount = (double)(CreateCustomer_Discount_Input.SelectedIndex);
                    discount /= 10;
                    Console.WriteLine("New Customer Discount: " + discount);
                    c = new VipCustomer(Text_CreateName.Text, Text_Create_Address.Text, new Date(Date_Create_DOB.Value.Day, Date_Create_DOB.Value.Month, Date_Create_DOB.Value.Year), new Date(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year), tempItems, discount);

                    VipCustomer v = c as VipCustomer;
                }
                else
                {
                    RegCustomerType RegTypetemp = RegCustomerType.GOLD;
                    Console.WriteLine(CreateCustomer_RegScore_ComboBox.SelectedIndex);
                    switch (CreateCustomer_RegScore_ComboBox.SelectedItem.ToString())
                    {
                    case "SILVER":
                        RegTypetemp = RegCustomerType.SILVER;
                        break;

                    case "PLATINUM":
                        RegTypetemp = RegCustomerType.PLATINUM;
                        break;

                    default:
                        break;
                    }
                    c = new RegCustomer(Text_CreateName.Text, Text_Create_Address.Text, new Date(Date_Create_DOB.Value.Day, Date_Create_DOB.Value.Month, Date_Create_DOB.Value.Year), new Date(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year), tempItems, RegTypetemp);
                }
                CustomerContainer.S.Add(c);
            }
            else if (currentMode == Mode.Edit)

            {
                c = CustomerContainer.S.Find(currentCustomerID);
                Console.WriteLine("Name: " + c.Name + "Type: " + c.GetType().ToString());
                c.Name    = Text_CreateName.Text;
                c.Address = Text_Create_Address.Text;
                c.dob     = new Date(Date_Create_DOB.Value.Day, Date_Create_DOB.Value.Month, Date_Create_DOB.Value.Year);

                if (c is VipCustomer)
                {
                    VipCustomer v = c as VipCustomer;
                    v.Discount = (double)(CreateCustomer_Discount_Input.SelectedIndex) / 10;
                    CreateCustomer_Discount_Input.SelectedIndex = (int)(Math.Round(v.Discount * 10));
                }
                else if (c is RegCustomer)
                {
                    Console.WriteLine("c is REG");
                    RegCustomer r = c as RegCustomer;

                    RegCustomerType RegTypetemp = (RegCustomerType)CreateCustomer_RegScore_ComboBox.SelectedIndex;
                    Console.WriteLine("Save Cust RegType: " + RegTypetemp.ToString());
                    Console.WriteLine((RegCustomerType)CreateCustomer_RegScore_ComboBox.SelectedIndex);
                    switch (RegTypetemp)
                    {
                    case RegCustomerType.SILVER:
                        break;

                    case RegCustomerType.GOLD:
                        break;

                    case RegCustomerType.PLATINUM:
                        break;

                    default:
                        break;
                    }

                    r.RegType = RegTypetemp;
                }
            }

            DataManager.S.SaveToBinary(c);
            DataManager.S.SaveAllToBinary(CustomerContainer.S);
            _mainForm.Update();
        }