public int Update(Chi_Tiet_Phieu_Xuat_Tam ctxt) { DatabaseHelper help = new DatabaseHelper(); help.ConnectDatabase(); int temp = 0; using (var dbcxtransaction = help.ent.Database.BeginTransaction()) { using (var context = help.ent) { context.Chi_Tiet_Phieu_Xuat_Tam.Attach(ctxt); context.Entry(ctxt).State = EntityState.Modified; temp = help.ent.SaveChanges(); dbcxtransaction.Commit(); } } return temp; //DAL.BeginTransaction(); //m_dbConnection = DAL.m_conn; //if (m_dbConnection.State == ConnectionState.Closed) // m_dbConnection.Open(); //string sql = ""; //sql += "UPDATE Chi_Tiet_Phieu_xuat_tam "; //sql += "Set ma_phieu_xuat_tam=@ma_phieu_xuat_tam,Ma_vat_tu=@Ma_vat_tu,So_luong_de_nghi=@So_luong_de_nghi,So_luong_hoan_nhap=@So_luong_hoan_nhap,So_luong_giu_lai = @So_luong_giu_lai ,so_luong_thuc_lanh = @so_luong_thuc_lanh"; //sql += "WHERE ma_phieu_xuat_tam=@ma_phieu_xuat_tam and ID_vat_tu = @ID_vat_tu"; //SqlCommand command = new SqlCommand(sql, m_dbConnection, DAL.m_trans); //command.CommandType = CommandType.Text; //command.Parameters.Add(new SqlParameter("@ma_phieu_xuat_tam", Ma_phieu_xuat_tam)); //command.Parameters.Add(new SqlParameter("@Ma_vat_tu", Ma_vat_tu)); //command.Parameters.Add(new SqlParameter("@So_luong_de_nghi", So_luong_de_nghi)); //command.Parameters.Add(new SqlParameter("@So_luong_hoan_nhap", So_luong_hoan_nhap)); //command.Parameters.Add(new SqlParameter("@So_luong_giu_lai", So_luong_giu_lai)); //// command.Parameters.Add(new SqlParameter("@so_hoa_don", So_hoa_don)); //int result = command.ExecuteNonQuery(); //DAL.CommitTransaction(); //return result; }
public int Update( DatabaseHelper help,Chi_Tiet_Phieu_Xuat_Tam ctxt) { int temp = 0; { { help.ent.Chi_Tiet_Phieu_Xuat_Tam.Attach(ctxt); help.ent.Entry(ctxt).State = EntityState.Modified; temp = help.ent.SaveChanges(); } } return temp; }
public int Delete(Chi_Tiet_Phieu_Xuat_Tam ctxt) { DatabaseHelper help = new DatabaseHelper(); help.ConnectDatabase(); using (var dbcxtransaction = help.ent.Database.BeginTransaction()) { help.ent.Chi_Tiet_Phieu_Xuat_Tam.Attach(ctxt); help.ent.Chi_Tiet_Phieu_Xuat_Tam.Remove(ctxt); help.ent.SaveChanges(); dbcxtransaction.Commit(); return 1; //} //DAL.BeginTransaction(); //m_dbConnection = DAL.m_conn; //if (m_dbConnection.State == ConnectionState.Closed) // m_dbConnection.Open(); //string sql = "Delete from Chi_Tiet_Phieu_xuat_tam WHERE ma_phieu_xuat_tam=@ma_phieu_xuat_tam and Ma_vat_tu = @Ma_vat_tu"; //SqlCommand command = new SqlCommand(sql, m_dbConnection, DAL.m_trans); //command.CommandType = CommandType.Text; //command.Parameters.Add(new SqlParameter("@ma_phieu_xuat_tam", Ma_phieu_xuat_tam)); //command.Parameters.Add(new SqlParameter("@Ma_vat_tu", Ma_vat_tu)); //int result = command.ExecuteNonQuery(); //DAL.CommitTransaction(); //return result; } }
public int Insert(DatabaseHelper help) { { Chi_Tiet_Phieu_Xuat_Tam ctpxt = new Chi_Tiet_Phieu_Xuat_Tam(); ctpxt.Ma_phieu_xuat_tam = this.Ma_phieu_xuat_tam ; ctpxt.Ma_vat_tu = this.Ma_vat_tu; ctpxt.ID_kho = this.ID_kho; ctpxt.Id_chat_luong = this.Id_chat_luong; ctpxt.ID_chi_tiet_phieu_xuat_tam = this.ID_chi_tiet_phieu_xuat_tam; ctpxt.So_luong_dang_giu = this.So_luong_dang_giu; ctpxt.So_luong_de_nghi = this.So_luong_de_nghi; ctpxt.So_luong_hoan_nhap = this.So_luong_hoan_nhap; ctpxt.So_luong_thuc_xuat = this.so_luong_thuc_lanh; ctpxt.So_luong_giu_lai = this.So_luong_giu_lai; help.ent.Chi_Tiet_Phieu_Xuat_Tam.Add(ctpxt); return help.ent.SaveChanges(); } }
public int Update(DatabaseHelper help) { try { { var item = new Phieu_Xuat_Tam_Vat_Tu(); item.ID_kho = this.ID_kho; item.ID_nhan_vien = this.ID_Nhan_vien; item.isGiuLai = this.isGiuLai; item.isHoanNhap = this.isHoanNhap; item.Ly_do = this.Ly_do; item.Cong_trinh = this.Cong_trinh; item.Dia_chi = this.Dia_chi; item.Ngay_xuat = this.Ngay_xuat; item.Ma_phieu_xuat_tam = this.Ma_phieu_xuat_tam; item.Da_duyet = this.Da_duyet; item.ID_phieu_xuat_tam = this.ID_phieu_xuat_tam; help.ent.Phieu_Xuat_Tam_Vat_Tu.Attach(item); help.ent.Entry(item).State = EntityState.Modified; help.ent.SaveChanges(); var ctpxt = new Chi_Tiet_Phieu_Xuat_Tam(); var dm = (from d in help.ent.Chi_Tiet_Phieu_Xuat_Tam where d.Ma_phieu_xuat_tam == item.Ma_phieu_xuat_tam select d ).ToList(); if (dm == null) { return 1; } for (int i = 0; i < dm.Count; i++) { help.ent.Chi_Tiet_Phieu_Xuat_Tam.Attach(dm[i]); help.ent.Chi_Tiet_Phieu_Xuat_Tam.Remove(dm[i]); help.ent.SaveChanges(); } return 1; } } catch (Exception ex) { return 0; } }