/// <summary> /// hàm insert này dùng transaction để insert /// </summary> /// <param name="help"></param> /// <returns></returns> public int Insert(DatabaseHelper help) { // insert { try { var t = new Phieu_Nhap_Kho //Make sure you have a table called test in DB { Ma_phieu_nhap = this.Ma_phieu_nhap??"", Kho_nhan = this.Kho_nhan??"", Ngay_lap = this.Ngay_lap, Ly_do = this.Ly_do??"", So_hoa_don = this.So_hoa_don ?? "", Cong_trinh = this.Cong_trinh ?? "", Dia_Chi = this.Dia_chi ?? "", ID_Loai_Phieu_Nhap = this.ID_Loai_Phieu_Nhap ==null?null:this.ID_Loai_Phieu_Nhap, Kho_xuat_ra = this.Kho_xuat_ra ?? "", Da_phan_kho = this.Da_phan_kho==null?false:this.Da_phan_kho, ID_kho = this.ID_khoNhan, Ngay_nhap_vat_tu = DateTime.Today, isGoiDau = this.isGoiDau, isNhapNgoai = this.isNhapNgoai, isCanTru = this.isCanTru, isKNMN = this.isKNMN, isDaTraNo = this.isDaTraNo, isKNTN = this.isKNTN, ngay_xac_nhan = this.ngay_xac_nhan, isToTrinh = this.isToTrinh, isKCTN = this.isKCTN, isKCMN = this.isKCMN, isNVMN = this.isNVMN, Ten_kho_muon = this.Ten_kho_muon, }; help.ent.Phieu_Nhap_Kho.Add(t); help.ent.SaveChanges(); return 1; } catch (Exception ex) { return 0; } } }
public int Insert(SQLDAL dal) { DatabaseHelper help = new DatabaseHelper(); help.ConnectDatabase(); // insert using (var dbcxtransaction = help.ent.Database.BeginTransaction()) { try { var t = new Phieu_Nhap_Kho //Make sure you have a table called test in DB { Ma_phieu_nhap = this.Ma_phieu_nhap, Kho_nhan = this.Kho_nhan, Ngay_lap = this.Ngay_lap, Ly_do = this.Ly_do, So_hoa_don = this.So_hoa_don, Cong_trinh = this.Cong_trinh, Dia_Chi = this.Dia_chi, ID_Loai_Phieu_Nhap = this.ID_Loai_Phieu_Nhap, Kho_xuat_ra = this.Kho_xuat_ra, Da_phan_kho = this.Da_phan_kho, // ID_phieu_nhap = this.ID_phieu_nhap, ID_kho = this.ID_khoNhan, isGoiDau = this.isGoiDau, }; help.ent.Phieu_Nhap_Kho.Add(t); help.ent.SaveChanges(); dbcxtransaction.Commit(); return 1; } catch (Exception ex) { dbcxtransaction.Rollback(); return 0; } } }