예제 #1
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            string sql;

            // Kiểm tra thông tin
            if (tblKhachHang.Rows.Count == 0)
            {
                MessageBox.Show("Không có dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (txtMaKH.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa chọn khách hàng nào!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            // Show dialog
            if (MessageBox.Show("Bạn chắc chắn muốn xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                sql = "delete tbKhachHang where MaKH = '" + txtMaKH.Text + "'";
                ConnectToSQL.RunSQL(sql);
                LoadData();
                ClearValues();
            }
        }
예제 #2
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            string sql;

            // Kiểm tra thông tin
            if (tblKhachHang.Rows.Count == 0)
            {
                MessageBox.Show("Không có dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (txtMaKH.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa chọn khách hàng nào!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMaKH.Focus();
                return;
            }

            if (txtTenKH.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập tên khách hàng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenKH.Focus();
                return;
            }

            if (txtDiaChiKH.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập địa chỉ!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDiaChiKH.Focus();
                return;
            }

            if (txtDienThoaiKH.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập số điện thoại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDienThoaiKH.Focus();
                return;
            }

            if (txtCMNDKH.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập CMND!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtCMNDKH.Focus();
                return;
            }

            // Update thông tin khách hàng
            sql = "update tbKhachHang set TenKhachHang = N'" + txtTenKH.Text.Trim() + "'," +
                  "SDT = '" + txtDienThoaiKH.Text.Trim() + "'," +
                  "DiaChi = N'" + txtDiaChiKH.Text.Trim() + "'," +
                  "CMND = '" + txtCMNDKH.Text.Trim() + "'" +
                  "where MaKH = '" + txtMaKH.Text.Trim() + "'";
            ConnectToSQL.RunSQL(sql);
            LoadData();
            ClearValues();
        }
예제 #3
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            string sql;

            // Kiểm tra thông tin
            if (txtMaKH.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập mã khách hàng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMaKH.Focus();
                return;
            }

            if (txtTenKH.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập tên khách hàng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenKH.Focus();
                return;
            }

            if (txtDiaChiKH.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập địa chỉ!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDiaChiKH.Focus();
                return;
            }

            if (txtDienThoaiKH.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập số điện thoại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDienThoaiKH.Focus();
                return;
            }

            if (txtCMNDKH.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập CMND!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtCMNDKH.Focus();
                return;
            }

            // Kiểm tra mã khách hàng nhập vào
            sql = "select MaKH from tbKhachHang where MaKH = '" + txtMaKH.Text.Trim() + "'";

            if (ConnectToSQL.CheckPrimaryKey(sql))
            {
                MessageBox.Show("Mã khách hàng đã tồn tại, vui lòng nhập lại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtMaKH.Focus();
                txtMaKH.Text = "";
                return;
            }

            // Lưu thông tin khách hàng vừa tạo
            sql = "insert into tbKhachHang values('" + txtMaKH.Text.Trim() + "', N'" + txtTenKH.Text.Trim() + "', '" + txtDienThoaiKH.Text.Trim() + "', N'" + txtDiaChiKH.Text.Trim() + "', '" + txtCMNDKH.Text + "')";
            ConnectToSQL.RunSQL(sql);
            LoadData();
            ClearValues();
            btnThem.Enabled = true;
            btnXoa.Enabled  = true;
            btnSua.Enabled  = true;
            btnLuu.Enabled  = false;
            btnHuy.Enabled  = false;
            txtMaKH.Enabled = false;
        }
예제 #4
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            string sql, gender;

            // Kiểm tra thông tin
            if (tblNhanVien.Rows.Count == 0)
            {
                MessageBox.Show("Không có dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (txtMaNhanVien.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa chọn nhân viên nào!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMaNhanVien.Focus();
                return;
            }

            if (txtTenNhanVien.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập tên nhân viên!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenNhanVien.Focus();
                return;
            }

            if (txtDiaChi.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập địa chỉ!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDiaChi.Focus();
                return;
            }

            if (txtDienThoai.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập số điện thoại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDienThoai.Focus();
                return;
            }

            if (chkGioiTinh.Checked == true)
            {
                gender = "Nam";
            }
            else
            {
                gender = "Nữ";
            }

            if (txtMatKhauNV.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa điền mật khẩu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMatKhauNV.Focus();
                return;
            }

            // Update thông tin nhân viên
            sql = "update tbNhanVien set TenNhanVien = N'" + txtTenNhanVien.Text.Trim() + "', " +
                  "GioiTinh = N'" + gender + "', " +
                  "DiaChi = N'" + txtDiaChi.Text.Trim() + "', " +
                  "SDT = '" + txtDienThoai.Text.Trim() + "', " +
                  "NgaySinh = '" + dtmNgaySinh.Value + "', " +
                  "MatKhau = '" + txtMatKhauNV.Text.Trim() + "'" +
                  "where MaNV = '" + txtMaNhanVien.Text.Trim() + "'";
            ConnectToSQL.RunSQL(sql);
            LoadData();
            ClearValues();
        }
예제 #5
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            string sql, gender;

            // Kiểm tra thông tin
            if (txtMaNhanVien.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập mã nhân viên!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMaNhanVien.Focus();
                return;
            }

            if (txtTenNhanVien.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập tên nhân viên!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenNhanVien.Focus();
                return;
            }

            if (txtDiaChi.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập địa chỉ!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDiaChi.Focus();
                return;
            }

            if (txtDienThoai.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập số điện thoại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDienThoai.Focus();
                return;
            }

            if (txtMatKhauNV.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa điền mật khẩu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMatKhauNV.Focus();
                return;
            }

            if (chkGioiTinh.Checked == true)
            {
                gender = "Nam";
            }
            else
            {
                gender = "Nữ";
            }

            // Kiểm tra mã nhân viên nhập vào
            sql = "select MaNV from tbNhanVien where MaNV = '" + txtMaNhanVien.Text.Trim() + "'";

            if (ConnectToSQL.CheckPrimaryKey(sql))
            {
                MessageBox.Show("Mã nhân viên đã tồn tại, vui lòng nhập lại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtMaNhanVien.Focus();
                txtMaNhanVien.Text = "";
                return;
            }

            // Lưu thông tin nhân viên vừa tạo
            sql = "insert into tbNhanVien values('" + txtMaNhanVien.Text.Trim() + "', N'" + txtTenNhanVien.Text.Trim() + "', N'" + gender + "', N'" + txtDiaChi.Text.Trim() + "', '" + txtDienThoai.Text.Trim() + "', '" + dtmNgaySinh.Value + "', '" + txtMatKhauNV.Text.Trim() + "')";
            ConnectToSQL.RunSQL(sql);
            LoadData();
            ClearValues();
            btnThem.Enabled       = true;
            btnXoa.Enabled        = true;
            btnSua.Enabled        = true;
            btnLuu.Enabled        = false;
            btnHuy.Enabled        = false;
            txtMaNhanVien.Enabled = false;
        }