示例#1
0
        static void Main(string[] args)
        {
            ConfigBuilder <AppConfig> _appsettings = new ConfigBuilder <AppConfig>(Utils.FileToProjectDirectory("..\\IIOT_OPCconfig.json"));
            //AbstractDataAccess<DailyProduction> dailyProductionDataAccess = new DailyProductionDataAccess() { ConnectionString = _appsettings.Config.ConnectionString };

            //// insert new items
            //dailyProductionDataAccess.Insert(
            //    new DailyProduction
            //            {
            //                TimeStamp = new DateTime(1999,2,3)
            //                , NumPieces = 12
            //                , NumPiecesRejected = 0
            //            }
            //    );
            //dailyProductionDataAccess.Insert(new DailyProduction { TimeStamp = new DateTime(1999,3,3), NumPieces = 24, NumPiecesRejected = 0 });
            //dailyProductionDataAccess.Insert(new DailyProduction { TimeStamp = new DateTime(1999, 3,4), NumPieces = 35, NumPiecesRejected = 5 });

            //// retrieve items by filters
            //var itemByDate = dailyProductionDataAccess.GetItem(
            //    new
            //            {
            //                TimeStamp = new DateTime(1999, 3, 3)
            //            }
            //    );
            //var itemById = dailyProductionDataAccess.GetItem(new { Id = 2 });
            //var itemByPieces = dailyProductionDataAccess.GetItem(new { NumPieces = 2 });

            //AbstractDataAccess<PlantStateRowData> plantStatesDataAccess = new PlantStatesDataAccess() { ConnectionString = _appsettings.Config.ConnectionString };

            //plantStatesDataAccess.Insert(
            //    new PlantStateRowData
            //    {
            //                TimeStamp = new DateTime(1999, 2, 3, 6, 36, 11)
            //                , PlantState = (PlantState)1
            //            }
            //    );
            //plantStatesDataAccess.Insert(new PlantStateRowData { TimeStamp = new DateTime(1999, 2, 3, 7, 00, 45), PlantState = (PlantState)2 });
            //plantStatesDataAccess.Insert(new PlantStateRowData { TimeStamp = new DateTime(1999, 2, 3, 12, 24, 13), PlantState = (PlantState)3 });
            //plantStatesDataAccess.Insert(new PlantStateRowData { TimeStamp = new DateTime(1999, 2, 3, 12, 25, 54), PlantState = (PlantState)2 });
            //plantStatesDataAccess.Insert(new PlantStateRowData { TimeStamp = new DateTime(1999, 2, 3, 18, 16, 9), PlantState = (PlantState)1 });

            //var stateByDate = plantStatesDataAccess.GetItem(new { TimeStamp = new DateTime(1999, 2, 3, 7, 00, 45) });



            AbstractDataAccess <PlantStateDuration> plantStateDurationDataAccess = new PlantStateDurationDataAccess()
            {
                ConnectionString = _appsettings.Config.ConnectionString
            };

            // insert new items
            plantStateDurationDataAccess.Insert(
                new PlantStateDuration
            {
                TimeStamp          = DateTime.Now,
                OffDuration        = new TimeSpan(8, 0, 0),
                OnRunningDuration  = new TimeSpan(15, 30, 0),
                OnStoppedfDuration = new TimeSpan(0, 30, 0)
            }
                );

            // retrieve items by filters
            var itemByDate = plantStateDurationDataAccess.GetItem(
                new
            {
                TimeStamp = new DateTime(1999, 3, 3)
            }
                );
            var itemById     = plantStateDurationDataAccess.GetItem(new { Id = 2 });
            var itemByPieces = plantStateDurationDataAccess.GetItem(new { OnRunningDuration = new TimeSpan(15, 30, 0) });
        }
示例#2
0
        static int GetDataFromDB(DateTime date, out int productedPieces, out int defectedPieces, out TimeSpan plannedProductionTime, out TimeSpan productionTime)
        {
            ConfigBuilder <AppConfig> _appsettings = new ConfigBuilder <AppConfig>(Utils.FileToProjectDirectory("..\\IIOT_OPCconfig.json"));
            AbstractDataAccess <PlantStateDuration> plantStateDurationDataAccess = new PlantStateDurationDataAccess()
            {
                ConnectionString = _appsettings.Config.ConnectionString
            };
            AbstractDataAccess <DailyProduction> dailyProductionDataAccess = new DailyProductionDataAccess()
            {
                ConnectionString = _appsettings.Config.ConnectionString
            };
            // retrieve items by filters
            PlantStateDuration stateDuration = null;
            DailyProduction    productionObject;

            productedPieces       = 0;
            defectedPieces        = 0;
            plannedProductionTime = new TimeSpan(0);
            productionTime        = new TimeSpan(0);

            #region try get duration
            try
            {
                stateDuration = plantStateDurationDataAccess.GetItem(
                    new
                {
                    TimeStamp = date.AddHours(23).AddMinutes(59).AddSeconds(59)
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Errore in Program.TryGetDuration() -> {ex}");
                return(-1);
            }
            #endregion

            #region try get production pieces
            try
            {
                productionObject = dailyProductionDataAccess.GetItem(
                    new
                {
                    TimeStamp = date.AddHours(23).AddMinutes(59).AddSeconds(59)
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Errore in Program.TryGetDuration() -> {ex}");
                return(-1);
            }
            #endregion

            if (stateDuration == null || productionObject == null)
            {
                Console.WriteLine("runningDuration o onStoppedDuration not found");
                Console.WriteLine("introduce a new date to check");
                return(-2);
            }
            plannedProductionTime = stateDuration.OnRunningDuration + stateDuration.OnStoppedfDuration;
            productionTime        = stateDuration.OnRunningDuration;
            productedPieces       = productionObject.NumPieces;
            defectedPieces        = productionObject.NumPiecesRejected;

            //Console.WriteLine("db get result:");
            //Console.WriteLine($"    OnRunningDuration {string.Format("{0:t}", stateDuration.OnRunningDuration)}");
            //Console.WriteLine($"    OnStoppedfDuration {string.Format("{0:t}", stateDuration.OnStoppedfDuration)}");
            //Console.WriteLine($"    plannedProductionTime {string.Format("{0:t}", plannedProductionTime)}");
            //Console.WriteLine($"    productionTime {string.Format("{0:t}", productionTime)}");
            //Console.WriteLine($"    productedPieces {productedPieces}");
            //Console.WriteLine($"    defectedPieces {defectedPieces}");

            return(0);
        }