3064 lines
139 KiB
C#
3064 lines
139 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Linq;
|
||
using System.Xml;
|
||
using System.Xml.Linq;
|
||
using Kingdee.BOS;
|
||
using Kingdee.BOS.App;
|
||
using Kingdee.BOS.App.Core;
|
||
using Kingdee.BOS.App.Data;
|
||
using Kingdee.BOS.Contracts;
|
||
using Kingdee.BOS.Core;
|
||
using Kingdee.BOS.Core.Bill;
|
||
using Kingdee.BOS.Core.Bill.PlugIn;
|
||
using Kingdee.BOS.Core.CommonFilter;
|
||
using Kingdee.BOS.Core.Const;
|
||
using Kingdee.BOS.Core.DynamicForm;
|
||
using Kingdee.BOS.Core.DynamicForm.Operation;
|
||
using Kingdee.BOS.Core.DynamicForm.PlugIn;
|
||
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
|
||
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
|
||
using Kingdee.BOS.Core.Enums;
|
||
using Kingdee.BOS.Core.List;
|
||
using Kingdee.BOS.Core.Metadata;
|
||
using Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs;
|
||
using Kingdee.BOS.Core.Metadata.EntityElement;
|
||
using Kingdee.BOS.Core.Metadata.FieldElement;
|
||
using Kingdee.BOS.Core.Metadata.FormElement;
|
||
using Kingdee.BOS.Core.Permission;
|
||
using Kingdee.BOS.Orm;
|
||
using Kingdee.BOS.Orm.DataEntity;
|
||
using Kingdee.BOS.Orm.Metadata.DataEntity;
|
||
using Kingdee.BOS.Resource;
|
||
using Kingdee.BOS.ServiceHelper;
|
||
using Kingdee.BOS.Util;
|
||
using Kingdee.K3.BD.BarCode.App.Core;
|
||
using Kingdee.K3.BD.BarCode.Business.PlugIn;
|
||
using Kingdee.K3.BD.BarCode.Core;
|
||
using Kingdee.K3.BD.BarCode.Core.DataModel.Service;
|
||
using Kingdee.K3.BD.BarCode.ServiceHelper;
|
||
using Kingdee.K3.BD.NewCode.Core.Utils;
|
||
|
||
namespace GZ.LJY000.Biori.UHIK_BAR_BarCodeScan
|
||
{
|
||
[HotUpdate]
|
||
[Description("条码扫描业务端表单插件_V1.0")]
|
||
public class BarCodeScanEditEx : AbstractBillPlugIn
|
||
{
|
||
private string _permissionConst = string.Empty;
|
||
|
||
private bool isAllowDelete = false;
|
||
|
||
private bool isFailure = false;
|
||
|
||
private bool needMatchToSourceBill = false;
|
||
|
||
private Dictionary<string, DynamicObject> doSourceBillInfo = null;
|
||
|
||
private FormMetadata billFormMetaData = null;
|
||
|
||
private DynamicObject barcodeRule = null;
|
||
|
||
private DynamicObject[] barcodeRuleEntities = null;
|
||
|
||
private int defaultScanNumber = 1;
|
||
|
||
private string sourceBillFormId = string.Empty;
|
||
|
||
private string middleBillFormId = string.Empty;
|
||
|
||
private string createBillFormId = string.Empty;
|
||
|
||
private Dictionary<string, int> validCodeAndRowMapping = new Dictionary<string, int>();
|
||
|
||
private Dictionary<string, decimal> validCodeAndQtyMapping = new Dictionary<string, decimal>();
|
||
|
||
private Dictionary<string, int> validCodeAndSumRowMapping = new Dictionary<string, int>();
|
||
|
||
private Dictionary<string, long> validCodeAndSumSrcEntryIDMapping = new Dictionary<string, long>();
|
||
|
||
private Dictionary<int, Dictionary<string, decimal>> validSumRowMapping = new Dictionary<int, Dictionary<string, decimal>>();
|
||
|
||
private Dictionary<int, Dictionary<string, string>> validSumRowSeriMapping = new Dictionary<int, Dictionary<string, string>>();
|
||
|
||
private Dictionary<int, string> invalidCodeAndRowMapping = new Dictionary<int, string>();
|
||
|
||
private Dictionary<int, string> invalidCodeAndRowSeriMapping = new Dictionary<int, string>();
|
||
|
||
//private long sourceBillId = 0L;
|
||
|
||
//private string sourceBillNo = string.Empty;
|
||
|
||
private const string ScanDetailEntityKey = "FScanDetailEntity";
|
||
|
||
private const string ScanSummaryEntityKey = "FScanSummaryEntity";
|
||
|
||
private BarCodeSysParamsModel barcodeSysParm = null;
|
||
|
||
private long barcodeRuleId = 0L;
|
||
|
||
private long barcodeRuleNewId = 0L;
|
||
|
||
private bool isCKBarCodeRule = false;
|
||
|
||
private List<Dictionary<Field, Field>> lstMatchItem = new List<Dictionary<Field, Field>>();
|
||
|
||
private List<Dictionary<Field, Field>> lstSumMatchItem = new List<Dictionary<Field, Field>>();
|
||
|
||
private Dictionary<string, int> noMatchCodeAndRowMapping = new Dictionary<string, int>();
|
||
|
||
private DynamicObjectCollection doSummaryDatas = null;
|
||
|
||
private FormMetadata tagbillFormMetaData = null;
|
||
|
||
private Dictionary<string, Dictionary<string, string>> dctMatchData = new Dictionary<string, Dictionary<string, string>>();
|
||
|
||
private string srcEntryKey;
|
||
|
||
private string srcMaterialIdKey;
|
||
|
||
private string srcMaterialIdPropName;
|
||
|
||
private string srcQtyKey;
|
||
|
||
private Entity srcEntryEntity;
|
||
|
||
private string createEntryKey;
|
||
|
||
private string createMaterialIdKey;
|
||
|
||
private string createMaterialIdPropName;
|
||
|
||
private string createQtyKey;
|
||
|
||
private string billPageId = string.Empty;
|
||
|
||
private List<long> _sourceBillIds = null;
|
||
private List<string> _sourceBillNos = null;
|
||
private Dictionary<string, long> _sourceBillNoToIds = null;
|
||
private int BillCodeIdx = 0;
|
||
private string _BDBarCodeMainFile;
|
||
private string _BD_BarCodeRule;
|
||
|
||
public override void OnInitialize(InitializeEventArgs e)
|
||
{
|
||
//BarCodeLog.InitLog(base.Context, "ScanEdit", "CloudIDE", Guid.NewGuid().ToString());
|
||
base.OnInitialize(e);
|
||
if (this.Context.DBId.Equals("66eec1c506d225"))
|
||
{
|
||
_permissionConst = "YCKE_BD_BarCodeScan";
|
||
_BDBarCodeMainFile = "BD_BarCodeMainFile";
|
||
_BD_BarCodeRule = "BD_BarCodeRule";
|
||
}
|
||
else
|
||
{
|
||
_permissionConst = "UHIK_BD_BarCodeScan";
|
||
_BDBarCodeMainFile = "UHIK_BD_BarCodeMainFile";
|
||
_BD_BarCodeRule = "UHIK_BD_BarCodeRule";
|
||
}
|
||
|
||
}
|
||
|
||
public override void OnLoad(EventArgs e)
|
||
{
|
||
base.OnLoad(e);
|
||
|
||
if (!sourceBillFormId.IsNullOrEmpty())
|
||
{
|
||
var sql = $@"
|
||
SELECT t0.FID,t0.FENTRYID
|
||
FROM T_BD_BARCODERULETOBILL t0
|
||
WHERE t0.FISCHECK = 1
|
||
AND t0.FBILLID = '{sourceBillFormId}'
|
||
";
|
||
var data = DBUtils.ExecuteDynamicObject(this.Context, sql);
|
||
if (data != null && data.Any())
|
||
{
|
||
barcodeRuleId = data[0]["FID"].Long2Int();
|
||
Model.SetValue("FBarCodeRule", barcodeRuleId);
|
||
base.View.InvokeFieldUpdateService("FBarCodeRule", 0);
|
||
}
|
||
}
|
||
|
||
this.View.Model.SetValue("FIsSave", "1");
|
||
}
|
||
|
||
public override void BeforeClosed(BeforeClosedEventArgs e)
|
||
{
|
||
base.BeforeClosed(e);
|
||
//BarCodeLog.EndLog();
|
||
}
|
||
|
||
private void LockScanInfoBy()
|
||
{
|
||
base.View.GetMainBarItem("tbNew").Enabled = true;
|
||
base.View.GetMainBarItem("tbSave").Enabled = true;
|
||
base.View.GetMainBarItem("tbChooseBill").Enabled = false;
|
||
base.View.GetMainBarItem("tbExit").Enabled = true;
|
||
base.View.GetBarItem("FEntityToBill", "tbButton").Enabled = false;
|
||
base.View.GetBarItem("FEntityToBill", "tbDeleteRow").Enabled = false;
|
||
base.View.GetBarItem("FEntityToBill", "tbBatchFill").Enabled = false;
|
||
base.View.GetBarItem("FEntityToBill", "tbCreBarCodeSum").Enabled = false;
|
||
base.View.GetBarItem("FEntityToBill", "tbCreBarCodeRow").Enabled = false;
|
||
base.View.GetBarItem("FEntityToBill", "tbGetNewData").Enabled = false;
|
||
base.View.GetBarItem("FEntityToBill", "tbDeleteList").Enabled = false;
|
||
Entity entity = base.View.BusinessInfo.GetEntity("FEntityToBill");
|
||
base.View.StyleManager.SetEnabled(entity, "", value: false);
|
||
base.View.StyleManager.SetEnabled("FBillId", "FBillId", value: false);
|
||
base.View.StyleManager.SetEnabled("FBarCodeRule", "FBarCodeRule", value: false);
|
||
base.View.StyleManager.SetEnabled("FBILLCODEHEAD", "FBILLCODEHEAD", value: false);
|
||
base.View.GetControl("FCustomer").Enabled = false;
|
||
base.View.GetControl("FAssistantType").Enabled = false;
|
||
base.View.GetControl("FAssistant").Enabled = false;
|
||
}
|
||
|
||
public override void AfterCreateNewData(EventArgs e)
|
||
{
|
||
InitNewVaraible();
|
||
GetDefaultByUserID();
|
||
}
|
||
|
||
public override void AfterBindData(EventArgs e)
|
||
{
|
||
InitBillNameFilter();
|
||
}
|
||
|
||
private void InitBillNameFilter()
|
||
{
|
||
Field field = base.View.BusinessInfo.GetField("FSourceBillName");
|
||
Field field2 = base.View.BusinessInfo.GetField("FCreatedBillName");
|
||
BarCodeCommonServiceHelper.GetBarCodeBillFilter(base.Context, (BaseDataField)field);
|
||
BarCodeCommonServiceHelper.GetBarCodeBillFilter(base.Context, (BaseDataField)field2);
|
||
}
|
||
|
||
public override void BeforeDoOperation(BeforeDoOperationEventArgs e)
|
||
{
|
||
string str = Convert.ToString(base.View.Model.GetValue("FDocumentStatus"));
|
||
switch (e.Operation.FormOperation.Operation.ToUpperInvariant())
|
||
{
|
||
case "SAVE":
|
||
if (!str.EqualsIgnoreCase("Z") && !str.EqualsIgnoreCase("A"))
|
||
{
|
||
break;
|
||
}
|
||
|
||
if (createBillFormId.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
base.View.ShowMessage(ResManager.LoadKDString("请先选择生成单据名称!", "f5502ba0733042e9", "APP_ISVPAAC2016062210550"));
|
||
e.Cancel = true;
|
||
break;
|
||
}
|
||
|
||
if (tagbillFormMetaData.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
tagbillFormMetaData = (FormMetadata)MetaDataServiceHelper.Load(base.Context, createBillFormId);
|
||
}
|
||
|
||
SummaryScanDetail_New();
|
||
|
||
//if (sourceBillFormId.ToUpper().Equals("PRD_MO"))
|
||
// DoCheckPush("PRD_MORPT", createBillFormId);
|
||
//else if (sourceBillFormId.ToUpper().Equals("UHIK_PRD_PACKAGE_INSTOCK"))
|
||
// DoCheckPush("PRD_MORPT", createBillFormId);
|
||
//else
|
||
// DoCheckPush(sourceBillFormId, createBillFormId);
|
||
|
||
break;
|
||
case "CLOSE":
|
||
//barcodeSysParm = barcodeSysParm ?? BarCodeCommonServiceHelper.GetBarCodeBillSystemParameters(base.Context, base.Context.CurrentOrganizationInfo.ID, sourceBillFormId);
|
||
//if (barcodeSysParm.AutoSaveScanRecord && (str.EqualsIgnoreCase("Z") || str.EqualsIgnoreCase("A")) && base.View.Model.DataChanged)
|
||
//{
|
||
// base.View.InvokeFormOperation(FormOperationEnum.Save);
|
||
//}
|
||
|
||
if (isFailure)
|
||
{
|
||
base.View.Model.SetValue("FDocumentStatus", "C");
|
||
base.View.InvokeFormOperation(FormOperationEnum.Save);
|
||
}
|
||
|
||
break;
|
||
}
|
||
|
||
base.BeforeDoOperation(e);
|
||
}
|
||
|
||
public override void BeforeUpdateValue(BeforeUpdateValueEventArgs e)
|
||
{
|
||
base.BeforeUpdateValue(e);
|
||
string text = e.Key.ToUpperInvariant();
|
||
if (!(text == "FSCANCODE"))
|
||
{
|
||
if (text == "FISMAPTOSOURCEBILL")
|
||
{
|
||
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
string text2 = e.Value.ToString();
|
||
|
||
text2 = text2.Long2Int() == 0 ? text2 : GetBarCode(text2);
|
||
|
||
if (text2.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
return;
|
||
}
|
||
|
||
string text3 = ((!(base.View.Model.GetValue("FCREATEDBILLNAME") is DynamicObject dynamicObject)) ? "" : Convert.ToString(dynamicObject["Id"]));
|
||
|
||
//if (barCodeBillSystemParameters != null && !barCodeBillSystemParameters.IsSameCodeRepeatOut)
|
||
{
|
||
if (text3.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
base.View.ShowMessage(ResManager.LoadKDString(ResManager.LoadKDString(ResManager.LoadKDString("请先选择生成单据名称!", "f5502ba0733042e9", "APP_ISVPAAC2016062210550"), "af9bdd7c5e6d4abc", "APP_ISVPAAC2016062210550"), "0011019000003170", SubSystemType.BASE));
|
||
e.Cancel = true;
|
||
return;
|
||
}
|
||
|
||
if (!BarCodeCommonServiceHelper.IsCanOutScan(base.Context, text2, text3))
|
||
{
|
||
base.View.ShowMessage(ResManager.LoadKDString("当前条码【" + text2 + ResManager.LoadKDString("】已经出库,不允许扫描!", "b11f35b68c9f45d7", "APP_ISVPAAC2016062210550"), "0011019000003170", SubSystemType.BASE));
|
||
e.Cancel = true;
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (isCKBarCodeRule)
|
||
{
|
||
DynamicObject value3 = base.View.Model.GetValue("FBarCodeRule") as DynamicObject;
|
||
if (value3.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
base.View.ShowMessage(ResManager.LoadKDString("请选择条码规则!", "811a54b853f74bff", "APP_ISVPAAC2016062210550"));
|
||
e.Cancel = true;
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
barcodeRuleId = 0L;
|
||
}
|
||
|
||
if (!sourceBillFormId.IsNullOrEmptyOrWhiteSpace() && billFormMetaData == null)
|
||
{
|
||
billFormMetaData = (FormMetadata)MetaDataServiceHelper.Load(base.Context, sourceBillFormId);
|
||
}
|
||
|
||
if (!billFormMetaData.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
var billNo = HandleBarCode(text2);
|
||
if (_sourceBillNos == null)
|
||
_sourceBillNos = new List<string>();
|
||
|
||
if (!_sourceBillNos.Contains(billNo))
|
||
_sourceBillNos.Add(billNo);
|
||
|
||
Field billNoField = billFormMetaData.BusinessInfo.GetBillNoField();
|
||
string strFilter = $" {billNoField.Key} IN ('{string.Join("','", _sourceBillNos)}') ";
|
||
OQLFilter ofilter = OQLFilter.CreateHeadEntityFilter(strFilter);
|
||
var data = BusinessDataServiceHelper.Load(base.Context, sourceBillFormId, null, ofilter);
|
||
doSourceBillInfo = data.ToDictionary(x => x["BillNo"].ToString(), v => v);
|
||
_sourceBillIds = data.Select(x => (long)x["Id"].Long2Int()).ToList();
|
||
_sourceBillNoToIds = data.ToDictionary(x => x["BillNo"].ToString(), v => (long)v["Id"].Long2Int());
|
||
_sourceBillNos = data.Select(x => x["BillNo"].ToString()).ToList();
|
||
}
|
||
|
||
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("AnalyseBarCode开始", "273cba0aa8e9406a", "APP_ISVPAAC2016062210550") + text2);
|
||
AnalyseBarCode(text2);
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("AnalyseBarCode结束", "50880294a810495c", "APP_ISVPAAC2016062210550") + text2);
|
||
e.Value = "";
|
||
Control control = base.View.GetControl("FScanCode");
|
||
control.SetFocus();
|
||
e.Cancel = true;
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit BeforeUpdateValue", "newScanBarCode" + text2);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 如扫码结果的是内码则获取内码保存的条码
|
||
/// </summary>
|
||
/// <param name="val"></param>
|
||
/// <returns></returns>
|
||
public string GetBarCode(string val)
|
||
{
|
||
if (!val.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
var resVal = string.Empty;
|
||
|
||
//获取元数据服务
|
||
IMetaDataService metadataService = ServiceHelper.GetService<IMetaDataService>();
|
||
|
||
//获取ViewService
|
||
IViewService viewService = ServiceHelper.GetService<IViewService>();
|
||
//获取物料元数据
|
||
|
||
var fromId = "UHIK_BD_BarCodeMainFile";
|
||
//fromId = "BD_BarCodeMainFile";
|
||
FormMetadata sourceMetada = metadataService.Load(this.Context, fromId) as FormMetadata;
|
||
|
||
//构建快捷过滤条件
|
||
OQLFilter filter = new OQLFilter();
|
||
filter.Add(new OQLFilterHeadEntityItem() { FilterString = $" FID = {val} " });
|
||
|
||
//构建关心的字段片段信息
|
||
List<SelectorItemInfo> lstSelectorItemInfos = new List<SelectorItemInfo>
|
||
{
|
||
new SelectorItemInfo("FID"),
|
||
new SelectorItemInfo("FBarCode"),
|
||
};
|
||
|
||
var resData = viewService.Load(this.Context, sourceMetada.BusinessInfo, lstSelectorItemInfos, filter);
|
||
|
||
if (resData != null && resData.Count() > 0)
|
||
{
|
||
resVal = resData[0]["BarCode"].ToString();
|
||
}
|
||
|
||
return resVal;
|
||
}
|
||
|
||
|
||
return "";
|
||
}
|
||
|
||
public void SetBarCodeRuleId()
|
||
{
|
||
var sql = $@"/*dialect*/
|
||
SELECT *
|
||
FROM (
|
||
SELECT t0e.FENTRYID,t0e.FID,t0e.FSEQ,ROW_NUMBER() OVER (ORDER BY t0e.FSEQ) - 1 RN
|
||
,t1.FTYPE,t1.FBARCODEFIELDKEY
|
||
FROM T_BD_BARCODERULE t0
|
||
INNER JOIN T_BD_BARCODERULEENTRY t0e on t0.FID = t0e.FID
|
||
INNER JOIN T_BD_BARCODEITEM t1 on t1.FID = t0e.FBARCODEPROPERTYID
|
||
WHERE t0.FID = {barcodeRuleId}
|
||
AND t0e.FCODEITEM = 1
|
||
) t0
|
||
WHERE 1=1 AND t0.FBARCODEFIELDKEY = 'FBILLCODE'
|
||
|
||
";
|
||
var data = DBUtils.ExecuteDynamicObject(this.Context, sql);
|
||
|
||
if (data != null && data.Count > 0)
|
||
{
|
||
BillCodeIdx = data[0]["RN"].Long2Int();
|
||
}
|
||
}
|
||
|
||
public static bool GetBarCodeStatus(Context ctx, string barCode, string formID)
|
||
{
|
||
string empty = string.Empty;
|
||
empty = @"
|
||
SELECT FBARCODEINVSTATUS
|
||
FROM T_BD_BARCODEMAIN
|
||
WHERE FBARCODE=@barCode ";
|
||
List<SqlParam> list = new List<SqlParam>();
|
||
list.Add(new SqlParam("@barCode", KDDbType.String, barCode));
|
||
string text = DBUtils.ExecuteScalar(ctx, empty, "", list.ToArray());
|
||
if (!string.IsNullOrWhiteSpace(text) && text.EqualsIgnoreCase("1"))
|
||
{
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
public override void DataChanged(DataChangedEventArgs e)
|
||
{
|
||
base.DataChanged(e);
|
||
switch (e.Field.Key.ToUpperInvariant())
|
||
{
|
||
case "FSOURCEBILLNAME":
|
||
{
|
||
sourceBillFormId = e.NewValue as string;
|
||
if (!sourceBillFormId.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
switch (sourceBillFormId.ToUpper())
|
||
{
|
||
case "PRD_MO":
|
||
middleBillFormId = "PRD_MORPT";
|
||
break;
|
||
}
|
||
}
|
||
|
||
DynamicObject dynamicObject = base.View.Model.GetValue("FSOURCEBILLNAME") as DynamicObject;
|
||
|
||
_sourceBillIds = null;
|
||
_sourceBillNos = null;
|
||
_sourceBillNoToIds = null;
|
||
base.View.Model.SetValue("FSOURCEBILLID", null);
|
||
if (dynamicObject != null && Convert.ToInt32(dynamicObject["ModelTypeId"]) != 100)
|
||
{
|
||
base.View.GetControl("FSourceBillId").Enabled = false;
|
||
}
|
||
else
|
||
{
|
||
base.View.GetControl("FSourceBillId").Enabled = true;
|
||
}
|
||
|
||
GetSourceBillTypeKeyProperty(sourceBillFormId);
|
||
ClearMatchData();
|
||
|
||
break;
|
||
}
|
||
case "FALLOWDELETE":
|
||
isAllowDelete = Convert.ToBoolean(e.NewValue);
|
||
break;
|
||
case "FISMAPTOSOURCEBILL":
|
||
needMatchToSourceBill = Convert.ToBoolean(e.NewValue);
|
||
if (needMatchToSourceBill)
|
||
{
|
||
if (!sourceBillFormId.IsNullOrEmptyOrWhiteSpace() && billFormMetaData == null)
|
||
{
|
||
billFormMetaData = (FormMetadata)MetaDataServiceHelper.Load(base.Context, sourceBillFormId);
|
||
}
|
||
|
||
lstMatchItem = GetMatchRuleContent();
|
||
MatchScanData();
|
||
}
|
||
else
|
||
{
|
||
ClearMatchData();
|
||
}
|
||
|
||
break;
|
||
case "FBARCODERULE":
|
||
barcodeRule = base.View.Model.GetValue("FBarCodeRule") as DynamicObject;
|
||
barcodeRuleId = ((barcodeRule != null) ? Convert.ToInt32(barcodeRule["Id"]) : 0);
|
||
barcodeRuleEntities = BarCodeCommonServiceHelper.GetBarCodeRuleById(base.Context, barcodeRuleId);
|
||
|
||
SetBarCodeRuleId();
|
||
break;
|
||
case "FDEFAULTSCANNUMBER":
|
||
defaultScanNumber = Convert.ToInt32(e.NewValue);
|
||
if (defaultScanNumber == 0)
|
||
{
|
||
base.View.ShowNotificationMessage(ResManager.LoadKDString("每次默认扫描数量不可为0!", "0011019000003081", SubSystemType.BASE));
|
||
base.View.Model.SetValue("FDEFAULTSCANNUMBER", 1);
|
||
}
|
||
|
||
break;
|
||
case "FCREATEDBILLNAME":
|
||
createBillFormId = e.NewValue as string;
|
||
if (!createBillFormId.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
tagbillFormMetaData = (FormMetadata)MetaDataServiceHelper.Load(base.Context, createBillFormId);
|
||
}
|
||
else
|
||
{
|
||
tagbillFormMetaData = null;
|
||
}
|
||
|
||
base.View.Model.SetValue("FCreatedBillType", null);
|
||
break;
|
||
case "FCKBARCODERULE":
|
||
isCKBarCodeRule = Convert.ToBoolean(e.NewValue);
|
||
if (!isCKBarCodeRule)
|
||
{
|
||
base.View.Model.SetValue("FBARCODERULE", 0);
|
||
barcodeRuleId = 0L;
|
||
barcodeRule = null;
|
||
barcodeRuleEntities = null;
|
||
}
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
public override void BeforeF7Select(BeforeF7SelectEventArgs e)
|
||
{
|
||
switch (e.FieldKey.ToUpperInvariant())
|
||
{
|
||
case "FSOURCEBILLID":
|
||
if (!sourceBillFormId.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
if (base.View.Model.GetValue("FSOURCEBILLNAME") is DynamicObject dynamicObject3 && Convert.ToInt32(dynamicObject3["ModelTypeId"]) == 100)
|
||
{
|
||
//ShowSelectBillForm(sourceBillFormId);
|
||
OpenBarCodeGetBill(sourceBillFormId);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
base.View.ShowNotificationMessage(ResManager.LoadKDString("请先选择业务对象名称!", "0011019000003816", SubSystemType.BASE));
|
||
}
|
||
|
||
break;
|
||
case "FSOURCEBILLNAME":
|
||
case "FCREATEDBILLNAME":
|
||
{
|
||
if (!isCKBarCodeRule)
|
||
{
|
||
break;
|
||
}
|
||
|
||
barcodeRule = base.View.Model.GetValue("FBarCodeRule") as DynamicObject;
|
||
barcodeRuleId = ((barcodeRule != null) ? Convert.ToInt32(barcodeRule["Id"]) : 0);
|
||
if (barcodeRuleId == 0)
|
||
{
|
||
base.View.ShowNotificationMessage(ResManager.LoadKDString("请先选择条码规则!", "0011019000003169", SubSystemType.BASE));
|
||
e.Cancel = true;
|
||
break;
|
||
}
|
||
|
||
DynamicObject dynamicObject2 = BarCodeCommonServiceHelper.GetBarCodeRuleById(base.Context, barcodeRuleId).FirstOrDefault();
|
||
DynamicObjectCollection source = dynamicObject2["BD_BARCODERULEENTRYToBill"] as DynamicObjectCollection;
|
||
List<string> values = source.Select((DynamicObject b) => Convert.ToString(b["BillId_Id"])).ToList();
|
||
string arg = "FID";
|
||
string filter2 = string.Format("{0} IN ('{1}')", arg, string.Join("','", values));
|
||
e.ListFilterParameter.Filter = filter2;
|
||
break;
|
||
}
|
||
case "FCREATEDBILLTYPE":
|
||
{
|
||
DynamicObject dynamicObject = base.View.Model.GetValue("FCREATEDBILLNAME") as DynamicObject;
|
||
createBillFormId = ((dynamicObject == null) ? "" : Convert.ToString(dynamicObject["Id"]));
|
||
if (createBillFormId.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
base.View.ShowMessage(ResManager.LoadKDString(ResManager.LoadKDString(ResManager.LoadKDString("请先选择生成单据名称!", "f5502ba0733042e9", "APP_ISVPAAC2016062210550"), "af9bdd7c5e6d4abc", "APP_ISVPAAC2016062210550"), "0011019000003170", SubSystemType.BASE));
|
||
e.Cancel = true;
|
||
break;
|
||
}
|
||
|
||
List<string> billTypesByBillName = BarCodeScanServiceHelper.GetBillTypesByBillName(base.Context, createBillFormId);
|
||
if (!billTypesByBillName.IsNullOrEmpty() && billTypesByBillName.Count > 0)
|
||
{
|
||
string filter = string.Format("FBILLTYPEID IN ('{0}')", string.Join("','", billTypesByBillName));
|
||
e.ListFilterParameter.Filter = filter;
|
||
}
|
||
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
public override void BarItemClick(BarItemClickEventArgs e)
|
||
{
|
||
base.BarItemClick(e);
|
||
string text = e.BarItemKey.ToUpperInvariant();
|
||
if (!(text == "TBBTNSCANLOG"))
|
||
{
|
||
if (!(text == "TBSPLITSUBMIT"))
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (base.View.Model.DataChanged)
|
||
{
|
||
base.View.ShowErrMessage(ResManager.LoadKDString("数据已更改,请先保存!", "0011019000003087", SubSystemType.BASE));
|
||
return;
|
||
}
|
||
|
||
if (Convert.ToString(base.View.Model.GetValue("FDocumentStatus")).EqualsIgnoreCase("B"))
|
||
{
|
||
base.View.ShowErrMessage(ResManager.LoadKDString("已经生成单据,不能重复生成。", "0011019000003278", SubSystemType.BASE));
|
||
return;
|
||
}
|
||
|
||
DynamicObject dynamicObject = base.View.Model.GetValue("FCreatedBillName") as DynamicObject;
|
||
createBillFormId = ((dynamicObject != null) ? (dynamicObject["Id"] as string) : string.Empty);
|
||
string createdBillType = ((base.View.Model.GetValue("FCreatedBillType") is DynamicObject dynamicObject2) ? (dynamicObject2["Id"] as string) : string.Empty);
|
||
if (createdBillType.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
base.View.ShowMessage(ResManager.LoadKDString("请录入生成单据类型以提交单据!", "0011019000003171", SubSystemType.BASE));
|
||
}
|
||
else
|
||
{
|
||
if (base.View.Model.GetEntryRowCount("FScanSummaryEntity") <= 0)
|
||
{
|
||
return;
|
||
}
|
||
|
||
barcodeRule = base.View.Model.GetValue("FBarCodeRule") as DynamicObject;
|
||
barcodeRuleId = ((barcodeRule != null) ? Convert.ToInt32(barcodeRule["Id"]) : 0);
|
||
DynamicObject doRule = GetBarCodeRuleById(base.Context, barcodeRuleId).FirstOrDefault();
|
||
if (IsAvailableRule(doRule, createBillFormId))
|
||
{
|
||
try
|
||
{
|
||
Entity entity = base.View.BusinessInfo.GetEntity("FScanSummaryEntity");
|
||
DynamicObjectCollection entityDataObject = base.View.Model.GetEntityDataObject(entity);
|
||
long scanFid = Convert.ToInt64(base.View.Model.GetPKValue());
|
||
long num = 0L;
|
||
bool isSave = Convert.ToBoolean(base.View.Model.GetValue("FIsSave"));
|
||
bool isAudit = Convert.ToBoolean(base.View.Model.GetValue("FIsAudit"));
|
||
try
|
||
{
|
||
if (sourceBillFormId.ToUpper().Equals("PRD_MO"))
|
||
DoPush("PRD_MORPT", createBillFormId, out num);
|
||
else if (sourceBillFormId.ToUpper().Equals("UHIK_PRD_PACKAGE_INSTOCK"))
|
||
DoPush("PRD_MORPT", createBillFormId, out num);
|
||
else
|
||
DoPush(sourceBillFormId, createBillFormId, out num);
|
||
|
||
base.View.Model.SetValue("FDocumentStatus", "B");
|
||
base.View.Model.SetValue("FSubmitUserId", base.Context.UserId);
|
||
base.View.Model.SetValue("FSubmitDate", DateTime.Now.Date);
|
||
base.View.Model.DataChanged = false;
|
||
isFailure = false;
|
||
AfterCreateBillAutoNewBill(barcodeRuleId, sourceBillFormId, createBillFormId, createdBillType);
|
||
bool flag = Convert.ToBoolean(base.View.Model.GetValue("FAutoOpenTargetBill"));
|
||
if (num > 0 && flag)
|
||
{
|
||
ShowTargetForm(createBillFormId, num);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string text3 = ResManager.LoadKDString("生成单据失败!", "0011019000003252", SubSystemType.BASE);
|
||
base.View.ShowErrMessage(text3 + ex.Message);
|
||
base.View.Model.DataChanged = false;
|
||
isFailure = true;
|
||
}
|
||
|
||
base.View.InvokeFormOperation("Save");
|
||
base.View.UpdateView();
|
||
return;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string text4 = ResManager.LoadKDString("生成单据失败,可能由以下原因导致:1、生成单据类型仅支持关联生成。", "0011019000003374", SubSystemType.BASE);
|
||
base.View.ShowErrMessage(text4 + ex.Message);
|
||
return;
|
||
}
|
||
}
|
||
|
||
base.View.ShowMessage(ResManager.LoadKDString("条码规则不支持生成单据名称!", "0011019000003084", SubSystemType.BASE));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ListShowParameter listShowParameter = new ListShowParameter();
|
||
listShowParameter.ParentPageId = base.View.PageId;
|
||
listShowParameter.MultiSelect = false;
|
||
listShowParameter.FormId = "BD_BarCodeScanLog";
|
||
listShowParameter.OpenStyle.ShowType = ShowType.MainNewTabPage;
|
||
base.View.ShowForm(listShowParameter);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 执行单据转换
|
||
/// </summary>
|
||
/// <param name="sourceFormId">源单据标识</param>
|
||
/// <param name="targetFormId"></param>
|
||
/// <param name="sbillNo">目标单据标识</param>
|
||
/// <exception cref="Exception"></exception>
|
||
private void DoPush(string sourceFormId, string targetFormId, out long billId)
|
||
{
|
||
IConvertService service = ServiceHelper.GetService<IConvertService>();
|
||
billId = 0;
|
||
//获取启用中的规则,按照是否默认,创建日期进行排序
|
||
var crSqlL = $@"/*dialect*/
|
||
SELECT TOP 1 FID
|
||
,FKERNELXML.query('//ConvertRule/Policies/DefaultConvertPolicy/SourceEntryKey').value('(SourceEntryKey)[1]','varchar(max)') as 'SourceEntryKey'
|
||
,FKERNELXML.query('//ConvertRule/Policies/DefaultConvertPolicy/TargetEntryKey').value('(TargetEntryKey)[1]','varchar(max)') as 'TargetEntryKey'
|
||
FROM T_META_CONVERTRULE t0
|
||
WHERE 1 = 1
|
||
AND t0.FSOURCEFORMID = '{sourceFormId}'
|
||
AND t0.FTARGETFORMID = '{targetFormId}'
|
||
AND t0.FSTATUS = 1
|
||
AND t0.FDEVTYPE = 0
|
||
ORDER BY t0.FISDEFAULT DESC,t0.FMODIFYDATE DESC
|
||
|
||
";
|
||
|
||
var resData = DBUtils.ExecuteDynamicObject(this.Context, crSqlL);
|
||
|
||
if (!(resData != null && resData.Count > 0))
|
||
throw new Exception($"需要转换源单据({sourceFormId})的目标单({targetFormId})据不存在转换规则!");
|
||
|
||
//转换规则
|
||
string convertRuleId = resData[0]["FID"].ToString();
|
||
|
||
var ruleMeta = service.GetConvertRule(this.Context, convertRuleId);
|
||
|
||
if (ruleMeta == null)
|
||
throw new Exception($"需要转换源单据({sourceFormId})的目标单({targetFormId})据不存在转换规则!");
|
||
|
||
//获取元数据服务
|
||
IMetaDataService metadataService = ServiceHelper.GetService<IMetaDataService>();
|
||
|
||
//获取ViewService
|
||
IViewService viewService = ServiceHelper.GetService<IViewService>();
|
||
//获取源单元数据
|
||
FormMetadata sourceMetada = metadataService.Load(this.Context, sourceFormId) as FormMetadata;
|
||
|
||
#region 获取数量转换字段
|
||
var sqlL = $@"/*dialect*/
|
||
IF EXISTS (SELECT 1 WHERE OBJECT_ID('tempdb..#查询结果') IS NOT NULL)
|
||
BEGIN
|
||
DROP TABLE [dbo].[#查询结果]
|
||
END
|
||
|
||
DECLARE @FromId varchar(100),@TargetFromId varchar(100)
|
||
|
||
SET @FromId = '{sourceFormId}'
|
||
SET @TargetFromId = '{targetFormId}'
|
||
CREATE TABLE #查询结果 (
|
||
FromId Nvarchar(100)
|
||
,FromName Nvarchar(100)
|
||
,HeadTableName Nvarchar(100)
|
||
,SourceEntryKey Nvarchar(100)
|
||
,TargetEntryKey Nvarchar(100)
|
||
,FFIELDKEY Nvarchar(100)
|
||
,TargetFromId Nvarchar(100)
|
||
,QtyFieldName Nvarchar(100)
|
||
,FKERNELXML xml
|
||
)
|
||
|
||
INSERT INTO #查询结果
|
||
SELECT t0.FID,t0_l.FNAME
|
||
,t0.FKERNELXML.query('//HeadEntity/TableName').value('(TableName)[1]','varchar(max)') as '单据头表名'
|
||
,REPLACE(t1e.FFIELDKEY,'FSeq','') AS 'SourceEntryKey'
|
||
,REPLACE(t2e.FFIELDKEY,'FSeq','') AS 'TargetEntryKey'
|
||
,t3e.FFIELDKEY
|
||
,@TargetFromId
|
||
,''
|
||
,t0.FKERNELXML
|
||
FROM T_META_OBJECTTYPE t0
|
||
INNER JOIN T_META_OBJECTTYPE_L t0_l on t0.FID = t0_l.FID AND t0_l.FLOCALEID = 2052
|
||
INNER JOIN T_BD_BARCODEITEMENTRY t1e on t1e.FBILLFORMID = t0.FID
|
||
INNER JOIN T_BD_BARCODEITEM t1 on t1.FID = t1e.FID AND t1.FBARCODEFIELDKEY = 'FBILLSEQ'
|
||
INNER JOIN T_BD_BARCODEITEMENTRY t2e on t2e.FID = t1.FID AND t2e.FBILLFORMID = @TargetFromId
|
||
INNER JOIN T_BD_BARCODEITEMENTRY t3e on t3e.FBILLFORMID = t2e.FBILLFORMID
|
||
INNER JOIN T_BD_BARCODEITEM t3 on t3.FID = t3e.FID AND t3.FBARCODEFIELDKEY = 'FQTY'
|
||
WHERE 1=1
|
||
AND t0.FID = @FromId
|
||
AND FISTEMPLATE = 0
|
||
AND FDEVTYPE != 2
|
||
AND FMODELTYPEID = 100
|
||
|
||
DECLARE @QtyFieldkey varchar(100)
|
||
SELECT @QtyFieldkey = FFIELDKEY
|
||
FROM #查询结果
|
||
|
||
EXEC (N'
|
||
|
||
UPDATE t2 SET t2.QtyFieldName = t0.FKERNELXML.query(''//QtyField[Key=""'+ @QtyFieldkey + '""]/PropertyName'').value(''(PropertyName)[1]'',''varchar(max)'')
|
||
FROM T_META_OBJECTTYPE t0
|
||
INNER JOIN T_BD_BARCODEITEMENTRY t1e on t1e.FBILLFORMID = t0.FID
|
||
INNER JOIN T_BD_BARCODEITEM t1 on t1.FID = t1e.FID AND t1.FBARCODEFIELDKEY = ''FQTY''
|
||
INNER JOIN #查询结果 t2 on t2.TargetFromId = t0.FID
|
||
WHERE 1 = 1
|
||
AND t0.FISTEMPLATE = 0
|
||
AND t0.FDEVTYPE != 2
|
||
AND t0.FMODELTYPEID = 100
|
||
')
|
||
|
||
SELECT* FROM #查询结果
|
||
";
|
||
var entryResData = DBUtils.ExecuteDynamicObject(this.Context, sqlL);
|
||
var entryRes = entryResData[0];
|
||
|
||
#endregion
|
||
|
||
#region 获取单据的entryId
|
||
var scanEntity = this.View.Model.BillBusinessInfo.GetEntryEntity("FScanDetailEntity");
|
||
var scanRows = this.View.Model.GetEntityDataObject(scanEntity);
|
||
var unionTableList = scanRows.Select(row => $" SELECT '{row["BillCode"]}' BillNo,{row["BillSeq"].Long2Int()} FSEQ,{row["Qty"]} Qty , {row["StockerId_Id"]} StockerId").ToList();
|
||
|
||
var sql = string.Empty;
|
||
if (sourceBillFormId.ToUpper().Equals("PRD_MO"))
|
||
{
|
||
sql = $@"
|
||
;WITH #基础数据 AS (
|
||
SELECT tt.BillNo,tt.FSEQ,tt.StockerId,SUM(tt.Qty) AS 'QTY'
|
||
FROM (
|
||
{string.Join(" UNION ALL ", unionTableList)}
|
||
) tt
|
||
GROUP BY tt.BillNo,tt.FSEQ,tt.StockerId
|
||
), #汇报单数据 AS (
|
||
SELECT t1e.FMOBILLNO,t1e.FMOID,t1e.FMOENTRYID,t1e.FMOENTRYSEQ
|
||
,t1.FBILLNO,t1e.FENTRYID AS 'ENTRYID',t1e.FID AS 'ID'
|
||
,t1e.FFINISHQTY,t1e.FLot_Text FLot
|
||
FROM T_PRD_MORPT t1
|
||
INNER JOIN T_PRD_MORPTENTRY t1e ON t1e.FID = t1.FID
|
||
INNER JOIN #基础数据 ss ON ss.BillNo = t1e.FMOBILLNO AND ss.FSEQ = t1e.FMOENTRYSEQ
|
||
WHERE t1.FDOCUMENTSTATUS = 'C'
|
||
), #数据分配 AS (
|
||
SELECT *
|
||
,SUM(FFINISHQTY) OVER(PARTITION BY t0.FMOBILLNO,t0.FMOENTRYSEQ ORDER BY ENTRYID,ID) AS GrandQty
|
||
,ROW_NUMBER() OVER (PARTITION BY t0.FMOBILLNO,t0.FMOENTRYSEQ ORDER BY ENTRYID,ID) AS x
|
||
,COUNT(1) OVER (PARTITION BY t0.FMOBILLNO,t0.FMOENTRYSEQ ORDER BY FMOBILLNO) AS y
|
||
FROM #汇报单数据 t0
|
||
)
|
||
SELECT *
|
||
FROM #基础数据 tt
|
||
CROSS APPLY (
|
||
SELECT t0.ENTRYID,t0.ID,t0.FLot
|
||
,CASE WHEN GrandQty <= tt.Qty THEN
|
||
(CASE WHEN x = y THEN ISNULL(LAG(GrandQty,1) OVER(ORDER BY t0.ENTRYID),LAG(GrandQty,0) OVER(ORDER BY t0.ENTRYID)) ELSE FFINISHQTY END)
|
||
ELSE (CASE WHEN t0.FFINISHQTY -(GrandQty - tt.Qty) < 0 THEN 0 ELSE t0.FFINISHQTY -(GrandQty - tt.Qty) END)
|
||
END AS AvgQty
|
||
FROM #数据分配 t0
|
||
WHERE tt.BillNo = t0.FMOBILLNO AND tt.FSEQ = t0.FMOENTRYSEQ
|
||
) t1
|
||
WHERE t1.AvgQty > 0
|
||
|
||
";
|
||
}
|
||
else if (sourceBillFormId.ToUpper().Equals("UHIK_PRD_PACKAGE_INSTOCK"))
|
||
{
|
||
sql = $@"
|
||
;WITH #基础数据 AS (
|
||
SELECT tt.BillNo,tt.FSEQ
|
||
,QTY
|
||
FROM (
|
||
{string.Join(" UNION ALL ", unionTableList)}
|
||
) tt
|
||
), #组装单数据 AS (
|
||
SELECT t1e.FMOBILLNO,t1e.FMOID,t1e.FMOENTRYID,t1e.FMOENTRYSEQ
|
||
,t1.FBILLNO,t1e.FENTRYID AS 'ENTRYID',t1e.FID AS 'ID'
|
||
,t1e.FQTY FFINISHQTY,t1e.FLot_Text FLot
|
||
,t1e.FSeq
|
||
FROM T_PRD_PACKAGEINSTOCK t1
|
||
INNER JOIN T_PRD_PACKAGEINSTOCKENTRY t1e ON t1e.FID = t1.FID
|
||
INNER JOIN #基础数据 ss ON ss.BillNo = t1.FBILLNO
|
||
WHERE t1.FDOCUMENTSTATUS = 'C'
|
||
)
|
||
, #数据分配 AS (
|
||
SELECT *
|
||
,SUM(FFINISHQTY) OVER(PARTITION BY t0.FBILLNO,t0.FSEQ ORDER BY ENTRYID,ID) AS GrandQty
|
||
,ROW_NUMBER() OVER (PARTITION BY t0.FBILLNO,t0.FSEQ ORDER BY ENTRYID,ID) AS x
|
||
,COUNT(1) OVER (PARTITION BY t0.FBILLNO,t0.FSEQ ORDER BY FMOBILLNO) AS y
|
||
FROM #组装单数据 t0
|
||
)
|
||
SELECT *
|
||
FROM #基础数据 tt
|
||
CROSS APPLY (
|
||
SELECT t0.ENTRYID,t0.ID,t0.FLot
|
||
,CASE WHEN GrandQty <= tt.Qty THEN
|
||
(CASE WHEN x = y THEN ISNULL(LAG(GrandQty,1) OVER(ORDER BY t0.ENTRYID),LAG(GrandQty,0) OVER(ORDER BY t0.ENTRYID)) ELSE FFINISHQTY END)
|
||
ELSE (CASE WHEN t0.FFINISHQTY -(GrandQty - tt.Qty) < 0 THEN 0 ELSE t0.FFINISHQTY -(GrandQty - tt.Qty) END)
|
||
END AS AvgQty
|
||
FROM #数据分配 t0
|
||
WHERE tt.BillNo = t0.FBILLNO
|
||
) t1
|
||
WHERE t1.AvgQty > 0
|
||
";
|
||
}
|
||
else
|
||
{
|
||
sql = $@"
|
||
SELECT *
|
||
INTO #seqSet
|
||
FROM (
|
||
{string.Join(" UNION ALL ", unionTableList)}
|
||
)tt
|
||
|
||
SELECT t0.FBILLNO,'' ID
|
||
,t0e.FENTRYID ENTRYID,t0e.FSEQ
|
||
,ss.Qty
|
||
FROM {entryRes["HeadTableName"].ToString()} t0
|
||
INNER JOIN {entryRes["HeadTableName"].ToString() + "Entry"} t0e on t0.FID = t0e.FID
|
||
INNER JOIN #seqSet ss on ss.BillNo = t0.FBILLNO AND ss.FSEQ = t0e.FSEQ
|
||
WHERE 1 = 1 AND t0.FDOCUMENTSTATUS = 'C'
|
||
";
|
||
}
|
||
var dbList = DBUtils.ExecuteDynamicObject(this.Context, $"/*dialect*/{sql}");
|
||
#endregion
|
||
|
||
//目标单据类型
|
||
var createdBillType = this.View.Model.GetValue("FCreatedBillType") as DynamicObject;
|
||
var createdBillTypeId = createdBillType["Id"].ToString();
|
||
|
||
if (dbList != null && dbList.Count() > 0)
|
||
{
|
||
if (sourceBillFormId.ToUpper().Equals("UHIK_PRD_PACKAGE_INSTOCK"))
|
||
{
|
||
List<ListSelectedRow> selectedRows = dbList.Select(x => new ListSelectedRow(x["ID"].ToString(), x["ENTRYID"].ToString(), 0, sourceFormId) { EntryEntityKey = resData[0]["SourceEntryKey"].ToString() }).ToList();
|
||
|
||
foreach (var row in selectedRows)
|
||
{
|
||
var rows = new List<ListSelectedRow>();
|
||
rows.Add(row);
|
||
PushArgs pushArgs = new PushArgs(ruleMeta.Rule, rows.ToArray());//下推入口参数
|
||
|
||
pushArgs.TargetBillTypeId = createdBillTypeId;
|
||
pushArgs.CustomParams = new Dictionary<string, object>();
|
||
pushArgs.CustomParams.Add("ScanEntry", dbList);
|
||
OperateOption option = OperateOption.Create();//选项参数
|
||
|
||
//不按照整单下推
|
||
option.SetVariableValue(ConvertConst.SelectByBillId, false);
|
||
|
||
try
|
||
{
|
||
|
||
//源单数据转换目标数据
|
||
ConvertOperationResult convertResult = service.Push(this.Context, pushArgs, option);
|
||
|
||
DynamicObject[] destObjs = convertResult.TargetDataEntities.Select(r => r.DataEntity).ToArray();
|
||
|
||
FormMetadata destFormMetadata = metadataService.Load(this.Context, targetFormId) as FormMetadata;
|
||
|
||
string msg = string.Empty;
|
||
|
||
#region 自动保存
|
||
IOperationResult saveResult = ServiceHelper.GetService<ISaveService>().Save(this.Context, destFormMetadata.BusinessInfo, destObjs, OperateOption.Create());
|
||
|
||
if (!saveResult.IsSuccess)
|
||
{
|
||
if (saveResult.ValidationErrors != null && saveResult.ValidationErrors.Count > 0)
|
||
{
|
||
var errorInfo = string.Join(";", saveResult.ValidationErrors.Select(x => x.Message));
|
||
|
||
throw new KDBusinessException("", "未知原因导致自动保存失败原因:" + errorInfo);
|
||
}
|
||
|
||
throw new KDBusinessException("", "未知原因导致自动保存失败原因:" + JsonUtil.SerializeWithOutNull(saveResult));
|
||
}
|
||
#endregion
|
||
|
||
var isAudit = this.View.Model.GetValue("FIsAudit").Long2Int();
|
||
|
||
object[] pkArray = (from p in destObjs select p[0]).ToArray();
|
||
//if (isAudit == 1)
|
||
//{
|
||
#region 自动提交
|
||
|
||
//设置提交参数
|
||
IOperationResult submitResult = ServiceHelper.GetService<ISubmitService>().Submit(this.Context, destFormMetadata.BusinessInfo, pkArray, "Submit", OperateOption.Create());
|
||
|
||
// 判断提交结果,如果失败,则内部会抛出错误,回滚代码
|
||
if (submitResult.IsSuccess == false)
|
||
{
|
||
throw new KDBusinessException("", "未知原因导致自动提交失败!");
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 自动审核
|
||
|
||
//设置审核参数
|
||
IOperationResult auditResult = ServiceHelper.GetService<IAuditService>().Audit(this.Context, destFormMetadata.BusinessInfo, pkArray, OperateOption.Create());
|
||
// 判断提交结果,如果失败,则内部会抛出错误,回滚代码
|
||
if (auditResult.IsSuccess == false)
|
||
{
|
||
throw new KDBusinessException("", "未知原因导致自动审核失败!");
|
||
}
|
||
|
||
#endregion
|
||
//}
|
||
|
||
billId = pkArray[0].Long2Int();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
List<ListSelectedRow> selectedRows = dbList.Select(x => new ListSelectedRow(x["ID"].ToString(), x["ENTRYID"].ToString(), 0, sourceFormId) { EntryEntityKey = resData[0]["SourceEntryKey"].ToString() }).ToList();
|
||
|
||
PushArgs pushArgs = new PushArgs(ruleMeta.Rule, selectedRows.ToArray());//下推入口参数
|
||
|
||
pushArgs.TargetBillTypeId = createdBillTypeId;
|
||
pushArgs.CustomParams = new Dictionary<string, object>();
|
||
pushArgs.CustomParams.Add("ScanEntry", dbList);
|
||
OperateOption option = OperateOption.Create();//选项参数
|
||
|
||
//不按照整单下推
|
||
option.SetVariableValue(ConvertConst.SelectByBillId, false);
|
||
|
||
try
|
||
{
|
||
|
||
//源单数据转换目标数据
|
||
ConvertOperationResult convertResult = service.Push(this.Context, pushArgs, option);
|
||
|
||
DynamicObject[] destObjs = convertResult.TargetDataEntities.Select(r => r.DataEntity).ToArray();
|
||
|
||
FormMetadata destFormMetadata = metadataService.Load(this.Context, targetFormId) as FormMetadata;
|
||
|
||
string msg = string.Empty;
|
||
|
||
#region 自动保存
|
||
IOperationResult saveResult = ServiceHelper.GetService<ISaveService>().Save(this.Context, destFormMetadata.BusinessInfo, destObjs, OperateOption.Create());
|
||
|
||
if (!saveResult.IsSuccess)
|
||
{
|
||
if (saveResult.ValidationErrors != null && saveResult.ValidationErrors.Count > 0)
|
||
{
|
||
var errorInfo = string.Join(";", saveResult.ValidationErrors.Select(x => x.Message));
|
||
|
||
throw new KDBusinessException("", "未知原因导致自动保存失败原因:" + errorInfo);
|
||
}
|
||
|
||
throw new KDBusinessException("", "未知原因导致自动保存失败原因:" + JsonUtil.SerializeWithOutNull(saveResult));
|
||
}
|
||
#endregion
|
||
|
||
var isAudit = this.View.Model.GetValue("FIsAudit").Long2Int();
|
||
|
||
object[] pkArray = (from p in destObjs select p[0]).ToArray();
|
||
if (isAudit == 1)
|
||
{
|
||
#region 自动提交
|
||
|
||
//设置提交参数
|
||
IOperationResult submitResult = ServiceHelper.GetService<ISubmitService>().Submit(this.Context, destFormMetadata.BusinessInfo, pkArray, "Submit", OperateOption.Create());
|
||
|
||
// 判断提交结果,如果失败,则内部会抛出错误,回滚代码
|
||
if (submitResult.IsSuccess == false)
|
||
{
|
||
throw new KDBusinessException("", "未知原因导致自动提交失败!");
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 自动审核
|
||
|
||
//设置审核参数
|
||
IOperationResult auditResult = ServiceHelper.GetService<IAuditService>().Audit(this.Context, destFormMetadata.BusinessInfo, pkArray, OperateOption.Create());
|
||
// 判断提交结果,如果失败,则内部会抛出错误,回滚代码
|
||
if (auditResult.IsSuccess == false)
|
||
{
|
||
throw new KDBusinessException("", "未知原因导致自动审核失败!");
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
|
||
billId = pkArray[0].Long2Int();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//this.View.ShowErrMessage("数据不存在,请检查");
|
||
throw new Exception("数据不存在,请检查二维码数据是否正确!");
|
||
}
|
||
}
|
||
|
||
private void DoCheckPush(string sourceFormId, string targetFormId)
|
||
{
|
||
IConvertService service = ServiceHelper.GetService<IConvertService>();
|
||
//获取启用中的规则,按照是否默认,创建日期进行排序
|
||
var crSqlL = $@"/*dialect*/
|
||
SELECT TOP 1 FID
|
||
,FKERNELXML.query('//ConvertRule/Policies/DefaultConvertPolicy/SourceEntryKey').value('(SourceEntryKey)[1]','varchar(max)') as 'SourceEntryKey'
|
||
,FKERNELXML.query('//ConvertRule/Policies/DefaultConvertPolicy/TargetEntryKey').value('(TargetEntryKey)[1]','varchar(max)') as 'TargetEntryKey'
|
||
FROM T_META_CONVERTRULE t0
|
||
WHERE 1 = 1
|
||
AND t0.FSOURCEFORMID = '{sourceFormId}'
|
||
AND t0.FTARGETFORMID = '{targetFormId}'
|
||
AND t0.FSTATUS = 1
|
||
AND t0.FDEVTYPE = 0
|
||
ORDER BY t0.FISDEFAULT DESC,t0.FMODIFYDATE DESC
|
||
|
||
";
|
||
|
||
var resData = DBUtils.ExecuteDynamicObject(this.Context, crSqlL);
|
||
|
||
if (!(resData != null && resData.Count > 0))
|
||
throw new Exception($"需要转换源单据({sourceFormId})的目标单({targetFormId})据不存在转换规则!");
|
||
|
||
//转换规则
|
||
string convertRuleId = resData[0]["FID"].ToString();
|
||
|
||
var ruleMeta = service.GetConvertRule(this.Context, convertRuleId);
|
||
|
||
if (ruleMeta == null)
|
||
throw new Exception($"需要转换源单据({sourceFormId})的目标单({targetFormId})据不存在转换规则!");
|
||
|
||
//获取元数据服务
|
||
IMetaDataService metadataService = ServiceHelper.GetService<IMetaDataService>();
|
||
|
||
//获取ViewService
|
||
IViewService viewService = ServiceHelper.GetService<IViewService>();
|
||
//获取源单元数据
|
||
FormMetadata sourceMetada = metadataService.Load(this.Context, sourceFormId) as FormMetadata;
|
||
|
||
#region 获取数量转换字段
|
||
var sqlL = $@"/*dialect*/
|
||
IF EXISTS (SELECT 1 WHERE OBJECT_ID('tempdb..#查询结果') IS NOT NULL)
|
||
BEGIN
|
||
DROP TABLE [dbo].[#查询结果]
|
||
END
|
||
|
||
DECLARE @FromId varchar(100),@TargetFromId varchar(100)
|
||
|
||
SET @FromId = '{sourceFormId}'
|
||
SET @TargetFromId = '{targetFormId}'
|
||
CREATE TABLE #查询结果 (
|
||
FromId Nvarchar(100)
|
||
,FromName Nvarchar(100)
|
||
,HeadTableName Nvarchar(100)
|
||
,SourceEntryKey Nvarchar(100)
|
||
,TargetEntryKey Nvarchar(100)
|
||
,FFIELDKEY Nvarchar(100)
|
||
,TargetFromId Nvarchar(100)
|
||
,QtyFieldName Nvarchar(100)
|
||
,FKERNELXML xml
|
||
)
|
||
|
||
INSERT INTO #查询结果
|
||
SELECT t0.FID,t0_l.FNAME
|
||
,t0.FKERNELXML.query('//HeadEntity/TableName').value('(TableName)[1]','varchar(max)') as '单据头表名'
|
||
,REPLACE(t1e.FFIELDKEY,'FSeq','') AS 'SourceEntryKey'
|
||
,REPLACE(t2e.FFIELDKEY,'FSeq','') AS 'TargetEntryKey'
|
||
,t3e.FFIELDKEY
|
||
,@TargetFromId
|
||
,''
|
||
,t0.FKERNELXML
|
||
FROM T_META_OBJECTTYPE t0
|
||
INNER JOIN T_META_OBJECTTYPE_L t0_l on t0.FID = t0_l.FID AND t0_l.FLOCALEID = 2052
|
||
INNER JOIN T_BD_BARCODEITEMENTRY t1e on t1e.FBILLFORMID = t0.FID
|
||
INNER JOIN T_BD_BARCODEITEM t1 on t1.FID = t1e.FID AND t1.FBARCODEFIELDKEY = 'FBILLSEQ'
|
||
INNER JOIN T_BD_BARCODEITEMENTRY t2e on t2e.FID = t1.FID AND t2e.FBILLFORMID = @TargetFromId
|
||
INNER JOIN T_BD_BARCODEITEMENTRY t3e on t3e.FBILLFORMID = t2e.FBILLFORMID
|
||
INNER JOIN T_BD_BARCODEITEM t3 on t3.FID = t3e.FID AND t3.FBARCODEFIELDKEY = 'FQTY'
|
||
WHERE 1=1
|
||
AND t0.FID = @FromId
|
||
AND FISTEMPLATE = 0
|
||
AND FDEVTYPE != 2
|
||
AND FMODELTYPEID = 100
|
||
|
||
DECLARE @QtyFieldkey varchar(100)
|
||
SELECT @QtyFieldkey = FFIELDKEY
|
||
FROM #查询结果
|
||
|
||
EXEC (N'
|
||
|
||
UPDATE t2 SET t2.QtyFieldName = t0.FKERNELXML.query(''//QtyField[Key=""'+ @QtyFieldkey + '""]/PropertyName'').value(''(PropertyName)[1]'',''varchar(max)'')
|
||
FROM T_META_OBJECTTYPE t0
|
||
INNER JOIN T_BD_BARCODEITEMENTRY t1e on t1e.FBILLFORMID = t0.FID
|
||
INNER JOIN T_BD_BARCODEITEM t1 on t1.FID = t1e.FID AND t1.FBARCODEFIELDKEY = ''FQTY''
|
||
INNER JOIN #查询结果 t2 on t2.TargetFromId = t0.FID
|
||
WHERE 1 = 1
|
||
AND t0.FISTEMPLATE = 0
|
||
AND t0.FDEVTYPE != 2
|
||
AND t0.FMODELTYPEID = 100
|
||
')
|
||
|
||
SELECT* FROM #查询结果
|
||
";
|
||
var entryResData = DBUtils.ExecuteDynamicObject(this.Context, sqlL);
|
||
var entryRes = entryResData[0];
|
||
|
||
#endregion
|
||
|
||
#region 获取单据的entryId
|
||
var scanEntity = this.View.Model.BillBusinessInfo.GetEntryEntity("FScanDetailEntity");
|
||
var scanRows = this.View.Model.GetEntityDataObject(scanEntity);
|
||
var unionTableList = scanRows.Select(row => $" SELECT '{row["BillCode"]}' BillNo,{row["BillSeq"].Long2Int()} FSEQ,{row["Qty"]} Qty , {row["StockerId_Id"]} StockerId").ToList();
|
||
|
||
var sql = string.Empty;
|
||
if (sourceBillFormId.ToUpper().Equals("PRD_MO"))
|
||
{
|
||
sql = $@"
|
||
;WITH #基础数据 AS (
|
||
SELECT tt.BillNo,tt.FSEQ,tt.StockerId,SUM(tt.Qty) AS 'QTY'
|
||
FROM (
|
||
{string.Join(" UNION ALL ", unionTableList)}
|
||
) tt
|
||
GROUP BY tt.BillNo,tt.FSEQ,tt.StockerId
|
||
), #汇报单数据 AS (
|
||
SELECT t1e.FMOBILLNO,t1e.FMOID,t1e.FMOENTRYID,t1e.FMOENTRYSEQ
|
||
,t1.FBILLNO,t1e.FENTRYID AS 'ENTRYID',t1e.FID AS 'ID'
|
||
,t1e.FFINISHQTY,t1e.FLot_Text FLot
|
||
FROM T_PRD_MORPT t1
|
||
INNER JOIN T_PRD_MORPTENTRY t1e ON t1e.FID = t1.FID
|
||
INNER JOIN #基础数据 ss ON ss.BillNo = t1e.FMOBILLNO AND ss.FSEQ = t1e.FMOENTRYSEQ
|
||
WHERE t1.FDOCUMENTSTATUS = 'C'
|
||
), #数据分配 AS (
|
||
SELECT *
|
||
,SUM(FFINISHQTY) OVER(PARTITION BY t0.FMOBILLNO,t0.FMOENTRYSEQ ORDER BY ENTRYID,ID) AS GrandQty
|
||
,ROW_NUMBER() OVER (PARTITION BY t0.FMOBILLNO,t0.FMOENTRYSEQ ORDER BY ENTRYID,ID) AS x
|
||
,COUNT(1) OVER (PARTITION BY t0.FMOBILLNO,t0.FMOENTRYSEQ ORDER BY FMOBILLNO) AS y
|
||
FROM #汇报单数据 t0
|
||
)
|
||
SELECT *
|
||
FROM #基础数据 tt
|
||
CROSS APPLY (
|
||
SELECT t0.ENTRYID,t0.ID,t0.FLot
|
||
,CASE WHEN GrandQty <= tt.Qty THEN
|
||
(CASE WHEN x = y THEN ISNULL(LAG(GrandQty,1) OVER(ORDER BY t0.ENTRYID),LAG(GrandQty,0) OVER(ORDER BY t0.ENTRYID)) ELSE FFINISHQTY END)
|
||
ELSE (CASE WHEN t0.FFINISHQTY -(GrandQty - tt.Qty) < 0 THEN 0 ELSE t0.FFINISHQTY -(GrandQty - tt.Qty) END)
|
||
END AS AvgQty
|
||
FROM #数据分配 t0
|
||
WHERE tt.BillNo = t0.FMOBILLNO AND tt.FSEQ = t0.FMOENTRYSEQ
|
||
) t1
|
||
WHERE t1.AvgQty > 0
|
||
|
||
";
|
||
}
|
||
else if (sourceBillFormId.ToUpper().Equals("UHIK_PRD_PACKAGE_INSTOCK"))
|
||
{
|
||
sql = $@"
|
||
;WITH #基础数据 AS (
|
||
SELECT tt.BillNo,tt.FSEQ
|
||
,QTY
|
||
FROM (
|
||
{string.Join(" UNION ALL ", unionTableList)}
|
||
) tt
|
||
), #组装单数据 AS (
|
||
SELECT t1e.FMOBILLNO,t1e.FMOID,t1e.FMOENTRYID,t1e.FMOENTRYSEQ
|
||
,t1.FBILLNO,t1e.FENTRYID AS 'ENTRYID',t1e.FID AS 'ID'
|
||
,t1e.FQTY FFINISHQTY,t1e.FLot_Text FLot
|
||
,t1e.FSeq
|
||
FROM T_PRD_PACKAGEINSTOCK t1
|
||
INNER JOIN T_PRD_PACKAGEINSTOCKENTRY t1e ON t1e.FID = t1.FID
|
||
INNER JOIN #基础数据 ss ON ss.BillNo = t1.FBILLNO
|
||
WHERE t1.FDOCUMENTSTATUS = 'C'
|
||
)
|
||
, #数据分配 AS (
|
||
SELECT *
|
||
,SUM(FFINISHQTY) OVER(PARTITION BY t0.FBILLNO,t0.FSEQ ORDER BY ENTRYID,ID) AS GrandQty
|
||
,ROW_NUMBER() OVER (PARTITION BY t0.FBILLNO,t0.FSEQ ORDER BY ENTRYID,ID) AS x
|
||
,COUNT(1) OVER (PARTITION BY t0.FBILLNO,t0.FSEQ ORDER BY FMOBILLNO) AS y
|
||
FROM #组装单数据 t0
|
||
)
|
||
SELECT *
|
||
FROM #基础数据 tt
|
||
CROSS APPLY (
|
||
SELECT t0.ENTRYID,t0.ID,t0.FLot
|
||
,CASE WHEN GrandQty <= tt.Qty THEN
|
||
(CASE WHEN x = y THEN ISNULL(LAG(GrandQty,1) OVER(ORDER BY t0.ENTRYID),LAG(GrandQty,0) OVER(ORDER BY t0.ENTRYID)) ELSE FFINISHQTY END)
|
||
ELSE (CASE WHEN t0.FFINISHQTY -(GrandQty - tt.Qty) < 0 THEN 0 ELSE t0.FFINISHQTY -(GrandQty - tt.Qty) END)
|
||
END AS AvgQty
|
||
FROM #数据分配 t0
|
||
WHERE tt.BillNo = t0.FBILLNO
|
||
) t1
|
||
WHERE t1.AvgQty > 0
|
||
";
|
||
}
|
||
else
|
||
{
|
||
sql = $@"
|
||
SELECT *
|
||
INTO #seqSet
|
||
FROM (
|
||
{string.Join(" UNION ALL ", unionTableList)}
|
||
)tt
|
||
|
||
SELECT t0.FBILLNO,'' ID
|
||
,t0e.FENTRYID ENTRYID,t0e.FSEQ
|
||
,ss.Qty
|
||
FROM {entryRes["HeadTableName"].ToString()} t0
|
||
INNER JOIN {entryRes["HeadTableName"].ToString() + "Entry"} t0e on t0.FID = t0e.FID
|
||
INNER JOIN #seqSet ss on ss.BillNo = t0.FBILLNO AND ss.FSEQ = t0e.FSEQ
|
||
WHERE 1 = 1 AND t0.FDOCUMENTSTATUS = 'C'
|
||
";
|
||
}
|
||
var dbList = DBUtils.ExecuteDynamicObject(this.Context, $"/*dialect*/{sql}");
|
||
#endregion
|
||
|
||
//目标单据类型
|
||
var createdBillType = this.View.Model.GetValue("FCreatedBillType") as DynamicObject;
|
||
var createdBillTypeId = createdBillType["Id"].ToString();
|
||
|
||
if (dbList != null && dbList.Count() > 0)
|
||
{
|
||
if (sourceBillFormId.ToUpper().Equals("UHIK_PRD_PACKAGE_INSTOCK"))
|
||
{
|
||
List<ListSelectedRow> selectedRows = dbList.Select(x => new ListSelectedRow(x["ID"].ToString(), x["ENTRYID"].ToString(), 0, sourceFormId) { EntryEntityKey = resData[0]["SourceEntryKey"].ToString() }).ToList();
|
||
|
||
foreach (var row in selectedRows)
|
||
{
|
||
var rows = new List<ListSelectedRow>();
|
||
rows.Add(row);
|
||
PushArgs pushArgs = new PushArgs(ruleMeta.Rule, rows.ToArray());//下推入口参数
|
||
|
||
pushArgs.TargetBillTypeId = createdBillTypeId;
|
||
pushArgs.CustomParams = new Dictionary<string, object>();
|
||
pushArgs.CustomParams.Add("ScanEntry", dbList);
|
||
OperateOption option = OperateOption.Create();//选项参数
|
||
|
||
//不按照整单下推
|
||
option.SetVariableValue(ConvertConst.SelectByBillId, false);
|
||
|
||
try
|
||
{
|
||
//源单数据转换目标数据
|
||
ConvertOperationResult convertResult = service.Push(this.Context, pushArgs, option);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
List<ListSelectedRow> selectedRows = dbList.Select(x => new ListSelectedRow(x["ID"].ToString(), x["ENTRYID"].ToString(), 0, sourceFormId) { EntryEntityKey = resData[0]["SourceEntryKey"].ToString() }).ToList();
|
||
|
||
PushArgs pushArgs = new PushArgs(ruleMeta.Rule, selectedRows.ToArray());//下推入口参数
|
||
|
||
pushArgs.TargetBillTypeId = createdBillTypeId;
|
||
pushArgs.CustomParams = new Dictionary<string, object>();
|
||
pushArgs.CustomParams.Add("ScanEntry", dbList);
|
||
OperateOption option = OperateOption.Create();//选项参数
|
||
|
||
//不按照整单下推
|
||
option.SetVariableValue(ConvertConst.SelectByBillId, false);
|
||
|
||
try
|
||
{
|
||
//源单数据转换目标数据
|
||
ConvertOperationResult convertResult = service.Push(this.Context, pushArgs, option);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//this.View.ShowErrMessage("数据不存在,请检查");
|
||
throw new Exception("数据不存在,请检查");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建单据视图
|
||
/// </summary>
|
||
/// <param name="ctx"></param>
|
||
/// <param name="metaData"></param>
|
||
/// <returns></returns>
|
||
private IDynamicFormView CreateView(string formId)
|
||
{
|
||
FormMetadata metadata = FormMetaDataCache.GetCachedFormMetaData(this.Context, formId);
|
||
var OpenParameter = CreateOpenParameter(this.Context, metadata);
|
||
var Provider = metadata.BusinessInfo.GetForm().GetFormServiceProvider(true);
|
||
string importViewClass = "Kingdee.BOS.Web.Import.ImportBillView,Kingdee.BOS.Web";
|
||
Type type = Type.GetType(importViewClass);
|
||
IDynamicFormView view = (IDynamicFormView)Activator.CreateInstance(type);
|
||
((IDynamicFormViewService)view).Initialize(OpenParameter, Provider);
|
||
return view;
|
||
}
|
||
/// <summary>
|
||
/// 创建输入参数
|
||
/// </summary>
|
||
/// <param name="ctx"></param>
|
||
/// <param name="metaData"></param>
|
||
/// <returns></returns>
|
||
private BillOpenParameter CreateOpenParameter(Context ctx, FormMetadata metaData)
|
||
{
|
||
Form form = metaData.BusinessInfo.GetForm();
|
||
BillOpenParameter openPara = new BillOpenParameter(form.Id, metaData.GetLayoutInfo().Id);
|
||
openPara = new BillOpenParameter(form.Id, string.Empty);
|
||
openPara.Context = ctx;
|
||
openPara.ServiceName = form.FormServiceName;
|
||
openPara.PageId = Guid.NewGuid().ToString();
|
||
// 单据
|
||
openPara.FormMetaData = metaData;
|
||
openPara.LayoutId = metaData.GetLayoutInfo().Id;
|
||
// 操作相关参数
|
||
openPara.Status = OperationStatus.ADDNEW;
|
||
openPara.PkValue = null;
|
||
openPara.CreateFrom = CreateFrom.Default;
|
||
openPara.ParentId = 0;
|
||
openPara.GroupId = "";
|
||
openPara.DefaultBillTypeId = null;
|
||
openPara.DefaultBusinessFlowId = null;
|
||
// 修改主业务组织无须用户确认
|
||
openPara.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false);
|
||
// 插件
|
||
List<AbstractDynamicFormPlugIn> plugins = form.CreateFormPlugIns();
|
||
openPara.SetCustomParameter(FormConst.PlugIns, plugins);
|
||
return openPara;
|
||
}
|
||
|
||
private void GetEntryName(string xmlStr)
|
||
{
|
||
var doc = XmlUtils.LoadSecureXmlDocByStr(xmlStr);
|
||
|
||
XmlNode book;
|
||
XmlNode root = doc.DocumentElement;
|
||
|
||
book = root.SelectSingleNode("descendant::book[author/last-name='Austen']");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 生成单据成功后重新打开界面
|
||
/// </summary>
|
||
/// <param name="newbarcodeRuleId">新的条码规则</param>
|
||
/// <param name="newsourceBillFormId">新的源单对象</param>
|
||
/// <param name="newcreateBillFormId">新的生成单据对象</param>
|
||
/// <param name="newcreatedBillType">创建的单据类型</param>
|
||
private void AfterCreateBillAutoNewBill(long newbarcodeRuleId, string newsourceBillFormId, string newcreateBillFormId, string newcreatedBillType)
|
||
{
|
||
//保存条码规则默认对象生成依据
|
||
BarCodeScanServiceHelper.SaveDefaultToDB(base.Context, base.Context.UserId, sourceBillFormId, newbarcodeRuleId, newsourceBillFormId, newcreateBillFormId, newcreatedBillType);
|
||
BillShowParameter billShowParameter = new BillShowParameter();
|
||
billShowParameter.ParentPageId = base.View.PageId;
|
||
billShowParameter.MultiSelect = false;
|
||
billShowParameter.FormId = _permissionConst;
|
||
billShowParameter.OpenStyle.ShowType = ShowType.InCurrentForm;
|
||
billShowParameter.OpenStyle.TagetKey = "FMainTab";
|
||
base.View.ShowForm(billShowParameter);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取用户默认对象规则
|
||
/// </summary>
|
||
private void GetDefaultByUserID()
|
||
{
|
||
Dictionary<string, string> defaultFromDB = BarCodeScanServiceHelper.GetDefaultFromDB(base.Context, base.Context.UserId, sourceBillFormId);
|
||
if (defaultFromDB != null && defaultFromDB.Count > 0)
|
||
{
|
||
long num = Convert.ToInt64(defaultFromDB["FBarCodeRuleID"]);
|
||
string value = defaultFromDB["FSOURCEBILLID"];
|
||
string value2 = defaultFromDB["FCREATEDBILLID"];
|
||
string value3 = defaultFromDB["FCREATEDBILLTYPE"];
|
||
Model.SetValue("FBarCodeRule", num);
|
||
base.View.InvokeFieldUpdateService("FBarCodeRule", 0);
|
||
barcodeRuleId = num;
|
||
barcodeRuleEntities = BarCodeCommonServiceHelper.GetBarCodeRuleById(base.Context, num);
|
||
Model.SetValue("FSourceBillName", value);
|
||
base.View.InvokeFieldUpdateService("FSourceBillName", 0);
|
||
sourceBillFormId = value;
|
||
GetSourceBillTypeKeyProperty(sourceBillFormId);
|
||
ClearMatchData();
|
||
Model.SetValue("FCreatedBillName", value2);
|
||
base.View.InvokeFieldUpdateService("FCreatedBillName", 0);
|
||
createBillFormId = value2;
|
||
Model.SetValue("FCreatedBillType", value3);
|
||
base.View.InvokeFieldUpdateService("FCreatedBillType", 0);
|
||
}
|
||
}
|
||
|
||
public override void EntryBarItemClick(BarItemClickEventArgs e)
|
||
{
|
||
base.EntryBarItemClick(e);
|
||
string text = e.BarItemKey.ToUpperInvariant();
|
||
if (text == "TBBTNCLEAR")
|
||
{
|
||
base.View.Model.DeleteEntryData("FScanDetailEntity");
|
||
base.View.Model.DeleteEntryData("FScanSummaryEntity");
|
||
validCodeAndRowMapping.Clear();
|
||
invalidCodeAndRowMapping.Clear();
|
||
dctMatchData.Clear();
|
||
validCodeAndQtyMapping.Clear();
|
||
}
|
||
}
|
||
|
||
public override void AfterDeleteRow(AfterDeleteRowEventArgs e)
|
||
{
|
||
base.AfterDeleteRow(e);
|
||
EntryGrid control = base.View.GetControl<EntryGrid>("FScanDetailEntity");
|
||
control.SetForecolor("FBarCode", "", e.Row);
|
||
if (!e.EntityKey.EqualsIgnoreCase("FScanDetailEntity"))
|
||
{
|
||
return;
|
||
}
|
||
|
||
string text = Convert.ToString(e.DataEntity["BarCode"]);
|
||
validCodeAndRowMapping.Clear();
|
||
invalidCodeAndRowMapping.Clear();
|
||
EntryEntity entryEntity = base.View.BillBusinessInfo.GetEntryEntity("FScanDetailEntity");
|
||
DynamicObjectCollection entityDataObject = base.View.Model.GetEntityDataObject(entryEntity);
|
||
foreach (DynamicObject item in entityDataObject)
|
||
{
|
||
string text2 = Convert.ToString(item["BarCode"]);
|
||
bool flag = Convert.ToBoolean(item["IsValidCode"]);
|
||
int num = Convert.ToInt32(item["Seq"]) - 1;
|
||
if (flag && !validCodeAndRowMapping.Keys.Contains(text2))
|
||
{
|
||
validCodeAndRowMapping.Add(text2, num);
|
||
}
|
||
|
||
if (!flag)
|
||
{
|
||
invalidCodeAndRowMapping.Add(num, text2);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void SummaryScanDetail()
|
||
{
|
||
Entity entity = base.View.BusinessInfo.GetEntity("FScanSummaryEntity");
|
||
DynamicObjectCollection dynamicObjectCollection = new DynamicObjectCollection(entity.DynamicObjectType);
|
||
Entity entity2 = base.View.BusinessInfo.GetEntity("FScanDetailEntity");
|
||
DynamicObjectCollection entityDataObject = base.View.Model.GetEntityDataObject(entity2);
|
||
foreach (DynamicObject item in entityDataObject)
|
||
{
|
||
string value = Convert.ToString(item["BarCode"]);
|
||
bool flag = Convert.ToBoolean(item["IsMatched"]);
|
||
if (invalidCodeAndRowMapping.Values.Contains(value) || (needMatchToSourceBill && flag))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
DynamicObject dynamicObject = new DynamicObject(entity.DynamicObjectType);
|
||
foreach (DynamicProperty property in item.DynamicObjectType.Properties)
|
||
{
|
||
string empty = string.Empty;
|
||
empty = ((!(property.Name == "Id") && !(property.Name == "Seq")) ? ("Sum" + property.Name) : property.Name);
|
||
if (dynamicObject.DynamicObjectType.Properties.Contains(empty))
|
||
{
|
||
dynamicObject[empty] = item[property.Name];
|
||
}
|
||
}
|
||
|
||
if (dynamicObjectCollection.Count == 0)
|
||
{
|
||
dynamicObjectCollection.Add(dynamicObject);
|
||
continue;
|
||
}
|
||
|
||
bool flag2 = false;
|
||
foreach (DynamicObject item2 in dynamicObjectCollection)
|
||
{
|
||
foreach (DynamicProperty property2 in item2.DynamicObjectType.Properties)
|
||
{
|
||
if (!item2[property2].IsNullOrEmptyOrWhiteSpace() && !dynamicObject[property2].IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
flag2 = item2[property2].Equals(dynamicObject[property2]);
|
||
if (!flag2)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (flag2)
|
||
{
|
||
decimal num = Convert.ToDecimal(item2["SumQty"]);
|
||
item2["SumQty"] = num + Convert.ToDecimal(item["Qty"]);
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (!flag2)
|
||
{
|
||
dynamicObjectCollection.Add(dynamicObject);
|
||
}
|
||
}
|
||
|
||
int num2 = 0;
|
||
foreach (DynamicObject item3 in dynamicObjectCollection)
|
||
{
|
||
base.View.Model.CreateNewEntryRow(entity, num2++, item3);
|
||
}
|
||
|
||
base.View.UpdateView("FScanSummaryEntity");
|
||
}
|
||
|
||
private void DeleteUnMatchedRow()
|
||
{
|
||
Entity entity = base.View.BusinessInfo.GetEntity("FScanDetailEntity");
|
||
DynamicObjectCollection entityDataObject = base.View.Model.GetEntityDataObject(entity);
|
||
foreach (DynamicObject item in entityDataObject)
|
||
{
|
||
}
|
||
|
||
Entity entity2 = base.View.BusinessInfo.GetEntity("FScanSummaryEntity");
|
||
DynamicObjectCollection entityDataObject2 = base.View.Model.GetEntityDataObject(entity2);
|
||
foreach (DynamicObject item2 in entityDataObject2)
|
||
{
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 匹配源单信息
|
||
/// </summary>
|
||
/// <param name="doMaterial"></param>
|
||
/// <returns></returns>
|
||
private bool IsMatchToSourceBill(DynamicObject doMaterial)
|
||
{
|
||
if (doMaterial["Billseq"] == null || doMaterial["BillCode"] == null || doMaterial["MaterialId"] == null)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
bool result = false;
|
||
string billCode = Convert.ToString(doMaterial["BillCode"]);
|
||
int num = Convert.ToInt32(doMaterial["BillSeq"]);
|
||
long num2 = Convert.ToInt64(doMaterial["MaterialId_Id"]);
|
||
if (_sourceBillNos.Contains(billCode))
|
||
{
|
||
foreach (Entity entry in billFormMetaData.BusinessInfo.Entrys)
|
||
{
|
||
string seqDynamicPropertyName = ((entry.SeqDynamicProperty != null) ? entry.SeqDynamicProperty.Name : string.Empty);
|
||
string propertyName = string.Empty;
|
||
if (seqDynamicPropertyName.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
continue;
|
||
}
|
||
|
||
foreach (Field field in entry.Fields)
|
||
{
|
||
if (field is BaseDataField)
|
||
{
|
||
BaseDataField baseDataField = field as BaseDataField;
|
||
if (baseDataField.LookUpObject.FormId.EqualsIgnoreCase("BD_MATERIAL"))
|
||
{
|
||
propertyName = field.PropertyName;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (propertyName.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
continue;
|
||
}
|
||
|
||
DynamicObjectCollection dynamicObjectCollection = doSourceBillInfo[billCode][entry.EntryName] as DynamicObjectCollection;
|
||
foreach (DynamicObject item in dynamicObjectCollection)
|
||
{
|
||
if (item[propertyName] is DynamicObject dynamicObject && Convert.ToInt32(item[seqDynamicPropertyName]) == num && Convert.ToInt64(dynamicObject["Id"]) == num2)
|
||
{
|
||
result = true;
|
||
return result;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
private void AnalyseBarCode(string barcode)
|
||
{
|
||
|
||
bool isBindToEntry = true;
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("AnalyseBarCode进入开始", "5f84cd6a15db440f", "APP_ISVPAAC2016062210550"));
|
||
if (barcode.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (validCodeAndRowMapping.Keys.Contains(barcode) && !noMatchCodeAndRowMapping.ContainsKey(barcode))
|
||
{
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("AnalyseBarCode界面已有数据进入开始", "30c98bbf999742bb", "APP_ISVPAAC2016062210550"));
|
||
int value = 0;
|
||
validCodeAndRowMapping.TryGetValue(barcode, out value);
|
||
decimal num = Convert.ToDecimal(base.View.Model.GetValue("FQty", value));
|
||
barcodeSysParm = BarCodeCommonServiceHelper.GetBarCodeBillSystemParameters(base.Context, base.Context.CurrentOrganizationInfo.ID, sourceBillFormId);
|
||
if (isAllowDelete)
|
||
{
|
||
decimal value2 = default(decimal);
|
||
if (validCodeAndQtyMapping.ContainsKey(barcode))
|
||
{
|
||
validCodeAndQtyMapping.TryGetValue(barcode, out value2);
|
||
if (value2 == 0m)
|
||
{
|
||
value2 = defaultScanNumber;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
value2 = defaultScanNumber;
|
||
}
|
||
|
||
if (num > value2)
|
||
{
|
||
base.View.GetControl<EntryGrid>("FScanDetailEntity").SetFocusRowIndex(value);
|
||
base.View.Model.SetValue("FQty", num - value2, value);
|
||
}
|
||
else
|
||
{
|
||
validCodeAndRowMapping.Remove(barcode);
|
||
base.View.Model.DeleteEntryRow("FScanDetailEntity", value);
|
||
}
|
||
}
|
||
else if (barcodeSysParm.IsAllowScanRepeat)
|
||
{
|
||
if (barcodeSysParm.IsMergeSameCode)
|
||
{
|
||
base.View.GetControl<EntryGrid>("FScanDetailEntity").SetFocusRowIndex(value);
|
||
decimal value3 = default(decimal);
|
||
if (validCodeAndQtyMapping.ContainsKey(barcode))
|
||
{
|
||
validCodeAndQtyMapping.TryGetValue(barcode, out value3);
|
||
if (value3 == 0m)
|
||
{
|
||
value3 = defaultScanNumber;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
value3 = defaultScanNumber;
|
||
}
|
||
|
||
base.View.Model.SetValue("FQty", num + value3, value);
|
||
}
|
||
else if (Convert.ToBoolean(base.View.Model.GetValue("FSameCopy")))
|
||
{
|
||
int entryRowCount = Model.GetEntryRowCount("FScanDetailEntity");
|
||
base.View.Model.CopyEntryRow("FScanDetailEntity", value, entryRowCount);
|
||
}
|
||
else
|
||
{
|
||
ExplainAnalyseBarCode(barcode, isBindToEntry);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
base.View.ShowNotificationMessage(ResManager.LoadKDString("不允许条码重复扫描!", "0011019000003080", SubSystemType.BASE));
|
||
}
|
||
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("AnalyseBarCode界面已有数据进入结束", "b874c39f1a3c4830", "APP_ISVPAAC2016062210550"));
|
||
}
|
||
else
|
||
{
|
||
ExplainAnalyseBarCode(barcode, isBindToEntry);
|
||
}
|
||
|
||
Control control = base.View.GetControl("FScanCode");
|
||
control.SetFocus();
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("AnalyseBarCode完成", "a4d7a0ee58914ac2", "APP_ISVPAAC2016062210550"));
|
||
}
|
||
|
||
private void HandleBillCode(string sourceBillNo)
|
||
{
|
||
if (sourceBillNo.IsNullOrEmptyOrWhiteSpace())
|
||
return;
|
||
|
||
if (_sourceBillNos.Contains(sourceBillNo))
|
||
return;
|
||
|
||
|
||
}
|
||
|
||
//private void HandleBillCode(string sourceBillNo)
|
||
//{
|
||
// if (sourceBillNo.IsNullOrEmptyOrWhiteSpace())
|
||
// return;
|
||
|
||
// var oldSourceBillNo = this.View.Model.GetValue("FSourceBillId");
|
||
// if (oldSourceBillNo.IsNullOrEmptyOrWhiteSpace())
|
||
// {
|
||
// this.View.Model.SetValue("FSOURCEBILLID", sourceBillNo);
|
||
// }
|
||
// else
|
||
// {
|
||
// if (oldSourceBillNo.ToString().Contains(sourceBillNo))
|
||
// return;
|
||
|
||
// var newSourceBillNo = oldSourceBillNo + "," + sourceBillNo;
|
||
|
||
// this.View.Model.SetValue("FSOURCEBILLID", newSourceBillNo);
|
||
// }
|
||
//}
|
||
|
||
|
||
private string HandleBarCode(string barcode)
|
||
{
|
||
var val = "";
|
||
var sp = '_';
|
||
if (this.Context.DBId.Equals("66eec1c506d225"))
|
||
sp = '&';
|
||
|
||
var strArr = barcode.Split(sp);
|
||
if (strArr.Count() > BillCodeIdx)
|
||
val = strArr[BillCodeIdx];
|
||
|
||
return val;
|
||
}
|
||
|
||
private void ExplainAnalyseBarCode(string barcode, bool isBindToEntry)
|
||
{
|
||
try
|
||
{
|
||
var sourceBillNo = HandleBarCode(barcode);
|
||
//HandleBillCode(sourceBillNo);
|
||
|
||
BarcodeExplainArgs barcodeExplainArgs = new BarcodeExplainArgs();
|
||
barcodeExplainArgs.Barcode = barcode;
|
||
barcodeExplainArgs.Context = base.Context;
|
||
barcodeExplainArgs.BarcodeRule = barcodeRuleId;
|
||
barcodeExplainArgs.BillTypeName = sourceBillFormId;
|
||
barcodeExplainArgs.BillNo = sourceBillNo;
|
||
barcodeExplainArgs.Barcodes = new List<string> { barcodeExplainArgs.Barcode };
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("ExplainBarCode_New解析开始", "cadec661729046dc", "APP_ISVPAAC2016062210550"));
|
||
DynamicObject dynamicObject = BarCodeExplainServiceHelper.ExplainBatchBarCode(barcodeExplainArgs).FirstOrDefault();
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("ExplainBarCode_New解析结束", "0a59d2c2d513485d", "APP_ISVPAAC2016062210550"));
|
||
if (dynamicObject.Contains("BarCodeRule_Id"))
|
||
{
|
||
barcodeRuleNewId = Convert.ToInt64(dynamicObject["BarCodeRule_Id"]);
|
||
}
|
||
|
||
if (barcodeRuleNewId == 0)
|
||
{
|
||
throw new Exception(ResManager.LoadKDString("解析失败,未找到满足条码的条码规则,请检查!", "251604046f8e419c", "APP_ISVPAAC2016062210550"));
|
||
}
|
||
|
||
if (barcodeRuleNewId > 0)
|
||
{
|
||
base.View.Model.SetValue("FBarCodeRule", barcodeRuleNewId);
|
||
needMatchToSourceBill = Convert.ToBoolean(base.View.Model.GetValue("FISMAPTOSOURCEBILL"));
|
||
if (needMatchToSourceBill)
|
||
{
|
||
lstMatchItem = GetMatchRuleContent();
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", "needMatchToSourceBill" + needMatchToSourceBill.ToString() + lstMatchItem.Count);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
base.View.Model.SetValue("FBarCodeRule", 0);
|
||
}
|
||
|
||
if (dynamicObject != null)
|
||
{
|
||
BarCodeSysParamsModel barCodeBillSystemParameters = BarCodeCommonServiceHelper.GetBarCodeBillSystemParameters(base.Context, base.Context.CurrentOrganizationInfo.ID, createBillFormId);
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", "AnalyseBarCode:" + barCodeBillSystemParameters.FFIFO + "OrgID" + base.Context.CurrentOrganizationInfo.ID + "FormID");
|
||
if (!barCodeBillSystemParameters.FFIFO.EqualsIgnoreCase("1"))
|
||
{
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("barcodecreatesysparam开始", "cb99e9cd7ae54b07", "APP_ISVPAAC2016062210550"));
|
||
string empty = string.Empty;
|
||
string empty2 = string.Empty;
|
||
DynamicObject dynamicObject2 = dynamicObject["MaterialId"] as DynamicObject;
|
||
DynamicObject dynamicObject3 = dynamicObject["StockId"] as DynamicObject;
|
||
string value = Convert.ToString(dynamicObject["BillDate"]);
|
||
if (!string.IsNullOrWhiteSpace(value))
|
||
{
|
||
DateTime dateTime = Convert.ToDateTime(value);
|
||
if (dynamicObject2 != null && dynamicObject3 != null)
|
||
{
|
||
empty = Convert.ToString(dynamicObject2["Number"]);
|
||
empty2 = Convert.ToString(dynamicObject3["Number"]);
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("GetBillDateByMaterial开始", "78f75fc6c5a14437", "APP_ISVPAAC2016062210550"));
|
||
string billDateByMaterial = BarCodeCommonServiceHelper.GetBillDateByMaterial(base.Context, empty, empty2, barcode);
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("GetBillDateByMaterial结束", "ef3e9140012946ba", "APP_ISVPAAC2016062210550") + billDateByMaterial);
|
||
if (!string.IsNullOrWhiteSpace(billDateByMaterial))
|
||
{
|
||
DateTime dateTime2 = Convert.ToDateTime(billDateByMaterial);
|
||
if (dateTime > dateTime2)
|
||
{
|
||
if (barCodeBillSystemParameters.FFIFO.EqualsIgnoreCase("3"))
|
||
{
|
||
isBindToEntry = false;
|
||
base.View.ShowMessage(string.Format(ResManager.LoadKDString("当前条码【{0}】对应的日期不是最早日期!", "a2910c5be946498f", "APP_ISVPAAC2016062210550"), barcode));
|
||
return;
|
||
}
|
||
|
||
if (barCodeBillSystemParameters.FFIFO.EqualsIgnoreCase("2"))
|
||
{
|
||
base.View.ShowMessage(string.Format(ResManager.LoadKDString("当前条码【{0}】对应的日期不是最早日期!", "a2910c5be946498f", "APP_ISVPAAC2016062210550"), barcode), MessageBoxOptions.YesNo, delegate (MessageBoxResult result)
|
||
{
|
||
switch (result)
|
||
{
|
||
case MessageBoxResult.Yes:
|
||
isBindToEntry = true;
|
||
break;
|
||
case MessageBoxResult.No:
|
||
isBindToEntry = false;
|
||
break;
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if (isBindToEntry)
|
||
{
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("BindingScanResultToDetailEntity开始", "e8982c7a493b42f0", "APP_ISVPAAC2016062210550"));
|
||
BindingScanResultToDetailEntity(dynamicObject, barcode, defaultScanNumber);
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("BindingScanResultToDetailEntity完成", "59d20f4790ce4b8b", "APP_ISVPAAC2016062210550"));
|
||
}
|
||
}
|
||
}
|
||
catch (BarCodeExplainException ex)
|
||
{
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("AnalyseBarCode异常", "0af732e840ac4f17", "APP_ISVPAAC2016062210550"));
|
||
base.View.Model.CreateNewEntryRow("FScanDetailEntity");
|
||
int entryCurrentRowIndex = Model.GetEntryCurrentRowIndex("FScanDetailEntity");
|
||
base.View.Model.SetValue("FBarCode", barcode, entryCurrentRowIndex);
|
||
base.View.Model.SetValue("FIsValidCode", false, entryCurrentRowIndex);
|
||
EntryGrid control = base.View.GetControl<EntryGrid>("FScanDetailEntity");
|
||
control.SetForecolor("FBarCode", "#FF0000", entryCurrentRowIndex);
|
||
invalidCodeAndRowMapping.Add(entryCurrentRowIndex, barcode);
|
||
base.View.ShowNotificationMessage(ex.Message);
|
||
}
|
||
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("AnalyseBarCode完成", "66749e08ae024630", "APP_ISVPAAC2016062210550"));
|
||
}
|
||
|
||
private void BindingScanResultToDetailEntity(DynamicObject doScanMaterial, string barcode, int scanCount)
|
||
{
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("BindingScanResultToDetailEntity 首先删除之前未解析出来的相同条码记录开始", "aefe29f4d1154ca5", "APP_ISVPAAC2016062210550"));
|
||
do
|
||
{
|
||
foreach (int key in invalidCodeAndRowMapping.Keys)
|
||
{
|
||
string value = string.Empty;
|
||
invalidCodeAndRowMapping.TryGetValue(key, out value);
|
||
if (value == barcode)
|
||
{
|
||
base.View.Model.DeleteEntryRow("FScanDetailEntity", key);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
while (invalidCodeAndRowMapping.Values.Contains(barcode));
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("BindingScanResultToDetailEntity 首先删除之前未解析出来的相同条码记录结束", "33cdee362bd2442f", "APP_ISVPAAC2016062210550"));
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("BindingScanResultToDetailEntity IsMatchSourceBillByMatchItem开始", "b434d75fc6b34cd7", "APP_ISVPAAC2016062210550"));
|
||
bool flag = needMatchToSourceBill && IsMatchSourceBillByMatchItem(doScanMaterial);
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("BindingScanResultToDetailEntity IsMatchSourceBillByMatchItem结束", "80dfc402db2343b4", "APP_ISVPAAC2016062210550") + needMatchToSourceBill);
|
||
if (needMatchToSourceBill && !flag)
|
||
{
|
||
string msg = string.Format(ResManager.LoadKDString("条码【{0}】未找到匹配的行!", "ca77c58466b44f8d", "APP_ISVPAAC2016062210550"), barcode);
|
||
base.View.ShowErrMessage(msg);
|
||
return;
|
||
}
|
||
|
||
base.View.Model.CreateNewEntryRow("FScanDetailEntity");
|
||
int entryCurrentRowIndex = Model.GetEntryCurrentRowIndex("FScanDetailEntity");
|
||
Entity entity = base.View.BillBusinessInfo.GetEntity("FScanDetailEntity");
|
||
foreach (Field field in entity.Fields)
|
||
{
|
||
object obj = null;
|
||
if (doScanMaterial.DynamicObjectType.Properties.Contains(field.PropertyName))
|
||
{
|
||
obj = doScanMaterial[field.PropertyName];
|
||
}
|
||
|
||
if (obj != null)
|
||
{
|
||
if (obj is DynamicObject)
|
||
{
|
||
if (field is BaseDataField)
|
||
{
|
||
DynamicObject dynamicObject = obj as DynamicObject;
|
||
if (field is AssistantField)
|
||
{
|
||
base.View.Model.SetValue(field.Key, obj, entryCurrentRowIndex);
|
||
}
|
||
else
|
||
{
|
||
string propertyName = ((BaseDataField)field).NumberProperty.PropertyName;
|
||
string text = Convert.ToString(dynamicObject[propertyName]);
|
||
string strFilter = $"FUseOrgID='{base.Context.CurrentOrganizationInfo.ID}' AND FNumber='{text}'";
|
||
OQLFilter ofilter = OQLFilter.CreateHeadEntityFilter(strFilter);
|
||
string empty = string.Empty;
|
||
empty = (field as BaseDataField).LookUpObject.FormId;
|
||
if (empty.EqualsIgnoreCase("BD_MATERIAL"))
|
||
{
|
||
dynamicObject = BusinessDataServiceHelper.Load(base.Context, empty, null, ofilter).FirstOrDefault();
|
||
if (dynamicObject.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
string description = string.Format(ResManager.LoadKDString("基础资料的【{0}】【{1}】在当前登录组织不存在", "1ddc09c938c04230", "APP_ISVPAAC2016062210550"), field.Name, Convert.ToString(text));
|
||
base.View.ShowMessage(ResManager.LoadKDString(description, "0011019000003240", SubSystemType.BASE));
|
||
base.View.Model.DeleteEntryRow("FScanDetailEntity", entryCurrentRowIndex);
|
||
return;
|
||
}
|
||
|
||
base.View.Model.SetValue(field.Key, dynamicObject["Id"], entryCurrentRowIndex);
|
||
base.View.InvokeFieldUpdateService(field.Key, entryCurrentRowIndex);
|
||
}
|
||
else if (empty.EqualsIgnoreCase("BD_BatchMainFile"))
|
||
{
|
||
base.View.Model.SetValue(field.Key, text, entryCurrentRowIndex);
|
||
base.View.InvokeFieldUpdateService(field.Key, entryCurrentRowIndex);
|
||
}
|
||
else
|
||
{
|
||
base.View.Model.SetValue(field.Key, obj, entryCurrentRowIndex);
|
||
}
|
||
}
|
||
}
|
||
|
||
if (field is RelatedFlexGroupField && obj is DynamicObject)
|
||
{
|
||
DynamicObject dynamicObject2 = obj as DynamicObject;
|
||
base.View.Model.SetValue(field.FieldName, dynamicObject2["Id"], entryCurrentRowIndex);
|
||
base.View.InvokeFieldUpdateService(field.FieldName, entryCurrentRowIndex);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
base.View.Model.SetValue(field.Key, obj, entryCurrentRowIndex);
|
||
}
|
||
}
|
||
else if (field is LotField && doScanMaterial.Contains(field.PropertyName + "_Text"))
|
||
{
|
||
obj = doScanMaterial[field.PropertyName + "_Text"];
|
||
if (Convert.ToString(obj) != null && !Convert.ToString(obj).IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
base.View.Model.SetValue(field.Key, Convert.ToString(obj), entryCurrentRowIndex);
|
||
}
|
||
}
|
||
}
|
||
|
||
decimal num = ((Convert.ToDecimal(doScanMaterial["Qty"]) == 0m) ? 0m : Convert.ToDecimal(doScanMaterial["Qty"]));
|
||
base.View.Model.SetValue("FBarCode", barcode, entryCurrentRowIndex);
|
||
if (num == 0m)
|
||
{
|
||
base.View.Model.SetValue("FQty", scanCount, entryCurrentRowIndex);
|
||
}
|
||
else if (Model.DataObject.DynamicObjectType.Properties.Contains("isNomalSetQty"))
|
||
{
|
||
if (Model.GetValue("FisNomalSetQty").Equals(true))
|
||
{
|
||
base.View.Model.SetValue("FQty", Model.GetValue("FDEFAULTSCANNUMBER"), entryCurrentRowIndex);
|
||
}
|
||
else
|
||
{
|
||
base.View.Model.SetValue("FQty", num, entryCurrentRowIndex);
|
||
}
|
||
}
|
||
|
||
base.View.Model.SetValue("FIsMatched", flag, entryCurrentRowIndex);
|
||
base.View.Model.SetValue("FIsValidCode", true, entryCurrentRowIndex);
|
||
EntryGrid control = base.View.GetControl<EntryGrid>("FScanDetailEntity");
|
||
control.SetForecolor("FBarCode", "", entryCurrentRowIndex);
|
||
if (!validCodeAndRowMapping.ContainsKey(barcode))
|
||
{
|
||
validCodeAndRowMapping.Add(barcode, entryCurrentRowIndex);
|
||
}
|
||
|
||
if (!validCodeAndQtyMapping.ContainsKey(barcode))
|
||
{
|
||
validCodeAndQtyMapping.Add(barcode, num);
|
||
}
|
||
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("BindingScanResultToDetailEntity 字段赋值结束", "367f74e81f214c6a", "APP_ISVPAAC2016062210550") + entryCurrentRowIndex);
|
||
}
|
||
|
||
private string GetBillNameByBillTypeNumber(string billTypeNumber)
|
||
{
|
||
string result = string.Empty;
|
||
if (!billTypeNumber.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
result = BarCodeScanServiceHelper.GetBillNameByBillTypeNumber(base.Context, billTypeNumber);
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
private List<string> GetBillTypeByBillName(string billName)
|
||
{
|
||
List<string> result = new List<string>();
|
||
if (!billName.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
result = BarCodeScanServiceHelper.GetBillTypesByBillName(base.Context, billName);
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
|
||
public DynamicObject[] GetBarCodeRuleById(Context ctx, long barcodeRuleId)
|
||
{
|
||
FormMetadata formMetadata = (FormMetadata)MetaDataServiceHelper.Load(ctx, _BD_BarCodeRule);
|
||
DynamicObjectType dynamicObjectType = formMetadata.BusinessInfo.GetDynamicObjectType();
|
||
DynamicObjectCollection dynamicObjectCollection = new DynamicObjectCollection(dynamicObjectType);
|
||
return BusinessDataServiceHelper.Load(ctx, new object[1] { barcodeRuleId }, dynamicObjectType);
|
||
}
|
||
|
||
private bool IsAvailableRule(DynamicObject doRule, string billName)
|
||
{
|
||
bool result = false;
|
||
if (!billName.IsNullOrEmptyOrWhiteSpace() && doRule != null)
|
||
{
|
||
DynamicObjectCollection dynamicObjectCollection = doRule["BD_BARCODERULEENTRYToBill"] as DynamicObjectCollection;
|
||
foreach (DynamicObject item in dynamicObjectCollection)
|
||
{
|
||
string str = Convert.ToString(item["BillId_Id"]);
|
||
if (str.EqualsIgnoreCase(billName))
|
||
{
|
||
result = true;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
private bool IsMatchSourceBillByMatchItem(DynamicObject doMaterial)
|
||
{
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", ResManager.LoadKDString("BindingScanResultToDetailEntity IsMatchSourceBillByMatchItem进入", "54459867fc6b4db2", "APP_ISVPAAC2016062210550"));
|
||
if (sourceBillFormId.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
return false;
|
||
}
|
||
|
||
string text = Convert.ToString(doMaterial["BarCode"]);
|
||
int num = Convert.ToInt32(doMaterial["Qty"]);
|
||
if (dctMatchData.ContainsKey(text))
|
||
{
|
||
Dictionary<string, string> dictionary = dctMatchData[text];
|
||
dictionary["QTY"] = (Convert.ToInt32(dictionary["QTY"]) + num).ToString();
|
||
return true;
|
||
}
|
||
|
||
if (lstMatchItem.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
base.View.ShowMessage(ResManager.LoadKDString("当前条码规则不存在匹配项,请设置!", "0011019000003240", SubSystemType.BASE));
|
||
return false;
|
||
}
|
||
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", "BindingScanResultToDetailEntity lstMatchItem.Count" + lstMatchItem.Count);
|
||
if (!doMaterial["MaterialId"].IsNullOrEmpty() && !lstMatchItem.IsNullOrEmptyOrWhiteSpace() && lstMatchItem.Count > 0)
|
||
{
|
||
string msg = string.Empty;
|
||
if (srcEntryEntity is EntryEntity)
|
||
{
|
||
DynamicObject dynamicObject = doMaterial["MaterialId"] as DynamicObject;
|
||
|
||
var BillCode = "";
|
||
if (doMaterial.DynamicObjectType.Properties.ContainsKey("BillCode"))
|
||
{
|
||
BillCode = doMaterial["BillCode"].ToString();
|
||
}
|
||
|
||
long num2 = Convert.ToInt64(dynamicObject[FormConst.MASTER_ID]);
|
||
string entryName = billFormMetaData.BusinessInfo.GetEntryEntity(srcEntryKey).EntryName;
|
||
DynamicObjectCollection source = doSourceBillInfo[BillCode][entryName] as DynamicObjectCollection;
|
||
DynamicObject dynamicObject2 = source.Where((DynamicObject p) => isMatchWhereValue(p, doMaterial, ref msg)).FirstOrDefault();
|
||
if (dynamicObject2.IsNullOrEmpty())
|
||
{
|
||
base.View.ShowMessage(ResManager.LoadKDString(msg, "0011019000003240", SubSystemType.BASE));
|
||
return false;
|
||
}
|
||
|
||
long num3 = Convert.ToInt64(dynamicObject2["Id"]);
|
||
long num4 = 0L;
|
||
if (dynamicObject2.DynamicObjectType.Properties.ContainsKey("Seq"))
|
||
{
|
||
num4 = Convert.ToInt64(dynamicObject2["Seq"]);
|
||
}
|
||
|
||
long num5 = 0L;
|
||
if (doMaterial.DynamicObjectType.Properties.ContainsKey("BillSeq"))
|
||
{
|
||
num5 = Convert.ToInt64(doMaterial["BillSeq"]);
|
||
}
|
||
|
||
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", "BindingScanResultToDetailEntity entryId" + dynamicObject2["Id"]);
|
||
Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
|
||
dictionary2.Add("MATERIALMASTERID", num2.ToString());
|
||
dictionary2.Add("SEQ", num4.ToString());
|
||
dictionary2.Add("ENTRYID", num3.ToString());
|
||
dictionary2.Add("SUBENTRYID", "0");
|
||
dictionary2.Add("QTY", num.ToString());
|
||
dictionary2.Add("BillSeq", num5.ToString());
|
||
dictionary2.Add("BillSrcId", _sourceBillNoToIds[BillCode].ToString());
|
||
dctMatchData.Add(text, dictionary2);
|
||
//UNWLogger.Info(base.Context, "BarCodeScanEdit AnalyseBarCode", "BindingScanResultToDetailEntity barcode" + text);
|
||
return true;
|
||
}
|
||
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
private bool isMatchWhereValue(DynamicObject srcEntryInfo, DynamicObject doScanMaterial, ref string msg)
|
||
{
|
||
if (lstMatchItem.Count == 0)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
Dictionary<Field, Field> dictionary = lstMatchItem[0];
|
||
string empty = string.Empty;
|
||
string empty2 = string.Empty;
|
||
msg = string.Empty;
|
||
if (dictionary.IsNullOrEmptyOrWhiteSpace() || dictionary.Count <= 0)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
foreach (Field key in dictionary.Keys)
|
||
{
|
||
empty = key.PropertyName;
|
||
empty2 = dictionary[key].PropertyName;
|
||
if (!srcEntryInfo.DynamicObjectType.Properties.Contains(empty2))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if ((key is BaseDataField && !(key is LotField)) || key is RelatedFlexGroupField)
|
||
{
|
||
long num = Convert.ToInt64(srcEntryInfo[empty2 + "_Id"]);
|
||
long num2 = Convert.ToInt64(doScanMaterial[empty + "_Id"]);
|
||
if ((key is BaseDataField || key is AssistantField) && doScanMaterial[empty] is DynamicObject dynamicObject)
|
||
{
|
||
string empty3 = string.Empty;
|
||
string assistantId = string.Empty;
|
||
string empty4 = string.Empty;
|
||
if (key is AssistantField)
|
||
{
|
||
empty4 = Convert.ToString(dynamicObject["FNumber"]);
|
||
empty3 = ((AssistantField)key).LookUpObject.FormId.ToString();
|
||
assistantId = ((AssistantField)key).LookUpObjectID.ToString();
|
||
}
|
||
else
|
||
{
|
||
empty4 = Convert.ToString(dynamicObject["Number"]);
|
||
empty3 = ((BaseDataField)key).LookUpObject.FormId.ToString();
|
||
}
|
||
|
||
DynamicObject[] baseDataByNumberOrg = BarCodeBaseInfoServiceHelper.GetBaseDataByNumberOrg(base.Context, empty3, base.Context.CurrentOrganizationInfo.ID, empty4, assistantId);
|
||
if (baseDataByNumberOrg != null && !baseDataByNumberOrg.IsEmpty() && baseDataByNumberOrg.Count() > 0)
|
||
{
|
||
DynamicObject dynamicObject2 = baseDataByNumberOrg[0];
|
||
if (dynamicObject2 != null)
|
||
{
|
||
num2 = Convert.ToInt64(dynamicObject2["Id"]);
|
||
}
|
||
}
|
||
}
|
||
|
||
if (num2 != num)
|
||
{
|
||
msg = string.Concat(msg, ResManager.LoadKDString("匹配项【", "365a6bce3ca64ce7", "APP_ISVPAAC2016062210550"), key.Name, ResManager.LoadKDString("】不匹配", "a354658df5984dc5", "APP_ISVPAAC2016062210550"));
|
||
return false;
|
||
}
|
||
}
|
||
else if (key is LotField)
|
||
{
|
||
string text = Convert.ToString(srcEntryInfo[empty2 + "_Text"]);
|
||
string text2 = Convert.ToString(doScanMaterial[empty + "_Text"]);
|
||
if (text2.IsEmpty() || text.IsEmpty())
|
||
{
|
||
long num3 = Convert.ToInt64(srcEntryInfo[empty2 + "_Id"]);
|
||
long num4 = Convert.ToInt64(doScanMaterial[empty + "_Id"]);
|
||
if (num4 != num3)
|
||
{
|
||
msg = string.Concat(msg, ResManager.LoadKDString("匹配项【", "365a6bce3ca64ce7", "APP_ISVPAAC2016062210550"), key.Name, ResManager.LoadKDString("】不匹配", "a354658df5984dc5", "APP_ISVPAAC2016062210550"));
|
||
return false;
|
||
}
|
||
}
|
||
else if (!text2.EqualsIgnoreCase(text))
|
||
{
|
||
msg = string.Concat(msg, ResManager.LoadKDString("匹配项【", "365a6bce3ca64ce7", "APP_ISVPAAC2016062210550"), key.Name, ResManager.LoadKDString("】不匹配", "a354658df5984dc5", "APP_ISVPAAC2016062210550"));
|
||
return false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
string str = Convert.ToString(srcEntryInfo[empty2]);
|
||
string str2 = Convert.ToString(doScanMaterial[empty]);
|
||
if (!str2.EqualsIgnoreCase(str))
|
||
{
|
||
msg = string.Concat(msg, ResManager.LoadKDString("匹配项【", "365a6bce3ca64ce7", "APP_ISVPAAC2016062210550"), key.Name, ResManager.LoadKDString("】不匹配", "a354658df5984dc5", "APP_ISVPAAC2016062210550"));
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
private bool isMatchSumWhereValue(DynamicObject srcEntryInfo, DynamicObject doScanMaterial, ref string msg)
|
||
{
|
||
if (lstSumMatchItem.Count == 0)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
Dictionary<Field, Field> dictionary = lstSumMatchItem[0];
|
||
string empty = string.Empty;
|
||
string empty2 = string.Empty;
|
||
msg = string.Empty;
|
||
if (dictionary.IsNullOrEmptyOrWhiteSpace() || dictionary.Count <= 0)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
foreach (Field key in dictionary.Keys)
|
||
{
|
||
empty = key.PropertyName;
|
||
empty2 = key.PropertyName;
|
||
empty = "Sum" + empty;
|
||
if (!srcEntryInfo.DynamicObjectType.Properties.Contains(empty2))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if ((key is BaseDataField && !(key is LotField)) || key is RelatedFlexGroupField)
|
||
{
|
||
string text = Convert.ToString(srcEntryInfo[empty2 + "_Id"]);
|
||
string text2 = Convert.ToString(doScanMaterial[empty + "_Id"]);
|
||
if (!(text2 == text))
|
||
{
|
||
msg = string.Concat(msg, ResManager.LoadKDString("匹配项【", "365a6bce3ca64ce7", "APP_ISVPAAC2016062210550"), key.Name, ResManager.LoadKDString("】不匹配", "a354658df5984dc5", "APP_ISVPAAC2016062210550"));
|
||
return false;
|
||
}
|
||
}
|
||
else if (key is LotField)
|
||
{
|
||
string text3 = Convert.ToString(srcEntryInfo[empty2 + "_Text"]);
|
||
string text4 = Convert.ToString(doScanMaterial[empty + "_Text"]);
|
||
if (text4.IsEmpty() || text3.IsEmpty())
|
||
{
|
||
long num = Convert.ToInt64(srcEntryInfo[empty2 + "_Id"]);
|
||
long num2 = Convert.ToInt64(doScanMaterial[empty + "_Id"]);
|
||
if (num2 != num)
|
||
{
|
||
msg = string.Concat(msg, ResManager.LoadKDString("匹配项【", "365a6bce3ca64ce7", "APP_ISVPAAC2016062210550"), key.Name, ResManager.LoadKDString("】不匹配", "a354658df5984dc5", "APP_ISVPAAC2016062210550"));
|
||
return false;
|
||
}
|
||
}
|
||
else if (!text4.EqualsIgnoreCase(text3))
|
||
{
|
||
msg = string.Concat(msg, ResManager.LoadKDString("匹配项【", "365a6bce3ca64ce7", "APP_ISVPAAC2016062210550"), key.Name, ResManager.LoadKDString("】不匹配", "a354658df5984dc5", "APP_ISVPAAC2016062210550"));
|
||
return false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
string str = Convert.ToString(srcEntryInfo[empty2]);
|
||
string str2 = Convert.ToString(doScanMaterial[empty]);
|
||
if (!str2.EqualsIgnoreCase(str))
|
||
{
|
||
msg = string.Concat(msg, ResManager.LoadKDString("匹配项【", "365a6bce3ca64ce7", "APP_ISVPAAC2016062210550"), key.Name, ResManager.LoadKDString("】不匹配", "a354658df5984dc5", "APP_ISVPAAC2016062210550"));
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
private bool isMatchWhereValueByOperation(DynamicObject srcEntryInfo, DynamicObject doScanMaterial, ref string msg)
|
||
{
|
||
Dictionary<Field, Field> dictionary = lstMatchItem[0];
|
||
string empty = string.Empty;
|
||
string empty2 = string.Empty;
|
||
msg = string.Empty;
|
||
if (dictionary.IsNullOrEmptyOrWhiteSpace() || dictionary.Count <= 0)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
foreach (Field key in dictionary.Keys)
|
||
{
|
||
empty = key.PropertyName;
|
||
empty2 = dictionary[key].PropertyName;
|
||
if (!srcEntryInfo.DynamicObjectType.Properties.Contains(empty2))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if ((key is BaseDataField && !(key is LotField)) || key is RelatedFlexGroupField)
|
||
{
|
||
long num = Convert.ToInt64(srcEntryInfo[empty2 + "_Id"]);
|
||
long num2 = Convert.ToInt64(doScanMaterial[empty + "_Id"]);
|
||
if (num2 != num)
|
||
{
|
||
msg = string.Concat(msg, ResManager.LoadKDString("匹配项【", "365a6bce3ca64ce7", "APP_ISVPAAC2016062210550"), key.Name, ResManager.LoadKDString("】不匹配", "a354658df5984dc5", "APP_ISVPAAC2016062210550"));
|
||
return false;
|
||
}
|
||
}
|
||
else if (key is LotField)
|
||
{
|
||
string text = Convert.ToString(srcEntryInfo[empty2 + "_Text"]);
|
||
string text2 = Convert.ToString(doScanMaterial[empty + "_Text"]);
|
||
if (text2.IsEmpty() || text.IsEmpty())
|
||
{
|
||
long num3 = Convert.ToInt64(srcEntryInfo[empty2 + "_Id"]);
|
||
long num4 = Convert.ToInt64(doScanMaterial[empty + "_Id"]);
|
||
if (num4 != num3)
|
||
{
|
||
msg = string.Concat(msg, ResManager.LoadKDString("匹配项【", "365a6bce3ca64ce7", "APP_ISVPAAC2016062210550"), key.Name, ResManager.LoadKDString("】不匹配", "a354658df5984dc5", "APP_ISVPAAC2016062210550"));
|
||
return false;
|
||
}
|
||
}
|
||
else if (!text2.EqualsIgnoreCase(text))
|
||
{
|
||
msg = string.Concat(msg, ResManager.LoadKDString("匹配项【", "365a6bce3ca64ce7", "APP_ISVPAAC2016062210550"), key.Name, ResManager.LoadKDString("】不匹配", "a354658df5984dc5", "APP_ISVPAAC2016062210550"));
|
||
return false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
string str = Convert.ToString(srcEntryInfo[empty2]);
|
||
string str2 = Convert.ToString(doScanMaterial[empty]);
|
||
if (!str2.EqualsIgnoreCase(str))
|
||
{
|
||
msg = string.Concat(msg, ResManager.LoadKDString("匹配项【", "365a6bce3ca64ce7", "APP_ISVPAAC2016062210550"), key.Name, ResManager.LoadKDString("】不匹配", "a354658df5984dc5", "APP_ISVPAAC2016062210550"));
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
private List<Dictionary<Field, Field>> GetMatchRuleContent()
|
||
{
|
||
FormMetadata formMetadata = (FormMetadata)MetaDataServiceHelper.Load(base.Context, _BDBarCodeMainFile);
|
||
List<Dictionary<Field, Field>> list = new List<Dictionary<Field, Field>>();
|
||
if (barcodeRuleEntities != null && barcodeRuleEntities.Count() > 0)
|
||
{
|
||
DynamicObjectCollection dynamicObjectCollection = barcodeRuleEntities[0]["BD_BARCODERULEENTRY"] as DynamicObjectCollection;
|
||
Dictionary<Field, Field> dictionary = new Dictionary<Field, Field>();
|
||
foreach (DynamicObject item in dynamicObjectCollection)
|
||
{
|
||
int id = Convert.ToInt32(item["BarCodePropertyId_Id"]);
|
||
if (!Convert.ToBoolean(item["FIsPCMatch"]))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
DynamicObject dynamicObject = BarCodeCommonServiceHelper.LoadBillData(base.Context, "BD_BarCodeItem", id).FirstOrDefault();
|
||
DynamicObjectCollection source = dynamicObject["BD_BARCODEITEMENTRY"] as DynamicObjectCollection;
|
||
DynamicObject dynamicObject2 = source.Where((DynamicObject p) => Convert.ToString(p["BILLFORMID_ID"]).EqualsIgnoreCase(sourceBillFormId)).FirstOrDefault();
|
||
string key = Convert.ToString(dynamicObject["BarCodeFieldKey"]);
|
||
Field field = formMetadata.BusinessInfo.GetField(key);
|
||
if (dynamicObject2 != null)
|
||
{
|
||
string key2 = Convert.ToString(dynamicObject2["FieldKey"]);
|
||
Field field2 = billFormMetaData.BusinessInfo.GetField(key2);
|
||
if (field != null && field2 != null && !dictionary.ContainsKey(field))
|
||
{
|
||
dictionary.Add(field, field2);
|
||
}
|
||
}
|
||
}
|
||
|
||
list.Add(dictionary);
|
||
}
|
||
|
||
return list;
|
||
}
|
||
|
||
private List<Dictionary<Field, Field>> GetMatchRuleContentByTagBillName()
|
||
{
|
||
FormMetadata formMetadata = (FormMetadata)MetaDataServiceHelper.Load(base.Context, _BDBarCodeMainFile);
|
||
List<Dictionary<Field, Field>> list = new List<Dictionary<Field, Field>>();
|
||
if (barcodeRuleEntities != null && barcodeRuleEntities.Count() > 0)
|
||
{
|
||
DynamicObjectCollection dynamicObjectCollection = barcodeRuleEntities[0]["BD_BARCODERULEENTRY"] as DynamicObjectCollection;
|
||
Dictionary<Field, Field> dictionary = new Dictionary<Field, Field>();
|
||
foreach (DynamicObject item in dynamicObjectCollection)
|
||
{
|
||
int id = Convert.ToInt32(item["BarCodePropertyId_Id"]);
|
||
bool flag = Convert.ToBoolean(item["FIsPCMatch"]);
|
||
DynamicObject dynamicObject = BarCodeCommonServiceHelper.LoadBillData(base.Context, "BD_BarCodeItem", id).FirstOrDefault();
|
||
DynamicObjectCollection source = dynamicObject["BD_BARCODEITEMENTRY"] as DynamicObjectCollection;
|
||
DynamicObject dynamicObject2 = source.Where((DynamicObject p) => Convert.ToString(p["BILLFORMID_ID"]).EqualsIgnoreCase(createBillFormId)).FirstOrDefault();
|
||
string key = Convert.ToString(dynamicObject["BarCodeFieldKey"]);
|
||
Field field = formMetadata.BusinessInfo.GetField(key);
|
||
if (!(field is QtyField) && field != null && dynamicObject2 != null)
|
||
{
|
||
string key2 = Convert.ToString(dynamicObject2["FieldKey"]);
|
||
Field field2 = tagbillFormMetaData.BusinessInfo.GetField(key2);
|
||
if (field2 != null && !dictionary.ContainsKey(field))
|
||
{
|
||
dictionary.Add(field, field2);
|
||
}
|
||
}
|
||
}
|
||
|
||
list.Add(dictionary);
|
||
}
|
||
|
||
return list;
|
||
}
|
||
|
||
private void MatchScanData()
|
||
{
|
||
dctMatchData = new Dictionary<string, Dictionary<string, string>>();
|
||
Entity entity = base.View.BusinessInfo.GetEntity("FScanDetailEntity");
|
||
DynamicObjectCollection entityDataObject = base.View.Model.GetEntityDataObject(entity);
|
||
foreach (DynamicObject item in entityDataObject)
|
||
{
|
||
string key = Convert.ToString(item["BarCode"]);
|
||
bool flag = IsMatchSourceBillByMatchItem(item);
|
||
int rowIndex = base.View.Model.GetRowIndex(entity, item);
|
||
base.View.Model.SetValue("FIsMatched", flag, rowIndex);
|
||
if (needMatchToSourceBill && !flag && !noMatchCodeAndRowMapping.ContainsKey(key))
|
||
{
|
||
noMatchCodeAndRowMapping.Add(key, rowIndex);
|
||
}
|
||
|
||
EntryGrid control = base.View.GetControl<EntryGrid>("FScanDetailEntity");
|
||
control.SetForecolor("FBarCode", "#FF0000", rowIndex);
|
||
}
|
||
}
|
||
|
||
private void ClearMatchData()
|
||
{
|
||
int entryRowCount = Model.GetEntryRowCount("FScanDetailEntity");
|
||
EntryGrid control = base.View.GetControl<EntryGrid>("FScanDetailEntity");
|
||
for (int i = 0; i < entryRowCount; i++)
|
||
{
|
||
base.View.Model.SetValue("FIsMatched", false, i);
|
||
control.SetForecolor("FBarCode", "", i);
|
||
}
|
||
|
||
noMatchCodeAndRowMapping.Clear();
|
||
dctMatchData.Clear();
|
||
}
|
||
|
||
private void SummaryScanDetail_New()
|
||
{
|
||
validCodeAndSumRowMapping = new Dictionary<string, int>();
|
||
validCodeAndSumSrcEntryIDMapping = new Dictionary<string, long>();
|
||
validSumRowMapping = new Dictionary<int, Dictionary<string, decimal>>();
|
||
validSumRowSeriMapping = new Dictionary<int, Dictionary<string, string>>();
|
||
Entity entity = base.View.BusinessInfo.GetEntity("FScanSummaryEntity");
|
||
DynamicObjectCollection entityDataObject = base.View.Model.GetEntityDataObject(entity);
|
||
entityDataObject.Clear();
|
||
Entity entity2 = base.View.BusinessInfo.GetEntity("FScanDetailEntity");
|
||
DynamicObjectCollection entityDataObject2 = base.View.Model.GetEntityDataObject(entity2);
|
||
int num = 0;
|
||
needMatchToSourceBill = Convert.ToBoolean(base.View.Model.GetValue("FISMAPTOSOURCEBILL"));
|
||
lstSumMatchItem = GetMatchRuleContentByTagBillName();
|
||
foreach (DynamicObject detailEntry in entityDataObject2)
|
||
{
|
||
string text = Convert.ToString(detailEntry["BarCode"]);
|
||
string value = text;
|
||
if (needMatchToSourceBill && detailEntry["SerialNo"] is DynamicObject dynamicObject)
|
||
{
|
||
value = Convert.ToString(dynamicObject["Number"]);
|
||
}
|
||
|
||
if (invalidCodeAndRowMapping.Values.Contains(text))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
DynamicObject dynamicObject2 = null;
|
||
long srcEntryId = 0L;
|
||
long srcSubEntryId = 0L;
|
||
long num2 = 0L;
|
||
long BillSeq = 0L;
|
||
var sourceBillId = 0L;
|
||
if (needMatchToSourceBill && dctMatchData.ContainsKey(text))
|
||
{
|
||
Dictionary<string, string> dictionary = dctMatchData[text];
|
||
srcEntryId = Convert.ToInt64(dictionary["ENTRYID"]);
|
||
srcSubEntryId = Convert.ToInt64(dictionary["SUBENTRYID"]);
|
||
num2 = Convert.ToInt64(dictionary["SEQ"]);
|
||
BillSeq = Convert.ToInt64(dictionary["BillSeq"]);
|
||
sourceBillId = dictionary["BillSrcId"].Long2Int();
|
||
string msg2 = string.Empty;
|
||
dynamicObject2 = entityDataObject.Where((DynamicObject p) => Convert.ToInt64(p["SUMBILLENTRYID"]) == srcEntryId && Convert.ToInt64(p["SUMBILLSUBENTRYID"]) == srcSubEntryId && Convert.ToInt64(p["SUMBILLSEQ"]) == BillSeq && isMatchSumWhereValue(detailEntry, p, ref msg2)).FirstOrDefault();
|
||
}
|
||
else
|
||
{
|
||
string msg = string.Empty;
|
||
dynamicObject2 = entityDataObject.Where((DynamicObject p) => isMatchSumWhereValue(detailEntry, p, ref msg)).FirstOrDefault();
|
||
}
|
||
|
||
if (dynamicObject2.IsNullOrEmpty())
|
||
{
|
||
num++;
|
||
DynamicObject dynamicObject3 = new DynamicObject(entity.DynamicObjectType);
|
||
dynamicObject3["Seq"] = num;
|
||
dynamicObject3["SUMBILLID"] = sourceBillId;
|
||
dynamicObject3["SUMBILLENTRYID"] = srcEntryId;
|
||
dynamicObject3["SUMBILLSUBENTRYID"] = srcSubEntryId;
|
||
foreach (DynamicProperty property in detailEntry.DynamicObjectType.Properties)
|
||
{
|
||
string empty = string.Empty;
|
||
if (!(property.Name == "Id") && !(property.Name == "Seq"))
|
||
{
|
||
empty = "Sum" + property.Name;
|
||
if (dynamicObject3.DynamicObjectType.Properties.Contains(empty))
|
||
{
|
||
dynamicObject3[empty] = detailEntry[property.Name];
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!validSumRowMapping.ContainsKey(num))
|
||
{
|
||
Dictionary<string, decimal> dictionary2 = new Dictionary<string, decimal>();
|
||
dictionary2.Add(text, Convert.ToDecimal(detailEntry["Qty"]));
|
||
validSumRowMapping.Add(num, dictionary2);
|
||
}
|
||
else
|
||
{
|
||
Dictionary<string, decimal> dictionary3 = validSumRowMapping[num];
|
||
if (dictionary3.ContainsKey(text))
|
||
{
|
||
dictionary3[text] += Convert.ToDecimal(detailEntry["Qty"]);
|
||
}
|
||
else
|
||
{
|
||
dictionary3.Add(text, Convert.ToDecimal(detailEntry["Qty"]));
|
||
}
|
||
}
|
||
|
||
if (!validSumRowSeriMapping.ContainsKey(num))
|
||
{
|
||
Dictionary<string, string> dictionary4 = new Dictionary<string, string>();
|
||
dictionary4.Add(text, value);
|
||
validSumRowSeriMapping.Add(num, dictionary4);
|
||
}
|
||
else
|
||
{
|
||
Dictionary<string, string> dictionary5 = validSumRowSeriMapping[num];
|
||
if (!dictionary5.ContainsKey(text))
|
||
{
|
||
dictionary5.Add(text, value);
|
||
}
|
||
}
|
||
|
||
if (!validCodeAndSumRowMapping.ContainsKey(text))
|
||
{
|
||
validCodeAndSumRowMapping.Add(text, num);
|
||
}
|
||
|
||
if (!validCodeAndSumSrcEntryIDMapping.ContainsKey(text))
|
||
{
|
||
validCodeAndSumSrcEntryIDMapping.Add(text, srcEntryId);
|
||
}
|
||
|
||
if (!validCodeAndQtyMapping.ContainsKey(text))
|
||
{
|
||
validCodeAndQtyMapping.Add(text, Convert.ToDecimal(detailEntry["Qty"]));
|
||
}
|
||
else
|
||
{
|
||
validCodeAndQtyMapping[text] += Convert.ToDecimal(detailEntry["Qty"]);
|
||
}
|
||
|
||
entityDataObject.Add(dynamicObject3);
|
||
continue;
|
||
}
|
||
|
||
decimal num3 = Convert.ToDecimal(dynamicObject2["SumQty"]);
|
||
dynamicObject2["SumQty"] = num3 + Convert.ToDecimal(detailEntry["Qty"]);
|
||
int num4 = Convert.ToInt32(dynamicObject2["Seq"]);
|
||
if (!validSumRowMapping.ContainsKey(num4))
|
||
{
|
||
Dictionary<string, decimal> dictionary6 = new Dictionary<string, decimal>();
|
||
dictionary6.Add(text, Convert.ToDecimal(detailEntry["Qty"]));
|
||
validSumRowMapping.Add(num, dictionary6);
|
||
}
|
||
else
|
||
{
|
||
Dictionary<string, decimal> dictionary7 = validSumRowMapping[num4];
|
||
if (dictionary7.ContainsKey(text))
|
||
{
|
||
dictionary7[text] += Convert.ToDecimal(detailEntry["Qty"]);
|
||
}
|
||
else
|
||
{
|
||
dictionary7.Add(text, Convert.ToDecimal(detailEntry["Qty"]));
|
||
}
|
||
}
|
||
|
||
if (!validSumRowSeriMapping.ContainsKey(num4))
|
||
{
|
||
Dictionary<string, string> dictionary8 = new Dictionary<string, string>();
|
||
dictionary8.Add(text, value);
|
||
validSumRowSeriMapping.Add(num, dictionary8);
|
||
}
|
||
else
|
||
{
|
||
Dictionary<string, string> dictionary9 = validSumRowSeriMapping[num4];
|
||
if (!dictionary9.ContainsKey(text))
|
||
{
|
||
dictionary9.Add(text, value);
|
||
}
|
||
}
|
||
|
||
if (!validCodeAndSumRowMapping.ContainsKey(text))
|
||
{
|
||
validCodeAndSumRowMapping.Add(text, num4);
|
||
}
|
||
|
||
if (!validCodeAndSumSrcEntryIDMapping.ContainsKey(text))
|
||
{
|
||
validCodeAndSumSrcEntryIDMapping.Add(text, srcEntryId);
|
||
}
|
||
|
||
if (!validCodeAndQtyMapping.ContainsKey(text))
|
||
{
|
||
validCodeAndQtyMapping.Add(text, Convert.ToDecimal(detailEntry["Qty"]));
|
||
}
|
||
else
|
||
{
|
||
validCodeAndQtyMapping[text] += Convert.ToDecimal(detailEntry["Qty"]);
|
||
}
|
||
}
|
||
|
||
if (entityDataObject != null && !entityDataObject.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
doSummaryDatas = entityDataObject;
|
||
}
|
||
|
||
base.View.UpdateView("FScanSummaryEntity");
|
||
}
|
||
|
||
private decimal GetNewQtyByMatchData(long masterialmasterId)
|
||
{
|
||
decimal result = default(decimal);
|
||
foreach (Dictionary<string, string> value in dctMatchData.Values)
|
||
{
|
||
if (Convert.ToInt64(value["MATERIALMASTERID"]) == masterialmasterId)
|
||
{
|
||
result = Convert.ToDecimal(value["QTY"]);
|
||
}
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
private decimal GetNewQtyByMatchData_New(long masterialmasterId)
|
||
{
|
||
decimal result = default(decimal);
|
||
if (doSummaryDatas != null)
|
||
{
|
||
foreach (DynamicObject doSummaryData in doSummaryDatas)
|
||
{
|
||
if (doSummaryData["SumMaterialId"] != null)
|
||
{
|
||
DynamicObject dynamicObject = doSummaryData["SumMaterialId"] as DynamicObject;
|
||
if (Convert.ToInt64(dynamicObject[FormConst.MASTER_ID]) == masterialmasterId)
|
||
{
|
||
result = Convert.ToDecimal(doSummaryData["SUMQTY"]);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
private void GetSourceBillTypeKeyProperty(string formId)
|
||
{
|
||
if (formId.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
ClearSourceBillTypeKeyProperty();
|
||
return;
|
||
}
|
||
|
||
FormMetadata formMetadata = (FormMetadata)MetaDataServiceHelper.Load(base.View.Context, formId);
|
||
DynamicObject dynamicObject = BarCodeCommonServiceHelper.LoadBillData(base.Context, "BD_BarCodeItem", 4).FirstOrDefault();
|
||
DynamicObjectCollection source = dynamicObject["BD_BARCODEITEMENTRY"] as DynamicObjectCollection;
|
||
DynamicObject dynamicObject2 = source.Where((DynamicObject p) => Convert.ToString(p["BILLFORMID_ID"]).EqualsIgnoreCase(formId)).FirstOrDefault();
|
||
if (dynamicObject2 != null)
|
||
{
|
||
srcMaterialIdKey = Convert.ToString(dynamicObject2["FieldKey"]);
|
||
srcMaterialIdPropName = formMetadata.BusinessInfo.GetField(srcMaterialIdKey).PropertyName;
|
||
srcEntryKey = formMetadata.BusinessInfo.GetField(srcMaterialIdKey).EntityKey;
|
||
srcEntryEntity = formMetadata.BusinessInfo.GetField(srcMaterialIdKey).Entity;
|
||
}
|
||
else
|
||
{
|
||
base.View.Model.SetValue("FSOURCEBILLNAME", null);
|
||
base.View.ShowErrMessage(string.Format(ResManager.LoadKDString("条码属性【物料编码】的业务对象设置中缺少源单单据【{0}】及对应的字段,请先维护!", "eccc647f9e43469a", "APP_ISVPAAC2016062210550"), formMetadata.Name.ToString(base.Context.UserLocale)));
|
||
}
|
||
|
||
dynamicObject = BarCodeCommonServiceHelper.LoadBillData(base.Context, "BD_BarCodeItem", 19).FirstOrDefault();
|
||
source = dynamicObject["BD_BARCODEITEMENTRY"] as DynamicObjectCollection;
|
||
dynamicObject2 = source.Where((DynamicObject p) => Convert.ToString(p["BILLFORMID_ID"]).EqualsIgnoreCase(formId)).FirstOrDefault();
|
||
srcQtyKey = ((dynamicObject2 != null) ? Convert.ToString(dynamicObject2["FieldKey"]) : string.Empty);
|
||
}
|
||
|
||
private void ClearSourceBillTypeKeyProperty()
|
||
{
|
||
srcEntryKey = "";
|
||
srcMaterialIdKey = "";
|
||
srcMaterialIdPropName = "";
|
||
srcQtyKey = "";
|
||
srcEntryEntity = null;
|
||
}
|
||
|
||
private void GetCreateBillTypeKeyProperty(string formId)
|
||
{
|
||
if (formId.IsNullOrEmptyOrWhiteSpace())
|
||
{
|
||
ClearCreateBillTypeKeyProperty();
|
||
return;
|
||
}
|
||
|
||
FormMetadata formMetadata = (FormMetadata)MetaDataServiceHelper.Load(base.View.Context, formId);
|
||
DynamicObject dynamicObject = BarCodeCommonServiceHelper.LoadBillData(base.Context, "BD_BarCodeItem", 4).FirstOrDefault();
|
||
DynamicObjectCollection source = dynamicObject["BD_BARCODEITEMENTRY"] as DynamicObjectCollection;
|
||
DynamicObject dynamicObject2 = source.Where((DynamicObject p) => Convert.ToString(p["BILLFORMID_ID"]).EqualsIgnoreCase(formId)).FirstOrDefault();
|
||
createMaterialIdKey = Convert.ToString(dynamicObject2["FieldKey"]);
|
||
createMaterialIdPropName = formMetadata.BusinessInfo.GetField(createMaterialIdKey).PropertyName;
|
||
createEntryKey = formMetadata.BusinessInfo.GetField(createMaterialIdKey).EntityKey;
|
||
dynamicObject = BarCodeCommonServiceHelper.LoadBillData(base.Context, "BD_BarCodeItem", 19).FirstOrDefault();
|
||
source = dynamicObject["BD_BARCODEITEMENTRY"] as DynamicObjectCollection;
|
||
dynamicObject2 = source.Where((DynamicObject p) => Convert.ToString(p["BILLFORMID_ID"]).EqualsIgnoreCase(formId)).FirstOrDefault();
|
||
createQtyKey = Convert.ToString(dynamicObject2["FieldKey"]);
|
||
}
|
||
|
||
private void ClearCreateBillTypeKeyProperty()
|
||
{
|
||
createEntryKey = "";
|
||
createMaterialIdKey = "";
|
||
createMaterialIdPropName = "";
|
||
createQtyKey = "";
|
||
}
|
||
|
||
private void InitNewVaraible()
|
||
{
|
||
needMatchToSourceBill = Convert.ToBoolean(base.View.Model.GetValue("FISMAPTOSOURCEBILL"));
|
||
validCodeAndRowMapping = new Dictionary<string, int>();
|
||
validCodeAndQtyMapping = new Dictionary<string, decimal>();
|
||
dctMatchData = new Dictionary<string, Dictionary<string, string>>();
|
||
invalidCodeAndRowMapping = new Dictionary<int, string>();
|
||
if (needMatchToSourceBill)
|
||
{
|
||
lstMatchItem = GetMatchRuleContent();
|
||
MatchScanData();
|
||
}
|
||
else
|
||
{
|
||
ClearMatchData();
|
||
}
|
||
|
||
//sourceBillId = 0L;
|
||
sourceBillFormId = "";
|
||
//sourceBillNo = "";
|
||
_sourceBillIds = null;
|
||
_sourceBillNos = null;
|
||
_sourceBillNoToIds = null;
|
||
barcodeRuleId = 0L;
|
||
barcodeRuleNewId = 0L;
|
||
barcodeRuleEntities = null;
|
||
ClearCreateBillTypeKeyProperty();
|
||
ClearSourceBillTypeKeyProperty();
|
||
}
|
||
|
||
private void ShowTargetForm(string formId, long pkValue)
|
||
{
|
||
string pageId = Guid.NewGuid().ToString();
|
||
BillShowParameter billShowParameter = new BillShowParameter();
|
||
billShowParameter.FormId = formId;
|
||
billShowParameter.OpenStyle.ShowType = ShowType.Floating;
|
||
billShowParameter.PageId = pageId;
|
||
billShowParameter.Status = OperationStatus.EDIT;
|
||
billShowParameter.PKey = Convert.ToString(pkValue);
|
||
base.View.ShowForm(billShowParameter);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 多选单据
|
||
/// </summary>
|
||
/// <param name="sourceBillFormId"></param>
|
||
public void OpenBarCodeGetBill(string sourceBillFormId)
|
||
{
|
||
if (string.IsNullOrEmpty(sourceBillFormId))
|
||
{
|
||
base.View.ShowWarnningMessage(ResManager.LoadKDString("请先录入源业务对象!", "0011019000003167", SubSystemType.BASE));
|
||
return;
|
||
}
|
||
|
||
string text = sourceBillFormId;
|
||
|
||
List<long> permissionOrg = PermissionServiceHelper.GetPermissionOrg(base.View.Context, new BusinessObject
|
||
{
|
||
Id = text
|
||
}, "6e44119a58cb4a8e86f6c385e14a17ad");
|
||
if (!permissionOrg.Contains(base.Context.CurrentOrganizationInfo.ID))
|
||
{
|
||
base.View.ShowWarnningMessage(ResManager.LoadKDString("当前组织下没有源业务对象的查看权限,不允许选单!", "0011019000003231", SubSystemType.BASE));
|
||
return;
|
||
}
|
||
|
||
ListShowParameter listShowParameter = new ListShowParameter();
|
||
billPageId = SequentialGuid.NewGuid().ToString();
|
||
listShowParameter.IsLookUp = true;
|
||
listShowParameter.ParentPageId = base.View.PageId;
|
||
listShowParameter.FormId = sourceBillFormId;
|
||
listShowParameter.MultiSelect = true;
|
||
listShowParameter.PageId = billPageId;
|
||
listShowParameter.IsIsolationOrg = true;
|
||
if (sourceBillFormId.EqualsIgnoreCase("BD_MATERIAL"))
|
||
{
|
||
listShowParameter.ListType = Convert.ToInt32(BOSEnums.Enu_ListType.BaseList);
|
||
}
|
||
|
||
if (sourceBillFormId.EqualsIgnoreCase("ENG_WorkCenter"))
|
||
{
|
||
listShowParameter.CustomParams.Add("WorkCenterType", "D");
|
||
}
|
||
|
||
if (sourceBillFormId.EqualsIgnoreCase("STK_Inventory"))
|
||
{
|
||
listShowParameter.CustomParams.Add("NeedReturnData", "1");
|
||
listShowParameter.CustomParams.Add("IsFromStockQuery", "True");
|
||
listShowParameter.CustomParams.Add("QueryMode", "1");
|
||
listShowParameter.CustomParams.Add("IsShowExit", "True");
|
||
listShowParameter.CustomParams.Add("IsFromQuery", "True");
|
||
}
|
||
|
||
string text2 = string.Empty;
|
||
List<string> list = new List<string>();
|
||
list.Add("PUR_PurchaseOrder");
|
||
list.Add("SAL_SaleOrder");
|
||
list.Add("SAL_DELIVERYNOTICE");
|
||
if (list.Contains(sourceBillFormId))
|
||
{
|
||
text2 = " t0.FCLOSESTATUS='A' ";
|
||
}
|
||
|
||
if (sourceBillFormId == "PRD_MO")
|
||
{
|
||
text2 = " t1_A.FSTATUS!=6 ";
|
||
}
|
||
|
||
if (sourceBillFormId == "SUB_SUBREQORDER")
|
||
{
|
||
text2 = " t1.FSTATUS!=6 ";
|
||
}
|
||
|
||
if (sourceBillFormId == "STK_LOTADJUST")
|
||
{
|
||
text2 += (text2.IsNullOrEmptyOrWhiteSpace() ? " FConvertType='B' " : " AND FConvertType='B' ");
|
||
}
|
||
|
||
if (sourceBillFormId == "FA_CARD")
|
||
{
|
||
text2 = "FISNEWREC=2";
|
||
}
|
||
|
||
if (sourceBillFormId.ToUpperInvariant() == "PUR_RECEIVEBILL" && createBillFormId.ToUpperInvariant() == "STK_INSTOCK")
|
||
{
|
||
text2 = " abs(FBaseStockInMaxQty) - abs(FInStockJoinBaseQty) - abs(FReturnJoinBaseQty) >0 And ( (FReceiveBaseQty - FInStockJoinBaseQty > 0 Or FProcScrapQty - FProcScrapJoinQty > 0 Or FMtrlScrapQty - FMtrlScrapJoinQty > 0 Or FCsnReceiveQty - FCsnReceiveJoinQty > 0 Or FRefuseQty - FRefuseJoinQty - FReturnJoinQty > 0) OR FCheckInComing = '0' Or FEmergencyRelease = 'B' ) ";
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(text2))
|
||
{
|
||
if (string.IsNullOrEmpty(listShowParameter.ListFilterParameter.Filter))
|
||
{
|
||
listShowParameter.ListFilterParameter.Filter = text2;
|
||
}
|
||
else
|
||
{
|
||
IRegularFilterParameter listFilterParameter = listShowParameter.ListFilterParameter;
|
||
listFilterParameter.Filter = listFilterParameter.Filter + " AND " + text2;
|
||
}
|
||
}
|
||
|
||
base.View.ShowForm(listShowParameter, delegate (FormResult result)
|
||
{
|
||
if (result != null)
|
||
{
|
||
object returnData = result.ReturnData;
|
||
if (returnData is ListSelectedRowCollection && returnData is ListSelectedRowCollection listSelectedRowCollection && !listSelectedRowCollection.IsEmpty())
|
||
{
|
||
//sourceBillId = Convert.ToInt32(listSelectedRowCollection[0].PrimaryKeyValue);
|
||
_sourceBillNoToIds = new Dictionary<string, long>();
|
||
_sourceBillIds = new List<long>();
|
||
_sourceBillNos = new List<string>();
|
||
foreach (var row in listSelectedRowCollection)
|
||
{
|
||
if (_sourceBillNoToIds.ContainsKey(row.BillNo))
|
||
continue;
|
||
_sourceBillIds.Add(row.PrimaryKeyValue.LongCount());
|
||
_sourceBillNos.Add(row.BillNo);
|
||
_sourceBillNoToIds.Add(row.BillNo, row.PrimaryKeyValue.Long2Int());
|
||
}
|
||
|
||
Model.SetValue("FSOURCEBILLID", string.Join(",", _sourceBillNos));
|
||
}
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}
|