Exemple #1
0
        private void addButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(customerNameTextBox.Text))
                {
                    MessageBox.Show("Please Enter Customer Name..!");
                    return;
                }

                _customer.Name = customerNameTextBox.Text;

                if (_customerManager.IsCustomerExist(_customer))
                {
                    MessageBox.Show("This Customer Already Exist..!");
                    return;
                }

                if (String.IsNullOrEmpty(contactTextBox.Text))
                {
                    MessageBox.Show("Please Enter Valid Mobile Number..!");
                    return;
                }

                if (String.IsNullOrEmpty(addressTextBox.Text))
                {
                    MessageBox.Show("Please Enter Customer Address..!");
                    return;
                }

                _customer.Contact = contactTextBox.Text;
                _customer.Address = addressTextBox.Text;

                if (_customerManager.AddCustomer(_customer))
                {
                    showDataGridView.DataSource = _customerManager.Display();
                    MessageBox.Show("Customer Added Successfully...!");
                }
                else
                {
                    MessageBox.Show("Not Added...!");
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string error = string.Empty;

            Model.Customer customer = new Model.Customer();
            customer.CustomerId        = this.txtCustomerNumber.Text.Trim();
            customer.CustomerName      = this.txtCustomerName.Text.Trim();
            customer.RegisteredAddress = this.txtRegisteredAddress.Text.Trim();
            customer.LegalPerson       = this.txtLegalPerson.Text.Trim();
            customer.Contacts          = this.txtContacts.Text.Trim();
            customer.RegisteredPhone   = this.txtRegisteredPhone.Text.Trim();
            customer.ContactTelephone  = this.txtContactTelephone.Text.Trim();
            customer.Fax                   = this.txtFax.Text.Trim();
            customer.MobilePhone           = this.txtMobilePhone.Text.Trim();
            customer.ZipCode               = this.txtZipCode.Text.Trim();
            customer.SparePhone            = this.txtSparePhone.Text.Trim();
            customer.Email                 = this.txtEmail.Text.Trim();
            customer.QQ                    = this.txtQQ.Text.Trim();
            customer.AccountBank           = this.txtAccountBank.Text.Trim();
            customer.SortCode              = this.txtSortCode.Text.Trim();
            customer.BankAccount           = this.txtBankAccount.Text.Trim();
            customer.TaxNo                 = this.txtTaxNo.Text.Trim();
            customer.WebsiteAddress        = this.txtWebsiteAddress.Text.Trim();
            customer.DeliveryAddress       = this.txtDeliveryAddress.Text.Trim();
            customer.Paymentdays           = 0;
            customer.PercentageInAdvance   = 0;
            customer.Remark                = this.txtRemark.Text.Trim();
            customer.FactoryAddress        = this.txtFactoryAddress.Text.Trim();
            customer.MakeCollectionsModeId = this.drpMakeCollectionsModeId.SelectedValue;
            customer.ReceiveType           = this.drpReceiveType.SelectedValue;
            if (string.IsNullOrEmpty(customer.CustomerId) || string.IsNullOrEmpty(customer.CustomerName))
            {
                lbSubmit.Text = "请将带*号的内容填写完整!";
                return;
            }
            bool result = false;

            if (btnSubmit.Text.Equals("添加"))
            {
                result        = CustomerInfoManager.AddCustomer(customer, ref error);
                lbSubmit.Text = result == true ? "添加成功" : "添加失败!原因" + error;
                if (result)
                {
                    Tool.WriteLog(Tool.LogType.Operating, "增加客户信息" + customer.CustomerId, "增加成功");
                    ToolCode.Tool.ResetControl(this.Controls);
                    return;
                }
                else
                {
                    Tool.WriteLog(Tool.LogType.Operating, "增加客户信息" + customer.CustomerId, "增加失败!原因" + error);
                    return;
                }
            }
            else
            {
                result        = CustomerInfoManager.EditCustomer(customer, ref error);
                lbSubmit.Text = result == true ? "修改成功" : "修改失败!原因" + error;
                if (result)
                {
                    Tool.WriteLog(Tool.LogType.Operating, "修改客户信息" + customer.CustomerId, "修改成功");
                    return;
                }
                else
                {
                    Tool.WriteLog(Tool.LogType.Operating, "修改客户信息" + customer.CustomerId, "修改失败!原因" + error);
                    return;
                }
            }
        }