コード例 #1
0
        public static int GetBatchId(string Batch)
        {
            using (var db = new RIT_QAEntities())
            {
                Batch ExistBatch = null;
                var   b          = Batch;
                try
                {
                    ExistBatch = db.Batches.FirstOrDefault(x => x.BatchNumber == b);
                }
                catch (Exception ex)
                {
                    Logger.Error("This should happend only when the Batch table is empty", ex);
                }

                int BatchId = 0;
                // and create if it is new
                if (ExistBatch == null)
                {
                    Batch _currentBatch = db.Batches.Create();
                    _currentBatch.BatchNumber = Batch;
                    _currentBatch.Date        = DateTime.Now;
                    db.Batches.Add(_currentBatch);
                    db.SaveChanges();
                    BatchId = _currentBatch.Id;
                    Logger.Debug("New batch created. Batch Number = " + _currentBatch.BatchNumber);
                }
                else
                {
                    BatchId = ExistBatch.Id;
                }

                return(BatchId);
            }
        }
コード例 #2
0
        private static void Main() //string[] args)
        {
            string testedSerial = GetSerial();

            #region Add Electrical test result
            DpsTest dps = new DpsTest();

            dps.Start("22566322221", testedSerial);

            dps.MAC = GetMAC();

            dps.Result = GetResult();

            dps.Save();
            #endregion

            #region How to use the Electrical test database
            Console.WriteLine("Entered: " + dps.ToString());

            using (var db = new RIT_QAEntities())
            {
                foreach (ElectricalTest e in  db.Batches.Where(x => x.Id == dps.BatchId).First().ElectricalTests)
                {
                    Console.WriteLine(String.Format("{0,15}\t{1,15}\t{2,6}", e.SerialNo, e.MAC, e.Result ? "+" : "-"));
                }
            }
            #endregion

            #region How to use the Calibration test database
            DpsCalibration d = new DpsCalibration("22566322221", testedSerial);
            d.AddData(1, 0.99887766, 1223, 1222, 7);
            d.AddData(1.5, 1.448877, 223, 222, 7.1);
            d.AddData(2, 1.99887766, 13, 12, 7.2);
            d.Save();
            #endregion

            #region Detached use
            Console.WriteLine(utils.RecordToString(d.GetDpsInfo()));
            Console.WriteLine(utils.RecordToString(d.GetCalibrationBatch()));
            foreach (CalibrationData cd in d.GetCalibrationData())
            {
                Console.WriteLine(utils.RecordToString(cd));
            }
            #endregion

            #region Attached use
            using (var db = new RIT_QAEntities())
            {
                Calibration dd = db.Calibrations.FirstOrDefault(x => x.SerialNo == testedSerial);

                foreach (CalibrationData cd in dd.CalibrationDatas.ToList())
                {
                    Console.WriteLine("Setpoint {0,20}, Pressure{1,5},temp{2,5}", cd.SetPoint, cd.Pressure, cd.Temp);
                }
            }
            #endregion
        }
コード例 #3
0
 public static Calibration GetDpsInfo(string SerialNo)
 {
     using (var db = new RIT_QAEntities())
     {
         Calibration dps = db.Calibrations.FirstOrDefault(x => x.SerialNo == SerialNo);
         db.Entry(dps).State = System.Data.Entity.EntityState.Detached;
         return(dps);
     }
 }
コード例 #4
0
 public static Batch GetCalibrationBatch(string SerialNo)
 {
     using (var db = new RIT_QAEntities())
     {
         Batch batch = db.Calibrations.FirstOrDefault(x => x.SerialNo == SerialNo).Batch;
         db.Entry(batch).State = System.Data.Entity.EntityState.Detached;
         return(batch);
     }
 }
コード例 #5
0
        private static string GetSerial()
        {
            using (var db = new RIT_QAEntities())
            {
                var test = db.ElectricalTests.Create();
                do
                {
                    test.SerialNo = new Random().Next(1000, 10000000).ToString();
                } while (db.ElectricalTests.Find(test.SerialNo) != null);

                return(test.SerialNo);
            }
        }
コード例 #6
0
        public static List <CalibrationData> GetCalibrationData(string SerialNo)
        {
            List <CalibrationData> list = new List <CalibrationData>();

            using (var db = new RIT_QAEntities())
            {
                foreach (CalibrationData data in db.Calibrations.FirstOrDefault(x => x.SerialNo == SerialNo).CalibrationDatas.ToList())
                {
                    db.Entry(data).State = System.Data.Entity.EntityState.Detached;
                    list.Add(data);
                }
            }
            return(list);
        }
コード例 #7
0
 public void Save()
 {
     using (var db = new RIT_QAEntities())
     {
         try
         {
             db.Calibrations.Add(DpsDetails);
             foreach (CalibrationData record in DataRecords)
             {
                 db.CalibrationDatas.Add(record);
             }
             db.SaveChanges();
             Logger.Debug("Calibrations saved");
         }
         catch (Exception ex)
         {
             Logger.Info("Save DPS calibration result failed.");
             Logger.Error("", ex);
         }
     }
 }
コード例 #8
0
        public void Save()
        {
            using (var db = new RIT_QAEntities())
            {
                try
                {
                    if (this.EndDate == null)
                    {
                        this.EndDate = DateTime.Now;
                    }

                    db.ElectricalTests.Add(GetBase());
                    db.SaveChanges();
                    Logger.Debug("Test saved");
                }
                catch (Exception ex)
                {
                    Logger.Info("Save DPS test result failed. Please that SErialNo, MAC and Result are field", ex);
                    Logger.Error("", ex);
                }
            }
        }
コード例 #9
0
        private static string GetMAC()
        {
            using (var db = new RIT_QAEntities())
            {
                // Create new MAC based on the last in table
                PhysicalAddress lastMac;
                byte[]          macArray = { 0x04, 0x11, 0x22, 0x33, 0x44, 0xFF };
                try
                {
                    lastMac      = PhysicalAddress.Parse(db.ElectricalTests.Min(r => r.MAC).ToUpper());
                    macArray     = lastMac.GetAddressBytes();
                    macArray[5] -= 1; // Chnage the MAC address
                }
                catch (Exception ex)
                {
                    Logger.Warn("This should happend only when the ElectricalTest table is empty", ex);
                }

                lastMac = PhysicalAddress.Parse(string.Concat(Array.ConvertAll(macArray, j => j.ToString("X2"))));
                return(lastMac.ToString());
            }
        }