Exemple #1
0
        private void Button_AddToPayment_Click(object sender, EventArgs e)
        {
            if (ItemList.CheckedIndices.Count > 1)
            {
                DialogResult d = MessageBox.Show("You can only add one item at a time", "Warning - Multiple Items Selected", MessageBoxButtons.OK);
            }
            else
            {
                Customer    c         = CustomerContainer.S.Find(int.Parse(Label_Num_Cust_ID.Text));
                List <Item> purchases = new List <Item>();
                foreach (int num in ItemList.CheckedIndices)
                {
                    c.items.Add(ItemContainer.S.Find(num));
                    purchases.Add(ItemContainer.S.Find(num));
                }
                foreach (Item purchase in purchases)
                {
                    if (c is VipCustomer)
                    {
                        VipCustomer v = c as VipCustomer;
                        v.AddToPayment(purchase.Price);
                    }
                    else
                    {
                        c.AddToPayment(purchase.Price);
                    }
                }

                SetCustomerItemList(c);
                label_text_highestPrice.Text = c.GetHighestPrice().ToString();
                label_text_Total.Text        = c.GetTotalAmount().ToString();
            }
        }
Exemple #2
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;
            }
        }
Exemple #3
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);
            }
        }
Exemple #4
0
        public void SetCustomerItemList(Customer c)
        {
            ListViewItem lvi = new ListViewItem();

            for (int i = 0; i < c.items.Count; i++)
            {
                lvi.SubItems.Insert(0, new ListViewItem.ListViewSubItem(lvi, (c.items[i].ProductSerialNum.ToString())));
                lvi.SubItems.Insert(1, new ListViewItem.ListViewSubItem(lvi, (c.items[i].Name.ToString())));
                if (c is VipCustomer)
                {
                    VipCustomer v = c as VipCustomer;
                    lvi.SubItems.Insert(2, new ListViewItem.ListViewSubItem(lvi, (c.items[i].Price * (1 - v.Discount)).ToString()));
                }
                else
                {
                    lvi.SubItems.Insert(2, new ListViewItem.ListViewSubItem(lvi, (c.items[i].Price.ToString())));
                }
            }
            listView1.Items.Add(lvi);
            listView1.View = View.Details;
        }
        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);
            }
        }
Exemple #6
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();
        }