756 lines
36 KiB
C#
756 lines
36 KiB
C#
using FastReport.DevComponents.DotNetBar;
|
||
using FineUIPro;
|
||
using Model;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using WIA;
|
||
|
||
namespace BLL
|
||
{
|
||
/// <summary>
|
||
/// 包装管理服务类
|
||
/// </summary>
|
||
public static class HJGLPackagingmanageService
|
||
{
|
||
#region Fields
|
||
/// <summary>
|
||
/// 包装分类映射字典
|
||
/// </summary>
|
||
public static Dictionary<string, int> CategoryIntMap = new Dictionary<string, int>
|
||
{
|
||
{ "打捆" ,(int)CategoryInt.打捆},
|
||
{ "装箱" ,(int)CategoryInt.装箱},
|
||
{ "散装" ,(int)CategoryInt.散装},
|
||
};
|
||
|
||
/// <summary>
|
||
/// 未到场
|
||
/// </summary>
|
||
public static int state_0 = 0;
|
||
|
||
/// <summary>
|
||
/// 已发货
|
||
/// </summary>
|
||
public static int state_1 = 1;
|
||
|
||
/// <summary>
|
||
/// 已到场
|
||
/// </summary>
|
||
public static int state_2 = 2;
|
||
|
||
public static Dictionary<string, int> TypeIntMap = new Dictionary<string, int>
|
||
{
|
||
{ "预制组件" ,(int)TypeInt.预制组件},
|
||
{ "预制散件" ,(int)TypeInt.预制散件},
|
||
{ "其他材料" ,(int)TypeInt.其他材料},
|
||
};
|
||
|
||
#endregion Fields
|
||
|
||
#region Enums
|
||
|
||
public enum CategoryInt : int
|
||
{
|
||
打捆 = 10,
|
||
装箱 = 20,
|
||
散装 = 30,
|
||
}
|
||
|
||
public enum TypeInt : int
|
||
{
|
||
预制组件 = 10,
|
||
预制散件 = 20,
|
||
其他材料 = 30,
|
||
}
|
||
|
||
#endregion Enums
|
||
|
||
#region Methods
|
||
|
||
/// <summary>
|
||
/// 新增实体
|
||
/// </summary>
|
||
/// <param name="newtable"></param>
|
||
public static void AddHJGL_PackagingManage(Model.HJGL_PackagingManage newtable)
|
||
{
|
||
Model.HJGL_PackagingManage table = new Model.HJGL_PackagingManage
|
||
{
|
||
PackagingManageId = newtable.PackagingManageId,
|
||
PackagingCode = newtable.PackagingCode,
|
||
ProjectId = newtable.ProjectId,
|
||
PipelineComponentId = newtable.PipelineComponentId,
|
||
StackingPosition = newtable.StackingPosition,
|
||
State = newtable.State,
|
||
ContactName = newtable.ContactName,
|
||
ContactPhone = newtable.ContactPhone,
|
||
Remark = newtable.Remark,
|
||
ReceiveDate = newtable.ReceiveDate,
|
||
ReceiveMan = newtable.ReceiveMan,
|
||
TrainNumber = newtable.TrainNumber,
|
||
TrainNumberId = newtable.TrainNumberId,
|
||
TypeInt = newtable.TypeInt,
|
||
CategoryInt = newtable.CategoryInt,
|
||
CompileMan = newtable.CompileMan,
|
||
CompileDate = newtable.CompileDate
|
||
};
|
||
var db1 = Funs.DB;
|
||
db1.HJGL_PackagingManage.InsertOnSubmit(table);
|
||
db1.SubmitChanges();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 新增或更新包装信息(Id为空则新增,否则更新),返回创建或更新后的Id。
|
||
/// </summary>
|
||
/// <param name="model">包装信息实体,包含包装编号、项目ID、状态等信息</param>
|
||
/// <returns>创建或更新后的包装管理ID</returns>
|
||
/// <exception cref="ArgumentNullException">当model为null时抛出异常</exception>
|
||
public static string AddOrUpdatePackaging(Model.HJGL_PackagingManage model)
|
||
{
|
||
if (model == null)
|
||
throw new ArgumentNullException(nameof(model));
|
||
|
||
if (string.IsNullOrEmpty(model.PackagingManageId))
|
||
{
|
||
// 新增
|
||
model.PackagingManageId = SQLHelper.GetNewID(typeof(Model.HJGL_PackagingManage));
|
||
AddHJGL_PackagingManage(model);
|
||
return model.PackagingManageId;
|
||
}
|
||
else
|
||
{
|
||
// 修改
|
||
var exist = GetHJGL_PackagingManageById(model.PackagingManageId);
|
||
if (exist == null)
|
||
{
|
||
AddHJGL_PackagingManage(model);
|
||
return model.PackagingManageId;
|
||
}
|
||
else
|
||
{
|
||
UpdateHJGL_PackagingManage(model);
|
||
return model.PackagingManageId;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加包装与预制组件关联关系
|
||
/// </summary>
|
||
/// <param name="packagingManageId">包装管理ID</param>
|
||
/// <param name="pipelineComponentId">管道组件ID</param>
|
||
/// <exception cref="Exception">当该预制组件已被包装时抛出异常</exception>
|
||
public static void AddPipelineComponentToPackaging(string packagingManageId, string pipelineComponentId)
|
||
{
|
||
var ComponentModel = BLL.HJGL_PipelineComponentService.GetPipelineComponentById(pipelineComponentId);
|
||
if (ComponentModel != null)
|
||
{
|
||
var model = new Model.HJGL_PackagingManageDetail()
|
||
{
|
||
Id = SQLHelper.GetNewID(),
|
||
PackagingManageId = packagingManageId,
|
||
PipelineId = ComponentModel.PipelineId,
|
||
PipelineComponentId = pipelineComponentId,
|
||
CreateTime = DateTime.Now,
|
||
CreateUser = null,
|
||
};
|
||
HJGLPackagingmanagedetailService.Add(model);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据ID删除包装管理记录
|
||
/// </summary>
|
||
/// <param name="PackagingManageId">包装管理ID</param>
|
||
public static void DeleteHJGL_PackagingManageById(string PackagingManageId)
|
||
{
|
||
var db1 = Funs.DB;
|
||
Model.HJGL_PackagingManage table = db1.HJGL_PackagingManage.FirstOrDefault(x => x.PackagingManageId == PackagingManageId);
|
||
if (table != null)
|
||
{
|
||
db1.HJGL_PackagingManage.DeleteOnSubmit(table);
|
||
db1.SubmitChanges();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除包装与预制组件的关联关系
|
||
/// </summary>
|
||
/// <param name="pipelineComponentId">管道组件ID</param>
|
||
public static void DeletePipelineComponentFromPackaging(string pipelineComponentId)
|
||
{
|
||
HJGLPackagingmanagedetailService.DeleteByPipelineComponentId(pipelineComponentId);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据分类整数值获取分类字符串描述
|
||
/// </summary>
|
||
/// <param name="CategoryInt">分类整数值(10:打捆, 20:装箱, 30:散装)</param>
|
||
/// <returns>分类字符串描述,如果未找到则返回空字符串</returns>
|
||
public static string GetCategoryString(int? CategoryInt)
|
||
{
|
||
return CategoryIntMap.FirstOrDefault(c => c.Value == CategoryInt).Key;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据包装管理ID获取包装信息实体
|
||
/// </summary>
|
||
/// <param name="PackagingManageId">包装管理ID</param>
|
||
/// <returns>包装信息实体,如果未找到则返回null</returns>
|
||
public static Model.HJGL_PackagingManage GetHJGL_PackagingManageById(string PackagingManageId)
|
||
{
|
||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||
{
|
||
return db.HJGL_PackagingManage.FirstOrDefault(x => x.PackagingManageId == PackagingManageId);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 获取包装中所有组件的最早计划开始日期
|
||
/// </summary>
|
||
/// <param name="PackagingManageId">包装管理ID</param>
|
||
/// <returns>最早计划开始日期字符串,如果没有组件则返回空字符串</returns>
|
||
public static string GetMinPlanStartDate(string PackagingManageId)
|
||
{
|
||
string PlanStartDate = "";
|
||
var tb = GetPackagingDetailById(PackagingManageId);
|
||
if (tb == null || tb.Count == 0)
|
||
{
|
||
return PlanStartDate;
|
||
}
|
||
PlanStartDate = tb.OrderBy(x => x.PlanStartDate).FirstOrDefault()?.PlanStartDate.ToString();
|
||
return PlanStartDate;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据项目ID生成新的包装编号
|
||
/// </summary>
|
||
/// <param name="projectid">项目ID</param>
|
||
/// <returns>新包装编号,格式为:项目编号-日期-序号(如:PROJ20241029-001)</returns>
|
||
public static string GetNewPackagingCode(string projectid)
|
||
{
|
||
string code = ProjectService.GetProjectCodeByProjectId(projectid) + "-" + string.Format("{0:yyyyMMdd}", DateTime.Now) + "-";
|
||
|
||
var q = GetPackagingManageList(projectid, code);
|
||
if (q.Total > 0)
|
||
{
|
||
code = code + (q.Total + 1).ToString().PadLeft(3, '0');
|
||
}
|
||
else
|
||
{
|
||
code = code + "001";
|
||
}
|
||
return code;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据项目号获取包装编号历史记录
|
||
/// </summary>
|
||
/// <param name="projectid">项目ID</param>
|
||
/// <returns>该项目的所有包装编号列表(去重)</returns>
|
||
public static List<string> GetPackagingCode(string projectid)
|
||
{
|
||
Model.SGGLDB db = Funs.DB;
|
||
var q = (from x in db.HJGL_PackagingManage
|
||
where x.ProjectId.Contains(projectid)
|
||
select x.PackagingCode).Distinct().ToList();
|
||
return q;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据主键获取装箱明细,用于打印输出
|
||
/// </summary>
|
||
/// <param name="PackagingManageId">包装管理ID</param>
|
||
/// <returns>包装打印输出列表,包含组件信息、单位工程、计划开始日期等</returns>
|
||
/// <remarks>
|
||
/// 根据包装类型返回不同的数据:
|
||
/// - 预制组件:从HJGL_PackagingManageDetail表获取关联的组件ID,查询详细的组件信息
|
||
/// - 预制散件/其他材料:从HJGL_PackagingManageDetail表获取散装材料信息
|
||
/// </remarks>
|
||
public static List<Model.PackagingManagePrintOutput> GetPackagingDetailById(string PackagingManageId)
|
||
{
|
||
var model = GetHJGL_PackagingManageById(PackagingManageId);
|
||
var result = new List<Model.PackagingManagePrintOutput>();
|
||
if (model.TypeInt == (int)HJGLPackagingmanageService.TypeInt.预制组件)
|
||
{
|
||
// 从子表HJGL_PackagingManageDetail中获取关联的组件ID
|
||
var PipelineComponentIdList = (from x in Funs.DB.HJGL_PackagingManageDetail
|
||
where x.PackagingManageId == PackagingManageId
|
||
select x.PipelineComponentId).ToList();
|
||
if (PipelineComponentIdList == null || PipelineComponentIdList.Count == 0)
|
||
return new List<Model.PackagingManagePrintOutput>();
|
||
|
||
var query = from com in Funs.DB.HJGL_Pipeline_Component
|
||
join pipe in Funs.DB.HJGL_Pipeline on com.PipelineId equals pipe.PipelineId into pipeGroup
|
||
from pipe in pipeGroup.DefaultIfEmpty()
|
||
join unitwork in Funs.DB.WBS_UnitWork on pipe.UnitWorkId equals unitwork.UnitWorkId into unitworkGroup
|
||
from unitwork in unitworkGroup.DefaultIfEmpty()
|
||
where PipelineComponentIdList.Contains(com.PipelineComponentId)
|
||
orderby com.PipelineComponentCode
|
||
select new Model.PackagingManagePrintOutput
|
||
{
|
||
PipelineComponentId = com.PipelineComponentId,
|
||
PipelineComponentCode = com.PipelineComponentCode,
|
||
PlanStartDate = pipe != null && pipe.PlanStartDate != null ? pipe.PlanStartDate : DateTime.Now,
|
||
UnitWorkName = unitwork != null ? unitwork.UnitWorkName : "",
|
||
num = "1",
|
||
CU = "个",
|
||
//FlowingSection = pipe != null ? pipe.FlowingSection : ""
|
||
FlowingSection = model.StackingPosition
|
||
};
|
||
result = query.ToList();
|
||
}
|
||
else
|
||
{
|
||
var query = HJGLPackagingmanagedetailService.GetPackagingData(PackagingManageId).ToList();
|
||
var detailList = from x in query
|
||
select new Model.PackagingManagePrintOutput
|
||
{
|
||
PipelineComponentId = x.Id,
|
||
PipelineComponentCode = x.MaterialCode,
|
||
num = x.Number.ToString(),
|
||
CU = x.MaterialUnit,
|
||
UnitWorkName = UnitWorkService.GetNameById( TwOutputdetailService.GetInOutMasterById(x.TwOutputDetailId)?.UnitWorkId ),
|
||
FlowingSection = model.StackingPosition,
|
||
};
|
||
result = detailList.ToList();
|
||
}
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据ID获取包装信息(包含权限验证)
|
||
/// </summary>
|
||
/// <param name="projectId">项目ID,用于权限验证</param>
|
||
/// <param name="personId">人员ID,用于权限验证</param>
|
||
/// <param name="packagingManageId">包装管理ID</param>
|
||
/// <returns>包含包装详情、组件明细和权限信息的包装管理项</returns>
|
||
/// <remarks>
|
||
/// 该方法会:
|
||
/// 1. 查询包装基本信息及关联的项目、接收人信息
|
||
/// 2. 从子表HJGL_PackagingManageDetail中获取关联的组件ID列表
|
||
/// 3. 根据组件ID查询详细的组件信息包括管道、单位工程等
|
||
/// 4. 验证用户是否有操作权限(总包单位或质检工程师)
|
||
/// </remarks>
|
||
public static Model.PackagingManageItem GetPackagingInformationById(string projectId, string personId, string packagingManageId)
|
||
{
|
||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||
{
|
||
PackagingManageItem packagingManageItem = new PackagingManageItem();
|
||
List<PackagingPrepipeItem> packagingPrepipeItem = new List<PackagingPrepipeItem>();
|
||
|
||
var q = (from x in db.HJGL_PackagingManage
|
||
join n in db.Base_Project on x.ProjectId equals n.ProjectId
|
||
join m in db.Person_Persons on x.ReceiveMan equals m.PersonId into tt
|
||
from t in tt.DefaultIfEmpty()
|
||
where x.PackagingManageId == packagingManageId
|
||
select new PackagingManageDetailItem
|
||
{
|
||
PackagingManageId = x.PackagingManageId,
|
||
PackagingCode = x.PackagingCode,
|
||
ProjectName = n.ProjectName,
|
||
ProjectId = x.ProjectId,
|
||
ContactName = x.ContactName,
|
||
ContactPhone = x.ContactPhone,
|
||
StackingPosition = x.StackingPosition,
|
||
State = x.State,
|
||
ReceiveMan = t.PersonName,
|
||
ReceiveDate = string.Format("{0:g}", x.ReceiveDate),
|
||
TrainNumber = x.TrainNumber,
|
||
}).FirstOrDefault();
|
||
|
||
// 从子表HJGL_PackagingManageDetail中根据PackagingManageId获取关联的组件ID
|
||
var PipelineComponentIdList = (from x in db.HJGL_PackagingManageDetail
|
||
where x.PackagingManageId == packagingManageId
|
||
select x.PipelineComponentId).ToList();
|
||
if (PipelineComponentIdList != null && PipelineComponentIdList.Count() > 0)
|
||
{
|
||
packagingPrepipeItem = (from x in db.HJGL_Pipeline_Component
|
||
join y in db.HJGL_Pipeline on x.PipelineId equals y.PipelineId
|
||
join z in db.WBS_UnitWork on y.UnitWorkId equals z.UnitWorkId
|
||
where PipelineComponentIdList.Contains(x.PipelineComponentId)
|
||
select new PackagingPrepipeItem
|
||
{
|
||
PipelineComponentId = x.PipelineComponentId,
|
||
PipelineComponentCode = x.PipelineComponentCode,
|
||
PreUnit = "1/个",
|
||
UnitWorkName = z.UnitWorkName,
|
||
PlanStartDate = string.Format("{0:g}", y.PlanStartDate),
|
||
}).ToList();
|
||
}
|
||
|
||
bool isPower = Person_PersonsService.IsGeneralUnitByPersonId(personId, projectId);
|
||
if (!isPower)
|
||
{
|
||
var roleList = Person_PersonsService.GetRoleListByProjectIdPersonId(projectId, personId);
|
||
if (roleList.Contains(Const.CQEngineer))
|
||
{
|
||
isPower = true;
|
||
}
|
||
}
|
||
packagingManageItem.packagingManageDetailItem = q;
|
||
packagingManageItem.packagingPrepipeItems = packagingPrepipeItem;
|
||
packagingManageItem.isPower = isPower;
|
||
return packagingManageItem;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据车次ID获取包装管理列表
|
||
/// </summary>
|
||
/// <param name="trainNumberId">车次ID</param>
|
||
/// <returns>该车次关联的所有包装管理记录</returns>
|
||
public static List<Model.HJGL_PackagingManage> GetPackagingManage(string trainNumberId)
|
||
{
|
||
Model.SGGLDB db = Funs.DB;
|
||
var q = (from x in db.HJGL_PackagingManage
|
||
where x.TrainNumberId == trainNumberId
|
||
select x).Distinct().ToList();
|
||
return q;
|
||
}
|
||
|
||
public static (List<PackagingManageOutput> Data, int Total) GetPackagingManageList(string projectId, string PackagingCode, int pageIndex = 0, int pageSize = 20)
|
||
{
|
||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||
{
|
||
var baseQuery = (from x in db.HJGL_PackagingManage
|
||
join n in db.Base_Project on x.ProjectId equals n.ProjectId
|
||
join m in db.Person_Persons on x.ReceiveMan equals m.PersonId into tt
|
||
from t in tt.DefaultIfEmpty()
|
||
join train in db.HJGL_TrainNumberManage on x.TrainNumberId equals train.Id into trains
|
||
from train in trains.DefaultIfEmpty()
|
||
where x.ProjectId == projectId
|
||
&& (string.IsNullOrEmpty(PackagingCode) || x.PackagingCode.Contains(PackagingCode))
|
||
select new PackagingManageOutput
|
||
{
|
||
PackagingManageId = x.PackagingManageId,
|
||
PackagingCode = x.PackagingCode,
|
||
ProjectName = n.ProjectName,
|
||
ContactName = train.ContactName,
|
||
ContactPhone = train.ContactPhone,
|
||
DriverName = train.DriverName,
|
||
DriverPhone = train.DriverPhone,
|
||
LicensePlateNumber = train.LicensePlateNumber,
|
||
StackingPosition = x.StackingPosition,
|
||
State = x.State,
|
||
TypeInt = x.TypeInt,
|
||
CategoryInt = x.CategoryInt,
|
||
TypeString = GetTypeString(x.TypeInt),
|
||
CategoryString = GetCategoryString(x.CategoryInt),
|
||
ReceiveMan = train.ContactName,//t.PersonName,
|
||
ReceiveDate = x.ReceiveDate.HasValue ? string.Format("{0:g}", x.ReceiveDate) : "",
|
||
PlanStartDate = GetMinPlanStartDate(x.PackagingManageId),
|
||
TrainNumberOld = x.TrainNumber,
|
||
TrainNumber = train.TrainNumber,
|
||
Code = x.PackagingCode.Substring(0, x.PackagingCode.LastIndexOf("-")).Substring(x.PackagingCode.Substring(0, x.PackagingCode.LastIndexOf("-")).LastIndexOf("-") + 1),
|
||
}).Distinct();
|
||
|
||
var pagedData = baseQuery
|
||
.OrderByDescending(x => x.Code)
|
||
.Skip((pageIndex) * pageSize)
|
||
.Take(pageSize)
|
||
.ToList();
|
||
|
||
// 获取总记录数(延迟计数优化)
|
||
var totalCount = baseQuery.Count();
|
||
return (pagedData, totalCount);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取包装管理列表(带过滤条件)
|
||
/// </summary>
|
||
/// <param name="filter">过滤条件</param>
|
||
/// <param name="pageIndex">页码</param>
|
||
/// <param name="pageSize">页大小</param>
|
||
/// <param name="totalCount">总记录数</param>
|
||
/// <returns>包装管理列表</returns>
|
||
public static List<Model.PackagingManageDetailItem> GetPackagingManageList(PackagingManageInput filter, int pageIndex, int pageSize, out int totalCount)
|
||
{
|
||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||
{
|
||
// base join query to include project and receive person
|
||
var baseQuery = from x in db.HJGL_PackagingManage
|
||
join n in db.Base_Project on x.ProjectId equals n.ProjectId
|
||
join m in db.Person_Persons on x.ReceiveMan equals m.PersonId into tt
|
||
from t in tt.DefaultIfEmpty()
|
||
join train in db.HJGL_TrainNumberManage on x.TrainNumberId equals train.Id into trains
|
||
from train in trains.DefaultIfEmpty()
|
||
select new { x, n, t , train };
|
||
|
||
if (filter != null)
|
||
{
|
||
if (!string.IsNullOrEmpty(filter.PackagingManageId))
|
||
{
|
||
baseQuery = baseQuery.Where(z => z.x.PackagingManageId == filter.PackagingManageId);
|
||
}
|
||
if (!string.IsNullOrEmpty(filter.PackagingCode))
|
||
{
|
||
baseQuery = baseQuery.Where(z => z.x.PackagingCode.Contains(filter.PackagingCode));
|
||
}
|
||
if (!string.IsNullOrEmpty(filter.ProjectId))
|
||
{
|
||
baseQuery = baseQuery.Where(z => z.x.ProjectId == filter.ProjectId);
|
||
}
|
||
if (!string.IsNullOrEmpty(filter.ProjectName))
|
||
{
|
||
baseQuery = baseQuery.Where(z => z.n.ProjectName.Contains(filter.ProjectName));
|
||
}
|
||
if (!string.IsNullOrEmpty(filter.ContactName))
|
||
{
|
||
baseQuery = baseQuery.Where(z => z.x.ContactName.Contains(filter.ContactName));
|
||
}
|
||
if (!string.IsNullOrEmpty(filter.ContactPhone))
|
||
{
|
||
baseQuery = baseQuery.Where(z => z.x.ContactPhone.Contains(filter.ContactPhone));
|
||
}
|
||
if (!string.IsNullOrEmpty(filter.StackingPosition))
|
||
{
|
||
baseQuery = baseQuery.Where(z => z.x.StackingPosition.Contains(filter.StackingPosition));
|
||
}
|
||
if (filter.State != null)
|
||
{
|
||
baseQuery = baseQuery.Where(z => z.x.State == filter.State);
|
||
}
|
||
if (!string.IsNullOrEmpty(filter.ReceiveMan))
|
||
{
|
||
baseQuery = baseQuery.Where(z => z.train.ContactName == filter.ReceiveMan || (z.train != null && z.train.ContactName.Contains(filter.ReceiveMan)));
|
||
}
|
||
if (!string.IsNullOrEmpty(filter.ReceiveDate))
|
||
{
|
||
DateTime dt;
|
||
if (DateTime.TryParse(filter.ReceiveDate, out dt))
|
||
{
|
||
var start = dt.Date;
|
||
var end = start.AddDays(1);
|
||
baseQuery = baseQuery.Where(z => z.x.ReceiveDate != null && z.x.ReceiveDate >= start && z.x.ReceiveDate < end);
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(filter.TrainNumberId))
|
||
{
|
||
baseQuery = baseQuery.Where(z => z.train.Id != null && z.train.Id.Contains(filter.TrainNumberId));
|
||
}
|
||
// 是否关联车次筛选
|
||
if (filter.HasTrainNumber.HasValue)
|
||
{
|
||
if (filter.HasTrainNumber.Value)
|
||
{
|
||
// 已关联车次:TrainNumberId 不为空
|
||
baseQuery = baseQuery.Where(z => z.x.TrainNumberId != null && z.x.TrainNumberId != "");
|
||
}
|
||
else
|
||
{
|
||
// 未关联车次:TrainNumberId 为空
|
||
baseQuery = baseQuery.Where(z => z.x.TrainNumberId == null || z.x.TrainNumberId == "");
|
||
}
|
||
}
|
||
}
|
||
|
||
baseQuery = baseQuery.OrderByDescending(z => (z.x.ReceiveDate ?? DateTime.MinValue)).ThenBy(z => z.x.PackagingCode);
|
||
|
||
var q = (from z in baseQuery
|
||
select new PackagingManageDetailItem
|
||
{
|
||
PackagingManageId = z.x.PackagingManageId,
|
||
PackagingCode = z.x.PackagingCode,
|
||
ProjectName = z.n.ProjectName,
|
||
ContactName = z.x.ContactName,
|
||
ContactPhone = z.x.ContactPhone,
|
||
StackingPosition = z.x.StackingPosition,
|
||
State = z.x.State,
|
||
ReceiveMan = z.train.ContactName,
|
||
ReceiveDate = string.Format("{0:g}", z.x.ReceiveDate),
|
||
TrainNumber = z.train.TrainNumber,
|
||
ComponentCount = db.HJGL_PackagingManageDetail.Count(d => d.PackagingManageId == z.x.PackagingManageId),
|
||
CategoryInt = z.x.CategoryInt,
|
||
CategoryString = z.x.CategoryInt == 10 ? "打捆" : (z.x.CategoryInt == 20 ? "装箱" : (z.x.CategoryInt == 30 ? "散装" : ""))
|
||
}).Distinct();
|
||
|
||
totalCount = q.Count();
|
||
|
||
if (pageIndex <= 0) pageIndex = 1;
|
||
if (pageSize <= 0) pageSize = 20;
|
||
|
||
return q.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 包装到场验收,将包装状态更新为已到场并记录验收人和验收时间
|
||
/// </summary>
|
||
/// <param name="packagingManageId">包装管理ID</param>
|
||
/// <param name="PersonId">验收人员ID</param>
|
||
/// <remarks>
|
||
/// 该方法会将包装状态更新为已到场(state_2),并设置接收人和接收时间
|
||
/// </remarks>
|
||
public static void GetPackingInfoConfirmArrival(string packagingManageId, string PersonId)
|
||
{
|
||
var q = GetHJGL_PackagingManageById(packagingManageId);
|
||
if (q != null)
|
||
{
|
||
q.State = state_2;
|
||
q.ReceiveMan = PersonId;
|
||
q.ReceiveDate = DateTime.Now;
|
||
UpdateHJGL_PackagingManage(q);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 保存包装信息(组件明细),将组件关联到包装并更新明细表
|
||
/// </summary>
|
||
/// <param name="packagingManageId">包装管理ID</param>
|
||
/// <param name="PipelineComponentIds">组件ID集合,多个ID用逗号分隔</param>
|
||
/// <remarks>
|
||
/// 该方法会:
|
||
/// 1. 获取现有的包装明细记录中的组件ID
|
||
/// 2. 合并新旧组件ID(去重)
|
||
/// 3. 根据组件ID查询对应的管道信息
|
||
/// 4. 删除原有的包装明细记录
|
||
/// 5. 批量插入新的包装明细记录到HJGL_PackagingManageDetail表
|
||
/// </remarks>
|
||
public static void getSavePackagingInformationById(string packagingManageId, string PipelineComponentIds)
|
||
{
|
||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||
{
|
||
// 获取现有的组件ID列表
|
||
var existingComponentIds = (from x in db.HJGL_PackagingManageDetail
|
||
where x.PackagingManageId == packagingManageId
|
||
select x.PipelineComponentId).ToList();
|
||
|
||
// 合并新旧组件ID(去重)
|
||
HashSet<string> allComponentIds = new HashSet<string>(existingComponentIds);
|
||
if (!string.IsNullOrEmpty(PipelineComponentIds))
|
||
{
|
||
string[] newIds = PipelineComponentIds.Split(',');
|
||
foreach (var id in newIds)
|
||
{
|
||
if (!string.IsNullOrEmpty(id))
|
||
{
|
||
allComponentIds.Add(id);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 创建新的包装明细记录
|
||
var newDetailList = new List<Model.HJGL_PackagingManageDetail>();
|
||
foreach (var item in allComponentIds)
|
||
{
|
||
var ComponentModel = BLL.HJGL_PipelineComponentService.GetPipelineComponentById(item);
|
||
if (ComponentModel != null)
|
||
{
|
||
var model = new Model.HJGL_PackagingManageDetail()
|
||
{
|
||
Id = SQLHelper.GetNewID(),
|
||
PackagingManageId = packagingManageId,
|
||
PipelineId = ComponentModel.PipelineId,
|
||
PipelineComponentId = item,
|
||
CreateTime = DateTime.Now,
|
||
};
|
||
newDetailList.Add(model);
|
||
}
|
||
}
|
||
|
||
// 更新数据库:先删除旧记录,再插入新记录
|
||
HJGLPackagingmanagedetailService.DeleteByPackagingManageId(packagingManageId);
|
||
if (newDetailList.Count > 0)
|
||
{
|
||
HJGLPackagingmanagedetailService.AddBulk(newDetailList);
|
||
}
|
||
|
||
// 可选:同时更新主表的PipelineComponentId字段以保持兼容性
|
||
var table = db.HJGL_PackagingManage.FirstOrDefault(x => x.PackagingManageId == packagingManageId);
|
||
if (table != null)
|
||
{
|
||
table.PipelineComponentId = string.Join(",", allComponentIds);
|
||
UpdateHJGL_PackagingManage(table);
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取包装状态下拉框选项
|
||
/// </summary>
|
||
/// <returns>包装状态列表,包含状态文本和值的映射关系</returns>
|
||
public static ListItem[] GetState()
|
||
{
|
||
ListItem[] list = new ListItem[3];
|
||
list[0] = new ListItem("预出库", state_0.ToString());
|
||
list[1] = new ListItem("已出库", state_1.ToString());
|
||
list[2] = new ListItem("已到场", state_2.ToString());
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据类型整数值获取类型字符串描述
|
||
/// </summary>
|
||
/// <param name="TypeInt">类型整数值(10:预制组件, 20:预制散件, 30:其他材料)</param>
|
||
/// <returns>类型字符串描述,如果未找到则返回空字符串</returns>
|
||
public static string GetTypeString(int? TypeInt)
|
||
{
|
||
return TypeIntMap.FirstOrDefault(c => c.Value == TypeInt).Key;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始化包装编号下拉框
|
||
/// </summary>
|
||
/// <param name="dropName">下拉框控件名称</param>
|
||
/// <param name="projectid">项目ID</param>
|
||
/// <param name="isShowPlease">是否显示"请选择"选项</param>
|
||
public static void InitPipelineDownList(FineUIPro.DropDownList dropName, string projectid, bool isShowPlease)
|
||
{
|
||
dropName.DataValueField = "string";
|
||
dropName.DataTextField = "string";
|
||
dropName.DataSource = GetPackagingCode(projectid);
|
||
dropName.DataBind();
|
||
if (isShowPlease)
|
||
{
|
||
Funs.FineUIPleaseSelect(dropName);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 形成出库单,将包装状态从未出库更新为已出库
|
||
/// </summary>
|
||
/// <param name="PackagingManageId">包装管理ID</param>
|
||
/// <remarks>仅当包装状态为预出库(state_0)时才允许更新为已出库(state_1)</remarks>
|
||
public static void PutOutOrder(string PackagingManageId)
|
||
{
|
||
var model = GetHJGL_PackagingManageById(PackagingManageId);
|
||
if (model.State == state_0)
|
||
{
|
||
model.State = state_1;
|
||
UpdateHJGL_PackagingManage(model);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新包装管理信息
|
||
/// </summary>
|
||
/// <param name="newtable">包含更新后信息的包装管理实体</param>
|
||
public static void UpdateHJGL_PackagingManage(Model.HJGL_PackagingManage newtable)
|
||
{
|
||
var db1 = Funs.DB;
|
||
Model.HJGL_PackagingManage table = db1.HJGL_PackagingManage.FirstOrDefault(x => x.PackagingManageId == newtable.PackagingManageId);
|
||
if (table != null)
|
||
{
|
||
table.PackagingManageId = newtable.PackagingManageId;
|
||
table.PackagingCode = newtable.PackagingCode;
|
||
table.ProjectId = newtable.ProjectId;
|
||
table.PipelineComponentId = newtable.PipelineComponentId;
|
||
table.StackingPosition = newtable.StackingPosition;
|
||
table.State = newtable.State;
|
||
table.ContactName = newtable.ContactName;
|
||
table.ContactPhone = newtable.ContactPhone;
|
||
table.Remark = newtable.Remark;
|
||
table.ReceiveMan = newtable.ReceiveMan;
|
||
table.ReceiveDate = newtable.ReceiveDate;
|
||
table.TrainNumber = newtable.TrainNumber;
|
||
table.TrainNumberId = newtable.TrainNumberId;
|
||
table.TypeInt = newtable.TypeInt;
|
||
table.CategoryInt = newtable.CategoryInt;
|
||
db1.SubmitChanges();
|
||
}
|
||
}
|
||
#endregion Methods
|
||
}
|
||
} |