Example #1
0
        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");
                }
            }
        }