Beispiel #1
0
        public static String Confrimrequ(List <WCF_RequisitionDetail> WRDS)

        {
            //String  WRDD= WRD.ToString();
            //JArray array = (JArray)JsonConvert.DeserializeObject(WRDD);
            //List<WCF_RequisitionDetail> WRDS = new List<WCF_RequisitionDetail>();
            //foreach (JObject j in array)
            //{
            //   WCF_RequisitionDetail w=  j.ToObject<WCF_RequisitionDetail>();
            //    WRDS.Add(w);
            //}



            int requid = Convert.ToInt32(WRDS.First().Requid);
            // int id = 13;
            LastADEntities    entities = new LastADEntities();
            Requisition       requ     = entities.Requisitions.Where(x => x.RequId == requid).First();
            List <RequDetail> details  = requ.RequDetails.ToList();
            int    percentage          = 0;
            string ending = WRDS.ToString();

            //String WCFitemid = "1";
            try
            {
                // foreach (RequDetail detail in details)
                for (int i = 0; i < WRDS.Count(); i++)
                {
                    // entities.Entry(detail).State = System.Data.Entity.EntityState.Modified;
                    //WCFitemid = WRDS[i].itemid.ToString();
                    String WCFitemdesc = WRDS[i].name.ToString();
                    // ending = WCFitemid;
                    RequDetail wdetail = details.Where(x => x.ItemList.Description == WCFitemdesc).First();
                    wdetail.OutstandingQuantity = Convert.ToInt32(WRDS[i].OutstandingQuantity);
                    if (wdetail.OutstandingQuantity != 0)
                    {
                        percentage++;
                    }
                    else
                    {
                    }

                    if (percentage == 0)
                    {
                        requ.Status         = "Completed";
                        requ.CollectionDate = DateTime.Now;
                    }
                    else
                    {
                        requ.Status = "Waiting for Collection";
                    }
                    entities.Entry(requ).State = System.Data.Entity.EntityState.Modified;
                }
                entities.SaveChanges();
                ending = "execute successfully";
            }
            catch (Exception e)
            {
                ending = e.ToString();
            }
            return(ending);
        }
        protected void Button4_Click(object sender, EventArgs e)
        {
            LastADEntities entities = new LastADEntities();

            if (Session["a"] != null)
            {
                list2 = (ArrayList)Session["a"];
            }
            Requisition        rr    = new Requisition();
            List <Requisition> c     = new List <Requisition>();
            List <string>      email = new List <string>();

            foreach (int i in list2)
            {
                rr = entities.Requisitions.Where(x => x.RequId == i).First();
                string emal = rr.Employee.Department.Employees.Where(x => x.RoleId == 5).First().Email.ToString();
                c.Add(rr);
                email.Add(emal);
            }
            for (int i = 0; i < this.GridView1.Rows.Count; i++)
            {
                TextBox    txt          = (TextBox)this.GridView1.Rows[i].Cells[5].FindControl("TextBox1");
                int        RetrievedAmt = Int32.Parse(txt.Text);
                Label      lab          = (Label)this.GridView1.Rows[i].Cells[2].FindControl("Label7");
                RequDetail requDetail   = new RequDetail();
                c = c.Where(x => x.RequDetails.Select(y => y.ItemId).Contains(lab.Text)).OrderBy(x => x.SignDate).ToList();
                foreach (Requisition requ in c)
                {
                    DateTime entryday       = DateTime.Now;
                    int?     RetrievedAmtnt = requ.RequDetails.Where(x => x.ItemId.Equals(lab.Text)).Select(x => x.RequestedQuantity).First();
                    if (RetrievedAmt == 0)
                    {
                    }
                    else if (RetrievedAmt < RetrievedAmtnt)
                    {
                        RetrievedAmtnt = RetrievedAmt;
                    }

                    if (RetrievedAmtnt != 0)
                    {
                        RequDetail requde = new RequDetail();
                        requde = requ.RequDetails.Where(x => x.ItemId.Equals(lab.Text)).First();
                        int         balance = Convert.ToInt32(requde.ItemList.Stock) - Convert.ToInt32(RetrievedAmtnt);
                        Transaction tt      = new Transaction();
                        tt.Balance   = balance;
                        tt.EntryDate = entryday;
                        tt.ItemId    = requde.ItemId;
                        tt.Quantity  = RetrievedAmtnt;
                        tt.Requid    = requde.RequId;
                        ItemList ii = new ItemList();
                        ii       = requde.ItemList;
                        ii.Stock = balance;


                        entities.Transactions.Add(tt);
                        entities.SaveChanges();
                        RetrievedAmt = RetrievedAmt - Convert.ToInt32(RetrievedAmtnt);
                    }
                }
                foreach (Requisition requ in c)
                {
                    requ.Status = "Waiting For Delivery";
                    entities.SaveChanges();
                }
            }
            foreach (string em in email)
            {
                string bossmail = em;
                Business.sendemail();
                MailMessage mm = new MailMessage("*****@*****.**",
                                                 bossmail);
                mm.Subject = "Your Requisition order has been send to your collection point ";
                mm.Body    = "Your Requisition order has been send to your collection point, please collect your item before tmr 12:00pm ";

                Business.sendemail().Send(mm);
            }
            Response.Redirect("DisbursementList.aspx");
        }