Esempio n. 1
0
        private void ButtonAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (txbUserName.Text.Trim().Length > 0 && txbPassword.Text.Trim().Length > 0 && txbEmail.Text.Trim().Length > 0 && cbBoxRole.Text.Length > 0 && txbPassword.Text == txbConfirm.Text)
                {
                    bool exist = false;
                    foreach (User user in Data.Instance.UsersList)
                    {
                        if (user.Email == txbEmail.Text.Trim())
                        {
                            exist = true;
                        }
                    }
                    if (exist)
                    {
                        throw null;
                    }

                    int    _ID       = UserBLL.Instance.RetreiveUserID();
                    string _UserName = txbUserName.Text;
                    var    h1        = new DTO.Hash();
                    string _Password = h1.MD5(txbPassword.Text);
                    string _Email    = txbEmail.Text;
                    string _Role     = cbBoxRole.Text;

                    if (UserBLL.Instance.AddNewUser(new User()
                    {
                        ID = _ID, Name = _UserName, Role = _Role, Email = _Email, Password = _Password
                    }))
                    {
                        MessageBox.Show("Them Thanh Cong!");
                    }
                    else
                    {
                        MessageBox.Show("Them That Bai!");
                    }
                }
                else
                {
                    throw null;
                }
            }
            catch
            {
                MessageBox.Show("Loi Nhap Thong Tin!");
            }
        }
Esempio n. 2
0
        private void ButtonUpdate_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are You Sure!", "Notify", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try {
                    if (txbNewPass.Text.Trim() != "")
                    {
                        if (txbUserName.Text.Trim().Length > 0 && txbPassword.Text.Trim().Length > 0 && txbEmail.Text.Trim().Length > 0 && txbNewPass.Text == txbConfirm.Text)
                        {
                            bool exist = false;
                            foreach (User user in Data.Instance.UsersList)
                            {
                                if (user.Email == txbEmail.Text.Trim() && user.ID != Data.Instance.User.ID)
                                {
                                    exist = true;
                                }
                            }
                            if (exist)
                            {
                                throw null;
                            }


                            int    _ID       = Data.Instance.User.ID;
                            string _UserName = txbUserName.Text;
                            var    h1        = new DTO.Hash();
                            string _Password = h1.MD5(txbNewPass.Text);
                            string _Role     = txbRole.Text;
                            string _Email    = txbEmail.Text;

                            UserBLL.Instance.UpdateUser(new User()
                            {
                                ID = _ID, Name = _UserName, Role = _Role, Email = _Email, Password = _Password
                            });
                            MessageBox.Show("Thanh Cong!");
                        }

                        else
                        {
                            MessageBox.Show("Cap Nhat That Bai!");
                        }
                    }

                    else
                    {
                        if (txbUserName.Text.Trim().Length > 0 && txbPassword.Text.Trim().Length > 0 && txbEmail.Text.Trim().Length > 0)
                        {
                            bool exist = false;
                            foreach (User user in Data.Instance.UsersList)
                            {
                                if (user.Email == txbEmail.Text.Trim() && user.ID != Data.Instance.User.ID)
                                {
                                    exist = true;
                                }
                            }
                            if (exist)
                            {
                                throw null;
                            }

                            int    _ID       = Data.Instance.User.ID;
                            string _UserName = txbUserName.Text;
                            string _Password = txbPassword.Text;
                            string _Email    = txbEmail.Text;
                            string _Role     = txbRole.Text;

                            UserBLL.Instance.UpdateUser(new User()
                            {
                                ID = _ID, Name = _UserName, Role = _Role, Email = _Email, Password = _Password
                            });
                            MessageBox.Show("Thanh Cong!");
                        }

                        else
                        {
                            MessageBox.Show("Cap Nhat That Bai!");
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Cap Nhat That Bai!");
                }
            }
        }