protected void ddlCompany_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (ddlCompany.SelectedIndex > 0)
                {
                    txtExchangeRateFactor.Enabled     = true;
                    txtTransactionReceiptDate.Enabled = true;
                    imgBtnInsert.Enabled = true;

                    exchangeRateFactorsBL = new ExchangeRateFactorsBL();
                    DataSet companyData = exchangeRateFactorsBL.GetCompanyData(ddlCompany.SelectedValue, out errorId);
                    exchangeRateFactorsBL = null;

                    if (companyData.Tables.Count != 0 && errorId != 2)
                    {
                        Session["ExchangeRateFactorData"] = companyData.Tables[1];
                        gvExchangeRateDetails.PageIndex   = 0;

                        //WUIN-746 clearing sort hidden files
                        hdnSortExpression.Value = string.Empty;
                        hdnSortDirection.Value  = string.Empty;

                        BindGrid(companyData.Tables[1]);

                        ddlCompany.Items.FindByValue(companyData.Tables[0].Rows[0]["company_code"].ToString()).Selected = true;
                        txtDomesticCurrency.Text         = companyData.Tables[0].Rows[0]["currency_code"].ToString();
                        txtDomesticCurrencyGrouping.Text = companyData.Tables[0].Rows[0]["domestic_currency_group"].ToString();
                    }
                    else
                    {
                        ExceptionHandler("Error in fetching data", string.Empty);
                    }
                }
                else
                {
                    txtDomesticCurrency.Text          = string.Empty;
                    txtDomesticCurrencyGrouping.Text  = string.Empty;
                    txtExchangeRateFactor.Enabled     = false;
                    txtTransactionReceiptDate.Enabled = false;
                    imgBtnInsert.Enabled = false;

                    dtEmpty = new DataTable();
                    gvExchangeRateDetails.DataSource = dtEmpty;
                    gvExchangeRateDetails.DataBind();
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler("Error in selecting company.", ex.Message);
            }
        }
        private void InsertExchangeRateFactor()
        {
            //Validate
            Page.Validate("valInsertExchangeRates");
            if (!Page.IsValid)
            {
                mpeSaveUndo.Hide();
                msgView.SetMessage("Exchange rate factor details not saved – invalid or missing data!", MessageType.Warning, PositionType.Auto);
                return;
            }

            string userCode = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString());
            int    month    = Convert.ToInt32(txtTransactionReceiptDate.Text.Split('/')[0].ToString());
            int    year     = Convert.ToInt32(txtTransactionReceiptDate.Text.Split('/')[1].ToString());

            exchangeRateFactorsBL = new ExchangeRateFactorsBL();
            DataSet updatedData = exchangeRateFactorsBL.InsertExchangeRateFactor(ddlCompany.SelectedValue, month, year, Convert.ToDouble(txtExchangeRateFactor.Text), userCode, out errorId);

            exchangeRateFactorsBL = null;

            if (errorId == 3)
            {
                msgView.SetMessage("Invalid month. Failed to save exchange rate factor details.", MessageType.Warning, PositionType.Auto);
            }
            else if (errorId == 1)
            {
                msgView.SetMessage("Exchange rate factor exists for this month and company.", MessageType.Success, PositionType.Auto);
            }
            else if (updatedData.Tables.Count != 0 && errorId != 2)
            {
                Session["ExchangeRateFactorData"] = updatedData.Tables[0];
                gvExchangeRateDetails.PageIndex   = 0;

                //WUIN-746 clearing sort hidden files
                hdnSortExpression.Value = string.Empty;
                hdnSortDirection.Value  = string.Empty;

                BindGrid(updatedData.Tables[0]);

                hdnInsertDataNotSaved.Value     = "N";
                txtTransactionReceiptDate.Text  = string.Empty;
                txtExchangeRateFactor.Text      = string.Empty;
                gvExchangeRateDetails.PageIndex = 0;
                msgView.SetMessage("Exchange rate factor created successfully.", MessageType.Success, PositionType.Auto);
            }
            else
            {
                msgView.SetMessage("Failed to save exchange rate factor details.", MessageType.Warning, PositionType.Auto);
            }
        }
        private void UpdateExchangeRateFactor()
        {
            if (!string.IsNullOrEmpty(hdnGridRowSelectedPrvious.Value))
            {
                string userCode = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString());
                int    rowIndex = Convert.ToInt32(hdnGridRowSelectedPrvious.Value);

                //Calculate the rowindex for validation
                int rowIndexValidation = (gvExchangeRateDetails.PageIndex * gvExchangeRateDetails.PageSize) + rowIndex;

                Page.Validate("GroupUpdate_" + rowIndexValidation + "");
                if (!Page.IsValid)
                {
                    msgView.SetMessage("Exchange rate factor details not saved – invalid or missing data!", MessageType.Warning, PositionType.Auto);
                    return;
                }

                //int rowIndex = ((GridViewRow)((ImageButton)(e.CommandSource)).NamingContainer).RowIndex;
                string companyCode        = ((HiddenField)gvExchangeRateDetails.Rows[rowIndex].FindControl("hdnCompanyCode")).Value;
                string monthId            = ((HiddenField)gvExchangeRateDetails.Rows[rowIndex].FindControl("hdnMonthId")).Value;
                string exchangeRateFactor = ((TextBox)gvExchangeRateDetails.Rows[rowIndex].FindControl("txtExchangeRateFactor")).Text;

                exchangeRateFactorsBL = new ExchangeRateFactorsBL();
                DataSet updatedData = exchangeRateFactorsBL.UpdateExchangeRateFactor(companyCode, Convert.ToInt32(monthId), Convert.ToDouble(exchangeRateFactor), userCode, out errorId);
                exchangeRateFactorsBL = null;

                if (updatedData.Tables.Count != 0 && errorId != 2)
                {
                    Session["ExchangeRateFactorData"] = updatedData.Tables[0];

                    //WUIN-746 clearing sort hidden files
                    hdnSortExpression.Value = string.Empty;
                    hdnSortDirection.Value  = string.Empty;

                    BindGrid(updatedData.Tables[0]);

                    hdnChangeNotSaved.Value         = "N";
                    hdnGridRowSelectedPrvious.Value = null;
                    msgView.SetMessage("Exchange rate factor details saved successfully.", MessageType.Success, PositionType.Auto);
                }
                else
                {
                    msgView.SetMessage("Failed to save exchange rate factor details.", MessageType.Warning, PositionType.Auto);
                }
            }
        }
        private void LoadData()
        {
            exchangeRateFactorsBL = new ExchangeRateFactorsBL();
            DataSet initialData = exchangeRateFactorsBL.GetInitialData(out errorId);

            exchangeRateFactorsBL = null;

            if (initialData.Tables.Count != 0 && errorId != 2)
            {
                hdnPageNumber.Value       = "1";
                ddlCompany.DataSource     = initialData.Tables[0];
                ddlCompany.DataTextField  = "company_data";
                ddlCompany.DataValueField = "company_code";
                ddlCompany.DataBind();
                ddlCompany.Items.Insert(0, new ListItem("-"));

                if (initialData.Tables.Count > 1)
                {
                    Session["ExchangeRateFactorData"] = initialData.Tables[2];
                    BindGrid(initialData.Tables[2]);

                    ddlCompany.Items.FindByValue(initialData.Tables[1].Rows[0]["company_code"].ToString()).Selected = true;
                    txtDomesticCurrency.Text         = initialData.Tables[1].Rows[0]["currency_code"].ToString();
                    txtDomesticCurrencyGrouping.Text = initialData.Tables[1].Rows[0]["domestic_currency_group"].ToString();
                    txtCompany.Text = ddlCompany.SelectedItem.ToString();

                    ddlCompany.Visible = false;
                    txtCompany.Visible = true;
                }
                else
                {
                    txtExchangeRateFactor.Enabled     = false;
                    txtTransactionReceiptDate.Enabled = false;
                    imgBtnInsert.Enabled = false;

                    ddlCompany.Visible = true;
                    txtCompany.Visible = false;
                }
            }
            else
            {
                ExceptionHandler("Error in fetching data", string.Empty);
            }
        }