/// <summary>Создает работника</summary>
        public static MFWorker MFPlannerCreateWorker(string name, string secondName, int post, DateTime?endWorkTime)
        {
            if (!CreateClient())
            {
                return(null);
            }

            try
            {
                int id        = service.MFPlannerCreateWorker(name, secondName, post, endWorkTime);
                var newWorker = new MFWorker(id, name, secondName, post)
                {
                    EndWorkTime = endWorkTime
                };

                LogManager.LogInfo(unit, string.Format("Сотрудник №{0} '{1}' '{2}') успешно добавлен", newWorker.Id, newWorker.Name, newWorker.SecondName));

                return(newWorker);
            }
            catch (Exception ex)
            {
                LogManager.LogError(unit, string.Format("Ошибка добавления сотрудника '{0}' '{1}'", name, secondName), ex);

                CloseClient();
            }

            return(null);
        }
Exemple #2
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            var post = 0;

            if (string.IsNullOrEmpty(txtPost.Text) || !int.TryParse(txtPost.Text, out post) || string.IsNullOrEmpty(txtName.Text))
            {
                MessageBox.Show("Пост и Имя - обязательные поля", "Внимание", MessageBoxButton.OK, MessageBoxImage.Stop);
                DialogResult = null;
                return;
            }

            var id = 0;

            if (!string.IsNullOrEmpty(txtId.Text))
            {
                int.TryParse(txtId.Text, out id);
            }

            Result = new MFWorker
            {
                Id         = id,
                Post       = post,
                Name       = txtName.Text,
                SecondName = txtSecondName.Text,
            };

            // Если уволили
            if (chkIsFired.IsChecked == true)
            {
                Result.EndWorkTime = DateTime.Now.Date;
            }

            DialogResult = true;
            Close();
        }
        /// <summary>Меняет описание работника</summary>
        public static bool MFPlannerChangeWorker(MFWorker worker)
        {
            if (ServiceManager.MFPlannerChangeWorker(worker))
            {
                ReloadWorkersAsync();
                return(true);
            }

            return(false);
        }
        /// <summary>Создать новый проект</summary>
        public static void CreateNewWorker(string name, string secondName, int post, DateTime?endWorkTime)
        {
            int workerId;

            lock (workers)
            {
                MFWorker newWorker = ServiceManager.MFPlannerCreateWorker(name, secondName, post, endWorkTime);
                workers.Add(newWorker);

                //if (!string.IsNullOrEmpty(win.NewComments))
                //    newProject.AddMessage(new AgrProjectComment(DateTime.Now, UserManager.Name, win.NewComments));

                workerId = newWorker.Id;
            }

            EventMessages.Insert(0, new EventMessage(DateTime.Now, workerId, "Добавлен новый работник"));

            DoWorkersChanged();
        }
        //public static bool MFPlannerCreateWorker(MFWorker worker)
        //{
        //    if (!CreateClient())
        //        return false;

        //    try
        //    {
        //        return service.MFPlannerCreateWorker();
        //    }
        //    catch (Exception ex)
        //    {
        //        LogManager.LogError(unit, string.Format("Ошибка создания работника: '{0} {1}'", worker.SecondName, worker.Name), ex);

        //        CloseClient();

        //        return false;
        //    }
        //}

        /// <summary>Меняет описание работника</summary>
        public static bool MFPlannerChangeWorker(MFWorker worker)
        {
            if (!CreateClient())
            {
                return(false);
            }

            try
            {
                return(service.MFPlannerChangeWorker(worker));
            }
            catch (Exception ex)
            {
                LogManager.LogError(unit, string.Format("Ошибка изменения работника: [{0}] '{1} {2}'", worker.Id, worker.SecondName, worker.Name), ex);

                CloseClient();

                return(false);
            }
        }
Exemple #6
0
        /// <summary>Меняет описание работника</summary>
        public bool MFPlannerChangeWorker(MFWorker worker)
        {
            lock (Db.Ds)
            {
                LogManager.LogInfo(IpClient(), "Запрос на изиенение работника " + worker.Id);
                Db.LoadPlanners();
                var dbWorker = Db.Ds.Worker.Where(s => s.Id == worker.Id).SingleOrDefault();
                if (dbWorker != null)
                {
                    dbWorker.Post        = worker.Post;
                    dbWorker.Name        = worker.Name;
                    dbWorker.SecondName  = worker.SecondName;
                    dbWorker.EndWorkTime = !worker.EndWorkTime.HasValue ? DateTime.MinValue : worker.EndWorkTime.Value;
                    if (Db.SavePlanners())
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #7
0
        /// <summary>Возвращает информацию по ячейке</summary>
        void GetCell(Point pos, out MFWorker worker, out DateTime?t)
        {
            worker = null;
            t      = null;
            if (rectGrid == Rect.Empty)
            {
                return;
            }

            var workers = MFPlannerManager.GetWorkers(IsShowEndWorkWokers);
            var index   = 0;

            for (; index < workers.Count; index++)
            {
                var rectTmp = new Rect(0, rectGrid.Y + rowHeight * index, rectGrid.Right, rowHeight);
                if (rectTmp.Contains(pos))
                {
                    worker = workers[index];
                }
            }

            var d = TimeStart;

            var cellWidth = rectGrid.Width / (TimeEnd - TimeStart).TotalDays;

            index = 0;
            while (d < TimeEnd)
            {
                var rectTmp = new Rect(rectGrid.X + index * cellWidth, rectGrid.Top - rowMonthAndDay, cellWidth, rectGrid.Height + rowMonthAndDay);
                if (rectTmp.Contains(pos))
                {
                    t = d;
                    return;
                }

                d = d.AddDays(1);
                index++;
            }
        }
Exemple #8
0
        public MFPlannerWorkerEditWindow(MFWorker w = null)
        {
            InitializeComponent();

            if (w != null)
            {
                txtId.Text         = w.Id.ToString();
                txtPost.Text       = w.Post.ToString();
                txtName.Text       = w.Name;
                txtSecondName.Text = w.SecondName;
                if (w.EndWorkTime.HasValue)
                {
                    chkIsFired.IsChecked = true;
                    txtFireDate.Text     = w.EndWorkTime.Value.ToString("dd/MM/yyyy");
                }
            }
            else
            {
                Result = new MFWorker();
                Title  = "Новый работник";
            }
        }
Exemple #9
0
        void mnu_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                isAddActionInProgress = true;

                var pos = (Point)ContextMenu.Tag;

                MFWorker worker = null;
                DateTime?date   = null;
                GetCell(pos, out worker, out date);
                if (worker == null || !date.HasValue)
                {
                    return;
                }

                // Если уволен то выходим
                if (worker.EndWorkTime.HasValue)
                {
                    MessageBox.Show("Невозможно дать задание уволенному работнику", "Внимание", MessageBoxButton.OK, MessageBoxImage.Stop);
                    return;
                }

                var t = (MFWorkerActionType)((FrameworkElement)sender).Tag;

                // Количество дней
                var winDays = new DaysWindow(14)
                {
                    Owner = Window.GetWindow(this)
                };
                if (winDays.ShowDialog() != true)
                {
                    return;
                }

                switch (t)
                {
                    #region Holiday/Hospital
                case MFWorkerActionType.Holiday:
                case MFWorkerActionType.Hospital:
                {
                    MFPlannerManager.CreateNewAction(t, worker.Id, -1, date.Value, winDays.Count);
                    break;
                }

                    #endregion
                    #region Project
                case MFWorkerActionType.Project:
                {
                    // Выбираем проект
                    var win = new MFPlannerSelectProjectWindow(TimeStart, TimeEnd)
                    {
                        Owner = Window.GetWindow(this)
                    };
                    if (win.ShowDialog() != true || win.SelectedProject == null)
                    {
                        return;
                    }

                    MFPlannerManager.CreateNewAction(t, worker.Id, win.SelectedProject.ProjectID, date.Value, winDays.Count);

                    // Устанавливаем пост
                    var sPost = CreatePost(win.SelectedProject.MF_Post, worker.Post.ToString());
                    if (win.SelectedProject.MF_Post != sPost)
                    {
                        ProjectManager.ChangeProjectPropety(win.SelectedProject.ProjectID, ProjectPropertyType.MF_Post, sPost);
                    }

                    // Устанавливаем ориентировочное время
                    var dateMFPlaned = date.Value.AddDays(winDays.Count);
                    var isChange     = true;
                    if (win.SelectedProject.MF_Time_Plan.HasValue)
                    {
                        var msg = string.Format("Изменить 'Планируемое время завершения производства'\n с {0} на {1}",
                                                win.SelectedProject.MF_Time_Plan.Value.ToString(ProjectConfiguration.DateFormat),
                                                dateMFPlaned.ToString(ProjectConfiguration.DateFormat));

                        isChange = MessageBox.Show(msg, "Внимание", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes;
                    }

                    if (isChange)
                    {
                        ProjectManager.ChangeProjectPropety(win.SelectedProject.ProjectID, ProjectPropertyType.MF_Time_Planed, dateMFPlaned);
                    }

                    //actions.Add(new MFPlannerAction { Type = t, WorkerId = worker.Id, TimeBegin = date.Value, Days = winDays.Count, Id = actions.Count + 1, TargetId = win.SelectedProject.ProjectID });
                    break;
                }

                    #endregion
                    #region ReseveProject
                case MFWorkerActionType.ReseveProject:
                {
                    var win = new MFPlannerCommentWindow {
                        Owner = Window.GetWindow(this)
                    };
                    if (win.ShowDialog() != true)
                    {
                        return;
                    }

                    MFPlannerManager.CreateNewAction(t, worker.Id, -1, date.Value, winDays.Count, win.Comment);

                    break;
                }

                    #endregion
                    #region Avait
                case MFWorkerActionType.Avait:
                {
                    MFPlannerManager.CreateNewAction(t, worker.Id, -1, date.Value, 1);
                    break;
                }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                LogManager.LogError(unit, "Ошибка добавления нового действия в проект", ex);
            }
            finally
            {
                isAddActionInProgress = false;

                //projects[1].MF_Post = worker.Post.ToString();
                isDirty = true;
                InvalidateVisual();
            }
        }
Exemple #10
0
        /// <summary>Выполняем запрос от проекта</summary>
        internal void MakeCommand(PlannerMode mode, Point pos, MFPlannerProjectControl sender)
        {
            MFWorker worker = null;
            DateTime?time   = null;

            GetCell(pos, out worker, out time);
            if (worker == null || time == null)
            {
                return;
            }

            switch (mode)
            {
                #region PlanProject_Confirm - Подтвердить проект
            case PlannerMode.PlanProject_Confirm:
            {
                // Выбираем проект
                var win = new MFPlannerSelectProjectWindow(TimeStart, TimeEnd)
                {
                    Owner = Window.GetWindow(this)
                };
                if (win.ShowDialog() != true || win.SelectedProject == null)
                {
                    return;
                }

                sender.Action.TargetId = win.SelectedProject.ProjectID;
                sender.Action.Type     = MFWorkerActionType.Project;

                if (!MFPlannerManager.MFPlannerChangeAction(sender.Action))
                {
                    sender.Action.TargetId = -1;
                    sender.Action.Type     = MFWorkerActionType.ReseveProject;

                    MessageBox.Show("Не удадось подтвердить проект", "Внимание", MessageBoxButton.OK, MessageBoxImage.Stop);
                    return;
                }

                // Устанавливаем пост
                var sPost = CreatePost(win.SelectedProject.MF_Post, worker.Post.ToString());
                if (win.SelectedProject.MF_Post != sPost)
                {
                    ProjectManager.ChangeProjectPropety(win.SelectedProject.ProjectID, ProjectPropertyType.MF_Post, sPost);
                }

                // Устанавливаем ориентировочное время
                var dateMFPlaned = sender.Action.TimeEnd;
                var isChange     = true;
                if (win.SelectedProject.MF_Time_Plan.HasValue)
                {
                    var msg = string.Format("Изменить 'Планируемое время завершения производства'\n с {0} на {1}",
                                            win.SelectedProject.MF_Time_Plan.Value.ToString(ProjectConfiguration.DateFormat),
                                            dateMFPlaned.ToString(ProjectConfiguration.DateFormat));

                    isChange = MessageBox.Show(msg, "Внимание", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes;
                }

                if (isChange)
                {
                    ProjectManager.ChangeProjectPropety(win.SelectedProject.ProjectID, ProjectPropertyType.MF_Time_Planed, dateMFPlaned);
                }

                break;
            }
                #endregion

                #region CommentEdit
            case PlannerMode.CommentEdit:
            {
                var win = new MFPlannerCommentWindow {
                    Title = "Изменить комментарий", Comment = sender.Action.Comment, Owner = Window.GetWindow(this)
                };
                if (win.ShowDialog() != true)
                {
                    return;
                }

                var prev = sender.Action.Comment;
                sender.Action.Comment = win.Comment;

                if (!MFPlannerManager.MFPlannerChangeAction(sender.Action))
                {
                    sender.Action.Comment = prev;
                    MessageBox.Show("Не удалось изменить описание проекта", "Внимание", MessageBoxButton.OK, MessageBoxImage.Stop);
                    return;
                }

                sender.InvalidateVisual();

                break;
            }
                #endregion

                #region ChangeDays - Изменить продолжительность дней
            case PlannerMode.ChangeDays:
            {
                var res = MessageBox.Show(string.Format("Изменить продолжительность дней?"), "Внимание", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
                if (res != MessageBoxResult.Yes)
                {
                    return;
                }

                var winDays = new DaysWindow(sender.Action.Days)
                {
                    Owner = Window.GetWindow(this)
                };
                if (winDays.ShowDialog() != true)
                {
                    return;
                }

                var prev = sender.Action.Days;
                sender.Action.Days = winDays.Count;

                // изменяем
                if (!MFPlannerManager.MFPlannerChangeAction(sender.Action))
                {
                    sender.Action.Days = prev;

                    MessageBox.Show("Не удалось сохранить изменения", "Внимание", MessageBoxButton.OK, MessageBoxImage.Stop);
                    return;
                }

                // Устанавливаем ориентировочное время
                ProjectManager.ChangeProjectPropety(sender.Action.TargetId, ProjectPropertyType.MF_Time_Planed, sender.Action.TimeEnd);

                isDirty = true;

                break;
            }

                #endregion
                #region Break - Прервать
            case PlannerMode.Break:
            {
                var days = (time.Value - sender.Action.TimeBegin).TotalDays;
                if (days <= 1)
                {
                    return;
                }

                var res = MessageBox.Show(string.Format("Сократить проект до: {0} дней?", days), "Внимание", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
                if (res != MessageBoxResult.Yes)
                {
                    return;
                }

                var prev = sender.Action.Days;
                sender.Action.Days = (int)days;

                // изменяем
                if (!MFPlannerManager.MFPlannerChangeAction(sender.Action))
                {
                    sender.Action.Days = prev;

                    MessageBox.Show("Не удалось сохранить изменения", "Внимание", MessageBoxButton.OK, MessageBoxImage.Stop);
                    return;
                }

                // Устанавливаем ориентировочное время
                ProjectManager.ChangeProjectPropety(sender.Action.TargetId, ProjectPropertyType.MF_Time_Planed, sender.Action.TimeEnd);

                isDirty = true;

                break;
            }

                #endregion
                #region Remove - удаление
            case PlannerMode.Remove:
            {
                var res = MessageBox.Show(string.Format("Удалить выбранный?"), "Внимание", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
                if (res != MessageBoxResult.Yes)
                {
                    return;
                }

                // удаляем
                if (!MFPlannerManager.RemoveAction(sender.Action))
                {
                    MessageBox.Show("Удаление не удалось", "Внимание", MessageBoxButton.OK, MessageBoxImage.Stop);
                    return;
                }

                var cProject = controlsCache[sender.Action.Id];

                controlsCache.Remove(sender.Action.Id);
                Children.Remove(cProject);

                // Удаляем пост
                var p     = ServiceManager.LoadProject(sender.Action.TargetId);
                var sPost = RemovePost(p.MF_Post, worker.Post.ToString());
                if (p.MF_Post != sPost)
                {
                    ProjectManager.ChangeProjectPropety(sender.Action.TargetId, ProjectPropertyType.MF_Post, sPost);
                }

                cProject.Dispose();
                cProject = null;

                break;
            }
                #endregion

                #region ChangeProgressNone/ChangeProgressStart/ChangeProgressHalf/ChangeProgressFinish
            case PlannerMode.ChangeProgressNone:
            case PlannerMode.ChangeProgressStart:
            case PlannerMode.ChangeProgressHalf:
            case PlannerMode.ChangeProgressFinish:
            {
                var name = "";
                if (mode == PlannerMode.ChangeProgressStart)
                {
                    name = Project.inStart;
                }
                else if (mode == PlannerMode.ChangeProgressHalf)
                {
                    name = Project.inHalf;
                }
                else if (mode == PlannerMode.ChangeProgressFinish)
                {
                    name = Project.inFinish;
                }

                // Удаляем пост
                var p = ServiceManager.LoadProject(sender.Action.TargetId);
                if (p.MF_Complete_Percentage != name)
                {
                    ProjectManager.ChangeProjectPropety(sender.Action.TargetId, ProjectPropertyType.MF_Complete_Percentage, name);
                }

                break;
            }
                #endregion
            }
        }
 /// <summary>Создать новый проект</summary>
 public static void CreateNewWorker(MFWorker w)
 {
     CreateNewWorker(w.Name, w.SecondName, w.Post, w.EndWorkTime);
 }