Exemple #1
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            HoaDonNhap hoaDonNhap = new HoaDonNhap();

            hoaDonNhap.id = long.Parse(id);
            hoaDonNhapDB.delete(hoaDonNhap);
            txtTenThuoc.Text  = "";
            txtHanSuDung.Text = "";
            loadDB();
        }
        public void delete(HoaDonNhap hoaDonNhap)
        {
            string        sql = "delete from HOADON_NHAP where id=" + hoaDonNhap.id;
            SqlConnection cnn = Database.getConnection();

            cnn.Open();
            using (SqlCommand cmd = new SqlCommand(sql, cnn))
            {
                cmd.ExecuteNonQuery();
            }
        }
Exemple #3
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (txtTenThuoc.Text == "" ||
                txtHanSuDung.Text == "")
            {
                MessageBox.Show("Hãy nhập đầy đủ thông tin");
                return;
            }
            HoaDonNhap hoaDonNhap = new HoaDonNhap();

            hoaDonNhap.tenThuoc  = txtTenThuoc.Text;
            hoaDonNhap.hanSuDung = txtHanSuDung.Text;
            hoaDonNhapDB.insert(hoaDonNhap);
            loadDB();
        }
        public void update(HoaDonNhap hoaDonNhap)
        {
            string sql = "update HOADON_NHAP set ";

            sql += "TenThuoc=N'" + hoaDonNhap.tenThuoc + "',";
            sql += "HanSuDung='" + hoaDonNhap.hanSuDung + "' ";
            sql += "where id=" + hoaDonNhap.id;
            SqlConnection cnn = Database.getConnection();

            cnn.Open();
            using (SqlCommand cmd = new SqlCommand(sql, cnn))
            {
                cmd.ExecuteNonQuery();
            }
        }
        public void insert(HoaDonNhap hoaDonNhap)
        {
            string sql = "insert into HOADON_NHAP ([TenThuoc], [HanSuDung]) ";

            sql += "values(@TenThuoc, @HanSuDung)";
            SqlConnection cnn = Database.getConnection();

            cnn.Open();
            using (SqlCommand cmd = new SqlCommand(sql, cnn))
            {
                cmd.Parameters.AddWithValue("@TenThuoc", hoaDonNhap.tenThuoc);
                cmd.Parameters.AddWithValue("@HanSuDung", hoaDonNhap.hanSuDung);
                cmd.ExecuteNonQuery();
            }
        }