private void cbLoaiSanPham_SelectedIndexChanged(object sender, EventArgs e) { if (cbLoaiSanPham.SelectedIndex == 0) { SLoai = 0; } else { SLoai = HamChung.GetIdFromCombobox(cbLoaiSanPham.SelectedItem.ToString()); } GetSanPham(); }
private void cbSNcc_SelectedIndexChanged(object sender, EventArgs e) { if (cbSNcc.SelectedIndex == 0) { NccId = 0; } else { NccId = HamChung.GetIdFromCombobox(cbSNcc.SelectedItem.ToString()); } GetSanPham(); }
private void InsertOrUpdate() { //try //{ string ten, mota, anh; int id, soluong, dongia, khoId, nccId, loaiId; DateTime ngaynhap; bool active; id = String.IsNullOrEmpty(txtMa.Text) ? 0 : int.Parse(txtMa.Text); ten = txtTen.Text; mota = txtMoTa.Text; anh = !String.IsNullOrEmpty(ptbAnh.Image.ToString()) ? HamChung.GetStringFromImage(ptbAnh.Image) : ""; soluong = Int32.Parse(txtSoLuong.Text); dongia = Int32.Parse(txtDonGia.Text); ngaynhap = DateTime.Now; khoId = HamChung.GetIdFromCombobox(cbKho.SelectedItem.ToString()); nccId = HamChung.GetIdFromCombobox(cbNCC.SelectedItem.ToString()); loaiId = HamChung.GetIdFromCombobox(cbLoaiSanPham.SelectedItem.ToString()); active = checkActive.Checked; if (id == 0) { // thêm cn.ExecuteNonQuery("INSERT INTO SANPHAM VALUES(N'" + ten + "',0," + dongia + ",'" + ngaynhap + "',N'" + mota + "'," + khoId + "," + nccId + "," + loaiId + ",1,0,'" + anh + "')"); MessageBox.Show("Thêm sản phẩm thành công"); } else { string sql = "UPDATE [dbo].[SanPham] SET [ten] = N'" + ten + "' ,[soluong] =" + soluong + " ,[dongia] = " + dongia + " ,[ngaynhap] = '" + ngaynhap + "' ,[mota] = N'" + mota + "' ,[khoId] = " + khoId + " ,[nccId] = " + nccId + " ,[LoaiSanPhamId] = " + loaiId + " ,[active] = '" + active + "' ,[luotxem] =luotxem ,[anh] = '" + anh + "' WHERE id = " + id; cn.ExecuteNonQuery(sql); MessageBox.Show("Sửa sản phẩm thành công"); } GetSanPham(); //} //catch (Exception) //{ // MessageBox.Show("Cách trường dữ liệu không đúng!", "Thông báo"); //} }