예제 #1
0
        // Method that adds a Customer to the list.
        public void CreateCustomer(Customer customerToCreate)
        {
            this.CustomersList.Add(customerToCreate);

            // Fire Event:
            modelChanged(this, new myModelEventArgs(customerToCreate, null));

            // Save data to files:
            this.SaveData();
        }
예제 #2
0
파일: IModel.cs 프로젝트: LooN3Y/COM
 public myModelEventArgs(Customer cust, Order ord)
 {
     this._passingCustomer = cust;
     this._passingOrder = ord;
 }
예제 #3
0
        // Method that updates an existing customer's info.
        public void UpdateCustomer(Customer customerToUpdate)
        {
            Customer oldCustomer = this.FindCustomer(customerToUpdate);
            if (oldCustomer != null)
            {
                oldCustomer.ID = customerToUpdate.ID;
                oldCustomer.Name = customerToUpdate.Name;
                oldCustomer.Phone = customerToUpdate.Phone;
                oldCustomer.Address = customerToUpdate.Address;

                // Fire event:
                modelChanged(this, new myModelEventArgs(customerToUpdate, null));

                // Save data to files:
                this.SaveData();
            }
        }
예제 #4
0
파일: MainForm.cs 프로젝트: LooN3Y/COM
        // Update Customer Button:
        private void selOpsUpdateBtn_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(this.selectedCustIdTxt.Text)
                && !string.IsNullOrWhiteSpace(this.selectedCustNameTxt.Text)
                && !string.IsNullOrWhiteSpace(this.selectedCustPhoneTxt.Text)
                && !string.IsNullOrWhiteSpace(this.selectedCustAddressTxt.Text))
            {
                Customer cust = new Customer(int.Parse(this.selectedCustIdTxt.Text),
                                                                this.selectedCustNameTxt.Text,
                                                                int.Parse(this.selectedCustPhoneTxt.Text),
                                                                this.selectedCustAddressTxt.Text);
                if (this._controller.FindCustomer(cust) != null)
                {
                    if (MessageBox.Show("Are you sure you want to Update this customer?\n\r    - ID: " + cust.ID
                                                                                    + "\n\r    - Name: " + cust.Name
                                                                                    + "\n\r    - Phone: " + cust.Phone
                                                                                    + "\n\r    - Address: " + cust.Address
                                                                                    + "\n\r",
                            "Attention!",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        // CALL the controller's Update-Customer Function:
                        this._controller.UpdateCustomer(cust);

                        // Fire Event with the customer to update
                        viewChanged.Invoke(this, new myViewEventArgs(cust, null));
                    }
                }
                else
                {
                    this.responceLbl.ForeColor = System.Drawing.Color.Red;
                    this.responceLbl.Text = "Customer with ID: " + cust.ID + " does not exist!";
                }
            }
            else
            {
                this.responceLbl.ForeColor = System.Drawing.Color.Red;
                this.responceLbl.Text = "No fields should be blank!";
            }
        }
예제 #5
0
        // Method that searches the list for a customer. Returns the customer object if he is found,
        // or else null.
        public Customer FindCustomer(Customer customerToFind)
        {
            Customer customer = null;

            foreach (Customer cust in this.CustomersList)
            {
                if (cust.ID == customerToFind.ID)
                    return cust;
            }

            return customer;
        }
예제 #6
0
파일: MainForm.cs 프로젝트: LooN3Y/COM
        // Create new Customer Button:
        private void selOpsCreateBtn_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(this.selectedCustIdTxt.Text)
                && !string.IsNullOrWhiteSpace(this.selectedCustNameTxt.Text)
                && !string.IsNullOrWhiteSpace(this.selectedCustPhoneTxt.Text)
                && !string.IsNullOrWhiteSpace(this.selectedCustAddressTxt.Text))
            {
                Customer newCust = new Customer(int.Parse(this.selectedCustIdTxt.Text),
                                                                this.selectedCustNameTxt.Text,
                                                                int.Parse(this.selectedCustPhoneTxt.Text),
                                                                this.selectedCustAddressTxt.Text);

                if (this._controller.FindCustomer(newCust) == null)
                {
                    this.responceLbl.ForeColor = System.Drawing.Color.Black;
                    this.responceLbl.Text = "";

                    MessageBox.Show("New customer created: \n\r    - ID: " + newCust.ID
                                                         + "\n\r    - Name: " + newCust.Name
                                                         + "\n\r    - Phone: " + newCust.Phone
                                                         + "\n\r    - Address: " + newCust.Address
                                                         + "\n\r", "Success!");

                    // CALL the controller's Create-Customer Function:
                    this._controller.CreateCustomer(newCust);

                    // Fire Event with the new customer added
                    viewChanged.Invoke(this, new myViewEventArgs(newCust, null));
                }
                else
                {
                    this.responceLbl.ForeColor = System.Drawing.Color.Red;
                    this.responceLbl.Text = "Customer with ID: " + newCust.ID + " already exists!";
                }
            }
            else
            {
                this.responceLbl.ForeColor = System.Drawing.Color.Red;
                this.responceLbl.Text = "No fields should be blank!";
            }
        }
예제 #7
0
파일: ComController.cs 프로젝트: LooN3Y/COM
 public void UpdateCustomer(Customer c)
 {
     this._myModel.UpdateCustomer(c);
 }
예제 #8
0
파일: ComController.cs 프로젝트: LooN3Y/COM
 public Customer FindCustomer(Customer c)
 {
     return this._myModel.FindCustomer(c);
 }
예제 #9
0
파일: ComController.cs 프로젝트: LooN3Y/COM
 public void DeleteCustomer(Customer c)
 {
     this._myModel.DeleteCustomer(c);
 }
예제 #10
0
파일: ComController.cs 프로젝트: LooN3Y/COM
 public void CreateCustomer(Customer c)
 {
     this._myModel.CreateCustomer(c);
 }