Пример #1
0
 public ManageCustomersForm()
 {
     InitializeComponent();
     _db = new AppContext();
     _customerRepository = new CustomerRepository(_db);
     _searchCustomer = new Repository.Models.Customer();
 }
Пример #2
0
        private void btnSaveCustomer_Click(object sender, EventArgs e)
        {
            try
            {
                bool validateFrom = true;
                var message = "Operation failed to add customer.";
                int result = 0;

                if (string.IsNullOrEmpty(txtCustomerName.Text))
                {
                    validateFrom = false;
                    message = "Please enter customer name.";
                }

                if (validateFrom)
                {

                    var customer = new Repository.Models.Customer()
                    {
                        Name = txtCustomerName.Text,
                        Email = txtCustomerEmail.Text,
                        ContactNo = txtCustomerContact.Text,
                        CustomerId = _editCustomer != null ? _editCustomer.CustomerId : 0
                    };


                    if (_editCustomer != null && _editCustomer.CustomerId > 0)
                    {
                        result = _customerRepository.UpdateCustomer(customer);
                    }
                    else
                    {
                        result = _customerRepository.AddCustomer(customer);
                    }


                    if (result > 0)
                    {
                        message = "Customer saved successfully.";

                        clearFormValue();
                        initGridView();
                    }
                    else
                    {
                        message = "Operation failed to save new customer.";
                    }

                }

                MessageBox.Show(message);

            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #3
0
 void clearFormValue()
 {
     txtCustomerContact.Text = null;
     txtCustomerEmail.Text = null;
     txtCustomerName.Text = null;
     _editCustomer = new Repository.Models.Customer();
     _searchCustomer = new Repository.Models.Customer();
     dgCustomerList.ClearSelection();
 }
Пример #4
0
 void setEditFormFields(int row)
 {
     try
     {
         if (_customersList != null && _customersList.Count > 0)
         {
             tabCustomer.SelectedTab = tabPageForm;
             _editCustomer = _customersList[row];
             txtCustomerContact.Text = _editCustomer.ContactNo;
             txtCustomerEmail.Text = _editCustomer.Email;
             txtCustomerName.Text = _editCustomer.Name;
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Пример #5
0
 private void btnClearSearch_Click(object sender, EventArgs e)
 {
     txtSearchContact.Text = null;
     txtSearchEmail.Text = null;
     txtSearchName.Text = null;
     _searchCustomer = new Repository.Models.Customer();
     initGridView();
 }
Пример #6
0
 private void btnSearch_Click(object sender, EventArgs e)
 {
     try
     {
         _searchCustomer = new Repository.Models.Customer() { Name = txtSearchName.Text, Email = txtSearchEmail.Text, ContactNo = txtSearchContact.Text };
         initGridView();
     }
     catch (Exception)
     {
         throw;
     }
 }