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.
320 lines
11 KiB
320 lines
11 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using CK.SCP.Models.AppBoxEntity;
|
|
using CK.SCP.Models.Enums;
|
|
using CK.SCP.Models.ScpEntity;
|
|
using CK.SCP.Utils;
|
|
|
|
namespace CK.SCP.Models
|
|
{
|
|
public static class ScpCache
|
|
{
|
|
private static readonly ScpEntities ScpDb = EntitiesFactory.CreateScpInstance();
|
|
private static readonly AppBoxContext Db = EntitiesFactory.CreateAppBoxInstance();
|
|
private static List<TA_VENDER> _vendList;
|
|
private static List<TA_PART> _PartList;
|
|
private static List<User> _usersList;
|
|
private static List<TB_RECEIVE> _ReceiveList;
|
|
private static List<TB_FACTORY> _FactoryList;
|
|
private static List<TA_REVICE_PORT> _PortList;
|
|
private static ScpConfig _config;
|
|
public static ScpConfig Config
|
|
|
|
{
|
|
get { return _config ?? (_config = GetConfig(ScpDb)); }
|
|
set { _config = value; }
|
|
}
|
|
|
|
private static ScpConfig GetConfig(ScpEntities db)
|
|
{
|
|
var config = new ScpConfig();
|
|
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.ShowError(ex);
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
return config;
|
|
}
|
|
|
|
private static void SetConfig(ScpEntities db, ScpConfig 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) ==null?"": pi.GetValue(Config, null).ToString(),
|
|
State = 1,
|
|
Remark = piName,
|
|
};
|
|
db.TA_CONFIG.Add(cfg);
|
|
}
|
|
EntitiesFactory.SaveDb(db);
|
|
}
|
|
|
|
public static List<TA_CONFIG> GetDbConfigList(ScpEntities db)
|
|
{
|
|
return db.TA_CONFIG.OrderByDescending(p => p.UID).ToList();
|
|
}
|
|
public static void Refresh(ScpEntities db)
|
|
{
|
|
try
|
|
{
|
|
Config = GetConfig(db);
|
|
SetConfig(db, Config);
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
throw new Exception(
|
|
$"系统无法连接到{GlobalConfig.ScpDatabase.数据库类型}数据库:{GlobalConfig.ScpDatabase.服务器地址},请检查配置的服务器,数据库,用户名和密码等信息是否正确。");
|
|
}
|
|
|
|
}
|
|
public static string GetVendFax(string vendId)
|
|
{
|
|
return VenderList.SingleOrDefault(p => p.VendId == vendId)?.Fax ?? string.Empty;
|
|
}
|
|
public static List<TA_VENDER> GetVendNameList(List<string> p_list, string p_site)
|
|
{
|
|
|
|
IQueryable<TA_VENDER> query = ScpDb.TA_VENDER;
|
|
if (p_list.Count > 0)
|
|
{
|
|
query = query.Where(p => p_list.Contains(p.VendId));
|
|
}
|
|
if (!string.IsNullOrEmpty(p_site))
|
|
{
|
|
query = query.Where(p => p.Site == p_site);
|
|
}
|
|
return query.ToList();
|
|
}
|
|
|
|
public static string GetVendPhone(string vendId)
|
|
{
|
|
return VenderList.SingleOrDefault(p => p.VendId == vendId)?.Phone ?? string.Empty;
|
|
}
|
|
|
|
public static string GetVendName(string vendId)
|
|
{
|
|
return VenderList.SingleOrDefault(p => p.VendId == vendId)?.VendName ?? string.Empty;
|
|
}
|
|
public static string GetFactoryNameByCode(string p_factoryId)
|
|
{
|
|
return FactoryList.SingleOrDefault(p => p.FactoryId == p_factoryId)?.FactoryName ?? string.Empty;
|
|
}
|
|
public static string GetPartDesc(string wmsDataPartCode)
|
|
{
|
|
return "";
|
|
}
|
|
public static string GetRevicePort(string p_code)
|
|
{
|
|
var _rev = PortList.SingleOrDefault(p => p.PORT_NO == p_code)?.PORT_DESCRIPTION ?? string.Empty;
|
|
return _rev;
|
|
}
|
|
|
|
public static string GetVendFax(string vendId, string p_site)
|
|
{
|
|
return VenderList.SingleOrDefault(p => p.VendId == vendId && p.Site == p_site)?.Fax ?? string.Empty;
|
|
}
|
|
|
|
public static string GetVendPhone(string vendId,string p_site)
|
|
{
|
|
return VenderList.SingleOrDefault(p => p.VendId == vendId && p.Site==p_site)?.Phone ?? string.Empty;
|
|
}
|
|
public static string GetVendName(string vendId,string p_site)
|
|
{
|
|
return VenderList.SingleOrDefault(p => p.VendId == vendId && p.Site==p_site)?.VendName ?? string.Empty;
|
|
}
|
|
public static string GetFactoryNameByCode(string p_factoryId,string p_site)
|
|
{
|
|
return FactoryList.SingleOrDefault(p => p.FactoryId == p_factoryId )?.FactoryName ?? string.Empty;
|
|
}
|
|
public static string GetPartDesc(string wmsDataPartCode,string p_site)
|
|
{
|
|
return "";
|
|
}
|
|
public static string GetRevicePort(string p_code,string p_site)
|
|
{
|
|
var _rev = PortList.SingleOrDefault(p => p.PORT_NO == p_code)?.PORT_DESCRIPTION ?? string.Empty;
|
|
return _rev;
|
|
}
|
|
|
|
public static string GetVendIDByUser(string name,string p_site)
|
|
{
|
|
return UsersList.SingleOrDefault(p => p.Name == name )?.SupplierCode ?? string.Empty;
|
|
}
|
|
public static string GetResourceByKey(string p_key,string p_languageType="CH")
|
|
{
|
|
string _str = p_key;
|
|
var _lag=LangauageList.Where(p => p.CH == p_key).FirstOrDefault();
|
|
if (_lag != null)
|
|
{
|
|
switch (p_languageType)
|
|
{
|
|
case "EN":
|
|
_str = _lag.EN;
|
|
break;
|
|
case "DE":
|
|
_str = _lag.DE;
|
|
break;
|
|
}
|
|
}
|
|
return _str;
|
|
}
|
|
|
|
public static DateTime GetServerTime()
|
|
{
|
|
return DateTime.Now;
|
|
}
|
|
public static List<TA_VENDER> VenderList
|
|
{
|
|
get
|
|
{
|
|
if (_vendList == null || _vendList.Count == 0)
|
|
{
|
|
_vendList = ScpDb.TA_VENDER.ToList();
|
|
}
|
|
return _vendList;
|
|
}
|
|
set { _vendList = value; }
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<TA_REVICE_PORT> PortList
|
|
{
|
|
get
|
|
{
|
|
if (_PortList == null || _PortList.Count == 0)
|
|
{
|
|
_PortList = ScpDb.TA_REVICE_PORT.ToList();
|
|
}
|
|
return _PortList;
|
|
}
|
|
set { _PortList = value; }
|
|
}
|
|
public static List<TB_FACTORY> FactoryList
|
|
{
|
|
get
|
|
{
|
|
if (_FactoryList == null || _FactoryList.Count == 0)
|
|
{
|
|
_FactoryList = ScpDb.TB_FACTORY.ToList();
|
|
}
|
|
return _FactoryList;
|
|
}
|
|
set { _FactoryList = value; }
|
|
}
|
|
|
|
|
|
private static List<TA_LANGUAGE> _LangauageList;
|
|
public static List<TA_LANGUAGE> LangauageList
|
|
{
|
|
get
|
|
{
|
|
if (_LangauageList == null || _LangauageList.Count == 0)
|
|
{
|
|
_LangauageList = ScpDb.TA_LANGUAGE.ToList();
|
|
}
|
|
return _LangauageList;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<User> UsersList
|
|
{
|
|
get
|
|
{
|
|
if (_usersList == null || _usersList.Count == 0)
|
|
{
|
|
_usersList = Db.Users.ToList();
|
|
}
|
|
return _usersList;
|
|
}
|
|
set { _usersList = value; }
|
|
}
|
|
public static List<TA_PART> PartList
|
|
{
|
|
get
|
|
{
|
|
if (_PartList == null || _PartList.Count == 0)
|
|
{
|
|
_PartList = ScpDb.TA_PART.ToList();
|
|
}
|
|
return _PartList;
|
|
}
|
|
set { _PartList = value; }
|
|
}
|
|
public static string GetPartDesc1(string partCode)
|
|
{
|
|
var _ta = PartList.SingleOrDefault(p => p.PartCode == partCode);
|
|
if (_ta != null)
|
|
{
|
|
return _ta.PartDesc1 + _ta.PartDesc2;
|
|
}
|
|
return PartList.SingleOrDefault(p => p.PartCode == partCode )?.PartDesc1 ?? string.Empty+ PartList.SingleOrDefault(p => p.PartCode == partCode)?.PartDesc2 ?? string.Empty;
|
|
}
|
|
|
|
|
|
public static string GetPartDesc1(string partCode,string p_site)
|
|
{
|
|
var _ta = PartList.SingleOrDefault(p => p.PartCode == partCode && p.Site==p_site);
|
|
if (_ta != null)
|
|
{
|
|
return _ta.PartDesc1 + _ta.PartDesc2;
|
|
}
|
|
return PartList.SingleOrDefault(p => p.PartCode == partCode)?.PartDesc1 ?? string.Empty + PartList.SingleOrDefault(p => p.PartCode == partCode)?.PartDesc2 ?? string.Empty;
|
|
}
|
|
|
|
|
|
}
|
|
public class ScpConfig
|
|
{
|
|
public string QAD域 { get; set; } = "BJINTIER";
|
|
public string QAD地点 { get; set; } = "BJCIAI";
|
|
public string WMS接口数据流水号格式 { get; set; } = "yyMMdd_HHmmssffff";
|
|
|
|
public string 项目名称 { get; set; } = "锦恒项目";
|
|
public string WMS用户名 { get; set; } = "W";
|
|
|
|
public string SCP用户名 { get; set; } = "SCP";
|
|
public string SCP接口数据流水号格式 { get; set; } = "yyMMdd_HHmmssffff";
|
|
|
|
|
|
public string 条码分隔符 { get; set; } = ".";//"1";
|
|
public bool 条码包含供应商简称 { get; set; } = false;
|
|
|
|
public string 二维码格式 { get; set; } = "1";
|
|
public string 条码序列号格式 { get; set; } = "000000";
|
|
public string 小包装条码序列号格式 { get; set; } = "600000";
|
|
public bool 负数发票 { get; set; } = false;
|
|
}
|
|
}
|