private void LoadData()
        {
            companyMaintenanceBL = new CompanyMaintenanceBL();
            DataSet initialData = companyMaintenanceBL.GetInitialData(out errorId);

            companyMaintenanceBL = null;

            if (initialData.Tables.Count != 0 && errorId != 2)
            {
                ddlCurrency.DataSource     = initialData.Tables[0];
                ddlCurrency.DataTextField  = "currency_data";
                ddlCurrency.DataValueField = "currency_code";
                ddlCurrency.DataBind();
                ddlCurrency.Items.Insert(0, new ListItem("-"));

                ddlAccountCompany.DataSource     = initialData.Tables[1];
                ddlAccountCompany.DataTextField  = "accountcompany_data";
                ddlAccountCompany.DataValueField = "accountcompany_code";
                ddlAccountCompany.DataBind();
                ddlAccountCompany.Items.Insert(0, new ListItem("-"));

                if (Request.QueryString != null && Request.QueryString.Count > 0)
                {
                    txtCompanySearch.Text  = Request.QueryString[0];
                    hdnIsValidSearch.Value = "Y";
                    LoadCompanyData();
                }
            }
            else
            {
                ExceptionHandler("Error in fetching filter list data", string.Empty);
            }
        }
        private void LoadCompanyData()
        {
            int companyCode = Convert.ToInt32(txtCompanySearch.Text.Split('-')[0].ToString().Trim());

            companyMaintenanceBL = new CompanyMaintenanceBL();
            DataSet companyData = companyMaintenanceBL.GetSearchedCompanyData(companyCode, out errorId);

            companyMaintenanceBL = null;

            if (companyData.Tables.Count != 0 && errorId != 2)
            {
                txtCompanyName.Text      = companyData.Tables[0].Rows[0]["company_name"].ToString();
                txtDescription.Text      = companyData.Tables[0].Rows[0]["company_desc"].ToString();
                txtAddress1.Text         = companyData.Tables[0].Rows[0]["company_add1"].ToString();
                txtAddress2.Text         = companyData.Tables[0].Rows[0]["company_add2"].ToString();
                txtAddress3.Text         = companyData.Tables[0].Rows[0]["company_add3"].ToString();
                txtAddress4.Text         = companyData.Tables[0].Rows[0]["company_add4"].ToString();
                txtDomesticCurrency.Text = companyData.Tables[0].Rows[0]["domestic_currency_group"].ToString();
                txtPaymentThreshold.Text = companyData.Tables[0].Rows[0]["payment_threshold"].ToString();
                txtRecoupedStmt.Text     = companyData.Tables[0].Rows[0]["threshold_recouped"].ToString();
                txtUnrecoupedStmt.Text   = companyData.Tables[0].Rows[0]["threshold_unrecouped"].ToString();
                hdnCompanySearch.Value   = txtCompanySearch.Text;
                hdnChangeNotSaved.Value  = "N";

                string currencyCode = companyData.Tables[0].Rows[0]["currency_code"].ToString().Trim();
                ddlCurrency.ClearSelection();
                ddlCurrency.Items.FindByValue(currencyCode).Selected = true;

                string accountCompany = companyData.Tables[0].Rows[0]["account_company"].ToString().Trim();
                if (!string.IsNullOrWhiteSpace(accountCompany))
                {
                    ddlAccountCompany.ClearSelection();
                    ddlAccountCompany.Items.FindByValue(accountCompany).Selected = true;
                }

                if (companyData.Tables[0].Rows[0]["primary"].ToString() == "Y")
                {
                    cbPrimaryCompany.Checked = true;
                }
                else
                {
                    cbPrimaryCompany.Checked = false;
                }

                if (companyData.Tables[0].Rows[0]["display_vat"].ToString() == "Y")
                {
                    cbDisplayVat.Checked = true;
                }
                else
                {
                    cbDisplayVat.Checked = false;
                }
            }
            else
            {
                ExceptionHandler("Error in fetching companydata", string.Empty);
            }
        }
        protected void btnSaveChanges_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(txtCompanySearch.Text))
                {
                    txtCompanySearch.Enabled = true;
                    btnCancel.Visible        = false;
                    btnCompanyAudit.Visible  = true;

                    string userCode = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString());
                    string isPrimary;
                    string accountCompany;
                    string isDisplayVat;

                    if (cbPrimaryCompany.Checked)
                    {
                        isPrimary = "Y";
                    }
                    else
                    {
                        isPrimary = "N";
                    }


                    if (ddlAccountCompany.SelectedIndex > 0)
                    {
                        accountCompany = ddlAccountCompany.SelectedValue;
                    }
                    else
                    {
                        accountCompany = string.Empty;
                    }

                    if (cbDisplayVat.Checked)
                    {
                        isDisplayVat = "Y";
                    }
                    else
                    {
                        isDisplayVat = "N";
                    }


                    companyMaintenanceBL = new CompanyMaintenanceBL();
                    DataSet companyData = companyMaintenanceBL.InsertCompanyData(txtCompanyName.Text.Trim(), txtDescription.Text.Trim(), txtAddress1.Text.Trim(), txtAddress2.Text.Trim(), txtAddress3.Text.Trim(), txtAddress4.Text.Trim(),
                                                                                 ddlCurrency.SelectedValue, txtDomesticCurrency.Text.Trim(), txtPaymentThreshold.Text.Trim(), txtRecoupedStmt.Text.Trim(), txtUnrecoupedStmt.Text.Trim(),
                                                                                 isPrimary, isDisplayVat, accountCompany, userCode, out errorId);
                    companyMaintenanceBL = null;

                    if (errorId == 1)
                    {
                        msgView.SetMessage("Can not create new company as already a primary company exists.", MessageType.Success, PositionType.Auto);
                    }
                    else if (companyData.Tables.Count != 0 && errorId != 2)
                    {
                        txtCompanySearch.Text  = companyData.Tables[0].Rows[0]["company_code"].ToString() + " - " + companyData.Tables[0].Rows[0]["company_name"].ToString();
                        hdnIsValidSearch.Value = "Y";
                        Session["FuzzySearchAllCompanyList"] = companyData.Tables[1];
                        msgView.SetMessage("New company created successfully.", MessageType.Success, PositionType.Auto);
                    }
                    else
                    {
                        msgView.SetMessage("Failed to create new company.", MessageType.Warning, PositionType.Auto);
                    }

                    hdnChangeNotSaved.Value = "N";
                }
                else if (hdnIsValidSearch.Value == "Y")
                {
                    string userCode    = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString());
                    int    companyCode = Convert.ToInt32(txtCompanySearch.Text.Split('-')[0].ToString().Trim());
                    string isPrimary;
                    string accountCompany;
                    string isDisplayVat;
                    if (cbPrimaryCompany.Checked)
                    {
                        isPrimary = "Y";
                    }
                    else
                    {
                        isPrimary = "N";
                    }

                    if (ddlAccountCompany.SelectedIndex > 0)
                    {
                        accountCompany = ddlAccountCompany.SelectedValue;
                    }
                    else
                    {
                        accountCompany = string.Empty;
                    }

                    if (cbDisplayVat.Checked)
                    {
                        isDisplayVat = "Y";
                    }
                    else
                    {
                        isDisplayVat = "N";
                    }

                    companyMaintenanceBL = new CompanyMaintenanceBL();
                    DataSet companyData = companyMaintenanceBL.UpdateCompanyData(companyCode, txtCompanyName.Text.Trim(), txtDescription.Text.Trim(), txtAddress1.Text.Trim(), txtAddress2.Text.Trim(), txtAddress3.Text.Trim(), txtAddress4.Text.Trim(),
                                                                                 ddlCurrency.SelectedValue, txtDomesticCurrency.Text.Trim(), txtPaymentThreshold.Text.Trim(), txtRecoupedStmt.Text.Trim(),
                                                                                 txtUnrecoupedStmt.Text.Trim(), isPrimary, isDisplayVat, accountCompany, userCode, out errorId);
                    companyMaintenanceBL = null;

                    if (errorId == 1)
                    {
                        msgView.SetMessage("Can not update company details as already a primary company exists.", MessageType.Success, PositionType.Auto);
                    }
                    else if (errorId == 0)
                    {
                        msgView.SetMessage("Company details updated successfully.", MessageType.Success, PositionType.Auto);
                    }
                    else
                    {
                        msgView.SetMessage("Failed to update company details.", MessageType.Warning, PositionType.Auto);
                    }

                    hdnChangeNotSaved.Value = "N";
                }
                else if (hdnIsValidSearch.Value == "N")
                {
                    msgView.SetMessage("Please select a valid company from serach list.", MessageType.Warning, PositionType.Auto);
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler("Error in saving data.", ex.Message);
            }
        }