Friday, 19 July 2013

Linq best example

  protected void lnkGrouptoDeposit_Click(object sender, EventArgs e)
        {

            double TotalAmount = 0.00;

            if (Request.Cookies["GeneralInfo"] != null)
            {
                HttpCookie cookie = Request.Cookies["GeneralInfo"];
                if (cookie != null)
                {
                    string strIndNew = gridAria.SelectedIndexVal.Replace("undefined", "0");
                    List<int> ListSele = (string.IsNullOrWhiteSpace(strIndNew)) ? new List<int>() : strIndNew.Split(',').Select(n => int.Parse(n)).Distinct().ToList();
                    cookie["EntityIdList"] = String.Join(",", ListSele.Select(x => x.ToString()).ToArray());
                    ViewState["EntityIdList"] = gridAria.ListChecked;
                }
                Response.Cookies.Add(cookie);
            }



            List<int> ListCheckedtest = gridAria.ListChecked;
            if (ListCheckedtest.Count > 0)
            {
                clsTransactionBO objDepositBO = new clsTransactionBO();

                int intEntityID = ListCheckedtest.FirstOrDefault();
                clsTransactionBO objTransModel = new clsTransactionBO();
                if (ViewState["ListData"] != null)
                {
                    uclCommonPopup.Visible = true;
                    NextGen.Controls.Common.clsGridBind<clsTransactionBO> objTransGridList = (NextGen.Controls.Common.clsGridBind<clsTransactionBO>)ViewState["ListData"];
                    List<clsTransactionBO> objList = objTransGridList.GridList.ToList();
                    objTransModel = objList.Where(x => x.EntityID == intEntityID).SingleOrDefault();
                }
                uclGroupReceipts.EntityList = String.Join(",", gridAria.ListChecked.Select(x => x.ToString()).ToArray());

                if (objTransModel != null && objTransModel.TransTypeId == 1)
                {

                    listGroupReceiptXML = GetReceiptList();
                    // we get selected list
                    int bankkid = listGroupReceiptXML.Select(b => b.BankAccountID).FirstOrDefault();
                    int countBankAccountID = listGroupReceiptXML.Count(b => b.BankAccountID == bankkid);
                    if (countBankAccountID == listGroupReceiptXML.Count)
                    {
                        int countDepositID = listGroupReceiptXML.Count(b => b.DepositID > 0);
                        if (countDepositID > 0)
                        {
                            uclCommonPopup.Alert("Display Message Box", "One or more Receipts have already been grouped to a deposit");
                        }
                        else
                        {
                            for (int i = 0; i < listGroupReceiptXML.Count; i++)
                            {
                                TotalAmount += Convert.ToDouble(listGroupReceiptXML[i].Amount);
                            }
                            objDepositBO.EntityIdList = XMLConvert(uclGroupReceipts.EntityList);
                            objDepositBO.Amount = TotalAmount.ToString();
                            objDepositBO.NoOfItems = Convert.ToString(ListCheckedtest.Count);
                            uclGroupReceipts.GroupDepositModel = objDepositBO;
                            uclGroupReceipts.ControlStatus = true;
                            mdlGrouptoDeposit.Show();
                        }

                    }
                    else
                    {
                        uclCommonPopup.Alert("Display Message Box", "Please select same bank account");
                    }

                }
                else
                {
                    uclCommonPopup.Alert("Display Message Box", "Selected items must be receipts");
                }
            }
            else
            {
                uclCommonPopup.Alert("Display Message Box", "At least one receipt must be selected before proceeding");
            }

            //CreateCookie();

        }

No comments:

Post a Comment