/// <summary> /// Create the All Project category (the root) and the No Category /// </summary> private void CreateBasicCategory() { using (Data.ConnectContainer Conn = new ConnectContainer()) { if (Conn.Categories.Count() == 0) { try { string AllProjectKey = Encryption.GetUniqueKey(16); Conn.Categories.Add(new Category() { Name = "All Projects", Key = AllProjectKey, AddedBy = this.MainWindow.StaffKey, AddedOn = ExtendedFunctions.GetNetworkTime(), Color = "DimGray", IsDeleted = false, ModifiedBy = this.MainWindow.StaffKey, ModifiedOn = ExtendedFunctions.GetNetworkTime(), ParentKey = "", Level = 0 }); Conn.Categories.Add(new Category() { Name = "No Category", Key = Encryption.GetUniqueKey(16), AddedBy = this.MainWindow.StaffKey, AddedOn = ExtendedFunctions.GetNetworkTime(), Color = "DimGray", IsDeleted = false, ModifiedBy = this.MainWindow.StaffKey, ModifiedOn = ExtendedFunctions.GetNetworkTime(), ParentKey = AllProjectKey, Level = 1 }); if (Conn.GetValidationErrors().Count() > 0) { foreach (var item in Conn.GetValidationErrors()) { foreach (var error in item.ValidationErrors) { Console.WriteLine(error.ErrorMessage); } } } else { Conn.SaveChanges(); } } finally { Conn.Dispose(); } } } }
/// <summary> /// Thêm các thông tin cuối cùng và gọi framework để chèn dự án vào csdl /// </summary> private void AddProjectToDb() { //Thông tin về phân nhóm dự án SetCategory(); //Thông tin về khách hàng (chưa làm) SetCustomer(); //Thông tin về nhân sự của dự án SetPeople(); //Thông tin về ngày của dự án SetDates(); //Thông tin về các thẻ đính kèm; SetTags(); //Thông tin về người tạo, giờ tạo this.NewProject.AddedBy = this.MainWindow.StaffKey; this.NewProject.AddedOn = ExtendedFunctions.GetNetworkTime(); //Thông tin về người sửa, giờ sửa this.NewProject.ModifiedBy = this.NewProject.AddedBy; this.NewProject.ModifiedOn = this.NewProject.AddedOn; //Danh sách công việc mặc định this.CreateDefaultTaskList(); //Kiểm tra lỗi if (this.Conn.GetValidationErrors().Count() > 0) { foreach (var item in Conn.GetValidationErrors()) { Console.WriteLine(item.Entry.GetType().ToString()); foreach (var error in item.ValidationErrors) { Console.WriteLine(" " + error.PropertyName + ": " + error.ErrorMessage); } } } else { try { //Thêm vào cơ sở dữ liệu Conn.SaveChanges(); //Nếu thành công thì gọi event this.ProjectAdded?.Invoke(this, EventArgs.Empty); } catch (Exception ex) { //Nếu có lỗi thì ghi vào console và thông báo Console.WriteLine(ex.Message); //Raise event this.AddingProjectFailed?.Invoke(this, EventArgs.Empty); } } }
private void Adddialog_Adding(object sender, EventArgs e) { AddNewProjectTaskList adddialog = (AddNewProjectTaskList)sender; adddialog.MyList.CreatedBy = this.MainWindow.StaffKey; adddialog.MyList.CreatedOn = ExtendedFunctions.GetNetworkTime(); adddialog.MyList.ProjectKey = this.MyProject.Key; adddialog.MyList.Key = Encryption.GetUniqueKey(16); this.TaskListDbset.Add(adddialog.MyList); if (this.TaskListConn.GetValidationErrors().Count() > 0) { foreach (var item in TaskListConn.GetValidationErrors()) { Console.WriteLine(item.Entry.GetType().ToString()); foreach (var error in item.ValidationErrors) { Console.WriteLine(" " + error.PropertyName + ": " + error.ErrorMessage); } } } else { try { //Thêm vào cơ sở dữ liệu TaskListConn.SaveChanges(); } catch (Exception ex) { //Nếu có lỗi thì ghi vào console và thông báo Console.WriteLine(ex.Message); } } }
private bool Validate() { bool result = true; if (Conn.GetValidationErrors().Count() > 0) { this.MySnackbar.MessageQueue.Enqueue("Please input all required information"); result = false; foreach (var item in Conn.GetValidationErrors()) { foreach (var error in item.ValidationErrors) { Console.WriteLine(error.ErrorMessage); } } } return(result); }