public ImportRecord[] Search(ImportRecord c,string cardNo,DateTime begin,DateTime end, ref int page, int pageSize, out int totalPages) { YogaEntities ey = new YogaEntities(); var query = from cc in ey.ImportRecord where cc.MemberName.Contains(c.MemberName) && cc.Member.CardNo.Contains(cardNo) select cc; if (c.MemberId > 0) query = query.Where((cc) => cc.MemberId == c.MemberId); totalPages = (int)Math.Ceiling(query.Count() * 1.0 / pageSize); if (totalPages < 1) { page = 0; return null; } if (page == -1 || page > totalPages) page = totalPages; else if (page < 1) page = 1; return query.OrderBy((cc) => cc.Id).Skip((page - 1) * pageSize).Take(pageSize).ToArray(); }
public string Import(int mid,string name,bool isTemp,int rid) { YogaEntities ye = new YogaEntities(); Member cc = ye.Member.FirstOrDefault((ccc) => ccc.Id == mid); if (cc == null) return string.Format("编号为{0}的会员不存在", mid); ImportRecord ir = new ImportRecord() { Date = DateTime.Now, IsTemp = isTemp, MemberId = mid, MemberName = name, }; ye.AddToImportRecord(ir); if (ye.SaveChanges() != 1) return "进场失败"; Rack r = ye.Rack.FirstOrDefault((rr) => rr.Id == rid && (rr.RenterId==null || rr.RentExpire<=DateTime.Now)); if (r != null) { r.RentDate = DateTime.Now; r.RentExpire = r.RentDate.AddHours(8); r.RenterId = mid; ye.SaveChanges(); } Member m = ye.Member.FirstOrDefault((rr) => rr.Id == ir.Member.Id); if (m == null) return "没有该会员"; if (m.IsTemp && m.TempTimes > 0) { m.TempTimes -= 1; cc.JoneCount += 1; ye.SaveChanges(); return "进场成功"; } if (m.IsTemp && m.TempTimes <= 0) { return "次数不足"; } cc.JoneCount += 1; ye.SaveChanges(); return "进场成功"; }
/// <summary> /// Deprecated Method for adding a new object to the ImportRecord EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToImportRecord(ImportRecord importRecord) { base.AddObject("ImportRecord", importRecord); }
/// <summary> /// Create a new ImportRecord object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="memberId">Initial value of the MemberId property.</param> /// <param name="date">Initial value of the Date property.</param> /// <param name="memberName">Initial value of the MemberName property.</param> /// <param name="isTemp">Initial value of the IsTemp property.</param> public static ImportRecord CreateImportRecord(global::System.Int32 id, global::System.Int32 memberId, global::System.DateTime date, global::System.String memberName, global::System.Boolean isTemp) { ImportRecord importRecord = new ImportRecord(); importRecord.Id = id; importRecord.MemberId = memberId; importRecord.Date = date; importRecord.MemberName = memberName; importRecord.IsTemp = isTemp; return importRecord; }