Files

161 lines
4.9 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using LFP_Manager.DataStructure;
using LFP_Manager.Utils;
namespace LFP_Manager.Controls
{
public delegate void LogDataUpdate(object sender, string LogResult, bool active, int aLogTime);
public partial class ucDataLog : DevExpress.XtraEditors.XtraUserControl
{
#region VARIABLES
CommConfig Config;
DeviceSystemTotalData SystemTotalData;
DeviceSystemData SystemData;
DateTime bakDateTime;
String LogFileName = "";
String LogFileNameTotal = "";
bool logging = false;
bool Active = false;
public event LogDataUpdate OnUpdate = null;
#endregion
#region CONSTRUCTORS
public ucDataLog()
{
InitializeComponent();
}
#endregion
#region PUBLIC UPDATE
public void UpdateActiveStatus(bool aStatus, CommConfig aConfig, ref DeviceSystemTotalData aSystemTotalData, ref DeviceSystemData aSystemData)
{
Active = aStatus;
Config = aConfig;
SystemTotalData = aSystemTotalData;
SystemData = aSystemData;
}
public void UpdateData(ref DeviceSystemTotalData aSystemTotalData, ref DeviceSystemData aSystemData)
{
SystemTotalData = aSystemTotalData;
SystemData = aSystemData;
}
#endregion
#region TIMER EVENT
private void tmrLogging_Tick(object sender, EventArgs e)
{
DateTime cDate = DateTime.Now;
int ss;
if ((logging) && (Active))
{
//if (SystemData[0].CommFail == false)
//{
ss = Convert.ToInt16(cbLogTime.Text);
if (
((bakDateTime.Minute != cDate.Minute)
|| (bakDateTime.Second != cDate.Second))
&& ((cDate.Second % ss) == 0)
)
{
int mQty = csUtils.GetModuleQty(Config);
for (int i = 0; i < mQty; i++)
{
try
{
csLog.SystemDataLog(i + 1, Config, SystemData, cDate, Application.ExecutablePath, LogFileName);
bakDateTime = cDate;
}
catch (Exception)
{
}
}
if (mQty > 0)
{
try
{
csLog.SystemTotalDataLog(Config, SystemTotalData, cDate, Application.ExecutablePath, LogFileNameTotal);
bakDateTime = cDate;
}
catch (Exception)
{
}
}
}
//}
}
}
#endregion
#region BUTTON EVENT
private void btnLogStart_Click(object sender, EventArgs e)
{
if (logging == true)
{
tmrLogging.Stop();
cbLogTime.Enabled = true;
logging = false;
btnLogStart.Text = "Log Start";
if (OnUpdate != null)
{
OnUpdate(this, String.Format("LogStop: {0:yyyy/MM/dd HH:mm:ss}", DateTime.Now), false, Convert.ToInt16(cbLogTime.Text));
}
}
else
{
LogFileNameTotal = String.Format("{0:yyMMddHHmmss}", DateTime.Now);
LogFileName = String.Format("{0:yyMMddHHmmss}", DateTime.Now);
tmrLogging.Start();
cbLogTime.Enabled = false;
logging = true;
btnLogStart.Text = "Log Stop";
if (OnUpdate != null)
{
OnUpdate(this, String.Format("Logging: SHELFX_LOG_{0}.csv", LogFileName), true, Convert.ToInt16(cbLogTime.Text));
}
}
}
private void btnOpenLogFolder_Click(object sender, EventArgs e)
{
System.Diagnostics.Process ps = new System.Diagnostics.Process();
ps.StartInfo.FileName = "explorer.exe";
ps.StartInfo.Arguments = csLog.GetLogFolder(Application.ExecutablePath);
ps.StartInfo.WorkingDirectory = csLog.GetLogFolder(Application.ExecutablePath);
ps.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
ps.Start();
}
#endregion
}
}