Example #1
0
        //GENERATE RUNNING NUMBER
        private String generateRunningNumber(string woeid)
        {
            WoExecutionTbl data = _db.WoExecutionTbl.Where(x => x.WorkExeId == "WOE" + DateTime.Now.ToString("yyMM") + "0001").FirstOrDefault();

            string tempPriceId = "";
            int    tempId;

            if (data == null)
            {
                woeid = "WOE" + DateTime.Now.ToString("yyMM") + "0001";
            }
            else
            {
                var xx = (from a in _db.WoExecutionTbl
                          where a.WorkExeId.Substring(0, 7) == "WOE" + DateTime.Now.ToString("yyMM")
                          select a).Max(a => a.WorkExeId);

                tempPriceId = xx.Substring(7, 4);
                tempId      = Convert.ToInt32(tempPriceId);
                tempId      = tempId + 1;

                if (tempId.ToString().Length == 1)
                {
                    woeid = "WOE" + DateTime.Now.ToString("yyMM") + "000" + tempId;
                }
                else if (tempId.ToString().Length == 2)
                {
                    woeid = "WOE" + DateTime.Now.ToString("yyMM") + "00" + tempId;
                }
                else if (tempId.ToString().Length == 3)
                {
                    woeid = "WOE" + DateTime.Now.ToString("yyMM") + "0" + tempId;
                }
                else if (tempId.ToString().Length == 4)
                {
                    woeid = "WOE" + DateTime.Now.ToString("yyMM") + tempId;
                }
            }

            return(woeid);
        }
Example #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 }));
        }