소스 검색

DB 수정

unque781 5 년 전
부모
커밋
b00b45b893

+ 7 - 0
Dev/OHV/OHV.Module.MainViews/Views/HistoryView.xaml.cs

@@ -27,6 +27,13 @@ namespace OHV.Module.MainViews.Views
             InitializeComponent();
 
             this.Loaded += HistoryView_Loaded;
+            this.IsVisibleChanged += HistoryView_IsVisibleChanged;
+        }
+
+        private void HistoryView_IsVisibleChanged( object sender, DependencyPropertyChangedEventArgs e )
+        {
+            if ( (bool)e.NewValue)
+                this.ViewModel.RefashList();
         }
 
         private void HistoryView_Loaded( object sender , RoutedEventArgs e )

+ 11 - 10
Dev/OHV/OHV.Module.MainViews/Views/HistoryViewModel.cs

@@ -6,6 +6,7 @@ using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Linq;
+using System.Security.Permissions;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Input;
@@ -36,7 +37,7 @@ namespace OHV.Module.MainViews.Views
             else
                 this.AlarmList = ll.OrderByDescending( x => x.OccurTime ).ToList();
 
-            this.sql.HisAlarmDAL.OnChangeTable += HisAlarmDAL_ChangedProperty;
+            //this.sql.HisAlarmDAL.OnChangeTable += HisAlarmDAL_ChangedProperty;
         }
 
         private void HisAlarmDAL_ChangedProperty()
@@ -51,20 +52,20 @@ namespace OHV.Module.MainViews.Views
             this.AlarmList = sql.HisAlarmDAL.GetAll().OrderByDescending( x => x.OccurTime ).ToList();
         }
 
-        //async private void ExecuteAlarmResetCommand( )
-        //{
-        //    //Grid Refresh 대안 찾을것
-        //    //var backupList = this.AlarmList.ToList();
-        //    //this.AlarmList.Clear();
+        public void RefashList()
+        {
+            if ( this.AlarmList == null )
+                return;
 
-        //    //await Task.Delay( 1000 );
+            this.AlarmList.Clear();
+            this.AlarmList = null;
 
-        //    //var e = new ObservableCollection<Alarm>( backupList );
-        //    //this.AlarmList = e;
-        //}
+            this.AlarmList = sql.HisAlarmDAL.GetAll().OrderByDescending( x => x.OccurTime ).ToList();
+        }
 
         public void Init( ) 
         {
+            //RefashList();
         }
     }
 }

+ 21 - 14
Dev/OHV/OHV.SqliteDAL/DAL/AbstractDAL.cs

@@ -169,11 +169,10 @@ namespace OHV.SqliteDAL.DAL
 
         public virtual IEnumerable<T> Get( Expression<Func<T, bool>> filter = null, Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null, string includeProperties = "" )
         {
+            IQueryable<T> query = this.table;
+
             lock ( lockObj )
             {
-
-                IQueryable<T> query = this.table;
-
                 if ( filter != null )
                     query = query.Where( filter );
 
@@ -219,6 +218,7 @@ namespace OHV.SqliteDAL.DAL
                 _context.Entry( obj ).State = EntityState.Modified;
                 this.Save();
             }
+
         }
 
         public void Delete( object id )
@@ -227,6 +227,7 @@ namespace OHV.SqliteDAL.DAL
             if ( existing == null )
                 return;
 
+
             lock ( lockObj )
             {
                 if ( _context.Entry( existing ).State == EntityState.Detached )
@@ -237,6 +238,7 @@ namespace OHV.SqliteDAL.DAL
                 table.Remove( existing );
                 this.Save();
             }
+
         }
 
         public void Delete( Expression<Func<T, bool>> filter )
@@ -244,7 +246,7 @@ namespace OHV.SqliteDAL.DAL
             lock ( lockObj )
             {
                 var delList = this.table.Where( filter ).ToList();
-                if ( delList.Count > 0 )
+                if ( delList.Any() && delList != null )
                 {
                     this.table.RemoveRange( delList );
                     Save();
@@ -256,8 +258,13 @@ namespace OHV.SqliteDAL.DAL
         {
             lock ( lockObj )
             {
-                table.RemoveRange( table );
-                this.Save();
+                var delList = table.ToList();
+
+                if ( delList != null && delList.Any() )
+                {
+                    table.RemoveRange( delList );
+                    this.Save();
+                }
             }
         }
 
@@ -279,14 +286,14 @@ namespace OHV.SqliteDAL.DAL
 
                 return;
             }
-            //catch ( DbUpdateConcurrencyException ex )
-            //{
-            //    ex.Entries.Single().Reload();
-            //    logger.E( $"[DataBase] - DbUpdateConcurrencyException {this.table.GetType().Name}" );
-            //    return;
-            //}
-
-            this.OnChangeTable?.BeginInvoke( null, null );
+            catch ( DbUpdateConcurrencyException ex )
+            {
+                ex.Entries.Single().Reload();
+                logger.E( $"[DataBase] - DbUpdateConcurrencyException {this.table.GetType().Name}" );
+                return;
+            }
+
+            this.OnChangeTable?.Invoke();
         }
     }
 

+ 2 - 2
Dev/OHV/OHV.sln

@@ -113,8 +113,8 @@ Global
 		{CF748E61-69C2-4DEC-A9EC-755B6999077E}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{CF748E61-69C2-4DEC-A9EC-755B6999077E}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{CF748E61-69C2-4DEC-A9EC-755B6999077E}.Release|Any CPU.Build.0 = Release|Any CPU
-		{CF748E61-69C2-4DEC-A9EC-755B6999077E}.Remote1|Any CPU.ActiveCfg = Debug|Any CPU
-		{CF748E61-69C2-4DEC-A9EC-755B6999077E}.Remote1|Any CPU.Build.0 = Debug|Any CPU
+		{CF748E61-69C2-4DEC-A9EC-755B6999077E}.Remote1|Any CPU.ActiveCfg = Release|Any CPU
+		{CF748E61-69C2-4DEC-A9EC-755B6999077E}.Remote1|Any CPU.Build.0 = Release|Any CPU
 		{CF748E61-69C2-4DEC-A9EC-755B6999077E}.Remote2|Any CPU.ActiveCfg = Remote|Any CPU
 		{CF748E61-69C2-4DEC-A9EC-755B6999077E}.Remote2|Any CPU.Build.0 = Remote|Any CPU
 		{EAFDB5FF-20F9-4172-9A11-EC8CF3AB6EDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU

+ 3 - 24
Dev/OHV/VehicleControlSystem/ControlLayer/Vehicle.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Linq;
 using System.Threading;
 using System.Threading.Tasks;
@@ -490,11 +491,6 @@ namespace VehicleControlSystem.ControlLayer
 
         public event Action<int> OnCurrentTagChanged;
 
-        public event Action OnManualMove;
-        public event Action OnManualLoad;
-        public event Action OnManualUnload;
-        public event Action OnManualCharging;
-
         public event Action<eFailCode> OnFailReport;
         #endregion
 
@@ -933,7 +929,6 @@ namespace VehicleControlSystem.ControlLayer
             logger.D( "Vehicle - _ThObstacleChecker Dispose" );
         }
 
-
         /// <summary>
         /// Scheduler 가 주는 Sub Command 를 이용하여 동작하자.
         /// </summary>
@@ -983,10 +978,12 @@ namespace VehicleControlSystem.ControlLayer
                             this.CurrentSubCommand = subCmd;
                             this.BatteryCharge( subCmd );
                             break;
+
                         case eSubCommandType.Cancel:
                             this.CurrentSubCommand = subCmd;
                             CancelCommand( subCmd );
                             break;
+
                         default:
                             break;
                     }
@@ -1528,19 +1525,6 @@ namespace VehicleControlSystem.ControlLayer
             return false;
         }
 
-        void CheckIOState()
-        {
-            //이미 알람이면 체크 안함.
-            if ( this.VehicleStateProperty == eVehicleState.Abnormal ) return;
-
-            if ( this.refObjects.IO.IsConnectError ) return;
-
-            //if ( this.iO.IsOn( "IN_EMS_SW" ) ) this.OccurVehicleAlarm( 28 );
-            //if ( !this.iO.IsOn( "IN_CP_ON_SAFETY" ) ) this.OccurVehicleAlarm( 31 );
-            //if ( !this.iO.IsOn( "IN_CP_ON_24V" ) ) this.OccurVehicleAlarm( 30 );
-            //if ( !this.iO.IsOn( "IN_MC_ON" ) ) this.OccurVehicleAlarm( 29 );
-        }
-
         #endregion
 
         #region Mechanical Method
@@ -1581,11 +1565,6 @@ namespace VehicleControlSystem.ControlLayer
         }
         #endregion
 
-        #region Drive
-        //public void DriveServoOff() => this.drive.ServoOff();
-        //public void DriveServoOn() => this.drive.ServoOn();
-        #endregion
-
         #region Conveyor
         public void ConveyorOff() => this.refObjects.Conveyor.OnOffConveyor( false );
         public int ConveyorLoad() => this.refObjects.Conveyor.ConveyorLoad();

+ 56 - 2
Dev/OHVDriveLogger/OHVDriveLogger/OHVDriveLogger/FormMain.cs

@@ -1,4 +1,5 @@
 using GSG.NET.Concurrent;
+using GSG.NET.FileSystem;
 using GSG.NET.Logging;
 using GSG.NET.PLC.KNC;
 using GSG.NET.Utils;
@@ -6,6 +7,8 @@ using log4net.Appender;
 using System;
 using System.Configuration;
 using System.Drawing;
+using System.IO;
+using System.Threading.Tasks;
 using System.Windows.Forms;
 
 namespace OHVDriveLogger
@@ -36,6 +39,8 @@ namespace OHVDriveLogger
             this.Load += FormMain_Load;
             this.FormClosing += FormMain_FormClosing;
 
+            MidnightNotifier.DayChanged += MidnightNotifier_DayChanged;
+
             this.vehicleID = ConfigurationManager.AppSettings["VehicleID"];
             this.UploadIP = ConfigurationManager.AppSettings["FTPUploadIP"];
             this.PLCAddress = ConfigurationManager.AppSettings["PLC_IP"];
@@ -45,6 +50,13 @@ namespace OHVDriveLogger
             FTPLogger.Instance.PLCAddress = this.PLCAddress;
         }
 
+        private void MidnightNotifier_DayChanged( object sender, EventArgs e )
+        {
+            logger.I( "자정 Event Occur" );
+            Task.Run( () => { DeleteNoBackupFiles( @"c:\LOG\OHV\DriveLogger\", 2 ); } );
+            Task.Run( () => { DeleteNoBackupFiles( @"c:\LOG\OHV\Vehicle\", 2 ); } );
+        }
+
         private void FormMain_FormClosing( object sender, FormClosingEventArgs e )
         {
             this.threadCancel.Cancel();
@@ -109,8 +121,6 @@ namespace OHVDriveLogger
                 plc.WriteBit( "DRIVE_LOGGING_ONOFF", false );
             else
                 plc.WriteBit( "DRIVE_LOGGING_ONOFF", true );
-
-            //logger.I( $"Test" );
         }
 
         void Th_DoWorker()
@@ -212,5 +222,49 @@ namespace OHVDriveLogger
         {
             this.Close();
         }
+
+        void DeleteNoBackupFiles(string directoryPath, int backupDays )
+        {
+            try
+            {
+                var dt = DateTime.Now.AddDays( -backupDays );
+                int delCount = 0;
+
+                foreach ( string path in FileUtils.GetFiles( directoryPath, "*", false ) )
+                {
+                    var fi = new FileInfo( path );
+                    if ( fi.LastWriteTime > dt )
+                        continue;
+
+                    FileUtils.DeleteFileIfExist( path );
+                    delCount++;
+                    logger.D( $"Deleted File - Name : [ {fi.Name} ]" );
+
+                    if ( delCount > 2 )
+                        break;
+                }
+
+                //if ( !IsFolderMakeDay )
+                //    return;
+
+                //foreach ( string item in FileUtils.GetFolders( FolderRoot, false ) )
+                //{
+                //    var ct = Directory.GetCreationTime( item );
+                //    if ( ct > dt )
+                //        continue;
+
+                //    int cnt = FileUtils.GetFiles( item, "*", false ).Length;
+                //    if ( cnt > 0 )
+                //        continue;
+
+                //    Directory.Delete( item );
+                //}
+
+            }
+            catch
+            {
+
+            }
+        }
     }
 }