Ejemplo n.º 1
0
 public ActionResult ScheduleDeactive(long Id, string remark)
 {
     try
     {
         ScheduleMachine olditem  = oldScheduledata(Id);
         ScheduleMachine Schedule = new ScheduleMachine();
         Schedule.Id     = Id;
         Schedule.Status = "Deactive";
         scheModel.ScheduleMachines.Attach(Schedule);
         scheModel.Entry(Schedule).Property(x => x.Status).IsModified = true;
         at.InsrtHistory((tblEmployee)Session["EmployeeData"], olditem.Id, "ScheduleMachine", olditem.Status.ToString(), Schedule.Status.ToString(), remark);
         at.InsrtHistory((tblEmployee)Session["EmployeeData"], olditem.Id, "ScheduleMachine", olditem.CreatedDate.ToString(), DateTime.Now.ToString(), remark);
         scheModel.SaveChanges();
         return(Json("Data Deactive Successfull", JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         at.InsrtHistory((tblEmployee)Session["EmployeeData"], Id, "ScheduleMachine", "NA", "Deactive", ex.Message);
         throw;
     }
 }
Ejemplo n.º 2
0
        public ActionResult ScheduleCreation(ScheduleMachine SM)
        {
            try
            {
                //var endDateID = Convert.ToInt64(SM.TillDate);
                //var enddaateType = scheModel.tblScheduleEndTypes.Where(x => x.scheduleEnd_Id == endDateID).FirstOrDefault();
                //SM.TillDate = enddaateType.ScheduleEnd_Type;

                var isExistm = scheModel.ScheduleMachines.Any(x => x.Id == SM.Id);
                if (!isExistm)
                {
                    var wfstep = scheModel.tblMachineCreations.
                                 Join(
                        scheModel.tblWorkFlowChilds,
                        M => M.Machine_Workflow,
                        WC => WC.WorFlowId,
                        (M, WC) => new
                    {
                        MachineId = M.Machine_Id,
                        wfID      = WC.WorFlowId,
                        wfChildId = WC.WFChild_Id,
                        flowStep  = WC.FlowStep,
                    }
                        ).Where(x => x.MachineId == SM.MachineId).ToList();
                    long WorkflowID = 0;
                    foreach (var item in wfstep)
                    {
                        WorkflowID = Convert.ToInt64(item.wfID);
                        if (item.flowStep == "Creater")
                        {
                            SM.ScheduleMovedStep = item.wfChildId + 1;
                            break;
                        }
                        else
                        {
                            SM.ScheduleMovedStep = item.wfChildId;
                            break;
                        }
                    }
                    var wfstepUpdated = scheModel.tblWorkFlowChilds.Where(x => x.WFChild_Id == SM.ScheduleMovedStep && x.WorFlowId == WorkflowID).FirstOrDefault();
                    if (wfstepUpdated == null)
                    {
                        SM.Status = "Completed";
                    }
                    else
                    {
                        SM.Status = wfstepUpdated.FlowStep;
                    }


                    DateTime date;
                    SM.CreatedBy         = ((tblEmployee)(Session["EmployeeData"])).Employee_Id;
                    SM.CreatedDepartment = ((tblEmployee)(Session["EmployeeData"])).Employee_Department;
                    date = Convert.ToDateTime(SM.ScheduleDueDate);
                    SM.BeforegracedDate = date.Subtract(TimeSpan.FromDays(Convert.ToInt64(SM.BGracedPeriod)));
                    SM.AftergracedDate  = date.AddDays(Convert.ToInt64(SM.AGrancedPeriod));
                    SM.CreatedDate      = DateTime.Now;
                    scheModel.ScheduleMachines.Add(SM);
                    scheModel.SaveChanges();
                    at.InsrtHistory((tblEmployee)Session["EmployeeData"], SM.Id, "ScheduleMachine", "NA", "New Schedule Created", SM.otherdata.Remark);
                    return(Json("Save Success", JsonRequestBehavior.AllowGet));
                }
                else
                {
                    ScheduleMachine olditem = oldScheduledata(SM.Id);

                    if (olditem.Status == "Rejected")
                    {
                        ScheduleMachine oldS = new ScheduleMachine();
                        oldS.Id     = SM.Id;
                        oldS.Status = "AfterReject";
                        scheModel.ScheduleMachines.Attach(oldS);
                        scheModel.Entry(oldS).Property(x => x.Status).IsModified = true;
                        scheModel.SaveChanges();
                    }

                    var MachineID = Convert.ToInt64(SM.otherdata.MachineID);
                    var wfstep    = scheModel.tblMachineCreations.
                                    Join(
                        scheModel.tblWorkFlowChilds,
                        M => M.Machine_Workflow,
                        WC => WC.WorFlowId,
                        (M, WC) => new
                    {
                        MachineId = M.Machine_Id,
                        wfID      = WC.WorFlowId,
                        wfChildId = WC.WFChild_Id,
                        flowStep  = WC.FlowStep,
                    }
                        ).Where(x => x.MachineId == MachineID).ToList();
                    long WorkflowID = 0;
                    foreach (var item in wfstep)
                    {
                        WorkflowID = Convert.ToInt64(item.wfID);
                        if (item.flowStep == "Creater")
                        {
                            SM.ScheduleMovedStep = item.wfChildId + 1;
                            break;
                        }
                        else
                        {
                            SM.ScheduleMovedStep = item.wfChildId;
                            break;
                        }
                    }
                    var wfstepUpdated = scheModel.tblWorkFlowChilds.Where(x => x.WFChild_Id == SM.ScheduleMovedStep && x.WorFlowId == WorkflowID).FirstOrDefault();
                    if (wfstepUpdated == null)
                    {
                        SM.Status = "Completed";
                    }
                    else
                    {
                        SM.Status = wfstepUpdated.FlowStep;
                    }

                    DateTime date;
                    SM.CreatedBy         = ((tblEmployee)(Session["EmployeeData"])).Employee_Id;
                    SM.CreatedDepartment = ((tblEmployee)(Session["EmployeeData"])).Employee_Department;
                    date = Convert.ToDateTime(SM.ScheduleDueDate);
                    SM.BeforegracedDate = date.Subtract(TimeSpan.FromDays(Convert.ToInt64(SM.BGracedPeriod)));
                    SM.AftergracedDate  = date.AddDays(Convert.ToInt64(SM.AGrancedPeriod));
                    SM.CreatedDate      = DateTime.Now;
                    SM.MachineId        = MachineID;
                    scheModel.ScheduleMachines.Add(SM);
                    scheModel.SaveChanges();

                    if (olditem.ScheduleType != SM.ScheduleType)
                    {
                        at.InsrtHistory((tblEmployee)Session["EmployeeData"], olditem.Id, "ScheduleMachine", olditem.ScheduleType.ToString(), SM.ScheduleType.ToString(), SM.otherdata.Remark);
                    }
                    if (olditem.FrequencyType != SM.FrequencyType)
                    {
                        at.InsrtHistory((tblEmployee)Session["EmployeeData"], olditem.Id, "ScheduleMachine", olditem.FrequencyType.ToString(), SM.FrequencyType.ToString(), SM.otherdata.Remark);
                    }
                    if (olditem.InstallationDate != SM.InstallationDate)
                    {
                        at.InsrtHistory((tblEmployee)Session["EmployeeData"], olditem.Id, "ScheduleMachine", olditem.InstallationDate.ToString(), SM.InstallationDate.ToString(), SM.otherdata.Remark);
                    }
                    if (olditem.ScheduleDueDate != SM.ScheduleDueDate)
                    {
                        at.InsrtHistory((tblEmployee)Session["EmployeeData"], olditem.Id, "ScheduleMachine", olditem.ScheduleDueDate.ToString(), SM.ScheduleDueDate.ToString(), SM.otherdata.Remark);
                    }
                    if (olditem.BGracedPeriod != SM.BGracedPeriod)
                    {
                        at.InsrtHistory((tblEmployee)Session["EmployeeData"], olditem.Id, "ScheduleMachine", olditem.BGracedPeriod.ToString(), SM.BGracedPeriod.ToString(), SM.otherdata.Remark);
                    }
                    if (olditem.AGrancedPeriod != SM.AGrancedPeriod)
                    {
                        at.InsrtHistory((tblEmployee)Session["EmployeeData"], olditem.Id, "ScheduleMachine", olditem.AGrancedPeriod.ToString(), SM.AGrancedPeriod.ToString(), SM.otherdata.Remark);
                    }
                    if (olditem.TillDate != SM.TillDate)
                    {
                        at.InsrtHistory((tblEmployee)Session["EmployeeData"], olditem.Id, "ScheduleMachine", olditem.TillDate.ToString(), SM.TillDate.ToString(), SM.otherdata.Remark);
                    }
                    if (olditem.Comment != SM.Comment)
                    {
                        at.InsrtHistory((tblEmployee)Session["EmployeeData"], olditem.Id, "ScheduleMachine", olditem.Comment.ToString(), SM.Comment.ToString(), SM.otherdata.Remark);
                    }
                    if (olditem.CreatedBy != SM.CreatedBy)
                    {
                        at.InsrtHistory((tblEmployee)Session["EmployeeData"], olditem.Id, "ScheduleMachine", olditem.CreatedBy.ToString(), SM.CreatedBy.ToString(), SM.otherdata.Remark);
                    }
                    at.InsrtHistory((tblEmployee)Session["EmployeeData"], olditem.Id, "ScheduleMachine", olditem.CreatedDate.ToString(), DateTime.Now.ToString(), SM.otherdata.Remark);


                    at.InsrtHistory((tblEmployee)Session["EmployeeData"], SM.Id, "ScheduleMachine", "NA", "New Schedule Created", SM.otherdata.Remark);
                    return(Json("Update Success", JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e) { throw; }
        }
Ejemplo n.º 3
0
        public ActionResult CreateSchedule(ScheduleMachine sm)
        {
            // var olddata = scheModel.ScheduleMachines.Where(x => x.Id == sm.Id);
            var isExist = scheModel.ScheduleMachines.Any(x => x.Id == sm.Id);

            if (!isExist)
            {
                sm.CreatedDate       = DateTime.Now;
                sm.CreatedBy         = ((tblEmployee)(Session["EmployeeData"])).Employee_Id;
                sm.CreatedDepartment = ((tblEmployee)(Session["EmployeeData"])).Employee_Department;
                sm.StartScheduleDate = Convert.ToDateTime(sm.StartScheduleDate);
                sm.EndScheduleDate   = Convert.ToDateTime(sm.EndScheduleDate);
                scheModel.ScheduleMachines.Add(sm);
                scheModel.SaveChanges();
                at.InsrtHistory((tblEmployee)Session["EmployeeData"], sm.Id, "ScheduleMachine", "NA", "Created Asset", sm.otherdata.Remark);
                return(Json("Schedule Generate", JsonRequestBehavior.AllowGet));
            }
            else
            {
                if (sm.Status == "Pass")
                {
                    sm.ApprovedDate = DateTime.Now;
                }
                ScheduleMachine olditem = oldentrydata(sm.Id);

                sm.CreatedDate = DateTime.Now;
                sm.CreatedBy   = ((tblEmployee)(Session["EmployeeData"])).Employee_Id;
                //sm.EmployeeHead = ((tblEmployee)(Session["EmployeeData"])).UserHead_Id;
                sm.StartScheduleDate = Convert.ToDateTime(sm.StartScheduleDate);
                sm.EndScheduleDate   = Convert.ToDateTime(sm.EndScheduleDate);
                scheModel.ScheduleMachines.Attach(sm);
                //scheModel.Entry(sm).State = EntityState.Modified;
                //foreach (var olditem in olddata)
                // {
                if (olditem.MachineId != sm.MachineId)
                {
                    at.InsrtHistory((tblEmployee)Session["EmployeeData"], sm.MachineId, "ScheduleMachine", olditem.MachineId.ToString(), sm.MachineId.ToString(), sm.otherdata.Remark);
                    scheModel.Entry(sm).Property(x => x.MachineId).IsModified = true;
                }
                if (olditem.MachineLocation != sm.MachineLocation)
                {
                    at.InsrtHistory((tblEmployee)Session["EmployeeData"], sm.MachineId, "ScheduleMachine", olditem.MachineLocation.ToString(), sm.MachineLocation.ToString(), sm.otherdata.Remark);
                    scheModel.Entry(sm).Property(x => x.MachineLocation).IsModified = true;
                }
                if (olditem.ScheduleType != sm.ScheduleType)
                {
                    at.InsrtHistory((tblEmployee)Session["EmployeeData"], sm.MachineId, "ScheduleMachine", olditem.ScheduleType.ToString(), sm.ScheduleType.ToString(), sm.otherdata.Remark);
                    scheModel.Entry(sm).Property(x => x.ScheduleType).IsModified = true;
                }
                if (olditem.StartScheduleDate != sm.StartScheduleDate)
                {
                    at.InsrtHistory((tblEmployee)Session["EmployeeData"], sm.MachineId, "ScheduleMachine", olditem.StartScheduleDate.ToString(), sm.StartScheduleDate.ToString(), sm.otherdata.Remark);
                    scheModel.Entry(sm).Property(x => x.StartScheduleDate).IsModified = true;
                }
                if (olditem.EndScheduleDate != sm.EndScheduleDate)
                {
                    at.InsrtHistory((tblEmployee)Session["EmployeeData"], sm.MachineId, "ScheduleMachine", olditem.EndScheduleDate.ToString(), sm.EndScheduleDate.ToString(), sm.otherdata.Remark);
                    scheModel.Entry(sm).Property(x => x.EndScheduleDate).IsModified = true;
                }
                if (olditem.AsignTo != sm.AsignTo)
                {
                    at.InsrtHistory((tblEmployee)Session["EmployeeData"], sm.MachineId, "ScheduleMachine", olditem.AsignTo.ToString(), sm.AsignTo.ToString(), sm.otherdata.Remark);
                    scheModel.Entry(sm).Property(x => x.AsignTo).IsModified = true;
                }
                if (olditem.Status != sm.Status)
                {
                    at.InsrtHistory((tblEmployee)Session["EmployeeData"], sm.MachineId, "ScheduleMachine", olditem.Status.ToString(), sm.Status.ToString(), sm.otherdata.Remark);
                    scheModel.Entry(sm).Property(x => x.Status).IsModified = true;
                }
                if (olditem.AsignType != sm.AsignType)
                {
                    at.InsrtHistory((tblEmployee)Session["EmployeeData"], sm.MachineId, "ScheduleMachine", olditem.AsignType.ToString(), sm.AsignType.ToString(), sm.otherdata.Remark);
                    scheModel.Entry(sm).Property(x => x.AsignType).IsModified = true;
                }
                if (olditem.ApprovedDate != sm.ApprovedDate)
                {
                    at.InsrtHistory((tblEmployee)Session["EmployeeData"], sm.MachineId, "ScheduleMachine", olditem.ApprovedDate.ToString(), sm.ApprovedDate.ToString(), sm.otherdata.Remark);
                    scheModel.Entry(sm).Property(x => x.ApprovedDate).IsModified = true;
                }
                if (olditem.CreatedBy != sm.CreatedBy)
                {
                    at.InsrtHistory((tblEmployee)Session["EmployeeData"], sm.MachineId, "ScheduleMachine", olditem.CreatedBy.ToString(), sm.CreatedBy.ToString(), sm.otherdata.Remark);
                    scheModel.Entry(sm).Property(x => x.CreatedBy).IsModified = true;
                }

                at.InsrtHistory((tblEmployee)Session["EmployeeData"], sm.MachineId, "ScheduleMachine", olditem.CreatedDate.ToString(), DateTime.Now.ToString(), sm.otherdata.Remark);
                //}
                scheModel.SaveChanges();
                return(Json("Update Success", JsonRequestBehavior.AllowGet));
            }
        }