protected void btnSaveChanges_Click(object sender, EventArgs e)
        {
            try
            {
                DataSet updateData;
                Page.Validate("valSave");
                if (!Page.IsValid)
                {
                    //WUIN-1023 Commented below code because validation marks '*' vanishing after colsing this message pop up.
                    //msgView.SetMessage("Transactions not saved – invalid or missing data!", MessageType.Warning, PositionType.Auto);
                    return;
                }
                else
                {
                    Array modifiedRowList = ModifiedRowsList();
                    Array deletedRowsList = DeletedRowsList();

                    if (modifiedRowList.Length == 0 && deletedRowsList.Length == 0)
                    {
                        msgView.SetMessage("No changes made to save!", MessageType.Warning, PositionType.Auto);
                        return;
                    }

                    transactionMaintenanceBL = new TransactionMaintenanceBL();
                    updateData = transactionMaintenanceBL.UpdateTransactionDetails(txtSellerSearch.Text.Trim() == string.Empty ? "" : txtSellerSearch.Text.Split('-')[0].Trim(),
                                                                                   txtSalesTypeSearch.Text.Trim() == string.Empty ? "" : txtSalesTypeSearch.Text.Split('-')[0].Trim(), txtReceivedDateSearch.Text.Contains('_') ? "" : txtReceivedDateSearch.Text,
                                                                                   txtReportedDateSearch.Text.Contains('_') ? "" : txtReportedDateSearch.Text, txtCatalogueNumber.Text == string.Empty ? "" : txtCatalogueNumber.Text.ToUpper().Trim(),
                                                                                   ddlCompany.SelectedValue, modifiedRowList, deletedRowsList, Convert.ToString(Session["UserCode"]), out errorId);
                    transactionMaintenanceBL = null;

                    if (errorId == 2 || updateData.Tables.Count == 0)
                    {
                        ExceptionHandler("Error in saving transactions", string.Empty);
                    }
                    else if (errorId == 0 || errorId == 1)
                    {
                        LoadGridData(updateData.Tables[0], true);

                        //any of transactions selected to delete are present in TRANS_PART table and are not deleted
                        if (errorId == 1)
                        {
                            msgView.SetMessage("One or more selected transactions to be deleted have participants and cannot be deleted. Rest are deleted.", MessageType.Warning, PositionType.Auto);
                        }
                        else
                        {
                            msgView.SetMessage("Transaction updated Successfully.!", MessageType.Warning, PositionType.Auto);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler("Error in saving transactions", ex.Message);
            }
        }
        protected void btnSaveTransactions_Click(object sender, EventArgs e)
        {
            try
            {
                Page.Validate("valGrpAddTransactions");
                if (!Page.IsValid)
                {
                    mpeAddTransactionDetailsPopup.Show();
                }
                else
                {
                    System.Globalization.DateTimeFormatInfo mfi = new System.Globalization.DateTimeFormatInfo();
                    string receivedDate = txtReceivedDateAddTrans.Text.Substring(0, 2) + "/" + mfi.GetMonthName(Convert.ToInt32(txtReceivedDateAddTrans.Text.Substring(3, 2))).Substring(0, 3) + "/" + txtReceivedDateAddTrans.Text.Substring(6, 4);
                    string reportedDate = txtAddTransReportedDate.Text.Substring(0, 2) + "/" + mfi.GetMonthName(Convert.ToInt32(txtAddTransReportedDate.Text.Substring(3, 2))).Substring(0, 3) + "/" + txtAddTransReportedDate.Text.Substring(6, 4);

                    transactionMaintenanceBL = new TransactionMaintenanceBL();
                    transactionMaintenanceBL.AddTransactionDetails(receivedDate,
                                                                   txtAddTransSalesType.Text.Trim() == string.Empty ? "" : txtAddTransSalesType.Text.Split('-')[0].Trim(), txtAddTransSales1.Text == string.Empty ? "" : txtAddTransSales1.Text,
                                                                   txtAddTransReceipts.Text == string.Empty ? "" : txtAddTransReceipts.Text, txtAddTransDolExchRate.Text == string.Empty ? "" : txtAddTransDolExchRate.Text,
                                                                   reportedDate, txtAddTransPrice1.Text == string.Empty ? "" : txtAddTransPrice1.Text,
                                                                   txtAddTransSales2.Text == string.Empty ? "" : txtAddTransSales2.Text, txtAddTransReceipts2.Text == string.Empty ? "" : txtAddTransReceipts2.Text,
                                                                   txtAddTransCurrencyCode.Text == string.Empty ? "" : txtAddTransCurrencyCode.Text.ToUpper(), txtAddTransCatNo.Text == string.Empty ? "" : txtAddTransCatNo.Text.ToUpper().Trim(),
                                                                   txtAddTransPrice2.Text == string.Empty ? "" : txtAddTransPrice2.Text, txtAddTransSales3.Text == string.Empty ? "" : txtAddTransSales3.Text,
                                                                   txtAddTransReceipts3.Text == string.Empty ? "" : txtAddTransReceipts3.Text, txtAddTransWhtTax.Text == string.Empty ? "" : txtAddTransWhtTax.Text,
                                                                   txtAddTransTerritory.Text.Trim() == string.Empty ? "" : txtAddTransTerritory.Text.Split('-')[0].Trim(), txtAddTransPrice3.Text == string.Empty ? "" : txtAddTransPrice3.Text,
                                                                   txtAddTransDestinationCountry.Text == string.Empty ? "" : txtAddTransDestinationCountry.Text,
                                                                   ddlAddTransCompanyCode.SelectedValue == "-" ? hdnCompanyCode.Value : ddlAddTransCompanyCode.SelectedValue, txtAddTransOwnerShare.Text == string.Empty ? "" : txtAddTransOwnerShare.Text,
                                                                   txtAddTransTotalShare.Text == string.Empty ? "" : txtAddTransTotalShare.Text, Convert.ToString(Session["UserCode"]), out errorId);
                    transactionMaintenanceBL = null;

                    if (errorId == 2)
                    {
                        ExceptionHandler("Error in saving transactions", string.Empty);
                    }
                    else if (errorId == 0)
                    {
                        msgView.SetMessage("Transaction saved successfully.!", MessageType.Warning, PositionType.Auto);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler("Error in saving transactions", ex.Message);
            }
        }
        private void SearchedData()
        {
            DataSet searchedData;

            Page.Validate("valGrpSearch");
            if (!Page.IsValid)
            {
                return;
            }
            else
            {
                transactionMaintenanceBL = new TransactionMaintenanceBL();
                searchedData             = transactionMaintenanceBL.GetSearchedTransactionsData(txtSellerSearch.Text.Trim() == string.Empty ? "" : txtSellerSearch.Text.Split('-')[0].Trim(), txtSalesTypeSearch.Text.Trim() == string.Empty ? "" : txtSalesTypeSearch.Text.Split('-')[0].Trim(), txtReceivedDateSearch.Text.Contains('_') ? "" : txtReceivedDateSearch.Text, txtReportedDateSearch.Text.Contains('_') ? "" : txtReportedDateSearch.Text, txtCatalogueNumber.Text == string.Empty ? "" : txtCatalogueNumber.Text.Replace("'", "").Trim().ToUpper(), ddlCompany.SelectedValue == "-" ? "" : ddlCompany.SelectedValue, out errorId);
            }
            transactionMaintenanceBL = null;

            if (searchedData.Tables.Count != 0 && errorId != 2)
            {
                LoadGridData(searchedData.Tables[0], false);
            }
        }
        private void LoadInitialData()
        {
            try
            {
                tdTrans.Visible          = false;
                transactionMaintenanceBL = new TransactionMaintenanceBL();
                DataSet fuzzySearchData = transactionMaintenanceBL.GetInitialData(out errorId);

                if (fuzzySearchData.Tables.Count != 0)
                {
                    catNoList     = fuzzySearchData.Tables[0];
                    currencyList  = fuzzySearchData.Tables[1];
                    dtCountryCode = fuzzySearchData.Tables[3];
                    Session["TransMaintCatnoList"]             = catNoList;
                    Session["TransMaintCurrencyList"]          = currencyList;
                    Session["TransMaintCountryList"]           = dtCountryCode;
                    Session["TransactionMaintCompanyCodeList"] = fuzzySearchData.Tables[2];
                    DataRow[] foundRows = fuzzySearchData.Tables[2].Select("primary = 'Y'");
                    if (foundRows.Length != 0)
                    {
                        DataTable dtPrimary = foundRows.CopyToDataTable();
                        hdnCompanyCode.Value = dtPrimary.Rows[0]["company_code"].ToString();
                    }
                    if (Session["FuzzySearchPriceGroupListTypeC"] == null)
                    {
                        DataSet dsList = new FuzzySearchBL().GetFuzzySearchList("GetPriceGroupListTypeC", out errorId);
                        Session["FuzzySearchPriceGroupListTypeC"] = dsList.Tables[0];
                    }

                    ddlAddTransCompanyCode.DataTextField  = "company_name";
                    ddlAddTransCompanyCode.DataValueField = "company_code";
                    ddlAddTransCompanyCode.DataSource     = fuzzySearchData.Tables[2];
                    ddlAddTransCompanyCode.DataBind();
                    ddlAddTransCompanyCode.Items.Insert(0, new ListItem("-"));
                    if (ddlAddTransCompanyCode.Items.FindByValue(hdnCompanyCode.Value) != null)
                    {
                        ddlAddTransCompanyCode.Items.FindByValue(hdnCompanyCode.Value).Selected = true;
                    }
                    else
                    {
                        ddlAddTransCompanyCode.SelectedIndex = 0;
                    }

                    ddlCompany.DataTextField  = "company_name";
                    ddlCompany.DataValueField = "company_code";
                    ddlCompany.DataSource     = fuzzySearchData.Tables[2];
                    ddlCompany.DataBind();
                    ddlCompany.Items.Insert(0, new ListItem("-"));
                    if (ddlCompany.Items.FindByValue(hdnCompanyCode.Value) != null)
                    {
                        ddlCompany.Items.FindByValue(hdnCompanyCode.Value).Selected = true;
                    }
                    else
                    {
                        ddlCompany.SelectedIndex = 0;
                    }
                }

                gvTransactions.DataSource = dtEmpty;
                gvTransactions.DataBind();
            }
            catch (Exception ex)
            {
                ExceptionHandler("Error in load initial data.", ex.Message);
            }
        }