예제 #1
0
        private void btnLuu_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.Warning);
                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.Warning);
                txttenkhach.Focus();
                return;
            }
            if (txtngaysinh.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập ngày sinh", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txttenkhach.Focus();
                return;
            }
            if (txttenkhach.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập giới tính", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txttenkhach.Focus();
                return;
            }
            if (txtdiachi.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập địa chỉ", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txttenkhach.Focus();
                return;
            }
            sql = "SELECT makhach FROM khachhang WHERE makhach=N'" +
                  txtmakhach.Text.Trim() + "'";
            if (DAO.CheckKey(sql))
            {
                MessageBox.Show("Mã khách này đã có, bạn phải nhập mã khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtmakhach.Focus();
                txtmakhach.Text = "";
                return;
            }
            sql = "INSERT INTO khachhang(makhach,tenkhach,ngaysinh,gioitinh,diachi) VALUES(N'" + txtmakhach.Text + "',N'" + txttenkhach.Text + "',N'" + txtngaysinh.Text + "',N'" + txtgioitinh.Text + "',N'" + txtdiachi.Text + "')";
            DAO.RunSql(sql);
            hienthi();
            ResetValues();
            btnXoa.Enabled     = true;
            btnThem.Enabled    = true;
            btnSua.Enabled     = true;
            btnHuy.Enabled     = false;
            btnLuu.Enabled     = false;
            txtmakhach.Enabled = false;
        }
예제 #2
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            string sql1;

            sql1  = "SELECT * FROM khachhang";
            tblKH = DAO.GetDataToTable(sql1);
            string sql;

            if (tblKH.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }
            else
            {
                if (txtmakhach.Text == "")
                {
                    MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    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.Warning);
                    txttenkhach.Focus();
                    return;
                }
                if (txtngaysinh.Text.Trim().Length == 0)
                {
                    MessageBox.Show("Bạn phải nhập ngày sinh", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txttenkhach.Focus();
                    return;
                }
                if (txtgioitinh.Text.Trim().Length == 0)
                {
                    MessageBox.Show("Bạn phải nhập giới tính", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txttenkhach.Focus();
                    return;
                }
                if (txtdiachi.Text.Trim().Length == 0)
                {
                    MessageBox.Show("Bạn phải nhập địa chỉ", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txttenkhach.Focus();
                    return;
                }
            }
            sql = "UPDATE khachhang SET tenkhach=N'" + txttenkhach.Text.ToString() + "',ngaysinh=N'" + txtngaysinh.Text.ToString() + "',gioitinh=N'" + txtgioitinh.Text.ToString() + "',diachi=N'" + txtdiachi.Text.ToString() + "' WHERE makhach=N'" + txtmakhach.Text + "'";
            DAO.RunSql(sql);
            hienthi();
            ResetValues();
            btnHuy.Enabled = false;
        }