private void PopulateData() { branchID = System.Convert.ToInt32(Request.QueryString["BranchID"]); RecordSet rs = BranchNL.GetBranchData(branchID); if (rs["Branch"] != DBNull.Value) { txtName.Text = rs["Branch"].ToString(); } if (rs["BranchCode"] != DBNull.Value) { txtBranchCode.Text = rs["BranchCode"].ToString(); } txtAddress1.Text = rs["Address1"].ToString(); txtAddress2.Text = rs["Address2"].ToString(); txtAddress3.Text = rs["Address3"].ToString(); txtAddress4.Text = rs["Address4"].ToString(); try { if (rs["CountryID"] != DBNull.Value) { cboCountry.SelectedValue = System.Convert.ToString(rs["CountryID"]); } } catch { } try { if (rs["CountyID"] != DBNull.Value) { cboCounty.SelectedValue = System.Convert.ToString(rs["CountyID"]); } } catch { } txtPostCode.Text = rs["PostCode"].ToString(); txtTelephone.Text = rs["Telephone"].ToString(); txtFax.Text = rs["Fax"].ToString(); txtAddress5.Text = rs["Address5"].ToString(); txtPContact.Text = rs["PContact"].ToString(); txtPEmail.Text = rs["PEmail"].ToString(); if (rs["IsInvoiceLocation"] != DBNull.Value) { chkInvoice.Checked = (bool)rs["IsInvoiceLocation"]; } if (rs["IsDeliveryLocation"] != DBNull.Value) { chkDelivery.Checked = (bool)rs["IsDeliveryLocation"]; } txtPurchaseVolume.Text = rs["PurchaseInvoiceVolume"].ToString(); txtSupplierCount.Text = rs["ActiveSupplierCount"].ToString(); txtCustomerCount.Text = rs["ActiveCustomerCount"].ToString(); txtSalesVolume.Text = rs["SalesInvoiceVolume"].ToString(); txtTurnover.Text = rs["ApproxTurnover"].ToString(); txtWebsite.Text = rs["Website"].ToString(); }
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"); } } }