protected void Page_Load(object sender, EventArgs e)
 {
     GetCurrencyControl();
     if (IsPostBack)
     {
         if (CURRENCY_ID.Items.Count > 0)
         {
             Guid gCURRENCY_ID = CommonTypeConvert.ToGuid(CURRENCY_ID.SelectedValue);
             SetCurrency(gCURRENCY_ID, CommonTypeConvert.ToFloat(EXCHANGE_RATE.Value));
             EXCHANGE_RATE.Value = Currency.GetCurrency.CONVERSION_RATE.ToString();
         }
         dtLineItems        = ViewState["LineItems"] as DataTable;
         grdMain.DataSource = dtLineItems;
     }
 }
        public void LoadLineItems(Guid gID, Guid gACCOUNT_ID, Guid gDuplicateID, InlineQueryDBManager oQuery,
                                  SqlDataReader rdr)
        {
            this.gACCOUNT_ID = gACCOUNT_ID;
            if (!IsPostBack)
            {
                GetCurrencyControl();
                CURRENCY_ID.SelectedValue = Currency.GetCurrency.ID.ToString();
                EXCHANGE_RATE.Value       = Currency.GetCurrency.CONVERSION_RATE.ToString();
                foreach (DataControlField col in grdMain.Columns)
                {
                    if (!CommonTypeConvert.IsEmptyString(col.HeaderText))
                    {
                        col.HeaderText = Translation.GetTranslation.Term(col.HeaderText);
                    }
                    var cf = col as CommandField;
                    if (cf != null)
                    {
                        cf.EditText   = Translation.GetTranslation.Term(cf.EditText);
                        cf.DeleteText = Translation.GetTranslation.Term(cf.DeleteText);
                        cf.UpdateText = Translation.GetTranslation.Term(cf.UpdateText);
                        cf.CancelText = Translation.GetTranslation.Term(cf.CancelText);
                    }
                }

                if ((!CommonTypeConvert.IsEmptyGuid(gID) || !CommonTypeConvert.IsEmptyGuid(gDuplicateID)) &&
                    (oQuery != null) && (rdr != null))
                {
                    CURRENCY_ID.SelectedValue = CommonTypeConvert.ToString(rdr["CURRENCY_ID"]);
                    EXCHANGE_RATE.Value       = Currency.GetCurrency.CONVERSION_RATE.ToString();
                    float fEXCHANGE_RATE = CommonTypeConvert.ToFloat(rdr["EXCHANGE_RATE"]);
                    if (fEXCHANGE_RATE == 0.0f)
                    {
                        fEXCHANGE_RATE = 1.0f;
                    }
                    EXCHANGE_RATE.Value = fEXCHANGE_RATE.ToString();
                    if (CURRENCY_ID.Items.Count > 0)
                    {
                        Guid gCURRENCY_ID = CommonTypeConvert.ToGuid(CURRENCY_ID.SelectedValue);
                        SetCurrency(gCURRENCY_ID, fEXCHANGE_RATE);
                        EXCHANGE_RATE.Value = Currency.GetCurrency.CONVERSION_RATE.ToString();
                    }
                    ALLOCATED.Text =
                        Currency.GetCurrency.ToCurrency(CommonTypeConvert.ToDecimal(rdr["TOTAL_ALLOCATED_USDOLLAR"])).
                        ToString("c");
                    ALLOCATED_USDOLLAR.Value =
                        CommonTypeConvert.ToDecimal(rdr["TOTAL_ALLOCATED_USDOLLAR"]).ToString("0.00");
                    rdr.Close();
                    string innerSql = ApplicationSQL.SQL["Payments_AllocationsView_233"].ToString();

                    oQuery.CommandText = innerSql;
                    TypeConvert.AppendParameter(oQuery, gID, "PAYMENT_ID", false);
                    oQuery.CommandText += " order by DATE_MODIFIED asc" + ControlChars.CrLf;
                    DataTable dtLineItems = oQuery.GetTable();
                    if (!CommonTypeConvert.IsEmptyGuid(gDuplicateID))
                    {
                        foreach (DataRow row in dtLineItems.Rows)
                        {
                            row["ID"] = Guid.NewGuid();
                        }
                    }
                    DataRow rowNew = dtLineItems.NewRow();
                    dtLineItems.Rows.Add(rowNew);

                    ViewState["LineItems"] = dtLineItems;
                    grdMain.DataSource     = dtLineItems;
                    grdMain.EditIndex      = dtLineItems.Rows.Count - 1;
                    grdMain.DataBind();
                }
                else
                {
                    dtLineItems = new DataTable();
                    var colID                  = new DataColumn("ID", Type.GetType("System.Guid"));
                    var colINVOICE_NAME        = new DataColumn("INVOICE_NAME", Type.GetType("System.String"));
                    var colINVOICE_ID          = new DataColumn("INVOICE_ID", Type.GetType("System.Guid"));
                    var colAMOUNT_DUE          = new DataColumn("AMOUNT_DUE", Type.GetType("System.Decimal"));
                    var colAMOUNT_DUE_USDOLLAR = new DataColumn("AMOUNT_DUE_USDOLLAR", Type.GetType("System.Decimal"));
                    var colAMOUNT              = new DataColumn("AMOUNT", Type.GetType("System.Decimal"));
                    var colAMOUNT_USDOLLAR     = new DataColumn("AMOUNT_USDOLLAR", Type.GetType("System.Decimal"));
                    dtLineItems.Columns.Add(colID);
                    dtLineItems.Columns.Add(colINVOICE_NAME);
                    dtLineItems.Columns.Add(colINVOICE_ID);
                    dtLineItems.Columns.Add(colAMOUNT_DUE);
                    dtLineItems.Columns.Add(colAMOUNT_DUE_USDOLLAR);
                    dtLineItems.Columns.Add(colAMOUNT);
                    dtLineItems.Columns.Add(colAMOUNT_USDOLLAR);
                    DataRow rowNew   = null;
                    string  innerSql = ApplicationSQL.SQL["Payments_AllocationsView"].ToString();

                    oQuery.CommandText = innerSql;
                    Guid gPARENT_ID = CommonTypeConvert.ToGuid(Request["PARENT_ID"]);
                    TypeConvert.AppendParameter(oQuery, gPARENT_ID, "ID", false);
                    using (SqlDataReader rdrInvoice = oQuery.ExecuteReader(CommandBehavior.SingleRow))
                    {
                        if (rdrInvoice.Read())
                        {
                            rowNew = dtLineItems.NewRow();
                            rowNew["INVOICE_NAME"]        = CommonTypeConvert.ToString(rdrInvoice["NAME"]);
                            rowNew["INVOICE_ID"]          = CommonTypeConvert.ToGuid(rdrInvoice["ID"]);
                            rowNew["AMOUNT_DUE"]          = CommonTypeConvert.ToDecimal(rdrInvoice["AMOUNT_DUE"]);
                            rowNew["AMOUNT_DUE_USDOLLAR"] =
                                CommonTypeConvert.ToDecimal(rdrInvoice["AMOUNT_DUE_USDOLLAR"]);
                            rowNew["AMOUNT"]          = CommonTypeConvert.ToDecimal(rdrInvoice["AMOUNT_DUE"]);
                            rowNew["AMOUNT_USDOLLAR"] = CommonTypeConvert.ToDecimal(rdrInvoice["AMOUNT_DUE_USDOLLAR"]);
                            if (rdrInvoice["AMOUNT_DUE"] == DBNull.Value)
                            {
                                rowNew["AMOUNT_DUE"]          = CommonTypeConvert.ToDecimal(rdrInvoice["TOTAL"]);
                                rowNew["AMOUNT_DUE_USDOLLAR"] = CommonTypeConvert.ToDecimal(rdrInvoice["TOTAL_USDOLLAR"]);
                                rowNew["AMOUNT"]          = CommonTypeConvert.ToDecimal(rdrInvoice["TOTAL"]);
                                rowNew["AMOUNT_USDOLLAR"] = CommonTypeConvert.ToDecimal(rdrInvoice["TOTAL_USDOLLAR"]);
                            }
                            dtLineItems.Rows.Add(rowNew);
                        }
                    }
                    rowNew = dtLineItems.NewRow();
                    dtLineItems.Rows.Add(rowNew);

                    ViewState["LineItems"] = dtLineItems;
                    grdMain.DataSource     = dtLineItems;
                    grdMain.EditIndex      = dtLineItems.Rows.Count - 1;
                    grdMain.DataBind();

                    UpdateTotals();
                }
            }
        }