public static CostDiary GetById(string id) { CostDiary diary = null; if (string.IsNullOrEmpty(id)) { return(diary); } using (pm2Entities entities = new pm2Entities()) { return((from m in entities.Bud_IndirectDiaryCost where m.InDiaryId == id select new CostDiary { Id = m.InDiaryId, Department = m.Department, Code = m.IndireCode, Name = m.Name, PrjId = m.ProjectId, IssuedBy = m.IssuedBy, FlowState = m.FlowState, InputDate = m.InputDate, InputUser = m.InputUser }).FirstOrDefault <CostDiary>()); } }
public void Add(CostDiary costDiary) { if (costDiary != null) { using (pm2Entities entities = new pm2Entities()) { Bud_IndirectDiaryCost cost = new Bud_IndirectDiaryCost { InDiaryId = costDiary.Id, Name = costDiary.Name, IndireCode = costDiary.Code, ProjectId = costDiary.PrjId, Department = costDiary.Department, IssuedBy = costDiary.IssuedBy, InputUser = costDiary.InputUser, InputDate = costDiary.InputDate, FlowState = costDiary.FlowState }; entities.AddToBud_IndirectDiaryCost(cost); entities.SaveChanges(); } } }
public void Update(CostDiary costDiary) { if (costDiary != null) { using (pm2Entities entities = new pm2Entities()) { Bud_IndirectDiaryCost cost = (from m in entities.Bud_IndirectDiaryCost where m.InDiaryId == costDiary.Id select m).FirstOrDefault <Bud_IndirectDiaryCost>(); if (cost == null) { throw new Exception("找不到要修改的间接成本日记对象!!!"); } cost.Name = costDiary.Name; cost.IndireCode = costDiary.Code; cost.Department = costDiary.Department; cost.IssuedBy = costDiary.IssuedBy; cost.InputDate = costDiary.InputDate; cost.InputUser = costDiary.InputUser; entities.SaveChanges(); } } }