This note describes how to generate a new SSCC number and print label from a script.
You can automate this task with the following script configured for Produmex Robot tool.
In this example I am going to do the following steps:
- selecting the DocEntry, ItemCodes from Picklists where the content of the PickPackRemarks field is "print"
- generating new LUID from PmxLogisticUnitIDProvider object by method GenerateNewLogisticUnit(null)
- Creating the PmxReportProvider object to get the report from OSE reportProvider.GetBO(6);
- Creating the PmxOsePrinterProvider object to get the printer from OSE printerProvider.GetBO("PRINTER");
- Configuring the parameters of the report
- Printing the report PrintReport(report, printer, null, 1, null, reportParameters);
- Updating PickPackRemarks filed in the Picklist to "Printed"
I created a new label file for the logistic unit label, and I added some other parameters to the parameter list.
I configured the report file in OSE. I am going to use the ID of the report file in the script: 6
I am going to use the printer code from the OSE: PRINTER
Creating the script
Next, save the following script as PrintAndGenerateLabelForPicklist.cs into folder C:\Program Files\Produmex\Produmex Tools\CsScript\
//css_ref CrystalDecisions.CrystalReports.Engine.dll;
using Produmex.Foundation.Data.Sbo.BusinessObjects;
using Produmex.Foundation.Data.Sbo.Utilities;
using Produmex.Foundation.Data.Sbo;
using Produmex.Foundation.Diagnostics;
using Produmex.Sbo.Logex.Data.BusinessObjects;
using Produmex.Sbo.Logex.Data.Providers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using Produmex.Sbo.Logex.Data.Devices;
using Produmex.Sbo.Logex.Data.DataObjects;
using static Produmex.Foundation.Data.Sbo.ViewObjects.Definitions.Views.PmxParameterValueViewDefinition.Columns;
using System.Collections.ObjectModel;
using Produmex.Foundation.Data.Sbo.DataObjects;
using System.Security.Cryptography;
namespace AddUpdateData
{
internal class Program
{
private static string CONNECTION_STRING = "ADDYOURCONNECTIONSTRINGHERE";
private static readonly ILog s_log = LogProvider.GetLogger(MethodInfo.GetCurrentMethod().DeclaringType);
static void Main(string[] args)
{
try
{
DoSomething();
}
catch (Exception ex)
{
s_log.Error("", ex);
Console.WriteLine(ex);
Console.ReadLine();
}
}
public static void DoSomething()
{
List<int> Luids = new List<int>();
List<int> PLDE = new List<int>();
List<string> ItemCodes = new List<string>();
int iLuids = 0;
string PlDocEntries = "";
string LastDocEntry = "";
// OPEN TRANSACTION
using (TransactionScope scope = PmxDbConnection.GetNewTransactionScope())
{
using (PmxDbConnectionDirect conn = PmxDbConnectionMgr.GetDirectConnection(SboConnectionString.ParseStringToObject(CONNECTION_STRING)))
{
conn.Open();
string query = @"select
PMX_PLLI.ItemCode, PMX_PLHE.DocEntry
from
PMX_PLLI left join PMX_PLHE on PMX_PLLI.DocEntry = PMX_PLHE.DocEntry
where
PMX_PLHE.DocStatus = 'O' and PMX_PLHE.PickPackRemarks = 'print'
order by PMX_PLHE.DocEntry, PMX_PLLI.ItemCode
";
using (ISboRecordset rs1 = SboRecordsetHelper.RunQuery(s_log, query, conn))
{
while (!rs1.EoF)
{
if (LastDocEntry != rs1.GetTypedValue<int>("DocEntry").ToString() )
{
if (PlDocEntries == "") { PlDocEntries = rs1.GetTypedValue<int>("DocEntry").ToString(); }
else { PlDocEntries += ", " + rs1.GetTypedValue<int>("DocEntry").ToString(); }
LastDocEntry = rs1.GetTypedValue<int>("DocEntry").ToString();
}
PmxLogisticUnitIDProvider luidProv = new PmxLogisticUnitIDProvider(conn);
Luids.Add(luidProv.GenerateNewLogisticUnit(null));
ItemCodes.Add(rs1.GetTypedValue<string>("itemCode"));
PLDE.Add(rs1.GetTypedValue<int>("DocEntry"));
iLuids++;
rs1.MoveNext();
}
}
}
scope.Complete();
}
if (iLuids > 0) {
using (TransactionScope scope = PmxDbConnection.GetNewTransactionScope())
{
using (PmxDbConnectionDirect conn = PmxDbConnectionMgr.GetDirectConnection(SboConnectionString.ParseStringToObject(CONNECTION_STRING)))
{
conn.Open();
PmxReportProvider reportProvider = new Produmex.Sbo.Logex.Data.Providers.PmxReportProvider(conn);
PmxReport report = reportProvider.GetBO(6);
PmxOsePrinterProvider printerProvider = new PmxOsePrinterProvider(conn);
PmxOsePrinter printer = printerProvider.GetNewBO();
printer= printerProvider.GetBO("PRINTER");
for (int i = 0; i < iLuids; i++)
{
Collection<ReportParameter> reportParameters = new Collection<ReportParameter>();
reportParameters.Add(new ReportParameter("@luid", Luids[i]));
reportParameters.Add(new ReportParameter("@itemC", ItemCodes[i]));
reportParameters.Add(new ReportParameter("PLHE", PLDE[i]));
ReportPrinterDevice device = new ReportPrinterDevice(conn);
device.PrintReport(report, printer, null, 1, null, reportParameters);
}
string querySSCC = @"update PMX_PLHE set PickPackRemarks = 'Printed' where DocEntry in (" + PlDocEntries + ")";
SboRecordsetHelper.RunQuery(s_log, querySSCC, conn);
}
scope.Complete();
}
}
}
}
}
Run the Robot tool with the necessary parameters. Set the connection string in the last parameter (yourconnectionstringhere)
"C:\Program Files\Produmex\Produmex Tools\Produmex.Sbo.Logex.Tools.Robot.exe" /t:csscript /a1:"C:\Program Files\Produmex\Produmex Tools\CsScript\PrintAndGenerateLabelForPicklist.cs" /cs:yourconnectionstringhere
Pause
Comments
0 comments
Please sign in to leave a comment.