public static int Delete(Int64 ID) { var db = new dbTrainEntities(ConnectionController.GetConnection()); try { var reply = db.tblListHandoverReplies.FirstOrDefault(vt => vt.ID == ID); if (reply == null) { return(0); } else { //update all related Handover RemoveListReplyIDFromHandover(ID); //delete Bang ke hoi bao db.DeleteObject(reply); return(db.SaveChanges()); } } catch (Exception ex) { return(0); } finally { db.Dispose(); } }
public static List <tblTrain> SearchTrain(string numberTrain, short type, bool seachDate, DateTime dateFrom, DateTime dateTo) { var db = new dbTrainEntities(ConnectionController.GetConnection()); try { IQueryable <tblTrain> lst = db.tblTrains; if (!string.IsNullOrEmpty(numberTrain)) { lst = lst.Where(x => x.Number.Contains(numberTrain)); } if (type >= 0) { lst = lst.Where(x => x.Type == type); } if (seachDate == true) { var fromDate = new DateTime(dateFrom.Year, dateFrom.Month, dateFrom.Day, 0, 0, 0); var toDate = new DateTime(dateTo.Year, dateTo.Month, dateTo.Day, 23, 59, 59); lst = lst.Where(x => x.DateImportExport.HasValue && x.DateImportExport.Value >= fromDate && x.DateImportExport.Value <= toDate); } return(lst.ToList()); } catch (Exception ex) { return(null); } finally { db.Dispose(); } }
public static List <tblHandover> SearchBBBG(string number, bool searchByDate, DateTime dateFrom, DateTime dateTo, Nullable <Boolean> replyStatus, String replyType, Nullable <Boolean> chuaTaoBangKe) { var db = new dbTrainEntities(ConnectionController.GetConnection()); try { IQueryable <tblHandover> lst = db.tblHandovers.Where(h => h.IsDeleted == null || h.IsDeleted == false); if (searchByDate) { var fromDate = new DateTime(dateFrom.Year, dateFrom.Month, dateFrom.Day, 0, 0, 0); var toDate = new DateTime(dateTo.Year, dateTo.Month, dateTo.Day, 23, 59, 59); lst = lst.Where(x => x.DateHandover.HasValue && x.DateHandover.Value >= fromDate && x.DateHandover.Value <= toDate); } if (!string.IsNullOrEmpty(number)) { lst = lst.Where(x => x.NumberHandover.Contains(number)); } if (replyStatus != null) { lst = lst.Where(x => x.IsReplied == replyStatus); } if (chuaTaoBangKe == true) { lst = lst.Where(x => x.tblListHandoverReply == null); } if (replyType != "-1") { lst = lst.Where(x => x.Type == replyType); } //if (type >= 0) lst = lst.Where(x => x.Type == type); return(lst.ToList()); } catch (Exception ex) { return(null); } finally{ db.Dispose(); } }
public static int RemoveListReplyIDFromHandover(Int64 replyID) { var db = new dbTrainEntities(ConnectionController.GetConnection()); try { //update all related Handover List <tblHandover> list = db.tblHandovers.Where(g => g.tblListHandoverReply.ID == replyID).ToList(); foreach (tblHandover obj in list) { obj.tblListHandoverReply = null; } return(db.SaveChanges()); } catch (Exception ex) { return(0); } finally { db.Dispose(); } }