Beispiel #1
0
 public void createRequisitionDetails(requisitiondetail rd)
 {
     try
     {
         requisitiondetail detail = new requisitiondetail();
         detail.ReqID = rd.ReqID;
         detail.ReqItemID = rd.ReqItemID;
         detail.ReqQuantityReq = rd.ReqQuantityReq;
         cntx.requisitiondetails.Add(detail);
         cntx.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #2
0
        //method to manage outstanding requests
        public void CheckForOutStanding(Disbursement_M disbl)
        {
            List<requisitiondetail> rdlist = new List<requisitiondetail>();
            checkdate = DateTime.Today; //checking requestions brfore today
            //checkdate = DateTime.Today.AddDays(2);
            requisitiondetail rcheck = new requisitiondetail();
            //checking
            requisition rq = new requisition();
            var m = from r in se.requisitiondetails
                    where
                    r.ReqItemID == disbl.ItemID &&
                    r.requisition.ReqDepID == disbl.DepID &&
                    r.ReqStatus=="approved" &&
                    r.requisition.ReqApproveDate < checkdate
                    select r;
            rdlist = m.ToList();
            rcheck = m.FirstOrDefault();
            foreach (requisitiondetail rd in rdlist)
            {
                //if (rd.requisition.ReqReason == "outstanding")
                //{
                //    //rd.ReqStatus = "confirmed";
                //    //se.SaveChanges();
                //    //totalcount = totalcount + rd.ReqQuantityReq;
                //    outstandingReqList.Add(rd);

                //}
                //else
                //{
                //    normalReqList.Add(rd);
                //    //changing the status to confirmed
                //    //rd.ReqStatus = "confirmed";
                //    //se.SaveChanges();
                //    //totalcount = totalcount + rd.ReqQuantityReq; //getting the count of items ordered by the dep
                //}
                rd.ReqStatus = "confirmed";
                try
                {
                    se.SaveChanges();
                }
                catch (Exception ex)
                {
                    string error;
                    if (ex.InnerException != null)
                    {
                        Exception ex1;
                        ex1 = ex.InnerException;
                        error = ex1.InnerException.StackTrace;

                    }
                    else
                    {
                        string error1;
                        error1 = ex.InnerException.Message;

                    }

                }
            }
            if (disbl.QuantinHand < disbl.RequiredQuant)
            {
                int outstanding = disbl.RequiredQuant - disbl.QuantinHand;
                requisition outreq = new requisition();
                requisitiondetail outreqdet = new requisitiondetail();

                //creating an oustanding request automatically
                outreq.ReqApproveEmpID = rcheck.requisition.ReqApproveEmpID;
                outreq.ReqApproveDate = rcheck.requisition.ReqApproveDate; // come back here to make sure your logic is right
                outreq.ReqStatus = "outstanding";
                outreq.ReqDate = rcheck.requisition.ReqDate;
                outreq.ReqDepID = rcheck.requisition.ReqDepID;
                outreq.ReqEmpId = rcheck.requisition.ReqEmpId;
                outreq.ReqReason = "outstanding";
                try
                {
                    se.requisitions.Add(outreq);
                    se.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }

                //creating an autogenerated requestdetails for that particular item
                outreqdet.ReqID = outreq.ReqID;
                outreqdet.ReqItemID = disbl.ItemID;
                outreqdet.ReqQuantityReq = outstanding;
                outreqdet.ReqStatus = "approved";
                try
                {
                    se.requisitiondetails.Add(outreqdet);
                    se.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
            }
        }