Beispiel #1
0
    protected void ReportGrid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            switch (e.CommandName)
            {
            case ("Select"):
            {
                ViewState["EditID"] = Convert.ToInt32(e.CommandArgument);
                DS = Obj_Recipe.GetRecordForEdit(Convert.ToInt32(e.CommandArgument), out StrError);
                if (DS.Tables.Count > 0)
                {
                    if (DS.Tables[0].Rows.Count > 0)
                    {
                        txtDate.Text           = DS.Tables[0].Rows[0]["OrderDate"].ToString();
                        txtTotalOrderCost.Text = DS.Tables[0].Rows[0]["TotalOrderCost"].ToString();
                    }
                    if (DS.Tables[1].Rows.Count > 0)
                    {
                        GridDetails.DataSource    = DS.Tables[1];
                        ViewState["CurrentTable"] = DS.Tables[1];
                        GridDetails.DataBind();
                    }
                    if (DS.Tables[2].Rows.Count > 0)
                    {
                        GridItemDtls.DataSource  = DS.Tables[2];
                        ViewState["ItemDetails"] = DS.Tables[2];
                        GridItemDtls.DataBind();
                    }
                    else
                    {
                        SetInitialRow();
                    }
                    BtnUpdate.Visible = true;
                    BtnSave.Visible   = false;
                }
            }
            break;

            case ("Delete"):
            {
                ViewState["DeleteID"]   = Convert.ToInt32(e.CommandArgument);
                Entity_Recipe.OrderId   = Convert.ToInt32(e.CommandArgument);
                Entity_Recipe.UserId    = Convert.ToInt32(Session["UserId"]);
                Entity_Recipe.LoginDate = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                int DeletedRow = Obj_Recipe.DeleteRecord(ref Entity_Recipe, out StrError);
                if (DeletedRow != 0)
                {
                    obj_Comm.ShowPopUpMsg("Record Deleted Successfully!", this.Page);
                    MakeEmptyForm();
                }
            }
            break;
            }
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }
Beispiel #2
0
 private void DeleteItemDetails(int RecipeId)
 {
     try
     {
         DataTable dt = (DataTable)ViewState["ItemDetails"];
         if (ViewState["ItemDetails"] != null)
         {
             for (int i = 0; i < dt.Rows.Count; i++)
             {
                 if (RecipeId == Convert.ToInt32(dt.Rows[i]["RecipeId"].ToString()))
                 {
                     dt.Rows.RemoveAt(i);
                 }
             }
         }
         ViewState["ItemDetails"] = dt;
         GridItemDtls.DataSource  = dt;
         GridItemDtls.DataBind();
         if (GridItemDtls.Rows.Count > 0)
         {
         }
         else
         {
             SetInitialRow_DetailsGrid();
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Beispiel #3
0
    public void SetInitialRow_DetailsGrid()
    {
        try
        {
            DataTable dt = new DataTable();
            DataRow   dr = null;
            dt.Columns.Add(new DataColumn("#", typeof(int)));
            dt.Columns.Add(new DataColumn("ItemName", typeof(string)));
            dt.Columns.Add(new DataColumn("ItemId", typeof(Int32)));
            dt.Columns.Add(new DataColumn("Quantity", typeof(string)));
            dt.Columns.Add(new DataColumn("IngredAmt", typeof(decimal)));
            dt.Columns.Add(new DataColumn("SubUnitId", typeof(Int32)));
            dt.Columns.Add(new DataColumn("RecipeId", typeof(Int32)));
            dt.Columns.Add(new DataColumn("ActualRate", typeof(decimal)));
            dt.Columns.Add(new DataColumn("QtyPerUnit", typeof(decimal)));

            dr = dt.NewRow();

            dr["#"]          = 0;
            dr["ItemName"]   = string.Empty;
            dr["ItemId"]     = 0;
            dr["Quantity"]   = string.Empty;
            dr["IngredAmt"]  = 0.0;
            dr["SubUnitId"]  = 0;
            dr["RecipeId"]   = 0;
            dr["ActualRate"] = 0;
            dr["QtyPerUnit"] = 0;

            dt.Rows.Add(dr);

            ViewState["ItemDetails"] = dt;
            GridItemDtls.DataSource  = dt;
            GridItemDtls.DataBind();
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }
Beispiel #4
0
    protected void BtnAdd_Click(object sender, EventArgs e)
    {
        try
        {
            if (ViewState["CurrentTable"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
                DataTable dtCurrentTableI = (DataTable)ViewState["ItemDetails"];
                DataRow   dtTableRow = null;
                DataRow   dtTableRow2 = null;
                bool      DupFlag = false;
                bool      DupFlagItem = false;
                int       k = 0, l = 0;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    if (dtCurrentTable.Rows.Count == 1 && string.IsNullOrEmpty(dtCurrentTable.Rows[0]["RecipeName"].ToString()))
                    {
                        dtCurrentTable.Rows.RemoveAt(0);
                    }
                    if (ViewState["GridIndex"] != null)
                    {
                        for (int i = 0; i < dtCurrentTable.Rows.Count; i++)
                        {
                            if (Convert.ToInt32(dtCurrentTable.Rows[i]["RecipeId"]) == Convert.ToInt32(ddlRecipeName.SelectedValue))
                            {
                                DupFlag = true;
                                k       = i;
                            }
                        }
                        if (DupFlag == true)
                        {
                            dtCurrentTable.Rows[k]["RecipeName"]  = ddlRecipeName.SelectedItem.Text;
                            dtCurrentTable.Rows[k]["RecipeId"]    = Convert.ToInt32(ddlRecipeName.SelectedValue);
                            dtCurrentTable.Rows[k]["#"]           = Convert.ToInt32(ddlRecipeName.SelectedValue);
                            dtCurrentTable.Rows[k]["Quantity"]    = txtTotalQty.Text;
                            dtCurrentTable.Rows[k]["AmtPerPlate"] = txtAmtPerPlate.Text;
                            dtCurrentTable.Rows[k]["TotalAmt"]    = txtTotAmt.Text;

                            ViewState["CurrentTable"] = dtCurrentTable;
                            GridDetails.DataSource    = dtCurrentTable;
                            GridDetails.DataBind();
                            //MakeControlEmpty();
                            // MakeEmptyFields();
                        }
                        else
                        {
                            dtTableRow = dtCurrentTable.NewRow();
                            int rowindex = Convert.ToInt32(ViewState["GridIndex"]);

                            dtTableRow["RecipeName"]  = ddlRecipeName.SelectedItem.Text;
                            dtTableRow["RecipeId"]    = Convert.ToInt32(ddlRecipeName.SelectedValue);
                            dtTableRow["#"]           = Convert.ToInt32(ddlRecipeName.SelectedValue);
                            dtTableRow["Quantity"]    = txtTotalQty.Text;
                            dtTableRow["AmtPerPlate"] = txtAmtPerPlate.Text;
                            dtTableRow["TotalAmt"]    = txtTotAmt.Text;

                            ViewState["CurrentTable"] = dtCurrentTable;
                            GridDetails.DataSource    = dtCurrentTable;
                            GridDetails.DataBind();
                            //MakeControlEmpty();
                            // MakeEmptyFields();
                        }
                    }
                    else
                    {
                        for (int i = 0; i < dtCurrentTable.Rows.Count; i++)
                        {
                            if (Convert.ToInt32(dtCurrentTable.Rows[i]["RecipeId"]) == Convert.ToInt32(ddlRecipeName.SelectedValue))
                            {
                                DupFlag = true;
                                k       = i;
                            }
                        }
                        if (DupFlag == true)
                        {
                            dtCurrentTable.Rows[k]["RecipeName"]  = ddlRecipeName.SelectedItem.Text;
                            dtCurrentTable.Rows[k]["RecipeId"]    = Convert.ToInt32(ddlRecipeName.SelectedValue);
                            dtCurrentTable.Rows[k]["#"]           = Convert.ToInt32(ddlRecipeName.SelectedValue);
                            dtCurrentTable.Rows[k]["Quantity"]    = txtTotalQty.Text;
                            dtCurrentTable.Rows[k]["AmtPerPlate"] = txtAmtPerPlate.Text;
                            dtCurrentTable.Rows[k]["TotalAmt"]    = txtTotAmt.Text;

                            ViewState["CurrentTable"] = dtCurrentTable;
                            GridDetails.DataSource    = dtCurrentTable;
                            GridDetails.DataBind();
                            //MakeControlEmpty();
                            // MakeEmptyFields();
                        }
                        else
                        {
                            dtTableRow = dtCurrentTable.NewRow();
                            int rowindex = Convert.ToInt32(ViewState["GridIndex"]);
                            dtTableRow["RecipeName"]  = ddlRecipeName.SelectedItem.Text;
                            dtTableRow["RecipeId"]    = Convert.ToInt32(ddlRecipeName.SelectedValue);
                            dtTableRow["#"]           = Convert.ToInt32(ddlRecipeName.SelectedValue);
                            dtTableRow["Quantity"]    = txtTotalQty.Text;
                            dtTableRow["AmtPerPlate"] = txtAmtPerPlate.Text;
                            dtTableRow["TotalAmt"]    = txtTotAmt.Text;

                            dtCurrentTable.Rows.Add(dtTableRow);

                            ViewState["CurrentTable"] = dtCurrentTable;
                            GridDetails.DataSource    = dtCurrentTable;
                            GridDetails.DataBind();
                            //MakeControlEmpty();
                            //MakeEmptyFields();
                        }
                    }
                }

                //Add ItemDetails Of Recipe
                if (dtCurrentTableI.Rows.Count > 0)
                {
                    DS = Obj_Recipe.GetRecipeDetails(RecipeId, out StrError, Convert.ToInt32(txtTotalQty.Text));
                    if (dtCurrentTableI.Rows.Count == 1 && string.IsNullOrEmpty(dtCurrentTableI.Rows[0]["ItemName"].ToString()))
                    {
                        dtCurrentTableI.Rows.RemoveAt(0);
                    }
                    if (DS.Tables.Count > 0 && DS.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < dtCurrentTableI.Rows.Count; i++)
                        {
                            if (Convert.ToInt32(dtCurrentTableI.Rows[i]["RecipeId"]) == Convert.ToInt32(ddlRecipeName.SelectedValue))
                            {
                                DupFlagItem = true;
                                l           = i;
                            }
                        }
                        if (DupFlagItem == true)
                        {
                            for (int i = 0; i <= DS.Tables[0].Rows.Count - 1; i++)
                            {
                                dtCurrentTableI.Rows[l]["ItemId"]     = DS.Tables[0].Rows[i]["ItemId"].ToString();
                                dtCurrentTableI.Rows[l]["ItemName"]   = DS.Tables[0].Rows[i]["ItemName"].ToString();
                                dtCurrentTableI.Rows[l]["#"]          = DS.Tables[0].Rows[i]["ItemId"].ToString();
                                dtCurrentTableI.Rows[l]["Quantity"]   = DS.Tables[0].Rows[i]["Quantity"].ToString();
                                dtCurrentTableI.Rows[l]["IngredAmt"]  = DS.Tables[0].Rows[i]["IngredAmt"].ToString();
                                dtCurrentTableI.Rows[l]["SubUnitId"]  = DS.Tables[0].Rows[i]["SubUnitId"].ToString();
                                dtCurrentTableI.Rows[l]["RecipeId"]   = DS.Tables[0].Rows[i]["RecipeId"].ToString();
                                dtCurrentTableI.Rows[l]["ActualRate"] = DS.Tables[0].Rows[i]["ActualRate"].ToString();
                                dtCurrentTableI.Rows[l]["QtyPerUnit"] = DS.Tables[0].Rows[i]["QtyPerUnit"].ToString();

                                ViewState["ItemDetails"] = dtCurrentTableI;
                                GridItemDtls.DataSource  = dtCurrentTableI;
                                GridItemDtls.DataBind();
                                //MakeControlEmpty();
                                MakeEmptyFields();
                            }
                        }
                        else
                        {
                            for (int i = 0; i <= DS.Tables[0].Rows.Count - 1; i++)
                            {
                                dtTableRow2 = dtCurrentTableI.NewRow();
                                int rowindex = Convert.ToInt32(ViewState["GridIndexI"]);

                                dtTableRow2["ItemId"]     = DS.Tables[0].Rows[i]["ItemId"].ToString();
                                dtTableRow2["ItemName"]   = DS.Tables[0].Rows[i]["ItemName"].ToString();
                                dtTableRow2["#"]          = DS.Tables[0].Rows[i]["ItemId"].ToString();
                                dtTableRow2["Quantity"]   = DS.Tables[0].Rows[i]["Quantity"].ToString();
                                dtTableRow2["IngredAmt"]  = DS.Tables[0].Rows[i]["IngredAmt"].ToString();
                                dtTableRow2["SubUnitId"]  = DS.Tables[0].Rows[i]["SubUnitId"].ToString();
                                dtTableRow2["RecipeId"]   = DS.Tables[0].Rows[i]["RecipeId"].ToString();
                                dtTableRow2["ActualRate"] = DS.Tables[0].Rows[i]["ActualRate"].ToString();
                                dtTableRow2["QtyPerUnit"] = DS.Tables[0].Rows[i]["QtyPerUnit"].ToString();

                                dtCurrentTableI.Rows.Add(dtTableRow2);

                                ViewState["ItemDetails"] = dtCurrentTableI;
                                GridItemDtls.DataSource  = dtCurrentTableI;
                                GridItemDtls.DataBind();
                                //MakeControlEmpty();
                                MakeEmptyFields();
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }