You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1003 lines
34 KiB

1 year ago
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
//using ChangKeTec.Utils;
using ChangKeTec.Wms.Models.Enums;
//using ChangKeTec.Wms.Models.Power;
using ChangKeTec.Wms.Models.Wms;
using CK.SCP.Models;
using CK.SCP.Utils;
using CK.SCP.Models.Enums;
namespace ChangKeTec.Wms.Models
{
public static class WmsCache
{
private static readonly WmsEntities WmsDb = EntitiesFactory.CreateWmsInstance();
#region Private
private static WmsConfig _config;
private static List<TA_PART> _partList;
private static List<TA_WORKLINE> _worklineList;
private static List<TA_BILLTYPE> _billTypeList;
private static List<TA_STORE_WHSE> _whseList;
private static List<TT_PART_GROUP> _partGroupList;
private static List<TA_STORE_GROUP> _storeGroupList;
private static List<TA_STORE_LOCATION> _locList;
private static List<TA_CELL> _cellList;
private static List<TA_CUST_PART> _custPartList;
private static List<TA_VEND_PART> _vendPartList;
private static List<TA_CUSTOMER> _custList;
private static List<TA_VENDER> _vendList;
private static List<TT_SHIFT> _shiftList;
private static List<TA_TEAM> _teamList;
// private static List<TA_MACHINE> _machineList;
private static List<TT_UNIT> _unitList;
private static List<TT_CURRENCY> _currencyList;
private static List<TT_PROJECT> _projectList;
private static List<TA_BOM> _bomList;
private static List<TA_CUST_BOM> _custBomList;
private static List<TA_ERP_LOC> _erpLocList;
private static List<TA_SALE_PRICE> _salePriceList;
private static List<TA_PURCHASE_PRICE> _purchasePriceList;
// private static List<TT_SUB_BILLTYPE> _subBilltypeList;
private static List<TA_OTHER_INOUT_REASON> _otherInoutReasonList;
private static List<TT_FAIL_TYPE> _failTypeList;
private static List<TT_CONTAINER_TYPE> _containerTypeList;
private static List<TA_DELIVER_DEST> _deliverdestList;
private static List<TA_DEST_LOC> _destlocList;
private static List<TM_CQBMPT_PART_RELATION> _cqBmptPartRelationList;
private static List<TM_CQBMPT_PAINT_FAILEDREASON> _cqBmptFailedReasonList;
private static List<TA_PARTGROUP_INSPECTER> _partGroupInsList;
private static List<TA_PAYMENT_DAY> _paymentDayList;
#endregion
public static WmsConfig Config
{
get { return _config ?? (_config = GetConfig(WmsDb)); }
set { _config = value; }
}
public static List<TA_CONFIG> GetDbConfigList(WmsEntities db)
{
return db.TA_CONFIG.OrderByDescending(p => p.UID).ToList();
}
private static WmsConfig GetConfig(WmsEntities db)
{
var config = new WmsConfig();
var peroperties = config.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
var configList = GetDbConfigList(db);
foreach (var pi in peroperties)
{
var piName = pi.Name.ToUpper();
foreach (var cfg in configList)
{
if (cfg.ParamName != piName) continue;
var value = ListHelper.ConvertToType(cfg.ParamValue, pi.PropertyType);
if (!pi.CanWrite) continue;
try
{
pi.SetValue(config, value, null);
break;
}
catch (Exception ex)
{
MessageHelper.ShowEx(ex);
throw;
}
}
}
return config;
}
private static void SetConfig(WmsEntities db, WmsConfig config)
{
var peroperties = config.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
var configList = GetDbConfigList(db);
foreach (var pi in peroperties)
{
var piName = pi.Name.ToUpper();
if (configList.Any(p => p.ParamName.ToUpper() == piName)) continue;
var cfg = new TA_CONFIG
{
ParamName = piName,
ParamValue = pi.GetValue(Config, null).ToString(),
State = 1,
Remark = piName,
};
db.TA_CONFIG.Add(cfg);
}
EntitiesFactory.SaveDb(db);
}
#region Public
public static List<TA_PART> PartList
{
get
{
if (_partList == null || _partList.Count == 0)
{
_partList = WmsDb.TA_PART.Where(p=>p.PartKind!="AST").ToList();
}
return _partList;
}
set { _partList = value; }
}
public static List<TA_WORKLINE> WorklineList
{
get
{
if (_worklineList == null || _worklineList.Count == 0)
{
_worklineList = WmsDb.TA_WORKLINE.ToList();
}
return _worklineList;
}
set { _worklineList = value; }
}
public static List<TA_BILLTYPE> BillTypeList
{
get
{
if (_billTypeList == null || _billTypeList.Count == 0)
{
_billTypeList = WmsDb.TA_BILLTYPE.ToList();
}
return _billTypeList;
}
set { _billTypeList = value; }
}
public static List<TA_STORE_WHSE> WhseList
{
get
{
if (_whseList == null || _whseList.Count == 0)
{
_whseList = WmsDb.TA_STORE_WHSE.ToList();
}
return _whseList;
}
set { _whseList = value; }
}
public static List<EnumItem> AreaList => EnumHelper.EnumToList<EnumStoreArea>();
public static List<TT_PART_GROUP> PartGroupList
{
get
{
if (_partGroupList == null || _partGroupList.Count == 0)
{
_partGroupList = WmsDb.TT_PART_GROUP.ToList();
}
return _partGroupList;
}
set { _partGroupList = value; }
}
public static List<TA_STORE_GROUP> StoreGroupList
{
get
{
if (_storeGroupList == null || _storeGroupList.Count == 0)
{
_storeGroupList = WmsDb.TA_STORE_GROUP.ToList();
}
return _storeGroupList;
}
set { _storeGroupList = value; }
}
public static List<TA_STORE_LOCATION> LocList
{
get
{
if (_locList == null || _locList.Count == 0)
{
_locList = WmsDb.TA_STORE_LOCATION.ToList();
}
return _locList;
}
set { _locList = value; }
}
public static List<TA_CELL> CellList
{
get
{
if (_cellList == null || _cellList.Count == 0)
{
_cellList = WmsDb.TA_CELL.ToList();
}
return _cellList;
}
set { _cellList = value; }
}
public static List<TA_CUST_PART> CustPartList
{
get
{
if (_custPartList == null || _custPartList.Count == 0)
{
_custPartList = WmsDb.TA_CUST_PART.ToList();
}
return _custPartList;
}
set { _custPartList = value; }
}
public static List<TA_VEND_PART> VendPartList
{
get
{
if (_vendPartList == null || _vendPartList.Count == 0)
{
_vendPartList = WmsDb.TA_VEND_PART.ToList();
}
return _vendPartList;
}
set { _vendPartList = value; }
}
public static List<TA_CUSTOMER> CustomerList
{
get
{
if (_custList == null || _custList.Count == 0)
{
_custList = WmsDb.TA_CUSTOMER.ToList();
}
return _custList;
}
set { _custList = value; }
}
public static List<TA_VENDER> VenderList
{
get
{
if (_vendList == null || _vendList.Count == 0)
{
_vendList = WmsDb.TA_VENDER.ToList();
}
return _vendList;
}
set { _vendList = value; }
}
public static List<TT_SHIFT> ShiftList
{
get
{
if (_shiftList == null || _shiftList.Count == 0)
{
_shiftList = WmsDb.TT_SHIFT.ToList();
}
return _shiftList;
}
set { _shiftList = value; }
}
public static List<TA_TEAM> TeamList
{
get
{
if (_teamList == null || _teamList.Count == 0)
{
_teamList = WmsDb.TA_TEAM.ToList();
}
return _teamList;
}
set { _teamList = value; }
}
public static List<TT_UNIT> UnitList
{
get
{
if (_unitList == null || _unitList.Count == 0)
{
_unitList = WmsDb.TT_UNIT.ToList();
}
return _unitList;
}
set { _unitList = value; }
}
public static List<TT_CURRENCY> CurrencyList
{
get
{
if (_currencyList == null || _currencyList.Count == 0)
{
_currencyList = WmsDb.TT_CURRENCY.ToList();
}
return _currencyList;
}
set { _currencyList = value; }
}
public static List<TT_PROJECT> ProjectList
{
get
{
if (_projectList == null || _projectList.Count == 0)
{
_projectList = WmsDb.TT_PROJECT.ToList();
}
return _projectList;
}
set { _projectList = value; }
}
public static List<TA_BOM> BomList
{
get
{
if (_bomList == null || _bomList.Count == 0)
{
_bomList = WmsDb.TA_BOM.ToList();
}
return _bomList;
}
}
public static List<TA_CUST_BOM> CustBomList
{
get
{
if (_custBomList == null || _custBomList.Count == 0)
{
_custBomList = WmsDb.TA_CUST_BOM.ToList();
}
return _custBomList;
}
set { _custBomList = value; }
}
public static List<TA_ERP_LOC> ErpLocList
{
get
{
if (_erpLocList == null || _erpLocList.Count == 0)
{
_erpLocList = WmsDb.TA_ERP_LOC.ToList();
}
return _erpLocList;
}
set { _erpLocList = value; }
}
public static List<TA_SALE_PRICE> SalePriceList
{
get
{
if (_salePriceList == null || _salePriceList.Count == 0)
{
_salePriceList = WmsDb.TA_SALE_PRICE.ToList();
}
return _salePriceList;
}
set { _salePriceList = value; }
}
public static List<TA_PURCHASE_PRICE> PurchasePriceList
{
get
{
if (_purchasePriceList == null || _purchasePriceList.Count == 0)
{
_purchasePriceList = WmsDb.TA_PURCHASE_PRICE.ToList();
}
return _purchasePriceList;
}
set { _purchasePriceList = value; }
}
public static List<TA_DELIVER_DEST> DeliverDestList
{
get
{
if (_deliverdestList == null || _deliverdestList.Count == 0)
{
_deliverdestList = WmsDb.TA_DELIVER_DEST.ToList();
}
return _deliverdestList;
}
}
public static List<TA_OTHER_INOUT_REASON> OtherInoutReasonList
{
get
{
if (_otherInoutReasonList == null || _otherInoutReasonList.Count == 0)
{
_otherInoutReasonList = WmsDb.TA_OTHER_INOUT_REASON.Where(p => p.State == (int)DataState.Enabled).ToList();
}
return _otherInoutReasonList;
}
set { _otherInoutReasonList = value; }
}
public static List<TT_FAIL_TYPE> FailTypeList
{
get
{
if (_failTypeList == null || _failTypeList.Count == 0)
{
_failTypeList = WmsDb.TT_FAIL_TYPE.ToList();
}
return _failTypeList;
}
set { _failTypeList = value; }
}
public static List<TT_CONTAINER_TYPE> ContainerTypeList
{
get
{
if (_containerTypeList == null || _containerTypeList.Count == 0)
{
_containerTypeList = WmsDb.TT_CONTAINER_TYPE.ToList();
}
return _containerTypeList;
}
set { _containerTypeList = value; }
}
public static List<TA_DEST_LOC> DestLocList
{
get
{
if (_destlocList == null || _destlocList.Count == 0)
{
_destlocList = WmsDb.TA_DEST_LOC.ToList();
}
return _destlocList;
}
}
public static List<TM_CQBMPT_PART_RELATION> CqBmptPartRelationList
{
get
{
if (_cqBmptPartRelationList == null || _cqBmptPartRelationList.Count == 0)
{
_cqBmptPartRelationList = WmsDb.TM_CQBMPT_PART_RELATION.ToList();
}
return _cqBmptPartRelationList;
}
set { _cqBmptPartRelationList = value; }
}
public static List<TM_CQBMPT_PAINT_FAILEDREASON> CqBmptFailedReasonList
{
get
{
if (_cqBmptFailedReasonList == null || _cqBmptFailedReasonList.Count == 0)
{
_cqBmptFailedReasonList = WmsDb.TM_CQBMPT_PAINT_FAILEDREASON.ToList();
}
return _cqBmptFailedReasonList;
}
set { _cqBmptFailedReasonList = value; }
}
public static List<TA_PARTGROUP_INSPECTER> PartGroupInsList
{
get
{
if (_partGroupInsList == null || _partGroupInsList.Count == 0)
{
_partGroupInsList = WmsDb.TA_PARTGROUP_INSPECTER.ToList();
}
return _partGroupInsList;
}
}
public static List<TA_PAYMENT_DAY> PaymentDayList
{
get
{
if (_paymentDayList == null || _paymentDayList.Count == 0)
{
_paymentDayList = WmsDb.TA_PAYMENT_DAY.ToList();
}
return _paymentDayList;
}
set { _paymentDayList = value; }
}
#endregion
public static DateTime GetServerTime()
{
var time = DateTime.Now;
try
{
time = WmsDb.TA_CONFIG.Select(p => DateTime.Now).First();
}
catch (Exception ex)
{
MessageHelper.ShowEx(ex);
}
return time;
}
#region Loc
public static string GetErpLoc(string locCode)
{
var loc = LocList.SingleOrDefault(p => p.LocCode == locCode);
var str = loc?.ErpLocCode;
str = str != null && str.Length > 8 ? str.Substring(0, 8) : str;
return str ?? string.Empty;
}
public static string GetErpSite(string locCode)
{
var erploc = ErpLocList.SingleOrDefault(p => p.ErpLocCode == GetErpLoc(locCode));
return erploc?.Site ?? "CAAIFJ";
}
public static string GetAreaCode(string locCode)
{
var loc = LocList.SingleOrDefault(p => p.LocCode == locCode);
return loc?.AreaCode ?? string.Empty;
}
public static string GetErpLocCode(string locCode)
{
return LocList.SingleOrDefault(p => p.LocCode == locCode)?.ErpLocCode ?? string.Empty;
}
public static string GetLocName(string locCode)
{
return LocList.SingleOrDefault(p => p.LocCode == locCode)?.LocName ?? string.Empty;
}
#endregion
public static void Refresh(WmsEntities db)
{
try
{
Config = GetConfig(db);
SetConfig(db, Config);
_partList = db.TA_PART.Where(p => p.PartKind != "AST").ToList();
_storeGroupList = db.TA_STORE_GROUP.ToList();
_locList = db.TA_STORE_LOCATION.ToList();
_custPartList = db.TA_CUST_PART.ToList();
_vendPartList = db.TA_VEND_PART.ToList();
_custList = db.TA_CUSTOMER.ToList();
_vendList = db.TA_VENDER.ToList();
_billTypeList = db.TA_BILLTYPE.ToList();
_worklineList = db.TA_WORKLINE.ToList();
_whseList = db.TA_STORE_WHSE.ToList();
_teamList = db.TA_TEAM.ToList();
_erpLocList = db.TA_ERP_LOC.ToList();
_salePriceList = db.TA_SALE_PRICE.ToList();
_purchasePriceList = db.TA_PURCHASE_PRICE.ToList();
_partGroupList = db.TT_PART_GROUP.ToList();
_shiftList = db.TT_SHIFT.ToList();
_unitList = db.TT_UNIT.ToList();
_currencyList = db.TT_CURRENCY.ToList();
_projectList = db.TT_PROJECT.ToList();
_paymentDayList = db.TA_PAYMENT_DAY.ToList();
// _subBilltypeList = db.TT_SUB_BILLTYPE.Where(p => p.State == (int)DataState.Enabled).ToList();
_otherInoutReasonList = db.TA_OTHER_INOUT_REASON.Where(p => p.State == (int)DataState.Enabled).ToList();
_failTypeList = db.TT_FAIL_TYPE.ToList();
_containerTypeList = db.TT_CONTAINER_TYPE.ToList();
_bomList = db.TA_BOM.ToList();
_custBomList = db.TA_CUST_BOM.ToList();
_cqBmptPartRelationList = db.TM_CQBMPT_PART_RELATION.ToList();
if (Config. == ProjectName..ToString())
{
_deliverdestList = db.TA_DELIVER_DEST.ToList();
_destlocList = db.TA_DEST_LOC.ToList();
}
}
catch (Exception ex)
{
throw new Exception(
$"系统无法连接到{GlobalConfig.WmsDatabase.数据库类型}数据库:{GlobalConfig.WmsDatabase.服务器地址},请检查配置的服务器,数据库,用户名和密码等信息是否正确。{Environment.NewLine}{ex.Message}");
}
}
public static async Task RefreshAsync(WmsEntities db)
{
try
{
Config = GetConfig(db);
SetConfig(db, Config);
_partList = await db.TA_PART.Where(p => p.PartKind != "AST").ToListAsync();
_storeGroupList = await db.TA_STORE_GROUP.ToListAsync();
_locList = await db.TA_STORE_LOCATION.ToListAsync();
_custPartList = await db.TA_CUST_PART.ToListAsync();
_vendPartList = await db.TA_VEND_PART.ToListAsync();
_custList = await db.TA_CUSTOMER.ToListAsync();
_vendList = await db.TA_VENDER.ToListAsync();
_billTypeList = await db.TA_BILLTYPE.ToListAsync();
_worklineList = await db.TA_WORKLINE.ToListAsync();
_whseList = await db.TA_STORE_WHSE.ToListAsync();
_teamList = await db.TA_TEAM.ToListAsync();
_erpLocList = await db.TA_ERP_LOC.ToListAsync();
_salePriceList = await db.TA_SALE_PRICE.ToListAsync();
_purchasePriceList = await db.TA_PURCHASE_PRICE.ToListAsync();
_partGroupList = await db.TT_PART_GROUP.ToListAsync();
_shiftList = await db.TT_SHIFT.ToListAsync();
_unitList = await db.TT_UNIT.ToListAsync();
_currencyList = await db.TT_CURRENCY.ToListAsync();
_projectList = await db.TT_PROJECT.ToListAsync();
_paymentDayList = await db.TA_PAYMENT_DAY.ToListAsync();
// _subBilltypeList = await db.TT_SUB_BILLTYPE.Where(p => p.State == (int)DataState.Enabled).ToListAsync();
_otherInoutReasonList = await db.TA_OTHER_INOUT_REASON.Where(p => p.State == (int)DataState.Enabled).ToListAsync();
_failTypeList = await db.TT_FAIL_TYPE.ToListAsync();
_containerTypeList = await db.TT_CONTAINER_TYPE.ToListAsync();
_bomList = await db.TA_BOM.ToListAsync();
_custBomList = await db.TA_CUST_BOM.ToListAsync();
if (Config. == ProjectName..ToString())
{
_deliverdestList = await db.TA_DELIVER_DEST.ToListAsync();
_destlocList = await db.TA_DEST_LOC.ToListAsync();
}
}
catch (Exception ex)
{
throw new Exception(
$"系统无法连接到{GlobalConfig.WmsDatabase.数据库类型}数据库:{GlobalConfig.WmsDatabase.服务器地址},请检查配置的服务器,数据库,用户名和密码等信息是否正确。{Environment.NewLine}{ex.Message}");
}
}
public static string GetReason(int reasonCode)
{
var sub = OtherInoutReasonList.SingleOrDefault(p => p.ReasonCode == reasonCode);
return sub?.ErpReasonCode ?? string.Empty;
}
#region Part
public static int GetValidateDays(string partCode)
{
var part = GetPart(partCode);
return part?.ValidityDays ?? 36500;
}
public static string GetUnit(string partCode)
{
var part = GetPart(partCode);
return part?.Unit ?? string.Empty;
}
public static string GetProjectId(string partCode)
{
var part = GetPart(partCode);
return part?.ProjectId ?? string.Empty;
}
public static string GetDoubleLinePartDesc(string partCode)
{
var part = GetPart(partCode);
if (part == null) return string.Empty;
return part.PartDesc1 + Environment.NewLine + part.PartDesc2;
}
public static InspectType GetInspectType(string partCode)
{
var part = GetPart(partCode);
return part?.InspectType ?? 0;
}
public static string GetPartTypeDesc(TA_PART part)
{
EnumPartType partType;
return Enum.TryParse(part.PartType, true, out partType) ? EnumHelper.GetDesc(partType) : string.Empty;
}
public static string GetPartKindDesc(TA_PART part)
{
EnumPartKind partKind;
return Enum.TryParse(part.PartKind, true, out partKind) ? EnumHelper.GetDesc(partKind) : string.Empty;
}
public static string GetPartStateDesc(TA_PART part)
{
PartState partState;
return Enum.TryParse(part.State, true, out partState) ? EnumHelper.GetDesc(partState) : string.Empty;
}
public static string GetPartGroupName(TA_PART part)
{
return PartGroupList.SingleOrDefault(p => p.GroupCode == part.PartGroup)?.GroupName ??
string.Empty;
}
public static string GetProjectName(TA_PART part)
{
return ProjectList.SingleOrDefault(p => p.ProjectId == part.ProjectId)?.ProjectName ??
string.Empty;
}
public static string GetPartDesc(TA_PART part)
{
return part.PartDesc1 + " " + part.PartDesc2;
}
public static string GetPartDesc(string partCode)
{
var part = GetPart(partCode);
if (part == null) return string.Empty;
return GetPartDesc(part);
}
public static string GetPartDesc1(string partCode)
{
return PartList.SingleOrDefault(p => p.PartCode == partCode)?.PartDesc1 ?? string.Empty;
}
public static string GetPartDesc2(string partCode)
{
return PartList.SingleOrDefault(p => p.PartCode == partCode)?.PartDesc2 ?? string.Empty;
}
public static string GetPartType(string partCode)
{
return PartList.SingleOrDefault(p => p.PartCode == partCode)?.PartType ?? string.Empty;
}
public static string GetPartKind(string partCode)
{
return PartList.SingleOrDefault(p => p.PartCode == partCode)?.PartKind ?? string.Empty;
}
public static int GetProcessIdFromPart(string partCode)
{
var process= PartList.SingleOrDefault(p => p.PartCode == partCode)?.Process ?? string.Empty;
int processId = 0;
int.TryParse(process, out processId);
return processId;
}
public static string GetLineIdFromPart(string partCode)
{
return PartList.SingleOrDefault(p => p.PartCode == partCode)?.Source ?? string.Empty;
}
public static TA_PART GetPart(string partCode)
{
return PartList.SingleOrDefault(p => p.PartCode == partCode);
}
public static TA_PART GetPartByErpPartCode(string erpPartCode)
{
return PartList.SingleOrDefault(p => p.ErpPartCode == erpPartCode);
}
public static string GetErpPartCode(string partCode)
{
return PartList.SingleOrDefault(p => p.PartCode == partCode)?.ErpPartCode ?? string.Empty;
}
public static string GetConfigration(string partCode)
{
return PartList.SingleOrDefault(p => p.PartCode == partCode)?.Configuration ?? string.Empty;
}
public static string GetCustPartCode(string custId, string partCode)
{
var custPart =
CustPartList.FirstOrDefault(p => p.CustId == custId && p.PartCode == partCode) ??
CustPartList.FirstOrDefault(p => p.PartCode == partCode);
return custPart == null ? "" : custPart.CustPartCode;
}
public static string GetVendPartCode(string vendId, string partCode)
{
var vendPart =
VendPartList.FirstOrDefault(p => p.VendId == vendId && p.PartCode == partCode) ??
VendPartList.FirstOrDefault(p => p.PartCode == partCode);
return vendPart == null ? "" : vendPart.VendPartCode;
}
public static decimal GetMaxQty(string partCode)
{
return PartList.SingleOrDefault(p => p.PartCode == partCode)?.MaxQty ?? 0;
}
public static decimal GetMinQty(string partCode)
{
return PartList.SingleOrDefault(p => p.PartCode == partCode)?.MinQty ?? 0;
}
public static decimal GetSafeQty(string partCode)
{
return PartList.SingleOrDefault(p => p.PartCode == partCode)?.SafeQty ?? 0;
}
public static string GetCustPartDesc(string custPartCode)
{
return CustPartList.SingleOrDefault(p => p.CustPartCode == custPartCode)?.CustPartName ?? "";
}
public static string GetPartGroup(string partCode)
{
return PartList.SingleOrDefault(p => p.PartCode == partCode)?.PartGroup ?? string.Empty;
}
public static TA_PART GetPartByCustPartCode(string custId, string custPartCode)
{
var custPart =
CustPartList.FirstOrDefault(p => p.CustId == custId && p.CustPartCode == custPartCode) ??
CustPartList.FirstOrDefault(p => p.CustPartCode == custPartCode);
if (custPart == null)
return null;
var part = PartList.SingleOrDefault(p => p.PartCode == custPart.PartCode);
return part;
}
public static decimal GetLinesidePackQty(string partCode)
{
return PartList.SingleOrDefault(p => p.PartCode == partCode)?.LinesidePackQty ?? 0;
}
public static decimal GetStockPackQty(string partCode)
{
return PartList.SingleOrDefault(p => p.PartCode == partCode)?.StockPackQty ?? 0;
}
#endregion
public static string GetVenderName(string vendId)
{
return VenderList.SingleOrDefault(p => p.VendId == vendId)?.VendName ?? string.Empty;
}
public static string GetCustName(string custId)
{
return CustomerList.SingleOrDefault(p => p.CustId == custId)?.CustName ?? string.Empty;
}
public static string GetSelfCode(string custId)
{
return CustomerList.SingleOrDefault(p => p.CustId == custId)?.SelfCode ?? string.Empty;
}
public static string GetWorkLineName(string lineId)
{
return WorklineList.SingleOrDefault(p => p.LineId == lineId)?.LineName ?? string.Empty;
}
public static string GetShiftName(string shiftId)
{
return ShiftList.SingleOrDefault(p => p.ShiftId == shiftId)?.ShiftName ?? string.Empty;
}
public static string GetTeamName(string teamId)
{
return TeamList.SingleOrDefault(p => p.TeamId == teamId)?.TeamName ?? string.Empty;
}
public static string GetVendAbbr(string vendId)
{
return VenderList.SingleOrDefault(p => p.VendId == vendId)?.VendAbbCode ?? string.Empty;
}
public static string GetColorName(string paintPartCode)
{
return CqBmptPartRelationList.FirstOrDefault(p => p.PaintPartCode == paintPartCode)?.ColorName ??
string.Empty;
}
public static string GetColorName(string injectionPartCode, string colorCode)
{
return
CqBmptPartRelationList.FirstOrDefault(
p => p.InjectionPartCode == injectionPartCode && p.ColorCode == colorCode)?.ColorName ?? string.Empty;
}
// public static string GetWorkLineFromLocCode(string lineId)
// {
// return WorklineList.SingleOrDefault(p => p.LineId == lineId)?.InLocCode ?? string.Empty;
// }
//
// public static string GetWorkLineToLocCode(string lineId)
// {
// return WorklineList.SingleOrDefault(p => p.LineId == lineId)?.OutLocCode ?? string.Empty;
// }
public static void TestWmsDbConntction()
{
try
{
WmsDb.Database.ExecuteSqlCommand("select getdate()");
}
catch (Exception ex)
{
throw new Exception(
$"系统无法连接到{GlobalConfig.WmsDatabase.数据库类型}数据库:{GlobalConfig.WmsDatabase},请检查配置的服务器,数据库,用户名和密码等信息是否正确。" + ex);
}
}
public static string GetErpLineId(string lineId)
{
return WorklineList.SingleOrDefault(p => p.LineId == lineId)?.ErpLineId ?? string.Empty;
}
public static int GetProcessIdFromLine(string lineId)
{
return WorklineList.SingleOrDefault(p => p.LineId == lineId)?.ProcessId ?? 10;
}
public static string GetDestName(string destCode)
{
return DestLocList.SingleOrDefault(p => p.SaleLocCode == destCode)?.DestName ?? "";
}
public static string GetServerTimeString()
{
return GetServerTime().ToString(Config.);
}
public static decimal GetPartPrice(string partCode)
{
var poDetail = WmsDb.TF_PO_DETAIL.OrderByDescending(p => p.UID).FirstOrDefault(p => p.PartCode == partCode);
return poDetail?.Price / poDetail?.UmConv ?? 0;
}
private static readonly List<TB_BILL> TbBillList = new List<TB_BILL>();
public static TB_BILL GetBillVendId(string billNum)
{
var bill = TbBillList.FirstOrDefault(p => p.BillNum == billNum);
if (bill == null)
{
{
bill = WmsDb.TB_BILL.FirstOrDefault(p => p.BillNum == billNum);
if (bill != null)
TbBillList.Add(bill);
}
}
return bill;
}
}
}