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.
442 lines
19 KiB
442 lines
19 KiB
using ICS.WCF.Base;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.ServiceModel;
|
|
using System.Text;
|
|
using UFSoft.UBF.Service;
|
|
using UFSoft.UBF.Util.Context;
|
|
using www.ufida.org.EntityData;
|
|
|
|
namespace UFIDA.ISV.Create_U9_ItemMaster
|
|
{
|
|
public class Create_U9_ItemMaster
|
|
{
|
|
public string orgID = "";
|
|
|
|
public OperationResult CustCreateItemMaster(List<ItemMasterDataClass> itemList)
|
|
{
|
|
OperationResult result = new OperationResult();
|
|
//U9.PM.PO.POShipLine.CreatePOShipLineDefault();
|
|
#region 服务调用框架结构
|
|
//实例化代理类 UFIDAU9ISVItemIBatchCreateItemByDTOSRVClient
|
|
|
|
UFIDAU9ISVItemIBatchCreateItemByDTOSRVClient client = new UFIDAU9ISVItemIBatchCreateItemByDTOSRVClient();
|
|
//服务返回结果
|
|
UFIDAU9CBOSCMItemItemMasterData[] returnItems;
|
|
//返回异常信息,目前还没有使用此属性
|
|
UFSoft.UBF.Exceptions.MessageBase[] returnMsg;
|
|
//上下文信息
|
|
object context;
|
|
//传入 参数
|
|
|
|
string[] splitBy = new string[] { };
|
|
|
|
try
|
|
{
|
|
//给上下文信息赋值
|
|
result.ItemCode = "";
|
|
//给传入参数赋值
|
|
UFIDAU9ISVItemItemMasterDTOData[] itemDatas = setDataForItem(itemList);
|
|
|
|
context = CreateContextObj(orgID);
|
|
|
|
UFIDAU9CBOPubControllerContextDTOData custContext = CreateContextDto();
|
|
//服务调用
|
|
|
|
(client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
|
|
(client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
|
|
returnItems = client.Do(out returnMsg, context, itemDatas.ToArray(), custContext);
|
|
|
|
|
|
foreach (ItemMasterDataClass data in itemList)
|
|
{
|
|
StringBuilder str = new StringBuilder();
|
|
str.AppendLine("创建U9料号");
|
|
str.AppendLine("料号:" + data.Code);
|
|
str.AppendLine("品名:" + data.ItemName);
|
|
str.AppendLine("料品分类:" + data.ItemCategory);
|
|
str.AppendLine("料品规格:" + data.SPEC);
|
|
|
|
str.AppendLine("组织:" + ConfigurationManager.AppSettings["orgCode"].ToString());
|
|
str.AppendLine("结果:" + "True");
|
|
//Appconfig.WriteLogFile(str.ToString(), "创建U9料号");
|
|
|
|
result.ItemCode += data.Code + "|";
|
|
|
|
if (true)
|
|
{
|
|
string Updatesql = @"UPDATE CBO_ItemMaster_Trl SET Description='" + data.Description + "' where CombineName='" + data.Code + "'";
|
|
Updatesql = string.Format(Updatesql);
|
|
DBhlper.Query(Updatesql, Appconfig.GetU9ConnStr());
|
|
}
|
|
|
|
|
|
}
|
|
result.IsSuccess = true;
|
|
result.MESSAGE = "料品创建成功";
|
|
return result;
|
|
//return returnItems;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//异常信息捕获
|
|
|
|
string Message = GetExceptionMessage(ex);
|
|
|
|
StringBuilder str = new StringBuilder();
|
|
foreach (ItemMasterDataClass data in itemList)
|
|
{
|
|
str.AppendLine("创建U9料号");
|
|
str.AppendLine("料号:" + data.Code);
|
|
str.AppendLine("品名:" + data.ItemName);
|
|
str.AppendLine("料品分类:" + data.ItemCategory);
|
|
str.AppendLine("料品规格:" + data.SPEC);
|
|
|
|
str.AppendLine("组织:" + ConfigurationManager.AppSettings["orgCode"].ToString());
|
|
|
|
str.AppendLine("结果:" + "");
|
|
|
|
}
|
|
str.AppendLine("结果:" + "False");
|
|
str.AppendLine("错误:" + GetExceptionMessage(ex));
|
|
result.MESSAGE = "料品创建失败";
|
|
Appconfig.WriteLogFile(str.ToString(), "创建U9料号");
|
|
result.MESSAGE = Message;
|
|
return result;
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
#region 提取异常信息
|
|
/// <summary>
|
|
/// 提取异常信息
|
|
/// </summary>
|
|
/// <param name="ex"></param>
|
|
private string GetExceptionMessage(Exception ex)
|
|
{
|
|
string faultMessage = "未知错误,请查看ERP日志!";
|
|
|
|
System.TimeoutException timeoutEx = ex as System.TimeoutException;
|
|
if (timeoutEx != null)
|
|
{
|
|
faultMessage = "访问服务超时,请修改配置信息!";
|
|
}
|
|
else
|
|
{
|
|
FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
|
|
if (faultEx == null)
|
|
{
|
|
faultMessage = ex.Message;
|
|
}
|
|
else
|
|
{
|
|
ServiceException serviceEx = faultEx.Detail;
|
|
if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
|
|
&& !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
// 错误信息在faultEx.Message中,请提取,
|
|
// 格式为"Fault:料品不能为空,请录入\n 在....."
|
|
int startIndex = serviceEx.Message.IndexOf(":");
|
|
int endIndex = serviceEx.Message.IndexOf("\n");
|
|
if (endIndex == -1)
|
|
endIndex = serviceEx.Message.Length;
|
|
if (endIndex > 0 && endIndex > startIndex + 1)
|
|
{
|
|
faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
|
|
}
|
|
else
|
|
{
|
|
faultMessage = serviceEx.Message;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return faultMessage;
|
|
}
|
|
#endregion
|
|
public class OperationResult
|
|
{
|
|
public bool IsSuccess { get; set; }
|
|
public string MESSAGE { get; set; }
|
|
public string ItemCode { get; set; }
|
|
|
|
}
|
|
#region 给上下文信息赋值
|
|
/// <summary>
|
|
/// 给上下文信息赋值
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private UFIDAU9CBOPubControllerContextDTOData CreateContextDto()
|
|
{
|
|
// 实例化应用上下文对象
|
|
UFIDAU9CBOPubControllerContextDTOData thContext = new UFIDAU9CBOPubControllerContextDTOData();
|
|
|
|
thContext.m_orgID = long.Parse(ConfigurationManager.AppSettings["orgID"].ToString());
|
|
thContext.m_cultureName = ConfigurationManager.AppSettings["cultureName"].ToString();
|
|
thContext.m_entCode = ConfigurationManager.AppSettings["enterpriseID"].ToString();
|
|
thContext.m_orgCode = ConfigurationManager.AppSettings["orgCode"].ToString();
|
|
thContext.m_userCode = ConfigurationManager.AppSettings["userCode"].ToString();
|
|
thContext.m_userID = long.Parse(ConfigurationManager.AppSettings["userID"].ToString());
|
|
return thContext;
|
|
}
|
|
#endregion
|
|
|
|
#region 给上下文信息赋值1
|
|
/// <summary>
|
|
/// 给上下文信息赋值
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private ThreadContext CreateContextObj(string OrgID)
|
|
{
|
|
// 实例化应用上下文对象
|
|
ThreadContext thContext = new ThreadContext();
|
|
|
|
System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
|
|
ns.Add("OrgID", ConfigurationManager.AppSettings["orgID"].ToString());
|
|
//ns.Add("OrgID", long.Parse(OrgID));
|
|
|
|
ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
|
|
ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
|
|
ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
|
|
ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
|
|
ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
|
|
thContext.nameValueHas = ns;
|
|
|
|
return thContext;
|
|
}
|
|
#endregion
|
|
|
|
private UFIDAU9ISVItemItemMasterDTOData[] setDataForItem(List<ItemMasterDataClass> datas)
|
|
{
|
|
List<UFIDAU9ISVItemItemMasterDTOData> items = new List<UFIDAU9ISVItemItemMasterDTOData>();
|
|
foreach (ItemMasterDataClass data in datas)
|
|
{
|
|
|
|
// string orgsql = @"select ID from Base_Organization
|
|
// where Code='{0}' ";
|
|
// orgsql = string.Format(orgsql, data.OrgCode);
|
|
// DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
|
|
// if (orgdt.Rows.Count == 0)
|
|
// {
|
|
// throw new Exception("组织编码不存在!");
|
|
// }
|
|
// else
|
|
// {
|
|
// orgID = orgdt.Rows[0]["ID"].ToString();
|
|
// }
|
|
|
|
|
|
UFIDAU9ISVItemItemMasterDTOData item = new UFIDAU9ISVItemItemMasterDTOData();
|
|
//主分类
|
|
item.m_mainItemCategory = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
|
|
item.m_mainItemCategory.m_code = data.ItemCategory;
|
|
item.Description = data.Description;
|
|
//料号
|
|
item.m_code = data.Code;
|
|
item.m_code1 = data.Code1;
|
|
item.m_code2 = data.Code2;
|
|
UFIDAU9CBOPubControllerCommonArchiveDataDTOData m_org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
|
|
m_org.m_code = ConfigurationManager.AppSettings["orgCode"].ToString();
|
|
|
|
UFIDAU9CBOPubControllerCommonArchiveDataDTOData uom = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
|
|
uom.m_code = data.InventoryUOM;//件
|
|
//AssetCategory
|
|
item.m_assetCategory = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
|
|
item.m_assetCategory.m_code = data.FinanceType;// "C02";
|
|
string InventoryUOM = "";
|
|
string sqlWH = @"select id from Base_UOM where Code='" + data.InventoryUOM + "' ";
|
|
sqlWH = string.Format(sqlWH);
|
|
DataTable _dtWH = DBhlper.Query(sqlWH, Appconfig.GetU9ConnStr());
|
|
string WHCode = string.Empty;
|
|
if (_dtWH != null && _dtWH.Rows.Count > 0)
|
|
{
|
|
InventoryUOM = _dtWH.Rows[0][0].ToString();
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(InventoryUOM))
|
|
uom.m_iD = Convert.ToInt64(InventoryUOM);
|
|
else
|
|
throw new Exception("单位编码未存在!");
|
|
|
|
|
|
|
|
item.m_sPECS = data.SPEC;//规格
|
|
|
|
#region 料品主档DTO
|
|
|
|
item.m_costCurrency = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
|
|
item.m_costCurrency.m_code = "C001";//成本币种
|
|
|
|
//物料自动审核 20190219
|
|
item.m_effective = new UFIDAU9BasePropertyTypesEffectiveData();
|
|
item.m_effective.m_isEffective = true;
|
|
item.m_effective.m_effectiveDate = data.Effective_EffectiveDate;//DateTime.Now.AddDays(-1); //20190222
|
|
item.m_effective.m_disableDate = DateTime.Parse("9999.12.31");
|
|
|
|
item.m_org = m_org;
|
|
item.m_code = data.Code;
|
|
item.m_name = data.ItemName;
|
|
|
|
item.m_itemFormAttribute = 10;
|
|
if (data.ItemFormAttribute == "MakePart")
|
|
{
|
|
item.m_itemFormAttribute = 10;
|
|
}
|
|
if (data.ItemFormAttribute == "FeeItem")
|
|
{
|
|
item.m_itemFormAttribute = 22;
|
|
}
|
|
if (data.ItemFormAttribute == "PurchasePart")
|
|
{
|
|
item.m_itemFormAttribute = 9;
|
|
}
|
|
if (data.ItemFormAttribute == "SubcontractPart")
|
|
{
|
|
item.m_itemFormAttribute = 4;
|
|
}
|
|
|
|
item.m_isInventoryEnable = true;
|
|
item.m_isPurchaseEnable = true;
|
|
item.m_isSalesEnable = true;
|
|
item.m_isBuildEnable = true;
|
|
item.m_isOutsideOperationEnable = true;
|
|
|
|
item.m_isMRPEnable = true;
|
|
item.m_isBOMEnable = true;
|
|
|
|
item.m_inventoryUOM = uom;
|
|
item.m_inventorySecondUOM = uom;
|
|
item.m_salesUOM = uom;
|
|
item.m_purchaseUOM = uom;
|
|
|
|
item.m_priceUOM = uom;
|
|
item.m_manufactureUOM = uom;
|
|
item.m_materialOutUOM = uom;
|
|
item.m_costUOM = uom;
|
|
item.m_converRatioRule = 0;//标准转换率
|
|
|
|
item.m_standardPotency = -1;//标准成分
|
|
item.m_standardGrade = -1;//标准等级
|
|
item.m_startGrade = -1;//起始等级
|
|
item.m_startPotency = -1;//起始成分
|
|
item.m_endGrade = -1;
|
|
item.m_endPotency = -1;
|
|
item.m_itemForm = -1;
|
|
item.m_boundedCategory = -1;
|
|
|
|
|
|
#endregion
|
|
|
|
//料品库存信息DTO
|
|
UFIDAU9ISVItemItemInvInfoDTOData m_invInfo = new UFIDAU9ISVItemItemInvInfoDTOData();
|
|
|
|
|
|
m_invInfo.m_inventoryPlanningMethod = 4;// MRP规划
|
|
m_invInfo.m_purchaseControlMode = 1;//最高存量限制
|
|
m_invInfo.m_isInvCalculateBySeiban = true;//番号存货核算
|
|
m_invInfo.m_reserveMode = -1;//预留方式
|
|
m_invInfo.m_inventoryPlanTime = -1;//规划时机
|
|
m_invInfo.m_invToPurMode = 1;//规划转采购方式
|
|
m_invInfo.m_safetyStockType = 0;//安全存量法
|
|
m_invInfo.m_supplyMethod = -1;//补货方法
|
|
m_invInfo.m_lotControlMode = 2;//批号控制
|
|
m_invInfo.m_barcodeMakeMode = 0;//条码模式
|
|
m_invInfo.m_barcodeTrackMode = 0;//追踪方式
|
|
|
|
item.m_inventoryInfo = m_invInfo;
|
|
|
|
//料品采购信息DTO ItemPurchaseInfoDTO
|
|
UFIDAU9ISVItemItemPurchaseInfoDTOData m_purchaseInfo = new UFIDAU9ISVItemItemPurchaseInfoDTOData();
|
|
m_purchaseInfo.m_quotaSupplier = 1;//仅大批量采购
|
|
m_purchaseInfo.m_receiptType = 0;//收货至仓库
|
|
m_purchaseInfo.m_inquireFixedPeriod = 0;
|
|
m_purchaseInfo.m_inquireRule = -1;
|
|
m_purchaseInfo.m_purchaseQuotaMode = 1;
|
|
m_purchaseInfo.m_statisticPeriod = -1;
|
|
|
|
m_purchaseInfo.m_budgetControlType = -1;//预算控制方式
|
|
m_purchaseInfo.m_isConfirmOnFinished = false; //可事后定价
|
|
m_purchaseInfo.m_isControlPOItemFree = false; //订货控制自由项
|
|
m_purchaseInfo.m_isPURtnTradePathModify = true;//采购退货贸易路径可改
|
|
m_purchaseInfo.m_isPUTradePathModify = true;//采购贸易路径可改
|
|
m_purchaseInfo.m_maxLimitPriceSource = 0;//最高限价来源
|
|
m_purchaseInfo.m_priceSource = 0;//取价来源
|
|
m_purchaseInfo.m_quotaSupplier = 1;//配额供应商
|
|
//m_purchaseInfo.m_receiptMode = 3;//收货程序
|
|
m_purchaseInfo.m_receiptMode = 0;//收货程序
|
|
|
|
m_purchaseInfo.m_returnPriceSource = 2;//退货取价来源
|
|
m_purchaseInfo.m_chargeAssignMode = 0;//费用分配
|
|
m_purchaseInfo.m_chargeProcessMode = 1;//费用料处理
|
|
m_purchaseInfo.m_dangerType = 0;//危险类别
|
|
m_purchaseInfo.m_receiptType = 0;//收货方式
|
|
|
|
item.m_purchaseInfo = m_purchaseInfo;
|
|
|
|
//料品销售信息DTO ItemSaleInfoDTO
|
|
UFIDAU9ISVItemItemSaleInfoDTOData m_saleInfo = new UFIDAU9ISVItemItemSaleInfoDTOData();
|
|
m_saleInfo.m_limitPriceMode = 0;//定义绝对价格
|
|
m_saleInfo.m_supplySource = 4;//当前组织
|
|
|
|
m_saleInfo.m_familyLayer = -1;//系列件层级
|
|
m_saleInfo.m_isSDRtnTradePathModify = true;//销售退货贸易路径可改
|
|
m_saleInfo.m_isSDTradePathModify = true;//销售贸易路径可改
|
|
m_saleInfo.m_demandTransType = 4;//供应类型
|
|
m_saleInfo.m_isReturnable = true;//可退换
|
|
m_saleInfo.m_isRMAAllowModify = true;//退货可改
|
|
m_saleInfo.m_limitPriceBy = -1;//限价依据
|
|
|
|
item.m_saleInfo = m_saleInfo;
|
|
|
|
//料品生产信息DTO ItemMFGInfoDTO
|
|
UFIDAU9ISVItemItemMFGInfoDTOData m_mfgInfo = new UFIDAU9ISVItemItemMFGInfoDTOData();
|
|
m_mfgInfo.m_buildShrinkageRate = 1M;//产出率
|
|
m_mfgInfo.m_isSueOverType = -1;//备料超额类型:0 比例 1 数量
|
|
m_mfgInfo.m_buildQuanSelectType = 0;//依需求量
|
|
|
|
m_mfgInfo.m_operateType = -1;//排产方式
|
|
|
|
item.m_mfgInfo = m_mfgInfo;
|
|
|
|
//料品MRP(计划)信息DTO ItemMRPInfoDTO
|
|
UFIDAU9ISVItemItemMRPInfoDTOData m_mrpInfo = new UFIDAU9ISVItemItemMRPInfoDTOData();
|
|
m_mrpInfo.m_forecastContorlType = 2;//无
|
|
m_mrpInfo.m_mRPPlanningType = 1;//MPS
|
|
m_mrpInfo.m_planningTimeFenceRuleType = 0;//客户订单
|
|
m_mrpInfo.m_planningTimeFence = 0;//累计汇总提前期
|
|
m_mrpInfo.m_demandTimeFenceRuleType = 0;//客户订单
|
|
m_mrpInfo.m_demandTimeFence = 0;//累计汇总提前期
|
|
m_mrpInfo.m_releaseTimeFence = 0;//累计汇总提前期
|
|
item.m_mrpInfo = m_mrpInfo;
|
|
|
|
|
|
|
|
|
|
//UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData m_descFlexField = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
|
|
//m_descFlexField.m_privateDescSeg2 = data.ValveMaterial;//材质
|
|
//item.m_descFlexField = m_descFlexField;
|
|
|
|
//m_descFlexField.m_privateDescSeg15 = data.PartType;
|
|
|
|
|
|
items.Add(item);
|
|
}
|
|
return items.ToArray();
|
|
}
|
|
|
|
#region 时间戳方法
|
|
private DateTime TimestampToDateTime(long timestamp)
|
|
{
|
|
DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
|
|
long lTime = timestamp * 10000000;
|
|
TimeSpan nowTimeSpan = new TimeSpan(lTime);
|
|
DateTime resultDateTime = dateTimeStart.Add(nowTimeSpan);
|
|
return resultDateTime;
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|