private void btnInsert_Click(object sender, EventArgs e) { try { int MaKH = int.Parse(txtMaKH.Text); string HoTen = txtHoTen.Text; string GioiTinh = cbGioiTinh.SelectedItem.ToString(); string DiaChi = txtDiaChi.Text; string Phone = txtDienThoai.Text; string ThanhPho = txtThanhPho.Text; string status = ""; status = Customer.Insert(MaKH, HoTen, GioiTinh, DiaChi, Phone, ThanhPho); if (status != "Successful") { throw new Exception(status); } MessageBox.Show("Thêm thành công", "STATUS", MessageBoxButtons.OK, MessageBoxIcon.Information); Reset(); } catch (FormatException exception) { MessageBox.Show("Mã không hợp lệ!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception exception) { MessageBox.Show(exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected void btnSave_Click(object sender, EventArgs e) { #region ServerSide Validation #endregion ServerSide Validations CustomerENT entCustomer = new CustomerENT(); CustomerBAL balCustomer = new CustomerBAL(); #region Gather Data if (txtCustomerName.Text.Trim() != String.Empty) { entCustomer.CustomerName = txtCustomerName.Text.Trim(); } if (txtEmailAddress.Text.Trim() != String.Empty) { entCustomer.EmailID = txtEmailAddress.Text.Trim(); } if (txtMobileNo.Text.Trim() != String.Empty) { entCustomer.MobileNo = txtMobileNo.Text.Trim(); } if (txtAddress.Text.Trim() != String.Empty) { entCustomer.Address = txtAddress.Text.Trim(); } entCustomer.CreationDate = DateTime.Now; entCustomer.UserID = Convert.ToInt32(Session["UserID"]); if (Request.QueryString["CustomerID"] == null) { balCustomer.Insert(entCustomer); lblMessage.Text = "Data Insert SuccessFully"; ClearControl(); } else { entCustomer.CustomerID = Convert.ToInt32(Request.QueryString["CustomerID"]); balCustomer.Update(entCustomer); Response.Redirect("~/AdminPanel/Customer/CustomerList.aspx"); } #endregion Gather Data }
private void btnSave_Click(object sender, EventArgs e) { int maKH = int.Parse(txtMaKH.Text); string HoTen = txtFullName.Text; string DiaChi = txtAddress.Text; string Phone = txtPhoneNumber.Text; string Gender = cbGender.SelectedItem.ToString(); string City = txtThanhPho.Text; try { string status = Customer.Insert(maKH, HoTen, Gender, DiaChi, Phone, City); if (status != "Successful") { throw new Exception(status); } MessageBox.Show("Ghi thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception exception) { MessageBox.Show(exception.Message, "LỖI", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected void btnSave_Click(object sender, EventArgs e) { try { #region Server Side Validation String strError = String.Empty; if (txtCustomerName.Text.Trim() == String.Empty) { strError += "- Enter Customer Name<br />"; } if (txtMobileNo.Text.Trim() == String.Empty) { strError += "- Enter Mobile No<br />"; } if (txtCustomerAddress.Text.Trim() == String.Empty) { strError += "- Enter Customer Address<br />"; } if (ddlBranchID.SelectedIndex == 0) { strError += "- Select Branch<br />"; } if (ddlDistributorID.SelectedIndex == 0) { strError += "- Select Distributor<br />"; } if (ddlProductID.SelectedIndex == 0) { strError += "- Select Product<br />"; } if (txtQuantity.Text.Trim() == String.Empty) { strError += "- Enter Quantity<br />"; } if (txtAmount.Text.Trim() == String.Empty) { strError += "- Enter Bottle Amount<br />"; } #endregion Server Side Validation CustomerENT entCustomer = new CustomerENT(); CustomerBAL balCustomer = new CustomerBAL(); #region Gather Data if (txtCustomerName.Text.Trim() != String.Empty) { entCustomer.CustomerName = txtCustomerName.Text.Trim(); } if (txtMobileNo.Text.Trim() != String.Empty) { entCustomer.MobileNo = txtMobileNo.Text.Trim(); } if (txtCustomerAddress.Text.Trim() != String.Empty) { entCustomer.Address = txtCustomerAddress.Text.Trim(); } if (ddlBranchID.SelectedIndex > 0) { entCustomer.BranchID = Convert.ToInt32(ddlBranchID.SelectedValue); } if (ddlDistributorID.SelectedIndex > 0) { entCustomer.DistributorID = Convert.ToInt32(ddlDistributorID.SelectedValue); } if (ddlProductID.SelectedIndex > 0) { entCustomer.ProductID = Convert.ToInt32(ddlProductID.SelectedValue); } if (txtQuantity.Text.Trim() != String.Empty) { entCustomer.Quantity = Convert.ToInt32(txtQuantity.Text.Trim()); } if (txtAmount.Text.Trim() != String.Empty) { entCustomer.BottlePrice = Convert.ToDecimal(txtAmount.Text.Trim()); } entCustomer.UserID = Convert.ToInt32(Session["UserID"]); if (Request.QueryString["CustomerID"] == null) { balCustomer.Insert(entCustomer); lblMessage.Text = "Data Inserted Successfully"; ClearControls(); } else { entCustomer.CustomerID = Convert.ToInt32(Request.QueryString["CustomerID"]); balCustomer.Update(entCustomer); Response.Redirect("~/AdminPanel/Customer/CustomerList.aspx"); } #endregion Gather Data } catch (Exception ex) { lblErrorMessage.Text = ex.Message.ToString(); } }