internal void OnBarcodeScanned(object sender, BarcodeEventArgs e) { BarcodeForm bcInstance = BarcodeForm.GetInstance(); bcInstance.lbScannedBarcodes.Items.Add(e.Barcode); bcInstance.tbScannedBarcode.Text = ""; Task.Factory.StartNew(() => LookupBarcode(e.Barcode)); }
// No need for locking - you'll be doing all this on the UI thread... public static BarcodeForm GetInstance() { if (bcForm == null) { bcForm = new BarcodeForm(); bcForm.FormClosed += delegate { bcForm = null; }; } return(bcForm); }
private void SetText(string text) { if (BarcodeForm.GetInstance().lbDecodedBarcode.InvokeRequired) { SetTextCallback d = new SetTextCallback(SetText); BarcodeForm.GetInstance().Invoke(d, new object[] { text }); } else { BarcodeForm.GetInstance().lbDecodedBarcode.Items.Add(text); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Application.Run(new Start()); BarcodeForm bcScanner = BarcodeForm.GetInstance(); // Publisher BarcodeScannedEvents eventHelper = new BarcodeScannedEvents(); // Subscriber bcScanner.BarcodeScanned += eventHelper.OnBarcodeScanned; bcScanner.ProcessScannedCodes += eventHelper.OnProcessScannedCodes; bcScanner.ProcessStock += eventHelper.OnProcessStock; bcScanner.ShowDialog(); //TestManyToMany t = new TestManyToMany(); //t.ShowDialog(); }
internal void OnProcessScannedCodes(object sender, BarcodeProcessEventArgs e) { ScanObject scannedObject = null; List <ScanObject> scannedObjects = null; try { foreach (var item in BarcodeForm.GetInstance().lbScannedBarcodes.Items) { string barcode = (string)item; string switch_on = barcode.Substring(0, 1); switch (switch_on) { case "A": // Assembly scanned switch (e.type) { case BarcodeProcessType.DISPATCH: if (!InternalNoteStartScan) { throw new System.InvalidOperationException("Missed scan of delivery/galvanising note!"); } if (scannedObject.ScannedObjects == null) { scannedObject.ScannedObjects = new List <ScanObjectItem>(); } if (!barcode.Contains("-")) { throw new System.InvalidOperationException(string.Format("Invalid Assembly barcode {0}", barcode)); } int[] decoded = DecodeAssembyBarcode(barcode); scannedObject.ScannedObjects.Add(new ScanObjectItem { ObjectBarcode = barcode, ObjectEntityTypeID = decoded[0], UniqueIdentifier = decoded[1] }); break; case BarcodeProcessType.RIGGING: if (!barcode.Contains("-")) { throw new System.InvalidOperationException(string.Format("Invalid Assembly barcode {0}", barcode)); } ProcessRigging(ref scannedObject, barcode); break; default: break; } break; case "G": // Galv Note Scanned if (InternalNoteStartScan == false) { InternalNoteStartScan = true; scannedObject = new ScanObject(BarcodeProcessType.GALVANISING, barcode); } else if (InternalNoteStartScan == true) { if (scannedObject.ScanObjectIdentifier != barcode) { throw new System.InvalidOperationException("Start and End note scans don't match!"); } if (scannedObjects == null) { scannedObjects = new List <ScanObject>(); } scannedObjects.Add(scannedObject); InternalNoteStartScan = false; } break; case "D": // Delivery Note Scanned if (InternalNoteStartScan == false) { InternalNoteStartScan = true; scannedObject = new ScanObject(BarcodeProcessType.DISPATCH, barcode); } else if (InternalNoteStartScan == true) { if (scannedObject.ScanObjectIdentifier != barcode) { throw new System.InvalidOperationException("Start and End note scans don't match!"); } // FinaliseScannedObject(scannedObject); if (scannedObjects == null) { scannedObjects = new List <ScanObject>(); } scannedObjects.Add(scannedObject); InternalNoteStartScan = false; } break; default: break; } } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Barcode Utility", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (e.type == BarcodeProcessType.RIGGING) { scannedObjects = new List <ScanObject>(); scannedObjects.Add(scannedObject); } FinaliseScannedObject(scannedObjects); } }
private void UpdateStockStatus() { BarcodeForm.GetInstance().lbStockStatus.Items.Clear(); BarcodeForm.GetInstance().lbStockStatus.Items.Add(string.Format("Stock Status: {0} on {1}.", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString())); using (KYLIEEntities ctx = new KYLIEEntities()) { int dispatchTypeID = (int)Convert.ChangeType(BarcodeProcessType.DISPATCH, BarcodeProcessType.DISPATCH.GetTypeCode()); int galvanisingTypeID = (int)Convert.ChangeType(BarcodeProcessType.GALVANISING, BarcodeProcessType.GALVANISING.GetTypeCode()); Dictionary <int, int> entityGalvanisingIDs = new Dictionary <int, int>(); Dictionary <int, int> entityDispatchIDs = new Dictionary <int, int>(); // ########## GALAVANISING ####################### var galavanisingEntityIDsScanned = (from st in ctx.SCAN_ScanType where st.ScanType == galvanisingTypeID select st.SCAN_AssemblyScans).ToList(); foreach (var sList in galavanisingEntityIDsScanned) { foreach (var s in sList) { // Must be first time round, so add the first Assembly EntityID if (entityGalvanisingIDs.Count == 0) { entityGalvanisingIDs.Add(s.EntityID, 1); } else { foreach (var a in entityGalvanisingIDs) { if (entityGalvanisingIDs.ContainsKey(s.EntityID)) { entityGalvanisingIDs[s.EntityID] = entityGalvanisingIDs[s.EntityID] + 1; break; } else { entityGalvanisingIDs.Add(s.EntityID, 1); break; } } } } } List <int> distinctScannedGalvanisingEntityIDs = entityGalvanisingIDs.Keys.ToList(); var descriptionAssemblyGalvanising = ctx.Assemblies.Where(f => distinctScannedGalvanisingEntityIDs.Contains(f.SubComponents_PK)).Select(f => new { id = f.SubComponents_PK, desc = f.SubComponentDescription }).ToList(); // ###### DISPATCH ############################## var dispatchEntityIDsScanned = (from st in ctx.SCAN_ScanType where st.ScanType == dispatchTypeID select st.SCAN_AssemblyScans).ToList(); foreach (var sList in dispatchEntityIDsScanned) { foreach (var s in sList) { // Must be first time round, so add the first Assembly EntityID if (entityDispatchIDs.Count == 0) { entityDispatchIDs.Add(s.EntityID, 1); } else { foreach (var a in entityDispatchIDs) { if (entityDispatchIDs.ContainsKey(s.EntityID)) { entityDispatchIDs[s.EntityID] = entityDispatchIDs[s.EntityID] + 1; break; } else { entityDispatchIDs.Add(s.EntityID, 1); break; } } } } } List <int> distinctScannedDispatchEntityIDs = entityDispatchIDs.Keys.ToList(); var descriptionAssemblyDispatch = ctx.Assemblies.Where(f => distinctScannedDispatchEntityIDs.Contains(f.SubComponents_PK)).Select(f => new { id = f.SubComponents_PK, desc = f.SubComponentDescription }).ToList(); // ####### DISPLAY ############################# BarcodeForm.GetInstance().lbStockStatus.Items.Add(""); BarcodeForm.GetInstance().lbStockStatus.Items.Add("Scanned back from galvanising"); BarcodeForm.GetInstance().lbStockStatus.Items.Add(""); foreach (var d in descriptionAssemblyGalvanising) { int cnt = 0; string assyDesc = ""; if (d.desc == null) { assyDesc = "Can't find the assembly!!!!"; } else { assyDesc = string.Format("\t{0} {1}", d.desc, entityGalvanisingIDs.TryGetValue(d.id, out cnt) ? cnt : 0); } BarcodeForm.GetInstance().lbStockStatus.Items.Add(assyDesc); } BarcodeForm.GetInstance().lbStockStatus.Items.Add(""); BarcodeForm.GetInstance().lbStockStatus.Items.Add("Scanned as dispatched"); BarcodeForm.GetInstance().lbStockStatus.Items.Add(""); foreach (var d in descriptionAssemblyDispatch) { int cnt = 0; string assyDesc = ""; if (d == null) { assyDesc = "Can't find the assembly!!!!"; } else { assyDesc = string.Format("\t{0} {1}", d.desc, entityDispatchIDs.TryGetValue(d.id, out cnt) ? cnt : 0); } BarcodeForm.GetInstance().lbStockStatus.Items.Add(assyDesc); } BarcodeForm.GetInstance().lbStockStatus.Items.Add(""); BarcodeForm.GetInstance().lbStockStatus.Items.Add("Stock level"); BarcodeForm.GetInstance().lbStockStatus.Items.Add(""); foreach (var d in descriptionAssemblyGalvanising) { int cntGalv = 0; int cntDisp = 0; string assyDesc = ""; if (d.desc == null) { assyDesc = "Can't find the assembly!!!!"; } else { int backFromGalv = entityGalvanisingIDs.TryGetValue(d.id, out cntGalv) ? cntGalv : 0; int sentToDispatch = entityDispatchIDs.TryGetValue(d.id, out cntDisp) ? cntDisp : 0; assyDesc = string.Format("\t{0} {1}", d.desc, (backFromGalv - sentToDispatch)); } BarcodeForm.GetInstance().lbStockStatus.Items.Add(assyDesc); } } }
private static void LookupBarcode(string barcode) { BarcodeForm.GetInstance().lbDecodedBarcode.Items.Add(barcode); }