Beispiel #1
0
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            bool            flag            = false;
            int             num             = Convert.ToInt32(this.btnCapNhat.Tag.ToString());
            NguoiDungEntity nguoiDungEntity = null;
            bool            flag2           = !this.btnThemMoi.Enabled && num == 0;

            if (flag2)
            {
                nguoiDungEntity = new NguoiDungEntity();
                flag            = true;
            }
            else
            {
                bool flag3 = num > 0;
                if (flag3)
                {
                    nguoiDungEntity = ManageBase.SelectNguoiDungById(num);
                }
            }
            bool flag4 = nguoiDungEntity != null;

            if (flag4)
            {
                bool flag5 = this.txtUser.Text.Trim() == "" || this.txtPass.Text.Trim() == "";
                if (flag5)
                {
                    MessageBox.Show("Tên đăng nhập và mật khẩu không được để trống!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.txtUser.Focus();
                    this.Cursor = Cursors.Default;
                    return;
                }
                bool flag6 = ManageBase.NguoiDungExist(num, this.txtUser.Text.Trim());
                if (flag6)
                {
                    MessageBox.Show("Tên đăng nhập đã tồn tại. Hãy chọn tên đăng nhập khác!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.txtUser.Focus();
                    this.Cursor = Cursors.Default;
                    return;
                }
                nguoiDungEntity.TenDangNhap    = this.txtUser.Text.Trim();
                nguoiDungEntity.MatKhau        = Util.Encrypt(this.txtPass.Text.Trim());
                nguoiDungEntity.HoTenNguoiDung = this.txtHoTen.Text.Trim();
                nguoiDungEntity.SoDienThoai    = this.txtSoDienThoai.Text.Trim();
                nguoiDungEntity.DiaChiEmail    = this.txtEmail.Text.Trim();
                nguoiDungEntity.VaiTro         = (byte)this.cboVaiTro.SelectedIndex;
                bool flag7 = this.chkGioiTinh.CheckState == CheckState.Checked;
                if (flag7)
                {
                    nguoiDungEntity.GioiTinh = 1;
                }
                else
                {
                    bool flag8 = this.chkGioiTinh.CheckState == CheckState.Unchecked;
                    if (flag8)
                    {
                        nguoiDungEntity.GioiTinh = 0;
                    }
                    else
                    {
                        nguoiDungEntity.GioiTinh = 3;
                    }
                }
                bool flag9 = ManageBase.SaveNguoiDung(nguoiDungEntity);
                if (flag9)
                {
                    bool flag10 = nguoiDungEntity.NguoiDungId == GlobalVariable.NguoiDungId;
                    if (flag10)
                    {
                        GlobalVariable.TenDangNhap = nguoiDungEntity.TenDangNhap;
                        GlobalVariable.MatKhau     = nguoiDungEntity.MatKhau;
                        string text = ProcessConfigXML.LoadData("Account");
                        Dictionary <string, object> dictionary = ProcessConfigXML.ConfigString2Dictionary(text, new Dictionary <string, object>
                        {
                            {
                                "User",
                                "admin"
                            },
                            {
                                "Pass",
                                "123"
                            },
                            {
                                "Remember",
                                "true"
                            }
                        });
                        dictionary["User"] = nguoiDungEntity.TenDangNhap;
                        dictionary["Pass"] = nguoiDungEntity.MatKhau;
                        text = ProcessConfigXML.Dictionary2ConfigString(dictionary);
                        ProcessConfigXML.SaveData("Account", text);
                    }
                    bool flag11 = flag;
                    if (flag11)
                    {
                        DataTable dataTable = (DataTable)this._bindingTaiKhoan.DataSource;
                        DataRow   dataRow   = dataTable.NewRow();
                        dataRow["NguoiDungId"]    = nguoiDungEntity.NguoiDungId;
                        dataRow["TenDangNhap"]    = nguoiDungEntity.TenDangNhap;
                        dataRow["MatKhau"]        = nguoiDungEntity.MatKhau;
                        dataRow["HoTenNguoiDung"] = nguoiDungEntity.HoTenNguoiDung;
                        dataRow["GioiTinh"]       = nguoiDungEntity.GioiTinh;
                        dataRow["SoDienThoai"]    = nguoiDungEntity.SoDienThoai;
                        dataRow["DiaChiEmail"]    = nguoiDungEntity.DiaChiEmail;
                        dataRow["VaiTro"]         = nguoiDungEntity.VaiTro;
                        dataTable.Rows.Add(dataRow);
                        this.dgvTaiKhoan.Rows[this.dgvTaiKhoan.Rows.Count - 1].Selected = true;
                    }
                    this.btnThemMoi.Enabled  = true;
                    this.dgvTaiKhoan.Enabled = true;
                    this.btnXoa.Enabled      = true;
                    this.dgvTaiKhoan_SelectionChanged(null, null);
                    MessageBox.Show("Cập nhật tài khoản thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    MessageBox.Show("Cập nhật tài khoản không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            this.Cursor = Cursors.Default;
        }
Beispiel #2
0
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            bool flag = this.txtUser.Text.Trim() == "" || this.txtPassOld.Text.Trim() == "" || this.txtPassNew.Text.Trim() == "";

            if (flag)
            {
                MessageBox.Show("Tên đăng nhập và mật khẩu không được để trống!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.txtUser.Focus();
            }
            else
            {
                bool flag2 = this.txtPassOld.Text.Trim() != Util.Decrypt(GlobalVariable.MatKhau);
                if (flag2)
                {
                    MessageBox.Show("Mật khẩu hiện tại không đúng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.txtUser.Focus();
                }
                else
                {
                    bool flag3 = !ManageBase.NguoiDungExist(GlobalVariable.NguoiDungId, this.txtUser.Text.Trim());
                    if (flag3)
                    {
                        NguoiDungEntity nguoiDungEntity = ManageBase.SelectNguoiDungById(GlobalVariable.NguoiDungId);
                        nguoiDungEntity.TenDangNhap    = this.txtUser.Text.Trim();
                        nguoiDungEntity.MatKhau        = Util.Encrypt(this.txtPassNew.Text.Trim());
                        nguoiDungEntity.HoTenNguoiDung = this.txtHoTen.Text.Trim();
                        nguoiDungEntity.SoDienThoai    = this.txtSoDienThoai.Text.Trim();
                        nguoiDungEntity.DiaChiEmail    = this.txtEmail.Text.Trim();
                        bool flag4 = this.chkGioiTinh.CheckState == CheckState.Checked;
                        if (flag4)
                        {
                            nguoiDungEntity.GioiTinh = 1;
                        }
                        else
                        {
                            bool flag5 = this.chkGioiTinh.CheckState == CheckState.Unchecked;
                            if (flag5)
                            {
                                nguoiDungEntity.GioiTinh = 0;
                            }
                            else
                            {
                                nguoiDungEntity.GioiTinh = 3;
                            }
                        }
                        bool flag6 = ManageBase.SaveNguoiDung(nguoiDungEntity);
                        if (flag6)
                        {
                            GlobalVariable.TenDangNhap = nguoiDungEntity.TenDangNhap;
                            GlobalVariable.MatKhau     = nguoiDungEntity.MatKhau;
                            string text = ProcessConfigXML.LoadData("Account");
                            Dictionary <string, object> dictionary = ProcessConfigXML.ConfigString2Dictionary(text, new Dictionary <string, object>
                            {
                                {
                                    "User",
                                    ""
                                },
                                {
                                    "Pass",
                                    ""
                                },
                                {
                                    "Remember",
                                    "true"
                                }
                            });
                            dictionary["User"] = nguoiDungEntity.TenDangNhap;
                            dictionary["Pass"] = nguoiDungEntity.MatKhau;
                            text = ProcessConfigXML.Dictionary2ConfigString(dictionary);
                            ProcessConfigXML.SaveData("Account", text);
                            MessageBox.Show("Cập nhật tài khoản thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                        else
                        {
                            MessageBox.Show("Cập nhật tài khoản không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Tên đăng nhập đã tồn tại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        this.txtUser.Focus();
                    }
                }
            }
        }