protected void SaveButton_Click(object sender, EventArgs e)
    {
        UnitHolderRegistration regObj = new UnitHolderRegistration();

        regObj.FundCode   = fundCodeTextBox.Text;
        regObj.BranchCode = branchCodeTextBox.Text;
        regObj.RegNumber  = regNoTextBox.Text;

        renwalObj                = new UnitRenewal();
        renwalObj.RenewalNo      = renewalNumberTextBox.Text.Trim().ToString();
        renwalObj.RenewalDate    = renewalDateTextBox.Text.Trim().ToString();
        renwalObj.RenewalType    = renewalTypeDropDownList.SelectedValue.ToString().ToUpper();
        renwalObj.RenewalUnitQty = Convert.ToInt32(renewalUnitsTextBox.Text.Trim());

        try
        {
            if (renewalBLObj.IsRenewalLock(regObj))
            {
                ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "Popup", "alert('" + msgObj.Error().ToString() + " " + "Renewal Operation is Locked " + "');", true);
            }
            else if (renewalBLObj.IsDuplicateRenewal(regObj, renwalObj))
            {
                ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "Popup", "alert('" + msgObj.Duplicate().ToString() + " " + "Renewal Number " + "');", true);
            }
            else
            {
                int       rowNumber = 1;
                int       line      = 0;
                DataTable dtDino    = opendMFDAO.getTableDinomination();
                DataRow   drDino;
                bool      invalidCert       = false;
                bool      allocateCert      = true;
                int       duplicateCerNoReg = 0;
                string    dino  = "";
                string    cerNo = "";
                foreach (DataGridItem gridItem in dinoGridView.Items)
                {
                    drDino = dtDino.NewRow();
                    TextBox txtDino   = null;
                    TextBox txtCert   = null;
                    TextBox txtWeight = null;
                    txtDino           = (TextBox)(gridItem.FindControl("dinoTextBox"));
                    txtCert           = (TextBox)(gridItem.FindControl("certNoTextBox"));
                    txtWeight         = (TextBox)(gridItem.FindControl("weightTextBox"));
                    duplicateCerNoReg = opendMFDAO.duplicateCerNoReg(regObj, txtDino.Text.ToString(), txtCert.Text.ToString());
                    allocateCert      = unitSaleBLObj.IsCertificateAllocate(regObj, txtDino.Text.ToString(), txtCert.Text.ToString());
                    if (duplicateCerNoReg == 0)
                    {
                        if (opendMFDAO.validationDino(txtDino.Text.ToString().ToUpper(), regObj.FundCode.ToString().ToUpper()) && opendMFDAO.validationWeight(Convert.ToInt32(txtWeight.Text.ToString()), regObj.FundCode.ToString().ToUpper()))
                        {
                            if (allocateCert)
                            {
                                drDino["dino"]        = txtDino.Text.Trim().ToString().ToUpper();
                                drDino["cert_no"]     = Convert.ToInt32(txtCert.Text.Trim().ToString());
                                drDino["cert_weight"] = Convert.ToInt32(txtWeight.Text.Trim().ToString());
                                dtDino.Rows.Add(drDino);
                                rowNumber++;
                            }
                            else
                            {
                                allocateCert = false;
                                line         = rowNumber;
                                dino         = txtDino.Text.Trim().ToString();
                                cerNo        = txtCert.Text.Trim().ToString();
                                break;
                            }
                        }
                        else
                        {
                            invalidCert = true;
                            line        = rowNumber;
                            break;
                        }
                    }
                    else
                    {
                        dino  = txtDino.Text.Trim().ToString();
                        cerNo = txtCert.Text.Trim().ToString();
                        break;
                    }
                }

                if (duplicateCerNoReg > 0)
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "Popup", "alert('Certificate " + dino + "-" + cerNo + " is Already Used to Reg No:" + duplicateCerNoReg + "');", true);
                }
                else
                {
                    if (invalidCert)
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "Popup", "alert('Save Failed!!Invalid Dinomination or Weight at Line: " + line + "');", true);
                    }
                    else if (!allocateCert)
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "Popup", "alert('Save Failed!! Line: " + line + " and Certificate No: " + dino + "-" + cerNo + " is not allocated in this branch');", true);
                    }
                    else if (!invalidCert && allocateCert)
                    {
                        DataTable dtGrid = opendMFDAO.getTableDataGrid();
                        DataRow   drGrid;
                        foreach (DataGridItem gridRow in leftDataGrid.Items)
                        {
                            CheckBox leftCheckBox = (CheckBox)gridRow.FindControl("leftCheckBox");
                            if (leftCheckBox.Checked)
                            {
                                drGrid                = dtGrid.NewRow();
                                drGrid["SL_NO"]       = gridRow.Cells[1].Text.Trim().ToString();
                                drGrid["CERTIFICATE"] = gridRow.Cells[2].Text.Trim().ToString();
                                drGrid["QTY"]         = gridRow.Cells[3].Text.Trim().ToString();
                                dtGrid.Rows.Add(drGrid);
                            }
                        }

                        renewalBLObj.SaveUnitRenewal(regObj, dtGrid, renwalObj, dtDino, userObj);
                        // unitSaleBLObj.SaveUnitSale(regObj, saleObj, dtDino, userObj);
                        ClearText();
                        leftDataGrid.Visible      = false;
                        renewalNumberTextBox.Text = "";
                        regNoTextBox.Text         = "";
                        //saleNumberTextBox.Text = unitSaleBLObj.getNextSaleNo(regObj, userObj).ToString();
                        //saleObj.SaleNo = unitSaleBLObj.getNextSaleNo(regObj, userObj) - 1;
                        //saleDateTextBox.Text = opendMFDAO.getLastSaleDate(regObj, saleObj).ToString("dd-MMM-yyyy");
                        //saleRateTextBox.Text = opendMFDAO.getLastSaleRate(regObj, saleObj).ToString();
                        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "Popup", "alert('" + msgObj.Success().ToString() + "');", true);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "Popup", "alert ('" + msgObj.Error().ToString() + " " + ex.Message.Replace("'", "").ToString() + "');", true);
        }
    }
    protected void SaveButton_Click(object sender, EventArgs e)
    {
        UnitHolderRegistration regObj = new UnitHolderRegistration();

        regObj.FundCode   = fundCodeTextBox.Text;
        regObj.BranchCode = branchCodeTextBox.Text;
        regObj.RegNumber  = regNoTextBox.Text;



        UnitSale saleObj = new UnitSale();

        saleObj.SaleNo = Convert.ToInt32(saleNumberTextBox.Text.Trim().ToString());
        if (MoneyReceiptNoTextBox.Text.Trim() != "")
        {
            saleObj.MoneyReceiptNo = Convert.ToInt32(MoneyReceiptNoTextBox.Text.Trim());
        }
        if (ChqRadioButton.Checked)
        {
            saleObj.PaymentType = ChequeTypeDropDownList.SelectedValue.ToString();
            if (CHQDDNoRemarksTextBox.Text.Trim() != "")
            {
                saleObj.ChequeNo = CHQDDNoRemarksTextBox.Text.Trim().ToString();
            }
            if (chequeDateTextBox.Text.Trim() != "")
            {
                saleObj.ChequeDate = chequeDateTextBox.Text.Trim().ToString();
            }
            if (bankNameDropDownList.SelectedValue.Trim() != "0")
            {
                saleObj.BankCode = Convert.ToInt16(bankNameDropDownList.SelectedValue.ToString());
            }
            if (branchNameDropDownList.SelectedValue.Trim() != "0" && branchNameDropDownList.SelectedValue.Trim() != "")
            {
                saleObj.BranchCode = Convert.ToInt16(branchNameDropDownList.SelectedValue.ToString());
            }
        }
        else if (CashRadioButton.Checked)
        {
            saleObj.PaymentType = "CASH";
            saleObj.CashAmount  = Convert.ToDecimal(Convert.ToDecimal(saleRateTextBox.Text.Trim().ToString()) * Convert.ToInt32(unitQtyTextBox.Text.Trim().ToString()));
        }
        else if (BothRadioButton.Checked)
        {
            saleObj.PaymentType = "BOTH";
            saleObj.ChequeNo    = CHQDDNoRemarksTextBox.Text.Trim().ToString();
            if (CHQDDNoRemarksTextBox.Text.Trim() != "")
            {
                saleObj.ChequeNo = CHQDDNoRemarksTextBox.Text.Trim().ToString();
            }
            if (chequeDateTextBox.Text.Trim() != "")
            {
                saleObj.ChequeDate = chequeDateTextBox.Text.Trim().ToString();
            }
            if (bankNameDropDownList.SelectedValue.Trim() != "0")
            {
                saleObj.BankCode = Convert.ToInt16(bankNameDropDownList.SelectedValue.ToString());
            }
            if (branchNameDropDownList.SelectedValue.Trim() != "0" || branchNameDropDownList.SelectedValue.Trim() != "")
            {
                saleObj.BranchCode = Convert.ToInt16(branchNameDropDownList.SelectedValue.ToString());
            }
            if (CashAmountTextBox.Text.Trim() != "")
            {
                saleObj.CashAmount = Convert.ToDecimal(CashAmountTextBox.Text.Trim().ToString());
            }
        }
        else if (MultiRadioButton.Checked)
        {
            saleObj.PaymentType = "MULTI";
            if (MultiplePayTypeTextBox.Text.Trim() != "")
            {
                saleObj.MultiPayType = MultiplePayTypeTextBox.Text.Trim().ToString();
            }
        }
        saleObj.SaleRate    = Convert.ToDecimal(saleRateTextBox.Text.Trim().ToString());
        saleObj.SaleType    = saleTypeDropDownList.SelectedValue.ToString().ToUpper();
        saleObj.SaleUnitQty = Convert.ToInt32(unitQtyTextBox.Text.Trim().ToString());
        saleObj.SaleDate    = saleDateTextBox.Text.Trim().ToString();
        saleObj.SaleRemarks = saleRemarksTextBox.Text.Trim().ToString();
        int  saleLimitLower  = unitSaleBLObj.SaleLimitLower(regObj);
        long saleLimmitUpper = unitSaleBLObj.SaleLimitUpper(regObj);



        try
        {
            //if (unitSaleBLObj.IsDuplicateSale(regObj, saleObj))// Checking Duplicate Sale No
            //{
            //    ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('" + msgObj.Duplicate().ToString() + " "+"Sale Number "+"');", true);
            //}
            //else
            if (saleLimitLower > Convert.ToInt32(unitQtyTextBox.Text.Trim().ToString()) && saleTypeDropDownList.SelectedValue.ToString() == "SL")
            {
                unitQtyTextBox.Focus();
                ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Sale Unit Quantity can not less than " + saleLimitLower.ToString() + "');", true);
            }
            else if (saleLimmitUpper < Convert.ToInt32(unitQtyTextBox.Text.Trim().ToString()))
            {
                unitQtyTextBox.Focus();
                ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Sale Unit Quantity can not greater than " + saleLimmitUpper.ToString() + "');", true);
            }

            else if (!opendMFDAO.IsValidRegistration(regObj))
            {
                regNoTextBox.Focus();
                ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Invalid Registration Number!!');", true);
            }
            //else if (regObj.FundCode == "IAMPH")
            //{
            //    string errorMessage = "Please Contace with Administrator";
            //    ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Save Failed :" + errorMessage + "');", true);

            //}
            else
            {
                int       loop       = 0;
                DataTable dtSaleInfo = (DataTable)Session["dtSaleInfo"];
                int       rowNumber  = 1;
                int       line       = 0;
                int       countCheck = 0;
                DataTable dtDino     = unitSaleBLObj.getTableDinoForEdit();
                DataRow   drDino;
                bool      invalidCert       = false;
                bool      allocateCert      = true;
                bool      bannedCert        = false;
                int       duplicateCerNoReg = 0;
                string    dino  = "";
                string    cerNo = "";
                foreach (DataGridItem gridItem in dinoGridView.Items)
                {
                    drDino = dtDino.NewRow();
                    TextBox txtDino   = null;
                    TextBox txtCert   = null;
                    TextBox txtWeight = null;
                    TextBox txtStatus = null;
                    txtDino   = (TextBox)(gridItem.FindControl("dinoTextBox"));
                    txtCert   = (TextBox)(gridItem.FindControl("certNoTextBox"));
                    txtWeight = (TextBox)(gridItem.FindControl("weightTextBox"));
                    txtStatus = (TextBox)(gridItem.FindControl("statusTextBox"));
                    CheckBox leftCheckBox = (CheckBox)gridItem.FindControl("leftCheckBox");
                    if (leftCheckBox.Checked)
                    {
                        countCheck++;
                        duplicateCerNoReg = opendMFDAO.duplicateCerNoReg(regObj, txtDino.Text.ToString(), txtCert.Text.ToString());
                        allocateCert      = unitSaleBLObj.IsCertificateAllocate(regObj, txtDino.Text.ToString(), txtCert.Text.ToString());
                        bannedCert        = unitSaleBLObj.IsCertificateBanned(regObj, txtDino.Text.ToString(), txtCert.Text.ToString());
                        if (duplicateCerNoReg == Convert.ToInt32(regNoTextBox.Text.Trim().ToString()) || duplicateCerNoReg == 0)
                        {
                            if (opendMFDAO.validationDino(txtDino.Text.ToString().ToUpper(), regObj.FundCode.ToString().ToUpper()) && opendMFDAO.validationWeight(Convert.ToInt32(txtWeight.Text.ToString()), regObj.FundCode.ToString().ToUpper()))
                            {
                                if (allocateCert)
                                {
                                    if (bannedCert)
                                    {
                                        bannedCert = true;
                                        line       = rowNumber;
                                        dino       = txtDino.Text.Trim().ToString();
                                        cerNo      = txtCert.Text.Trim().ToString();
                                        break;
                                    }
                                    else
                                    {
                                        drDino["dino"]        = txtDino.Text.Trim().ToString().ToUpper();
                                        drDino["cert_no"]     = Convert.ToInt32(txtCert.Text.Trim().ToString());
                                        drDino["cert_weight"] = Convert.ToInt32(txtWeight.Text.Trim().ToString());
                                        drDino["status"]      = txtStatus.Text.Trim().ToString().ToUpper();
                                        drDino["ROWID"]       = dtSaleInfo.Rows[loop]["ROWID"].ToString();
                                        dtDino.Rows.Add(drDino);
                                        rowNumber++;
                                    }
                                }
                                else
                                {
                                    allocateCert = false;
                                    line         = rowNumber;
                                    dino         = txtDino.Text.Trim().ToString();
                                    cerNo        = txtCert.Text.Trim().ToString();
                                    break;
                                }
                            }
                            else
                            {
                                invalidCert = true;
                                line        = rowNumber;
                                break;
                            }
                        }
                        else
                        {
                            dino  = txtDino.Text.Trim().ToString();
                            cerNo = txtCert.Text.Trim().ToString();
                            break;
                        }
                    }
                    loop++;
                }

                if (duplicateCerNoReg > 0 && !(duplicateCerNoReg == Convert.ToInt32(regNoTextBox.Text.Trim().ToString())))
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Certificate " + dino + "-" + cerNo + " is Already Sold to Reg No:" + duplicateCerNoReg + "');", true);
                }
                else
                {
                    if (invalidCert)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Save Failed!!Invalid Dinomination or Weight at Line: " + line + "');", true);
                    }
                    else if (!allocateCert)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Save Failed!! Line: " + line + " and Certificate No: " + dino + "-" + cerNo + " is not allocated in this branch');", true);
                    }
                    else if (bannedCert)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Save Failed!! Line: " + line + " and Certificate No: " + dino + "-" + cerNo + " is banned for sale');", true);
                    }
                    else if (!invalidCert && allocateCert && !bannedCert)
                    {
                        unitSaleBLObj.SaveSaleEditInfo(regObj, saleObj, dtDino, userObj);
                        ClearText();
                        ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('" + msgObj.Success().ToString() + "');", true);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            errorMassege = msgObj.ExceptionErrorMessageString(ex.Message.ToString());
            ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert ('" + msgObj.Error().ToString() + " " + errorMassege.ToString() + "');", true);
        }
    }
    protected void SaveButton_Click(object sender, EventArgs e)
    {
        UnitHolderRegistration regObj = new UnitHolderRegistration();

        regObj.FundCode   = fundCodeTextBox.Text;
        regObj.BranchCode = branchCodeTextBox.Text;
        regObj.RegNumber  = regNoTextBox.Text;



        UnitSale saleObj = new UnitSale();

        saleObj.SaleNo = Convert.ToInt32(saleNumberTextBox.Text.Trim().ToString());
        if (moneyReceipDropDownList.SelectedValue.ToString() != "0")
        {
            saleObj.MoneyReceiptNo = Convert.ToInt32(moneyReceipDropDownList.SelectedItem.Text.ToString());
        }
        if (ChqRadioButton.Checked)
        {
            saleObj.PaymentType = ChequeTypeDropDownList.SelectedValue.ToString();
            if (CHQDDNoRemarksTextBox.Text.Trim() != "")
            {
                saleObj.ChequeNo = CHQDDNoRemarksTextBox.Text.Trim().ToString();
            }
            if (chequeDateTextBox.Text.Trim() != "")
            {
                saleObj.ChequeDate = chequeDateTextBox.Text.Trim().ToString();
            }
            if (bankNameDropDownList.SelectedValue.Trim() != "0")
            {
                saleObj.BankCode = Convert.ToInt16(bankNameDropDownList.SelectedValue.ToString());
            }
            if (branchNameDropDownList.SelectedValue.Trim() != "0" && branchNameDropDownList.SelectedValue.Trim() != "")
            {
                saleObj.BranchCode = Convert.ToInt16(branchNameDropDownList.SelectedValue.ToString());
            }
        }
        else if (CashRadioButton.Checked)
        {
            saleObj.PaymentType = "CASH";
            saleObj.CashAmount  = Convert.ToDecimal(Convert.ToDecimal(saleRateTextBox.Text.Trim().ToString()) * Convert.ToInt32(unitQtyTextBox.Text.Trim().ToString()));
        }
        else if (BothRadioButton.Checked)
        {
            saleObj.PaymentType = "BOTH";
            saleObj.ChequeNo    = CHQDDNoRemarksTextBox.Text.Trim().ToString();
            if (CHQDDNoRemarksTextBox.Text.Trim() != "")
            {
                saleObj.ChequeNo = CHQDDNoRemarksTextBox.Text.Trim().ToString();
            }
            if (chequeDateTextBox.Text.Trim() != "")
            {
                saleObj.ChequeDate = chequeDateTextBox.Text.Trim().ToString();
            }
            if (bankNameDropDownList.SelectedValue.Trim() != "0")
            {
                saleObj.BankCode = Convert.ToInt16(bankNameDropDownList.SelectedValue.ToString());
            }
            if (branchNameDropDownList.SelectedValue.Trim() != "0" || branchNameDropDownList.SelectedValue.Trim() != "")
            {
                saleObj.BranchCode = Convert.ToInt16(branchNameDropDownList.SelectedValue.ToString());
            }
            if (CashAmountTextBox.Text.Trim() != "")
            {
                saleObj.CashAmount = Convert.ToDecimal(CashAmountTextBox.Text.Trim().ToString());
            }
        }
        else if (MultiRadioButton.Checked)
        {
            saleObj.PaymentType = "MULTI";
            if (MultiplePayTypeTextBox.Text.Trim() != "")
            {
                saleObj.MultiPayType = MultiplePayTypeTextBox.Text.Trim().ToString();
            }
        }
        saleObj.SaleRate         = Convert.ToDecimal(saleRateTextBox.Text.Trim().ToString());
        saleObj.SaleType         = saleTypeDropDownList.SelectedValue.ToString().ToUpper();
        saleObj.SaleUnitQty      = Convert.ToInt32(unitQtyTextBox.Text.Trim().ToString());
        saleObj.SaleDate         = saleDateTextBox.Text.Trim().ToString();
        saleObj.SaleRemarks      = saleRemarksTextBox.Text.Trim().ToString();
        saleObj.SellingAgentCode = Convert.ToInt32(sellingAgentCodeTextBox.Text.Trim().ToString());
        int  saleLimitLower  = unitSaleBLObj.SaleLimitLower(regObj);
        long saleLimmitUpper = unitSaleBLObj.SaleLimitUpper(regObj);



        try
        {
            if (unitSaleBLObj.IsSaleLock(regObj))//Cheking Lock in status
            {
                ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('" + msgObj.Error().ToString() + " " + " Sale Operation is Locked " + "');", true);
            }
            else if (unitSaleBLObj.IsDuplicateSale(regObj, saleObj))// Checking Duplicate Sale No
            {
                ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('" + msgObj.Duplicate().ToString() + " " + "Sale Number " + "');", true);
            }
            else if (saleLimitLower > Convert.ToInt32(unitQtyTextBox.Text.Trim().ToString()) && saleTypeDropDownList.SelectedValue.ToString() == "SL")
            {
                unitQtyTextBox.Focus();
                ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Sale Unit Quantity can not less than " + saleLimitLower.ToString() + "');", true);
            }
            else if (saleLimmitUpper < Convert.ToInt32(unitQtyTextBox.Text.Trim().ToString()))
            {
                unitQtyTextBox.Focus();
                ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Sale Unit Quantity can not greater than " + saleLimmitUpper.ToString() + "');", true);
            }
            else
            {
                int       rowNumber = 1;
                int       line      = 0;
                DataTable dtDino    = opendMFDAO.getTableDinomination();
                DataRow   drDino;
                bool      invalidCert       = false;
                bool      allocateCert      = true;
                bool      bannedCert        = false;
                int       duplicateCerNoReg = 0;
                string    dino  = "";
                string    cerNo = "";
                foreach (DataGridItem gridItem in dinoGridView.Items)
                {
                    drDino = dtDino.NewRow();
                    TextBox txtDino   = null;
                    TextBox txtCert   = null;
                    TextBox txtWeight = null;
                    txtDino           = (TextBox)(gridItem.FindControl("dinoTextBox"));
                    txtCert           = (TextBox)(gridItem.FindControl("certNoTextBox"));
                    txtWeight         = (TextBox)(gridItem.FindControl("weightTextBox"));
                    duplicateCerNoReg = opendMFDAO.duplicateCerNoReg(regObj, txtDino.Text.ToString(), txtCert.Text.ToString());
                    allocateCert      = unitSaleBLObj.IsCertificateAllocate(regObj, txtDino.Text.ToString(), txtCert.Text.ToString());
                    bannedCert        = unitSaleBLObj.IsCertificateBanned(regObj, txtDino.Text.ToString(), txtCert.Text.ToString());
                    if (duplicateCerNoReg == 0)
                    {
                        if (saleTypeDropDownList.SelectedValue.ToString().ToUpper() == "CIP")
                        {
                            if (opendMFDAO.validationDino(txtDino.Text.ToString().ToUpper(), regObj.FundCode.ToString().ToUpper()))
                            {
                                if (allocateCert)
                                {
                                    if (bannedCert)
                                    {
                                        bannedCert = true;
                                        line       = rowNumber;
                                        dino       = txtDino.Text.Trim().ToString();
                                        cerNo      = txtCert.Text.Trim().ToString();
                                        break;
                                    }
                                    else
                                    {
                                        drDino["dino"]        = txtDino.Text.Trim().ToString().ToUpper();
                                        drDino["cert_no"]     = Convert.ToInt32(txtCert.Text.Trim().ToString());
                                        drDino["cert_weight"] = Convert.ToInt32(txtWeight.Text.Trim().ToString());
                                        dtDino.Rows.Add(drDino);
                                        rowNumber++;
                                    }
                                }
                                else
                                {
                                    allocateCert = false;
                                    line         = rowNumber;
                                    dino         = txtDino.Text.Trim().ToString();
                                    cerNo        = txtCert.Text.Trim().ToString();
                                    break;
                                }
                            }
                            else
                            {
                                invalidCert = true;
                                line        = rowNumber;
                                break;
                            }
                        }

                        else if (saleTypeDropDownList.SelectedValue.ToString().ToUpper() == "SL")
                        {
                            if (opendMFDAO.validationDino(txtDino.Text.ToString().ToUpper(), regObj.FundCode.ToString().ToUpper()) && opendMFDAO.validationWeight(Convert.ToInt32(txtWeight.Text.ToString()), regObj.FundCode.ToString().ToUpper()))
                            {
                                if (allocateCert)
                                {
                                    if (bannedCert)
                                    {
                                        bannedCert = true;
                                        line       = rowNumber;
                                        dino       = txtDino.Text.Trim().ToString();
                                        cerNo      = txtCert.Text.Trim().ToString();
                                        break;
                                    }
                                    else
                                    {
                                        drDino["dino"]        = txtDino.Text.Trim().ToString().ToUpper();
                                        drDino["cert_no"]     = Convert.ToInt32(txtCert.Text.Trim().ToString());
                                        drDino["cert_weight"] = Convert.ToInt32(txtWeight.Text.Trim().ToString());
                                        dtDino.Rows.Add(drDino);
                                        rowNumber++;
                                    }
                                }
                                else
                                {
                                    allocateCert = false;
                                    line         = rowNumber;
                                    dino         = txtDino.Text.Trim().ToString();
                                    cerNo        = txtCert.Text.Trim().ToString();
                                    break;
                                }
                            }
                            else
                            {
                                invalidCert = true;
                                line        = rowNumber;
                                break;
                            }
                        }
                    }
                    else
                    {
                        dino  = txtDino.Text.Trim().ToString();
                        cerNo = txtCert.Text.Trim().ToString();
                        break;
                    }
                }

                if (duplicateCerNoReg > 0)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Certificate " + dino + "-" + cerNo + " is Already Sold to Reg No:" + duplicateCerNoReg + "');", true);
                }
                else
                {
                    if (invalidCert)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Save Failed!!Invalid Dinomination or Weight at Line: " + line + "');", true);
                    }
                    else if (!allocateCert)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Save Failed!! Line: " + line + " and Certificate No: " + dino + "-" + cerNo + " is not allocated in this branch');", true);
                    }
                    else if (bannedCert)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Save Failed!! Line: " + line + " and Certificate No: " + dino + "-" + cerNo + " is banned for sale');", true);
                    }
                    else if (!invalidCert && allocateCert && !bannedCert)
                    {
                        commonGatewayObj.BeginTransaction();
                        commonGatewayObj.ExecuteNonQuery("UPDATE U_MASTER SET SELLING_AGENT_ID=" + saleObj.SellingAgentCode + "  WHERE  REG_BK='" + regObj.FundCode + "' AND REG_BR='" + regObj.BranchCode + "' AND REG_NO='" + regObj.RegNumber + "' AND SELLING_AGENT_ID IS NULL");
                        commonGatewayObj.ExecuteNonQuery("UPDATE MONEY_RECEIPT SET SL_REP_TR_RN_NO=" + saleObj.SaleNo + "  WHERE ID=" + Convert.ToUInt64(moneyReceipDropDownList.SelectedValue.ToString()));
                        unitSaleBLObj.SaveUnitSale(regObj, saleObj, dtDino, userObj);
                        commonGatewayObj.CommitTransaction();

                        ClearText();
                        moneyReceipDropDownList.DataSource     = unitSaleBLObj.dtMoneyRecieptInfoforDDL(regObj, "SL");
                        moneyReceipDropDownList.DataTextField  = "RECEIPT_NO";
                        moneyReceipDropDownList.DataValueField = "ID";
                        moneyReceipDropDownList.DataBind();

                        ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('" + msgObj.Success().ToString() + "');", true);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            commonGatewayObj.RollbackTransaction();
            errorMassege = msgObj.ExceptionErrorMessageString(ex.Message.ToString());
            ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert ('" + msgObj.Error().ToString() + " " + errorMassege.ToString() + "');", true);
        }
    }