private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (mModel.AreAllValid())
            {
                CmsWebServiceClient mCmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

                mCmsWebServiceClient.AddMobilePlantRevisionHistoryCompleted +=
                    (s1, e1) =>
                    {
                        AddedRevisionHistory = e1.Result;
                        DialogResult = true;
                    };

                mModel.User = CMS.User;
                mModel.Date = DateTime.Now;
                mCmsWebServiceClient.AddMobilePlantRevisionHistoryAsync(mModel.History);
            }
        }
 public MobilePlantRevisionHistoryViewModel(MobilePlantRevisionHistory history)
 {
     mHistory = history;
 }
        private MobilePlantRevisionHistory BuildRevisionHistory(MobilePlantComponent existing)
        {
            const decimal incrediment = 0.001m;
            var revision = new decimal(1.000);

            List<decimal> foo = (from x in Cee.MobilePlantRevisionHistories where x.MobilePlantId == existing.MobilePlantId orderby x.Revision descending select x.Revision).ToList();

            if (foo.Count > 0)
            {
                revision = foo[0] + incrediment;
            }

            var rvh = new MobilePlantRevisionHistory
            {
                Date = DateTime.Now,
                MobilePlantId = existing.MobilePlantId,
                UserId = MetaData.UserId,
                Description = BuildRevisionHistoryInsertVersionComment(MetaData.RevisionHistoryComment, revision),
                Revision = revision,
                IsSystemMessage = true
            };
            return rvh;
        }
        private void OkButtonHander(object parameter)
        {
            if (!AreAllValid()){return;}

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            //Save
            cmsWebServiceClient.SaveMobilePlantCompleted +=
                (s2, e2) =>
                {
                    if (e2.Result.HasErrors)
                    {
                        View.ValidationPopup.Show(Utils.BuildValidationResultFromServerErrors("Save Mobile Plant Failed", e2.Result.ServerErrorMessages));
                    }
                    else
                    {
                        View.SavedMobilePlant = e2.Result.EntityResult;
                        View.DialogResult = true;
                        EventAggregator.GetEvent<PrismEvents.RefreshNavigationEvent>().Publish(new QuickMobilePlant());
                    }

                };

            mMobilePlant.MobileHirerId = mMobilePlant.MobileHirer.Id;
            mMobilePlant.MobileOwnerId = mMobilePlant.MobileOwner.Id;

            mMobilePlant.MobilePlantRevisionHistories = new List<MobilePlantRevisionHistory>();
            MobilePlantRevisionHistory rh = new MobilePlantRevisionHistory();
            rh.Date = DateTime.Now;
            rh.Description = "Initial Creation";
            rh.Revision = new decimal(0.001);
            rh.UserId = CMS.User.Id;
            mMobilePlant.MobilePlantRevisionHistories.Add(rh);

            cmsWebServiceClient.SaveMobilePlantAsync(mMobilePlant, CMS.User.Id);
        }
        private void SaveAcceptanceTestButton_Click(object sender, RoutedEventArgs e)
        {
            CmsWebServiceClient mCmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            mCmsWebServiceClient.AddMobilePlantRevisionHistoryCompleted +=
                (s1, e1) =>
                {
                    AddedRevisionHistory = e1.Result;
                    DialogResult = true;
                };

            mModel.User = CMS.User;
            mModel.Date = DateTime.Now;
            mModel.Description = "Site Acceptance Testing";
            mModel.Issue = null;
            mCmsWebServiceClient.AddMobilePlantRevisionHistoryAsync(mModel.History);
        }
Esempio n. 6
0
        private void AddInsertRevisionHistory(MobilePlant newEquipment)
        {
            var revision = new decimal(1.000);

            Cee.MobilePlants.Add(newEquipment);
            var rvh = new MobilePlantRevisionHistory
            {
                Date = DateTime.Now,
                UserId = MetaData.UserId,
                Description = BuildRevisionHistoryInsertComment(MetaData.RevisionHistoryComment),
                Revision = revision,
                IsSystemMessage = true
            };
            newEquipment.MobilePlantRevisionHistories.Add(rvh);
        }
        public MobilePlantRevisionHistory AddMobilePlantRevisionHistory(MobilePlantRevisionHistory history)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                const decimal incrediment = 0.001m;

                var latestPrh = (from x in cee.MobilePlantRevisionHistories
                                 where x.MobilePlantId == history.MobilePlantId
                                 select x.Revision).ToList();

                if (latestPrh.Count > 0)
                {
                    history.Revision = latestPrh.AsQueryable().Max() + incrediment;
                }
                else
                {
                    history.Revision = incrediment;
                }

                int userid = history.UserId;
                int? issueId = history.IssueId;

                history.Issue = null;
                history.User = null;
                history.IssueId = null;
                history.IsSystemMessage = false;

                if (issueId.HasValue && issueId.Value > 0)
                {
                    history.IssueId = issueId;
                }

                history.UserId = userid;

                cee.MobilePlantRevisionHistories.Add(history);
                cee.SaveChanges();

                return (from x in cee.MobilePlantRevisionHistories.Include("Issue").Include("User") where x.Id == history.Id select x).FirstOrDefault();
            }
        }
        private void SaveMobilePlantComponents(IEnumerable<MobilePlantComponent> mobilePlantComponents, CmsEntities cee, int mobilePlantEquipmentId, int userId)
        {
            foreach (var mobilePlantComponent in mobilePlantComponents)
            {
                var q = (from x in cee.MobilePlantComponents
                         where x.Id == mobilePlantComponent.Id
                         select x).FirstOrDefault();

                if (q != null)
                {
                    if (q.LastInspectedDate != mobilePlantComponent.LastInspectedDate)
                    {
                        MobilePlantRevisionHistory rv = new MobilePlantRevisionHistory
                        {
                            MobilePlantId = mobilePlantEquipmentId,
                            Date = DateTime.Now,
                            UserId = userId,
                            Description = string.Format("Component '{0}': Last Inspected Date changed from '{1}' to '{2}'.", mobilePlantComponent.Name, q.LastInspectedDate, mobilePlantComponent.LastInspectedDate),
                            IsSystemMessage = true
                        };
                        AddMobilePlantRevisionHistoryInternal(rv, cee);
                    }

                    //Update
                    cee.Entry(q).CurrentValues.SetValues(mobilePlantComponent);

                }
                else
                {
                    //Add new
                    q = new MobilePlantComponent();
                    q.MobilePlantId = mobilePlantComponent.MobilePlantId;
                    q.MobilePlantComponentTypeId = mobilePlantComponent.MobilePlantComponentTypeId;
                    q.Name = mobilePlantComponent.Name;
                    q.Ordinal = mobilePlantComponent.Ordinal;
                    q.NextInspectionDate = mobilePlantComponent.NextInspectionDate;
                    q.LastInspectedById = mobilePlantComponent.LastInspectedById;
                    q.LastInspectedDate = mobilePlantComponent.LastInspectedDate;
                    q.LastModifiedById = mobilePlantComponent.LastModifiedById;
                    q.LastModifiedDate = mobilePlantComponent.LastModifiedDate;
                    q.Description = mobilePlantComponent.Description;
                    q.ManufacturerId = mobilePlantComponent.ManufacturerId;
                    q.ModelId = mobilePlantComponent.ModelId;

                    cee.MobilePlantComponents.Add(q);
                }

                foreach (var mobilePlantComponentPropertyValue in mobilePlantComponent.MobilePlantPropertyValues)
                {
                    var qq = (from x in cee.MobilePlantPropertyValues
                              where x.Id == mobilePlantComponentPropertyValue.Id
                              select x).FirstOrDefault();

                    if (qq != null)
                    {
                        cee.Entry(qq).CurrentValues.SetValues(mobilePlantComponentPropertyValue);
                    }
                    else
                    {
                        cee.MobilePlantPropertyValues.Add(mobilePlantComponentPropertyValue);
                    }
                }
            }
        }
        private void AddMobilePlantRevisionHistoryInternal(MobilePlantRevisionHistory history, CmsEntities cee)
        {
            const decimal incrediment = 0.001m;

            var latestPrh = (from x in cee.MobilePlantRevisionHistories
                             where x.MobilePlantId == history.MobilePlantId
                             select x.Revision).ToList();

            if (latestPrh.Count > 0)
            {
                history.Revision = latestPrh.AsQueryable().Max() + incrediment;
            }
            else
            {
                history.Revision = incrediment;
            }

            int userid = history.UserId;
            int? issueId = history.IssueId;

            history.Issue = null;
            history.User = null;
            history.IssueId = null;

            if (issueId.HasValue && issueId.Value > 0)
            {
                history.IssueId = issueId;
            }

            history.UserId = userid;

            cee.MobilePlantRevisionHistories.Add(history);
            cee.SaveChanges();
        }
        private static MobilePlantRevisionHistory BuildRevisonHistory(MobilePlant equip, int userId, IEnumerable<MobilePlantComponent> mobilePlantComponentsToBeDeleted, CmsEntities cee)
        {
            MobilePlantRevisionHistory rh = new MobilePlantRevisionHistory();

            string[] deleted = (from x in mobilePlantComponentsToBeDeleted select "Name: " + x.Name + " Type: " + x.MobilePlantComponentType.Name).ToArray();

            if (deleted.Length > 0)
            {
                string removedItems = string.Join(",", deleted);

                rh.Description = string.Format("Mobile Plant Components were removed : {0}", removedItems);
                rh.MobilePlantId = equip.Id;
                rh.Date = DateTime.Now;
                rh.UserId = userId;
                rh.IsSystemMessage = true;
                const decimal incrediment = 0.001m;

                var latestPrh = (from x in cee.MobilePlantRevisionHistories
                                 where x.MobilePlantId == equip.Id
                                 select x.Revision).ToList();

                if (latestPrh.Count > 0)
                {
                    rh.Revision = latestPrh.AsQueryable().Max() + incrediment;
                }
                else
                {
                    rh.Revision = incrediment;
                }

                cee.MobilePlantRevisionHistories.Add(rh);
            }
            return rh;
        }