예제 #1
0
        public ActionResult UpdateCustomer(List <string> listkey)
        {
            var t = listkey;

            string quant  = t[0];
            string spares = t[1];
            string aidi   = t[2];

            WoExeSparepartTbl woExe = _db.WoExeSparepartTbl.Where(x => x.WoExeId == Convert.ToInt64(aidi) && x.SparepartCode == spares).First();

            woExe.Quantity = Convert.ToInt32(quant);
            _db.Update(woExe);
            _db.SaveChanges();


            return(new EmptyResult());
        }
예제 #2
0
        public ActionResult Run(long id)
        {
            WorkOrderTbl wotbl = _db.WorkOrderTbl.Where(x => x.WoId == id).First();

            string woeid = "";

            woeid = generateRunningNumber(woeid);

            WoExecutionTbl woe = new WoExecutionTbl();

            woe.WoId          = wotbl.WoId;
            woe.Date          = DateTime.Now;
            woe.SiteId        = wotbl.SiteId;
            woe.TechnicianId  = wotbl.TechnicianId;
            woe.WoDesc        = wotbl.WoDesc;
            woe.WorkExeId     = woeid;
            woe.RequestId     = wotbl.RequestId;
            woe.MaintenanceId = wotbl.MaentenanceId;
            woe.Status        = "Not Started";
            //Not Enough Parts
            _db.WoExecutionTbl.Add(woe);
            _db.SaveChanges();

            var            IdWoe = _db.WoExecutionTbl.Where(x => x.WoId == wotbl.WoId).First().Id;
            WoExecutionTbl wowo  = _db.WoExecutionTbl.Where(x => x.Id == IdWoe).First();

            if (wotbl.MaentenanceId == null)
            {
                if (wotbl.SparepartActive == true)
                {
                    List <WoRequestSpartpartLineTbl> spline = _db.WoRequestSpartpartLineTbl.Where(x => x.WoRequestId == wotbl.RequestId).ToList();
                    for (int i = 0; i < spline.Count; i++)
                    {
                        var checkQty             = _db.SparepartTbl.Where(x => x.SparepartId == spline[i].SparepartId).First();
                        WoExeSparepartTbl wosptb = new WoExeSparepartTbl();
                        wosptb.WoExeId       = IdWoe;
                        wosptb.SparepartId   = spline[i].SparepartId;
                        wosptb.SparepartCode = _db.SparepartTbl.Where(x => x.SparepartId == spline[i].SparepartId).First().SparepartCode;
                        wosptb.Quantity      = spline[i].Quantity;
                        if (checkQty.Qty < spline[i].Quantity && wotbl.Status == "Approved")
                        {
                            createSPR(spline[i], wotbl.WoId, checkQty.Qty);

                            wowo.Status = "Not Enough Parts";
                        }



                        _db.WoExeSparepartTbl.Add(wosptb);
                        _db.SaveChanges();
                    }
                }

                List <WoRequestTaskLine> tskline = _db.WoRequestTaskLine.Where(x => x.WoRequestId == wotbl.RequestId).ToList();
                for (int i = 0; i < tskline.Count; i++)
                {
                    WoExeTaskTbl wotsk = new WoExeTaskTbl();
                    wotsk.WoExeId  = IdWoe;
                    wotsk.TaskCode = "FRQ";
                    wotsk.Detail   = tskline[i].TaskDetail;
                    //wotsk.TaskType = tskline[i].TaskType;

                    _db.WoExeTaskTbl.Add(wotsk);
                    _db.SaveChanges();
                }
            }
            else
            {
                if (wotbl.SparepartActive == true)
                {
                    List <ScheduleSparepartLinesTbl> spline = _db.ScheduleSparepartLinesTbl.Where(x => x.ScheduleMainId == wotbl.MaentenanceId).ToList();
                    for (int i = 0; i < spline.Count; i++)
                    {
                        var checkQty             = _db.SparepartTbl.Where(x => x.SparepartId == spline[i].SparepartId).First();
                        WoExeSparepartTbl wosptb = new WoExeSparepartTbl();
                        wosptb.WoExeId       = IdWoe;
                        wosptb.SparepartId   = spline[i].SparepartId;
                        wosptb.SparepartCode = _db.SparepartTbl.Where(x => x.SparepartId == spline[i].SparepartId).First().SparepartCode;
                        wosptb.Quantity      = spline[i].Quantity;
                        if (checkQty.Qty < spline[i].Quantity && wotbl.Status == "Approved")
                        {
                            createSPR2(spline[i], wotbl.WoId, checkQty.Qty);
                            wowo.Status = "Not Enough Parts";
                        }

                        _db.WoExeSparepartTbl.Add(wosptb);
                        _db.SaveChanges();
                    }
                }

                List <TaskLineTbl> tskline = _db.TaskLineTbl.Where(x => x.TaskCode == wotbl.EntityId).ToList();
                for (int i = 0; i < tskline.Count; i++)
                {
                    WoExeTaskTbl wotsk = new WoExeTaskTbl();
                    wotsk.WoExeId  = IdWoe;
                    wotsk.TaskCode = tskline[i].TaskCode;
                    wotsk.Detail   = tskline[i].TaskName;
                    wotsk.TaskType = tskline[i].TaskType;

                    _db.WoExeTaskTbl.Add(wotsk);
                    _db.SaveChanges();
                }
            }

            _db.Update(wowo);
            _db.SaveChanges();


            return(Json(new { success = true }));
        }