private void Edit(UpdateJournal updateJournal)
 {
     using (var monitorContext = new DefaultContext())
     {
         var journal = monitorContext.Journals.FirstOrDefault(x => x.ID == updateJournal.ID);
         if (journal.Null())
         {
             Message = "请选择要修改的日志";
             return;
         }
         journal.ProjectName = updateJournal.ProjectName;
         journal.Path = updateJournal.Path;
         monitorContext.ModifiedModel(journal);
         monitorContext.SaveChanges();
     }
     Flag = true;
 }
Beispiel #2
0
 private void Edit(UpdateTree updateTree)
 {
     using (var monitorContext = new DefaultContext())
     {
         var tree = monitorContext.Trees.FirstOrDefault(x => x.ID == updateTree.ID);
         if (tree.Null())
         {
             Message = "请选择要修改的服务器";
             return;
         }
         tree.Name = updateTree.Name;
         tree.Description = updateTree.Description;
         tree.IpAddr = updateTree.IpAddr;
         monitorContext.ModifiedModel(tree);
         monitorContext.SaveChanges();
     }
     Flag = true;
 }
Beispiel #3
0
 private void Edit(UpdateCard updateCard)
 {
     using (var defaultContext = new DefaultContext())
     {
         var systemCard = defaultContext.SystemCards.FirstOrDefault(x => x.ID == updateCard.ID);
         if (systemCard.Null())
         {
             Message = "请选择要修改的服务器";
             return;
         }
         systemCard.Action = updateCard.Action;
         systemCard.CardName = updateCard.CardName;
         systemCard.BranchId = updateCard.BranchId;
         defaultContext.ModifiedModel(systemCard);
         defaultContext.SaveChanges();
     }
     Flag = true;
 }
        private void Edit(UpdateDepartment updateDepartment)
        {
            using (var accountContext = new DefaultContext())
            {
                var department = accountContext.Departments.SingleOrDefault(x => x.ID == updateDepartment.ID);
                if (department.Null())
                {
                    return;
                }
                department = updateDepartment.UpdateShowDepartment(department);
                accountContext.ModifiedModel(department);
                var workCard =
                    accountContext.WorkCards.FirstOrDefault(x => x.Owner && x.DepartmentId == updateDepartment.ID);

                if (!workCard.Null())
                {
                    if (workCard.AccountId != updateDepartment.ID)
                    {
                        workCard.Owner = false;
                        accountContext.ModifiedModel(workCard);
                    }
                }
                var newWorkCard =
                        accountContext.WorkCards.FirstOrDefault(x => x.AccountId == updateDepartment.OwnerId && x.DepartmentId == updateDepartment.ID);
                if (!newWorkCard.Null())
                {
                    newWorkCard.Owner = true;
                    accountContext.ModifiedModel(newWorkCard);
                }



                accountContext.SaveChanges();
                Flag = true;
            }
        }
 public void ReplyLetter(UpdateLetter updateLetter)
 {
     using (var content = new DefaultContext())
     {
         var letter = content.Letters.AsNoTracking().FirstOrDefault(x => x.ID == updateLetter.ID);
         if (letter == null)
         {
             return;
         }
         letter.ReplyTime = DateTime.Now;
         letter.Reply = updateLetter.Message;
         content.ModifiedModel(letter);
         content.SaveChanges();
     }
     Flag = true;
 }
 private void Edit(UpdateBranch updateBranch)
 {
     using (var context = new DefaultContext())
     {
         var editBranch = context.Branches.FirstOrDefault(x => x.ID == updateBranch.ID);
         if (editBranch.Null())
         {
             Message = "修改菜单不存在";
             return;
         }
         editBranch.Title = updateBranch.Title;
         editBranch.Level = updateBranch.Level;
         editBranch.PreBranch = updateBranch.PreBranch;
         editBranch.SortID = updateBranch.SortID;
         editBranch.Logo = updateBranch.Logo;
         editBranch.ActionName = updateBranch.ActionName;
         editBranch.AreaName = updateBranch.AreaName;
         editBranch.Description = updateBranch.Description;
         context.ModifiedModel(editBranch);
         context.SaveChanges();
     }
 }
 private void EditComment(UpdateWorkComment updateWorkComment)
 {
     using (var workContext = new DefaultContext())
     {
         var workComment = workContext.WorkComments.FirstOrDefault(x => x.ID == updateWorkComment.ID);
         workComment = updateWorkComment.Update(workComment);
         workContext.ModifiedModel(workComment);
         workContext.SaveChanges();
         Flag = true;
     }
 }
 private void Edit(UpdateWorkRecord updateWorkRecord)
 {
     using (var workContext = new DefaultContext())
     {
         var workRecord = workContext.WorkRecords.FirstOrDefault(x => x.ID == updateWorkRecord.ID);
         if (workRecord.Null())
         {
             Message = "被修改日志不存在!";
             return;
         }
         if (workRecord.CreateTime.Date.AddHours(27) < DateTime.Now)
         {
             Message = "日志已经被锁定无法修改!";
             return;
         }
         workRecord = updateWorkRecord.Update(workRecord);
         workContext.ModifiedModel(workRecord);
         workContext.SaveChanges();
         Flag = true;
     }
 }
        public void Execution()
        {
            var nowTime = DateTime.Today.AddHours(DateTime.Now.Hour);
            using (var monitorContext = new DefaultContext())
            {
                //var warehouses = monitorContext.Warehouses.FirstOrDefault(x => x.KeyName == SystemType.LastUpdateCpu);
                //if (warehouses == null)
                //{
                //    warehouses = new Warehouse();
                //    warehouses.ID = Guid.NewGuid();
                //    warehouses.KeyName = SystemType.LastUpdateCpu;
                //    warehouses.Value = "1";
                //    warehouses.LastUpdateTime = SqlDateTime.MinValue.Value;
                //    monitorContext.Warehouses.Add(warehouses);
                //}
                //else
                //{
                //    lastUpdate = warehouses.LastUpdateTime;
                //    monitorContext.ModifiedModel(warehouses);
                //}
                //if (nowTime < lastUpdate)
                //{
                //    return;
                //}

                var trees = monitorContext.Trees.Where(x => x.LastUpdateTime < nowTime);
                if (!trees.Any())
                {
                    return;
                }
                foreach (var tree in trees)
                {
                    var heartbeatList = new List<HeartbeatBody>();
                    var electrocardiograms = monitorContext.Electrocardiograms.Where(x => x.CreateTime >= tree.LastUpdateTime && x.CreateTime < nowTime).ToList();
                    var machIds = electrocardiograms.Select(x => x.MachineId).Distinct().ToList();
                    foreach (var machId in machIds)
                    {
                        var electrocGroup = electrocardiograms.Where(x => x.MachineId == machId).GroupBy(x => new DateTime(x.CreateTime.Year, x.CreateTime.Month, x.CreateTime.Day, x.CreateTime.Hour, 0, 0)).OrderBy(x => x.Key);
                        var maxTime = tree.LastUpdateTime;
                        foreach (var eletro in electrocGroup)
                        {
                            var heartbeat = new HeartbeatBody();
                            heartbeat.LogTime = eletro.Key;
                            heartbeat.MaxNum = eletro.Max(x => x.CpuNum);
                            heartbeat.AvgNum = eletro.Average(x => x.CpuNum);
                            heartbeat.MaxMemory = eletro.Max(x => x.AllMemory - x.Memory);
                            heartbeat.AvgMemory = eletro.Average(x => x.AllMemory - x.Memory);
                            heartbeat.HourTime = eletro.Key.Hour;
                            heartbeatList.Add(heartbeat);
                            if (heartbeat.LogTime > maxTime)
                            {
                                maxTime = heartbeat.LogTime;
                            }
                        }

                        IPostHttpEvent postHttpEvent = new HeartbeatEvent(heartbeatList, machId);
                        DomainEvent.Publish(postHttpEvent);

                        tree.LastUpdateTime = maxTime;
                        monitorContext.ModifiedModel(tree);
                    }
                }

                Flag = true;
                monitorContext.SaveChanges();
            }
        }
        public void ChangePassword(ChangeAccount changeAccount)
        {

            using (var accountContext = new DefaultContext())
            {
                var account = accountContext.Accounts.FirstOrDefault(x => x.ID == changeAccount.ID);
                if (account == null)
                {
                    Message = "输入账号不存在";
                    return;
                }
                if (!account.State)
                {
                    Message = "账号已禁用";
                    return;
                }
                if (account.Password != changeAccount.OldPassword.MD5().ToLower())
                {
                    Message = "旧密码错误,请重新输入!";
                    return;
                }
                if (string.IsNullOrEmpty(changeAccount.NewPassword))
                {
                    Message = "新密码不能为空,请重新输入!";
                    return;
                }
                account.SetPassword(changeAccount.NewPassword);
                accountContext.ModifiedModel(account);
                accountContext.SaveChanges();
                Flag = true;
            }
        }
 public void Edit(UpdateAccount updateAccount)
 {
     using (var defaultContent = new DefaultContext())
     {
         var account = defaultContent.Accounts.FirstOrDefault(x => x.ID == updateAccount.ID);
         if (account.Null())
         {
             Message = "请选择要修改的账号";
             return;
         }
         account.LastLoginTime = DateTime.Now;
         account.LoginID = updateAccount.LoginID;
         account.Name = updateAccount.Name;
         defaultContent.ModifiedModel(account);
         var workCards = defaultContent.WorkCards.Where(x => x.AccountId == updateAccount.ID).ToList();
         if (workCards.Count() == 1)
         {
             var workCard = workCards.FirstOrDefault();
             workCard.DepartmentId = updateAccount.DepartmentId;
             defaultContent.ModifiedModel(workCard);
         }
         if (!workCards.Any())
         {
             var workCard = new WorkCard();
             workCard.ID = Guid.NewGuid();
             workCard.AccountId = updateAccount.ID;
             workCard.DepartmentId = updateAccount.DepartmentId;
             defaultContent.WorkCards.Add(workCard);
         }
         defaultContent.SaveChanges();
     }
     Flag = true;
 }
 private void EditComment(UpdateWeekComment updateWeekComment)
 {
     using (var workContext = new DefaultContext())
     {
         var comment = workContext.WeekComments.FirstOrDefault(x => x.ID == updateWeekComment.ID);
         if (comment.Null())
         {
             Message = "修改的评价不存在";
             return;
         }
         var weekComment = updateWeekComment.UpdateComment(comment);
         workContext.ModifiedModel(weekComment);
         workContext.SaveChanges();
         Flag = true;
     }
 }
        //private void AddTarget(UpdateWeeklyTarget updateWeeklyTarget)
        //{
        //    var weekNum = DateTimeUtility.GetWeekOfYear(DateTime.Today);
        //    using (var workContext = new DefaultContext())
        //    {
        //        var weekTarget = workContext.WeekTargets.FirstOrDefault(x => x.WeekNum == weekNum && x.DepartmentId == updateWeeklyTarget.DepartmentId);
        //        if (!weekTarget.Null())
        //        {
        //            Message = "本周已经有日志";
        //            return;
        //        }
        //        weekTarget = updateWeeklyTarget.CreateWeekTarget(weekNum);
        //        workContext.WeekTargets.Add(weekTarget);
        //        Flag = true;
        //    }
        //}

        //private void EditTarget(UpdateWeeklyTarget updateWeeklyTarget)
        //{
        //    var weekNum = DateTimeUtility.GetWeekOfYear(DateTime.Today);


        //    using (var workContext = new DefaultContext())
        //    {
        //    }
        //}


        public void UpdateSummary(UpdateWeekSummary updateWeekSummary)
        {
            using (var workContext = new DefaultContext())
            {
                var weekTarget = workContext.WeekTargets.FirstOrDefault(x => x.ID == updateWeekSummary.ID);
                if (weekTarget.Null())
                {
                    Message = "总结周记不存在";
                    return;
                }
                var weekNum = DateTimeUtility.GetWeekOfYear(DateTime.Now);
                if (weekNum > weekTarget.WeekNum + 1)
                {
                    if (DateTime.Now.Hour > 2 || DateTime.Today.DayOfWeek > DayOfWeek.Monday)
                    {
                        Message = "周记已经被锁定无法总结!";
                        return;
                    }
                }
                var weekSummary = workContext.WeekSummaries.FirstOrDefault(x => x.ID == updateWeekSummary.ID);
                if (weekSummary.Null())
                {
                    weekSummary = new WeekSummary();
                    weekSummary.ID = updateWeekSummary.ID;
                    weekSummary.CreateTime = DateTime.Now;
                    weekSummary.DepartmentId = updateWeekSummary.DepartmentId;
                    weekSummary.WeekNum = weekTarget.WeekNum;
                    weekSummary.DepartmentId = weekTarget.DepartmentId;
                    workContext.WeekSummaries.Add(weekSummary);
                }
                else
                {
                    workContext.ModifiedModel(weekSummary);
                }

                weekSummary.Description = updateWeekSummary.Description;
                workContext.SaveChanges();
                Flag = true;
            }
        }
        public void Update(UpdateWeeklyTarget updateWeeklyTarget, Guid userId)
        {
            using (var workContext = new DefaultContext())
            {
                var workCard = workContext.WorkCards.FirstOrDefault(x => x.AccountId == userId);
                if (workCard.Null())
                {
                    Message = "账号没有部门";
                    return;
                }
                updateWeeklyTarget.DepartmentId = workCard.DepartmentId;
                updateWeeklyTarget.AccountId = userId;

                var weekNum = DateTimeUtility.GetWeekOfYear(DateTime.Today);
                var dayOfWeek = DateTime.Now.DayOfWeek;
                var weekTarget = workContext.WeekTargets.FirstOrDefault(x => x.WeekNum == weekNum && x.DepartmentId == updateWeeklyTarget.DepartmentId);
                if (weekTarget.Null())
                {
                    Message = "修改日志不存在";
                    return;
                }
                if (((dayOfWeek == DayOfWeek.Monday && DateTime.Now.Hour > 11) || dayOfWeek > DayOfWeek.Monday))
                {
                    Message = "周计划目标已经锁定,无法修改";
                    //Message = "周记已经被锁定无法总结";
                    return;
                }
                weekTarget = updateWeeklyTarget.UpdateWeekTarget(weekTarget);
                workContext.ModifiedModel(weekTarget);
                workContext.SaveChanges();
                Flag = true;
            }
        }