200 lines
7.5 KiB
C#
200 lines
7.5 KiB
C#
using FineUIPro;
|
|
using Model;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
|
|
namespace BLL
|
|
{
|
|
|
|
public static class TwInoutplandetailRelationService
|
|
{
|
|
|
|
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 记录数
|
|
/// </summary>
|
|
public static int Count
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
public static IQueryable<Model.Tw_InOutPlanDetail_Relation> GetTw_InOutPlanDetail_RelationByModle(Model.Tw_InOutPlanDetail_Relation table)
|
|
{
|
|
var q = from x in Funs.DB.Tw_InOutPlanDetail_Relation
|
|
where
|
|
(string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) &&
|
|
(string.IsNullOrEmpty(table.PipelineId) || x.PipelineId.Contains(table.PipelineId)) &&
|
|
(string.IsNullOrEmpty(table.InOutPlanMasterId) || x.InOutPlanMasterId.Contains(table.InOutPlanMasterId)) &&
|
|
(string.IsNullOrEmpty(table.MaterialCode) || x.MaterialCode.Contains(table.MaterialCode)) &&
|
|
(string.IsNullOrEmpty(table.PrefabricatedComponents) || x.PrefabricatedComponents.Contains(table.PrefabricatedComponents))
|
|
select x
|
|
;
|
|
|
|
return q;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取分页列表
|
|
/// </summary>
|
|
/// <param name="table"></param>
|
|
/// <param name="grid1"></param>
|
|
/// <returns></returns>
|
|
public static IEnumerable GetListData(Model.Tw_InOutPlanDetail_Relation table, Grid grid1)
|
|
{
|
|
var q = GetTw_InOutPlanDetail_RelationByModle(table);
|
|
Count = q.Count();
|
|
if (Count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
q = q.Skip(grid1.PageSize * grid1.PageIndex).Take(grid1.PageSize);
|
|
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
|
|
return from x in q
|
|
join y in Funs.DB.HJGL_Pipeline on x.PipelineId equals y.PipelineId
|
|
join mat in Funs.DB.HJGL_MaterialCodeLib on x.MaterialCode equals mat.MaterialCode into mm
|
|
from mat in mm.DefaultIfEmpty()
|
|
orderby x.PipelineId, x.PrefabricatedComponents
|
|
select new
|
|
{
|
|
x.Id,
|
|
x.PipelineId,
|
|
y.PipelineCode,
|
|
x.InOutPlanMasterId,
|
|
x.MaterialCode,
|
|
x.PrefabricatedComponents,
|
|
x.Number,
|
|
mat.MaterialName,
|
|
|
|
};
|
|
}
|
|
#endregion
|
|
|
|
public static Model.Tw_InOutPlanDetail_Relation GetById(string Id)
|
|
{
|
|
return Funs.DB.Tw_InOutPlanDetail_Relation.FirstOrDefault(x => x.Id == Id);
|
|
}
|
|
|
|
|
|
public static void Add(Model.Tw_InOutPlanDetail_Relation newtable)
|
|
{
|
|
|
|
Model.Tw_InOutPlanDetail_Relation table = new Model.Tw_InOutPlanDetail_Relation
|
|
{
|
|
Id = newtable.Id,
|
|
PipelineId = newtable.PipelineId,
|
|
InOutPlanMasterId = newtable.InOutPlanMasterId,
|
|
MaterialCode = newtable.MaterialCode,
|
|
PrefabricatedComponents = newtable.PrefabricatedComponents,
|
|
Number = newtable.Number,
|
|
};
|
|
Funs.DB.Tw_InOutPlanDetail_Relation.InsertOnSubmit(table);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
/// <summary>
|
|
/// 批量添加计划明细
|
|
/// </summary>
|
|
/// <param name="list"></param>
|
|
/// <param name="inoutPlanMasterId"></param>
|
|
public static void AddList(IEnumerable<Model.Tw_InOutPlanDetail_Relation> list, string inoutPlanMasterId)
|
|
{
|
|
foreach (var item in list)
|
|
{
|
|
item.Id = SQLHelper.GetNewID();
|
|
item.InOutPlanMasterId = inoutPlanMasterId;
|
|
Add(item);
|
|
}
|
|
}
|
|
|
|
public static void Update(Model.Tw_InOutPlanDetail_Relation newtable)
|
|
{
|
|
|
|
Model.Tw_InOutPlanDetail_Relation table = Funs.DB.Tw_InOutPlanDetail_Relation.FirstOrDefault(x => x.Id == newtable.Id);
|
|
if (table != null)
|
|
{
|
|
table.Id = newtable.Id;
|
|
table.PipelineId = newtable.PipelineId;
|
|
table.InOutPlanMasterId = newtable.InOutPlanMasterId;
|
|
table.MaterialCode = newtable.MaterialCode;
|
|
table.PrefabricatedComponents = newtable.PrefabricatedComponents;
|
|
table.Number = newtable.Number;
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
|
|
}
|
|
public static void DeleteById(string Id)
|
|
{
|
|
|
|
Model.Tw_InOutPlanDetail_Relation table = Funs.DB.Tw_InOutPlanDetail_Relation.FirstOrDefault(x => x.Id == Id);
|
|
if (table != null)
|
|
{
|
|
Funs.DB.Tw_InOutPlanDetail_Relation.DeleteOnSubmit(table);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
|
|
}
|
|
public static void DeleteByInOutPlanMasterId(string inoutPlanMasterId)
|
|
{
|
|
var list = Funs.DB.Tw_InOutPlanDetail_Relation.Where(x => x.InOutPlanMasterId == inoutPlanMasterId);
|
|
if (list != null)
|
|
{
|
|
Funs.DB.Tw_InOutPlanDetail_Relation.DeleteAllOnSubmit(list);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
public static void InsertByPipeLineMat(string inOutPlanMasterId, List<Model.Tw_PipeLineMat> tw_PipeLineMats)
|
|
{
|
|
var master =TwInOutplanmasterService.GetById(inOutPlanMasterId);
|
|
if (master == null)
|
|
{
|
|
return;
|
|
}
|
|
var outMateriaList = from x in tw_PipeLineMats
|
|
group x by new { x.MaterialCode, x.MaterialUnit }
|
|
into g
|
|
select new
|
|
{
|
|
g.Key.MaterialCode,
|
|
planNum = g.Sum(x => x.Number) ?? 0,
|
|
MaterialName = g.Key.MaterialUnit,
|
|
};
|
|
|
|
switch (master.Category)
|
|
{
|
|
case (int)TwConst.Category.管段:
|
|
outMateriaList.Where(x => x.MaterialName.Contains("米"));//管段
|
|
break;
|
|
case (int)TwConst.Category.管件:
|
|
outMateriaList.Where(x => x.MaterialName.Contains("个"));//管件
|
|
break;
|
|
}
|
|
|
|
foreach (var item in outMateriaList)
|
|
{
|
|
Model.Tw_InOutPlanDetail detail = new Model.Tw_InOutPlanDetail
|
|
{
|
|
Id = Guid.NewGuid().ToString(),
|
|
InOutPlanMasterId = inOutPlanMasterId,
|
|
MaterialCode = item.MaterialCode,
|
|
PlanNum = item.planNum,
|
|
};
|
|
TwInOutplandetailService.Add(detail);
|
|
}
|
|
var twinoutplandetailRelationList = tw_PipeLineMats.Select(x => new Tw_InOutPlanDetail_Relation
|
|
{
|
|
PipelineId = x.PipelineId,
|
|
MaterialCode = x.MaterialCode,
|
|
Number = x.Number,
|
|
PrefabricatedComponents = x.PrefabricatedComponents,
|
|
}).ToList();
|
|
TwInoutplandetailRelationService.AddList(twinoutplandetailRelationList, inOutPlanMasterId);
|
|
|
|
}
|
|
}
|
|
} |