SGGL_SHJ/SGGL/BLL/HSSE/CostGoods/CostManageItemService.cs

125 lines
5.2 KiB
C#

using System.Collections.Generic;
using System.Linq;
namespace BLL
{
/// <summary>
/// 费用管理明细
/// </summary>
public static class CostManageItemService
{
/// <summary>
/// 根据主键删除费用管理明细
/// </summary>
/// <param name="costManageItemId"></param>
/// <returns></returns>
public static Model.CostGoods_CostManageItem GetCostManageItemById(string costManageItemId)
{
return Funs.DB.CostGoods_CostManageItem.FirstOrDefault(e => e.CostManageItemId == costManageItemId);
}
/// <summary>
/// 根据费用管理主键获取所有相关明细信息
/// </summary>
/// <param name="costManageId"></param>
/// <returns></returns>
public static List<Model.CostGoods_CostManageItem> GetCostManageItemByCostManageId(string costManageId)
{
return (from x in Funs.DB.CostGoods_CostManageItem where x.CostManageId == costManageId select x).ToList();
}
/// <summary>
/// 添加费用管理明细
/// </summary>
/// <param name="costManageItem"></param>
public static void AddCostManageItem(Model.CostGoods_CostManageItem costManageItem)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
Model.CostGoods_CostManageItem newCostManageItem = new Model.CostGoods_CostManageItem
{
CostManageItemId = costManageItem.CostManageItemId,
CostManageId = costManageItem.CostManageId,
InvestCostProject = costManageItem.InvestCostProject,
PriceMoney = costManageItem.PriceMoney,
SupCostTypeId = costManageItem.SupCostTypeId,
SupCostTypeName = costManageItem.SupCostTypeName,
SupSortIndex = costManageItem.SupSortIndex,
CostTypeId = costManageItem.CostTypeId,
CostTypeName = costManageItem.CostTypeName,
SortIndex = costManageItem.SortIndex,
};
db.CostGoods_CostManageItem.InsertOnSubmit(newCostManageItem);
db.SubmitChanges();
CostManageService.UpdateSumMoney(newCostManageItem.CostManageId);
}
}
/// <summary>
/// 修改费用管理明细
/// </summary>
/// <param name="costManageItem"></param>
public static void UpdateCostManageItem(Model.CostGoods_CostManageItem costManageItem)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
Model.CostGoods_CostManageItem newCostManageItem = db.CostGoods_CostManageItem.FirstOrDefault(e => e.CostManageItemId == costManageItem.CostManageItemId);
if (newCostManageItem != null)
{
newCostManageItem.InvestCostProject = costManageItem.InvestCostProject;
newCostManageItem.PriceMoney = costManageItem.PriceMoney;
newCostManageItem.SupCostTypeId = costManageItem.SupCostTypeId;
newCostManageItem.SupCostTypeName = costManageItem.SupCostTypeName;
newCostManageItem.SupSortIndex = costManageItem.SupSortIndex;
newCostManageItem.CostTypeId = costManageItem.CostTypeId;
newCostManageItem.CostTypeName = costManageItem.CostTypeName;
newCostManageItem.SortIndex = costManageItem.SortIndex;
db.SubmitChanges();
CostManageService.UpdateSumMoney(newCostManageItem.CostManageId);
}
}
}
/// <summary>
/// 根据费用管理主键删除所有相关明细信息
/// </summary>
/// <param name="costManageId"></param>
public static void DeleteCostManageItemByCostManageId(string costManageId)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var q = (from x in db.CostGoods_CostManageItem where x.CostManageId == costManageId select x).ToList();
if (q != null)
{
db.CostGoods_CostManageItem.DeleteAllOnSubmit(q);
db.SubmitChanges();
}
CostManageService.UpdateSumMoney(costManageId);
}
}
/// <summary>
/// 根据主键删除费用管理信息
/// </summary>
/// <param name="costManageItemId"></param>
public static void DeleteCostManageItemById(string costManageItemId)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
Model.CostGoods_CostManageItem costManageItem = db.CostGoods_CostManageItem.FirstOrDefault(e => e.CostManageItemId == costManageItemId);
if (costManageItem != null)
{
db.CostGoods_CostManageItem.DeleteOnSubmit(costManageItem);
db.SubmitChanges();
CostManageService.UpdateSumMoney(costManageItem.CostManageId);
}
}
}
}
}