コード例 #1
0
        private void btnStartTest_Click(object sender, EventArgs e)
        {
            using (KYLIEEntities ctx = new KYLIEEntities())
            {
                SCAN_ScanType st = new SCAN_ScanType();
                st.Barcode  = "DISP2222";
                st.ScanDate = DateTime.Now;
                st.ScanType = 2;



                // Check exists, or add new

                SCAN_AssemblyScans sa = ctx.SCAN_AssemblyScans.FirstOrDefault(f => f.UniqueIdentifier == 1);

                st.SCAN_AssemblyScans.Add(sa);

                //st.SCAN_AssemblyScans.Add(new SCAN_AssemblyScans() { Barcode = "A145-1", EntityID = 145, UniqueIdentifier = 1 });
                //st.SCAN_AssemblyScans.Add(new SCAN_AssemblyScans() { Barcode = "A144-2", EntityID = 144, UniqueIdentifier = 2 });
                //st.SCAN_AssemblyScans.Add(new SCAN_AssemblyScans() { Barcode = "A143-3", EntityID = 143, UniqueIdentifier = 3 });

                //SCAN_ScanType newScan =
                //newScan.SCAN_AssemblyScans.Add(sa);

                ctx.SCAN_ScanType.Add(st);

                ctx.SaveChanges();
            }
        }
コード例 #2
0
        private void FinaliseScannedObject(List <ScanObject> o)
        {
            List <string> assembliesScanned = new List <string>();
            Boolean       canAddAssembly    = false;

            try
            {
                using (KYLIEEntities ctx = new KYLIEEntities())
                {
                    foreach (ScanObject scanObject in o)
                    {
                        // Check it doesn't already exist first, else add new.

                        SCAN_ScanType so = ctx.SCAN_ScanType.FirstOrDefault(f => f.Barcode == scanObject.ScanObjectIdentifier);
                        if (so != null)
                        {
                            MessageBox.Show(string.Format("{0} has already been scanned.", so.Barcode));
                            return;
                        }

                        // Now generate a new ScanType object to insert

                        SCAN_ScanType scanType = new SCAN_ScanType();
                        scanType.ScanDate = DateTime.Now;
                        scanType.Barcode  = scanObject.ScanObjectIdentifier;
                        scanType.ScanType = (int)Convert.ChangeType(scanObject.ScanObjectType, scanObject.ScanObjectType.GetTypeCode());

                        foreach (ScanObjectItem item in scanObject.ScannedObjects)
                        {
                            if (assembliesScanned.Contains(item.ObjectBarcode))
                            {
                                MessageBox.Show(string.Format("{0} has already been scanned - ignoring.", item.ObjectBarcode));
                                canAddAssembly = false;
                            }
                            else
                            {
                                assembliesScanned.Add(item.ObjectBarcode);
                                canAddAssembly = true;
                            }

                            if (canAddAssembly)
                            {
                                // Has the assmebly already been added to SCAN_AssemblyScans?
                                SCAN_AssemblyScans a = ctx.SCAN_AssemblyScans.FirstOrDefault(f => f.Barcode == item.ObjectBarcode);

                                if (a == null)
                                {
                                    a                  = new SCAN_AssemblyScans();
                                    a.Barcode          = item.ObjectBarcode;
                                    a.EntityID         = item.ObjectEntityTypeID;
                                    a.UniqueIdentifier = item.UniqueIdentifier;
                                }
                                scanType.SCAN_AssemblyScans.Add(a);
                            }
                        }

                        ctx.SCAN_ScanType.Add(scanType);

                        ctx.SaveChanges();
                    }
                }
            }

            catch (Exception expn)
            {
                MessageBox.Show(expn.Message);
            }
            finally
            {
                // Should really fire an update stock event here
                UpdateStockStatus();
            }
        }