Example #1
0
        private void btnDongY_Click(object sender, EventArgs e)
        {
            switch (hd)
            {
                case 1:
                    {
                        if (CheckRetyePass())
                        {
                            if (MessageBox.Show("Bạn muốn người dùng" + LayUser().USERID.ToString(), "Thêm chức vụ", MessageBoxButtons.OKCancel) == DialogResult.OK)
                            {
                                DTO.DTOtblUSER _User = LayUser();
                                busUser = new BUS.BUStblUSER();
                                busUser.ThemtblUSER(_User);
                                foreach (var a in LayGroupUser())
                                {
                                    busGroupUser = new BUS.BUStblGROUPUSER();
                                    busGroupUser.ThemtblGROUPUSER(a);
                                }
                                //_cdGroupUser.Version += 1;
                                //checkdata.CapnhatCheckData(_cdGroupUser);
                                txtPass.Text = "";
                                cmbMaNV.Enabled = false;
                                txtPass.Enabled = false;
                                txtRetype.Enabled = false;
                                btnDongY.Visible = false;
                                btnHuy.Visible = false;
                                btnThem.Visible = true;
                                btnSua.Visible = true;
                                btnXoa.Visible = true;
                                clbGroup.Enabled = false;
                                hd = 0;
                                LoadUser();
                                grdvUser.FocusedRowHandle = grdvUser.RowCount - 1;
                            }
                        }
                        else
                            MessageBox.Show("Kiểm tra lại mật khẩu.", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    }; break;
                case 2:
                    {
                       //try
                        {
                            string _strThongBao = string.Format("Bạn muốn xóa người dùng {0} - {1}?\nViệc xóa này sẽ xóa đi tất cả các quyền mà người này đang giữ!", cmbMaNV.Text, grdvUser.GetRowCellValue(grdvUser.FocusedRowHandle, colName));
                            if (MessageBox.Show(_strThongBao, "Chú ý!", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                busUser = new BUS.BUStblUSER();
                                busUser.XoatblUSER(int.Parse(cmbMaNV.Text));
                                cmbMaNV.Enabled = false;
                                txtPass.Enabled = false;
                                txtRetype.Enabled = false;
                                btnDongY.Visible = false;
                                btnHuy.Visible = false;
                                btnThem.Visible = true;
                                btnSua.Visible = true;
                                btnXoa.Visible = true;
                                hd = 0;
                                LoadUser();
                            }
                        }
                       //catch
                       //{
                       //    MessageBox.Show("Hiện đang có nhân viên thuộc lại nhân viên này");
                       //}
                    }; break;
                case 3:
                    {
                        string _strThongBao = string.Format("Bạn muốn cập nhật người dùng {0} - {1}?", cmbMaNV.Text, grdvUser.GetRowCellValue(grdvUser.FocusedRowHandle, colName));
                        if (MessageBox.Show(_strThongBao, "Chú ý!", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            UpdateUser();
                            //txtPass.Text = "";
                            cmbMaNV.Enabled = false;
                            txtPass.Enabled = false;
                            txtRetype.Enabled = false;
                            btnDongY.Visible = false;
                            btnHuy.Visible = false;
                            btnThem.Visible = true;
                            btnSua.Visible = true;
                            btnXoa.Visible = true;
                            clbGroup.Enabled = false;
                            hd = 0;
                            LoadUser();

                        }
                    }; break;
            }
        }
Example #2
0
        private void UpdateUser()
        {
            int _UserID = int.Parse(cmbMaNV.Text);
            var _oldGroup = GetGroupByUserID((int)grdvUser.GetRowCellValue(grdvUser.FocusedRowHandle, colUserID));
            var _newGroup = LayGroupUser();

            #region Insert - Remove group
            //var _themGroup = _newGroup.Concat(_oldGroup).GroupBy(a => a.GROUPID,(key, group) =>group.First());
            //var _xoaGroup = _newGroup.Concat(_oldGroup).GroupBy(a => a.GROUPID,(key, group) =>group.First());

            //foreach (var _s1 in _oldGroup.ToList())
            //{
            //    _themGroup.ToList().RemoveAll(a => a.GROUPID == _s1.GROUPID);
            //    _themGroup.ToList().Remove(_s1);
            //}

            //for (int i = 0; i < _oldGroup.ToList().Count; i++)
            //{
            //    _themGroup.ToList().Remove(_oldGroup.ToList()[i]);
            //    _themGroup.ToList().RemoveAll(a=>a.GROUPID==_oldGroup[i].GROUPID);
            //}

            //foreach (var _s2 in _newGroup)
            //{
            //    _xoaGroup.ToList().RemoveAll(a=>a.GROUPID==_s2.GROUPID);
            //}
            #endregion

            if (CheckRetyePass())
            {
                if (Encrypt_Decrypt.Decrypt(busUser.LayTheoMatblUSER(_UserID).ToList()[0].PASSWORDS,true) == txtPass.Text.Trim())
                {
                    foreach (var _b in _oldGroup)
                    {
                        busGroupUser = new BUS.BUStblGROUPUSER();
                        busGroupUser.XoatblGROUPUSER(_UserID, _b.GROUPID);
                    }

                    foreach (var _a in _newGroup)
                    {
                        busGroupUser = new BUS.BUStblGROUPUSER();
                        var _dtoGroupUser = new DTO.DTOtblGROUPUSER();
                        _dtoGroupUser.GROUPID = _a.GROUPID;
                        _dtoGroupUser.USERID = _UserID;
                        busGroupUser.ThemtblGROUPUSER(_dtoGroupUser);
                    }
                }

                else   //Cập nhật password nếu thay đổi
                {
                    string _strTB = "Mật khẩu không giống với mật khẩu cũ.\nNếu tiếp tục bạn sẽ đổi mật khẩu của người dùng này\n Bạn muốn tiếp tục chứ?";
                    if (MessageBox.Show(_strTB, "Lưu ý!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                    {

                        foreach (var _b in _oldGroup)
                        {
                            busGroupUser = new BUS.BUStblGROUPUSER();
                            busGroupUser.XoatblGROUPUSER(_UserID, _b.GROUPID);
                        }

                        foreach (var _a in _newGroup)
                        {
                            busGroupUser = new BUS.BUStblGROUPUSER();
                            var _dtoGroupUser = new DTO.DTOtblGROUPUSER();
                            _dtoGroupUser.GROUPID = _a.GROUPID;
                            _dtoGroupUser.USERID = _UserID;
                            busGroupUser.ThemtblGROUPUSER(_dtoGroupUser);
                        }
                        busUser = new BUS.BUStblUSER();
                        var _dtoUser = new DTO.DTOtblUSER();
                        _dtoUser.USERID = _UserID;
                        _dtoUser.PASSWORDS = Encrypt_Decrypt.Encrypt(txtPass.Text, true); ;
                        _dtoUser.LASTCHANGEDPASS = DateTime.Now;
                        _dtoUser.LASTLOGIN = busUser.LayTheoMatblUSER(_UserID)[0].LASTLOGIN;
                        busUser.CapnhattblUSER(_dtoUser);
                    }
                }

            }
            else
                MessageBox.Show("Kiểm tra lại mật khẩu.", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            grdvUser.FocusedRowHandle = grdvUser.RowCount-1;
        }