/// <summary> /// Метод обрабатывающий нажатие по кнопке и добавление департамента /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddDepartment_Click(object sender, RoutedEventArgs e) { if (NameDepBox.Text == String.Empty) { MessageBox.Show("Укажите название для департамента"); } else { Department dep = new Department(null); if ((Department)txt1.DataContext is Department) { dep = (Department)txt1.DataContext; } dep.AddSubDepartment(new Department(NameDepBox.Text)); var CurrentTree = (TreeViewItem)txt2.DataContext; if (CurrentTree is null) { MessageBox.Show("Не выбран управляющий департамент"); } else { if (CurrentTree.Items.Count == 0) { CurrentTree.Items.Add(null); } CurrentTree.IsExpanded = true; CurrentTree.IsExpanded = false; CurrentTree.IsExpanded = true; } } repo.IsSaved = false; }
/// <summary> /// Добавляет подразделение /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddDepartmentOnClick(object sender, RoutedEventArgs e) { MessageBoxResult result; if (string.IsNullOrEmpty(DivisionID.Text)) { result = MessageBox.Show( "Отдел не выбран. Добавить подразделение в организацию?", "Подтверждение", MessageBoxButton.OKCancel); if (result == MessageBoxResult.OK) { organization.AddSubDepartment(new Department(newDivisionName.Text, new Manager(newDivManagerName.Text, newDivManagerPost.Text))); //treeView1.Items.Refresh(); } newDivisionName.Text = null; newDivManagerName.Text = null; newDivManagerPost.Text = null; return; } if (string.IsNullOrEmpty(newDivisionName.Text) || string.IsNullOrEmpty(newDivManagerName.Text) || string.IsNullOrEmpty(newDivManagerPost.Text)) { MessageBox.Show("Не все поля заполнены"); return; } Department division = organization.FindDepartmentByID(int.Parse(DivisionID.Text)); if (division == null) { MessageBox.Show("Отдел не найден"); return; } result = MessageBox.Show("Добавить подразделение в выбранный отдел? Если нет, то оно будет добавлено в организацию", "Подтверждение", MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Yes) { division.AddSubDepartment(new Department(newDivisionName.Text, new Manager(newDivManagerName.Text, newDivManagerPost.Text))); //treeView1.Items.Refresh(); } else if (result == MessageBoxResult.No) { organization.AddSubDepartment(new Department(newDivisionName.Text, new Manager(newDivManagerName.Text, newDivManagerPost.Text))); //treeView1.Items.Refresh(); } newDivisionName.Text = null; newDivManagerName.Text = null; newDivManagerPost.Text = null; }
/// <summary> /// 新增部门。 /// </summary> /// <param name="dto">待新增部门的信息。</param> /// <returns>新部门的Id。</returns> public static string InsertDepartment(DepartmentDTO dto) { Db.SessionFactory.EvictQueries("Department"); Department d = new Department(); d.Id = IdGen.GetNextId(typeof(Department)); d.Name = dto.Name; d.Phone = dto.Phone; d.ExtNumber = dto.ExtNumber; d.Fax = dto.Fax; d.Remark = dto.Remark; d.OrderId = dto.OrderId; if (dto.ParentDepartmentId != null && dto.ParentDepartmentId.Length > 0) { Department pd = Db.Session.Load(typeof(Department), dto.ParentDepartmentId) as Department; pd.AddSubDepartment(d); } Db.TransInsert(d); return(d.Id); }