/// <summary> /// Tải danh sách các dự án /// </summary> internal void LoadProjects() { //Tạo kết nối riêng cho các dự án if (this.projectConn == null) { this.projectConn = new ConnectContainer(); } //Lưu danh sách các dự án if (this.ProjectsLoaded == null) { this.ProjectsLoaded = new List <Project>(); } //Tất cả các dự án liên quan đến người dùng hiện tại var projectsToLoad = projectConn.ProjectStaffs.Where(assign => assign.StaffKey == this.MainWindow.StaffKey).ToList(); //Duyệt qua tất cả các dự án, nếu chưa thêm vào trang xem thì thêm vào foreach (ProjectStaffs item in projectsToLoad) { bool existed = (this.ProjectsLoaded.Where(pr => pr.Key == item.ProjectKey).FirstOrDefault() != null); if (!existed) { var p = projectConn.Projects.Where(x => x.Key == item.ProjectKey).FirstOrDefault(); ProjectCard card = new ProjectCard(); card.MyProject = p; this.ProjectsLoaded.Add(p); ProjectList_ListBox.Items.Add(card); card.RequestOpenDetail += Card_RequestOpenDetail; } } }
/// <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(); } } } }
public AddNewProject() { InitializeComponent(); this.DataContext = this; this.MainWindow = (MainWindow)App.Current.MainWindow; this.Conn = new ConnectContainer(); this.LoadStaff(); this.CreateEmptyProjectInstance(); }
private async void LoadStaff() { //Lấy tham chiếu đến Database Entity Model if (this.Conn == null) { this.MainWindow = (MainWindow)App.Current.MainWindow; this.Conn = this.MainWindow.DataConn; } if (this.StaffDbset == null) { this.StaffDbset = this.Conn.Set(typeof(Data.Staff)); await this.StaffDbset.LoadAsync(); this.StaffGrid.ItemsSource = this.StaffDbset.Local; this.AlphabetListbox.SelectionChanged += AlphabetFilterChanged; } int i = this.StaffDbset.Local.Count; this.SetNoOfUserText(i); this.CreateAlphabetFilter(); }
/// <summary> /// Tải danh sách nhóm các công việc /// </summary> private void LoadTaskList() { if (this.TaskListConn == null) { this.TaskListConn = new Data.ConnectContainer(); } if (this.TaskListDbset == null) { this.TaskListDbset = this.TaskListConn.Set <Data.ProjectTaskList>(); } //Danh sách các nhóm công việc thuộc dự án này var list = this.TaskListConn.ProjectTaskLists.Where(tl => tl.ProjectKey == this.MyProject.Key).ToList(); //Tải vào dbset foreach (var item in list) { this.TaskListDbset.Attach(item); } //Thêm dbset làm nguồn dữ liệu this.ProjectList_ListBox.ItemsSource = this.TaskListDbset.Local; }
/// <summary> /// Load categories to treeview /// </summary> internal void LoadTreeView() { //Clear all items this.ProjectCategoryTree.Items.Clear(); //Create the basic categories CreateBasicCategory(); using (Data.ConnectContainer Conn = new ConnectContainer()) { //Create new dbset (short live) var CategoryDbset = Conn.Set <Data.Category>(); CategoryDbset.Load(); //The root item this.ProjectCategories = new CategoryItem(); this.ProjectCategories.Category = CategoryDbset.Local.Where(cate => cate.ParentKey == "").FirstOrDefault(); this.FindChild(this.ProjectCategories, CategoryDbset.Local); //Attach to the tree this.ProjectCategoryTree.Items.Add(this.ProjectCategories); this.ProjectCategoryTree.ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged; } }
/// <summary> /// Create a dataset from database and bind to datagrid view /// </summary> private void BindingDatabase() { //Lấy tham chiếu đến Database Entity Model if (this.Conn == null) { this.Conn = new Data.ConnectContainer(); } //Personal information if (this.PersonalDataset == null) { this.PersonalDataset = Conn.Set(typeof(Data.Staff)); if (this.IsEditing) { var Personal = Conn.Staffs.Where(stf => stf.Key == this.StaffKey); foreach (var item in Personal) { PersonalDataset.Attach(item); } } if (this.PersonalDataset.Local.Count == 0) { var newPs = this.PersonalDataset.Create(); Staff C = (Staff)newPs; C.Key = this.StaffKey; this.PersonalDataset.Local.Add(newPs); } this.PersonalDatagrid.ItemsSource = PersonalDataset.Local; } //Chức vụ if (this.JobTitleDataSet == null) { this.JobTitleDataSet = Conn.Set(typeof(Data.JobTitles)); JobTitleDataSet.Load(); this.JobTitleDbset = JobTitleDataSet.Local; } //Phòng ban if (this.DepartmentDataSet == null) { this.DepartmentDataSet = Conn.Set(typeof(Data.Department)); DepartmentDataSet.Load(); this.DepartmentDbset = DepartmentDataSet.Local; } //Học vấn if (this.EducationDbset == null) { var Edus = Conn.Educations.Where(edu => edu.StaffKey == this.StaffKey); this.EducationDbset = Conn.Set(typeof(Data.Education)); foreach (var item in Edus) { EducationDbset.Attach(item); } this.EducationGrid.ItemsSource = EducationDbset.Local; } //Ngoại ngữ if (this.LanguageDbset == null) { var Language = Conn.ForeignLanguages.Where(lg => lg.StaffKey == this.StaffKey); this.LanguageDbset = Conn.Set(typeof(Data.ForeignLanguage)); foreach (var item in Language) { LanguageDbset.Attach(item); } this.ForeignLanguageDatagrid.ItemsSource = this.LanguageDbset.Local; } //Lĩnh vực chuyên môn if (this.ProfessionalDbset == null) { this.ProfessionalDbset = Conn.Set(typeof(Data.ProfesstionalArea)); ProfessionalDbset.Load(); } //Giấy phép hành nghề if (this.LicenseDbset == null) { var Licenses = Conn.PracticingLicenses.Where(lc => lc.StaffKey == this.StaffKey); this.LicenseDbset = Conn.Set(typeof(Data.PracticingLicense)); foreach (var item in Licenses) { LicenseDbset.Attach(item); } this.PracticingDatagrid.ItemsSource = this.LicenseDbset.Local; } //Kinh nghiệm làm việc if (this.ExpDbset == null) { var Exps = Conn.WorkingExperiences.Where(exp => exp.StaffKey == this.StaffKey); this.ExpDbset = Conn.Set(typeof(Data.WorkingExperience)); foreach (var item in Exps) { ExpDbset.Attach(item); } this.ExperienceGrid.ItemsSource = this.ExpDbset.Local; } //Phan quyen if (this.PermissionDbset == null) { var Permission = Conn.Permissions.Where(pm => pm.StaffKey == this.StaffKey); this.PermissionDbset = Conn.Set(typeof(Data.Permission)); foreach (var item in Permission) { PermissionDbset.Attach(item); } this.PermissionGrid.ItemsSource = PermissionDbset.Local; if (PermissionDbset.Local.Count == 0) { Data.Permission myPermission = (Data.Permission)PermissionDbset.Create(); myPermission.StaffKey = this.StaffKey; myPermission.Key = Encryption.GetUniqueKey(16); this.PermissionDbset.Local.Add(myPermission); } } }