private void btnSave_Click(object sender, EventArgs e) { ourCustomer customernewinof = new ourCustomer(customer.CustomerId); //TODO: customer id customernewinof.FirstName = textBoxFirstName.Text; customernewinof.LastName = textBoxLastName.Text; customernewinof.Email = textBoxEmail.Text; customernewinof.DOB = dateTimePickerDOB.Value.ToString("yyyy-MM-dd"); // make it fit to MS SQL customernewinof.MemberCard = textBoxMemberCard.Text; customernewinof.LoyaltyMember = (checkBoxLoyaltyMember.Checked) ? "true" : "false"; customernewinof.Phone = textBoxPhone.Text; customernewinof.Mobile = textBoxmoblie.Text; customernewinof.Fax = textBoxFax.Text; customernewinof.Website = textBoxwebsite.Text; //Todo: update to Database if (customer.SaveCustomer(customernewinof)) { System.Windows.Forms.MessageBox.Show("Record was updated sucessful!"); CloseSave(sender, e); this.Close(); } else { System.Windows.Forms.MessageBox.Show("Record was updated failed!"); } }
private void btnSave_Click(object sender, EventArgs e) { //Todo: create a customer class and set up the vaild data. if (isInformationVaild == true && textBoxMemberCard.Text != null) { customer.FirstName = textBoxFirstName.Text; customer.LastName = textBoxLastName.Text; customer.Email = textBoxEmail.Text; customer.Website = textBoxwebsite.Text; customer.DOB = dateTimePickerDOB.Value.ToString("yyyy-MM-dd"); // make it fit to MS SQL customer.MemberCard = textBoxMemberCard.Text; customer.LoyaltyMember = (checkBoxLoyaltyMember.Checked)?"true":"false"; customer.Phone = textBoxPhone.Text; customer.Mobile = textBox1moblie.Text; customer.Fax = textBoxFax.Text; //2. Update if (customer.SaveCustomer()) { System.Windows.Forms.MessageBox.Show("Record was updated sucessful!"); CloseSave(sender, e); // 3. Check for account, if user does not have one, ask for create one // 3.1 check data base by membercard try { sqlAccess useraccountcheck = new sqlAccess(); if (!useraccountcheck.IsUserExist(customer.MemberCard)) { var confirmfeedback = MessageBox.Show("The member do not have a account. Do you want to create it?", "User create!", MessageBoxButtons.YesNo); if (confirmfeedback == DialogResult.Yes) { CreateNewUserAccount newuseracc = new CreateNewUserAccount(customer.MemberCard); newuseracc.Owner = this; newuseracc.ShowDialog(); } } } catch { MessageBox.Show("Cannot connect with sql server!"); } this.Close(); } else { System.Windows.Forms.MessageBox.Show("Record was updated failed!"); } } else { System.Windows.Forms.MessageBox.Show("There is/are some data invaild. Please check the data again!"); } }