public OrderForm(UserAccount user, LoginForm loginForm, Customer orderCustomer) { userAccount = user; _loginForm = loginForm; InitializeComponent(); customer = orderCustomer; }
public static BusinessObject.Customer ToBusinessObject(Entities.Customer entity) { if (entity == null) return null; BusinessObject.Customer businessObject = new BusinessObject.Customer { CustomerId = entity.CustomerId, PersonId = entity.PersonId }; return businessObject; }
public void DeleteCustomer(Customer customer) { string connectionString = ConfigurationManager.ConnectionStrings["ZhenLiuOnlineDBContext"].ConnectionString; using (SqlConnection conn = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("spDeleteCustomer", conn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter paramId = new SqlParameter(); paramId.ParameterName = "@CustomerID"; paramId.Value = customer.CustomerId; cmd.Parameters.Add(paramId); conn.Open(); cmd.ExecuteNonQuery(); } }
public static Entities.Customer ToEntity(BusinessObject.Customer businessObject) { if (businessObject == null) { return(null); } Entities.Customer entity = new Entities.Customer { CustomerId = businessObject.CustomerId, PersonId = businessObject.PersonId }; return(entity); }
public static BusinessObject.Customer ToBusinessObject(Entities.Customer entity) { if (entity == null) { return(null); } BusinessObject.Customer businessObject = new BusinessObject.Customer { CustomerId = entity.CustomerId, PersonId = entity.PersonId }; return(businessObject); }
public CustomerViewModel ConvertToViewModelFromCustomer(Customer customer) { var customerViewModel = new CustomerViewModel(); customerViewModel.Address = customer.Address; customerViewModel.CustomerID = customer.CustomerId; customerViewModel.FirstName = customer.FirstName; customerViewModel.LastName = customer.LastName; customerViewModel.Mobile = customer.Mobile; customerViewModel.UserPass = customer.UserPass; customerViewModel.ConfirmUserPass = customer.UserPass; customerViewModel.UserName = customer.UserName; customerViewModel.Email = customer.Email; customerViewModel.ConfirmEmailAddress = customer.Email; customerViewModel.DateOfBirth = customer.DateOfBirth; return customerViewModel; }
public Customer ConvertToCustomerFromViewModel(CustomerViewModel customerViewModel) { Customer customer = new Customer { Address = customerViewModel.Address, CustomerId = customerViewModel.CustomerID, Email = customerViewModel.Email, FirstName = customerViewModel.FirstName, LastName = customerViewModel.LastName, Mobile = customerViewModel.Mobile, UserName = customerViewModel.UserName, UserPass = customerViewModel.UserPass, DateOfBirth = customerViewModel.DateOfBirth }; return customer; }
public void CreateNewCustomer(Customer customer) { using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ZhenLiuOnlineDBContext"].ConnectionString; conn.Open(); SqlCommand sql = new SqlCommand("insert into customers (UserName,UserPass,Mobile,Email,LastName,FirstName,Address,DateOfBirth) values(@UserName,@UserPass,@Mobile,@Email,@LastName,@FirstName,@Address,@DateOfBirth)", conn); sql.Parameters.Add(new SqlParameter("UserName", customer.UserName)); sql.Parameters.Add(new SqlParameter("UserPass", customer.UserPass)); sql.Parameters.Add(new SqlParameter("Mobile", customer.Mobile)); sql.Parameters.Add(new SqlParameter("Email", customer.Email)); sql.Parameters.Add(new SqlParameter("LastName", customer.LastName)); sql.Parameters.Add(new SqlParameter("FirstName", customer.FirstName)); sql.Parameters.Add(new SqlParameter("Address", customer.Address)); sql.Parameters.Add(new SqlParameter("DateOfBirth", customer.DateOfBirth)); sql.ExecuteNonQuery(); } }
public void UpdateCustomer(Customer customer) { using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ZhenLiuOnlineDBContext"].ConnectionString; conn.Open(); SqlCommand sql = new SqlCommand("Update customers set UserPass=@UserPass,Mobile=@Mobile,Email=@Email,LastName=@LastName,FirstName=@FirstName,Address=@Address,DateOfBirth = @DateOfBirth where customerID = @CustomerID", conn); sql.Parameters.Add(new SqlParameter("UserName", customer.UserName)); sql.Parameters.Add(new SqlParameter("CustomerID", customer.CustomerId)); sql.Parameters.Add(new SqlParameter("UserPass", customer.UserPass)); sql.Parameters.Add(new SqlParameter("Mobile", customer.Mobile)); sql.Parameters.Add(new SqlParameter("Email", customer.Email)); sql.Parameters.Add(new SqlParameter("LastName", customer.LastName)); sql.Parameters.Add(new SqlParameter("FirstName", customer.FirstName)); sql.Parameters.Add(new SqlParameter("Address", customer.Address)); sql.Parameters.Add(new SqlParameter("DateOfBirth", customer.DateOfBirth)); sql.ExecuteNonQuery(); } }
private void cmdAdd_Click(object sender, EventArgs e) { if (txtCustomerCode.Text.Trim() == "") { MessageBox.Show("กรุณาป้อนรหัสลูกค้าก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtCustomerCode.Focus(); return; } if (txtCustomerName.Text.Trim() == "") { MessageBox.Show("กรุณาป้อนชื่อลูกค้าก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtCustomerName.Focus(); return; } if (txtCustomerAddress.Text.Trim() == "") { MessageBox.Show("กรุณาป้อนที่อยู่ลูกค้าก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtCustomerAddress.Focus(); return; } if (txtCustomerPhone.Text.Trim() == "") { MessageBox.Show("กรุณาป้อนโทรศัพท์ลูกค้าก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtCustomerPhone.Focus(); return; } if (MessageBox.Show("คุณต้องการเพิ่มลูกค้าใหม่ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { try { Customer customer = serviceCustomer.getByCode(txtCustomerCode.Text.Trim()); if (customer == null) { Customer newCustomer = new Customer(); newCustomer.CCode = txtCustomerCode.Text.Trim(); newCustomer.CName = txtCustomerName.Text.Trim(); newCustomer.Address = txtCustomerAddress.Text.Trim(); newCustomer.PRVID = cboProvince.SelectedValue.ToString(); newCustomer.Phone = txtCustomerPhone.Text.Trim(); newCustomer.Discount = Convert.ToInt32(txtDiscount.Text.Trim()); bool save = serviceCustomer.Save(newCustomer); if (save) { MessageBox.Show("เพิ่มลูกค้า เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information); loadData(); } else { MessageBox.Show("ไม่สามารถ เพิ่มลูกค้า ใหม่ได้!!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("มีลูกค้า นี้อยู่แล้ว!!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("ไม่สามารถ เพิ่มลูกค้า ได้ เนื่องจาก !!! : " + ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public void ShowOrderForm(UserAccount user,LoginForm loginForm, Customer customer) { foreach (Form form in Application.OpenForms) { if (String.Compare(form.Name, "OrderForm") == 0) { form.Show(); return; } } orderForm = new OrderForm(user, loginForm, customer); orderForm.Show(); }
// Begin CREATE CUSTOMER button click event private void btnCreateCustomer_Click(object sender, EventArgs e) { // BEGIN USER INPUT DATA VALIDATION..... // Verify that PERSONAL information was not left blank if ((tbx_FirstName.Text == "") || (tbx_LastName.Text == "") || (tbx_PhoneNumber.Text == "") || (tbx_EMail.Text == "")) { // If any personal information was blank, display error and break code ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the personal fields and try again."); return; } // Verify that MAILING address information was not left blank if ((tbx_MailingStreetNumber.Text == "") || (tbx_MailingStreetName.Text == "") || (tbx_MailingCity.Text == "") || (tbx_MailingState.Text == "") || (tbx_MailingZipCode.Text == "")) { // If any mailing address information was blank, display error and break code ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the mailing address fields and try again."); return; } // Verify that BILLING address information was not left blank if ((tbx_BillingStreetNumber.Text == "") || (tbx_BillingStreetName.Text == "") || (tbx_BillingCity.Text == "") || (tbx_BillingState.Text == "") || (tbx_BillingZipCode.Text == "")) { // If any billing address information was blank, display error and break code ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the billing address fields and try again."); return; } // Variable used in TryParse functions long number; // Validate numeric input for phone number if ((!long.TryParse((tbx_PhoneNumber.Text), out number)) || (tbx_PhoneNumber.Text.Length != 10)) { // If phone number input was not numeric, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid phone number entered. Please enter 10 digits (no dashes) & try again."); return; } // validate email address format if (!ApplicationObjects.EmailIsValid(tbx_EMail.Text)) { // If email address was not in specified format, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid e-mail address entered. Please try again."); return; } // Validate numeric input for street numbers if ((!long.TryParse((tbx_MailingStreetNumber.Text), out number)) || (!long.TryParse((tbx_BillingStreetNumber.Text), out number))) { // If street number input was not numeric, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid street number entered. Please enter only numeric values & try again."); return; } // Verify that the state is only 2 characters if ((tbx_MailingState.Text.Length != 2) || (tbx_BillingState.Text.Length != 2)) { // If state input does not have only 2 characters, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid state entered. Please enter a 2-letter state abbreviation & try again."); return; } // Validate numeric input for zip codes if ((!long.TryParse((tbx_MailingZipCode.Text), out number)) || (!long.TryParse((tbx_BillingZipCode.Text), out number))) { // If zip code input was not numeric, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid zip code entered. Please enter only numeric values & try again."); return; } // If zip is numeric, validate only 5 digits else if ((tbx_MailingZipCode.Text.Length != 5) || (tbx_BillingZipCode.Text.Length != 5)) { // If zip code does not have only 5 characters, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid zip code entered. Please enter only 5 digits & try again."); return; } // .....END USER INPUT DATA VALIDATION // Populate customer object with user input Customer customer = new Customer(); customer.FirstName = tbx_FirstName.Text; customer.LastName = tbx_LastName.Text; customer.PhoneNumber = tbx_PhoneNumber.Text; customer.EmailAddress = tbx_EMail.Text; // Populate mailing address object with user input Address mailingAddress = new Address(); mailingAddress.PersonId = customer.PersonId; mailingAddress.StreetNumber = int.Parse(tbx_MailingStreetNumber.Text); mailingAddress.StreetName = tbx_MailingStreetName.Text; mailingAddress.AddressCity = tbx_MailingCity.Text; mailingAddress.AddressState = tbx_MailingState.Text; mailingAddress.AddressZip = tbx_MailingZipCode.Text; mailingAddress.AddressType = AddressType.Mailing; // Populate billing address object with user input Address billingAddress = new Address(); billingAddress.PersonId = customer.PersonId; billingAddress.StreetNumber = int.Parse(tbx_BillingStreetNumber.Text); billingAddress.StreetName = tbx_BillingStreetName.Text; billingAddress.AddressCity = tbx_BillingCity.Text; billingAddress.AddressState = tbx_BillingState.Text; billingAddress.AddressZip = tbx_BillingZipCode.Text; billingAddress.AddressType = AddressType.Billing; // Transaction to perform 4 inter-related data inserts on multiple database tables using (TransactionScope scope = new TransactionScope()) { int returnValue = 1; // Write PERSON record to database BusinessObjects _personBusinessObject = new BusinessObjects(); returnValue = _personBusinessObject.InsertPersonFromCustomer(customer); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return; } // Write CUSTOMER record to database BusinessObjects _customerBusinessObject = new BusinessObjects(); returnValue = _customerBusinessObject.InsertCustomer(customer); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return; } // Write MAILING ADDRESS record to database BusinessObjects _mailingAddressBusinessObject = new BusinessObjects(); returnValue = _mailingAddressBusinessObject.InsertAddress(mailingAddress); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return; } // Write BILLING ADDRESS record to database BusinessObjects _billingAddressBusinessObject = new BusinessObjects(); returnValue = _billingAddressBusinessObject.InsertAddress(billingAddress); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return; } // Committ data transaction & display success message scope.Complete(); ApplicationObjects.DisplayDataStatus(returnValue); }// End transaction _loginForm.ShowCustomerInfoForm(userAccount, _loginForm); this.Close(); }
public static int CreateCustomer(Customer customer) { BusinessObjects _businessObjects = new BusinessObjects(); return _businessObjects.InsertPersonFromCustomer(customer); }
// CUSTOMER METHODS public static int UpdateCustomer(Customer customer) { // Transaction to perform 4 inter-related data inserts on multiple database tables using (TransactionScope scope = new TransactionScope()) { int returnValue = 1; // Write PERSON record to database BusinessObjects _personBusinessObject = new BusinessObjects(); returnValue = _personBusinessObject.UpdatePersonFromCustomer(customer); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return 1; } // Write MAILING ADDRESS record to database BusinessObjects _mailingAddressBusinessObject = new BusinessObjects(); returnValue = _mailingAddressBusinessObject.UpdateAddress(customer.MailingAddress); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return 1; } // Write BILLING ADDRESS record to database BusinessObjects _billingAddressBusinessObject = new BusinessObjects(); returnValue = _billingAddressBusinessObject.UpdateAddress(customer.BillingAddress); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return 1; } // Committ data transaction & display success message scope.Complete(); ApplicationObjects.DisplayDataStatus(returnValue); return 0; }// End transaction }
private void btnSave_Click(object sender, EventArgs e) { //populate objects with UI data //ORDER OrderStatus orderStatus = (OrderStatus)Enum.Parse(typeof(OrderStatus), this.cboxOrderStatus.Text); order.OrderStatus = orderStatus; //CUSTOMER char[] delimiterChars = { ' ' }; string[] names = this.txtCustomer.Text.Split(delimiterChars); Address mailingAddress = new Address { StreetNumber = Convert.ToInt32(this.txtStreetNumber.Text), StreetName = this.txtStreetName.Text, AddressCity = this.txtCity.Text, AddressState = this.txtState.Text, AddressZip = this.txtZipcode.Text }; Address billingAddress = new Address { StreetNumber = Convert.ToInt32(this.txtBillingStreetNumber.Text), StreetName = this.txtBillingStreetName.Text, AddressCity = this.txtBillingCity.Text, AddressState = this.txtBillingState.Text, AddressZip = this.txtBillingZipcode.Text }; Customer customer = new Customer { CustomerId = Guid.NewGuid(), FirstName = names[0], LastName = names[1], PhoneNumber = this.txtPhoneNumber.Text, EmailAddress = this.txtEmail.Text, MailingAddress = mailingAddress, BillingAddress = billingAddress }; order.Person = (Person)customer; if (order != null && customer != null) { int returnValue = ApplicationObjects.CreateCustomer(customer); if (returnValue == 0) returnValue = ApplicationObjects.CreateOrder(order); ApplicationObjects.DisplayDataStatus(returnValue); if (returnValue == 0) { //Return to order list _loginForm.ShowOrdersForm(userAccount, _loginForm); this.Close(); } } }