コード例 #1
0
        private void btnDoiMK_Click(object sender, EventArgs e)
        {
            if (txtTenDangNhap.Text == "" || txtMatKhauCu.Text == "" || txtMatKhauMoi.Text == "" || txtNhapLaiMatKhauMoi.Text == "")
            {
                MessageBox.Show("Thông tin không được để trống");
                return;
            }

            if (txtMatKhauMoi.Text != txtNhapLaiMatKhauMoi.Text)
            {
                MessageBox.Show("Mật khẩu nhập lại không đúng!");
                return;
            }

            if (txtMatKhauMoi.Text.Length < 6)
            {
                MessageBox.Show("Mật khẩu mới phải có 6 ký tự trở lên!");
                return;
            }
            if (MessageBox.Show("Bạn có chắc muốn sửa mật khẩu?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                var NhanVien = new NhanVien
                {
                    MaNhanVien = frmDangNhap.MaNV,
                    MatKhau = txtMatKhauMoi.Text
                };
                NhanVienDAL.SuaMatKhau(NhanVien);
                MessageBox.Show("Thao tác thành công!");
            }
        }
コード例 #2
0
        public static void SuaMatKhau(NhanVien entity)
        {
            String sql = "UPDATE NhanVien SET  MatKhau=@MatKhau WHERE MaNhanVien=@MaNhanVien";

            SqlCommand command = new SqlCommand(sql, DB.Connection);
            command.Parameters.AddWithValue("@MaNhanVien", entity.MaNhanVien);
            command.Parameters.AddWithValue("@MatKhau", entity.MatKhau);

            command.Connection.Open();
            command.ExecuteNonQuery();
            command.Connection.Close();
        }
コード例 #3
0
        public static void Them(NhanVien entity)
        {
            String sql = "INSERT INTO NhanVien(MaNhanVien, TenNhanVien, TaiKhoan, MatKhau, VaiTro, GioiTinh,ThongTin) VALUES(@MaNhanVien, @TenNhanVien, @TaiKhoan, @MatKhau, @VaiTro, @GioiTinh, @ThongTin)";

            SqlCommand command = new SqlCommand(sql, DB.Connection);
            command.Parameters.AddWithValue("@MaNhanVien", entity.MaNhanVien);
            command.Parameters.AddWithValue("@TenNhanVien", entity.TenNhanVien);
            command.Parameters.AddWithValue("@TaiKhoan", entity.TaiKhoan);
            command.Parameters.AddWithValue("@MatKhau", entity.MatKhau);
            command.Parameters.AddWithValue("@VaiTro", entity.VaiTro);
            command.Parameters.AddWithValue("@GioiTinh", entity.GioiTinh);
            command.Parameters.AddWithValue("@ThongTin", entity.ThongTin);

            command.Connection.Open();
            command.ExecuteNonQuery();
            command.Connection.Close();
        }
コード例 #4
0
        public static void Sua(NhanVien entity)
        {
            String sql = "UPDATE NhanVien SET TenNhanVien=@TenNhanVien, TaiKhoan=@TaiKhoan, MatKhau=@MatKhau, VaiTro=@VaiTro, GioiTinh=@GioiTinh, ThongTin = @ThongTin WHERE MaNhanVien=@MaNhanVien";

            SqlCommand command = new SqlCommand(sql, DB.Connection);
            command.Parameters.AddWithValue("@MaNhanVien", entity.MaNhanVien);
            command.Parameters.AddWithValue("@TenNhanVien", entity.TenNhanVien);
            command.Parameters.AddWithValue("@TaiKhoan", entity.TaiKhoan);
            command.Parameters.AddWithValue("@MatKhau", entity.MatKhau);
            command.Parameters.AddWithValue("@VaiTro", entity.VaiTro);
            command.Parameters.AddWithValue("@GioiTinh", entity.GioiTinh);
            command.Parameters.AddWithValue("@ThongTin", entity.ThongTin);

            command.Connection.Open();
            command.ExecuteNonQuery();
            command.Connection.Close();
        }
コード例 #5
0
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (txtMaNV.Text == "" || txtTenNV.Text == "" || txtTK.Text == "" || txtMatKhau.Text == "")
            {
                MessageBox.Show("Không được để trống thông tin", "Thông báo");
            }
            var NV1 = new NhanVien
            {
                MaNhanVien = txtMaNV.Text,
                TenNhanVien = txtTenNV.Text,
                TaiKhoan = txtTK.Text,
                MatKhau = txtMatKhau.Text,
                ThongTin = txtThongTin.Text

            };
            NhanVienDAL.Sua(NV1);

            bsNV.DataSource = NhanVienDAL.LietKe();
            MessageBox.Show("Thao tác thành công", "Thông báo");
        }
コード例 #6
0
        public static NhanVien Tim(String MaNhanVien)
        {
            String sql = "SELECT * FROM NhanVien WHERE MaNhanVien=@MaNhanVien";

            SqlCommand command = new SqlCommand(sql, DB.Connection);
            command.Parameters.AddWithValue("@MaNhanVien", MaNhanVien);

            command.Connection.Open();
            SqlDataReader Reader = command.ExecuteReader();
            if (Reader.Read())
            {
                var NhanVien = new NhanVien
                {
                    MaNhanVien = Convert.ToString(Reader["MaNhanVien"]),
                    TenNhanVien = Convert.ToString(Reader["TenNhanVien"]),
                    TaiKhoan = Convert.ToString(Reader["TaiKhoan"]),
                    MatKhau = Convert.ToString(Reader["MatKhau"]),
                    GioiTinh = Convert.ToBoolean(Reader["GioiTinh"]),
                    VaiTro = Convert.ToBoolean(Reader["VaiTro"]),
                    ThongTin = Convert.ToString(Reader["ThongTin"])
                };
                return NhanVien;
            }
            command.Connection.Close();
            return null;
        }
コード例 #7
0
        public static List<NhanVien> TimTheoSql(String sql)
        {
            SqlCommand command = new SqlCommand(sql, DB.Connection);

            command.Connection.Open();
            SqlDataReader Reader = command.ExecuteReader();
            var dsNV = new List<NhanVien>();
            while (Reader.Read())
            {
                var NhanVien = new NhanVien
                {
                    MaNhanVien = Convert.ToString(Reader["MaNhanVien"]),
                    TenNhanVien = Convert.ToString(Reader["TenNhanVien"]),
                    TaiKhoan = Convert.ToString(Reader["TaiKhoan"]),
                    MatKhau = Convert.ToString(Reader["MatKhau"]),
                    GioiTinh = Convert.ToBoolean(Reader["GioiTinh"]),
                    VaiTro = Convert.ToBoolean(Reader["VaiTro"]),
                    ThongTin = Convert.ToString(Reader["ThongTin"])
                };
                dsNV.Add(NhanVien);
            }
            command.Connection.Close();
            return dsNV;
        }
コード例 #8
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            //txtMaNV.Enabled = true;
            //bsNV.AddNew();
            if (txtMaNV.Text == "" || txtTenNV.Text == "" || txtTK.Text == "" || txtMatKhau.Text == "")
            {
                MessageBox.Show("Không được để trống thông tin", "Thông báo");
                return;
            }
            if (NhanVienDAL.Tim(txtMaNV.Text) != null)
            {
                MessageBox.Show("Mã nhân viên không được trùng", "Thông Báo");
                return;
            }

                bool GT, VT;
                if (cboGioiTinh.SelectedIndex == 0)
                    GT = true;
                else
                    GT = false;

                if (cboVaiTro.SelectedIndex == 0)
                    VT = true;
                else
                    VT = false;

                if (MessageBox.Show("Bạn có muốn thêm sản phẩm không?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    var NV = new NhanVien
                    {
                        MaNhanVien = txtMaNV.Text,
                        TenNhanVien = txtTenNV.Text,
                        TaiKhoan = txtTK.Text,
                        MatKhau = txtMatKhau.Text,
                        ThongTin = txtThongTin.Text,
                        GioiTinh = GT,
                        VaiTro = VT
                    };
                    NhanVienDAL.Them(NV);

                    bsNV.DataSource = NhanVienDAL.LietKe();
                    MessageBox.Show("Thao tác thành công", "Thông báo");

                }
                else
                {
                    MessageBox.Show("Nhân viên đã tồn tại", "Lỗi");
                }
        }