コード例 #1
0
        private void iconButton2_Click(object sender, EventArgs e)
        {
            string sql;

            if (tblNV.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaNV.Text == "")
            {
                MessageBox.Show("Bạn phải chọn bản ghi cần sửa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtTenNV.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên khách", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTenNV.Focus();
                return;
            }
            if (txtDiaChiNV.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập địa chỉ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtDiaChiNV.Focus();
                return;
            }
            if (mtbSDTNV.Text == "(  )    -")
            {
                MessageBox.Show("Bạn phải nhập điện thoại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                mtbSDTNV.Focus();
                return;
            }
            if (datetimeNV.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập ngày sinh", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                datetimeNV.Focus();
                return;
            }
            try
            {
                sql = "SELECT Users FROM tblNhanVien WHERE iDNhanVien=N'" + txtTk.Text.Trim() + "'";
                if (DAO_KhachHang.CheckKey(sql))
                {
                    MessageBox.Show("Tài khoản nhân viên này đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtMaNV.Focus();
                    return;
                }
                sql = "UPDATE tblNhanVien SET TenNV=N'" + txtTenNV.Text.Trim().ToString() + "',GioiTinh=N'" +
                      rdbGioiTinh() + "',DiaChi=N'" + txtDiaChiNV.Text.Trim().ToString() + "',DienThoai='" + mtbSDTNV.Text.ToString() + "',NgaySinh=N'" + datetimeNV.Value.ToString() + "',Users= '" + txtTk.Text + "',pass='******' WHERE idNhanVien=N'" + txtMaNV.Text + "'";
                DataProvider.Instance.ExecuteQuery(sql);
                LoadDataGridView();
                ResetValues();
                btnBoQua.Enabled = false;
            }
            catch (Exception)
            {
                MessageBox.Show("Sửa thất bại", "Thông báo");
            }
            ActivateButton(sender, RGBColors.color4);
        }
コード例 #2
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtMaKhach.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã khách", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMaKhach.Focus();
                return;
            }
            if (txtTenKhach.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên khách", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTenKhach.Focus();
                return;
            }
            if (txtDiaChiKH.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập địa chỉ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtDiaChiKH.Focus();
                return;
            }
            if (mtbSDTKhach.Text == "(   )    -") // mặc định của trường masktextNumber
            {
                MessageBox.Show("Bạn phải nhập điện thoại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                mtbSDTKhach.Focus();
                return;
            }

            try
            {
                //Kiểm tra tồn tại mã khách
                sql = "SELECT iDKhachHang FROM tblKhachHang WHERE iDKhachHang=N'" + txtMaKhach.Text.Trim() + "'";
                if (DAO_KhachHang.CheckKey(sql))
                {
                    MessageBox.Show("Mã khách này đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtMaKhach.Focus();
                    return;
                }

                //Chèn thêm
                sql = "INSERT INTO dbo.tblKhachHang VALUES (N'" + txtMaKhach.Text.Trim() +
                      "',N'" + txtTenKhach.Text.Trim() + "',N'" + txtDiaChiKH.Text.Trim() + "','" + mtbSDTKhach.Text + "',N'" + dateTimeSNKH.Value.ToString() + "')";
                //Functions.RunSQL(sql);

                DataProvider.Instance.ExecuteQuery(sql);
                //  fBill f = new fBill();
                //  f.Load();
                MessageBox.Show("Bạn đã thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Thêm thất bại", "Thông báo");
            }
            //  ActivateButton(sender, RGBColors.color4);
        }
コード例 #3
0
        private void iconButton3_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtMaNV.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã nhân viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMaNV.Focus();
                return;
            }
            if (txtTenNV.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên nhân viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTenNV.Focus();
                return;
            }
            if (txtDiaChiNV.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập địa chỉ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtDiaChiNV.Focus();
                return;
            }
            if (mtbSDTNV.Text == "(   )    -") // mặc định của trường masktextNumber
            {
                MessageBox.Show("Bạn phải nhập điện thoại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                mtbSDTNV.Focus();
                return;
            }
            if (rdbNam.Checked == false && rdbNu.Checked == false)
            {
                MessageBox.Show("Bạn chưa chọn giới tính", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtTk.Text == "") // mặc định của trường masktextNumber
            {
                MessageBox.Show("Bạn phải nhập tài khoản", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTk.Focus();
                return;
            }
            if (txtMK.Text == "")
            {
                MessageBox.Show("Bạn phải nhập mật khẩu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMK.Focus();
                return;
            }
            try
            {
                //Kiểm tra tồn tại mã khách
                sql = "SELECT iDNhanVien FROM tblNhanVien WHERE iDNhanVien=N'" + txtMaNV.Text.Trim() + "'";
                if (DAO_KhachHang.CheckKey(sql))
                {
                    MessageBox.Show("Mã khách này đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtMaNV.Focus();
                    return;
                }

                sql = "SELECT Users FROM tblNhanVien WHERE iDNhanVien=N'" + txtTk.Text.Trim() + "'";
                if (DAO_KhachHang.CheckKey(sql))
                {
                    MessageBox.Show("Tài khoản nhân viên này đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtMaNV.Focus();
                    return;
                }
                string strGioiTinh = rdbGioiTinh();

                //Chèn thêm
                sql = "INSERT INTO dbo.tblNhanVien ( iDNhanVien ,TenNV , GioiTinh ,DiaChi ,  DienThoai ,NgaySinh ,Users,pass ) VALUES (N'" + txtMaNV.Text.Trim() + "',N'" + txtTenNV.Text.Trim() + "',N'" + strGioiTinh + "',N'" + txtDiaChiNV.Text.Trim() + "','" + mtbSDTNV.Text + "',N'" + datetimeNV.Value.ToString() + "','" + txtTk.Text + "','" + txtMK.Text + "')";
                //Functions.RunSQL(sql);

                DataProvider.Instance.ExecuteQuery(sql);
                LoadDataGridView();
                ResetValues();

                btnXoa.Enabled   = true;
                btnThem.Enabled  = true;
                btnSua.Enabled   = true;
                btnBoQua.Enabled = false;
                btnLuu.Enabled   = false;
                txtMaNV.Enabled  = false;
            }
            catch (Exception)
            {
                MessageBox.Show("Thêm thất bại", "Thông báo");
            }
            ActivateButton(sender, RGBColors.color5);
        }