private void LoadSupplierSearchData(string supplierNumber, string supplierSiteName)
        {
            if (Session["ContPayeeSupplierList"] == null)
            {
                royaltorId             = txtRoyaltor.Text.Substring(0, txtRoyaltor.Text.IndexOf("-") - 1);
                royContractPayeeSuppBL = new RoyContractPayeeSuppBL();
                DataSet dropdownListData = royContractPayeeSuppBL.GetDropdownData(royaltorId, out errorId);
                royContractPayeeSuppBL  = null;
                Session["SupplierList"] = dropdownListData.Tables["SupplierList"];
                DataTable dtSupplierNumberList = dropdownListData.Tables["SupplierList"].DefaultView.ToTable(true, "supplier");
                Session["ContPayeeSupplierList"] = dtSupplierNumberList;
            }

            DataTable dtSupplierList = (DataTable)Session["SupplierList"];

            DataRow[] drSupplier = dtSupplierList.Select("supplier_number='" + supplierNumber + "' and supplier_site_name='" + supplierSiteName + "'");
            if (drSupplier.Count() > 0)
            {
                LoadSupplierDetails(drSupplier.CopyToDataTable());
            }
            else
            {
                ClearSupplierFields();
            }
        }
        private void SavePayeeSupplier()
        {
            //check if insert/update/delete
            string insertUpdDelete = string.Empty;

            //if (hdnSupplierNumber.Value == string.Empty && txtSupplier.Text != string.Empty)
            //{
            //    //Insert
            //    insertUpdDelete = "I";
            //}
            //else
            if (hdnSupplierDelete.Value == "Y" && hdnSupplierNumber.Value != string.Empty && hdnSupplierSiteName.Value != string.Empty)
            {
                //delete
                insertUpdDelete = "D";
            }
            else if ((txtSupplier.Text != hdnSupplierNumber.Value) || (txtSuppSiteName.Text != hdnSupplierSiteName.Value))
            {
                //update
                insertUpdDelete = "U";
            }
            else if (hdnPayeeCurrency.Value != ddlCurrency.SelectedValue)
            {
                insertUpdDelete = "C";  //WUIN-1233 - Saving currecy alone
            }


            royContractPayeeSuppBL = new RoyContractPayeeSuppBL();
            DataSet payeeSuppData = royContractPayeeSuppBL.SavePayeeSupplier(royaltorId, ddlPayee.SelectedValue, ddlCurrency.SelectedValue, hdnSupplierNumber.Value, txtSupplier.Text, hdnSupplierSiteName.Value, txtSuppSiteName.Text,
                                                                             txtAccCompany.Text, hdnMismatchFlag.Value, insertUpdDelete, Convert.ToString(Session["UserCode"]), out errorId);

            royContractPayeeSuppBL = null;

            //if (errorId == 2 || payeeSuppData.Tables["PayeeSupplier"].Rows.Count == 0)
            if (errorId == 2)
            {
                ExceptionHandler("Error in saving supplier data", string.Empty);
                return;
            }
            //WUIN-1233
            if (hdnPayeeCurrency.Value != ddlCurrency.SelectedValue)
            {
                hdnPayeeCurrency.Value = ddlCurrency.SelectedValue;

                //WUIN-1233 - If currency changed then updating payee list datatable with updated currency code
                DataRow[] dtPayee = ((DataTable)Session["roySuppPayeeList"]).Select("item_value=" + ddlPayee.SelectedValue);
                if (dtPayee.Count() == 1)
                {
                    dtPayee[0]["payee_currency"] = ddlCurrency.SelectedValue;
                }
            }

            LoadSupplierDetails(payeeSuppData.Tables["PayeeSupplier"]);
            Session["SupplierList"] = payeeSuppData.Tables["SupplierList"];
            DataTable dtSupplierNumberList = payeeSuppData.Tables["SupplierList"].DefaultView.ToTable(true, "supplier");

            Session["ContPayeeSupplierList"] = dtSupplierNumberList;


            //new royaltor - redirect to Option periods screen
            //existing royaltor - remain in same screen
            if (isNewRoyaltor == "Y")
            {
                //WUIN-450
                //set screen button enabled = Y
                contractNavigationButtons.SetNewRoyButtonStatus(ContractScreens.PayeeSupplier.ToString());

                //redirect in javascript so that issue of data not saved validation would be handled
                ScriptManager.RegisterStartupScript(this, typeof(Page), "NewRoySave", "RedirectOnNewRoyaltorSave(" + royaltorId + ");", true);
            }
            else
            {
                if (hdnMismatchFlag.Value == "Y")
                {
                    msgView.SetMessage("Payee supplier details saved. Address of payee is different to address of supplier - payments cannot be approved until difference is resolved", MessageType.Warning, PositionType.Auto);
                }
                else if (insertUpdDelete == "C") //WUIN-1233
                {
                    msgView.SetMessage("Payee currency saved", MessageType.Warning, PositionType.Auto);
                }
                else
                {
                    msgView.SetMessage("Payee supplier details saved", MessageType.Warning, PositionType.Auto);
                }
            }

            //reset the values of hidden fields
            hdnMismatchFlag.Value     = "N";
            hdnSupplierDelete.Value   = "N";
            hdnSupplierNumber.Value   = txtSupplier.Text;
            hdnSupplierSiteName.Value = txtSuppSiteName.Text;
            ddlSupplierSite.Items.Clear();
            txtSupplierSearch.Text = string.Empty;
        }
        private void LoadPayeeSupplierData(string intPartyId)
        {
            string  royaltor = string.Empty;
            string  supplierSiteNameRegValue = string.Empty;
            DataSet payeeSuppData            = null;

            if (intPartyId == "-")
            {
                //initial load
                royContractPayeeSuppBL = new RoyContractPayeeSuppBL();
                payeeSuppData          = royContractPayeeSuppBL.GetInitialData(royaltorId, out royaltor, out supplierSiteNameRegValue, out errorId);
                royContractPayeeSuppBL = null;

                if (errorId == 2 || payeeSuppData.Tables.Count == 0)
                {
                    ExceptionHandler("Error in loading supplier data", string.Empty);
                    return;
                }
                txtRoyaltor.Text = royaltor;

                ddlPayee.DataSource     = payeeSuppData.Tables["PayeeList"];
                ddlPayee.DataTextField  = "item_text";
                ddlPayee.DataValueField = "item_value";
                ddlPayee.DataBind();

                Session["roySuppPayeeList"] = payeeSuppData.Tables["PayeeList"];

                if (payeeSuppData.Tables["PayeeList"].Rows.Count == 0)
                {
                    ddlPayee.Items.Insert(0, new ListItem("-"));
                    ddlCurrency.Items.Insert(0, new ListItem("-"));
                    ddlCurrency.SelectedIndex = 0;

                    //Do not allow Supplier selection if no Payees exist for the Royaltor
                    txtSupplierSearch.ReadOnly     = true;
                    btnSupplierFuzzySearch.Enabled = false;
                }
                else
                {
                    //WUIN-1223 Populatating currency only if royaltor has payees.
                    ddlCurrency.DataSource     = payeeSuppData.Tables["CurrencyList"];
                    ddlCurrency.DataTextField  = "currency_code";
                    ddlCurrency.DataValueField = "currency_code";
                    ddlCurrency.DataBind();

                    //select the primary payee on initial load
                    //int intPartyId = Convert.ToInt32(payeeSuppData.Tables["PayeeList"].Compute("min([item_value])", string.Empty));
                    DataRow[] dtPrimaryPayee = payeeSuppData.Tables["PayeeList"].Select("primary_payee='Y'");
                    if (dtPrimaryPayee.Count() == 1)
                    {
                        ddlPayee.SelectedValue    = dtPrimaryPayee[0]["item_value"].ToString();
                        ddlCurrency.SelectedValue = hdnPayeeCurrency.Value = dtPrimaryPayee[0]["payee_currency"].ToString(); //WUIN-1233
                    }

                    DataRow[] dtPayeeAddress = payeeSuppData.Tables["PayeeList"].Select("item_value=" + ddlPayee.SelectedValue + "");
                    if (dtPayeeAddress.Count() == 1)
                    {
                        hdnPayeeName.Value     = dtPayeeAddress[0]["item_text"].ToString();
                        hdnPayeeAddress1.Value = dtPayeeAddress[0]["int_party_add1"].ToString();
                        hdnPayeePostcode.Value = dtPayeeAddress[0]["int_party_postcode"].ToString();
                    }
                }
                Session["SupplierList"] = payeeSuppData.Tables["SupplierList"];
                DataTable dtSupplierNumberList = payeeSuppData.Tables["SupplierList"].DefaultView.ToTable(true, "supplier");
                Session["ContPayeeSupplierList"]  = dtSupplierNumberList;
                hdnSupplierSiteNameRegValue.Value = supplierSiteNameRegValue;
            }
            else
            {
                royContractPayeeSuppBL = new RoyContractPayeeSuppBL();
                payeeSuppData          = royContractPayeeSuppBL.GetPayeeSupplier(royaltorId, intPartyId, out errorId);
                royContractPayeeSuppBL = null;
                //WUIN-1233 Population currecny for selected payee
                DataRow[] dtPayee = ((DataTable)Session["roySuppPayeeList"]).Select("item_value=" + intPartyId);
                if (dtPayee.Count() == 1)
                {
                    ddlCurrency.SelectedValue = hdnPayeeCurrency.Value = dtPayee[0]["payee_currency"].ToString();
                }
            }

            if (errorId == 2 || payeeSuppData.Tables.Count == 0)
            {
                ExceptionHandler("Error in loading supplier data", string.Empty);
                return;
            }

            LoadSupplierDetails(payeeSuppData.Tables["PayeeSupplier"]);

            //assign hidden field values
            hdnSupplierNumber.Value   = txtSupplier.Text;
            hdnSupplierSiteName.Value = txtSuppSiteName.Text;
        }