public void Add(CostAccounting budCost, string inputUser) { using (pm2Entities entities = new pm2Entities()) { Bud_CostAccounting accounting = new Bud_CostAccounting { Id = budCost.Id, CBSCode = budCost.Code, Name = budCost.Name, Type = budCost.Type, Note = budCost.Note }; entities.AddToBud_CostAccounting(accounting); entities.SaveChanges(); } }
public static CostAccounting GetById(string id) { using (pm2Entities entities = new pm2Entities()) { Bud_CostAccounting accounting = (from m in entities.Bud_CostAccounting where m.Id == id select m).FirstOrDefault <Bud_CostAccounting>(); if (accounting == null) { throw new Exception("核算成本,不能找到!"); } return(new CostAccounting { Id = accounting.Id, Name = accounting.Name, Code = accounting.CBSCode, Note = accounting.Note, Type = accounting.Type }); } }
public void Update(CostAccounting budCost) { using (pm2Entities entities = new pm2Entities()) { Bud_CostAccounting accounting = (from m in entities.Bud_CostAccounting where m.Id == budCost.Id orderby m.CBSCode select m).FirstOrDefault <Bud_CostAccounting>(); if (accounting == null) { throw new Exception("核算成本,不能找到要修改的项!"); } accounting.Name = budCost.Name; accounting.Note = budCost.Note; accounting.Type = budCost.Type; entities.SaveChanges(); } }
public static CostAccounting GetByCode(string code) { CostAccounting accounting = new CostAccounting(); using (pm2Entities entities = new pm2Entities()) { Bud_CostAccounting accounting2 = (from m in entities.Bud_CostAccounting where m.CBSCode == code select m).FirstOrDefault <Bud_CostAccounting>(); if (accounting2 != null) { return(new CostAccounting { Id = accounting2.Id, Name = accounting2.Name, Code = accounting2.CBSCode, Note = accounting2.Note, Type = accounting2.Type }); } return(null); } }
public static bool Del(List <string> ids) { bool flag = false; CostAccounting accounting = new CostAccounting(); if (accounting.IsDelAll(ids)) { using (pm2Entities entities = new pm2Entities()) { using (List <string> .Enumerator enumerator = ids.GetEnumerator()) { string id; while (enumerator.MoveNext()) { id = enumerator.Current; Bud_CostAccounting entity = (from m in entities.Bud_CostAccounting where (m.Id == id) && (m.CBSCode.Length >= 6) select m).FirstOrDefault <Bud_CostAccounting>(); if (entity != null) { bool flag3 = true; string cBSCode = entity.CBSCode; if (entity.Type == "D") { flag3 = ConstructResource.IsExistCBSCode(cBSCode); } else { flag3 = IndirectBudget.IsExistCBSCode(cBSCode) || OrganizationBudget.IsExistCBSCode(cBSCode); } if (!flag3) { entities.DeleteObject(entity); entities.SaveChanges(); flag = true; } } } } } } return(flag); }
protected bool IsDelAll(List <string> ids) { bool flag = true; using (pm2Entities entities = new pm2Entities()) { using (List <string> .Enumerator enumerator = ids.GetEnumerator()) { string id; while (enumerator.MoveNext()) { id = enumerator.Current; Bud_CostAccounting accounting = (from m in entities.Bud_CostAccounting where (m.Id == id) && (m.CBSCode.Length >= 6) select m).FirstOrDefault <Bud_CostAccounting>(); if (accounting != null) { bool flag2 = true; string cBSCode = accounting.CBSCode; if (accounting.Type == "D") { flag2 = ConstructResource.IsExistCBSCode(cBSCode); } else { flag2 = IndirectBudget.IsExistCBSCode(cBSCode) || OrganizationBudget.IsExistCBSCode(cBSCode); } if (flag2) { return(false); } } } return(flag); } } }