protected void loadFoodItemGrid(int fOODITEM_TRANSMASTERID)
    {
        List <FOODITEM_TRANSMASTERDETAIL> fOODITEM_TRANSMASTERDETAIL = new List <FOODITEM_TRANSMASTERDETAIL>();

        fOODITEM_TRANSMASTERDETAIL = FOODITEM_TRANSDETAILManager.GetAllFOODITEM_TRANSDETAILByFoodTransID(fOODITEM_TRANSMASTERID);

        //Label1.Text = fOODITEM_TRANSMASTERDETAIL.Count.ToString();

        foreach (FOODITEM_TRANSMASTERDETAIL item in fOODITEM_TRANSMASTERDETAIL)
        {
            if (hfIsLocation.Value == "1")
            {
                item.IsAgent          = false;
                trTotalAmount.Visible = false;
            }
            else
            {
                item.IsAgent = true;
            }
        }

        gvFoodTransactionItemRelation.DataSource = fOODITEM_TRANSMASTERDETAIL;
        gvFoodTransactionItemRelation.DataBind();

        //Label1.Text = fOODITEM_TRANSMASTERDETAIL[0].LOCATIONID.ToString();
    }
    protected void updateFoodItemDetails()
    {
        bool result = FOODITEM_TRANSDETAILManager.DeleteFOODITEM_TRANSDETAILByTID(Convert.ToInt32(hfFOODTRANSID.Value.ToString()));

        //if (result == true)
        {
            FOODITEM_TRANSDETAIL fOODITEM_TRANSDETAIL = new FOODITEM_TRANSDETAIL();
            for (int i = 0; i < gvFoodTransactionItemRelation.Rows.Count; i++)
            {
                Label lblfID   = (Label)gvFoodTransactionItemRelation.Rows[i].FindControl("lblfID");
                Label lblfRATE = (Label)gvFoodTransactionItemRelation.Rows[i].FindControl("lblfRATE");
                Label lblfQTY  = (Label)gvFoodTransactionItemRelation.Rows[i].FindControl("lblfQTY");


                Label lblCUSTID     = (Label)gvFoodTransactionItemRelation.Rows[i].FindControl("lblCUSTID");
                Label lblLOCATIONID = (Label)gvFoodTransactionItemRelation.Rows[i].FindControl("lblLOCATIONID");
                Label lblRECEIVERID = (Label)gvFoodTransactionItemRelation.Rows[i].FindControl("lblRECEIVERID");


                fOODITEM_TRANSDETAIL.TID       = int.Parse(hfFOODTRANSID.Value.ToString());
                fOODITEM_TRANSDETAIL.FID       = Int32.Parse(lblfID.Text);
                fOODITEM_TRANSDETAIL.FRATE     = decimal.Parse(lblfRATE.Text);
                fOODITEM_TRANSDETAIL.FQTY      = Int32.Parse(lblfQTY.Text);
                fOODITEM_TRANSDETAIL.CREATEDON = DateTime.Now;
                fOODITEM_TRANSDETAIL.CREATEDBY = 1;
                fOODITEM_TRANSDETAIL.UPDATEDON = DateTime.Now;
                fOODITEM_TRANSDETAIL.UPDATEDBY = 1;
                int resutl = FOODITEM_TRANSDETAILManager.InsertFOODITEM_TRANSDETAIL(fOODITEM_TRANSDETAIL);
            }
        }
    }
    protected void btnSaveTransaction_Click(object sender, EventArgs e)
    {
        try
        {
            if (Session["sessionFOODITEM_TRANSMASTERDETAIL"] != null)
            {
                AGENT    aGENT    = (AGENT)Session["aGENT"];
                DateTime nullDate = DateTime.Parse(ConfigurationManager.AppSettings["NULL_DATE"].ToString());

                List <FOODITEM_TRANSMASTERDETAIL> fOODITEM_TRANSMASTERDETAIL_Ori = new List <FOODITEM_TRANSMASTERDETAIL>();
                fOODITEM_TRANSMASTERDETAIL_Ori = (List <FOODITEM_TRANSMASTERDETAIL>)Session["sessionFOODITEM_TRANSMASTERDETAIL"];
                List <FOODITEM_TRANSMASTERDETAIL> fOODITEM_TRANSMASTERDETAIL_Distinct = new List <FOODITEM_TRANSMASTERDETAIL>();
                int count = 0;
                for (int i = 0; i < fOODITEM_TRANSMASTERDETAIL_Ori.Count; i++)
                {
                    count = fOODITEM_TRANSMASTERDETAIL_Distinct.FindAll(x => x.CUSTID == fOODITEM_TRANSMASTERDETAIL_Ori[i].CUSTID && x.LOCATIONID == fOODITEM_TRANSMASTERDETAIL_Ori[i].LOCATIONID && x.RECEIVERID == fOODITEM_TRANSMASTERDETAIL_Ori[i].RECEIVERID).Count;

                    if (count == 0)
                    {
                        fOODITEM_TRANSMASTERDETAIL_Distinct.Add(fOODITEM_TRANSMASTERDETAIL_Ori[i]);
                    }
                }

                string refCode = string.Empty;

                for (int j = 0; j < fOODITEM_TRANSMASTERDETAIL_Distinct.Count; j++)
                {
                    #region FoodItemTransMaster

                    FOODITEM_TRANSMASTER fOODITEM_TRANSMASTER = new FOODITEM_TRANSMASTER();

                    fOODITEM_TRANSMASTER.TDATE = DateTime.Now;
                    fOODITEM_TRANSMASTER.CID   = fOODITEM_TRANSMASTERDETAIL_Distinct[j].CUSTID;
                    fOODITEM_TRANSMASTER.LID   = int.Parse(Session["snFoodlocationID"].ToString());
                    fOODITEM_TRANSMASTER.AID   = aGENT.AGENTID;
                    //fOODITEM_TRANSMASTER.TOTALAMT = fOODITEM_TRANSMASTERDETAIL_Distinct[j].TOTALAMT;
                    fOODITEM_TRANSMASTER.TOTALAMT    = decimal.Parse(lblTotalAmount.Text);
                    fOODITEM_TRANSMASTER.TRANSSTATUS = "PENDING";
                    fOODITEM_TRANSMASTER.REFCODE     = txtReferenceCode.Text;
                    fOODITEM_TRANSMASTER.RECID       = fOODITEM_TRANSMASTERDETAIL_Distinct[j].RECEIVERID;
                    fOODITEM_TRANSMASTER.RECDATE     = nullDate;
                    fOODITEM_TRANSMASTER.STOREID     = 1;
                    fOODITEM_TRANSMASTER.CREATEDON   = DateTime.Now;
                    fOODITEM_TRANSMASTER.CREATEDBY   = aGENT.AGENTID;
                    fOODITEM_TRANSMASTER.UPDATEDON   = DateTime.Now;
                    fOODITEM_TRANSMASTER.UPDATEDBY   = aGENT.AGENTID;
                    int resutlfOODITEM_TRANSMASTER = FOODITEM_TRANSMASTERManager.InsertFOODITEM_TRANSMASTER(fOODITEM_TRANSMASTER);

                    #endregion


                    FOODITEM_TRANSDETAIL fOODITEM_TRANSDETAIL = new FOODITEM_TRANSDETAIL();

                    for (int i = 0; i < gvFoodTransactionItemRelation.Rows.Count; i++)
                    {
                        Label lblfID   = (Label)gvFoodTransactionItemRelation.Rows[i].FindControl("lblfID");
                        Label lblfRATE = (Label)gvFoodTransactionItemRelation.Rows[i].FindControl("lblfRATE");
                        Label lblfQTY  = (Label)gvFoodTransactionItemRelation.Rows[i].FindControl("lblfQTY");


                        Label lblCUSTID     = (Label)gvFoodTransactionItemRelation.Rows[i].FindControl("lblCUSTID");
                        Label lblLOCATIONID = (Label)gvFoodTransactionItemRelation.Rows[i].FindControl("lblLOCATIONID");
                        Label lblRECEIVERID = (Label)gvFoodTransactionItemRelation.Rows[i].FindControl("lblRECEIVERID");

                        if (int.Parse(lblCUSTID.Text) == fOODITEM_TRANSMASTERDETAIL_Distinct[j].CUSTID && int.Parse(lblLOCATIONID.Text) == fOODITEM_TRANSMASTERDETAIL_Distinct[j].LOCATIONID && int.Parse(lblRECEIVERID.Text) == fOODITEM_TRANSMASTERDETAIL_Distinct[j].RECEIVERID)
                        {
                            fOODITEM_TRANSDETAIL.TID       = resutlfOODITEM_TRANSMASTER;
                            fOODITEM_TRANSDETAIL.FID       = Int32.Parse(lblfID.Text);
                            fOODITEM_TRANSDETAIL.FRATE     = decimal.Parse(lblfRATE.Text);
                            fOODITEM_TRANSDETAIL.FQTY      = Int32.Parse(lblfQTY.Text);
                            fOODITEM_TRANSDETAIL.CREATEDON = DateTime.Now;
                            fOODITEM_TRANSDETAIL.CREATEDBY = 1;
                            fOODITEM_TRANSDETAIL.UPDATEDON = DateTime.Now;
                            fOODITEM_TRANSDETAIL.UPDATEDBY = 1;
                            int resutl = FOODITEM_TRANSDETAILManager.InsertFOODITEM_TRANSDETAIL(fOODITEM_TRANSDETAIL);
                        }
                    }



                    lblReferenceCODE.Text = FOODITEM_TRANSMASTERManager.GetFOODITEM_TRANSMASTERByID(resutlfOODITEM_TRANSMASTER).REFCODE.ToString();// +"<br/>" + refCode.ToString();
                    refCode = lblReferenceCODE.Text;
                }



                //lblmessage.Text = resutlfOODITEM_TRANSMASTER.ToString();
                lblmessage.Text = "Food Transfer Successfully.. ";
                lblText.Text    = "Reference CODE: ";
                //lblReferenceCODE.Text= FOODITEM_TRANSMASTERManager.GetFOODITEM_TRANSMASTERByID(resutlfOODITEM_TRANSMASTER).REFCODE ;
            }
        }
        catch (Exception ex)
        {
            lblmessage.Text = ex.ToString();
        }
    }