예제 #1
0
        public LaborVM(WorkOrderDetailVM workOrderDetailVM, MaximoLabTrans labTrans = null)
        {
            WorkOrderDetailVM = workOrderDetailVM;
            CancelCommand     = new Command.CancelCommand <LaborVM>(this);
            SaveCommand       = new Command.SaveCommand <LaborVM>(this);
            LabTrans          = labTrans;


            List <string> craftrate;

            if (((App)Application.Current).AppType == "PM")
            {
                craftrate = new string[] { "SSWR", "SSLR", "SSWL" }.ToList();
            }
            else
            {
                craftrate = new string[] { "SSWR", "SSLR", "SSWL", "SCRW", "CNRW" }.ToList();
            }

            var labors = MaximoServiceLibrary.AppContext.laborRepository.findAll().Where(labor => labor.laborcraftrate.Where(laborcraftrate => craftrate.Contains(laborcraftrate.craft)).Count() > 0);

            LaborList = new List <MaximoPerson>();
            foreach (var labor in labors)
            {
                LaborList.AddRange(labor.person.Where(per => per.status == "ACTIVE").ToList());
            }

            if (LabTrans != null)
            {
                StartDate   = LabTrans.startdateentered + LabTrans.starttimeentered.TimeOfDay;
                Duration    = new DateTime(1900, 1, 1) + (LabTrans.finishdateentered + LabTrans.finishtimeentered.TimeOfDay - LabTrans.startdateentered - LabTrans.starttimeentered.TimeOfDay);
                IsDriver    = LabTrans.dcw_truckdriver;
                IsSecondMan = LabTrans.dcw_trucksecond;
                IsLeadMan   = LabTrans.dcw_trucklead;
                Labor       = LabTrans.laborcode;
                Type        = LabTrans.transtype;
            }
            else
            {
                StartDate = DateTime.Now;
                Type      = "WORK";
                Labor     = MaximoServiceLibrary.AppContext.synchronizationService.mxuser.userPreferences?.setting?.leadMan;
            }
        }
        public void Execute(object parameter)
        {
            if (parameter == null)
            {
                return;
            }
            if (((MaximoWorkOrder)parameter).status != "DISPTCHD")
            {
                return;
            }
            var values = MaximoServiceLibrary.AppContext.workOrderRepository.findNot("startTimerDate", null).ToList();

            if (values.Count > 0)
            {
                if (values[0].Id == ((MaximoWorkOrder)parameter).Id)
                {
                }
                else
                {
                    MessageBox.Show($"Wonum : {values[0].wonum} is still start timer");
                    var woo = WorkOrderListVM.WorkOrders.Where(w => w.Id == values[0].Id).FirstOrDefault();
                    if (woo != null)
                    {
                        WorkOrderListVM.listView.ScrollIntoView(woo);
                    }

                    return;
                }
            }
            else
            {
            }

            MaximoWorkOrder wo = ((MaximoWorkOrder)parameter);

            if (wo.startTimerDate == null)
            {
                wo.startTimerDate = DateTime.Now;
                wo.timerImageUri  = "pack://application:,,,/CatchBasin;component/Resources/Images/startWatch.png";
                MaximoServiceLibrary.AppContext.workOrderRepository.upsert(wo);
                WorkOrderListVM.Update();
            }
            else
            {
                DateTime stopTimerDate  = DateTime.Now;
                DateTime startTimerDate = Convert.ToDateTime(wo.startTimerDate);
                TimeSpan?time           = stopTimerDate - wo.startTimerDate;
                MaximoServiceLibrary.AppContext.Log.Warn($"time :{time}");

                var mxuser = MaximoServiceLibrary.AppContext.synchronizationService.mxuser;

                MaximoLabTrans labTrans       = new MaximoLabTrans();
                MaximoLabTrans secondlabTrans = new MaximoLabTrans();


                labTrans.startdateentered  = startTimerDate - startTimerDate.TimeOfDay;
                labTrans.starttimeentered  = new DateTime(1900, 1, 1) + startTimerDate.TimeOfDay;
                labTrans.finishdateentered = stopTimerDate - stopTimerDate.TimeOfDay;
                labTrans.finishtimeentered = new DateTime(1900, 1, 1) + stopTimerDate.TimeOfDay;
                labTrans.transdate         = DateTime.Now;

                if (wo.worktype == "EM" || wo.worktype == "INV" || wo.worktype == "EMERG")
                {
                    labTrans.transtype = "TRAV";
                }
                else
                {
                    labTrans.transtype = "WORK";
                }

                var _labors = MaximoServiceLibrary.AppContext.laborRepository.Find("person[*].personid", mxuser.userPreferences.setting?.leadMan).ToList();
                try
                {
                    labTrans.craft = _labors?[0].laborcraftrate?[0].craft;
                }
                catch (Exception e)
                {
                    labTrans.craft = null;
                }

                labTrans.siteid               = "DWS_DSS";
                labTrans.orgid                = "DC_WASA";
                labTrans.dcw_truckdriver      = mxuser.userPreferences.setting?.leadMan == mxuser.userPreferences.setting?.driverMan;
                labTrans.dcw_trucksecond      = false;
                labTrans.dcw_trucklead        = true;
                labTrans.dcw_trucknum         = mxuser.userPreferences.setting.vehiclenum;
                labTrans.enterdate            = DateTime.Now;
                labTrans.laborcode            = mxuser.userPreferences.setting?.leadMan;
                labTrans.enterby              = MaximoServiceLibrary.AppContext.synchronizationService?.mxuser.personId;
                labTrans.syncronizationStatus = LocalDBLibrary.model.SyncronizationStatus.CREATED;



                if (((App)Application.Current).AppType == "PM")
                {
                    secondlabTrans.startdateentered  = startTimerDate - startTimerDate.TimeOfDay;
                    secondlabTrans.starttimeentered  = new DateTime(1900, 1, 1) + startTimerDate.TimeOfDay;
                    secondlabTrans.finishdateentered = stopTimerDate - stopTimerDate.TimeOfDay;
                    secondlabTrans.finishtimeentered = new DateTime(1900, 1, 1) + stopTimerDate.TimeOfDay;
                    secondlabTrans.transdate         = DateTime.Now;
                    if (wo.worktype == "EM" || wo.worktype == "INV" || wo.worktype == "EMERG")
                    {
                        secondlabTrans.transtype = "TRAV";
                    }
                    else
                    {
                        secondlabTrans.transtype = "WORK";
                    }
                    _labors = MaximoServiceLibrary.AppContext.laborRepository.Find("person[*].personid", mxuser.userPreferences.setting?.secondMan).ToList();
                    try
                    {
                        secondlabTrans.craft = _labors?[0].laborcraftrate?[0].craft;
                    }
                    catch (Exception e)
                    {
                        secondlabTrans.craft = null;
                    }
                    secondlabTrans.siteid               = "DWS_DSS";
                    secondlabTrans.orgid                = "DC_WASA";
                    secondlabTrans.dcw_truckdriver      = mxuser.userPreferences.setting?.secondMan == mxuser.userPreferences.setting?.driverMan;
                    secondlabTrans.dcw_trucksecond      = true;
                    secondlabTrans.dcw_trucklead        = false;
                    secondlabTrans.dcw_trucknum         = mxuser.userPreferences.setting.vehiclenum;
                    secondlabTrans.enterdate            = DateTime.Now;
                    secondlabTrans.laborcode            = mxuser.userPreferences.setting?.secondMan;
                    secondlabTrans.enterby              = MaximoServiceLibrary.AppContext.synchronizationService?.mxuser.personId;
                    secondlabTrans.syncronizationStatus = LocalDBLibrary.model.SyncronizationStatus.CREATED;
                }


                MaximoToolTrans tool = new MaximoToolTrans();
                tool.transdate = DateTime.Now;
                tool.toolrate  = 0;
                tool.toolqty   = 1;
                if (time.HasValue)
                {
                    tool.toolhrs = time.Value.TotalHours;
                }
                tool.itemnum              = mxuser.userPreferences.setting.vehiclenum;
                tool.itemsetid            = "IDC_WASA";
                tool.enterdate            = DateTime.Now;
                tool.enterby              = MaximoServiceLibrary.AppContext.synchronizationService?.mxuser.personId;
                tool.langcode             = "EN";
                tool.syncronizationStatus = LocalDBLibrary.model.SyncronizationStatus.CREATED;



                if (WorkOrderListVM.MapVM.WorkOrderDetailIsVisible && wo?.Id == WorkOrderListVM.MapVM.WorkOrderDetailVM.MaximoWorkOrder?.Id)
                {
                    WorkOrderListVM.MapVM.WorkOrderDetailVM.LabTrans.Add(labTrans);
                    if (((App)Application.Current).AppType == "PM")
                    {
                        WorkOrderListVM.MapVM.WorkOrderDetailVM.LabTrans.Add(secondlabTrans);
                    }
                    WorkOrderListVM.MapVM.WorkOrderDetailVM.ToolTrans.Add(tool);
                    WorkOrderListVM.MapVM.WorkOrderDetailVM.MaximoWorkOrder.startTimerDate = null;
                    WorkOrderListVM.MapVM.WorkOrderDetailVM.MaximoWorkOrder.timerImageUri  = "pack://application:,,,/CatchBasin;component/Resources/Images/stopWatch.png";
                }
                else
                {
                    if (wo.labtrans == null)
                    {
                        wo.labtrans = new List <MaximoLabTrans>();
                    }
                    wo.labtrans.Add(labTrans);

                    if (((App)Application.Current).AppType == "PM")
                    {
                        wo.labtrans.Add(secondlabTrans);
                    }

                    if (wo.tooltrans == null)
                    {
                        wo.tooltrans = new List <MaximoToolTrans>();
                    }
                    wo.tooltrans.Add(tool);
                }

                wo.startTimerDate = null;
                wo.timerImageUri  = "pack://application:,,,/CatchBasin;component/Resources/Images/stopWatch.png";
                wo = MaximoServiceLibrary.AppContext.workOrderRepository.upsert(wo);
                WorkOrderListVM.Update();
                if (!WorkOrderListVM.MapVM.WorkOrderDetailIsVisible)
                {
                    WorkOrderListVM.showWorkOrder(wo);
                }
            }
        }
예제 #3
0
        public void Save()
        {
            if (String.IsNullOrEmpty(Labor))
            {
                MessageBox.Show("Please Select Labor", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (LabTrans == null)
            {
                MaximoLabTrans labTrans = new MaximoLabTrans();
                labTrans.startdateentered  = StartDate.Date;
                labTrans.starttimeentered  = new DateTime(1900, 1, 1) + StartDate.TimeOfDay;
                labTrans.finishdateentered = (StartDate + Duration.TimeOfDay).Date;
                labTrans.finishtimeentered = new DateTime(1900, 1, 1) + (StartDate + Duration.TimeOfDay).TimeOfDay;
                labTrans.transdate         = DateTime.Now;
                labTrans.transtype         = Type;


                var _labor = MaximoServiceLibrary.AppContext.laborRepository.Find("person[*].personid", Labor).FirstOrDefault();

                labTrans.craft = _labor?.laborcraftrate.FirstOrDefault()?.craft;


                labTrans.craft           = null;
                labTrans.laborcode       = null;
                labTrans.siteid          = "DWS_DSS";
                labTrans.orgid           = "DC_WASA";
                labTrans.dcw_truckdriver = IsDriver;
                labTrans.dcw_trucksecond = IsSecondMan;
                labTrans.dcw_trucklead   = IsLeadMan;
                labTrans.dcw_trucknum    = MaximoServiceLibrary.AppContext.synchronizationService.mxuser.userPreferences?.setting?.vehiclenum;
                labTrans.enterdate       = DateTime.Now;
                labTrans.laborcode       = Labor;

                labTrans.enterby = MaximoServiceLibrary.AppContext.synchronizationService?.mxuser.personId;
                labTrans.syncronizationStatus = LocalDBLibrary.model.SyncronizationStatus.CREATED;
                WorkOrderDetailVM.LabTrans.Add(labTrans);
            }
            else
            {
                var index = WorkOrderDetailVM.LabTrans.IndexOf(LabTrans);
                LabTrans.dcw_truckdriver   = IsDriver;
                LabTrans.dcw_trucksecond   = IsSecondMan;
                LabTrans.dcw_trucklead     = IsLeadMan;
                LabTrans.transtype         = Type;
                LabTrans.startdateentered  = StartDate.Date;
                LabTrans.starttimeentered  = new DateTime(1900, 1, 1) + StartDate.TimeOfDay;
                LabTrans.finishdateentered = (StartDate + Duration.TimeOfDay).Date;
                LabTrans.finishtimeentered = new DateTime(1900, 1, 1) + (StartDate + Duration.TimeOfDay).TimeOfDay;
                LabTrans.enterdate         = DateTime.Now;
                LabTrans.laborcode         = Labor;
                var _labor = MaximoServiceLibrary.AppContext.laborRepository.Find("person[*].personid", Labor).FirstOrDefault();

                LabTrans.craft = _labor?.laborcraftrate.FirstOrDefault()?.craft;

                LabTrans.enterby = MaximoServiceLibrary.AppContext.synchronizationService?.mxuser.personId;

                if (LabTrans.syncronizationStatus != LocalDBLibrary.model.SyncronizationStatus.CREATED)
                {
                    LabTrans.syncronizationStatus = LocalDBLibrary.model.SyncronizationStatus.MODIFIED;
                }
                WorkOrderDetailVM.LabTrans[index] = LabTrans;

                var otherLabor = WorkOrderDetailVM.LabTrans.FirstOrDefault(lbtrns => lbtrns.startdateentered == LabTrans.startdateentered &&
                                                                           lbtrns.starttimeentered == LabTrans.starttimeentered &&
                                                                           lbtrns.finishdateentered == LabTrans.finishdateentered &&
                                                                           lbtrns.finishtimeentered == LabTrans.finishtimeentered &&
                                                                           lbtrns.laborcode != LabTrans.laborcode);

                if (otherLabor != null)
                {
                    var otherIndex = WorkOrderDetailVM.LabTrans.IndexOf(otherLabor);
                    otherLabor.transtype = Type;
                    if (otherLabor.syncronizationStatus != LocalDBLibrary.model.SyncronizationStatus.CREATED)
                    {
                        otherLabor.syncronizationStatus = LocalDBLibrary.model.SyncronizationStatus.MODIFIED;
                    }
                    WorkOrderDetailVM.LabTrans[otherIndex] = otherLabor;
                }
            }

            Close();
        }