private void btnSubmit_Click(object sender, System.EventArgs e) { BranchNL branch = new BranchNL(); DataAccess da = new DataAccess(CBSAppUtils.PrimaryConnectionString); if (ViewState["BranchID"] == null) { if (objInvoice.CheckDuplicateBranchCode(Convert.ToInt32(ViewState["BranchID"]), txtBranchCode.Text.Trim(), Convert.ToInt32(Session["CompanyID"]))) { lblErrorDuplicateBranchCode.Visible = true; return; } } RecordSet rs = null; if (branchID == 0) { rs = da.CreateInsertBuffer("Branch"); } else { rs = BranchNL.GetBranchData(branchID); } if (ViewState["CID"] != null) { rs["CompanyID"] = ViewState["CID"].ToString().Trim(); } else { rs["CompanyID"] = Session["CompanyID"].ToString(); } rs["Branch"] = txtName.Text; rs["BranchCode"] = txtBranchCode.Text.Trim(); rs["Address1"] = txtAddress1.Text; rs["Address2"] = txtAddress2.Text; rs["Address3"] = txtAddress3.Text; rs["Address4"] = txtAddress4.Text; rs["Address5"] = txtAddress5.Text; rs["PostCode"] = txtPostCode.Text; rs["Telephone"] = txtTelephone.Text; rs["Fax"] = txtFax.Text; if (cboCountry.SelectedIndex != 0) { rs["CountryID"] = cboCountry.SelectedValue; } else { rs["CountryID"] = DBNull.Value; } if (cboCounty.SelectedIndex != 0) { rs["CountyID"] = cboCounty.SelectedValue; } else { rs["CountyID"] = DBNull.Value; } rs["IsInvoiceLocation"] = chkInvoice.Checked; rs["IsDeliveryLocation"] = chkDelivery.Checked; rs["CurrencyTypeID"] = DBNull.Value; rs["PContact"] = txtPContact.Text; rs["PEmail"] = txtPEmail.Text; rs["PurchaseInvoiceVolume"] = txtPurchaseVolume.Text == "" ? 0 : System.Convert.ToDecimal(txtPurchaseVolume.Text); rs["ActiveSupplierCount"] = txtSupplierCount.Text == "" ? 0 : System.Convert.ToInt32(txtSupplierCount.Text); rs["ActiveCustomerCount"] = txtCustomerCount.Text == "" ? 0 : System.Convert.ToInt32(txtCustomerCount.Text); rs["SalesInvoiceVolume"] = txtSalesVolume.Text == "" ? 0 : System.Convert.ToDecimal(txtSalesVolume.Text); rs["ApproxTurnover"] = txtTurnover.Text == "" ? 0 : System.Convert.ToDecimal(txtTurnover.Text); rs["Website"] = txtWebsite.Text; rs["ModUserId"] = Session["UserID"].ToString(); if (branchID == 0) { if (branch.InsertBranchData(rs) == 0) { Response.Write(branch.ErrorMessage); } else { Response.Redirect("BranchBrowseNL.aspx"); } } else { if (!branch.UpdateBranchData(rs)) { Response.Write(branch.ErrorMessage); } else { Response.Redirect("BranchBrowseNL.aspx"); } } }
private void btnSubmit_Click(object sender, System.EventArgs e) { if (Page.IsValid) { if (CheckDuplicateCompanyName(Convert.ToInt32(Request["CompanyID"]), txtCompanyName.Text.Trim()) == -101) { lblMessage.Text = "Sorry, company name already exist."; return; } Company company = new Company(); DataAccess da = new DataAccess(CBSAppUtils.PrimaryConnectionString); RecordSet rs = null; string strPasswordGUID = System.Guid.NewGuid().ToString().Substring(0, 8).Trim(); if (companyID == 0) { string strNetworkGUID = System.Guid.NewGuid().ToString().Substring(0, 11).Trim(); rs = da.CreateInsertBuffer("Company"); rs["CreateDate"] = DateTime.Now; rs["NetworkID"] = strNetworkGUID; } else { rs = Company.GetCompanyData(companyID); } if (cboCompanyType.SelectedValue.Trim().Equals("2")) { rs["CompanyCode"] = DBNull.Value; } else { rs["CompanyCode"] = txtCompanyCode.Text; } rs["CompanyName"] = txtCompanyName.Text; rs["VATRegNo"] = txtVAT.Text.Trim() + "-" + txtVatNo.Text.Trim(); #region New_TaxCountryNo MODIFIED BY TARAKESHWAR DATE 26-JAN-2006 (11:42 AM) if (ddlCountryTaxNo.SelectedValue.Trim().Equals("Select")) { rs["New_TaxCountryNo"] = DBNull.Value; } else { rs["New_TaxCountryNo"] = ddlCountryTaxNo.SelectedValue; } #endregion #region New_TradersReference MODIFIED BY TARAKESHWAR DATE 26-JAN-2006 (2:42 PM) if (txtTradersReference.Text.Trim() != "") { rs["New_TradersReference"] = txtTradersReference.Text.Trim(); } else { rs["New_TradersReference"] = DBNull.Value; } #endregion rs["CompanyTypeID"] = cboCompanyType.SelectedItem.Value; rs["MemberTypeID"] = cboMemberType.SelectedItem.Value; rs["ModUserId"] = Session["UserID"].ToString(); rs["EmailID"] = txtEmail.Text.Trim(); if (Convert.ToInt32(Session["CompanyTypeID"]) == 0) { rs["ParentCompanyID"] = DBNull.Value; } else { rs["ParentCompanyID"] = iParentCompanyID; } if (Session["NewLook"].ToString() == "1") { if (ViewState["Mode"].ToString() == "ADD") { if (tbAddress1.Text.Trim() != "") { rs["Address1"] = tbAddress1.Text.Trim(); } else { rs["Address1"] = DBNull.Value; } if (tbAddress2.Text.Trim() != "") { rs["Address2"] = tbAddress2.Text.Trim(); } else { rs["Address2"] = DBNull.Value; } if (tbAddress3.Text.Trim() != "") { rs["Address3"] = tbAddress3.Text.Trim(); } else { rs["Address3"] = DBNull.Value; } if (ddlCounty.SelectedIndex != 0) { rs["CountyID"] = ddlCounty.SelectedItem.Text.Trim(); } else { rs["CountyID"] = DBNull.Value; } if (ddlCountry.SelectedIndex != 0) { rs["CountryID"] = ddlCountry.SelectedItem.Text.Trim(); } else { rs["CountryID"] = DBNull.Value; } if (tbPostCode.Text.Trim() != "") { rs["PostCode"] = tbPostCode.Text.Trim(); } else { rs["PostCode"] = DBNull.Value; } if (tbPhoneNo.Text.Trim() != "") { rs["PhoneNumber1"] = tbPhoneNo.Text.Trim(); } else { rs["PhoneNumber1"] = DBNull.Value; } rs["ModDate"] = DateTime.Now; } } else { rs["Address1"] = DBNull.Value; rs["Address2"] = DBNull.Value; rs["Address3"] = DBNull.Value; rs["CountyID"] = DBNull.Value; rs["CountryID"] = DBNull.Value; rs["PostCode"] = DBNull.Value; rs["PhoneNumber1"] = DBNull.Value; rs["ModDate"] = DateTime.Now; } if (companyID == 0) { BranchNL branch = new BranchNL(); RecordSet rsBranch = null; if (Session["NewLook"].ToString() != "1") { rsBranch = da.CreateInsertBuffer("Branch"); rsBranch["Branch"] = txtCompanyName.Text; rsBranch["ModUserId"] = Session["UserID"].ToString(); } da.BeginTransaction(); companyPKID = company.InsertCompanyData(rs, da); if (companyPKID > 0) { if (Session["NewLook"].ToString() != "1") { rsBranch["CompanyID"] = companyPKID; branch.InsertBranchData(rsBranch, da); } } if (da.ErrorCode != DataAccessErrors.Successful) { da.RollbackTransaction(); Response.Write(da.ErrorMessage); } else { da.CommitTransaction(); lblMessage.Text = "Record(s) saved successfully."; } } else { if (!company.UpdateCompanyData(rs)) { Response.Write(company.ErrorMessage); } else { companyPKID = companyID; lblMessage.Text = "Record(s) saved successfully."; } } if (Session["NewLook"].ToString() == "1" && ViewState["Mode"].ToString() == "ADD") { if (companyPKID > 0) { bool bBranchInsertFlag = false; if (objCompany.SaveBranchForNewLook(companyPKID, txtCompanyName.Text.Trim(), txtCompanyCode.Text.Trim(), tbAddress1.Text.Trim(), tbAddress2.Text.Trim(), tbAddress3.Text.Trim(), tbPostCode.Text.Trim(), tbPhoneNo.Text.Trim(), Convert.ToInt32(ddlCounty.SelectedValue), Convert.ToInt32(ddlCountry.SelectedValue), txtEmail.Text.Trim(), Convert.ToInt32(Session["UserID"]), "I")) { bBranchInsertFlag = true; } else { bBranchInsertFlag = false; } if (objCompany.SaveBranchForNewLook(companyPKID, txtCompanyName.Text.Trim(), txtCompanyCode.Text.Trim(), tbDeliveryAddress1.Text.Trim(), tbDeliveryAddress2.Text.Trim(), tbDeliveryAddress3.Text.Trim(), tbDeliveryPostCode.Text.Trim(), tbDeliveryPhoneNo.Text.Trim(), Convert.ToInt32(ddlCountyDelivery.SelectedValue), Convert.ToInt32(ddlCountryDelivery.SelectedValue), txtEmail.Text.Trim(), Convert.ToInt32(Session["UserID"]), "D")) { bBranchInsertFlag = true; } else { bBranchInsertFlag = false; } if (bBranchInsertFlag) { lblMessage.Text = "Record(s) saved successfully."; } else { lblMessage.Text = "Error saving record(s)."; } } } else if (Session["NewLook"].ToString() == "1" && ViewState["Mode"].ToString().Equals("EDIT")) { bool bBranchInsertFlag = false; if (objCompany.UpdateDeliveryAddressBranchForNewLook(Convert.ToInt32(ViewState["SubCompanyID"]), txtCompanyName.Text.Trim(), txtCompanyCode.Text.Trim(), tbDeliveryAddress1.Text.Trim(), tbDeliveryAddress2.Text.Trim(), tbDeliveryAddress3.Text.Trim(), tbDeliveryPostCode.Text.Trim(), tbDeliveryPhoneNo.Text.Trim(), Convert.ToInt32(ddlCountyDelivery.SelectedValue), Convert.ToInt32(ddlCountryDelivery.SelectedValue), txtEmail.Text.Trim(), Convert.ToInt32(Session["UserID"]), "D")) { bBranchInsertFlag = true; } else { bBranchInsertFlag = false; } if (objCompany.UpdateDeliveryAddressBranchForNewLook(Convert.ToInt32(ViewState["SubCompanyID"]), txtCompanyName.Text.Trim(), txtCompanyCode.Text.Trim(), tbAddress1.Text.Trim(), tbAddress2.Text.Trim(), tbAddress3.Text.Trim(), tbPostCode.Text.Trim(), tbPhoneNo.Text.Trim(), Convert.ToInt32(ddlCounty.SelectedValue), Convert.ToInt32(ddlCountry.SelectedValue), txtEmail.Text.Trim(), Convert.ToInt32(Session["UserID"]), "I")) { bBranchInsertFlag = true; } else { bBranchInsertFlag = false; } if (bBranchInsertFlag) { lblMessage.Text = "Record(s) saved successfully."; } else { lblMessage.Text = "Error saving record(s)."; } } } }