/// <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);
                }
            }
        }
Example #2
0
        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);
                }
            }
        }
Example #3
0
        /// <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();
                    }
                }
            }
        }
Example #4
0
        private void NextMonday_Click(object sender, EventArgs e)
        {
            var date = ExtendedFunctions.GetNetworkTime();

            while (date.DayOfWeek != DayOfWeek.Monday)
            {
                date = date.AddDays(1);
            }
            this.SelectedDate = date.Date;
        }
        /// <summary>
        /// Thêm các thông tin về nhân sự dự án
        /// </summary>
        private void SetPeople()
        {
            //Create the staff dbset
            if (this.ProjectStaffDbset == null)
            {
                this.ProjectStaffDbset = this.Conn.Set <ProjectStaffs>();
            }
            else
            {
                this.ProjectStaffDbset.Local.Clear();
            }

            //Create the permission db set
            if (this.ProjectPermissionDbset == null)
            {
                this.ProjectPermissionDbset = this.Conn.Set <Data.UserProjectPermission>();
            }

            if (this.SelectedStaff == null)
            {
                this.SelectedStaff = new List <Data.Staff>();
                this.SelectedStaff.Add(MainWindow.LoggedInStaff);
            }

            //Create the assignment and permission
            foreach (Staff s in SelectedStaff)
            {
                var newAssign = this.ProjectStaffDbset.Create();

                if (IsProjectOwner(s.Key))
                {
                    this.NewProject.ProjectOwner = s.Key;
                }

                newAssign.StaffKey   = s.Key;
                newAssign.ProjectKey = this.NewProject.Key;
                newAssign.Key        = Encryption.GetUniqueKey(16);
                newAssign.AddedBy    = this.MainWindow.StaffKey;
                newAssign.AddedOn    = ExtendedFunctions.GetNetworkTime().ToString();

                //Create a permission record
                UserProjectPermission permission = this.ProjectPermissionDbset.Create();
                permission.ProjectStaffKey = newAssign.Key;
                permission.IsAdmin         = IsProjectOwner(newAssign.StaffKey);

                newAssign.PermissionKey = Encryption.GetPermisionKey(permission);

                this.ProjectPermissionDbset.Add(permission);
                this.ProjectStaffDbset.Add(newAssign);
            }
        }
Example #6
0
        private void UpdateCategoryToDb()
        {
            try
            {
                MainWindow M = (MainWindow)App.Current.MainWindow;
                using (Data.ConnectContainer conn = new Data.ConnectContainer())
                {
                    var cate   = conn.Categories.Where(c => c.Key == EditingCategory.Key).FirstOrDefault();
                    var Parent = ((ComboBoxItem)this.NestCombobox.SelectedItem).Tag as Category;

                    bool changed = false;

                    if (cate != null)
                    {
                        changed = changed || (cate.Name != NameTextbox.Text);
                        changed = changed || (cate.ParentKey != Parent.Key);
                        changed = changed || (cate.Color != this.colorPicker.CurrentSelectedColor.Color.ToString());
                    }

                    if (changed)
                    {
                        cate.Name       = NameTextbox.Text;
                        cate.Color      = this.colorPicker.CurrentSelectedColor.Color.ToString();
                        cate.ParentKey  = Parent.Key;
                        cate.ModifiedBy = M.StaffKey;
                        cate.ModifiedOn = ExtendedFunctions.GetNetworkTime();
                        cate.Level      = Parent.Level + 1;
                    }
                    int i = conn.SaveChanges();
                    if (i > 0)
                    {
                        this.Confirmed?.Invoke(this, EventArgs.Empty);
                    }
                    else
                    {
                        this.Failed?.Invoke(this, EventArgs.Empty);
                    }
                };
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
        private void AddTagButton_Clicked(object sender, RoutedEventArgs e)
        {
            if (this.TagsDbset == null)
            {
                this.TagsDbset = Conn.Set <Tags>();
            }
            if (this.ListOfTags == null)
            {
                this.ListOfTags = new List <Tags>();
            }

            //Detect if this tag is currently added to the project
            bool TagExist = this.ListOfTags.Where(lt => lt.TagName.ToLower() == this.NewTagTextBox.Text.ToLower().Trim()).FirstOrDefault() != null;

            if (TagExist)
            {
                this.AddTagPopupButton.IsPopupOpen = false;
                this.MySnackbar.MessageQueue.Enqueue("This tag is already added to project".ToUpper());
                return;
            }

            //Create the new tag
            var newTag = this.TagsDbset.Create();

            newTag.TagName = this.NewTagTextBox.Text;
            newTag.TagKey  = Encryption.GetUniqueKey(16);
            newTag.Color   = this.TagColorPicker.CurrentSelectedColor.Color.ToString();
            newTag.AddedBy = ((MainWindow)App.Current.MainWindow).StaffKey;
            newTag.AddOn   = ExtendedFunctions.GetNetworkTime();

            MyTagChips tc = new MyTagChips(newTag);

            tc.Margin    = new Thickness(3);
            tc.Deleting += Tc_Deleting;

            //Add to collections
            this.TagWrapPanel.Children.Add(tc);
            this.ListOfTags.Add(newTag);
            this.TagsDbset.Add(newTag);

            //Close the popup
            this.AddTagPopupButton.IsPopupOpen = false;
        }
Example #8
0
        /// <summary>
        /// Thêm nhân viên mới
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddUserButtonClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                var DateTimeNow = ExtendedFunctions.GetNetworkTime();
                foreach (var item in Conn.ChangeTracker.Entries <Staff>())
                {
                    if (!this.IsEditing)
                    {
                        item.Entity.AddedOn  = DateTimeNow;
                        item.Entity.AddedBy  = this.MainWindow.StaffKey != null ? this.MainWindow.StaffKey : item.Entity.Key;
                        item.Entity.Password = Encryption.GetUniqueKey(8);
                    }
                    ;
                    item.Entity.ModifiedBy = this.MainWindow.StaffKey != null ? this.MainWindow.StaffKey : item.Entity.Key;
                    item.Entity.ModifiedOn = DateTimeNow;
                }

                bool _NoMoreError = true;

                _NoMoreError = this.Validate();

                if (_NoMoreError)
                {
                    int i = Conn.SaveChanges();
                    if (i > 0)
                    {
                        this.StaffAdded?.Invoke(this, EventArgs.Empty);
                    }
                    else
                    {
                        MySnackbar.MessageQueue.Enqueue("Error while adding staff. Please try again later.");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #9
0
        private void AddNewCategoryToDb()
        {
            try
            {
                MainWindow M = (MainWindow)App.Current.MainWindow;
                using (Data.ConnectContainer conn = new Data.ConnectContainer())
                {
                    var cate = new Data.Category()
                    {
                        Name       = NameTextbox.Text,
                        ModifiedBy = M.StaffKey,
                        ModifiedOn = ExtendedFunctions.GetNetworkTime(),
                        AddedBy    = M.StaffKey,
                        AddedOn    = ExtendedFunctions.GetNetworkTime(),
                        Color      = this.colorPicker.CurrentSelectedColor.Color.ToString(),
                        IsDeleted  = false,
                        Key        = Encryption.GetUniqueKey(16)
                    };
                    var Parent = ((ComboBoxItem)this.NestCombobox.SelectedItem).Tag as Category;

                    cate.ParentKey = Parent.Key;
                    cate.Level     = Parent.Level + 1;

                    conn.Categories.Add(cate);
                    int i = conn.SaveChanges();
                    if (i > 0)
                    {
                        this.Confirmed?.Invoke(this, EventArgs.Empty);
                    }
                    else
                    {
                        this.Failed?.Invoke(this, EventArgs.Empty);
                    }
                };
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #10
0
        private void NextWeek_Click(object sender, EventArgs e)
        {
            var date = ExtendedFunctions.GetNetworkTime();

            this.SelectedDate = date.AddDays(7).Date;
        }
Example #11
0
        private void ToDayMyTextBlock_Click(object sender, EventArgs e)
        {
            var date = ExtendedFunctions.GetNetworkTime();

            this.SelectedDate = date.Date;
        }