星空二开对接地磅,电子称方案分享

因为社区上对接地磅的案例比较少,今天就厚脸皮分享一个不太成熟的案例给大家!不足之处望各位大佬多多指教![]()
业务场景:客户需要扫描托码或者箱码,箱/托的标准重量应当事先维护好一个值,也可以给客户做一个装托/箱单,给他生成托码箱码标准重量信息这些,这里就只分享地磅的对接方法和代码。
准备工作:端口模拟工具(VSPD6.9),端口模拟发送软件(bittly),这种软件不一定要用这两个,网上搜一堆,主要是用来模拟连接地磅,模拟地磅发送数据的。因为我们大部分的电子称,地磅基本都是用串口连接的,所以我们本地开发需要这些工具。还需要了解一下端口传输速率的一些基础知识,或者看这个类也可以:KDSerialPortConfig,上面会有相关的参数属性说明,对着地磅,电子称的说明抄就可以了。
设计说明:如下图案例是根发货通知单来进行称重的,所以开发了扫描发货单号自动拉取发货单的相关信息到称重单上。
49.3区域显示当前地磅的重量,右侧显示当前箱码,当前地磅重量与标准重量对比是否符合称重要求。如满足则自动将当前箱/托信息记录到明细行。

代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using BW.K3Cloud.DiBangApp.Business.Plugin.Utils;
using Kingdee.BOS;
using Kingdee.BOS.App;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.Operation;
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.ConvertElement;
using Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs;
using Kingdee.BOS.DataEntity;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
namespace BW.K3Cloud.DiBangApp.Business.Plugin
{
[Description("称重单表单插件")]
[HotUpdate]
public class WeighBillEdit : AbstractBillPlugIn
{
private readonly string red = "#FF0000";
private readonly string green = "#00FF00";
private readonly string blue = "#0000FF";
/// 是否显示保存信息
private bool isShowMessage = true;
public override void AfterBindData(EventArgs e)
{
base.AfterBindData(e);
int height = 25;
this.View.GetControl("FScan").SetCustomPropertyValue("height", height);
this.View.GetControl("FTorrSTDWeight").SetCustomPropertyValue("height", height);
this.View.GetControl("FErrorRate").SetCustomPropertyValue("height", height);
this.View.GetControl("FSCSWeight").SetCustomPropertyValue("height", height);
//设置按钮大小颜色
this.View.GetControl("FStartWeight").SetCustomPropertyValue("FontSize", 16);
this.View.GetControl("FEndWeight").SetCustomPropertyValue("FontSize", 16);
this.View.GetControl("FScan").Enabled = false;
// this.View.GetControl("FDeliveryNotice").SetFocus();
}
public override void BeforeF7Select(BeforeF7SelectEventArgs e)
{
base.BeforeF7Select(e);
//发货通知选单
if (e.FieldKey.EqualsIgnoreCase("FDeliveryNotice"))
{
ListShowParameter show = new ListShowParameter();
show.FormId = "SAL_DELIVERYNOTICE";
show.IsLookUp = true; //是否显示返回数据
show.MultiSelect = false; //是否多选
show.IsUseDefaultScheme = true;
show.ListType = Convert.ToInt32(BOSEnums.Enu_GetListDataType.List);
show.ListFilterParameter.Filter =
"FDocumentStatus='C' and FCLOSESTATUS='A' and FCancelStatus='A' and FTerminationStatus='A'";
this.View.ShowForm(show, result =>
{
var returnData = result.ReturnData;
if (returnData == null) return;
var resObj = (ListSelectedRowCollection)returnData;
var fhObj = KEDUtils.GetQueryData(this.Context, "SAL_DELIVERYNOTICE",
$"FID = {resObj[0].PrimaryKeyValue}");
this.setHeadValue(fhObj);
});
}
}
public override void ButtonClick(ButtonClickEventArgs e)
{
base.ButtonClick(e);
//开始称重
if (e.Key.EqualsIgnoreCase("FStartWeight"))
{
//获取端口名称
var comPort = this.Model.GetValue("FDBProt").ToString();
//new 一个串口配置对象
var kdSerialPort = new KDSerialPortConfig
{
PortName = comPort,
Rate = 9600,
Parity = 0,
Bits = 8,
StopBits = 1,
Timeout = -1
};
this.View.GetControl<SerialPortControl>("FSerialPortCtrl").Init(kdSerialPort); // 初始化并打开端口
this.View.ShowMessage("地磅连接成功!");
this.View.GetControl("FScan").Enabled = true;
this.View.GetControl("FScan").SetFocus();
}
//结束称重
if (e.Key.EqualsIgnoreCase("FEndWeight"))
{
this.View.GetControl<SerialPortControl>("FSerialPortCtrl").Close();//关闭串口
this.View.GetControl("FScan").Enabled = false;
this.View.ShowMessage("地磅连接关闭成功!");
}
}
public override void BarItemClick(BarItemClickEventArgs e)
{
base.BarItemClick(e);
if (e.BarItemKey.EqualsIgnoreCase("tbPushSaleOutStock"))
{
var pkValue = this.Model.GetValue("FFHFID",0).ToString();
var billTypeId = "193822715afc48aa9fa6d6beca7700ab";//标准发货通知单
var ruleId = "DeliveryNotice-OutStock"; //默认单据转换为发货通知单
var targetFormId = "SAL_OUTSTOCK"; //默认目标单为销售出库单
Dictionary<string, object> dic = this.GetPushData();
var pushEntryIds = dic.Keys.ToList();
DynamicObject[] objects = this.Push(this.Context, "SAL_DELIVERYNOTICE", targetFormId, ruleId,
pkValue, pushEntryIds, "FEntity", billTypeId);
var outView = KEDUtils.CreateBillView(this.Context, targetFormId);
outView.Model.DataObject = objects[0];
var fhEntry = outView.Model.GetEntityDataObject(outView.Model.BusinessInfo.GetEntity("FEntity")).ToList();
foreach (var valuePair in dic)
{
int index = fhEntry.FindIndex(x => x["FSourceEntryId"].ToString().Equals(valuePair.Key));
outView.Model.SetValue("FRealQty", valuePair.Value, index);
outView.InvokeFieldUpdateService("FRealQty", index);
}
var saveBill = KEDUtils.SaveBill(this.Context, targetFormId, outView.Model.DataObject);
if (saveBill.IsSuccess)
{
this.Model.SetValue("FJoinOutBills", saveBill.OperateResult.First().Number);
isShowMessage = false;
this.View.InvokeFormOperation(FormOperationEnum.Save);
this.View.ShowMessage("下推出库单成功!");
if (Convert.ToBoolean(this.Model.GetValue("FOutBillAudit")))
{
IOperationResult result = KEDUtils.SubmitAndAuditBill(this.Context, targetFormId,
new[] { saveBill.Oper
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using BW.K3Cloud.DiBangApp.Business.Plugin.Utils;
using Kingdee.BOS;
using Kingdee.BOS.App;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.Operation;
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.ConvertElement;
using Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs;
using Kingdee.BOS.DataEntity;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
namespace BW.K3Cloud.DiBangApp.Business.Plugin
{
[Description("称重单表单插件")]
[HotUpdate]
public class WeighBillEdit : AbstractBillPlugIn
{
private readonly string red = "#FF0000";
private readonly string green = "#00FF00";
private readonly string blue = "#0000FF";
/// 是否显示保存信息
private bool isShowMessage = true;
public override void AfterBindData(EventArgs e)
{
base.AfterBindData(e);
int height = 25;
this.View.GetControl("FScan").SetCustomPropertyValue("height", height);
this.View.GetControl("FTorrSTDWeight").SetCustomPropertyValue("height", height);
this.View.GetControl("FErrorRate").SetCustomPropertyValue("height", height);
this.View.GetControl("FSCSWeight").SetCustomPropertyValue("height", height);
//设置按钮大小颜色
this.View.GetControl("FStartWeight").SetCustomPropertyValue("FontSize", 16);
this.View.GetControl("FEndWeight").SetCustomPropertyValue("FontSize", 16);
this.View.GetControl("FScan").Enabled = false;
// this.View.GetControl("FDeliveryNotice").SetFocus();
}
public override void BeforeF7Select(BeforeF7SelectEventArgs e)
{
base.BeforeF7Select(e);
//发货通知选单
if (e.FieldKey.EqualsIgnoreCase("FDeliveryNotice"))
{
ListShowParameter show = new ListShowParameter();
show.FormId = "SAL_DELIVERYNOTICE";
show.IsLookUp = true; //是否显示返回数据
show.MultiSelect = false; //是否多选
show.IsUseDefaultScheme = true;
show.ListType = Convert.ToInt32(BOSEnums.Enu_GetListDataType.List);
show.ListFilterParameter.Filter =
"FDocumentStatus='C' and FCLOSESTATUS='A' and FCancelStatus='A' and FTerminationStatus='A'";
this.View.ShowForm(show, result =>
{
var returnData = result.ReturnData;
if (returnData == null) return;
var resObj = (ListSelectedRowCollection)returnData;
var fhObj = KEDUtils.GetQueryData(this.Context, "SAL_DELIVERYNOTICE",
$"FID = {resObj[0].PrimaryKeyValue}");
this.setHeadValue(fhObj);
});
}
}
public override void ButtonClick(ButtonClickEventArgs e)
{
base.ButtonClick(e);
//开始称重
if (e.Key.EqualsIgnoreCase("FStartWeight"))
{
//获取端口名称
var comPort = this.Model.GetValue("FDBProt").ToString();
//new 一个串口配置对象
var kdSerialPort = new KDSerialPortConfig
{
PortName = comPort,
Rate = 9600,
Parity = 0,
Bits = 8,
StopBits = 1,
Timeout = -1
};
this.View.GetControl<SerialPortControl>("FSerialPortCtrl").Init(kdSerialPort); // 初始化并打开端口
this.View.ShowMessage("地磅连接成功!");
this.View.GetControl("FScan").Enabled = true;
this.View.GetControl("FScan").SetFocus();
}
//结束称重
if (e.Key.EqualsIgnoreCase("FEndWeight"))
{
this.View.GetControl<SerialPortControl>("FSerialPortCtrl").Close();//关闭串口
this.View.GetControl("FScan").Enabled = false;
this.View.ShowMessage("地磅连接关闭成功!");
}
}
public override void BarItemClick(BarItemClickEventArgs e)
{
base.BarItemClick(e);
if (e.BarItemKey.EqualsIgnoreCase("tbPushSaleOutStock"))
{
var pkValue = this.Model.GetValue("FFHFID",0).ToString();
var billTypeId = "193822715afc48aa9fa6d6beca7700ab";//标准发货通知单
var ruleId = "DeliveryNotice-OutStock"; //默认单据转换为发货通知单
var targetFormId = "SAL_OUTSTOCK"; //默认目标单为销售出库单
Dictionary<string, object> dic = this.GetPushData();
var pushEntryIds = dic.Keys.ToList();
DynamicObject[] objects = this.Push(this.Context, "SAL_DELIVERYNOTICE", targetFormId, ruleId,
pkValue, pushEntryIds, "FEntity", billTypeId);
var outView = KEDUtils.CreateBillView(this.Context, targetFormId);
outView.Model.DataObject = objects[0];
var fhEntry = outView.Model.GetEntityDataObject(outView.Model.BusinessInfo.GetEntity("FEntity")).ToList();
foreach (var valuePair in dic)
{
int index = fhEntry.FindIndex(x => x["FSourceEntryId"].ToString().Equals(valuePair.Key));
outView.Model.SetValue("FRealQty", valuePair.Value, index);
outView.InvokeFieldUpdateService("FRealQty", index);
}
var saveBill = KEDUtils.SaveBill(this.Context, targetFormId, outView.Model.DataObject);
if (saveBill.IsSuccess)
{
this.Model.SetValue("FJoinOutBills", saveBill.OperateResult.First().Number);
isShowMessage = false;
this.View.InvokeFormOperation(FormOperationEnum.Save);
this.View.ShowMessage("下推出库单成功!");
if (Convert.ToBoolean(this.Model.GetValue("FOutBillAudit")))
{
IOperationResult result = KEDUtils.SubmitAndAuditBill(this.Context, targetFormId,
new[] { saveBill.Oper
星空二开对接地磅,电子称方案分享
因为社区上对接地磅的案例比较少,今天就厚脸皮分享一个不太成熟的案例给大家!不足之处望各位大佬多多指教业务场景:客户需要扫描托码或者...
点击下载文档文档为doc格式
声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。
上一篇
已经是第一篇



