2026-05-18 21:28:56 +08:00
|
|
|
using FineUIPro;
|
|
|
|
|
using Model;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2026-08-12 23:10:22 +08:00
|
|
|
using System;
|
2026-05-18 21:28:56 +08:00
|
|
|
|
|
|
|
|
namespace BLL
|
|
|
|
|
{
|
|
|
|
|
public static class TwInputdetailBarCodeService
|
|
|
|
|
{
|
2026-08-12 23:10:22 +08:00
|
|
|
private static readonly object BarCodeLock = new object();
|
|
|
|
|
|
2026-05-18 21:28:56 +08:00
|
|
|
public static int Count
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IEnumerable GetListData(Tw_InputDetailBarCodeOutput table, Grid grid1)
|
|
|
|
|
{
|
|
|
|
|
List<Tw_InputDetailBarCodeOutput> list = GetListData(table);
|
|
|
|
|
Count = list.Count;
|
|
|
|
|
if (Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return list.Skip(grid1.PageSize * grid1.PageIndex).Take(grid1.PageSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<Tw_InputDetailBarCodeOutput> GetListData(Tw_InputDetailBarCodeOutput table)
|
|
|
|
|
{
|
|
|
|
|
var q = from x in Funs.DB.Tw_InputDetailBarCode
|
|
|
|
|
join master in Funs.DB.Tw_InputMaster on x.InputMasterId equals master.Id into masters
|
|
|
|
|
from master in masters.DefaultIfEmpty()
|
|
|
|
|
join mat in Funs.DB.HJGL_MaterialCodeLib on x.MaterialCode equals mat.MaterialCode into mats
|
|
|
|
|
from mat in mats.DefaultIfEmpty()
|
|
|
|
|
where
|
|
|
|
|
(string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) &&
|
|
|
|
|
(string.IsNullOrEmpty(table.InputDetailId) || x.InputDetailId.Contains(table.InputDetailId)) &&
|
|
|
|
|
(string.IsNullOrEmpty(table.InputMasterId) || x.InputMasterId.Contains(table.InputMasterId)) &&
|
|
|
|
|
(string.IsNullOrEmpty(table.MaterialCode) || x.MaterialCode.Contains(table.MaterialCode))
|
|
|
|
|
orderby master.CusBillCode, x.MaterialCode, x.Id
|
|
|
|
|
select new Tw_InputDetailBarCodeOutput
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
InputDetailId = x.InputDetailId,
|
|
|
|
|
InputMasterId = x.InputMasterId,
|
|
|
|
|
CusBillCode = master.CusBillCode,
|
|
|
|
|
MaterialCode = x.MaterialCode,
|
2026-05-27 17:57:11 +08:00
|
|
|
Code = mat.Code,
|
|
|
|
|
HeatNo = mat.HeatNo,
|
|
|
|
|
BatchNo = mat.BatchNo,
|
2026-05-18 21:28:56 +08:00
|
|
|
MaterialName = mat.MaterialName,
|
|
|
|
|
MaterialDef = mat.MaterialDef,
|
2026-06-17 14:22:06 +08:00
|
|
|
MaterialSpec = mat.MaterialSpec,
|
|
|
|
|
MaterialUnit = mat.MaterialUnit,
|
2026-08-12 23:10:22 +08:00
|
|
|
BarCode = x.BarCode,
|
|
|
|
|
Quantity = x.Quantity
|
2026-05-18 21:28:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return q.ToList();
|
|
|
|
|
}
|
2026-07-07 10:40:21 +08:00
|
|
|
public static List<Tw_InputDetailBarCodeOutput> GetListData(string materialCode)
|
|
|
|
|
{
|
2026-08-12 23:10:22 +08:00
|
|
|
var q = from detailBarCode in Funs.DB.Tw_InputDetailBarCode
|
|
|
|
|
join mat in Funs.DB.HJGL_MaterialCodeLib on detailBarCode.MaterialCode equals mat.MaterialCode
|
|
|
|
|
where detailBarCode.MaterialCode == materialCode
|
|
|
|
|
orderby detailBarCode.BarCode
|
2026-07-07 10:40:21 +08:00
|
|
|
select new Tw_InputDetailBarCodeOutput
|
|
|
|
|
{
|
2026-08-12 23:10:22 +08:00
|
|
|
Id = detailBarCode.Id,
|
|
|
|
|
InputDetailId = detailBarCode.InputDetailId,
|
|
|
|
|
InputMasterId = detailBarCode.InputMasterId,
|
2026-07-07 10:40:21 +08:00
|
|
|
MaterialCode = mat.MaterialCode,
|
|
|
|
|
Code = mat.Code,
|
|
|
|
|
HeatNo = mat.HeatNo,
|
|
|
|
|
BatchNo = mat.BatchNo,
|
|
|
|
|
MaterialName = mat.MaterialName,
|
|
|
|
|
MaterialDef = mat.MaterialDef,
|
|
|
|
|
MaterialSpec = mat.MaterialSpec,
|
|
|
|
|
MaterialUnit = mat.MaterialUnit,
|
2026-08-12 23:10:22 +08:00
|
|
|
BarCode = detailBarCode.BarCode,
|
|
|
|
|
Quantity = detailBarCode.Quantity
|
2026-07-07 10:40:21 +08:00
|
|
|
};
|
2026-05-18 21:28:56 +08:00
|
|
|
|
2026-07-07 10:40:21 +08:00
|
|
|
return q.ToList();
|
|
|
|
|
}
|
2026-05-18 21:28:56 +08:00
|
|
|
public static void AddByInputDetail(Tw_InputMaster inputMaster, Tw_InputDetail inputDetail)
|
|
|
|
|
{
|
|
|
|
|
if (inputMaster == null || inputDetail == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (IsExist(inputDetail.Id))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-12 23:10:22 +08:00
|
|
|
lock (BarCodeLock)
|
2026-05-18 21:28:56 +08:00
|
|
|
{
|
2026-08-12 23:10:22 +08:00
|
|
|
if (IsExist(inputDetail.Id))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string id = SQLHelper.GetNewID();
|
|
|
|
|
bool isMeter = IsMeterMaterial(inputDetail.MaterialCode);
|
|
|
|
|
Tw_InputDetailBarCode table = new Tw_InputDetailBarCode
|
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
InputDetailId = inputDetail.Id,
|
|
|
|
|
InputMasterId = inputMaster.Id,
|
|
|
|
|
MaterialCode = inputDetail.MaterialCode,
|
|
|
|
|
// 按米计量的管材由扫码后录入实际长度,其他材料每个条码固定代表1件。
|
|
|
|
|
Quantity = isMeter ? (decimal?)null : 1m,
|
|
|
|
|
BarCode = isMeter ? BuildNextBarCode(inputDetail.MaterialCode) : inputDetail.MaterialCode
|
|
|
|
|
};
|
|
|
|
|
Funs.DB.Tw_InputDetailBarCode.InsertOnSubmit(table);
|
|
|
|
|
Funs.DB.SubmitChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 为指定管材入库明细生成下一个流水条码。
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string AddNextByInputDetailId(string inputDetailId)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(inputDetailId))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("入库明细不能为空。");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lock (BarCodeLock)
|
|
|
|
|
{
|
|
|
|
|
var inputDetail = Funs.DB.Tw_InputDetail.FirstOrDefault(x => x.Id == inputDetailId);
|
|
|
|
|
if (inputDetail == null)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("未找到入库明细。");
|
|
|
|
|
}
|
|
|
|
|
if (!IsMeterMaterial(inputDetail.MaterialCode))
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("只有单位为米的管材可以生成新条码。");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string barCode = BuildNextBarCode(inputDetail.MaterialCode);
|
|
|
|
|
Funs.DB.Tw_InputDetailBarCode.InsertOnSubmit(new Tw_InputDetailBarCode
|
|
|
|
|
{
|
|
|
|
|
Id = SQLHelper.GetNewID(),
|
|
|
|
|
InputDetailId = inputDetail.Id,
|
|
|
|
|
InputMasterId = inputDetail.InputMasterId,
|
|
|
|
|
MaterialCode = inputDetail.MaterialCode,
|
|
|
|
|
BarCode = barCode,
|
|
|
|
|
Quantity = null
|
|
|
|
|
});
|
|
|
|
|
Funs.DB.SubmitChanges();
|
|
|
|
|
return barCode;
|
|
|
|
|
}
|
2026-05-18 21:28:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void DeleteByInputMasterId(string inputMasterId)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(inputMasterId))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = Funs.DB.Tw_InputDetailBarCode.Where(x => x.InputMasterId == inputMasterId).ToList();
|
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
Funs.DB.Tw_InputDetailBarCode.DeleteAllOnSubmit(list);
|
|
|
|
|
Funs.DB.SubmitChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void DeleteByInputDetailId(string inputDetailId)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(inputDetailId))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = Funs.DB.Tw_InputDetailBarCode.Where(x => x.InputDetailId == inputDetailId).ToList();
|
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
Funs.DB.Tw_InputDetailBarCode.DeleteAllOnSubmit(list);
|
|
|
|
|
Funs.DB.SubmitChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool IsExist(string inputDetailId)
|
|
|
|
|
{
|
|
|
|
|
return Funs.DB.Tw_InputDetailBarCode.Any(x => x.InputDetailId == inputDetailId);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 入库材料条形码生成规则,后续调整条形码内容只需修改此方法。
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string BuildBarCode(Tw_InputMaster inputMaster, Tw_InputDetail inputDetail, string barCodeDetailId)
|
|
|
|
|
{
|
2026-08-12 23:10:22 +08:00
|
|
|
if (inputDetail == null)
|
|
|
|
|
{
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
return IsMeterMaterial(inputDetail.MaterialCode)
|
|
|
|
|
? BuildNextBarCode(inputDetail.MaterialCode)
|
|
|
|
|
: inputDetail.MaterialCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool IsMeterMaterial(string materialCode)
|
|
|
|
|
{
|
|
|
|
|
string materialUnit = Funs.DB.HJGL_MaterialCodeLib
|
|
|
|
|
.Where(x => x.MaterialCode == materialCode)
|
|
|
|
|
.Select(x => x.MaterialUnit)
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
return string.Equals((materialUnit ?? string.Empty).Trim(), "米", StringComparison.Ordinal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string BuildNextBarCode(string materialCode)
|
|
|
|
|
{
|
|
|
|
|
string prefix = materialCode + "-";
|
|
|
|
|
int maxSequence = 0;
|
|
|
|
|
var barCodes = Funs.DB.Tw_InputDetailBarCode
|
|
|
|
|
.Where(x => x.MaterialCode == materialCode && x.BarCode.StartsWith(prefix))
|
|
|
|
|
.Select(x => x.BarCode)
|
|
|
|
|
.ToList();
|
|
|
|
|
foreach (string barCode in barCodes)
|
|
|
|
|
{
|
|
|
|
|
int sequence;
|
|
|
|
|
if (int.TryParse(barCode.Substring(prefix.Length), out sequence) && sequence > maxSequence)
|
|
|
|
|
{
|
|
|
|
|
maxSequence = sequence;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return prefix + (maxSequence + 1).ToString("D3");
|
2026-05-18 21:28:56 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|