Page 1
DC and PEID Integration Code
Person responsible / Author: Jacopo Cassina – Holonix
Deliverable No.: D3.3
Work Package No.: WP3
Date: 16.12.2013
Project No.: 286885
Classification: Public
Distribution: To All the Consortium
File name: D3.3 – DC and PEID Integration Code
Number of pages: 82
Page 2
286885 BOMA
2
Status of Deliverable
Action By Date (dd.mm.yyyy)
Submitted (author(s)) Jacopo Cassina 31.07.2013
VU (WP Leader) Holonix
Revision History
Date (dd.mm.yyyy) Version (version revision) Author Comments
04.12.2013 Initial Structure Jacopo Cassina Matteo Barone
12.12.2013 Draft Version Matteo Barone
16.12.2013 Draft Version – revised Matteo Barone Fiorella Colombo
20.12.2013 Final Version Matteo Barone
30.12.2013 Final Version – revised Alberto Alberio Michele Tibaldi
31.07.2013 Final Version Approved Jacopo Cassina
Author(’s) contact information
Name Organisation E-mail Tel
Jacopo Cassina Holonix [email protected] +39 02 0362 1582033
Alberto Alberio Holonix [email protected]
Michele Tibaldi Holonix [email protected]
Fiorella Colombo Holonix [email protected]
Matteo Barone POLIMI [email protected]
Page 3
286885 BOMA
3
Table of Contents
1. ABSTRACT .................................................................................................................................................. 5
2. INTRODUCTION.......................................................................................................................................... 6
2.1. OBJECTIVES OF THIS DOCUMENT ................................................................................................................. 6 2.2. OVERVIEW ............................................................................................................................................ 6
3. DEVICE CONTROLLER INTERFACE AND PEID INTEGRATION ........................................................................ 7
3.1. PRODUCTION MANAGEMENT MODULE – PDA SIDE ........................................................................................ 7 3.2. TELEDIAGNOSTIC SYSTEM INTEGRATION MODULE ..........................................................................................10
4. CODE .........................................................................................................................................................11
4.1. PRODUCTION MANAGEMENT – PDA CODE .................................................................................................11 4.2. TELEDIAGNOSTIC SYSTEM INTEGRATION CODE...............................................................................................72
4.2.1. Web Services Code ........................................................................................................................72
5. CONCLUSION ............................................................................................................................................82
Page 4
286885 BOMA
4
Abbreviations and Acronyms:
LMS Lifecycle Management Server
BOW BOat web application BM BOMA Middleware
DSS Decision Support System
DC Device Controller
PEID Product Embedded Information Device
UMG Universal Marine Gateway
Page 5
286885 BOMA
5
1. Abstract
This deliverable describes the code that has been developed according to the specific needs of the Project related to the marine industry sector.
The input used is related to D3.1 – Concept Mock Up that describes in details every functionality of the Platform. To meet the requirements presented in the mock up the code described in the chapters of this document has been developed.
Firstly, a brief description of the target of the code will be presented, and then the java code will be fully reported.
Page 6
286885 BOMA
6
2. Introduction
The BOMA system is thought to manage the data of each physical boat manufactured and delivered to
the customer during the whole lifecycle. For this reason the infrastructure of the BOMA system
contemplates several layers:
The BOMA Middleware (BM)
The Lifecycle Management Server (LMS)
The Decision Support System (DSS)
The Device Controller (DC)
The BOat Web Application (BOW)
The infrastructure has been built following a web-service based approach in order to allow any enabled
user to exchange data with any other. In this infrastructure it is possible to distinguish between a front-end
and a back-end. The first one includes the BOat Web application (BOW) to manage the boat lifecycle. It is
constituted by several modules (as described in the deliverable D3.1), with different level of access for the
different kind of users (designer, producer, maintenance crew, boatowner, etc.). The back-end coincides
with the server side (the lifecycle management server and the decision support system) that will take care
of managing and storing all the web data, which will be needed, allowing “off-line” analysis and distributing
the BOW.
The Boat Web Application has been developed starting from the already existing extended product
lifecycle management suite i-Like, owned by Holonix. However it required specific customization in order to
be used in the marine industry. Moreover it needed several technical components, designed and built from
scratch, which enable the above mentioned capabilities. One of these components is the Device Controller
(DC), which allows the connection of Product Embedded Information Devices or other systems to the
BOMA architecture.
In this section is presented a brief description of the main components developed in order to build the
Device Controller and PEID Integration and finally the java code of each of those.
2.1. Objectives of this document
The objective of this document is to present the Device Controller and PEID Integration Code that has
been developed for BOMA Application.
2.2. Overview
This deliverable has two main chapters:
1. Device Controller and PEID Integration: it contains a description of the code that will be presented
in the second chapter. In particular, it describes what is the main goal of the code, the results that
will be obtained.
2. Code: the code has been reported.
Page 7
286885 BOMA
7
3. Device Controller Interface and PEID Integration
The Device Controller Interface developed is the technical component of the BOMA application that
allows the connection of Product Embedded Information Devices or other systems to the BOMA
architecture. This will make BOMA hardware independent, since new devices will be easily connected,
through a standardized interface. Then, the boat manufacturers will be able to choose also among the
existing telediagnostic hardware, which will be integrated as a boat hardware controller. This will allow
easily the connection of the different devices like:
RFiD-Barcode systems to trace the boat’s, components and spare parts data and information
Telediagnostic system, to read and measure BOAT’s data
In the following paragraphs two different modules are going to be described in detail:
The Production Management Module (PDA): it is the standard module that will enable the use
of RFiD-Barcode systems into production in order to trace the boat’s components and spare
parts through the use of the PDA industrial device
The UMG Integration Module: it is the standard module that will allow the communication
between the BOMA Platform and the telediagnostic system. In particular this module has been
already customized to efficiently communicate with the Universal Marine Gateway, the smart
telediagnostic device developed within the BOMA project according to the boat manufactures
needs and requirements
3.1. Production Management Module – PDA Side
The Production Management Module is the module of the BOMA Application that allows to manage
and monitor the production processes and to record the related data and information. It consists of two
different parts:
- The serve side – it is addressed into the deliverable D3.5 “Lifecycle Management Server Code”
- The PDA side – it is going to be described into details in the following paragraphs while in the
second chapter of this deliverable the code developed for its implementation is going to be fully
reported
The PDA Production Management module supports many operations:
- Execution of the production processes (Figure 1, 2, 3, 4, 5). In particular:
o Provide the list of processes to be executed for each production sheet. Several type of
processes are supported:
Merging: a process that has many inputs and only one output – ex. Moulding
Assembly: a process has in input a master uniquely identified and many other parts
and components, which will be assembled on the master. The parts and
components are not tracked anymore at the end of the process (Figure 3)
Action: this process comprises a set of simple activities that may require a
measurement and must be flagged as done or not done – ex. Test before the
launch (Figure 4)
Change type: it is the process that allows to change the type to parts and
components (Figure 5)
Page 8
286885 BOMA
8
o Provide the list of parts and components for each process
o Report the effective items and related quantities used for each process
o Report the start and end date of each process
Figure 1 Production Sheet Selection
Figure 2 Process List
Figure 3 Assembly Interface
Figure 4 Action Interface
Figure 5 Change Type Interface
- Report personnel involved (Figure 6)
This page reports firstly how many hours the process is expected to require in order to be completed. The procedure for recording the number of hours worked by each worker is the following:
Select the type of the operator
Select the operator
Insert the number of hours worked
Tick the box “responsible” is the worker is the crew chief
Click the button confirm to record the information inserted
If the procedure is done successfully than the information inserted will appear in the table at the
bottom of the page, otherwise the procedure must be repeated.
If the process involves only one worker than the procedure reported below must be done only one
time. Otherwise the process must be repeated for each worker who takes part into the process.
- Identify products by reading the barcode or the RFiD tag attached on them (Figure 7)
Page 9
286885 BOMA
9
It allows to retrieve all the information related to an item. By typing the product ID in the field
“Item Code” or reading the barcode/RFiD through the PDA, all the information available will be
shown on the screen
- Add a new product to the system (Figure 8)
This feature allows to create a new product item uniquely identified in the BOMA platform when it is not manufactured. The procedure for creating a new product item is the following:
Identify the product. Two possible options are available:
1. Type the item ID or the Batch ID or both
2. Read the barcode attached on the item (if available) using the barcode reader of
the PDA
Select the reason among the possible choices
Assign a new tag to the selected product. Two possible option are available:
1. Type the ID of the tag
2. Read the tag (if available) clicking on the button “RFID”
Type the amount of the product
Click the button “Confirm” in order to end the addition of the product
Figure 6 Report Personnel
Figure 7 Item Identification
Figure 8 Add new product
Page 10
286885 BOMA
10
3.2. Telediagnostic system Integration Module
The Telediagnostic System Integration Module is the standard module that allows the communication
between the BOMA Platform and the telediagnostic system. In particular this module has been already
customized to efficiently communicate with the Universal Marine Gateway, the smart telediagnostic device
developed within the BOMA project according to the boat manufactures needs and requirements.
The objective of the Telediagnostic System Integration Module is to enable the association and
communication between the telediagnostic system installed on the boat and its related avatar in the BOMA
Platform. This association consists of several steps:
1. Configuration of the telediagnostic system (for the UMG configuration cf. Deliverable D3.8
“Training Material”) – it is the first step required in order to properly complete the association.
Within this step, the uniquely ID of the boat already created into the BOMA platform must be
associated with the telediagnostic system ID. Each boat can have one or more systems
associated at the same time.
2. Verification of the telediagnostic system – it contacts the BOMA Platform using a REST API
based on Jersey 1.17, JAX-RS Java reference implementation. Once the BOMA application
recognizes the telediagnostic system, the association is completed
3. Enter sensors list – at this point, the telediagnostic system is associated to the corresponding
boat represented into the BOMA Platform. Then, the telediagnostic system sends the list of the
sensors installed which will be shown within the boat avatar page of the BOMA Platform
4. Data exchange – once the BOMA systems knows the sensors list, the data can be exchange. The
sampling and sending frequencies can be customized according to the boat manufactures and
boat owners needs (for the UMG configuration cf. Deliverable D3.8 “Training Material”)
In order to enable the association and communication processes, three different web services have
been developed:
1. Marine Gateway recognition – it allows to receive the unique ID of the telediagnostic system
and its association with the boat avatar into the BOMA Platform
2. Sensors list – it allows to get sensors information and the association between the sensor and
the teledignostic system previously recorded into the BOMA Platform
3. Data exchange – it allows to get the data from each sensor connected to the telediagnostic
system
In the second chapter of this deliverable the code developed to implement the above mentioned web
services, is going to be reported.
Page 11
286885 BOMA
11
4. Code
In the following sections the code developed for the BOMA Platform application is going to be
reported. The code reported is divided into two main sections:
- Production Management – PDA code: it comprises the code developed for building both the logic
implementation and the interface of the PDA application
- Telediagnostic System Integration Code: it is the code developed for implementing the three web
services which ensure the association and communication between telediagnostic systems and the
BOMA Platform
4.1. Production Management – PDA Code
using System; using System.Linq; using System.Collections.Generic; using System.Text; using holonix.datamodel; using holonix.restapi; using holonix.datamodel.auxiliary; using System.Windows.Forms; using holonix.winform; namespace holonix.controllers { public class CompleteProcess { RESTAPI.BillOfProcess billOfProcessAPI = RESTAPI.BillOfProcess.getInstance(); RESTAPI.BillOfProcessInput billOfProcessInputAPI = RESTAPI.BillOfProcessInput.getInstance(); RESTAPI.BillOfProcessOutput billOfProcessOutputAPI = RESTAPI.BillOfProcessOutput.getInstance(); RESTAPI.Process processAPI = RESTAPI.Process.getInstance(); RESTAPI.BomAsProduced bomAsProducedAPI = RESTAPI.BomAsProduced.getInstance(); RESTAPI.ProcessPhysicalProductOutput processPhysicalProductOutputAPI = RESTAPI.ProcessPhysicalProductOutput.getInstance(); RESTAPI.ProdottoFisico physicalProductAPI = RESTAPI.ProdottoFisico.getInstance(); RESTAPI.PhysicalProductUniqueness physicalProductUniquenessApi = RESTAPI.PhysicalProductUniqueness.getInstance(); RESTAPI.Tag tagAPI = RESTAPI.Tag.getInstance(); RESTAPI.PhysicalProductTag physicalProductTagAPI = RESTAPI.PhysicalProductTag.getInstance(); RESTAPI.TipoProdotto productTypeAPI = RESTAPI.TipoProdotto.getInstance(); RESTAPI.NewPhysicalProductReason newPhysicalProductReasonApi = RESTAPI.NewPhysicalProductReason.getInstance(); RESTAPI.SchedaProduzione productionSheetAPI = RESTAPI.SchedaProduzione.getInstance(); RESTAPI.ProductFamily productFamilyAPI = RESTAPI.ProductFamily.getInstance(); RESTAPI.PackagingType packagingTypeAPI = RESTAPI.PackagingType.getInstance(); RESTAPI.WPlaceProdottoFisico wplacePhysicalProductApi = RESTAPI.WPlaceProdottoFisico.getInstance(); RESTAPI.TipoFineProdotto productEndTypeAPI = RESTAPI.TipoFineProdotto.getInstance(); RESTAPI.Batch batchAPI = RESTAPI.Batch.getInstance(); Process process; BillOfProcess billOfProcess; IHolonixCommonForm view; public CompleteProcess(Process process, IHolonixCommonForm view) { this.process = process; this.view = view; } public class CompleteResult { public TipoProdotto productType { get; set; } public List<Tag> tags { get; set; } public BillOfProcessOutputSummary bopSummaryOutput { get; set; } public CompleteResult(BillOfProcessOutputSummary bopSummaryOutput, TipoProdotto productType, List<Tag> tags) { this.bopSummaryOutput = bopSummaryOutput; this.productType = productType; this.tags = tags; } }
Page 12
286885 BOMA
12
private void getBillOfProcess() { billOfProcess = billOfProcessAPI.getByProcess(process.id.Value); } public void completeAssembly() { getBillOfProcess(); List<BillOfProcessInputSummary> bopSummaryInput = billOfProcessInputAPI.getBillOfProcessInputSummaries(process.id.Value, billOfProcess.id.Value); Int64? productId = null; for (int i = 0; i < bopSummaryInput.Count; i++) { if (bopSummaryInput[i].billOfProcessInput != null) if (bopSummaryInput[i].billOfProcessInput.master.Value) { productId = bopSummaryInput[i].processPhysicalProductInput[0].physicalProduct; break; } } ProcessPhysicalProductOutput output = new ProcessPhysicalProductOutput(); output.process = process.id.Value; output.billOfProcess = billOfProcess.id.Value; output.physicalProduct = productId.Value; output.date = DateTime.Now; output.master = true; output.quantity = null; output.numberOfItems = 1; processPhysicalProductOutputAPI.save(output); for (int i = 0; i < bopSummaryInput.Count; i++) { if (bopSummaryInput[i].processPhysicalProductInput == null) continue; if (bopSummaryInput[i].processPhysicalProductInput.Count < 1) continue; for (int j = 0; j < bopSummaryInput[i].processPhysicalProductInput.Count; j++) { if (bopSummaryInput[i].processPhysicalProductInput[j].master.Value) continue; BomAsProduced bomAsProduced = new BomAsProduced(); bomAsProduced.physicalProduct = productId; bomAsProduced.component = bopSummaryInput[i].processPhysicalProductInput[j].physicalProduct.Value; bomAsProduced.startDate = DateTime.Now; bomAsProduced.endDate = null; bomAsProduced.endNote = null; bomAsProduced.quantity = bopSummaryInput[i].processPhysicalProductInput[j].quantity; bomAsProduced.numberOfItems = bopSummaryInput[i].processPhysicalProductInput[j].numberOfItems; bomAsProduced.process = process.id; bomAsProduced.familyCode = null; bomAsProduced.batchCode = null; bomAsProduced.packagingCode = null; bomAsProducedAPI.save(bomAsProduced); } } } public List<CompleteResult> setResult() { List<BillOfProcessOutputSummary> bopSummaryOutputs = billOfProcessOutputAPI.getBillOfProcessOutputSummaries(process.id.Value, billOfProcess.id.Value); List<CompleteResult> completeResults = new List<CompleteResult>(); foreach (BillOfProcessOutputSummary bopSummaryOutput in bopSummaryOutputs) { holonix.production.mergingAndAssembly.FrmProcessMergingTagOutput dialogForm = new holonix.production.mergingAndAssembly.FrmProcessMergingTagOutput(process, bopSummaryOutput); if (dialogForm.ShowDialog() == DialogResult.OK) { TipoProdotto productType = dialogForm.getProductType(); List<Tag> tags = dialogForm.getTags(); dialogForm.Dispose(); completeResults.Add(new CompleteResult(bopSummaryOutput, productType, tags)); } else {
Page 13
286885 BOMA
13
return null; } } return completeResults; } public void completeMergingWithTag() { getBillOfProcess(); List<BillOfProcessInputSummary> bopSummaryInputs = billOfProcessInputAPI.getBillOfProcessInputSummaries(process.id.Value, billOfProcess.id.Value); List<CompleteResult> completeResults = setResult(); if (completeResults == null) { view.alert("Define all tags.", "000"); return; } foreach (CompleteResult completeResult in completeResults) { ProdottoFisico product = new ProdottoFisico(); product.tipoProdotto = completeResult.productType.id; product.attivo = true; product.dataScadenza = null; product.isWip = completeResult.bopSummaryOutput.billOfProcessOutput.wip; product.schedaProduzione = process.productionSheet; product.quantitaEffettiva = 1; product.dataStart = DateTime.Now; product.dataEnd = null; product.nome = completeResult.productType.codice; product.tara = 0; product.quantitaIniziale = 1; product.cardinalita = 1; product.isPack = false; product.unitLoad = 1; product.unitLoadSize = 0; product.canTakeToInside = true; product.canTakeToOutside = true; product.idUniqueness = 1; product.causaleNuovoProdotto = 1; product.isStocked = false; product.isPurchased = false; product.isSold = false; product.idEndType = null; product.canGroup = false; product.divisibile = false; product.isHandleQuantity = true; product.isHandleNumberOfItems = true; product = physicalProductAPI.save(ref product); ProcessPhysicalProductOutput output = new ProcessPhysicalProductOutput(); output.process = process.id.Value; output.billOfProcess = billOfProcess.id.Value; output.physicalProduct = product.id.Value; output.date = DateTime.Now; output.master = true; output.quantity = null; output.numberOfItems = 1; processPhysicalProductOutputAPI.save(output); for (int i = 0; i < bopSummaryInputs.Count; i++) { if (bopSummaryInputs[i].processPhysicalProductInput == null) continue; if (bopSummaryInputs[i].processPhysicalProductInput.Count < 1) continue; for (int j = 0; j < bopSummaryInputs[i].processPhysicalProductInput.Count; j++) { BomAsProduced bomAsProduced = new BomAsProduced(); bomAsProduced.physicalProduct = product.id; bomAsProduced.component = bopSummaryInputs[i].processPhysicalProductInput[j].physicalProduct.Value; bomAsProduced.startDate = DateTime.Now; bomAsProduced.endDate = null; bomAsProduced.endNote = null;
Page 14
286885 BOMA
14
bomAsProduced.quantity = bopSummaryInputs[i].processPhysicalProductInput[j].quantity; bomAsProduced.numberOfItems = bopSummaryInputs[i].processPhysicalProductInput[j].numberOfItems; bomAsProduced.process = process.id; bomAsProduced.familyCode = null; bomAsProduced.batchCode = null; bomAsProduced.packagingCode = null; bomAsProducedAPI.save(bomAsProduced); } } for (int i = 0; i < completeResult.tags.Count; i++) { Tag tag = completeResult.tags[i]; tagAPI.save(ref tag); PhysicalProductTag productTag = new PhysicalProductTag(); productTag.physicalProduct = product.id.Value; productTag.tag = tag.id.Value; productTag.fromDate = DateTime.Now; physicalProductTagAPI.save(ref productTag); } } } public void completeMergingWithWip() { getBillOfProcess(); List<BillOfProcessInputSummary> bopSummaryInputs = billOfProcessInputAPI.getBillOfProcessInputSummaries(process.id.Value, billOfProcess.id.Value); SchedaProduzione sheet = productionSheetAPI.get(process.productionSheet); Batch batch = null; if (bopSummaryInputs[0] != null && bopSummaryInputs[0].processPhysicalProductInput != null) if (bopSummaryInputs[0].processPhysicalProductInput.Count > 0 && bopSummaryInputs[0].processPhysicalProductInput[0] != null) { TipoProdotto typeBatch = productTypeAPI.getByPhysicalProduct(bopSummaryInputs[0].processPhysicalProductInput[0].physicalProduct); if (typeBatch != null) batch = batchAPI.getByCodeAndProductType(sheet.lotto, typeBatch.id); } TipoProdotto type = productTypeAPI.getByCode("WIP"); ProdottoFisico product = new ProdottoFisico(); product.tipoProdotto = type.id; if (batch != null) product.batch = batch.id; product.attivo = true; product.dataScadenza = null; product.isWip = true; product.schedaProduzione = sheet.id; product.quantitaEffettiva = 0; product.dataStart = DateTime.Now; product.dataEnd = null; product.nome = type.codice; product.tara = 0; product.quantitaIniziale = 0; product.cardinalita = 1; product.isPack = false; product.unitLoad = 1; product.unitLoadSize = UnitLoad.def; product.canTakeToInside = true; product.canTakeToOutside = true; product.idUniqueness = PhysicalProductUniqueness.ID_UNIQUE; product.causaleNuovoProdotto = newPhysicalProductReasonApi.get("1").id; product.isStocked = false; product.isPurchased = false; product.isSold = false; product.idEndType = null; product.canGroup = false; product.divisibile = false; product.isHandleQuantity = true; product.isHandleNumberOfItems = true; product = physicalProductAPI.save(ref product); ProcessPhysicalProductOutput output = new ProcessPhysicalProductOutput(); output.process = process.id.Value; output.billOfProcess = billOfProcess.id.Value;
Page 15
286885 BOMA
15
output.physicalProduct = product.id.Value; output.date = DateTime.Now; output.master = true; output.quantity = 0; output.numberOfItems = 1; processPhysicalProductOutputAPI.save(output); for (int i = 0; i < bopSummaryInputs.Count; i++) { if (bopSummaryInputs[i].processPhysicalProductInput == null) continue; if (bopSummaryInputs[i].processPhysicalProductInput.Count < 1) continue; for (int j = 0; j < bopSummaryInputs[i].processPhysicalProductInput.Count; j++) { BomAsProduced bomAsProduced = new BomAsProduced(); bomAsProduced.physicalProduct = product.id; bomAsProduced.component = bopSummaryInputs[i].processPhysicalProductInput[j].physicalProduct.Value; bomAsProduced.startDate = DateTime.Now; bomAsProduced.endDate = null; bomAsProduced.endNote = null; bomAsProduced.quantity = bopSummaryInputs[i].processPhysicalProductInput[j].quantity; bomAsProduced.numberOfItems = bopSummaryInputs[i].processPhysicalProductInput[j].numberOfItems; bomAsProduced.process = process.id; bomAsProduced.familyCode = productFamilyAPI.getByPhysicalProduct(bopSummaryInputs[i].processPhysicalProductInput[j].physicalProduct).code; bomAsProduced.batchCode = sheet.lotto; bomAsProduced.packagingCode = "KG"; PackagingType package = packagingTypeAPI.getByPhysicalProduct(bopSummaryInputs[i].processPhysicalProductInput[j].physicalProduct); if (!package.code.Equals("KG")) if (package.quantity.Equals(bopSummaryInputs[i].processPhysicalProductInput[j].quantity)) bomAsProduced.packagingCode = package.code; bomAsProducedAPI.save(bomAsProduced); } } } public void completeDivide() { getBillOfProcess(); List<BillOfProcessInputSummary> bopSummaryInputs = billOfProcessInputAPI.getBillOfProcessInputSummaries(process.id.Value, billOfProcess.id.Value); for (int i = 0; i < bopSummaryInputs.Count; i++) { List<ProcessPhysicalProductInput> processPhysicalProductInputs = bopSummaryInputs[i].processPhysicalProductInput; for (int j = 0; j < processPhysicalProductInputs.Count; j++) { ProdottoFisico physicalProduct = physicalProductAPI.get(processPhysicalProductInputs[j].physicalProduct); if (physicalProduct.idUniqueness == physicalProductUniquenessApi.Unique.id) { physicalProduct.attivo = false; physicalProduct.dataEnd = DateTime.Now; physicalProduct.idEndType = productEndTypeAPI.get("1").id; physicalProductAPI.save(ref physicalProduct); WPlaceProdottoFisico wppp = wplacePhysicalProductApi.getProductLocation(physicalProduct.id); if (wppp != null) { wppp.to = DateTime.Now; wplacePhysicalProductApi.save(ref wppp); } } } } } } } using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text;
Page 16
286885 BOMA
16
using System.Windows.Forms; using holonix.winform; using holonix.applicationlogic; namespace holonix.production { public partial class FrmActionProduction : HolonixCommonForm, IHolonixCommonForm { ApplicationLogic logic = new ApplicationLogic(); public FrmActionProduction() { InitializeComponent(); } private void FrmActionProduction_Load(object sender, EventArgs e) { start(); translation(); } private void translation() { logic.translate(this, VariabiliGlobali.idLanguage); logic.translate(miBack, VariabiliGlobali.idLanguage); } public void refresh() { } public void start() { } private void btnProduction_Click(object sender, EventArgs e) { new production.FrmProductionSheet().Show(); } private void btnNewProduct_Click(object sender, EventArgs e) { new production.FrmNewProduct().Show(); } public void end() { } private void miBack_Click(object sender, EventArgs e) { abort(); } } } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Collections; using holonix.applicationlogic; using holonix.winform; namespace holonix.boma { public partial class FrmMainMenu : HolonixCommonForm { ApplicationLogic logic = new ApplicationLogic(); public FrmMainMenu() { InitializeComponent(); } private void FrmAzione_Load(object sender, EventArgs e) { if (!Sessions.Current.IsAllowed("VIEW_PHYSICAL_PRODUCT")) this.button1.Enabled = false; logic.translate(this, VariabiliGlobali.idLanguage); logic.translate(mainMenu1, VariabiliGlobali.idLanguage); } private void menuItem1_Click(object sender, EventArgs e)
Page 17
286885 BOMA
17
{ if (!askQuestion("Sei sicuro di voler uscire?", "ok")) return; Sessions.Current.Close(); HolonixMySQL mydb = HolonixMySQL.getConnector(); mydb.disconnetti(); Application.Exit(); } private void btnProduzione_Click(object sender, EventArgs e) { new production.FrmActionProduction().Show(); } private void btnIdentificaProdotto_Click(object sender, EventArgs e) { new holonix.identificazione.FrmIdentificaItemProdotto().Show(); } } } using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using holonix.winform; using holonix.applicationlogic; using holonix.datamodel; using holonix.utility; using holonix.datamodel.auxiliary; using holonix.restapi; using holonix.rfid; namespace holonix.production { public partial class FrmNewProduct : HolonixCommonForm, IHolonixCommonForm { private ApplicationLogic logic = new ApplicationLogic(); private Utility utility = new Utility(); private CaenRfidControl rfidControl; private TipoProdotto productType; private Batch batchTag; private List<Tag> tags = new List<Tag>(); private RESTAPI.ProdottoFisico physicalProductAPI = RESTAPI.ProdottoFisico.getInstance(); private RESTAPI.Tag tagAPI = RESTAPI.Tag.getInstance(); private RESTAPI.PhysicalProductTag physicalProductTagAPI = RESTAPI.PhysicalProductTag.getInstance(); private RESTAPI.TipoProdotto productTypeAPI = RESTAPI.TipoProdotto.getInstance(); private RESTAPI.NewPhysicalProductReason newPhysicalProductReasonAPI = RESTAPI.NewPhysicalProductReason.getInstance(); private RESTAPI.Uom uomAPI = RESTAPI.Uom.getInstance(); private RESTAPI.PhysicalProductUniqueness physicalProductUniquenessAPI = RESTAPI.PhysicalProductUniqueness.getInstance(); private RESTAPI.WPlaceProdottoFisico wPlacePhysicalProductAPI = RESTAPI.WPlaceProdottoFisico.getInstance(); RESTAPI.Batch batchAPI = RESTAPI.Batch.getInstance(); public FrmNewProduct() { InitializeComponent(); List<Component> disabledControls = new List<Component>(); disabledControls.Add(btnRfid); rfidControl = new CaenRfidControl(this, disabledControls); } private void FrmNewProduct_Load(object sender, EventArgs e) { List<NewPhysicalProductReason> newPhysicalProductReasons = newPhysicalProductReasonAPI.get(); cbCausali.DisplayMember = "label"; cbCausali.ValueMember = "id"; cbCausali.DataSource = newPhysicalProductReasons; tbUom.Text = "-"; logic.translate(this, VariabiliGlobali.idLanguage); logic.translate(miBack, VariabiliGlobali.idLanguage); } private Boolean checkTag(String code) { return true;
Page 18
286885 BOMA
18
} private void btnAdd_Click(object sender, EventArgs e) { if (tbTag.Text.Length < 1) return; if (!checkTag(tbTag.Text)) return; Tag tag = new Tag(); tag.attivo = true; tag.codice = tbTag.Text; tag.isProdotto = true; tag.isProductType = false; tag.isResource = false; tag.isReusable = false; tag.isUnique = true; tag.isWarehouse = false; tag.tipoTag = 1; tags.Add(tag); refresh(); tbTag.Text = ""; } public override void refresh() { this.SuspendLayout(); lvTag.Items.Clear(); for (int i = 0; i < tags.Count; i++) { Tag tag = tags[i]; ListViewItem li = new ListViewItem(tag.codice); lvTag.Items.Add(li); } this.ResumeLayout(); } private void btnRfid_Click(object sender, EventArgs e) { rfidControl.Read(btnRfid, doAfterOriginRFIDRead); } private void doAfterOriginRFIDRead(List<String> strList) { tbTag.Text = ""; if (strList.Count == 0) { alert("Errore di lettura", "j4"); } else { for (int i = 0; i < strList.Count; i++) { if (!checkTag(strList[i])) return; } for (int i = 0; i < strList.Count; i++) { Tag tag = new Tag(); tag.attivo = true; tag.codice = strList[i]; tag.isProdotto = true; tag.isProductType = false; tag.isResource = false; tag.isReusable = false; tag.isUnique = false; tag.isWarehouse = false; tag.tipoTag = 1; tags.Add(tag); } refresh(); } } private void btnClearList_Click(object sender, EventArgs e) { tags.Clear();
Page 19
286885 BOMA
19
refresh(); tbTag.Focus(); } private void btnConfirm_Click(object sender, EventArgs e) { this.showBusy(true); DateTime now = DateTime.Now; Int32? numberOfItems = null; if (tbNumItem.Text.Length > 0) { try { numberOfItems = Int16.Parse(tbNumItem.Text); } catch { this.showBusy(false); return; } } Decimal? quantity = null; if (tbQuantity.Text.Length > 0) { try { quantity = Decimal.Parse(tbQuantity.Text); } catch { this.showBusy(false); return; } } if (productType == null) productType = productTypeAPI.getByCode(tbTipo.Text); if (productType == null) { this.showBusy(false); return; } if (tags.Count < 1) { this.showBusy(false); return; } if (Prefetch.WPlace.productionWPlace == null) { this.showBusy(false); return; } if (tbBatch.Text.Length > 0) { batchTag = batchAPI.getByCodeAndProductType(tbBatch.Text.Trim(), productType.id); if (batchTag == null) { batchTag.code = tbBatch.Text.Trim(); batchTag.productType = productType.id; batchAPI.save(ref batchTag); } } ProdottoFisico physicalProduct = new ProdottoFisico(); physicalProduct.attivo = true; physicalProduct.canTakeToInside = true; physicalProduct.canTakeToOutside = true; if (numberOfItems != null) { physicalProduct.cardinalita = numberOfItems; physicalProduct.isHandleNumberOfItems = true; } else {
Page 20
286885 BOMA
20
physicalProduct.isHandleNumberOfItems = false; } if (quantity != null) { physicalProduct.quantitaEffettiva = quantity; physicalProduct.quantitaIniziale = quantity; physicalProduct.isHandleQuantity = true; } else { physicalProduct.isHandleQuantity = false; } physicalProduct.causaleNuovoProdotto = ((NewPhysicalProductReason) cbCausali.SelectedItem).id; physicalProduct.dataStart = now; physicalProduct.idUniqueness = physicalProductUniquenessAPI.Unique.id.Value; physicalProduct.isPack = false; physicalProduct.isWip = false; physicalProduct.nome = productType.nome; physicalProduct.tipoProdotto = productType.id; physicalProduct.batch = batchTag.id; physicalProductAPI.save(ref physicalProduct); for (int i = 0; i < tags.Count; i++) { Tag tag = tags[i]; tagAPI.save(ref tag); PhysicalProductTag productTag = new PhysicalProductTag(); productTag.physicalProduct = physicalProduct.id.Value; productTag.tag = tag.id.Value; productTag.fromDate = now; physicalProductTagAPI.save(ref productTag); } WPlaceProdottoFisico wppp = new WPlaceProdottoFisico(); wppp.from = now; wppp.idPhysicalProduct = physicalProduct.id; wppp.idWPlace = Prefetch.WPlace.productionWPlace.id; wppp.numberOfItems = numberOfItems; wppp.quantity = quantity; wPlacePhysicalProductAPI.save(ref wppp); this.showBusy(false); this.Close(); } private void miBack_Click(object sender, EventArgs e) { this.Close(); } private void tbTipo_LostFocus(object sender, EventArgs e) { if (tbTipo.Text.Length < 1) return; productType = productTypeAPI.getByCode(tbTipo.Text); if (productType != null) { Uom uom = uomAPI.get(productType.idUom); if (uom != null) tbUom.Text = uom.label; } } } } using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using holonix.winform; using holonix.applicationlogic; using holonix.datamodel; using holonix.restapi; using holonix.datamodel.auxiliary;
Page 21
286885 BOMA
21
using holonix.rfid; namespace holonix.production.action { public partial class FrmProcessAction : HolonixCommonForm, IHolonixCommonForm { ApplicationLogic logic = new ApplicationLogic(); CaenRfidControl rfidControl; private RESTAPI.ProdottoFisico physicalProductAPI = RESTAPI.ProdottoFisico.getInstance(); private RESTAPI.BillOfProcess billOfProcessAPI = RESTAPI.BillOfProcess.getInstance(); private RESTAPI.BillOfProcessInput billOfProcessInputAPI = RESTAPI.BillOfProcessInput.getInstance(); private RESTAPI.BillOfProcessOutput billOfProcessOutputAPI = RESTAPI.BillOfProcessOutput.getInstance(); private RESTAPI.ProcessPhysicalProductInput processPhysicalProductInputAPI = RESTAPI.ProcessPhysicalProductInput.getInstance(); private RESTAPI.ProcessPhysicalProductOutput processPhysicalProductOutputAPI = RESTAPI.ProcessPhysicalProductOutput.getInstance(); private RESTAPI.Process processAPI = RESTAPI.Process.getInstance(); private Process process; private BillOfProcess billOfProcess; private ProdottoFisico physicalProduct; private List<BillOfProcessInputSummary> bopSummaryInput; private List<BillOfProcessOutputSummary> bopSummaryOutput; public FrmProcessAction(Process p, String processTypeLabel) { process = p; InitializeComponent(); lblProductCode.Text = ""; lblProdCodeOut.Text = ""; lblProdCodeDef.Text = ""; List<Component> disabledControls = new List<Component>(); disabledControls.Add(btnRfid); rfidControl = new CaenRfidControl(this, disabledControls); } public void FrmProcessAction_Load(object sender, EventArgs e) { start(); translation(); } private void translation() { logic.translate(this, VariabiliGlobali.idLanguage); logic.translate(miBack, VariabiliGlobali.idLanguage); } private void getSummaries() { billOfProcess = billOfProcessAPI.getByProcess(process.id.Value); bopSummaryInput = billOfProcessInputAPI.getBillOfProcessInputSummaries(process.id.Value, billOfProcess.id.Value); bopSummaryOutput = billOfProcessOutputAPI.getBillOfProcessOutputSummaries(process.id.Value, billOfProcess.id.Value); } public void start() { getSummaries(); lblProductCode.Text = bopSummaryInput[0].billOfProcessInput.code; pnlOutput.Visible = false; if (bopSummaryInput[0].processPhysicalProductInput.Count > 0) { tbProduct.Text = bopSummaryInput[0].processPhysicalProductInput[0].code; btnRfid.Enabled = false; tbProduct.Enabled = false; tbBatch.Enabled = false; btnCheckProduct.Enabled = false; pnlOutput.Visible = true; lblProdCodeOut.Text = bopSummaryOutput[0].billOfProcessOutput.code; if (bopSummaryOutput[0].processPhysicalProductOutput.Count > 0) { lblProdCodeDef.Text = bopSummaryInput[0].processPhysicalProductInput[0].code; ProdottoFisico p = physicalProductAPI.get(bopSummaryInput[0].processPhysicalProductInput[0].physicalProduct.Value); if (p.isWip.Value) ckTried.Checked = false; else ckTried.Checked = true; ckTried.Enabled = false; btnConfirm.Enabled = false; } }
Page 22
286885 BOMA
22
} public void refresh() { } private void doAfterOriginRFIDRead(List<String> strList) { if (strList.Count == 0) { alert("Errore di lettura", "j4"); } else if (strList.Count > 1) { alert("Troppi tag nell'area", "j7"); } else { tbProduct.Text = strList[0]; } } private void btnRfid_Click(object sender, EventArgs e) { physicalProduct = null; tbProduct.Text = ""; tbBatch.Text = ""; rfidControl.Read(btnRfid, doAfterOriginRFIDRead); } private void btnCheckProduct_Click(object sender, EventArgs e) { if (tbProduct.Text.Length < 1) return; String tag = ""; if (tbProduct.Text.Length > 0) tag = tbProduct.Text; if (tbBatch.Text.Length > 0) tag = tag + "##" + tbBatch.Text; List<ProdottoFisico> list = physicalProductAPI.getByTag(tag); if (list.Count > 0) physicalProduct = list[0]; if (physicalProduct == null) { tbProduct.Text = ""; tbBatch.Text = ""; return; } if (process.startDate == null) { process.startDate = DateTime.Now; processAPI.save(ref process); } ProcessPhysicalProductInput pppi = new ProcessPhysicalProductInput(); pppi.billOfProcess = billOfProcess.id; pppi.process = process.id; pppi.physicalProduct = physicalProduct.id; pppi.master = true; pppi.quantity = null; pppi.numberOfItems = 1; pppi.date = DateTime.Now; processPhysicalProductInputAPI.save(ref pppi); btnRfid.Enabled = false; tbProduct.Enabled = false; tbBatch.Enabled = false; btnCheckProduct.Enabled = false; pnlOutput.Visible = true; lblProdCodeOut.Text = bopSummaryOutput[0].billOfProcessOutput.code; lblProdCodeDef.Text = physicalProduct.nome; } private void btnConfirm_Click(object sender, EventArgs e) { physicalProduct.isWip = true; if (ckTried.Checked) {
Page 23
286885 BOMA
23
physicalProduct.isWip = false; physicalProduct = physicalProductAPI.save(ref physicalProduct); ProcessPhysicalProductOutput output = new ProcessPhysicalProductOutput(); output.process = process.id.Value; output.billOfProcess = billOfProcess.id.Value; output.physicalProduct = physicalProduct.id.Value; output.date = DateTime.Now; output.master = true; output.quantity = null; output.numberOfItems = 1; processPhysicalProductOutputAPI.save(output); } abort(); } public void end() { } private void miBack_Click(object sender, EventArgs e) { abort(); } } } using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using holonix.winform; using holonix.applicationlogic; using holonix.datamodel; using holonix.restapi; using holonix.datamodel.auxiliary; namespace holonix.production.divide { public partial class FrmProcessDivide : HolonixCommonForm, IHolonixCommonForm { ApplicationLogic logic = new ApplicationLogic(); private RESTAPI.BillOfProcess billOfProcessAPI = RESTAPI.BillOfProcess.getInstance(); private RESTAPI.BillOfProcessOutput billOfProcessOutputAPI = RESTAPI.BillOfProcessOutput.getInstance(); private RESTAPI.BillOfProcessInput billOfProcessInputAPI = RESTAPI.BillOfProcessInput.getInstance(); private RESTAPI.ProdottoFisico physicalProductAPI = RESTAPI.ProdottoFisico.getInstance(); private RESTAPI.ProcessPhysicalProductOutput processPhysicalProductOutputAPI = RESTAPI.ProcessPhysicalProductOutput.getInstance(); private RESTAPI.ProcessPhysicalProductInput processPhysicalProductInputAPI = RESTAPI.ProcessPhysicalProductInput.getInstance(); private Process process; private ProdottoFisico physicalProduct; private String descBop; private String descItem; private BillOfProcess billOfProcess; private List<BillOfProcessOutputSummary> bopSummary; public FrmProcessDivide(Process p, String processTypeLabel) { process = p; InitializeComponent(); } private void FrmProcessDivide_Load(object sender, EventArgs e) { start(); translation(); } private void translation() { logic.translate(this, VariabiliGlobali.idLanguage); logic.translate(miOk, VariabiliGlobali.idLanguage); logic.translate(lvBop, VariabiliGlobali.idLanguage); logic.translate(lvItem, VariabiliGlobali.idLanguage); } private void setPanels() {
Page 24
286885 BOMA
24
descBop = logic.translate("Bill of material", "vd", VariabiliGlobali.idLanguage); descItem = logic.translate("Effective products", "ve", VariabiliGlobali.idLanguage); pnlBop.Width = 465; pnlBop.Height = 300; pnlBop.Location = new Point(7, 180); pnlItem.Width = 465; pnlItem.Height = 300; pnlItem.Location = new Point(7, 180); showListBop(); } private void showListBop() { lbViewSelected.Text = descBop; pnlBop.Visible = true; pnlItem.Visible = false; btnShowBop.Enabled = false; btnShowItem.Enabled = true; } public void showListItem() { lbViewSelected.Text = descItem; pnlBop.Visible = false; pnlItem.Visible = true; btnShowBop.Enabled = true; btnShowItem.Enabled = false; } private void getBillOfProcess() { billOfProcess = billOfProcessAPI.getByProcess(process.id.Value); if (billOfProcess == null) { alert("There isn't billOfProcess.", "000"); abort(); } } private void getPhysicalProductToDivide() { showBusy(true); List<BillOfProcessInputSummary> bopInputs = billOfProcessInputAPI.getBillOfProcessInputSummaries(process.id.Value, billOfProcess.id.Value); Int64? idPhysProd = null; for (int i = bopInputs.Count - 1; i > -1; i--) { if (bopInputs[i].billOfProcessInput != null) { if (bopInputs[i].billOfProcessInput.billOfProcessOutput != null) { List<ProcessPhysicalProductOutput> list = processPhysicalProductOutputAPI.getByBillOfProcessOutput(process.productionSheet.Value, bopInputs[i].billOfProcessInput.billOfProcessOutput.Value); idPhysProd = list[0].physicalProduct.Value; break; } } } if (idPhysProd == null) { showBusy(false); alert("There isn't product to divide.", "000"); abort(); } ProdottoFisico pf = physicalProductAPI.get(idPhysProd.Value); lblProductCode.Text = pf.nome; physicalProduct = pf; if (bopInputs[0].processPhysicalProductInput == null || bopInputs[0].processPhysicalProductInput.Count == 1) { ProcessPhysicalProductInput pppi = new ProcessPhysicalProductInput(); pppi.billOfProcess = billOfProcess.id; pppi.process = process.id; pppi.physicalProduct = physicalProduct.id; pppi.master = false; pppi.quantity = null;
Page 25
286885 BOMA
25
pppi.numberOfItems = 1; pppi.date = DateTime.Now; processPhysicalProductInputAPI.save(ref pppi); } showBusy(false); } public void start() { setPanels(); if (process.endDate != null) btnAddItem.Enabled = false; getBillOfProcess(); getPhysicalProductToDivide(); refresh(); } public void refresh() { this.SuspendLayout(); showBusy(true); bopSummary = billOfProcessOutputAPI.getBillOfProcessOutputSummaries(process.id.Value, billOfProcess.id.Value); fillListBop(bopSummary); fillListItem(bopSummary); showBusy(false); this.ResumeLayout(); } private void fillListBop(List<BillOfProcessOutputSummary> bopSummary) { lvBop.Items.Clear(); for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].billOfProcessOutput == null) continue; ListViewItem li = new ListViewItem(bopSummary[i].billOfProcessOutput.code); if (bopSummary[i].billOfProcessOutput.quantity != null) { li.SubItems.Add(bopSummary[i].billOfProcessOutput.quantity.Value.ToString()); if (bopSummary[i].billOfProcessOutput.uom != null) li.SubItems.Add(bopSummary[i].billOfProcessOutput.uom); else li.SubItems.Add(""); if (bopSummary[i].processPhysicalProductOutput == null) li.SubItems.Add(""); else { Decimal? qtEff = null; for (int j = 0; j < bopSummary[i].processPhysicalProductOutput.Count; j++) { if (bopSummary[i].processPhysicalProductOutput[j].quantity != null) if (qtEff == null) qtEff = bopSummary[i].processPhysicalProductOutput[j].quantity.Value; else qtEff = qtEff + bopSummary[i].processPhysicalProductOutput[j].quantity.Value; } if (qtEff == null) li.SubItems.Add(""); else if (bopSummary[i].billOfProcessOutput.quantity < qtEff) li.SubItems.Add("+"); else if (bopSummary[i].billOfProcessOutput.quantity > qtEff) li.SubItems.Add("-"); else if (bopSummary[i].billOfProcessOutput.quantity == qtEff) li.SubItems.Add("ok"); else li.SubItems.Add(""); } } else if (bopSummary[i].billOfProcessOutput.numberOfItems != null) { li.SubItems.Add(bopSummary[i].billOfProcessOutput.numberOfItems.Value.ToString()); li.SubItems.Add(bopSummary[i].billOfProcessOutput.uom);
Page 26
286885 BOMA
26
if (bopSummary[i].processPhysicalProductOutput == null) li.SubItems.Add(""); else { Int32? numEff = null; for (int j = 0; j < bopSummary[i].processPhysicalProductOutput.Count; j++) { if (bopSummary[i].processPhysicalProductOutput[j].numberOfItems != null) if (numEff == null) numEff = bopSummary[i].processPhysicalProductOutput[j].numberOfItems.Value; else numEff = numEff + bopSummary[i].processPhysicalProductOutput[j].numberOfItems.Value; } if (numEff == null) li.SubItems.Add(""); else if (bopSummary[i].billOfProcessOutput.numberOfItems < numEff) li.SubItems.Add("+"); else if (bopSummary[i].billOfProcessOutput.numberOfItems > numEff) li.SubItems.Add("-"); else if (bopSummary[i].billOfProcessOutput.numberOfItems == numEff) li.SubItems.Add("ok"); else li.SubItems.Add(""); } } else { li.SubItems.Add(""); li.SubItems.Add(""); li.SubItems.Add(""); } if (bopSummary[i].billOfProcessOutput.tag != null) li.SubItems.Add(bopSummary[i].billOfProcessOutput.tag); else li.SubItems.Add(""); li.SubItems.Add(bopSummary[i].billOfProcessOutput.id.Value.ToString()); lvBop.Items.Add(li); } } private void fillListItem(List<BillOfProcessOutputSummary> bopSummary) { lvItem.Items.Clear(); for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].processPhysicalProductOutput == null) continue; if (bopSummary[i].processPhysicalProductOutput.Count < 1) continue; ListViewItem li = new ListViewItem(bopSummary[i].processPhysicalProductOutput[0].code); Decimal? qtEff = null; Int32? numEff = null; for (int j = 0; j < bopSummary[i].processPhysicalProductOutput.Count; j++) { if (bopSummary[i].processPhysicalProductOutput[j].quantity != null) if (qtEff == null) qtEff = bopSummary[i].processPhysicalProductOutput[j].quantity.Value; else qtEff = qtEff + bopSummary[i].processPhysicalProductOutput[j].quantity.Value; if (bopSummary[i].processPhysicalProductOutput[j].numberOfItems != null) if (numEff == null) numEff = bopSummary[i].processPhysicalProductOutput[j].numberOfItems.Value; else numEff = numEff + bopSummary[i].processPhysicalProductOutput[j].numberOfItems.Value; } if (qtEff != null) { li.SubItems.Add(qtEff.Value.ToString()); if (bopSummary[i].processPhysicalProductOutput[0].uom != null) li.SubItems.Add(bopSummary[i].processPhysicalProductOutput[0].uom); else li.SubItems.Add("");
Page 27
286885 BOMA
27
if (bopSummary[i].billOfProcessOutput != null && bopSummary[i].billOfProcessOutput.quantity != null) { if (qtEff < bopSummary[i].billOfProcessOutput.quantity) li.SubItems.Add("-"); else if (qtEff > bopSummary[i].billOfProcessOutput.quantity) li.SubItems.Add("+"); else if (qtEff == bopSummary[i].billOfProcessOutput.quantity) li.SubItems.Add("ok"); else li.SubItems.Add(""); } else li.SubItems.Add(""); } else if (numEff != null) { li.SubItems.Add(numEff.Value.ToString()); if (bopSummary[i].processPhysicalProductOutput[0].uom != null) li.SubItems.Add(bopSummary[i].processPhysicalProductOutput[0].uom); else li.SubItems.Add(""); if (bopSummary[i].billOfProcessOutput != null && bopSummary[i].billOfProcessOutput.numberOfItems != null) { if (numEff < bopSummary[i].billOfProcessOutput.numberOfItems) li.SubItems.Add("-"); else if (numEff > bopSummary[i].billOfProcessOutput.numberOfItems) li.SubItems.Add("+"); else if (numEff == bopSummary[i].billOfProcessOutput.numberOfItems) li.SubItems.Add("ok"); else li.SubItems.Add(""); } else li.SubItems.Add(""); } else { li.SubItems.Add(""); li.SubItems.Add(""); li.SubItems.Add(""); } if (bopSummary[i].processPhysicalProductOutput[0].tag != null) li.SubItems.Add(bopSummary[i].processPhysicalProductOutput[0].tag); else li.SubItems.Add(""); lvItem.Items.Add(li); } } private void btnAddItem_Click(object sender, EventArgs e) { ListView.SelectedIndexCollection selectedIndeces = lvBop.SelectedIndices; ListViewItem selectedItem = null; if (selectedIndeces.Count == 1) selectedItem = lvBop.Items[selectedIndeces[0]]; else return; Int64 idBill = Int64.Parse(selectedItem.SubItems[5].Text); BillOfProcessOutput billOfProcessOutput = null; for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].billOfProcessOutput.id.Value.Equals(idBill)) billOfProcessOutput = bopSummary[i].billOfProcessOutput; } if (billOfProcessOutput != null) new production.divide.FrmProcessDivideItem(process, billOfProcess, billOfProcessOutput, physicalProduct, this).Show(); } private void btnShowItem_Click(object sender, EventArgs e) { showListItem(); } private void btnShowBop_Click(object sender, EventArgs e) {
Page 28
286885 BOMA
28
showListBop(); } public void end() { } private void miOk_Click(object sender, EventArgs e) { abort(); } } } using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using holonix.winform; using holonix.applicationlogic; using holonix.datamodel; using holonix.utility; using holonix.datamodel.auxiliary; using holonix.restapi; using holonix.rfid; namespace holonix.production.divide { public partial class FrmProcessDivideItem : HolonixCommonForm, IHolonixCommonForm { ApplicationLogic logic = new ApplicationLogic(); Utility util = new Utility(); CaenRfidControl rfidControl; private Process process; private BillOfProcess billOfProcess; private BillOfProcessOutput billOfProcessOutput; private FrmProcessDivide parent; private ProdottoFisico physicalProduct; private RESTAPI.ProdottoFisico physicalProductAPI = RESTAPI.ProdottoFisico.getInstance(); private RESTAPI.Tag tagAPI = RESTAPI.Tag.getInstance(); private RESTAPI.PhysicalProductTag physicalProductTagAPI = RESTAPI.PhysicalProductTag.getInstance(); private RESTAPI.ProcessPhysicalProductOutput processPhysicalProductOutputAPI = RESTAPI.ProcessPhysicalProductOutput.getInstance(); private RESTAPI.Process processAPI = RESTAPI.Process.getInstance(); private RESTAPI.BomAsProduced bomAsProducedAPI = RESTAPI.BomAsProduced.getInstance(); public FrmProcessDivideItem(Process p, BillOfProcess b, BillOfProcessOutput o, ProdottoFisico pf, FrmProcessDivide f) { process = p; billOfProcess = b; billOfProcessOutput = o; parent = f; physicalProduct = pf; InitializeComponent(); List<Component> disabledControls = new List<Component>(); disabledControls.Add(btnRfid); rfidControl = new CaenRfidControl(this, disabledControls); } private void FrmProcessDivideItem_Load(object sender, EventArgs e) { start(); translation(); } private void translation() { logic.translate(this, VariabiliGlobali.idLanguage); logic.translate(miBack, VariabiliGlobali.idLanguage); } public void start() { tbTipo.Text = billOfProcessOutput.code; tbUom.Text = billOfProcessOutput.uom; }
Page 29
286885 BOMA
29
public void refresh() { } private void btnRfid_Click(object sender, EventArgs e) { rfidControl.Read(btnRfid, doAfterOriginRFIDRead); } private void doAfterOriginRFIDRead(List<String> strList) { tbTag.Text = ""; if (strList.Count == 0) { alert("Errore di lettura", "j4"); } else { fillLvTag(strList); } } private void fillLvTag(List<String> strTag) { for (int i = 0; i < strTag.Count; i++) { ListViewItem li = new ListViewItem(strTag[0]); lvTag.Items.Add(li); } } private void btnClearList_Click(object sender, EventArgs e) { lvTag.Items.Clear(); tbTag.Focus(); } private void btnAdd_Click(object sender, EventArgs e) { if (tbTag.Text.Length < 1) return; ListViewItem li = new ListViewItem(tbTag.Text); lvTag.Items.Add(li); tbTag.Text = ""; } private bool checkQuantity() { if (tbQuantity.Text.Length > 0) { tbQuantity.Text = util.getDecimalNumber(tbQuantity.Text); if (!util.controlloValoreDecimale(tbQuantity.Text)) { tbQuantity.Text = ""; return false; } } if (tbNumItem.Text.Length > 0) { if (!util.controlloValoreIntero(tbNumItem.Text)) { tbNumItem.Text = ""; return false; } } return true; } private void miConfirm_Click(object sender, EventArgs e) { if (tbQuantity.Text.Length > 0 && tbNumItem.Text.Length > 0) return; if (!checkQuantity()) return; Decimal? quantity = null; Int32? numItem = null; if (tbQuantity.Text.Length > 0) quantity = Convert.ToDecimal(tbQuantity.Text); if (tbNumItem.Text.Length > 0)
Page 30
286885 BOMA
30
numItem = Convert.ToInt32(tbNumItem.Text); for (int i = 0; i < lvTag.Items.Count; i++) { String tagCode = lvTag.Items[i].SubItems[0].Text; Tag tag = new Tag(); tag.codice = tagCode; tag.isUnique = true; tag.attivo = true; tag.tipoTag = 1; tag.isProdotto = true; tag.isWarehouse = false; tag.isResource = false; tag.isReusable = false; tag.isProductType = false; tag = tagAPI.save(ref tag); ProdottoFisico product = new ProdottoFisico(); if (billOfProcessOutput.physicalProduct == null) { if (billOfProcessOutput.productFamily != null) { product.tipoProdotto = null; } if (billOfProcessOutput.productType != null) product.tipoProdotto = billOfProcessOutput.productType; product.attivo = true; product.dataScadenza = null; product.isWip = false; product.schedaProduzione = process.productionSheet; product.quantitaEffettiva = quantity; product.dataStart = DateTime.Now; product.dataEnd = null; product.nome = billOfProcessOutput.code; product.tara = 0; product.quantitaIniziale = quantity; product.cardinalita = 1; product.isPack = false; product.unitLoad = 1; product.unitLoadSize = 0; product.canTakeToInside = false; product.canTakeToOutside = false; product.idUniqueness = 1; product.causaleNuovoProdotto = 1; product.isStocked = false; product.isPurchased = false; product.isSold = false; product.idEndType = null; product.canGroup = false; product.divisibile = false; product.idEffectiveQuantityUom = 1; if (quantity == null) product.isHandleQuantity = false; if (numItem == null) product.isHandleNumberOfItems = false; product = physicalProductAPI.save(ref product); } else product = physicalProductAPI.get(billOfProcessOutput.physicalProduct.Value); PhysicalProductTag productTag = new PhysicalProductTag(); productTag.physicalProduct = product.id.Value; productTag.tag = tag.id.Value; productTag.fromDate = DateTime.Now; physicalProductTagAPI.save(ref productTag); if (process.startDate == null) { process.startDate = DateTime.Now; processAPI.save(ref process); } BomAsProduced bomAsProduced = new BomAsProduced(); bomAsProduced.physicalProduct = product.id; bomAsProduced.component = physicalProduct.id; bomAsProduced.startDate = DateTime.Now; bomAsProduced.endDate = null;
Page 31
286885 BOMA
31
bomAsProduced.endNote = null; bomAsProduced.quantity = null; bomAsProduced.numberOfItems = 1; bomAsProduced.process = process.id; bomAsProduced.familyCode = null; bomAsProduced.batchCode = null; bomAsProduced.packagingCode = null; bomAsProducedAPI.save(bomAsProduced); ProcessPhysicalProductOutput output = new ProcessPhysicalProductOutput(); output.process = process.id.Value; output.billOfProcess = billOfProcess.id.Value; output.physicalProduct = product.id.Value; output.date = DateTime.Now; output.master = false; output.quantity = quantity; output.numberOfItems = numItem; processPhysicalProductOutputAPI.save(output); } parent.showListItem(); parent.refresh(); abort(); } public void end() { } private void miBack_Click(object sender, EventArgs e) { abort(); } } } using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using holonix.winform; using holonix.applicationlogic; using holonix.datamodel; using holonix.restapi; using holonix.datamodel.auxiliary; namespace holonix.production.mergingAndAssembly { public partial class FrmProcessMerging : HolonixCommonForm, IHolonixCommonForm { ApplicationLogic logic = new ApplicationLogic(); private RESTAPI.BillOfProcess billOfProcessAPI = RESTAPI.BillOfProcess.getInstance(); private RESTAPI.BillOfProcessInput billOfProcessInputAPI = RESTAPI.BillOfProcessInput.getInstance(); private Process process; private Boolean isAssembly; private String descBop; private String descItem; private BillOfProcess billOfProcess; private List<BillOfProcessInputSummary> bopSummary; public FrmProcessMerging(Boolean isAss, Process p) { isAssembly = isAss; process = p; InitializeComponent(); lblMasterCode.Text = ""; if (isAssembly) { lblMaster.Visible = true; lblMasterCode.Visible = true; } } private void FrmProcessMerging_Load(object sender, EventArgs e) {
Page 32
286885 BOMA
32
start(); translation(); } private void translation() { logic.translate(this, VariabiliGlobali.idLanguage); logic.translate(miOk, VariabiliGlobali.idLanguage); logic.translate(lvBop, VariabiliGlobali.idLanguage); logic.translate(lvItem, VariabiliGlobali.idLanguage); } private void setPanels() { descBop = logic.translate("Bill of material", "vd", VariabiliGlobali.idLanguage); descItem = logic.translate("Effective products", "ve", VariabiliGlobali.idLanguage); pnlBop.Width = 440; pnlBop.Height = 310; pnlBop.Location = new Point(20, 180); pnlItem.Width = 440; pnlItem.Height = 310; pnlItem.Location = new Point(20, 180); showListBop(); } private void showListBop() { lbViewSelected.Text = descBop; pnlBop.Visible = true; pnlItem.Visible = false; btnShowBop.Enabled = false; btnShowItem.Enabled = true; } public void showListItem() { lbViewSelected.Text = descItem; pnlBop.Visible = false; pnlItem.Visible = true; btnShowBop.Enabled = true; btnShowItem.Enabled = false; } public void start() { if (process.endDate != null) btnAddItem.Enabled = false; setPanels(); billOfProcess = billOfProcessAPI.getByProcess(process.id.Value); if (billOfProcess == null) { alert("There isn't billOfProcess.", "000"); abort(); } refresh(); } public void refresh() { this.SuspendLayout(); showBusy(true); bopSummary = billOfProcessInputAPI.getBillOfProcessInputSummaries(process.id.Value, billOfProcess.id.Value); fillListBop(bopSummary); fillListItem(bopSummary); showBusy(false); this.ResumeLayout(); } private void fillListBop(List<BillOfProcessInputSummary> bopSummary) { lvBop.Items.Clear(); for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].billOfProcessInput == null) continue; if (bopSummary[i].billOfProcessInput.master.Value) lblMasterCode.Text = bopSummary[i].billOfProcessInput.code; ListViewItem li = new ListViewItem(bopSummary[i].billOfProcessInput.code); if (bopSummary[i].billOfProcessInput.quantity != null)
Page 33
286885 BOMA
33
{ li.SubItems.Add(bopSummary[i].billOfProcessInput.quantity.Value.ToString()); if (bopSummary[i].billOfProcessInput.uom != null) li.SubItems.Add(bopSummary[i].billOfProcessInput.uom); else li.SubItems.Add(""); if (bopSummary[i].processPhysicalProductInput == null) li.SubItems.Add(""); else { Decimal? qtEff = null; for (int j = 0; j < bopSummary[i].processPhysicalProductInput.Count; j++) { if (bopSummary[i].processPhysicalProductInput[j].quantity != null) if (qtEff == null) qtEff = bopSummary[i].processPhysicalProductInput[j].quantity.Value; else qtEff = qtEff + bopSummary[i].processPhysicalProductInput[j].quantity.Value; } if (qtEff == null) li.SubItems.Add(""); else if (bopSummary[i].billOfProcessInput.quantity < qtEff) li.SubItems.Add("+"); else if (bopSummary[i].billOfProcessInput.quantity > qtEff) li.SubItems.Add("-"); else if (bopSummary[i].billOfProcessInput.quantity == qtEff) li.SubItems.Add("ok"); else li.SubItems.Add(""); } } else if (bopSummary[i].billOfProcessInput.numberOfItems != null) { li.SubItems.Add(bopSummary[i].billOfProcessInput.numberOfItems.Value.ToString()); if (bopSummary[i].billOfProcessInput.uom != null) li.SubItems.Add(bopSummary[i].billOfProcessInput.uom); else li.SubItems.Add(""); if (bopSummary[i].processPhysicalProductInput == null) li.SubItems.Add(""); else { Int32? numEff = null; for (int j = 0; j < bopSummary[i].processPhysicalProductInput.Count; j++) { if (bopSummary[i].processPhysicalProductInput[j].numberOfItems != null) if (numEff == null) numEff = bopSummary[i].processPhysicalProductInput[j].numberOfItems.Value; else numEff = numEff + bopSummary[i].processPhysicalProductInput[j].numberOfItems.Value; } if (numEff == null) li.SubItems.Add(""); else if (bopSummary[i].billOfProcessInput.numberOfItems < numEff) li.SubItems.Add("+"); else if (bopSummary[i].billOfProcessInput.numberOfItems > numEff) li.SubItems.Add("-"); else if (bopSummary[i].billOfProcessInput.numberOfItems == numEff) li.SubItems.Add("ok"); else li.SubItems.Add(""); } } else { li.SubItems.Add(""); li.SubItems.Add(""); li.SubItems.Add(""); }
Page 34
286885 BOMA
34
if (bopSummary[i].billOfProcessInput.tag != null) li.SubItems.Add(bopSummary[i].billOfProcessInput.tag); else li.SubItems.Add(""); lvBop.Items.Add(li); } } private void fillListItem(List<BillOfProcessInputSummary> bopSummary) { lvItem.Items.Clear(); for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].processPhysicalProductInput == null) continue; if (bopSummary[i].processPhysicalProductInput.Count < 1) continue; ListViewItem li = new ListViewItem(bopSummary[i].processPhysicalProductInput[0].code); Decimal? qtEff = null; Int32? numEff = null; for (int j = 0; j < bopSummary[i].processPhysicalProductInput.Count; j++) { if (bopSummary[i].processPhysicalProductInput[j].quantity != null) if (qtEff == null) qtEff = bopSummary[i].processPhysicalProductInput[j].quantity.Value; else qtEff = qtEff + bopSummary[i].processPhysicalProductInput[j].quantity.Value; if (bopSummary[i].processPhysicalProductInput[j].numberOfItems != null) if (numEff == null) numEff = bopSummary[i].processPhysicalProductInput[j].numberOfItems.Value; else numEff = numEff + bopSummary[i].processPhysicalProductInput[j].numberOfItems.Value; } if (qtEff != null) { li.SubItems.Add(qtEff.Value.ToString()); if (bopSummary[i].billOfProcessInput != null) { if (bopSummary[i].billOfProcessInput.uom != null) li.SubItems.Add(bopSummary[i].billOfProcessInput.uom); else li.SubItems.Add(""); } else { li.SubItems.Add(""); } if (bopSummary[i].billOfProcessInput != null && bopSummary[i].billOfProcessInput.quantity != null) { if (qtEff < bopSummary[i].billOfProcessInput.quantity) li.SubItems.Add("-"); else if (qtEff > bopSummary[i].billOfProcessInput.quantity) li.SubItems.Add("+"); else if (qtEff == bopSummary[i].billOfProcessInput.quantity) li.SubItems.Add("ok"); else li.SubItems.Add(""); } else li.SubItems.Add(""); } else if (numEff != null) { li.SubItems.Add(numEff.Value.ToString()); if (bopSummary[i].billOfProcessInput.uom != null) li.SubItems.Add(bopSummary[i].billOfProcessInput.uom); else li.SubItems.Add(""); if (bopSummary[i].billOfProcessInput != null && bopSummary[i].billOfProcessInput.numberOfItems != null) { if (numEff < bopSummary[i].billOfProcessInput.numberOfItems) li.SubItems.Add("-"); else if (numEff > bopSummary[i].billOfProcessInput.numberOfItems)
Page 35
286885 BOMA
35
li.SubItems.Add("+"); else if (numEff == bopSummary[i].billOfProcessInput.numberOfItems) li.SubItems.Add("ok"); else li.SubItems.Add(""); } else li.SubItems.Add(""); } else { li.SubItems.Add(""); li.SubItems.Add(""); li.SubItems.Add(""); } if (bopSummary[i].processPhysicalProductInput[0].tag != null) li.SubItems.Add(bopSummary[i].processPhysicalProductInput[0].tag); else li.SubItems.Add(""); lvItem.Items.Add(li); } } private void btnShowBop_Click(object sender, EventArgs e) { showListBop(); } private void btnShowItem_Click(object sender, EventArgs e) { showListItem(); } private void btnAddItem_Click(object sender, EventArgs e) { bool isMaster = false; if (isAssembly) { for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].billOfProcessInput == null) continue; if (bopSummary[i].billOfProcessInput.master == null) continue; if (bopSummary[i].billOfProcessInput.master == false) continue; if (bopSummary[i].processPhysicalProductInput.Count == 0) { isMaster = true; break; } } } new production.mergingAndAssembly.FrmProcessMergingItem(process, billOfProcess, isMaster, this).Show(); } public void end() { } private void miOk_Click(object sender, EventArgs e) { abort(); } } } using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using holonix.applicationlogic; using holonix.winform;
Page 36
286885 BOMA
36
using holonix.datamodel; using holonix.restapi; using holonix.utility; using holonix.rfid; namespace holonix.production.mergingAndAssembly { public partial class FrmProcessMergingItem : HolonixCommonForm, IHolonixCommonForm { ApplicationLogic logic; Utility util; CaenRfidControl rfidControl; private RESTAPI.ProdottoFisico physicalProductAPI = RESTAPI.ProdottoFisico.getInstance(); private RESTAPI.ProcessPhysicalProductInput processPhysicalProductInputAPI = RESTAPI.ProcessPhysicalProductInput.getInstance(); private RESTAPI.Process processAPI = RESTAPI.Process.getInstance(); private RESTAPI.WPlaceProdottoFisico wplacePhysicalProductApi = RESTAPI.WPlaceProdottoFisico.getInstance(); private RESTAPI.PhysicalProductUniqueness physicalProductUniquenessApi = RESTAPI.PhysicalProductUniqueness.getInstance(); private RESTAPI.Uom uomAPI = RESTAPI.Uom.getInstance(); private Boolean isMaster; private Process process; private BillOfProcess billOfProcess; private ProdottoFisico physicalProduct; private FrmProcessMerging parent; public FrmProcessMergingItem(Process p, BillOfProcess b, Boolean m, FrmProcessMerging f) { process = p; billOfProcess = b; isMaster = m; parent = f; InitializeComponent(); tbUom.Text = ""; logic = new ApplicationLogic(); util = new Utility(); List<Component> disabledControls = new List<Component>(); disabledControls.Add(btnRfid); rfidControl = new CaenRfidControl(this, disabledControls); } private void FrmProcessMergingItem_Load(object sender, EventArgs e) { start(); translation(); } private void translation() { logic.translate(this, VariabiliGlobali.idLanguage); logic.translate(miBack, VariabiliGlobali.idLanguage); } public void start() { if (isMaster) { lblDefineMaster.Visible = true; btnCheckProduct.Text = logic.translate("Confirm", "he", VariabiliGlobali.idLanguage); } pnlQuantity.Visible = false; tbQuantity.Enabled = false; tbNumItem.Enabled = false; } public void refresh() { } private void btnRfid_Click(object sender, EventArgs e) { physicalProduct = null; tbProduct.Text = ""; tbBatch.Text = ""; rfidControl.Read(btnRfid, doAfterOriginRFIDRead); } private void doAfterOriginRFIDRead(List<String> strList) { if (strList.Count == 0) { alert("Errore di lettura","j4");
Page 37
286885 BOMA
37
} else if (strList.Count > 1) { alert("Troppi tag nell'area", "j7"); } else { tbProduct.Text = strList[0]; } } private void btnConfirm_Click(object sender, EventArgs e) { Decimal? quantity = null; Int16? numItem = null; if (tbQuantity.Text.Length > 0) { tbQuantity.Text = util.getDecimalNumber(tbQuantity.Text); if (!util.controlloValoreDecimale(tbQuantity.Text)) { tbQuantity.Text = ""; return; } quantity = Convert.ToDecimal(tbQuantity.Text); } if (tbNumItem.Text.Length > 0) { if (!util.controlloValoreIntero(tbNumItem.Text)) { tbNumItem.Text = ""; return; } numItem = Convert.ToInt16(tbNumItem.Text); } if (!isMaster) if (quantity == null && numItem == null) return;0 if (process.startDate == null) { process.startDate = DateTime.Now; processAPI.save(ref process); } ProcessPhysicalProductInput pppi = new ProcessPhysicalProductInput(); pppi.billOfProcess = billOfProcess.id; pppi.process = process.id; pppi.physicalProduct = physicalProduct.id; pppi.master = isMaster; pppi.quantity = quantity; if (isMaster) pppi.quantity = null; pppi.numberOfItems = numItem; if (isMaster) pppi.numberOfItems = 1; pppi.date = DateTime.Now; processPhysicalProductInputAPI.save(ref pppi); if (!isMaster) { if (physicalProduct.idUniqueness == physicalProductUniquenessApi.Unique.id) { physicalProduct.attivo = false; physicalProductAPI.save(ref physicalProduct); WPlaceProdottoFisico wppp = wplacePhysicalProductApi.getProductLocation(physicalProduct.id); if (wppp != null) { wppp.to = DateTime.Now; wplacePhysicalProductApi.save(ref wppp); } } else { WPlaceProdottoFisico wppp = wplacePhysicalProductApi.get(Prefetch.WPlace.productionWPlace.id, physicalProduct.id); if (physicalProduct.isHandleQuantity) {
Page 38
286885 BOMA
38
if (wppp.quantity != null) wppp.quantity -= quantity; else wppp.quantity = -quantity; } if (physicalProduct.isHandleNumberOfItems) { if (wppp.numberOfItems != null) wppp.numberOfItems -= numItem; else wppp.numberOfItems = -numItem; } wplacePhysicalProductApi.save(ref wppp); } } parent.showListItem(); parent.refresh(); abort(); } private void btnCheckProduct_Click(object sender, EventArgs e) { if (tbProduct.Text.Length < 1) return; String tag = ""; if (tbProduct.Text.Length > 0) tag = tbProduct.Text; if (tbBatch.Text.Length > 0) tag = tag + "##" + tbBatch.Text; List<ProdottoFisico> list = physicalProductAPI.getByTag(tag); if (list.Count > 0) physicalProduct = list[0]; if (physicalProduct == null) { tbProduct.Text = ""; tbBatch.Text = ""; return; } btnRfid.Enabled = false; tbProduct.Enabled = false; tbBatch.Enabled = false; btnCheckProduct.Enabled = false; if (isMaster) { btnConfirm_Click(null, null); return; } pnlQuantity.Visible = true; tbUom.Text = uomAPI.getByPhysicalProductId(physicalProduct.id.Value).label; if (physicalProduct.isHandleQuantity) tbQuantity.Enabled = true; if (physicalProduct.isHandleNumberOfItems) tbNumItem.Enabled = true; } public void end() { } private void miBack_Click(object sender, EventArgs e) { if (physicalProduct == null) abort(); else alert("Continue operation befor exiting.", "000"); } } } using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;
Page 39
286885 BOMA
39
using System.Text; using System.Windows.Forms; using holonix.winform; using holonix.applicationlogic; using holonix.datamodel; using holonix.utility; using holonix.datamodel.auxiliary; using holonix.restapi; using holonix.rfid; namespace holonix.production.mergingAndAssembly { public partial class FrmProcessMergingTagOutput : HolonixCommonForm, IHolonixCommonForm { ApplicationLogic logic = new ApplicationLogic(); Utility util = new Utility(); CaenRfidControl rfidControl; private Process process; private ProductFamily productFamily; private TipoProdotto productType; private List<Tag> tags = new List<Tag>(); private RESTAPI.ProdottoFisico physicalProductAPI = RESTAPI.ProdottoFisico.getInstance(); private RESTAPI.Tag tagAPI = RESTAPI.Tag.getInstance(); private RESTAPI.PhysicalProductTag physicalProductTagAPI = RESTAPI.PhysicalProductTag.getInstance(); private RESTAPI.ProcessPhysicalProductOutput processPhysicalProductOutputAPI = RESTAPI.ProcessPhysicalProductOutput.getInstance(); private RESTAPI.Process processAPI = RESTAPI.Process.getInstance(); private RESTAPI.BomAsProduced bomAsProducedAPI = RESTAPI.BomAsProduced.getInstance(); private RESTAPI.ProductFamily productFamilyAPI = RESTAPI.ProductFamily.getInstance(); private RESTAPI.TipoProdotto productTypeAPI = RESTAPI.TipoProdotto.getInstance(); public FrmProcessMergingTagOutput(Process process, BillOfProcessOutputSummary bopOutputSummary) { this.process = process; InitializeComponent(); if (bopOutputSummary.billOfProcessOutput.productFamily != null) { productFamily = productFamilyAPI.get(bopOutputSummary.billOfProcessOutput.productFamily.Value); } if (bopOutputSummary.billOfProcessOutput.productType != null) { productType = productTypeAPI.get(bopOutputSummary.billOfProcessOutput.productType); } List<Component> disabledControls = new List<Component>(); disabledControls.Add(btnRfid); rfidControl = new CaenRfidControl(this, disabledControls); } private void FrmProcessMergingTagOutput_Load(object sender, EventArgs e) { if (productFamily != null) { tbProductFamilyCode.Text = productFamily.code; } else { tbProductFamilyCode.Visible = false; label2.Visible = false; } tbProductFamilyCode.Enabled = false; tbProductFamilyCode.ReadOnly = false; if (productType != null) { tbProductTypeCode.Text = productType.codice; tbProductTypeCode.Enabled = false; tbProductTypeCode.ReadOnly = false; } translation(); } private void translation() { logic.translate(this, VariabiliGlobali.idLanguage); logic.translate(miBack, VariabiliGlobali.idLanguage); } public void start() { }
Page 40
286885 BOMA
40
public void refresh() { } private void btnRfid_Click(object sender, EventArgs e) { rfidControl.Read(btnRfid, doAfterOriginRFIDRead); } private void doAfterOriginRFIDRead(List<String> strList) { tbTagCode.Text = ""; if (strList.Count == 0) { alert("Errore di lettura", "j4"); } else { fillLvTag(strList); } } private void fillLvTag(List<String> strTag) { for (int i = 0; i < strTag.Count; i++) { ListViewItem li = new ListViewItem(strTag[0]); lvTag.Items.Add(li); } } private void btnClearList_Click(object sender, EventArgs e) { lvTag.Items.Clear(); tbTagCode.Focus(); } private void btnAdd_Click(object sender, EventArgs e) { if (tbTagCode.Text.Length < 1) return; ListViewItem li = new ListViewItem(tbTagCode.Text); lvTag.Items.Add(li); tbTagCode.Text = ""; } private void miConfirm_Click(object sender, EventArgs e) { for (int i = 0; i < lvTag.Items.Count; i++) { String tagCode = lvTag.Items[i].SubItems[0].Text; Tag tag = new Tag(); tag.codice = tagCode; tag.isUnique = true; tag.attivo = true; tag.tipoTag = 1; tag.isProdotto = true; tag.isWarehouse = false; tag.isResource = false; tag.isReusable = false; tag.isProductType = false; tags.Add(tag); } this.DialogResult = DialogResult.OK; this.Close(); } public void end() { } private void miBack_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } public TipoProdotto getProductType() { return productType; } public List<Tag> getTags() { return tags; }
Page 41
286885 BOMA
41
} } using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using holonix.winform; using holonix.applicationlogic; using holonix.datamodel; using holonix.utility; using holonix.restapi; using holonix.datamodel.auxiliary; namespace holonix.production.personnel { public partial class FrmProcessOperator : HolonixCommonForm, IHolonixCommonForm { private ApplicationLogic logic = new ApplicationLogic(); private Utility util = new Utility(); private RESTAPI.BillOfProcess billOfProcessAPI = RESTAPI.BillOfProcess.getInstance(); private RESTAPI.Operator operatorAPI = RESTAPI.Operator.getInstance(); private RESTAPI.OperatorType operatorTypeAPI = RESTAPI.OperatorType.getInstance(); private RESTAPI.BillOfProcessOperator billOfProcessOperatorAPI = RESTAPI.BillOfProcessOperator.getInstance(); private RESTAPI.ProcessOperator processOperatorAPI = RESTAPI.ProcessOperator.getInstance(); private RESTAPI.Process processAPI = RESTAPI.Process.getInstance(); private Process process; private BillOfProcess billOfProcess; private List<BillOfProcessOperatorSummary> bopSummary; public FrmProcessOperator(Process p, String processTypeLabel) { process = p; InitializeComponent(); } private void FrmProcessOperator_Load(object sender, EventArgs e) { start(); translation(); } private void translation() { logic.translate(this, VariabiliGlobali.idLanguage); logic.translate(miBack, VariabiliGlobali.idLanguage); logic.translate(lvOperators, VariabiliGlobali.idLanguage); } private void fillComboboxOperatorType() { cbOperatorType.Items.Clear(); OperatorType t = new OperatorType(); t.label = "-"; List<OperatorType> operatorTypes = new List<OperatorType>(); operatorTypes.Add(t); operatorTypes.AddRange(operatorTypeAPI.get()); cbOperatorType.DataSource = operatorTypes; cbOperatorType.DisplayMember = "label"; } private void fillComboboxOperatorName() { cbOperatorName.Items.Clear(); Operator o = new Operator(); o.label = "-"; List<Operator> operators = new List<Operator>(); operators.Add(o); operators.AddRange(operatorAPI.get()); cbOperatorName.DataSource = operators; cbOperatorName.DisplayMember = "label"; }
Page 42
286885 BOMA
42
private void getBillOfProcess() { billOfProcess = billOfProcessAPI.getByProcess(process.id.Value); if (billOfProcess == null) { alert("There isn't billOfProcess.", "000"); abort(); } } private void getbopSummary() { bopSummary = billOfProcessOperatorAPI.getBillOfProcessOperatorSummaries(process.id.Value, billOfProcess.id.Value); Int32 hours = 0; for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].billOfProcessOperator != null) if (bopSummary[i].billOfProcessOperator.hours != null) hours = hours + bopSummary[i].billOfProcessOperator.hours.Value; } lblHours.Text = "" + hours; } private void fillListOperator() { lvOperators.Items.Clear(); for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].processOperator == null) continue; ListViewItem li; List<ProcessOperator> listProcess = bopSummary[i].processOperator; for (int j = 0; j < listProcess.Count; j++) { ProcessOperator p = listProcess[j]; if (p.operatorTypeLabel != null) li = new ListViewItem(p.operatorTypeLabel); else li = new ListViewItem(""); if (p.operatorLabel != null) li.SubItems.Add(p.operatorLabel); else li.SubItems.Add(""); if (p.hours != null) li.SubItems.Add(p.hours.Value.ToString()); else li.SubItems.Add(""); if (p.date != null) li.SubItems.Add(util.getDateFormat(p.date.Value).ToString()); else li.SubItems.Add(""); lvOperators.Items.Add(li); } } } public void start() { this.SuspendLayout(); showBusy(true); if (process.endDate != null) btnConfirm.Enabled = false; fillComboboxOperatorType(); fillComboboxOperatorName(); getBillOfProcess(); refresh(); showBusy(false); this.ResumeLayout(); } private void btnConfirm_Click(object sender, EventArgs e) { if ((cbOperatorName.SelectedItem as Operator).id == null) return; if ((cbOperatorType.SelectedItem as OperatorType).id == null)
Page 43
286885 BOMA
43
return; if (tbHours.Text.Length < 1) return; Int32? hours = null; if (!util.controlloValoreIntero(tbHours.Text)) { tbHours.Text = ""; return; } hours = Convert.ToInt32(tbHours.Text); if (process.startDate == null) { process.startDate = DateTime.Now; processAPI.save(ref process); } ProcessOperator p = new ProcessOperator(); p.process = process.id.Value; p.billOfProcess = billOfProcess.id.Value; p.operatore = (cbOperatorName.SelectedItem as Operator).id.Value; p.operatorType = (cbOperatorType.SelectedItem as OperatorType).id.Value; p.hours = hours.Value; p.date = DateTime.Now; p.master = ckMaster.Checked; processOperatorAPI.save(p); refresh(); } public void refresh() { getbopSummary(); fillListOperator(); } public void end() { } private void miBack_Click(object sender, EventArgs e) { abort(); } } } using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using holonix.winform; using holonix.applicationlogic; using holonix.datamodel; using holonix.utility; using holonix.restapi; using holonix.datamodel.auxiliary; namespace holonix.production.resource { public partial class FrmProcessResource : HolonixCommonForm, IHolonixCommonForm { private ApplicationLogic logic = new ApplicationLogic(); private Utility util = new Utility(); private RESTAPI.BillOfProcess billOfProcessAPI = RESTAPI.BillOfProcess.getInstance(); private RESTAPI.Risorsa resourceAPI = RESTAPI.Risorsa.getInstance(); private RESTAPI.ResourceType resourceTypeAPI = RESTAPI.ResourceType.getInstance(); private RESTAPI.BillOfProcessResource billOfProcessResourceAPI = RESTAPI.BillOfProcessResource.getInstance(); private RESTAPI.ProcessResource processResourceAPI = RESTAPI.ProcessResource.getInstance(); private RESTAPI.Process processAPI = RESTAPI.Process.getInstance(); private Process process; private BillOfProcess billOfProcess; private List<BillOfProcessResourceSummary> bopSummary; public FrmProcessResource(Process p, String processTypeLabel) {
Page 44
286885 BOMA
44
process = p; InitializeComponent(); } private void FrmProcessResource_Load(object sender, EventArgs e) { start(); translation(); } private void translation() { logic.translate(this, VariabiliGlobali.idLanguage); logic.translate(miBack, VariabiliGlobali.idLanguage); logic.translate(lvResources, VariabiliGlobali.idLanguage); } private void fillComboboxResourceType() { cbResourceType.Items.Clear(); ResourceType t = new ResourceType(); t.code = "-"; List<ResourceType> resourceTypes = new List<ResourceType>(); resourceTypes.Add(t); resourceTypes.AddRange(resourceTypeAPI.get()); cbResourceType.DataSource = resourceTypes; cbResourceType.DisplayMember = "code"; } private void cbResourceType_SelectedIndexChanged(object sender, EventArgs e) { if ((cbResourceType.SelectedItem as ResourceType).id == null) fillComboboxResourceName(resourceAPI.get()); else fillComboboxResourceName(resourceAPI.getByResourceType((cbResourceType.SelectedItem as ResourceType).id)); } private void fillComboboxResourceName(List<Risorsa> resources) { cbResourceName.DataSource = resources; cbResourceName.DisplayMember = "name"; } private void getBillOfProcess() { billOfProcess = billOfProcessAPI.getByProcess(process.id.Value); if (billOfProcess == null) { alert("There isn't billOfProcess.", "000"); abort(); } } private void getbopSummary() { bopSummary = billOfProcessResourceAPI.getBillOfProcessResourceSummaries(process.id.Value, billOfProcess.id.Value); } private void fillListResource() { lvResources.Items.Clear(); for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].processResource == null) continue; ListViewItem li; List<ProcessResource> listProcess = bopSummary[i].processResource; for (int j = 0; j < listProcess.Count; j++) { ProcessResource p = listProcess[j]; if (p.resourceTypeName != null) li = new ListViewItem(p.resourceTypeName); else li = new ListViewItem(""); if (p.resourceCode != null) li.SubItems.Add(p.resourceCode); else li.SubItems.Add(""); if (p.hours != null) li.SubItems.Add(p.hours.Value.ToString());
Page 45
286885 BOMA
45
else li.SubItems.Add(""); if (p.date != null) li.SubItems.Add(util.getDateFormat(p.date.Value).ToString()); else li.SubItems.Add(""); lvResources.Items.Add(li); } } } public void start() { this.SuspendLayout(); showBusy(true); if (process.endDate != null) btnConfirm.Enabled = false; fillComboboxResourceType(); fillComboboxResourceName(resourceAPI.get()); getBillOfProcess(); refresh(); showBusy(false); this.ResumeLayout(); } private void btnConfirm_Click(object sender, EventArgs e) { if ((cbResourceName.SelectedItem as Risorsa).id == null) return; if ((cbResourceType.SelectedItem as ResourceType).id == null) return; if (tbHours.Text.Length < 1) return; Int32? hours = null; if (!util.controlloValoreIntero(tbHours.Text)) { tbHours.Text = ""; return; } hours = Convert.ToInt32(tbHours.Text); if (process.startDate == null) { process.startDate = DateTime.Now; processAPI.save(ref process); } ProcessResource p = new ProcessResource(); p.process = process.id.Value; p.billOfProcess = billOfProcess.id.Value; p.resource = (cbResourceName.SelectedItem as Risorsa).id; p.hours = hours.Value; p.date = DateTime.Now; processResourceAPI.save(p); refresh(); } public void refresh() { getbopSummary(); fillListResource(); } public void end() { } private void miBack_Click(object sender, EventArgs e) { abort(); } } } using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data;
Page 46
286885 BOMA
46
using System.Drawing; using System.Text; using System.Windows.Forms; using holonix.winform; using holonix.restapi; using holonix.datamodel; using holonix.applicationlogic; namespace holonix.production { public partial class FrmProductionSheet : HolonixCommonForm, IHolonixCommonForm { ApplicationLogic logic = new ApplicationLogic(); private RESTAPI.SchedaProduzione productionSheetAPI = RESTAPI.SchedaProduzione.getInstance(); public FrmProductionSheet() { InitializeComponent(); } private void FrmProductionSheet_Load(object sender, EventArgs e) { start(); translation(); } private void translation() { logic.translate(this, VariabiliGlobali.idLanguage); logic.translate(miBack, VariabiliGlobali.idLanguage); } public void refresh() { } public void start() { } private void btnOpen_Click(object sender, EventArgs e) { if (tbCode.Text.Length < 1) return; SchedaProduzione productionSheet = productionSheetAPI.get(tbCode.Text); if (productionSheet == null) { tbCode.Text = ""; return; } new production.FrmProductionSheetProcesses(productionSheet).Show(); } public void end() { } private void miBack_Click(object sender, EventArgs e) { abort(); } } } using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using holonix.winform; using holonix.applicationlogic; using holonix.datamodel; using holonix.datamodel.auxiliary; using holonix.restapi; namespace holonix.production { public partial class FrmProductionSheetProcessAction : HolonixCommonForm, IHolonixCommonForm {
Page 47
286885 BOMA
47
ApplicationLogic logic = new ApplicationLogic(); private Process process; private ProcessType processType; private FrmProductionSheetProcesses parent; private RESTAPI.Process processAPI = RESTAPI.Process.getInstance(); private RESTAPI.BillOfProcess billOfProcessAPI = RESTAPI.BillOfProcess.getInstance(); private RESTAPI.BillOfProcessInput billOfProcessInputAPI = RESTAPI.BillOfProcessInput.getInstance(); private RESTAPI.BillOfProcessOutput billOfProcessOutputAPI = RESTAPI.BillOfProcessOutput.getInstance(); private RESTAPI.ProcessPhysicalProductOutput processPhysicalProductOutputAPI = RESTAPI.ProcessPhysicalProductOutput.getInstance(); private RESTAPI.BomAsProduced bomAsProducedAPI = RESTAPI.BomAsProduced.getInstance(); private RESTAPI.ProdottoFisico physicalProductAPI = RESTAPI.ProdottoFisico.getInstance(); private RESTAPI.WPlaceProdottoFisico wplacePhysicalProductApi = RESTAPI.WPlaceProdottoFisico.getInstance(); private RESTAPI.PhysicalProductUniqueness physicalProductUniquenessApi = RESTAPI.PhysicalProductUniqueness.getInstance(); private RESTAPI.Tag tagAPI = RESTAPI.Tag.getInstance(); private RESTAPI.PhysicalProductTag physicalProductTagAPI = RESTAPI.PhysicalProductTag.getInstance(); public FrmProductionSheetProcessAction(ProcessSummary summary, FrmProductionSheetProcesses f) { parent = f; process = summary.process; processType = summary.processType; InitializeComponent(); } private void FrmProductionSheetProcessAction_Load(object sender, EventArgs e) { start(); lbProcessName.Text = process.name; lbProcessType.Text = logic.translate(processType.label, processType.translation, VariabiliGlobali.idLanguage); translation(); } private void translation() { logic.translate(this, VariabiliGlobali.idLanguage); logic.translate(miBack, VariabiliGlobali.idLanguage); } public void refresh() { } public void start() { if (process.endDate != null) btnComplete.Enabled = false; } private void btnExecute_Click(object sender, EventArgs e) { switch (processType.code.ToUpper()) { case ProcessType.CHANGE_TYPE: new production.changeType.FrmProcessChangeType(process, lbProcessName.Text).Show(); break; case ProcessType.MERGING: new production.mergingAndAssembly.FrmProcessMerging(false, process).Show(); break; case ProcessType.ASSEMBLY: new production.mergingAndAssembly.FrmProcessMerging(true, process).Show(); break; case ProcessType.ACTION: new production.action.FrmProcessAction(process, lbProcessName.Text).Show(); break; case ProcessType.DIVIDE: new production.divide.FrmProcessDivide(process, lbProcessName.Text).Show(); break; default: alert("Unknown process type.", "000"); break; } } private void btnOperator_Click(object sender, EventArgs e) { new production.personnel.FrmProcessOperator(process, lbProcessName.Text).Show(); } private void btnResource_Click(object sender, EventArgs e) {
Page 48
286885 BOMA
48
new production.resource.FrmProcessResource(process, lbProcessName.Text).Show(); } private void btnComplete_Click(object sender, EventArgs e) { if (process.startDate == null) return; Boolean completed; switch (processType.code.ToUpper()) { case ProcessType.ASSEMBLY: completed = completeAssembly(); break; case ProcessType.MERGING: completed = completeMerging(); break; case ProcessType.DIVIDE: completed = completeDivide(); break; default: completed = true; break; } if (!completed) return; process.endDate = DateTime.Now; processAPI.save(ref process); btnComplete.Enabled = false; parent.refresh(); abort(); } private Boolean completeAssembly() { showBusy(true); BillOfProcess billOfProcess = billOfProcessAPI.getByProcess(process.id.Value); List<BillOfProcessInputSummary> bopSummaryInput = billOfProcessInputAPI.getBillOfProcessInputSummaries(process.id.Value, billOfProcess.id.Value); Int64? productId = null; for (int i = 0; i < bopSummaryInput.Count; i++) { if (bopSummaryInput[i].billOfProcessInput != null) if (bopSummaryInput[i].billOfProcessInput.master.Value) { productId = bopSummaryInput[i].processPhysicalProductInput[0].physicalProduct; break; } } ProcessPhysicalProductOutput output = new ProcessPhysicalProductOutput(); output.process = process.id.Value; output.billOfProcess = billOfProcess.id.Value; output.physicalProduct = productId.Value; output.date = DateTime.Now; output.master = true; output.quantity = null; output.numberOfItems = 1; processPhysicalProductOutputAPI.save(output); for (int i = 0; i < bopSummaryInput.Count; i++) { if (bopSummaryInput[i].processPhysicalProductInput == null) continue; if (bopSummaryInput[i].processPhysicalProductInput.Count < 1) continue; for (int j = 0; j < bopSummaryInput[i].processPhysicalProductInput.Count; j++) { if (bopSummaryInput[i].processPhysicalProductInput[j].master.Value) continue; BomAsProduced bomAsProduced = new BomAsProduced(); bomAsProduced.physicalProduct = productId; bomAsProduced.component = bopSummaryInput[i].processPhysicalProductInput[j].physicalProduct.Value; bomAsProduced.startDate = DateTime.Now; bomAsProduced.endDate = null; bomAsProduced.endNote = null; bomAsProduced.quantity = bopSummaryInput[i].processPhysicalProductInput[j].quantity;
Page 49
286885 BOMA
49
bomAsProduced.numberOfItems = bopSummaryInput[i].processPhysicalProductInput[j].numberOfItems; bomAsProduced.process = process.id; bomAsProduced.familyCode = null; bomAsProduced.batchCode = null; bomAsProduced.packagingCode = null; bomAsProducedAPI.save(bomAsProduced); } } showBusy(false); return true; } private class CompleteResult { public TipoProdotto productType { get; set; } public List<Tag> tags { get; set; } public BillOfProcessOutputSummary bopSummaryOutput { get; set; } public CompleteResult(BillOfProcessOutputSummary bopSummaryOutput, TipoProdotto productType, List<Tag> tags) { this.bopSummaryOutput = bopSummaryOutput; this.productType = productType; this.tags = tags; } } private Boolean completeMerging() { BillOfProcess billOfProcess = billOfProcessAPI.getByProcess(process.id.Value); List<BillOfProcessInputSummary> bopSummaryInputs = billOfProcessInputAPI.getBillOfProcessInputSummaries(process.id.Value, billOfProcess.id.Value); List<BillOfProcessOutputSummary> bopSummaryOutputs = billOfProcessOutputAPI.getBillOfProcessOutputSummaries(process.id.Value, billOfProcess.id.Value); List<CompleteResult> completeResults = new List<CompleteResult>(); foreach (BillOfProcessOutputSummary bopSummaryOutput in bopSummaryOutputs) { mergingAndAssembly.FrmProcessMergingTagOutput dialogForm = new mergingAndAssembly.FrmProcessMergingTagOutput(process, bopSummaryOutput); if (dialogForm.ShowDialog() == DialogResult.OK) { TipoProdotto productType = dialogForm.getProductType(); List<Tag> tags = dialogForm.getTags(); dialogForm.Dispose(); completeResults.Add(new CompleteResult(bopSummaryOutput, productType, tags)); } else { return false; } } showBusy(true); foreach (CompleteResult completeResult in completeResults) { ProdottoFisico product = new ProdottoFisico(); product.tipoProdotto = completeResult.productType.id; product.attivo = true; product.dataScadenza = null; product.isWip = completeResult.bopSummaryOutput.billOfProcessOutput.wip; product.schedaProduzione = process.productionSheet; product.quantitaEffettiva = 1; product.dataStart = DateTime.Now; product.dataEnd = null; product.nome = completeResult.productType.codice; product.tara = 0; product.quantitaIniziale = 1; product.cardinalita = 1; product.isPack = false; product.unitLoad = 1; product.unitLoadSize = 0; product.canTakeToInside = true; product.canTakeToOutside = true; product.idUniqueness = 1; product.causaleNuovoProdotto = 1; product.isStocked = false; product.isPurchased = false;
Page 50
286885 BOMA
50
product.isSold = false; product.idEndType = null; product.canGroup = false; product.divisibile = false; product.isHandleQuantity = true; product.isHandleNumberOfItems = true; product = physicalProductAPI.save(ref product); ProcessPhysicalProductOutput output = new ProcessPhysicalProductOutput(); output.process = process.id.Value; output.billOfProcess = billOfProcess.id.Value; output.physicalProduct = product.id.Value; output.date = DateTime.Now; output.master = true; output.quantity = null; output.numberOfItems = 1; processPhysicalProductOutputAPI.save(output); for (int i = 0; i < bopSummaryInputs.Count; i++) { if (bopSummaryInputs[i].processPhysicalProductInput == null) continue; if (bopSummaryInputs[i].processPhysicalProductInput.Count < 1) continue; for (int j = 0; j < bopSummaryInputs[i].processPhysicalProductInput.Count; j++) { BomAsProduced bomAsProduced = new BomAsProduced(); bomAsProduced.physicalProduct = product.id; bomAsProduced.component = bopSummaryInputs[i].processPhysicalProductInput[j].physicalProduct.Value; bomAsProduced.startDate = DateTime.Now; bomAsProduced.endDate = null; bomAsProduced.endNote = null; bomAsProduced.quantity = bopSummaryInputs[i].processPhysicalProductInput[j].quantity; bomAsProduced.numberOfItems = bopSummaryInputs[i].processPhysicalProductInput[j].numberOfItems; bomAsProduced.process = process.id; bomAsProduced.familyCode = null; bomAsProduced.batchCode = null; bomAsProduced.packagingCode = null; bomAsProducedAPI.save(bomAsProduced); } } for (int i = 0; i < completeResult.tags.Count; i++) { Tag tag = completeResult.tags[i]; tagAPI.save(ref tag); PhysicalProductTag productTag = new PhysicalProductTag(); productTag.physicalProduct = product.id.Value; productTag.tag = tag.id.Value; productTag.fromDate = DateTime.Now; physicalProductTagAPI.save(ref productTag); } } showBusy(false); return true; } private Boolean completeDivide() { BillOfProcess billOfProcess = billOfProcessAPI.getByProcess(process.id.Value); List<BillOfProcessInputSummary> bopSummaryInputs = billOfProcessInputAPI.getBillOfProcessInputSummaries(process.id.Value, billOfProcess.id.Value); for (int i = 0; i < bopSummaryInputs.Count; i++) { List<ProcessPhysicalProductInput> processPhysicalProductInputs = bopSummaryInputs[i].processPhysicalProductInput; for (int j = 0; j < processPhysicalProductInputs.Count; j++) { ProdottoFisico physicalProduct = physicalProductAPI.get(processPhysicalProductInputs[j].physicalProduct); if (physicalProduct.idUniqueness == physicalProductUniquenessApi.Unique.id) { physicalProduct.attivo = false; physicalProductAPI.save(ref physicalProduct); WPlaceProdottoFisico wppp = wplacePhysicalProductApi.getProductLocation(physicalProduct.id); if (wppp != null) { wppp.to = DateTime.Now;
Page 51
286885 BOMA
51
wplacePhysicalProductApi.save(ref wppp); } } } } return true; } public void end() { } private void miBack_Click(object sender, EventArgs e) { abort(); } } } using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using holonix.winform; using holonix.datamodel; using holonix.applicationlogic; using holonix.datamodel.auxiliary; using holonix.restapi; namespace holonix.production { public partial class FrmProductionSheetProcesses : HolonixCommonForm, IHolonixCommonForm { ApplicationLogic logic = new ApplicationLogic(); private RESTAPI.Process processAPI = RESTAPI.Process.getInstance(); private SchedaProduzione productionSheet; private List<datamodel.auxiliary.ProcessSummary> summary; public FrmProductionSheetProcesses(SchedaProduzione ps) { productionSheet = ps; InitializeComponent(); } private void FrmProductionSheetProcesses_Load(object sender, EventArgs e) { lblProductionSheetCode.Text = productionSheet.code; start(); translation(); } private void translation() { logic.translate(this, VariabiliGlobali.idLanguage); logic.translate(lvProcesses, VariabiliGlobali.idLanguage); logic.translate(miBack, VariabiliGlobali.idLanguage); } public void refresh() { summary = processAPI.getSummaryByProductionSheet(productionSheet.id.Value); if (summary != null) fillProcessesList(); } public void start() { refresh(); } private void fillProcessesList() { lvProcesses.Items.Clear(); for (int i = 0; i < summary.Count; i++) { String label = ""; if (summary[i].processType != null)
Page 52
286885 BOMA
52
label = logic.translate(summary[i].processType.label, summary[i].processType.translation, VariabiliGlobali.idLanguage); ListViewItem li = new ListViewItem(summary[i].process.name); li.SubItems.Add(label); li.SubItems.Add(summary[i].process.id.Value.ToString()); if (!summary[i].reachable) li.BackColor = Color.LightGray; lvProcesses.Items.Add(li); } } private void btnConfirm_Click(object sender, EventArgs e) { ListView.SelectedIndexCollection selectedIndeces = lvProcesses.SelectedIndices; ListViewItem selectedItem = null; if (selectedIndeces.Count == 1) selectedItem = lvProcesses.Items[selectedIndeces[0]]; else return; Int64 idProcess = Int64.Parse(selectedItem.SubItems[2].Text); ProcessSummary s = null; for (int i = 0; i < summary.Count; i++) { if (summary[i].process.id.Value.Equals(idProcess)) { s = summary[i]; break; } } if (s != null) if (s.reachable) new production.FrmProductionSheetProcessAction(s, this).Show(); } public void end() { } private void miBack_Click(object sender, EventArgs e) { abort(); } } } using System; using System.Linq; using System.Collections.Generic; using System.Text; using holonix.winform; namespace holonix.production.divide { public interface IHolonixProcessDivideItem : IHolonixCommonForm { void disableProductControls(); void enableProductControls(); void resetProductControls(); void setProduct(String code); void setPackaging(String code); void setBatch(String code); void disableTagControls(); void enableTagControls(); void disableNumberOfItemsControls(); void enableNumberOfItemsControls(); void setNumberOfItems(String numberOfItems); void setUom(String uom); String getUom(); void disableQuantityControls(); void enableQuantityControls(); void setQuantity(String quantity); void setQuantityLabel(String text); } } using System; using System.Linq;
Page 53
286885 BOMA
53
using System.Collections.Generic; using System.Text; using holonix.winform; namespace holonix.production.mergingAndAssembly { public interface IHolonixProcessMergingItem : IHolonixCommonForm { void disableCheckControls(); void enableCheckControls(); void resetTagControls(); void setTag(String tag); void setNumberOfTags(String number); void resetProductControls(); void disableNumberOfItemsControls(); void enableNumberOfItemsControls(); void setNumberOfItems(String numberOfItems); void setUom(String uom); String getUom(); void disableQuantityControls(); void enableQuantityControls(); void setQuantity(String quantity); void resetPanelConfirmControls(); void showPanelConfirmControls(); void hidePanelConfirmControls(); } } using System; using System.Linq; using System.Collections.Generic; using System.Text; using holonix.winform; namespace holonix.production { public interface IHolonixProductionSheet : IHolonixCommonForm { void showOpenControls(); void resetProductionSheetCodeControls(); void resetProductionSheetBatchControls(); } } using System; using System.Linq; using System.Collections.Generic; using System.Text; using holonix.production.divide; using holonix.datamodel; using holonix.restapi; using holonix.datamodel.auxiliary; using holonix.utility; using holonix.applicationlogic; using holonix.config; namespace holonix.controllers { public class ProcessDivide { Utility util; ApplicationLogic logic; IHolonixProcessDivideItem view; List<BillOfProcessOutputSummary> bopSummary; BillOfProcess billOfProcess; Process process; Boolean isRepackaging; BillOfProcessOutput bopOutput; Int64? scaleId; ProductFamily family; PackagingType packaging; TipoProdotto productType; RESTAPI.ProdottoFisico physicalProductAPI = RESTAPI.ProdottoFisico.getInstance(); RESTAPI.TipoProdotto productTypeAPI = RESTAPI.TipoProdotto.getInstance(); RESTAPI.ProductFamily productFamilyAPI = RESTAPI.ProductFamily.getInstance();
Page 54
286885 BOMA
54
RESTAPI.PackagingType packagingTypeAPI = RESTAPI.PackagingType.getInstance(); RESTAPI.Tag tagAPI = RESTAPI.Tag.getInstance(); RESTAPI.PhysicalProductTag physicalProductTagAPI = RESTAPI.PhysicalProductTag.getInstance(); RESTAPI.ProcessPhysicalProductOutput processPhysicalProductOutputAPI = RESTAPI.ProcessPhysicalProductOutput.getInstance(); RESTAPI.BomAsProduced bomAsProducedAPI = RESTAPI.BomAsProduced.getInstance(); RESTAPI.SchedaProduzione productionSheetAPI = RESTAPI.SchedaProduzione.getInstance(); RESTAPI.ResourceType resourceTypeAPI = RESTAPI.ResourceType.getInstance(); RESTAPI.BillOfProcessResource billOfProcessResourceAPI = RESTAPI.BillOfProcessResource.getInstance(); RESTAPI.Activity activityAPI = RESTAPI.Activity.getInstance(); RESTAPI.ActivityOperator activityOperatorAPI = RESTAPI.ActivityOperator.getInstance(); RESTAPI.ActivityPhysicalProductObject activityOperatorPhysicalProductObjectAPI = RESTAPI.ActivityPhysicalProductObject.getInstance(); RESTAPI.ActivityType activityTypeAPI = RESTAPI.ActivityType.getInstance(); RESTAPI.WPlaceProdottoFisico wplacePhysicalProductApi = RESTAPI.WPlaceProdottoFisico.getInstance(); RESTAPI.WPlace wplaceApi = RESTAPI.WPlace.getInstance(); RESTAPI.NewPhysicalProductReason newPhysicalProductReasonApi = RESTAPI.NewPhysicalProductReason.getInstance(); RESTAPI.Batch batchAPI = RESTAPI.Batch.getInstance(); RESTAPI.Process processAPI = RESTAPI.Process.getInstance(); RESTAPI.BillOfProcessOperator billOfProcessOperatorAPI = RESTAPI.BillOfProcessOperator.getInstance(); RESTAPI.ProcessOperator processOperatorAPI = RESTAPI.ProcessOperator.getInstance(); public ProcessDivide(IHolonixProcessDivideItem view, List<BillOfProcessOutputSummary> bopSummary, Process process, BillOfProcess billOfProcess, Boolean isRepackaging) { util = new Utility(); logic = new ApplicationLogic(); this.view = view; this.bopSummary = bopSummary; this.billOfProcess = billOfProcess; this.process = process; this.isRepackaging = isRepackaging; this.bopOutput = null; this.scaleId = null; this.family = null; this.packaging = null; this.productType = null; } public void setScale() { view.setQuantityLabel(logic.translate("Total qt", "000", VariabiliGlobali.idLanguage)); List<BillOfProcessResourceSummary> resources = billOfProcessResourceAPI.getBillOfProcessResourceSummaries(process.id.Value, billOfProcess.id.Value); ResourceType scaleType = resourceTypeAPI.get("BILANCIA"); if (resources != null) { for (int i = 0; i < resources.Count; i++) { if (resources[i].processResource != null) { for (int j = 0; j < resources[i].processResource.Count; j++) { Int64 idType = resources[i].processResource[j].resourceType.Value; if (idType.Equals(scaleType.id)) { scaleId = resources[i].processResource[j].resource; view.setQuantityLabel(logic.translate("Qt each", "000", VariabiliGlobali.idLanguage)); return; } } } } } } public void defineBopOutputToCreate(BillOfProcessOutput output) { if (output != null) { bopOutput = output; return; } if (output == null) { for (int i = 0; i < bopSummary.Count; i++) {
Page 55
286885 BOMA
55
if (bopSummary[i].billOfProcessOutput != null) { bopOutput = bopSummary[i].billOfProcessOutput; return; } } } } public void setProductControls() { if (bopOutput.physicalProduct != null) family = productFamilyAPI.getByPhysicalProduct(bopOutput.physicalProduct); else if (bopOutput.productType != null) family = productFamilyAPI.getByProductType(bopOutput.productType); else if (bopOutput.productFamily != null) family = productFamilyAPI.get(bopOutput.productFamily); if (family != null) view.setProduct(family.code); SchedaProduzione sheet = productionSheetAPI.get(process.productionSheet.Value); if (sheet != null) view.setBatch(sheet.lotto); if (bopOutput.uom != null) view.setUom(bopOutput.uom); else view.setUom("-"); } public Boolean checkPackage(String packageCode) { if (family == null) { view.alert("Error product family.", "000"); view.resetProductControls(); return false; } if (packageCode.Length < 1) { view.alert("Select packaging type.", "000"); return false; } PackagingType package = packagingTypeAPI.get(packageCode.Trim()); if (package == null) { view.alert("Check packaging type.", "000"); view.setPackaging(""); return false; } if (!isRepackaging) { Boolean find = false; for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].billOfProcessOutput != null) { if (bopSummary[i].billOfProcessOutput.productType != null) { PackagingType packDefined = packagingTypeAPI.getByProductType(bopSummary[i].billOfProcessOutput.productType.Value); if (packDefined.id.Equals(package.id)) { find = true; break; } } } } if (!find) { if (!view.askQuestion("Packaging not required. Continue?", "nh")) { view.setPackaging(""); return false; } }
Page 56
286885 BOMA
56
} TipoProdotto type = productTypeAPI.getByProductFamilyAndPackagingType(family.code, package.code); if (type == null) { if (!view.askQuestion("Tipo prodotto inesistente. Continuare?", "sq")) { view.setPackaging(""); return false; } type = new TipoProdotto(); type.idFamiglia = family.id; type.idConfezione = package.id; type.quantita = package.quantity; type.codice = family.code + "-" + package.code; type.attivo = true; type.nome = family.code + " - " + package.code; type.durata = 10000; if (package.code.Equals("KG")) type.standard = true; else type.standard = false; type.isSovrapponibile = 0; type.abc = AbcClassification.A; type.descrizione = null; type.constraint = null; type.waste = null; type.reorderQuantity = 0; type.idSupplier = null; type.startDate = DateTime.Now; type.endDate = null; type.minStock = 0; type.orderPoint = 0; type.weight = 0; type.itemVolume = 0; type.height = 0; type.length = 0; type.depth = 0; type.isRawMaterial = false; type.idUom = Uom.KG; productTypeAPI.save(ref type); } if (!type.standard.Value) { view.alert("Confezione non standard.", "os"); view.setPackaging(""); return false; } if (!isRepackaging) { if (package.code.Equals("KG")) { if (scaleId == null) { view.alert("For packaging KG, you have to use scale.", "ni"); view.setPackaging(""); return false; } } } packaging = package; productType = type; return true; } public List<KeyValuePair<Tag, Boolean>> checkTags(List<String> tagsRead, List<KeyValuePair<Tag, Boolean>> tagsToAdd) { for (int i = 0; i < tagsToAdd.Count; i++) { if (tagsRead.Contains(tagsToAdd[i].Key.codice)) tagsRead.Remove(tagsToAdd[i].Key.codice); } for (int i = 0; i < tagsRead.Count; i++) {
Page 57
286885 BOMA
57
Tag tag = new Tag(); tag.codice = tagsRead[i]; Boolean isOk = false; if (tagAPI.getByCode(tagsRead[i]) == null) { isOk = true; tag.isUnique = true; tag.attivo = true; tag.tipoTag = TagType.barcode; tag.isProdotto = true; tag.isWarehouse = false; tag.isResource = false; tag.isReusable = false; tag.isProductType = false; } tagsToAdd.Add(new KeyValuePair<Tag, Boolean>(tag, isOk)); } return tagsToAdd; } public Boolean checksAndInsert(String numItem, String qt, List<KeyValuePair<Tag, Boolean>> tags, ProdottoFisico productToDivide) { if (family == null) { view.alert("Error product family.", "000"); return false; } if (packaging == null) { view.alert("Check package.", "000"); view.setPackaging(""); return false; } if (productType == null) { view.alert("Error product type.", "000"); return false; } if (tags.Count < 1) { view.alert("Insert tags code.", "000"); return false; } else { for (int i = 0; i < tags.Count; i++) { if (!tags[i].Value) { view.alert("Check tags code.", "000"); return false; } } } Decimal? quantity = null; Int32? numberOfItems = null; if (qt.Length > 0) { String q = util.getDecimalNumber(qt); view.setQuantity(q); if (!util.controlloValoreDecimale(q)) { view.alert("Check quantity.", "000"); view.setQuantity(""); return false; } quantity = Convert.ToDecimal(q); } if (numItem.Length > 0) { if (!util.controlloValoreIntero(numItem)) { view.alert("Check number of items.", "000");
Page 58
286885 BOMA
58
view.setNumberOfItems(""); return false; } numberOfItems = Convert.ToInt16(numItem); } if (quantity == null && numberOfItems == null) { view.alert("Insert quantities.", "000"); return false; } if (quantity != null) { if (!isRepackaging && scaleId != null) { if (!packaging.code.Equals("KG")) { Decimal packageQuantity = packaging.quantity.Value; Decimal correctQuantity = packageQuantity * tags.Count; Decimal delta = correctQuantity * GlobalConfig.Instance.UnloadTolerance; if (quantity.Value < (correctQuantity - delta) || quantity.Value > (correctQuantity + delta)) { Decimal diff = correctQuantity - quantity.Value; if (diff < 0) { if (view.askQuestion("Hai scaricato {0} KG di troppo. Vuoi annullare?", "ne", Math.Abs(diff).ToString())) return false; } else if (diff > 0) { if (view.askQuestion("Hai scaricato {0} KG in meno. Vuoi annullare?", "nf", Math.Abs(diff).ToString())) return false; } } } quantity = quantity / tags.Count; } } if (numberOfItems != null) { } DateTime date = DateTime.Now; if (isRepackaging) { insertProcessOperator(); if (process.startDate == null) { process.startDate = date; processAPI.save(ref process); } } SchedaProduzione sheet = productionSheetAPI.get(process.productionSheet.Value); Batch batch = batchAPI.getByCodeAndProductType(sheet.lotto, productType.id); if (batch == null) { batch = new Batch(); batch.code = sheet.lotto; batch.productType = productType.id; batchAPI.save(ref batch); } for (int i = 0; i < tags.Count; i++) { Tag tagProduct = tags[i].Key; tagAPI.save(ref tagProduct); ProdottoFisico product = new ProdottoFisico(); product.tipoProdotto = productType.id; product.batch = batch.id; product.attivo = true; product.dataScadenza = date.AddDays(productType.durata.Value); product.isWip = false; product.schedaProduzione = process.productionSheet; product.quantitaEffettiva = quantity;
Page 59
286885 BOMA
59
product.dataStart = date; product.dataEnd = null; product.nome = productType.nome; product.tara = 0; product.quantitaIniziale = quantity; product.cardinalita = 1; product.isPack = false; product.unitLoad = UnitLoad.def; product.unitLoadSize = 1; product.canTakeToInside = true; product.canTakeToOutside = true; product.idUniqueness = PhysicalProductUniqueness.ID_UNIQUE; product.causaleNuovoProdotto = newPhysicalProductReasonApi.get("1").id; product.isStocked = false; product.isPurchased = false; product.isSold = false; product.idEndType = null; product.canGroup = false; product.divisibile = false; product.isHandleQuantity = true; product.isHandleNumberOfItems = false; physicalProductAPI.save(ref product); PhysicalProductTag pptProduct = new PhysicalProductTag(); pptProduct.physicalProduct = product.id.Value; pptProduct.tag = tagProduct.id.Value; pptProduct.fromDate = date; physicalProductTagAPI.save(ref pptProduct); Activity activity = new Activity(); activity.name = "Creazione prodotto fisico"; activity.startDate = date; activity.endDate = date.AddSeconds(1); activity.idActivityType = activityTypeAPI.get("creazione_prodotto_fisico").id; activity.idActivityStatus = ActivityStatus.completed; activity.export = false; activity.isExported = false; activityAPI.save(ref activity); ActivityOperator activityOperator = new ActivityOperator(); activityOperator.idActivity = activity.id.Value; activityOperator.idOperator = VariabiliGlobali.idOperatore; activityOperator.master = true; activityOperatorAPI.save(ref activityOperator); ActivityPhysicalProductObject appo = new ActivityPhysicalProductObject(); appo.idActivity = activity.id.Value; appo.idPhysicalProduct = product.id.Value; appo.numberOfItems = 1; appo.description = ""; activityOperatorPhysicalProductObjectAPI.save(ref appo); WPlaceProdottoFisico wppf = new WPlaceProdottoFisico(); wppf.idPhysicalProduct = product.id.Value; wppf.idWPlace = wplaceApi.get("Post-Produzione").id; wppf.from = date; wppf.to = null; wppf.numberOfItems = 1; wplacePhysicalProductApi.save(ref wppf); BomAsProduced bomAsProduced = new BomAsProduced(); bomAsProduced.physicalProduct = product.id; bomAsProduced.component = productToDivide.id; bomAsProduced.startDate = date; bomAsProduced.endDate = null; bomAsProduced.endNote = null; bomAsProduced.quantity = null; bomAsProduced.numberOfItems = 1; bomAsProduced.process = process.id; bomAsProduced.familyCode = family.code; bomAsProduced.batchCode = sheet.lotto; bomAsProduced.packagingCode = packaging.code; bomAsProducedAPI.save(bomAsProduced); ProcessPhysicalProductOutput output = new ProcessPhysicalProductOutput(); output.process = process.id.Value; output.billOfProcess = billOfProcess.id.Value; output.physicalProduct = product.id.Value; output.date = date;
Page 60
286885 BOMA
60
output.master = false; output.quantity = quantity; output.numberOfItems = numberOfItems; processPhysicalProductOutputAPI.save(output); } return true; } private void insertProcessOperator() { Boolean found = false; List<BillOfProcessOperatorSummary> bopSummary = billOfProcessOperatorAPI.getBillOfProcessOperatorSummaries(process.id.Value, billOfProcess.id.Value); for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].processOperator != null) { for (int j = 0; j < bopSummary[i].processOperator.Count; j++) { if (bopSummary[i].processOperator[j].operatore.Equals(VariabiliGlobali.idOperatore)) { found = true; break; } } if (found) break; } } if (!found) { ProcessOperator p = new ProcessOperator(); p.process = process.id.Value; p.billOfProcess = billOfProcess.id.Value; p.operatore = VariabiliGlobali.idOperatore; p.operatorType = null; p.hours = null; p.date = DateTime.Now; if (process.startDate == null) p.master = true; else p.master = false; processOperatorAPI.save(p); } } } } using System; using System.Linq; using System.Collections.Generic; using System.Text; using holonix.production.mergingAndAssembly; using holonix.datamodel; using holonix.restapi; using holonix.applicationlogic; using holonix.utility; using holonix.datamodel.auxiliary; using System.Globalization; using holonix.config; namespace holonix.controllers { public class ProcessMerge { ApplicationLogic logic; Utility util; RESTAPI.ProdottoFisico physicalProductAPI = RESTAPI.ProdottoFisico.getInstance(); RESTAPI.ProcessPhysicalProductInput processPhysicalProductInputAPI = RESTAPI.ProcessPhysicalProductInput.getInstance(); RESTAPI.Process processAPI = RESTAPI.Process.getInstance(); RESTAPI.WPlaceProdottoFisico wplacePhysicalProductApi = RESTAPI.WPlaceProdottoFisico.getInstance(); RESTAPI.PhysicalProductUniqueness physicalProductUniquenessApi = RESTAPI.PhysicalProductUniqueness.getInstance(); RESTAPI.Uom uomAPI = RESTAPI.Uom.getInstance(); RESTAPI.ProductFamily productFamilyAPI = RESTAPI.ProductFamily.getInstance();
Page 61
286885 BOMA
61
RESTAPI.TipoProdotto productTypeAPI = RESTAPI.TipoProdotto.getInstance(); RESTAPI.PackagingType packagingTypeAPI = RESTAPI.PackagingType.getInstance(); RESTAPI.Tag tagAPI = RESTAPI.Tag.getInstance(); RESTAPI.PhysicalProductTag physicalProductTagAPI = RESTAPI.PhysicalProductTag.getInstance(); RESTAPI.Activity activityAPI = RESTAPI.Activity.getInstance(); RESTAPI.ActivityOperator activityOperatorAPI = RESTAPI.ActivityOperator.getInstance(); RESTAPI.ActivityPhysicalProductObject activityOperatorPhysicalProductObjectAPI = RESTAPI.ActivityPhysicalProductObject.getInstance(); RESTAPI.TipoFineProdotto productEndTypeAPI = RESTAPI.TipoFineProdotto.getInstance(); RESTAPI.ActivityType activityTypeAPI = RESTAPI.ActivityType.getInstance(); RESTAPI.NewPhysicalProductReason newPhysicalProductReasonApi = RESTAPI.NewPhysicalProductReason.getInstance(); RESTAPI.WPlace wplaceApi = RESTAPI.WPlace.getInstance(); RESTAPI.Batch batchAPI = RESTAPI.Batch.getInstance(); RESTAPI.SchedaProduzione productionSheetAPI = RESTAPI.SchedaProduzione.getInstance(); RESTAPI.ProductionSheetStatus productionSheetStatusAPI = RESTAPI.ProductionSheetStatus.getInstance(); RESTAPI.BillOfProcessOperator billOfProcessOperatorAPI = RESTAPI.BillOfProcessOperator.getInstance(); RESTAPI.ProcessOperator processOperatorAPI = RESTAPI.ProcessOperator.getInstance(); IHolonixProcessMergingItem view; Process process; BillOfProcess billOfProcess; ProdottoFisico physicalProduct; List<ProdottoFisico> physicalProductList; BillOfProcessInput bopInputReference; List<BillOfProcessInputSummary> bopSummary; Boolean isRepackaging; public ProcessMerge(IHolonixProcessMergingItem view, Process p, BillOfProcess b, List<BillOfProcessInputSummary> bopSummary, Boolean isRepackaging) { this.view = view; this.process = p; this.billOfProcess = b; this.bopSummary = bopSummary; this.physicalProduct = null; this.physicalProductList = new List<ProdottoFisico>(); this.bopInputReference = null; this.isRepackaging = isRepackaging; this.logic = new ApplicationLogic(); this.util = new Utility(); } public ProdottoFisico getPhysicalProduct() { return this.physicalProduct; } public List<ProdottoFisico> getListPhysicalProducts() { return this.physicalProductList; } public List<ProdottoFisico> getListCheckingTags(List<String> strList) { physicalProductList = new List<ProdottoFisico>(); for (int i = 0; i < strList.Count; i++) { ProdottoFisico prod = checkProductUniqueTag(strList[i]); if (prod == null) return new List<ProdottoFisico>(); else physicalProductList.Add(prod); } for (int i = 0; i < physicalProductList.Count; i++) { if (!physicalProductList[i].batch.Equals(physicalProductList[i].batch)) return new List<ProdottoFisico>(); } return physicalProductList; } public void checkListTags(List<String> strList) { physicalProduct = null; view.resetTagControls(); getListCheckingTags(strList); if (physicalProductList.Count != 0) view.setNumberOfTags(physicalProductList.Count.ToString()); view.resetProductControls();
Page 62
286885 BOMA
62
} public ProdottoFisico checkProductUniqueTag(String tag) { physicalProduct = null; ProdottoFisico prod = null; List<ProdottoFisico> list = physicalProductAPI.getByTag(tag); if (list.Count == 1) { prod = list[0]; } else if (list.Count > 1) { view.alert("Not unique tag.", "000"); view.resetTagControls(); return null; } else if (list.Count == 0) { view.alert("Not found tag.", "000"); view.resetTagControls(); return null; } if (prod.idUniqueness != PhysicalProductUniqueness.ID_UNIQUE) { view.alert("Not unique tag.", "000"); view.resetTagControls(); return null; } if (!prod.attivo.Value) { view.alert("Not active.", "000"); view.resetTagControls(); return null; } if (! isRepackaging) if (!checkIfExistIntoBillOfProcess(prod)) return null; return prod; } public void defineQuantityControls(ProdottoFisico prod) { if (prod.isHandleQuantity) view.enableQuantityControls(); if (prod.isHandleNumberOfItems) view.enableNumberOfItemsControls(); Uom uom = uomAPI.getByPhysicalProductId(prod.id.Value); if (uom != null) view.setUom(logic.translate(uom.label, uom.translation, VariabiliGlobali.idLanguage)); } public void defineListTag() { view.setTag(""); view.resetProductControls(); defineQuantityControls(physicalProductList[0]); } public Boolean defineSingleTag(String tag) { view.resetProductControls(); physicalProduct = null; if (tag.Length < 1) return false; ProdottoFisico prod = checkProductUniqueTag(tag); if (prod == null) return false; else physicalProduct = prod; defineQuantityControls(prod); return true; } public bool checkIfExistIntoBillOfProcess(ProdottoFisico prod) {
Page 63
286885 BOMA
63
if (!checkIntoBillOfProcessInput(prod)) { if (!view.askQuestion("Product not required. Continue?", "000")) { view.resetTagControls(); return false; } } return true; } public bool checkIntoBillOfProcessInput(ProdottoFisico prod) { bool found = false; for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].billOfProcessInput != null && bopSummary[i].billOfProcessInput.physicalProduct != null) if (prod.id.Equals(bopSummary[i].billOfProcessInput.physicalProduct)) { found = true; bopInputReference = bopSummary[i].billOfProcessInput; return found; } } for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].billOfProcessInput != null && bopSummary[i].billOfProcessInput.productType != null) if (prod.tipoProdotto.Equals(bopSummary[i].billOfProcessInput.productType)) { found = true; bopInputReference = bopSummary[i].billOfProcessInput; return found; } } for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].billOfProcessInput != null && bopSummary[i].billOfProcessInput.productFamily != null) if (productFamilyAPI.getByPhysicalProduct(prod.id.Value).id.Equals(bopSummary[i].billOfProcessInput.productFamily)) { found = true; bopInputReference = bopSummary[i].billOfProcessInput; return found; } } return found; } public Boolean addProduct(String familyCode, String batchCode, String packagingCode) { physicalProduct = null; if (familyCode.Length < 1 || batchCode.Length < 1 || packagingCode.Length < 1) return false; PackagingType packaging = null; ProductFamily family = null; TipoProdotto type = null; Batch batchSet = null; packaging = packagingTypeAPI.get(packagingCode.Trim()); if (packaging == null) { view.alert("Check packaging type.", "000"); view.resetProductControls(); return false; } TipoProdotto productType = productTypeAPI.getByProductFamilyAndPackagingType(familyCode.Trim(), packagingCode.Trim()); if (productType != null) { Batch batch = batchAPI.getByCodeAndProductType(batchCode.Trim(), productType.id); if (batch != null) { List<ProdottoFisico> physicalProducts = physicalProductAPI.get(productType.id, batch.id); foreach (ProdottoFisico pp in physicalProducts) { if (tagAPI.getPhysicalProductUniqueTag(pp) != null) {
Page 64
286885 BOMA
64
view.alert("Exist this product into warehouse. Insert tag code.", "000"); view.resetProductControls(); return false; } } } } if (physicalProduct == null) { TipoProdotto KgProductType = productTypeAPI.getByProductFamilyAndPackagingType(familyCode.Trim(), "KG"); if (KgProductType != null) { Batch batch = batchAPI.getByCodeAndProductType(batchCode.Trim(), KgProductType.id); if (batch != null) { type = KgProductType; batchSet = batch; List<ProdottoFisico> KgPhysicalProducts = physicalProductAPI.get(type.id, batch.id); foreach (ProdottoFisico pp in KgPhysicalProducts) { if (tagAPI.getPhysicalProductUniqueTag(pp) == null) { physicalProduct = pp; break; } } if (physicalProduct == null) { view.alert("Prodotto in confezione KG non presente a sistema.", "n1"); view.resetProductControls(); return false; } } } } DateTime date = DateTime.Now; if (physicalProduct != null) { if (!isRepackaging) { if (!checkIfExistIntoBillOfProcess(physicalProduct)) { view.resetProductControls(); return false; } } } else { if (!view.askQuestion("New product. Continue?", "000")) { view.resetProductControls(); return false; } if (!isRepackaging) { if (!checkIfExistIntoBillOfProcessByCode(familyCode.Trim())) { view.resetProductControls(); return false; } } if (type == null) { family = productFamilyAPI.get(familyCode.Trim()); if (family == null) { family = new ProductFamily(); family.name = familyCode.Trim(); family.description = null; family.active = true; family.code = familyCode.Trim();
Page 65
286885 BOMA
65
family.startDate = DateTime.Now; family.endDate = null; family.isRawMaterial = false; family.parent = null; productFamilyAPI.save(ref family); } type = new TipoProdotto(); type.idFamiglia = family.id; type.idConfezione = packaging.id; type.quantita = 0; type.codice = familyCode.Trim() + "-" + packagingCode.Trim(); type.attivo = true; type.nome = familyCode.Trim() + " - " + packagingCode.Trim(); type.durata = 10000; type.standard = false; type.isSovrapponibile = 0; type.abc = AbcClassification.A; type.descrizione = null; type.constraint = null; type.waste = null; type.reorderQuantity = 0; type.idSupplier = null; type.startDate = DateTime.Now; type.endDate = null; type.minStock = 0; type.orderPoint = 0; type.weight = 0; type.itemVolume = 0; type.height = 0; type.length = 0; type.depth = 0; type.isRawMaterial = true; type.idUom = Uom.KG; productTypeAPI.save(ref type); } if (batchSet == null) { batchSet = batchAPI.getByCodeAndProductType(batchCode.Trim(), type.id); if (batchSet == null) { batchSet.code = batchCode.Trim(); batchSet.productType = type.id; batchAPI.save(ref batchSet); } } physicalProduct = new ProdottoFisico(); physicalProduct.tipoProdotto = type.id; physicalProduct.batch = batchSet.id; physicalProduct.attivo = true; physicalProduct.dataScadenza = null; physicalProduct.isWip = false; physicalProduct.schedaProduzione = process.productionSheet; physicalProduct.quantitaEffettiva = null; physicalProduct.dataStart = DateTime.Now; physicalProduct.dataEnd = null; physicalProduct.nome = familyCode.Trim() + " - " + packagingCode.Trim(); physicalProduct.tara = 0; physicalProduct.quantitaIniziale = null; physicalProduct.cardinalita = 0; physicalProduct.isPack = false; physicalProduct.unitLoad = UnitLoad.def; physicalProduct.unitLoadSize = 0; physicalProduct.canTakeToInside = true; physicalProduct.canTakeToOutside = true; physicalProduct.idUniqueness = PhysicalProductUniqueness.ID_BATCH; physicalProduct.causaleNuovoProdotto = newPhysicalProductReasonApi.get("1").id; physicalProduct.isStocked = false; physicalProduct.isPurchased = false; physicalProduct.isSold = false; physicalProduct.idEndType = null; physicalProduct.canGroup = false; physicalProduct.divisibile = false;
Page 66
286885 BOMA
66
physicalProduct.isHandleQuantity = true; physicalProduct.isHandleNumberOfItems = false; physicalProductAPI.save(ref physicalProduct); Activity activity = new Activity(); activity.name = "Creazione prodotto fisico"; activity.startDate = date; activity.endDate = date.AddSeconds(1); activity.idActivityType = activityTypeAPI.get("creazione_prodotto_fisico").id; activity.idActivityStatus = ActivityStatus.completed; activity.export = false; activity.isExported = false; activityAPI.save(ref activity); ActivityOperator activityOperator = new ActivityOperator(); activityOperator.idActivity = activity.id.Value; activityOperator.idOperator = VariabiliGlobali.idOperatore; activityOperator.master = true; activityOperatorAPI.save(ref activityOperator); ActivityPhysicalProductObject appo = new ActivityPhysicalProductObject(); appo.idActivity = activity.id.Value; appo.idPhysicalProduct = physicalProduct.id.Value; appo.numberOfItems = 1; appo.description = ""; activityOperatorPhysicalProductObjectAPI.save(ref appo); WPlaceProdottoFisico wppf = new WPlaceProdottoFisico(); wppf.idPhysicalProduct = physicalProduct.id.Value; wppf.idWPlace = wplaceApi.get("Post-Produzione").id; wppf.from = date; wppf.to = null; wppf.numberOfItems = 1; wplacePhysicalProductApi.save(ref wppf); } defineQuantityControls(physicalProduct); return true; } public bool checkIfExistIntoBillOfProcessByCode(String productCode) { bool found = false; for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].billOfProcessInput != null && bopSummary[i].billOfProcessInput.code != null) if (bopSummary[i].billOfProcessInput.code.Contains(productCode)) { bopInputReference = bopSummary[i].billOfProcessInput; found = true; break; } } if (!found) { if (!view.askQuestion("Product not required. Continue?", "000")) { return false; } } return true; } public Boolean checkIsMaster() { return bopInputReference.master.Value; } public Boolean mergeItem(String numItem, String qt, Boolean isMaster) { Decimal? quantity = null; Int32? numberOfItems = null; if (qt.Length > 0) { String q = util.getDecimalNumber(qt); view.setQuantity(q); if (!util.controlloValoreDecimale(q)) { view.alert("Check quantity.", "000"); view.setQuantity("");
Page 67
286885 BOMA
67
return false; } quantity = Convert.ToDecimal(q); } if (numItem.Length > 0) { if (!util.controlloValoreIntero(numItem)) { view.alert("Check number of items.", "000"); view.setNumberOfItems(""); return false; } numberOfItems = Convert.ToInt32(numItem); } if (!isMaster) if (quantity == null && numberOfItems == null) return false; DateTime date = DateTime.Now; if (numberOfItems != null) { if (!isMaster) { if (physicalProduct.idUniqueness == physicalProductUniquenessApi.Unique.id) { physicalProduct.attivo = false; physicalProductAPI.save(ref physicalProduct); WPlaceProdottoFisico wppp = wplacePhysicalProductApi.getProductLocation(physicalProduct.id); if (wppp != null) { wppp.to = DateTime.Now; wplacePhysicalProductApi.save(ref wppp); } } else { WPlaceProdottoFisico wppp = wplacePhysicalProductApi.get(Prefetch.WPlace.productionWPlace.id, physicalProduct.id); if (physicalProduct.isHandleQuantity) { if (wppp.quantity != null) wppp.quantity -= quantity; else wppp.quantity = -quantity; } if (physicalProduct.isHandleNumberOfItems) { if (wppp.numberOfItems != null) wppp.numberOfItems -= numberOfItems; else wppp.numberOfItems = -numberOfItems; } wplacePhysicalProductApi.save(ref wppp); } } } if (quantity != null) { if (physicalProductList.Count > 0) { Decimal effectiveQuantities = 0; for (int i = 0; i < physicalProductList.Count; i++) effectiveQuantities = effectiveQuantities + physicalProductList[i].quantitaEffettiva.Value; Decimal deltaAbs = effectiveQuantities + (effectiveQuantities * GlobalConfig.Instance.MultiplePackageEliminationTolerance); Decimal deltaSub = effectiveQuantities - (effectiveQuantities * GlobalConfig.Instance.MultiplePackageEliminationTolerance); if ((quantity > deltaAbs) || (quantity < deltaSub)) { view.alert("Peso errato: peso previsto {0}. Inserire i prodotti singolarmente.", "my", effectiveQuantities.ToString()); return false; } if (view.askQuestion("Stai inserendo {0} KG.", "ms", effectiveQuantities.ToString())) { view.alert("Le confezione verranno eliminate!", "mt"); for (int i = 0; i < physicalProductList.Count; i++)
Page 68
286885 BOMA
68
deleteProduct(physicalProductList[i], date); } } else if (physicalProduct != null) { if (!view.askQuestion("You are adding {0} {1}. Continue?", "000", quantity.ToString(), view.getUom())) return false; Boolean isNewProduct = false; if (physicalProduct.quantitaEffettiva == null) { isNewProduct = true; physicalProduct.quantitaIniziale = quantity; physicalProduct.quantitaEffettiva = quantity; } if (quantity > physicalProduct.quantitaEffettiva + GlobalConfig.Instance.WeighingTolerance) if (!view.askQuestion("Are you sure about the quantity?", "mu")) return false; Decimal newQuantity = physicalProduct.quantitaEffettiva.Value - quantity.Value; if (newQuantity < GlobalConfig.Instance.WasteEmptyPackaging) { if (!isNewProduct) if (!view.askQuestion("Empty package. Delete product?", "mv")) return false; deleteProduct(physicalProduct, date); if (newQuantity > 0) defineWaste(physicalProduct, quantity, date); } else { refreshPhysicalProductData(physicalProduct, newQuantity, date); } physicalProductList.Add(physicalProduct); } } if (process.startDate == null) { insertProcessOperator(); process.startDate = date; processAPI.save(ref process); if (isRepackaging) { SchedaProduzione sheet = productionSheetAPI.get(process.productionSheet.Value); sheet.lotto = batchAPI.getByPhysicalProduct(physicalProduct.id).code; sheet.code = "R-" + util.getDateFormat(date) + " " + date.Hour + ":" + date.Minute + " - " + productFamilyAPI.getByPhysicalProduct(physicalProduct.id).code; sheet.idProductionSheetStatus = productionSheetStatusAPI.InProgress.id.Value; productionSheetAPI.save(ref sheet); } } if (physicalProductList.Count > 1) quantity = quantity / physicalProductList.Count; for (int i = 0; i < physicalProductList.Count; i++) { ProcessPhysicalProductInput pppi = getProcessPhysicalProductInputByProductId(physicalProductList[i].id.Value); if (pppi == null) { pppi = new ProcessPhysicalProductInput(); pppi.billOfProcess = billOfProcess.id; pppi.process = process.id; pppi.physicalProduct = physicalProductList[i].id; pppi.master = isMaster; pppi.quantity = quantity; if (isMaster) pppi.quantity = null; pppi.numberOfItems = numberOfItems; if (isMaster) pppi.numberOfItems = 1; pppi.date = date; } else {
Page 69
286885 BOMA
69
if (pppi.quantity != null && quantity != null) pppi.quantity = pppi.quantity + quantity; else pppi.quantity = quantity; } processPhysicalProductInputAPI.save(ref pppi); } return true; } public void refreshPhysicalProductData(ProdottoFisico physicalProduct, Decimal quantity, DateTime date) { physicalProduct.quantitaEffettiva = quantity; physicalProductAPI.save(ref physicalProduct); if (process.wPlace != null) { WPlaceProdottoFisico currentWplace = wplacePhysicalProductApi.getProductLocation(physicalProduct.id.Value); if (currentWplace != null) { currentWplace.to = date; wplacePhysicalProductApi.save(ref currentWplace); WPlaceProdottoFisico newWplace = new WPlaceProdottoFisico(); newWplace.idPhysicalProduct = physicalProduct.id.Value; newWplace.idWPlace = process.wPlace.Value; newWplace.from = date; newWplace.numberOfItems = 1; wplacePhysicalProductApi.save(ref newWplace); } else { WPlaceProdottoFisico newWplace = new WPlaceProdottoFisico(); newWplace.idPhysicalProduct = physicalProduct.id.Value; newWplace.idWPlace = process.wPlace.Value; newWplace.from = date; newWplace.numberOfItems = 1; wplacePhysicalProductApi.save(ref newWplace); } } } public void deleteProduct(ProdottoFisico physicalProduct, DateTime endDate) { physicalProduct.quantitaEffettiva = 0; physicalProduct.dataEnd = endDate; physicalProduct.attivo = false; physicalProduct.idEndType = productEndTypeAPI.get("1").id; physicalProductAPI.save(ref physicalProduct); Activity activity = new Activity(); activity.name = "Eliminazione prodotto fisico"; activity.startDate = endDate.AddSeconds(-1); activity.endDate = endDate; activity.idActivityType = activityTypeAPI.get("Eliminazione_prodotto_fisico").id; activity.idActivityStatus = ActivityStatus.completed; activity.export = false; activityAPI.save(ref activity); ActivityOperator activityOperator = new ActivityOperator(); activityOperator.idActivity = activity.id.Value; activityOperator.idOperator = VariabiliGlobali.idOperatore; activityOperator.master = true; activityOperatorAPI.save(ref activityOperator); ActivityPhysicalProductObject appo = new ActivityPhysicalProductObject(); appo.idActivity = activity.id.Value; appo.idPhysicalProduct = physicalProduct.id.Value; appo.numberOfItems = 1; appo.description = "Produzione"; activityOperatorPhysicalProductObjectAPI.save(ref appo); WPlaceProdottoFisico currentWplace = wplacePhysicalProductApi.getProductLocation(physicalProduct.id.Value); if (currentWplace != null) { currentWplace.to = endDate; wplacePhysicalProductApi.save(ref currentWplace); } else {
Page 70
286885 BOMA
70
WPlace placeTemp = null; if (process.wPlace == null) if (isRepackaging) placeTemp = wplaceApi.get("Riconfezionamento"); else placeTemp = wplaceApi.get("Produzione"); WPlaceProdottoFisico newWplace = new WPlaceProdottoFisico(); newWplace.idPhysicalProduct = physicalProduct.id.Value; if (placeTemp != null) newWplace.idWPlace = placeTemp.id; else newWplace.idWPlace = process.wPlace; newWplace.from = endDate; newWplace.to = endDate; newWplace.numberOfItems = 1; wplacePhysicalProductApi.save(ref newWplace); } } public void defineWaste(ProdottoFisico physicalProduct, Decimal? quantity, DateTime endDate) { String fam = productFamilyAPI.getByPhysicalProduct(physicalProduct.id.Value).code; String lotto = batchAPI.getByPhysicalProduct(physicalProduct.id).code; String conf = packagingTypeAPI.getByPhysicalProduct(physicalProduct.id.Value).code; String dataS = String.Format("{0:dd/MM/yyyy}", endDate); String sqta = quantity.Value.ToString(CultureInfo.CreateSpecificCulture("it-IT")); String causa = productEndTypeAPI.get("9").nome; String desc = fam + ";" + lotto + ";" + causa + ";;;" + sqta + ";" + view.getUom() + ";" + dataS + ";;" + conf + ";;"; Activity activitySfrido = new Activity(); activitySfrido.name = "Sfrido confezione vuota da carico"; activitySfrido.startDate = endDate.AddSeconds(1); activitySfrido.endDate = endDate.AddSeconds(2); activitySfrido.idActivityType = activityTypeAPI.get("sfrido_confezione_vuota").id; ; activitySfrido.idActivityStatus = ActivityStatus.completed; activitySfrido.export = true; activitySfrido.isExported = false; activityAPI.save(ref activitySfrido); ActivityOperator activityOperatorSfrido = new ActivityOperator(); activityOperatorSfrido.idActivity = activitySfrido.id.Value; activityOperatorSfrido.idOperator = VariabiliGlobali.idOperatore; activityOperatorSfrido.master = true; activityOperatorAPI.save(ref activityOperatorSfrido); ActivityPhysicalProductObject appoSfrido = new ActivityPhysicalProductObject(); appoSfrido.idActivity = activitySfrido.id.Value; appoSfrido.idPhysicalProduct = physicalProduct.id.Value; appoSfrido.numberOfItems = 1; appoSfrido.description = desc; activityOperatorPhysicalProductObjectAPI.save(ref appoSfrido); } public ProcessPhysicalProductInput getProcessPhysicalProductInputByProductId(Int64 idPhysicalProduct) { for (int i = 0; i < bopSummary.Count; i++) { for (int j = 0; j < bopSummary[i].processPhysicalProductInput.Count; j++) { ProcessPhysicalProductInput ppi = bopSummary[i].processPhysicalProductInput[j]; if (idPhysicalProduct.Equals(ppi.physicalProduct)) { return ppi; } } } return null; } private void insertProcessOperator() { Boolean found = false; List<BillOfProcessOperatorSummary> bopSummary = billOfProcessOperatorAPI.getBillOfProcessOperatorSummaries(process.id.Value, billOfProcess.id.Value); for (int i = 0; i < bopSummary.Count; i++) { if (bopSummary[i].processOperator != null) {
Page 71
286885 BOMA
71
for (int j = 0; j < bopSummary[i].processOperator.Count; j++) { if (bopSummary[i].processOperator[j].operatore.Equals(VariabiliGlobali.idOperatore)) { found = true; break; } } if (found) break; } } if (!found) { ProcessOperator p = new ProcessOperator(); p.process = process.id.Value; p.billOfProcess = billOfProcess.id.Value; p.operatore = VariabiliGlobali.idOperatore; p.operatorType = null; p.hours = null; p.date = DateTime.Now; if (process.startDate == null) p.master = true; else p.master = false; processOperatorAPI.save(p); } } } } using System; using System.Linq; using System.Collections.Generic; using System.Windows.Forms; using holonix.restapi; using holonix.config; using holonix.boma.config; using OpenNETCF.Threading; namespace holonix.boma { static class Program { [MTAThread] static void Main() { bool firstInstance; NamedMutex mutex = new NamedMutex(false, "Holonix WM6", out firstInstance); if (!firstInstance) { MessageBox.Show("Holonix WM6 is already running."); Application.Exit(); return; } GlobalConfig.Instance.LoadFromDevice(); BOMAConfig.Instance.LoadFromDevice(); RESTAPI.initialize(GlobalConfig.Instance.RESTAPIAddress); Form applicationMenu = new FrmMainMenu(); Application.Run(new FrmInizializzazione(applicationMenu, GlobalConfig.Instance, BOMAConfig.Instance)); GC.KeepAlive(mutex); } } }
Page 72
286885 BOMA
72
4.2. Telediagnostic System Integration Code
4.2.1. Web Services Code
@Path("/boma/sensor") public class SensorREST { private SensorService sensorService = ServiceLocator.getSensorService(); private SensorGatewayService sensorGatewayService = ServiceLocator.getSensorGatewayService(); private DatumTypeService datumTypeService = ServiceLocator.getDatumTypeService(); private UomService uomManager = ServiceLocator.getUomService(); @GET @Path("sensorgateway/code/{code}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public List<SensorBOMA> getByProductTagCode(@PathParam("code") String code) { SensorGateway sensorGateway = sensorGatewayService.get(code); if (sensorGateway == null) throw new NotFoundException("No SensorGateway found with the specified code"); Search search = new Search(Sensor.class); search.addFilter(HxFilter.equal(code, Sensor._sensorGateway, PhysicalProductSensorGateway._physicalProduct, PhysicalProduct._physicalProductTags, PhysicalProductTag._tag, Tag._code)); List<Sensor> temps = sensorService.get(search); if (temps.size() == 0) throw new NotFoundException("No Sensor found attached to the specified SensorGateway"); List<SensorBOMA> result = new ArrayList<SensorBOMA>(temps.size()); for (int i = 0; i < temps.size(); i++) { Sensor sensor = temps.get(i); SensorBOMA sensorBoma = new SensorBOMA(); sensorBoma.setActive(sensor.isActive()); sensorBoma.setCode(sensor.getCode()); sensorBoma.setDescription(sensor.getDescription()); DatumType datumType = datumTypeService.get(sensor.getDatumType().getId()); sensorBoma.setMeasurand(datumType.getCode()); Uom uom = null; if (datumType.getUom() != null) { uom = uomManager.get(datumType.getUom().getId()); sensorBoma.setUom(uom.getCode()); } result.add(sensorBoma); } return result; } @GET @Path("/sensorgateway/code/{sensorGatewayCode}/sensor/code/{sensorCode}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public SensorBOMA getByCode(@PathParam("sensorGatewayCode") String sensorGatewayCode, @PathParam("sensorCode") String sensorCode) { Sensor sensor = sensorService.get(sensorGatewayCode, sensorCode); if (sensor == null) throw new NotFoundException(); SensorBOMA sensorBoma = new SensorBOMA(); sensorBoma.setActive(true); sensorBoma.setCode(sensor.getCode()); sensorBoma.setDescription(sensor.getDescription()); DatumType datumType = datumTypeService.get(sensor.getDatumType().getId()); sensorBoma.setMeasurand(datumType.getCode()); Uom uom = null; if (datumType.getUom() != null) { uom = uomManager.get(datumType.getUom().getId()); sensorBoma.setUom(uom.getCode()); } return sensorBoma; } @POST @Path("sensorgateway/code/{code}") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public SensorBOMA insert(@PathParam("code") String code, SensorBOMA sensorBoma) {
Page 73
286885 BOMA
73
SensorGateway sensorGateway = sensorGatewayService.get(code); if (sensorGateway == null) throw new NotFoundException("No SensorGateway found with specified code"); Sensor sensor = sensorService.get(code, sensorBoma.getCode()); if (sensor != null) throw new ConflictException("Sensor already exists with specified code in the specified SensorGateway"); Uom uom = null; if (sensorBoma.getUom() != null ) { if (!sensorBoma.getUom().equals("")) { uom = uomManager.get(sensorBoma.getUom()); if (uom == null) { uom = new Uom(); uom.setCode(sensorBoma.getUom()); uom.setLabel(sensorBoma.getUom()); uomManager.insert(uom); } } } DatumType datumType = datumTypeService.get(sensorBoma.getMeasurand()); if (datumType == null) { datumType = new DatumType(); datumType.setCode(sensorBoma.getMeasurand()); datumType.setLabel(sensorBoma.getMeasurand()); datumType.setUom(uom); datumTypeService.insert(datumType); } sensor = new Sensor(); sensor.setSensorGateway(sensorGateway); sensor.setCode(sensorBoma.getCode()); sensor.setActive(sensorBoma.isActive()); sensor.setDatumType(datumType); sensor.setDescription(sensorBoma.getDescription()); sensor.setName(sensorBoma.getCode()); sensor.setPrivate_(false); sensorService.insert(sensor); return sensorBoma; } @PUT @Path("sensorgateway/code/{code}") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public SensorBOMA update(@PathParam("code") String code, SensorBOMA sensorBoma) { SensorGateway sensorGateway = sensorGatewayService.get(code); if (sensorGateway == null) throw new NotFoundException("No SensorGateway found with specified code"); Sensor sensor = sensorService.get(code, sensorBoma.getCode()); if (sensor == null) throw new NotFoundException("No Sensor found with specified code in the specified SensorGateway"); Uom uom = null; if (sensorBoma.getUom() != null ) { if (!sensorBoma.getUom().equals("")) { uom = uomManager.get(sensorBoma.getUom()); if (uom == null) { uom = new Uom(); uom.setCode(sensorBoma.getUom()); uom.setLabel(sensorBoma.getUom()); uomManager.insert(uom); } } } DatumType datumType = datumTypeService.get(sensorBoma.getMeasurand()); if (datumType == null) { datumType = new DatumType(); datumType.setCode(sensorBoma.getMeasurand()); datumType.setLabel(sensorBoma.getMeasurand()); datumType.setUom(uom); datumTypeService.insert(datumType); } sensor.setActive(sensorBoma.isActive()); sensor.setDatumType(datumType); sensor.setDescription(sensorBoma.getDescription()); sensor.setName(sensorBoma.getCode());
Page 74
286885 BOMA
74
sensor.setPrivate_(false); sensorService.insert(sensor); return sensorBoma; } @DELETE @Path("sensorgateway/code/{code}") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public SensorBOMA delete(@PathParam("code") String code, SensorBOMA sensorBoma) { SensorGateway sensorGateway = sensorGatewayService.get(code); if (sensorGateway == null) throw new NotFoundException("No SensorGateway found with specified code"); Sensor sensor = sensorService.get(code, sensorBoma.getCode()); if (sensor == null) throw new NotFoundException("No Sensor found with specified code in the specified SensorGateway"); sensor.setActive(false); sensorService.insert(sensor); sensorBoma.setActive(false); return sensorBoma; } } @Path("/boma/sensorgateway") public class SensorGatewayREST { SensorGatewayService sensorGatewayService = ServiceLocator.getSensorGatewayService(); DatumTypeService datumTypeService = ServiceLocator.getDatumTypeService(); UomService uomManager = ServiceLocator.getUomService(); PhysicalProductSensorGatewayService physicalProductSensorService = ServiceLocator.getPhysicalProductSensorService(); PhysicalProductService prodottoFisicoManager = ServiceLocator.getPhysicalProductService(); @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public List<SensorGatewayBOMA> get() { List<SensorGateway> sensorGateways = sensorGatewayService.get(); if (sensorGateways.size() == 0) throw new NotFoundException(); List<SensorGatewayBOMA> result = new ArrayList<SensorGatewayBOMA>(sensorGateways.size()); for (int i = 0; i < sensorGateways.size(); i++) { SensorGateway sensorGateway = sensorGateways.get(i); SensorGatewayBOMA sensorGatewayBoma = new SensorGatewayBOMA(); sensorGatewayBoma.setActive(sensorGateway.isActive()); sensorGatewayBoma.setCode(sensorGateway.getCode()); sensorGatewayBoma.setDescription(sensorGateway.getDescription()); result.add(sensorGatewayBoma); } return result; } @GET @Path("code/{code}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public SensorGatewayBOMA getByCode(@PathParam("code") String code) { SensorGateway sensorGateway = sensorGatewayService.get(code); if (sensorGateway == null) throw new NotFoundException(); SensorGatewayBOMA sensorGatewayBoma = new SensorGatewayBOMA(); sensorGatewayBoma.setActive(sensorGateway.isActive()); sensorGatewayBoma.setCode(sensorGateway.getCode()); sensorGatewayBoma.setDescription(sensorGateway.getDescription()); return sensorGatewayBoma; } @GET @Path("physicalproduct/tag/code/{tag}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public List<SensorGatewayBOMA> getByProductTagCode(@PathParam("tag") String tag) { PhysicalProduct physicalProduct; Search searchPhysicalProduct = new Search(PhysicalProduct.class); searchPhysicalProduct.setDistinct(true); searchPhysicalProduct.addFilter(HxFilter.equal(true, PhysicalProduct._physicalProductTags, PhysicalProductTag._tag, Tag._isUniqueId)); searchPhysicalProduct.addFilter(HxFilter.equal(tag, PhysicalProduct._physicalProductTags, PhysicalProductTag._tag, Tag._code)); List<PhysicalProduct> physicalProductList = prodottoFisicoManager.getProdottoFisicoBySearch(searchPhysicalProduct); if (physicalProductList.size() == 0) {
Page 75
286885 BOMA
75
throw new NotFoundException("No PhysicalProduct found with specified tag"); } else if (physicalProductList.size() == 1) { physicalProduct = physicalProductList.get(0); } else { throw new BadRequestException("Non unique Tag specified"); } Search search = new Search(SensorGateway.class); search.addFilter(HxFilter.equal(physicalProduct, SensorGateway._physicalProductSensorGateways, PhysicalProductSensorGateway._physicalProduct)); List<SensorGateway> sensorGateways = sensorGatewayService.get(search); if (sensorGateways.size() == 0) throw new NotFoundException("No SensorGateway found attached to the specified PhysicalProduct"); List<SensorGatewayBOMA> result = new ArrayList<SensorGatewayBOMA>(sensorGateways.size()); for (int i = 0; i < sensorGateways.size(); i++) { SensorGateway sensorGateway = sensorGateways.get(i); SensorGatewayBOMA sensorGatewayBOMA = new SensorGatewayBOMA(); sensorGatewayBOMA.setActive(sensorGateway.isActive()); sensorGatewayBOMA.setCode(sensorGateway.getCode()); sensorGatewayBOMA.setDescription(sensorGateway.getDescription()); result.add(sensorGatewayBOMA); } return result; } @POST @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public SensorGatewayBOMA insert(SensorGatewayBOMA sensorGatewayBoma) { SensorGateway sensorGateway = sensorGatewayService.get(sensorGatewayBoma.getCode()); if (sensorGateway != null) throw new ConflictException("SensorGateway already exists with specified code"); sensorGateway = new SensorGateway(); sensorGateway.setCode(sensorGatewayBoma.getCode()); sensorGateway.setActive(sensorGatewayBoma.isActive()); sensorGateway.setDescription(sensorGatewayBoma.getDescription()); sensorGateway.setName(sensorGatewayBoma.getCode()); sensorGatewayService.insert(sensorGateway); return sensorGatewayBoma; } @POST @Path("physicalproduct/tag/code/{tag}") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public SensorGatewayBOMA insert(@PathParam("tag") String tag, SensorGatewayBOMA sensorGatewayBoma) { Date now = new Date(); SensorGateway sensorGateway = sensorGatewayService.get(sensorGatewayBoma.getCode()); if (sensorGateway != null) throw new ConflictException("SensorGateway already exists with specified code"); sensorGateway = new SensorGateway(); sensorGateway.setCode(sensorGatewayBoma.getCode()); sensorGateway.setActive(sensorGatewayBoma.isActive()); sensorGateway.setDescription(sensorGatewayBoma.getDescription()); sensorGateway.setName(sensorGatewayBoma.getCode()); PhysicalProduct physicalProduct; Search searchPhysicalProduct = new Search(PhysicalProduct.class); searchPhysicalProduct.setDistinct(true); searchPhysicalProduct.addFilter(HxFilter.equal(true, PhysicalProduct._physicalProductTags, PhysicalProductTag._tag, Tag._isUniqueId)); searchPhysicalProduct.addFilter(HxFilter.equal(tag, PhysicalProduct._physicalProductTags, PhysicalProductTag._tag, Tag._code)); List<PhysicalProduct> physicalProductList = prodottoFisicoManager.getProdottoFisicoBySearch(searchPhysicalProduct); if (physicalProductList.size() == 0) { throw new NotFoundException("No PhysicalProduct found with specified tag"); } else if (physicalProductList.size() == 1) { physicalProduct = physicalProductList.get(0); } else { throw new BadRequestException("Non unique Tag specified"); } PhysicalProductSensorGateway physicalProductSensorGateway = new PhysicalProductSensorGateway();
Page 76
286885 BOMA
76
physicalProductSensorGateway.setFromDate(now); physicalProductSensorGateway.setPhysicalProduct(physicalProduct); physicalProductSensorGateway.setSensorGateway(sensorGateway); physicalProductSensorGateway.setInherited(false); sensorGatewayService.insert(sensorGateway); physicalProductSensorService.insert(physicalProductSensorGateway); return sensorGatewayBoma; } @PUT @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public SensorGatewayBOMA update(SensorGatewayBOMA sensorGatewayBoma) { SensorGateway sensorGateway = sensorGatewayService.get(sensorGatewayBoma.getCode()); if (sensorGateway == null) throw new NotFoundException("No SensorGateway found with the specified code"); sensorGateway.setActive(sensorGatewayBoma.isActive()); sensorGateway.setDescription(sensorGatewayBoma.getDescription()); sensorGateway.setName(sensorGatewayBoma.getCode()); sensorGatewayService.insert(sensorGateway); return sensorGatewayBoma; } @PUT @Path("physicalproduct/tag/code/{tag}") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public SensorGatewayBOMA update(@PathParam("tag") String tag, SensorGatewayBOMA sensorGatewayBoma) { Date now = new Date(); SensorGateway sensorGateway = sensorGatewayService.get(sensorGatewayBoma.getCode()); if (sensorGateway == null) throw new NotFoundException("No SensorGateway found with the specified code"); PhysicalProduct physicalProduct; Search searchPhysicalProduct = new Search(PhysicalProduct.class); searchPhysicalProduct.setDistinct(true); searchPhysicalProduct.addFilter(HxFilter.equal(true, PhysicalProduct._physicalProductTags, PhysicalProductTag._tag, Tag._isUniqueId)); searchPhysicalProduct.addFilter(HxFilter.equal(tag, PhysicalProduct._physicalProductTags, PhysicalProductTag._tag, Tag._code)); List<PhysicalProduct> physicalProductList = prodottoFisicoManager.getProdottoFisicoBySearch(searchPhysicalProduct); if (physicalProductList.size() == 0) { throw new NotFoundException("No PhysicalProduct found with specified tag"); } else if (physicalProductList.size() == 1) { physicalProduct = physicalProductList.get(0); } else { throw new BadRequestException("Non unique Tag specified"); } PhysicalProductSensorGateway physicalProductSensorGateway; Search productSensorGatewaySearch = new Search(PhysicalProductSensorGateway.class); productSensorGatewaySearch.setDistinct(true); productSensorGatewaySearch.addFilter(HxFilter.equal(sensorGateway.getId(), PhysicalProductSensorGateway._sensorGateway, SensorGateway._id)); productSensorGatewaySearch.addFilter(HxFilter.equal(physicalProduct, PhysicalProductSensorGateway._physicalProduct)); List<PhysicalProductSensorGateway> physicalProductSensorList = physicalProductSensorService.get(productSensorGatewaySearch); if (physicalProductSensorList.size() == 0) { physicalProductSensorGateway = new PhysicalProductSensorGateway(); physicalProductSensorGateway.setFromDate(now); physicalProductSensorGateway.setPhysicalProduct(physicalProduct); physicalProductSensorGateway.setSensorGateway(sensorGateway); physicalProductSensorGateway.setInherited(false); } else if (physicalProductSensorList.size() == 1) { physicalProductSensorGateway = physicalProductSensorList.get(0); } else { throw new InternalServerErrorException("Non unique association between SensorGateway and PhysicalProduct"); } sensorGatewayService.insert(sensorGateway); physicalProductSensorService.insert(physicalProductSensorGateway); return sensorGatewayBoma;
Page 77
286885 BOMA
77
} @DELETE @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public SensorGatewayBOMA delete(SensorGatewayBOMA sensorGatewayBOMA) { SensorGateway sensorGateway = sensorGatewayService.get(sensorGatewayBOMA.getCode()); if (sensorGateway == null) throw new NotFoundException("No SensorGateway found with the specified code"); Date now = new Date(); Search sgppS = new Search(PhysicalProductSensorGateway.class); sgppS.addFilter(HxFilter.equal(sensorGateway, PhysicalProductSensorGateway._sensorGateway)); sgppS.addFilter(HxFilter.isNull(PhysicalProductSensorGateway._toDate)); List<PhysicalProductSensorGateway> sgppL = physicalProductSensorService.get(sgppS); for (int i = 0; i < sgppL.size(); i++) { PhysicalProductSensorGateway physicalProductSensorGateway = sgppL.get(i); physicalProductSensorGateway.setToDate(now); physicalProductSensorService.insert(physicalProductSensorGateway); } sensorGateway.setActive(false); sensorGatewayService.insert(sensorGateway); sensorGatewayBOMA.setActive(false); return sensorGatewayBOMA; } @DELETE @Path("physicalproduct/tag/code/{tag}") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public SensorGatewayBOMA deleteAssociation(@PathParam("tag") String tag, SensorGatewayBOMA sensorGatewayBOMA) { SensorGateway sensorGateway = sensorGatewayService.get(sensorGatewayBOMA.getCode()); if (sensorGateway == null) throw new NotFoundException("No SensorGateway found with the specified code"); PhysicalProduct physicalProduct; Search searchPhysicalProduct = new Search(PhysicalProduct.class); searchPhysicalProduct.setDistinct(true); searchPhysicalProduct.addFilter(HxFilter.equal(true, PhysicalProduct._physicalProductTags, PhysicalProductTag._tag, Tag._isUniqueId)); searchPhysicalProduct.addFilter(HxFilter.equal(tag, PhysicalProduct._physicalProductTags, PhysicalProductTag._tag, Tag._code)); List<PhysicalProduct> physicalProductList = prodottoFisicoManager.getProdottoFisicoBySearch(searchPhysicalProduct); if (physicalProductList.size() == 0) { throw new NotFoundException("No PhysicalProduct found with specified tag"); } else if (physicalProductList.size() == 1) { physicalProduct = physicalProductList.get(0); } else { throw new BadRequestException("Non unique Tag specified"); } Date now = new Date(); Search sgppS = new Search(PhysicalProductSensorGateway.class); sgppS.addFilter(HxFilter.equal(sensorGateway, PhysicalProductSensorGateway._sensorGateway)); sgppS.addFilter(HxFilter.equal(physicalProduct, PhysicalProductSensorGateway._physicalProduct)); sgppS.addFilter(HxFilter.isNull(PhysicalProductSensorGateway._toDate)); List<PhysicalProductSensorGateway> sgppL = physicalProductSensorService.get(sgppS); for (int i = 0; i < sgppL.size(); i++) { PhysicalProductSensorGateway physicalProductSensorGateway = sgppL.get(i); physicalProductSensorGateway.setToDate(now); physicalProductSensorService.insert(physicalProductSensorGateway); } return sensorGatewayBOMA; } } @XmlRootElement(name="sensor", namespace="holonix") @XmlType(name="sensor", namespace="holonix") public class SensorGatewayBOMA { private String code; private String description; private boolean active; @XmlElement(required = true) public String getCode() { return code;
Page 78
286885 BOMA
78
} public void setCode(String code) { this.code = code; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } @XmlElement(required = true) public boolean isActive() { return active; } public void setActive(boolean active) { this.active = active; } } @Path("/boma/sensordata") public class SensorDataREST { private SensorGatewayService sensorGatewayService = ServiceLocator.getSensorGatewayService(); private SensorDataTimeDecimalService sensorDataTimeDecimalService = ServiceLocator.getSensorDataService(); private SensorService sensorService = ServiceLocator.getSensorService(); @GET @Path("sensorgateway/code/{sensorGatewayCode}/sensor/code/{sensorCode}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public List<SensorDataBOMA> get(@PathParam("sensorGatewayCode") String sensorGatewayCode, @PathParam("sensorCode") String sensorCode) { SensorGateway sensorGateway = sensorGatewayService.get(sensorGatewayCode); if (sensorGateway == null) throw new NotFoundException("No SensorGateway found with specified code"); Sensor sensor = sensorService.get(sensorGatewayCode, sensorCode); if (sensor == null) throw new NotFoundException("No Sensor found with specified code in the specified SensorGateway"); Search search = new Search(SensorDataTimeDecimal.class); search.addFilter(HxFilter.equal(sensorGatewayCode, SensorDataTimeDecimal._sensor, Sensor._sensorGateway, SensorGateway._code)); search.addFilter(HxFilter.equal(sensorCode, SensorDataTimeDecimal._sensor, Sensor._code)); List<SensorDataTimeDecimal> sensorDatas = sensorDataTimeDecimalService.get(search); if (sensorDatas.size() == 0) throw new NotFoundException("No SensorData found fof the specified Sensor attached to the specified SensorGateway"); List<SensorDataBOMA> result = new ArrayList<SensorDataBOMA>(sensorDatas.size()); for (int i = 0; i < sensorDatas.size(); i++) { SensorDataTimeDecimal sensorDataTimeDecimal = sensorDatas.get(i); SensorDataBOMA sensorDataBOMA = new SensorDataBOMA(); sensorDataBOMA.setTimestamp(sensorDataTimeDecimal.getDate()); sensorDataBOMA.setValue(sensorDataTimeDecimal.getValue()); result.add(sensorDataBOMA); } return result; } @POST @Path("sensorgateway/code/{sensorGatewayCode}/sensor/code/{sensorCode}") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public SensorDataConfirmationBOMA insert(@PathParam("sensorGatewayCode") String sensorGatewayCode, @PathParam("sensorCode") String sensorCode, SensorDataBOMA sensorDataBOMA) { SensorGateway sensorGateway = sensorGatewayService.get(sensorGatewayCode); if (sensorGateway == null) throw new NotFoundException("No SensorGateway found with specified code"); Sensor sensor = sensorService.get(sensorGatewayCode, sensorCode); if (sensor == null) throw new NotFoundException("No Sensor found with specified code in the specified SensorGateway"); SensorDataTimeDecimal sensorDataTimeDecimal = new SensorDataTimeDecimal(); sensorDataTimeDecimal.setSensor(sensor); sensorDataTimeDecimal.setDate(sensorDataBOMA.getTimestamp()); sensorDataTimeDecimal.setValue(sensorDataBOMA.getValue()); sensorDataTimeDecimalService.insert(sensorDataTimeDecimal); return new SensorDataConfirmationBOMA(sensorGatewayCode, sensorCode, sensorDataBOMA.getTimestamp());
Page 79
286885 BOMA
79
} @PUT @Path("sensorgateway/code/{sensorGatewayCode}/sensor/code/{sensorCode}") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public SensorDataConfirmationBOMA safeInsert(@PathParam("sensorGatewayCode") String sensorGatewayCode, @PathParam("sensorCode") String sensorCode, SensorDataBOMA sensorDataBOMA) { SensorGateway sensorGateway = sensorGatewayService.get(sensorGatewayCode); if (sensorGateway == null) throw new NotFoundException("No SensorGateway found with specified code"); Sensor sensor = sensorService.get(sensorGatewayCode, sensorCode); if (sensor == null) throw new NotFoundException("No Sensor found with specified code in the specified SensorGateway"); Search search = new Search(SensorDataTimeDecimal.class); search.addFilter(HxFilter.equal(sensor, SensorDataTimeDecimal._sensor)); search.addFilter(HxFilter.equal(sensorDataBOMA.getTimestamp(), SensorDataTimeDecimal._date)); List<SensorDataTimeDecimal> list = sensorDataTimeDecimalService.get(search); SensorDataTimeDecimal sensorDataTimeDecimal; if (list.size() == 0) { sensorDataTimeDecimal = new SensorDataTimeDecimal(); sensorDataTimeDecimal.setSensor(sensor); sensorDataTimeDecimal.setDate(sensorDataBOMA.getTimestamp()); } else { sensorDataTimeDecimal = list.get(0); } sensorDataTimeDecimal.setValue(sensorDataBOMA.getValue()); sensorDataTimeDecimalService.insert(sensorDataTimeDecimal); return new SensorDataConfirmationBOMA(sensorGatewayCode, sensorCode, sensorDataBOMA.getTimestamp()); } @POST @Path("sensorgateway/code/{sensorGatewayCode}/sensor/code/{sensorCode}/multi") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public SensorDataConfirmationBOMA insert(@PathParam("sensorGatewayCode") String sensorGatewayCode, @PathParam("sensorCode") String sensorCode, List<SensorDataBOMA> sensorDataBOMA) { SensorGateway sensorGateway = sensorGatewayService.get(sensorGatewayCode); if (sensorGateway == null) throw new NotFoundException("No SensorGateway found with specified code"); Sensor sensor = sensorService.get(sensorGatewayCode, sensorCode); if (sensor == null) throw new NotFoundException("No Sensor found with specified code in the specified SensorGateway"); Collections.sort(sensorDataBOMA); for (int i = 0; i < sensorDataBOMA.size(); i++) { SensorDataBOMA data = sensorDataBOMA.get(i); SensorDataTimeDecimal sensorDataTimeDecimal = new SensorDataTimeDecimal(); sensorDataTimeDecimal.setSensor(sensor); sensorDataTimeDecimal.setDate(data.getTimestamp()); sensorDataTimeDecimal.setValue(data.getValue()); sensorDataTimeDecimalService.insert(sensorDataTimeDecimal); } int count = sensorDataBOMA.size(); Date oldestTimestamp = sensorDataBOMA.get(0).getTimestamp(); Date newestTimestamp = sensorDataBOMA.get(sensorDataBOMA.size() - 1).getTimestamp(); return new SensorDataConfirmationBOMA(sensorGatewayCode, sensorCode, count, oldestTimestamp, newestTimestamp); } @PUT @Path("sensorgateway/code/{sensorGatewayCode}/sensor/code/{sensorCode}/multi") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public SensorDataConfirmationBOMA safeInsert(@PathParam("sensorGatewayCode") String sensorGatewayCode, @PathParam("sensorCode") String sensorCode, List<SensorDataBOMA> sensorDataBOMA) { SensorGateway sensorGateway = sensorGatewayService.get(sensorGatewayCode); if (sensorGateway == null) throw new NotFoundException("No SensorGateway found with specified code"); Sensor sensor = sensorService.get(sensorGatewayCode, sensorCode); if (sensor == null) throw new NotFoundException("No Sensor found with specified code in the specified SensorGateway"); Collections.sort(sensorDataBOMA); for (int i = 0; i < sensorDataBOMA.size(); i++) { SensorDataBOMA data = sensorDataBOMA.get(i); Search search = new Search(SensorDataTimeDecimal.class);
Page 80
286885 BOMA
80
search.addFilter(HxFilter.equal(sensor, SensorDataTimeDecimal._sensor)); search.addFilter(HxFilter.equal(data.getTimestamp(), SensorDataTimeDecimal._date)); List<SensorDataTimeDecimal> list = sensorDataTimeDecimalService.get(search); SensorDataTimeDecimal sensorDataTimeDecimal; if (list.size() == 0) { sensorDataTimeDecimal = new SensorDataTimeDecimal(); sensorDataTimeDecimal.setSensor(sensor); sensorDataTimeDecimal.setDate(data.getTimestamp()); } else { sensorDataTimeDecimal = list.get(0); } sensorDataTimeDecimal.setValue(data.getValue()); sensorDataTimeDecimalService.insert(sensorDataTimeDecimal); } int count = sensorDataBOMA.size(); Date oldestTimestamp = sensorDataBOMA.get(0).getTimestamp(); Date newestTimestamp = sensorDataBOMA.get(sensorDataBOMA.size() - 1).getTimestamp(); return new SensorDataConfirmationBOMA(sensorGatewayCode, sensorCode, count, oldestTimestamp, newestTimestamp); } } @XmlRootElement public class SensorDataConfirmationBOMA { private String sensorGatewayCode; private String sensorCode; private int dataCount; private Date oldestTimestamp; private Date newestTimestamp; public SensorDataConfirmationBOMA() { super(); } public SensorDataConfirmationBOMA(String sensorGatewayCode, String sensorCode, Date timestamp) { this.sensorGatewayCode = sensorGatewayCode; this.sensorCode = sensorCode; this.dataCount = 1; this.oldestTimestamp = timestamp; this.newestTimestamp = timestamp; } public SensorDataConfirmationBOMA(String sensorGatewayCode, String sensorCode, int dataCount, Date oldestTimestamp, Date newestTimestamp) { this.sensorGatewayCode = sensorGatewayCode; this.sensorCode = sensorCode; this.dataCount = dataCount; this.oldestTimestamp = oldestTimestamp; this.newestTimestamp = newestTimestamp; } public String getSensorGatewayCode() { return sensorGatewayCode; } public void setSensorGatewayCode(String sensorGatewayCode) { this.sensorGatewayCode = sensorGatewayCode; } public String getSensorCode() { return sensorCode; } public void setSensorCode(String sensorCode) { this.sensorCode = sensorCode; } public int getDataCount() { return dataCount; } public void setDataCount(int dataCount) { this.dataCount = dataCount; } public Date getOldestTimestamp() { return oldestTimestamp; } public void setOldestTimestamp(Date oldestTimestamp) { this.oldestTimestamp = oldestTimestamp; } public Date getNewestTimestamp() {
Page 81
286885 BOMA
81
return newestTimestamp; } public void setNewestTimestamp(Date newestTimestamp) { this.newestTimestamp = newestTimestamp; } } @XmlRootElement(name="sensordata", namespace="holonix") @XmlType(name="sensordata", namespace="holonix") public class SensorDataBOMA implements Comparable<SensorDataBOMA> { private Date timestamp; private BigDecimal value; @XmlElement(required = true) public Date getTimestamp() { return timestamp; } public void setTimestamp(Date timestamp) { this.timestamp = timestamp; } @XmlElement(required = true) public BigDecimal getValue() { return value; } public void setValue(BigDecimal value) { this.value = value; } @Override public int compareTo(SensorDataBOMA o) { return timestamp.compareTo(o.timestamp); } } @XmlRootElement(name="sensor", namespace="holonix") @XmlType(name="sensor", namespace="holonix") public class SensorBOMA { private String code; private String description; private String measurand; private String uom; private boolean active; @XmlElement(required = true) public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } @XmlElement(required = true) public String getMeasurand() { return measurand; } public void setMeasurand(String measurand) { this.measurand = measurand; } public String getUom() { return uom; } public void setUom(String uom) { this.uom = uom; } @XmlElement(required = true) public boolean isActive() { return active; } public void setActive(boolean active) { this.active = active;}}
Page 82
286885 BOMA
82
5. Conclusion
This deliverable aims to show how the already existent extended product lifecycle management suite i-
Like has been customized for its adoption in the marine industry by different kind of users as well as
enriched with specific capabilities that fit and satisfy several technical requirements (as reported in the
deliverable D1.2).
In particular in this deliverable has been presented the description and the java code of the Device
Controller and PEID Integration, required in order to enable BOMA system to interact with telediagnostic
system installed on the boats and those devices which will enable the use of RFiD-Barcode systems into
production. These modules of the BOMA infrastructure allow:
- the identification and association of the telediagnostic system installed on each physical boat,
reading the list of sensors connected and finally extract and import data, selecting the data type
and the sampling frequency
- the use of industrial devices such as PDA that enable the adoption of RFiD and barcode into
production in order to trace the boat’s components and spare parts, personnel working hours and
production resources usage.