private void ImportDL()
        {
            string sql = "select initcap(nv.hoten) as TenDayDu, lower(tk.username) as TenDangNhap, nv.idnhanvien, nnd.idnhomnguoidung " +
                         "from tbl_tmp_nhanvien tk " +
                         "       inner join tbl_dm_nhanvien nv on tk.manhanvien = nv.manhanvien " +
                         "       inner join tbl_dm_nhomnguoidung nnd on tk.phanquyen = nnd.tennhom " +
                         "   where  lower(tk.username) not in (select lower(tendangnhap) from tbl_dm_nguoidung)";
            DataSet ds = DBTools.getData("TaiKhoan", sql);

            foreach (DataRow ct in ds.Tables["TaiKhoan"].Rows)
            {
                frmProgress.Instance.Description = String.Format("Đang import tai khoan {0} ....", ct["TenDangNhap"].ToString());
                try
                {
                    NguoiDungInfor objNguoiDung = new NguoiDungInfor();
                    //cap nhat thong tin NND
                    string mySalt = Password.CreateSalt();
                    string myPass = Password.SetPassword("123456", mySalt);

                    objNguoiDung.TenDayDu        = ct["TenDayDu"].ToString();
                    objNguoiDung.TenDangNhap     = ct["TenDangNhap"].ToString();
                    objNguoiDung.MatKhau         = myPass;
                    objNguoiDung.Salt            = mySalt;
                    objNguoiDung.IdNhanVien      = Common.IntValue(ct["IdNhanVien"].ToString());
                    objNguoiDung.IdNhomNguoiDung = Common.IntValue(ct["IdNhomNguoiDung"].ToString());
                    objNguoiDung.SuDung          = true;// (chkSuDung.Checked ? 1 : 0);
                    NguoiDungDataProvider.Insert(objNguoiDung);
                    frmProgress.Instance.Description = String.Format("Đã import xong tai khoan [{0}] ....", ct["TenDangNhap"].ToString());
                }
                catch {
                }
                frmProgress.Instance.Value += 1;
            }

            frmProgress.Instance.IsCompleted = true;
            frmProgress.Instance.Description = String.Format("Đã import xong {0} tai khoan", 384);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtUserName.Text.Trim().Equals(""))
                {
                    MessageBox.Show(Declare.msgInputData, Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtUserName.Focus();
                    return;
                }

                if (txtPassword.Text.Trim() != txtRetypePassword.Text.Trim())
                {
                    MessageBox.Show("Xác nhận lại mật khẩu!", Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtRetypePassword.Focus();
                    return;
                }

                if (bteThuongVien.Tag == null)
                {
                    MessageBox.Show("Phải chọn nhân viên!", Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    bteThuongVien.Focus();
                    return;
                }

                if (!String.IsNullOrEmpty(txtExpiredIn.Text) && !Common.IsNumeric4(txtExpiredIn.Text))
                {
                    txtExpiredIn.Focus();

                    throw new ManagedException("Thời gian áp dụng không đúng định dạng.");
                }

                if (Convert.ToInt32(txtExpiredIn.Text) < 0)
                {
                    throw new ManagedException("Thời gian áp dụng phải lớn hơn hoặc bằng 0.");
                }

                if (objNguoiDung == null)
                {
                    if (NguoiDungDataProvider.Exist(txtUserName.Text.Trim()))
                    {
                        MessageBox.Show("Tên đăng nhập này đã được sử dụng. Hãy chọn tên đăng nhập khác!");
                        txtUserName.Focus();
                        return;
                    }
                    objNguoiDung = new NguoiDungInfor();
                    //cap nhat thong tin NND
                    string mySalt = Password.CreateSalt();
                    string myPass = Password.SetPassword(txtPassword.Text.Trim(), mySalt);

                    objNguoiDung.TenDayDu        = txtFullName.Text.Trim();
                    objNguoiDung.TenDangNhap     = txtUserName.Text.Trim();
                    objNguoiDung.MatKhau         = myPass;
                    objNguoiDung.Salt            = mySalt;
                    objNguoiDung.IdNhanVien      = ((DMNhanVienInfo)bteThuongVien.Tag).IdNhanVien;
                    objNguoiDung.IdNhomNguoiDung = Common.IntValue(cboGroup.SelectedValue);
                    objNguoiDung.SuDung          = chkSuDung.Checked;// (chkSuDung.Checked ? 1 : 0);

                    if (chkNeverExpired.Checked)
                    {
                        objNguoiDung.ThoiGianApDung = -1;
                    }
                    else
                    {
                        objNguoiDung.ThoiGianApDung = Convert.ToInt32(txtExpiredIn.Text);
                    }

                    objNguoiDung.ChangeOnNext = chkForceChangeAtFirst.Checked;

                    NguoiDungDataProvider.Insert(objNguoiDung);

                    MessageBox.Show("Thêm mới thông tin người dùng thành công!");
                }
                else
                {
                    objNguoiDung.TenDayDu        = txtFullName.Text.Trim();
                    objNguoiDung.IdNhanVien      = ((DMNhanVienInfo)bteThuongVien.Tag).IdNhanVien;
                    objNguoiDung.IdNhomNguoiDung = Common.IntValue(cboGroup.SelectedValue);
                    objNguoiDung.SuDung          = chkSuDung.Checked;// (chkSuDung.Checked ? 1 : 0);

                    if (chkNeverExpired.Checked)
                    {
                        objNguoiDung.ThoiGianApDung = -1;
                    }
                    else
                    {
                        objNguoiDung.ThoiGianApDung = Convert.ToInt32(txtExpiredIn.Text);
                    }

                    objNguoiDung.ChangeOnNext = chkForceChangeAtFirst.Checked;

                    NguoiDungDataProvider.Update(objNguoiDung);

                    MessageBox.Show("Cập nhật thông tin người dùng thành công!");
                }
                this.frm.LoadAllNguoiDung();
            }
            catch (ManagedException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            catch (Exception ex)
            {
#if DEBUG
                MessageBox.Show(ex.ToString());
#else
                MessageBox.Show(ex.Message);
#endif
                EventLogProvider.Instance.WriteOfflineLog(ex.ToString(), "");
            }
        }