Beispiel #1
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            class_khachhang kh = new class_khachhang();

            if (kh.kiemtra(txtMaKH.Text, txtTen.Text, txtDiaChi.Text, txtDienThoai.Text, txtFax.Text) == false)
            {
                kh.sua(txtMaKH.Text, txtTen.Text, txtDiaChi.Text, txtDienThoai.Text, txtFax.Text);
                MessageBox.Show("Sua Thanh Cong ", "Thông Báo");
                update();
            }
            else
            {
                MessageBox.Show("Loi Sua", "Thong Bao");
            }

            //try
            //{
            //    cn.Open();
            //    string Update = "update KhachHang set TenKH ='" + txtTen.Text + "',DiaChi='" + txtDiaChi.Text + "',DienThoai='" + txtDienThoai.Text + "',Fax='" + txtFax.Text + "' where MaKH='" + txtMaKH.Text + "'";
            //    SqlCommand cmdUpdate = new SqlCommand(Update, cn);

            //    cmdUpdate.ExecuteNonQuery();
            //    Connect();
            //    MessageBox.Show("Sua Thanh Cong ", "Thông Báo");
            //}
            //catch (SqlException ex)
            //{
            //    MessageBox.Show("Loi Sua", "thong Bao\n" + ex.Message);

            //}
            //finally
            //{
            //    cn.Close();
            //}
        }
Beispiel #2
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            try
            {
                //class_khachhang kh = new class_khachhang();

                if (kh.kiemtra(txtMaKH.Text.Trim(), txtTen.Text.Trim(), txtDiaChi.Text.Trim(), txtDienThoai.Text.Trim(), txtFax.Text.Trim()) == false)
                {
                    kh.them(txtMaKH.Text, txtTen.Text, txtDiaChi.Text, txtDienThoai.Text, txtFax.Text);
                    MessageBox.Show("Them Thanh Cong ", "Thông Báo");
                    update();
                }
                else
                {
                    MessageBox.Show("Loi Them", "Thong Bao");
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show("Loi Them", "Thong Bao");
            }

            //try
            //{
            //    cn.Open();
            //    string Insert = "Insert into KhachHang(MaKH, TenKH, DiaChi, DienThoai, Fax) values('" + txtMaKH.Text + "','" + txtTen.Text + "','" + txtDiaChi.Text + "','" + txtDienThoai.Text + "','" + txtFax.Text + "')";
            //    SqlCommand cmdadd = new SqlCommand(Insert, cn);

            //    cmdadd.ExecuteNonQuery();
            //    Connect();
            //    MessageBox.Show("Them Thanh Cong ", "Thông Báo");
            //}
            //catch (SqlException ex)
            //{
            //    MessageBox.Show("Loi Them", "Thong Bao" + ex.Message);

            //}
            finally
            {
                cn.Close();
            }
        }
Beispiel #3
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            class_khachhang kh = new class_khachhang();

            if (kh.kiemtra(txtMaKH.Text, txtTen.Text, txtDiaChi.Text, txtDienThoai.Text, txtFax.Text) == false)
            {
                kh.xoa(txtTen.Text);
                MessageBox.Show("Xoa Thanh Cong ", "Thông Báo");
                update();
            }
            else
            {
                MessageBox.Show("Loi Xoa", "Thong Bao");
            }

            //try
            //{
            //    cn.Open();
            //    string Delete = "Delete KhachHang WHERE TenKH ='" + txtTen.Text + "'";
            //    SqlCommand cmddel = new SqlCommand(Delete, cn);

            //    cmddel.ExecuteNonQuery();
            //    Connect();
            //    MessageBox.Show("Xóa Thành Công ", "Thông Báo");



            //}
            //catch (SqlException ex)
            //{
            //    MessageBox.Show("Loi Xoa", "Thông Báo\n" + ex.Message);
            //}
            //finally
            //{
            //    cn.Close();
            //}
        }