192 lines
8.3 KiB
C#
192 lines
8.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Collections;
|
|
using System.Web.UI.WebControls;
|
|
|
|
namespace BLL
|
|
{
|
|
/// <summary>
|
|
/// 管线管线材料对应对应信息
|
|
/// </summary>
|
|
public static class HJGL_Match_PipeMaterialService
|
|
{
|
|
/// <summary>
|
|
/// 根据管线材料对应信息Id获取管线材料对应信息
|
|
/// </summary>
|
|
/// <param name="ndtrId"></param>
|
|
/// <returns></returns>
|
|
public static Model.HJGL_Match_PipeMaterial GetHJGL_Match_PipeMaterialByPipeMaterialId(string pipeMaterialId)
|
|
{
|
|
return Funs.DB.HJGL_Match_PipeMaterial.FirstOrDefault(e => e.PipeMaterialId == pipeMaterialId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据管线材料对应信息Id获取管线材料对应信息
|
|
/// </summary>
|
|
/// <param name="ndtrId"></param>
|
|
/// <returns></returns>
|
|
public static Model.HJGL_Match_PipeMaterial GetHJGL_Match_PipeMaterialByMaterialIdpipelineId(string materialId, string pipelineId)
|
|
{
|
|
return Funs.DB.HJGL_Match_PipeMaterial.FirstOrDefault(e => e.MaterialId == materialId && e.ISO_ID == pipelineId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加管线材料对应信息
|
|
/// </summary>
|
|
/// <param name="ndtrate"></param>
|
|
public static void AddHJGL_Match_PipeMaterial(Model.HJGL_Match_PipeMaterial pipeMaterial)
|
|
{
|
|
Model.SGGLDB db = Funs.DB;
|
|
Model.HJGL_Match_PipeMaterial newPipeMaterial = new Model.HJGL_Match_PipeMaterial();
|
|
newPipeMaterial.PipeMaterialId = SQLHelper.GetNewID(typeof(Model.HJGL_Match_PipeMaterial));
|
|
newPipeMaterial.ProjectId = pipeMaterial.ProjectId;
|
|
newPipeMaterial.MaterialId = pipeMaterial.MaterialId;
|
|
newPipeMaterial.ISO_ID = pipeMaterial.ISO_ID;
|
|
newPipeMaterial.NeedCount = pipeMaterial.NeedCount;
|
|
newPipeMaterial.UsedCount = pipeMaterial.UsedCount;
|
|
db.HJGL_Match_PipeMaterial.InsertOnSubmit(newPipeMaterial);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改
|
|
/// </summary>
|
|
/// <param name="ndtrate"></param>
|
|
public static void UpdateHJGL_Match_PipeMaterial(Model.HJGL_Match_PipeMaterial pipeMaterial)
|
|
{
|
|
Model.SGGLDB db = Funs.DB;
|
|
Model.HJGL_Match_PipeMaterial newPipeMaterial = db.HJGL_Match_PipeMaterial.FirstOrDefault(e => e.PipeMaterialId == pipeMaterial.PipeMaterialId);
|
|
if (newPipeMaterial != null)
|
|
{
|
|
newPipeMaterial.MaterialId = pipeMaterial.MaterialId;
|
|
newPipeMaterial.ISO_ID = pipeMaterial.ISO_ID;
|
|
newPipeMaterial.NeedCount = pipeMaterial.NeedCount;
|
|
newPipeMaterial.UsedCount = pipeMaterial.UsedCount;
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <param name="ndtrateId"></param>
|
|
public static void DeleteHJGL_Match_PipeMaterial(string PipeMaterialId)
|
|
{
|
|
Model.SGGLDB db = Funs.DB;
|
|
Model.HJGL_Match_PipeMaterial pipeMaterial = db.HJGL_Match_PipeMaterial.FirstOrDefault(e => e.PipeMaterialId == PipeMaterialId);
|
|
if (pipeMaterial != null)
|
|
{
|
|
db.HJGL_Match_PipeMaterial.DeleteOnSubmit(pipeMaterial);
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断是否存在相同的管线材料对应信息
|
|
/// </summary>
|
|
/// <param name="ndtrateCode"></param>
|
|
/// <returns></returns>
|
|
public static bool IsExitHJGL_Match_PipeMaterialCode(string materialId, string pipelineId)
|
|
{
|
|
Model.SGGLDB db = Funs.DB;
|
|
var q = from x in db.HJGL_Match_PipeMaterial where x.MaterialId == materialId && x.ISO_ID == pipelineId select x;
|
|
if (q.Count() > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 集合
|
|
/// </summary>
|
|
private static List<Model.HJGL_View_MatchPipeMaterial> ViewMatchPipeMaterialList
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询结果集合
|
|
/// </summary>
|
|
/// <param name="startDate"></param>
|
|
/// <param name="endDate"></param>
|
|
/// <returns></returns>
|
|
public static List<Model.HJGL_View_MatchPipeMaterial> GetViewMatchPipeMaterialList()
|
|
{
|
|
return ViewMatchPipeMaterialList;
|
|
}
|
|
/// <summary>
|
|
/// 根据项目状态获取管线组件匹配试图
|
|
/// </summary>
|
|
/// <param name="ManagerTotalId"></param>
|
|
/// <returns></returns>
|
|
public static List<Model.HJGL_View_MatchPipeMaterial> GetViewMatchPipeMaterial(string projectId, string rbMatch)
|
|
{
|
|
List<Model.HJGL_View_MatchPipeMaterial> returnViewMatch = new List<Model.HJGL_View_MatchPipeMaterial>();
|
|
////取库存数量
|
|
var storage = (from x in Funs.DB.HJGL_Match_Storage where x.ProjectId == projectId && ((x.InCount.HasValue ? x.InCount : 0) - (x.OutCount.HasValue ? x.OutCount : 0)) > 0 select x).ToList();
|
|
if (storage.Count() > 0)
|
|
{ ///单位下每个区域的需要匹配的管线
|
|
List<Model.HJGL_View_MatchPipeMaterial> viewMatch = (from x in Funs.DB.HJGL_View_MatchPipeMaterial
|
|
orderby x.ISO_IsoNo
|
|
where x.ProjectId == projectId && (x.NeedCount - x.UsedCount) > 0
|
|
select x).ToList();
|
|
|
|
if (rbMatch == "1")
|
|
{
|
|
foreach (var viewItem in viewMatch)
|
|
{
|
|
var matchStorage = storage.FirstOrDefault(x => x.MaterialId == viewItem.MaterialId && ((x.InCount.HasValue ? x.InCount : 0) - (x.OutCount.HasValue ? x.OutCount : 0)) >= viewItem.NowNeedCount);
|
|
if (matchStorage != null)
|
|
{
|
|
viewItem.MatchCount = viewItem.NowNeedCount.Value;
|
|
returnViewMatch.Add(viewItem);
|
|
|
|
storage.Remove(matchStorage);
|
|
matchStorage.OutCount = (matchStorage.OutCount.HasValue ? matchStorage.OutCount : 0) + viewItem.MatchCount;
|
|
storage.Add(matchStorage); ///更新库存中的数量
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (var viewItem in viewMatch)
|
|
{
|
|
var matchStorage = storage.FirstOrDefault(x => x.MaterialId == viewItem.MaterialId);
|
|
if (matchStorage != null)
|
|
{
|
|
////库存数量
|
|
decimal sCount = ((matchStorage.InCount.HasValue ? matchStorage.InCount : 0) - (matchStorage.OutCount.HasValue ? matchStorage.OutCount : 0)).Value;
|
|
if (sCount >= viewItem.NowNeedCount) ////库存数量大于等于匹配量
|
|
{
|
|
viewItem.MatchCount = viewItem.NowNeedCount.Value;
|
|
returnViewMatch.Add(viewItem);
|
|
|
|
storage.Remove(matchStorage);
|
|
matchStorage.OutCount = (matchStorage.OutCount.HasValue ? matchStorage.OutCount : 0) + viewItem.MatchCount;
|
|
storage.Add(matchStorage); ///更新库存中的数量
|
|
}
|
|
else ////库存数量小于匹配量
|
|
{
|
|
viewItem.MatchCount = sCount;
|
|
returnViewMatch.Add(viewItem);
|
|
////这个材料在库存量为0了
|
|
storage.Remove(matchStorage);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
ViewMatchPipeMaterialList= returnViewMatch;
|
|
return returnViewMatch;
|
|
}
|
|
}
|
|
}
|