protected void BtnDelete_Click(object sender, EventArgs e)
    {
        try
        {
            int DeleteId = 0;
            if (ViewState["EditID"] != null)
            {
                DeleteId = Convert.ToInt32(ViewState["EditID"]);
            }
            if (DeleteId != 0)
            {
                Entity_UnitConversion.UnitConvId = DeleteId;
                Entity_UnitConversion.LoginId    = Convert.ToInt32(Session["UserID"]);
                Entity_UnitConversion.LoginDate  = DateTime.Now;

                int iDelete = Obj_UnitConversion.DeleteRecord(ref Entity_UnitConversion, out StrError);
                if (iDelete != 0)
                {
                    obj_Comman.ShowPopUpMsg("Record Deleted Successfully..!", this.Page);
                    MakeEmptyForm();
                }
            }
            Entity_UnitConversion = null;
            Obj_UnitConversion    = null;
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }
    public static string[] GetCompletionList(string prefixText, int count, string contextKey)
    {
        DMUnitConversion Obj_CM = new DMUnitConversion();

        String[] SearchList = Obj_CM.GetSuggestRecord(prefixText);
        return(SearchList);
    }
    protected void BtnSave_Click(object sender, EventArgs e)
    {
        int InsertRow     = 0;
        int InsertRowDtls = 0;

        try
        {
            if (GridDetails.Rows[0].Cells[3].Text.Equals(" "))
            {
                obj_Comman.ShowPopUpMsg("Please Enter Details ..!", this.Page);
                ddlUnit.Focus();
                return;
            }

            Entity_UnitConversion.UnitId    = Convert.ToInt32(ddlUnit.SelectedValue);
            Entity_UnitConversion.LoginId   = Convert.ToInt32(Session["UserID"]);
            Entity_UnitConversion.LoginDate = System.DateTime.Now;

            InsertRow = Obj_UnitConversion.InsertRecord(ref Entity_UnitConversion, out StrError);

            if (InsertRow > 0)
            {
                if (ViewState["CurrentTable"] != null)
                {
                    DataTable dtInsert = new DataTable();
                    dtInsert = (DataTable)ViewState["CurrentTable"];

                    if (dtInsert.Rows.Count > 0 && !string.IsNullOrEmpty(dtInsert.Rows[0]["UnitFactor"].ToString()))
                    {
                        for (int i = 0; i < dtInsert.Rows.Count; i++)
                        {
                            Entity_UnitConversion.UnitConvId = InsertRow;
                            Entity_UnitConversion.UnitId     = Convert.ToInt32(dtInsert.Rows[i]["UnitId"].ToString());
                            Entity_UnitConversion.UnitFactor = dtInsert.Rows[i]["UnitFactor"].ToString();
                            Entity_UnitConversion.Qty        = Convert.ToDecimal(dtInsert.Rows[i]["Qty"].ToString());

                            InsertRowDtls = Obj_UnitConversion.InsertRecordDtls(ref Entity_UnitConversion, out StrError);
                        }
                    }
                }
                if (InsertRow > 0 && InsertRowDtls > 0)
                {
                    obj_Comman.ShowPopUpMsg("Record Saved Successfully..!", this.Page);
                    MakeControlEmpty();
                    MakeEmptyForm();
                    Obj_UnitConversion    = null;
                    Entity_UnitConversion = null;
                }
            }
            else
            {
                obj_Comman.ShowPopUpMsg("Please Enter Details ..!", this.Page);
            }
        }
        catch (Exception ex)
        {
            obj_Comman.ShowPopUpMsg(ex.Message, this.Page);
        }
    }
 protected void GrdReport_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     try
     {
         switch (e.CommandName)
         {
         case ("Select"):
         {
             if (Convert.ToInt32(e.CommandArgument) != 0)
             {
                 ViewState["EditID"] = Convert.ToInt32(e.CommandArgument);
                 Ds = Obj_UnitConversion.GetRecordToEdit(Convert.ToInt32(e.CommandArgument), out StrError);
                 if (Ds.Tables.Count > 0)
                 {
                     if (Ds.Tables.Count > 0 && Ds.Tables[0].Rows.Count > 0)
                     {
                         ddlUnit.SelectedValue = Ds.Tables[0].Rows[0]["UnitId"].ToString();
                     }
                     if (Ds.Tables[1].Rows.Count > 0)
                     {
                         GridDetails.DataSource = Ds.Tables[1];
                         GridDetails.DataBind();
                         ViewState["CurrentTable"] = Ds.Tables[1];
                     }
                     else
                     {
                         MakeEmptyForm();
                     }
                 }
                 Ds = null;
                 Obj_UnitConversion = null;
                 if (!FlagEdit)
                 {
                     BtnUpdate.Visible = true;
                 }
                 BtnSave.Visible = false;
                 if (!FlagDel)
                 {
                     BtnDelete.Visible = true;
                 }
                 ddlUnit.Focus();
                 MakeControlEmpty();
             }
             break;
         }
         }
     }
     catch (Exception ex)
     {
         obj_Comman.ShowPopUpMsg(ex.Message, this.Page);
         return;
     }
 }
    protected void BtnUpdate_Click(object sender, EventArgs e)
    {
        DataSet DsTemp = new DataSet();
        int     UpdateRow = 0, UpdateRowDtls = 0;
        decimal qty = 0;

        try
        {
            if (GridDetails.Rows[0].Cells[3].Text.Equals("&nbsp;"))
            {
                obj_Comman.ShowPopUpMsg("Please Enter Details ..!", this.Page);
                ddlUnit.Focus();
                return;
            }

            //If Record is not Updated in Details Grid(Update Image is Visible)
            if (ImgAddGrid.ImageUrl == "~/Images/Icon/GridUpdate.png")
            {
                obj_Comman.ShowPopUpMsg("Update The Current Record In Details Grid First!!", this.Page);
                return;
            }

            if (ViewState["EditID"] != null)
            {
                Entity_UnitConversion.UnitConvId = Convert.ToInt32(ViewState["EditID"]);
            }
            Entity_UnitConversion.UnitId    = Convert.ToInt32(ddlUnit.SelectedValue);
            Entity_UnitConversion.LoginId   = Convert.ToInt32(Session["UserID"]);
            Entity_UnitConversion.LoginDate = System.DateTime.Now;

            UpdateRow = Obj_UnitConversion.UpdateRecord(ref Entity_UnitConversion, out StrError);

            if (UpdateRow > 0)
            {
                if (ViewState["CurrentTable"] != null)
                {
                    DataTable dtInsert = new DataTable();
                    dtInsert = (DataTable)ViewState["CurrentTable"];

                    if (dtInsert.Rows.Count > 0 && !dtInsert.Rows[0]["UnitFactor"].ToString().Equals(""))
                    {
                        for (int i = 0; i < dtInsert.Rows.Count; i++)
                        {
                            Entity_UnitConversion.UnitConvId = Convert.ToInt32(ViewState["EditID"]);
                            Entity_UnitConversion.UnitId     = Convert.ToInt32(dtInsert.Rows[i]["UnitId"].ToString());
                            Entity_UnitConversion.UnitFactor = dtInsert.Rows[i]["UnitFactor"].ToString();
                            Entity_UnitConversion.Qty        = Convert.ToDecimal(dtInsert.Rows[i]["Qty"].ToString());
                            qty = Convert.ToDecimal(dtInsert.Rows[i]["Qty"].ToString());
                            //----For Updating Record In UnitConversionDtlsId-----
                            if (Convert.ToInt32(dtInsert.Rows[i]["#"].ToString()) != 0)
                            {
                                UpdateRowDtls = Obj_UnitConversion.UpdateRecordDtls(Convert.ToInt32(dtInsert.Rows[i]["#"].ToString()), qty, out StrError);
                                //DsTemp = Obj_UnitConversion.GetUnitConvrsndtlsId(ref Entity_UnitConversion, out StrError);
                                //if (DsTemp.Tables.Count > 0)
                                //{
                                //    if (DsTemp.Tables[0].Rows.Count > 0)
                                //    {
                                //        UpdateRowDtls = Obj_UnitConversion.UpdateRecordDtls(Convert.ToInt32(DsTemp.Tables[0].Rows[0]["UnitConvDtlsId"]), qty, out StrError);
                                //    }
                                //    else
                                //    {
                                //        UpdateRowDtls = Obj_UnitConversion.InsertRecordDtls(ref Entity_UnitConversion, out StrError);
                                //    }
                                //}
                            }
                            else
                            {
                                UpdateRowDtls = Obj_UnitConversion.InsertRecordDtls(ref Entity_UnitConversion, out StrError);
                            }
                        }
                    }
                }

                if (UpdateRow > 0)
                {
                    obj_Comman.ShowPopUpMsg("Record Updated Successfully..!", this.Page);
                    MakeControlEmpty();
                    MakeEmptyForm();
                    Obj_UnitConversion    = null;
                    Entity_UnitConversion = null;
                }
            }
        }
        catch (Exception ex)
        {
            obj_Comman.ShowPopUpMsg(ex.Message, this.Page);
        }
    }