FrmWorkLog: Import VARText.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
namespace VAR.Toolbox.UI.Tools
|
||||
namespace VAR.Toolbox.UI.Tools.WorkLog
|
||||
{
|
||||
partial class FrmWorkLog
|
||||
{
|
||||
@@ -29,6 +29,9 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.splitWindow = new System.Windows.Forms.SplitContainer();
|
||||
this.btnExport = new System.Windows.Forms.Button();
|
||||
this.btnImport = new System.Windows.Forms.Button();
|
||||
this.cboImporters = new System.Windows.Forms.ComboBox();
|
||||
this.txtName = new System.Windows.Forms.TextBox();
|
||||
this.btnLoad = new System.Windows.Forms.Button();
|
||||
this.btnSave = new System.Windows.Forms.Button();
|
||||
@@ -56,6 +59,9 @@
|
||||
//
|
||||
// splitWindow.Panel1
|
||||
//
|
||||
this.splitWindow.Panel1.Controls.Add(this.btnExport);
|
||||
this.splitWindow.Panel1.Controls.Add(this.btnImport);
|
||||
this.splitWindow.Panel1.Controls.Add(this.cboImporters);
|
||||
this.splitWindow.Panel1.Controls.Add(this.txtName);
|
||||
this.splitWindow.Panel1.Controls.Add(this.btnLoad);
|
||||
this.splitWindow.Panel1.Controls.Add(this.btnSave);
|
||||
@@ -76,6 +82,35 @@
|
||||
this.splitWindow.SplitterDistance = 442;
|
||||
this.splitWindow.TabIndex = 0;
|
||||
//
|
||||
// btnExport
|
||||
//
|
||||
this.btnExport.Location = new System.Drawing.Point(365, 6);
|
||||
this.btnExport.Name = "btnExport";
|
||||
this.btnExport.Size = new System.Drawing.Size(40, 21);
|
||||
this.btnExport.TabIndex = 8;
|
||||
this.btnExport.Text = "Exp";
|
||||
this.btnExport.UseVisualStyleBackColor = true;
|
||||
this.btnExport.Click += new System.EventHandler(this.btnExport_Click);
|
||||
//
|
||||
// btnImport
|
||||
//
|
||||
this.btnImport.Location = new System.Drawing.Point(319, 6);
|
||||
this.btnImport.Name = "btnImport";
|
||||
this.btnImport.Size = new System.Drawing.Size(40, 21);
|
||||
this.btnImport.TabIndex = 7;
|
||||
this.btnImport.Text = "Imp";
|
||||
this.btnImport.UseVisualStyleBackColor = true;
|
||||
this.btnImport.Click += new System.EventHandler(this.btnImport_Click);
|
||||
//
|
||||
// cboImporters
|
||||
//
|
||||
this.cboImporters.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.cboImporters.FormattingEnabled = true;
|
||||
this.cboImporters.Location = new System.Drawing.Point(224, 6);
|
||||
this.cboImporters.Name = "cboImporters";
|
||||
this.cboImporters.Size = new System.Drawing.Size(89, 21);
|
||||
this.cboImporters.TabIndex = 6;
|
||||
//
|
||||
// txtName
|
||||
//
|
||||
this.txtName.ImeMode = System.Windows.Forms.ImeMode.Disable;
|
||||
@@ -83,12 +118,13 @@
|
||||
this.txtName.Name = "txtName";
|
||||
this.txtName.Size = new System.Drawing.Size(104, 20);
|
||||
this.txtName.TabIndex = 5;
|
||||
this.txtName.TextChanged += new System.EventHandler(this.txtName_TextChanged);
|
||||
//
|
||||
// btnLoad
|
||||
//
|
||||
this.btnLoad.Location = new System.Drawing.Point(113, 7);
|
||||
this.btnLoad.Name = "btnLoad";
|
||||
this.btnLoad.Size = new System.Drawing.Size(53, 20);
|
||||
this.btnLoad.Size = new System.Drawing.Size(43, 20);
|
||||
this.btnLoad.TabIndex = 4;
|
||||
this.btnLoad.Text = "Load";
|
||||
this.btnLoad.UseVisualStyleBackColor = true;
|
||||
@@ -96,9 +132,9 @@
|
||||
//
|
||||
// btnSave
|
||||
//
|
||||
this.btnSave.Location = new System.Drawing.Point(172, 7);
|
||||
this.btnSave.Location = new System.Drawing.Point(162, 7);
|
||||
this.btnSave.Name = "btnSave";
|
||||
this.btnSave.Size = new System.Drawing.Size(57, 20);
|
||||
this.btnSave.Size = new System.Drawing.Size(41, 20);
|
||||
this.btnSave.TabIndex = 3;
|
||||
this.btnSave.Text = "Save";
|
||||
this.btnSave.UseVisualStyleBackColor = true;
|
||||
@@ -248,5 +284,8 @@
|
||||
private System.Windows.Forms.Button btnSave;
|
||||
private System.Windows.Forms.TextBox txtName;
|
||||
private System.Windows.Forms.Button btnLoad;
|
||||
private System.Windows.Forms.ComboBox cboImporters;
|
||||
private System.Windows.Forms.Button btnExport;
|
||||
private System.Windows.Forms.Button btnImport;
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,9 @@ using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using VAR.Json;
|
||||
using VAR.Toolbox.Code;
|
||||
|
||||
namespace VAR.Toolbox.UI.Tools
|
||||
namespace VAR.Toolbox.UI.Tools.WorkLog
|
||||
{
|
||||
public partial class FrmWorkLog : Form, IToolForm
|
||||
{
|
||||
@@ -25,6 +26,8 @@ namespace VAR.Toolbox.UI.Tools
|
||||
InitializeComponent();
|
||||
WorkLog_LoadConfig();
|
||||
WorkLog_LoadData();
|
||||
|
||||
cboImporters.Items.AddRange(WorkLogImporterFactory.GetNames());
|
||||
}
|
||||
|
||||
private void FrmWorkLog_FormClosing(object sender, FormClosingEventArgs e)
|
||||
@@ -36,8 +39,10 @@ namespace VAR.Toolbox.UI.Tools
|
||||
|
||||
#region UI events
|
||||
|
||||
private bool _selecting = false;
|
||||
|
||||
private void txtName_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
WorkLog_MarkDirty();
|
||||
}
|
||||
|
||||
private void btnLoad_Click(object sender, EventArgs e)
|
||||
{
|
||||
@@ -49,6 +54,48 @@ namespace VAR.Toolbox.UI.Tools
|
||||
WorkLog_SaveData();
|
||||
}
|
||||
|
||||
private void btnImport_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (cboImporters.SelectedItem == null) { return; }
|
||||
IWorkLogImporter workLogImporter = WorkLogImporterFactory.CreateFromName(cboImporters.SelectedItem as string);
|
||||
List<WorkLogItem> newWorkLog = workLogImporter.Import(this);
|
||||
if (newWorkLog != null)
|
||||
{
|
||||
_workLog = newWorkLog;
|
||||
WorkLog_Refresh();
|
||||
MessageBox.Show("OK");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(ex);
|
||||
MessageBox.Show("Error");
|
||||
}
|
||||
}
|
||||
|
||||
private void btnExport_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (cboImporters.SelectedItem == null) { return; }
|
||||
IWorkLogImporter workLogImporter = WorkLogImporterFactory.CreateFromName(cboImporters.SelectedItem as string);
|
||||
bool result = workLogImporter.Export(_workLog, this);
|
||||
if (result)
|
||||
{
|
||||
MessageBox.Show("OK");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(ex);
|
||||
MessageBox.Show("Error");
|
||||
}
|
||||
}
|
||||
|
||||
private bool _selecting = false;
|
||||
|
||||
private void lsbWorkLog_SelectedIndexChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
if (_selecting) { return; }
|
||||
@@ -341,6 +388,7 @@ namespace VAR.Toolbox.UI.Tools
|
||||
}
|
||||
|
||||
#endregion Private methods
|
||||
|
||||
}
|
||||
|
||||
public class WorkLogRow
|
||||
12
VAR.Toolbox/UI/Tools/WorkLog/IWorkLogImporter.cs
Normal file
12
VAR.Toolbox/UI/Tools/WorkLog/IWorkLogImporter.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using VAR.Toolbox.Code;
|
||||
|
||||
namespace VAR.Toolbox.UI.Tools.WorkLog
|
||||
{
|
||||
public interface IWorkLogImporter : INamed
|
||||
{
|
||||
List<WorkLogItem> Import(Form form);
|
||||
bool Export(List<WorkLogItem> items, Form form);
|
||||
}
|
||||
}
|
||||
94
VAR.Toolbox/UI/Tools/WorkLog/VARTextWorkLogImporter.cs
Normal file
94
VAR.Toolbox/UI/Tools/WorkLog/VARTextWorkLogImporter.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VAR.Toolbox.UI.Tools.WorkLog
|
||||
{
|
||||
public class VARTextWorkLogImporter : IWorkLogImporter
|
||||
{
|
||||
public string Name { get { return "VARText"; } }
|
||||
|
||||
public bool Export(List<WorkLogItem> items, Form form)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public List<WorkLogItem> Import(Form form)
|
||||
{
|
||||
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||
DialogResult dialogResult = openFileDialog.ShowDialog(form);
|
||||
if (dialogResult != DialogResult.OK) { return null; }
|
||||
|
||||
if (File.Exists(openFileDialog.FileName) == false) { return null; }
|
||||
|
||||
string[] allLines = File.ReadAllLines(openFileDialog.FileName);
|
||||
Regex regex = new Regex(@"(\d\d)_(\d\d)_(\d\d)\s-\s(\d\d)_(\d\d)_(\d\d)\s(.*)");
|
||||
|
||||
DateTime currentDateStart = DateTime.MinValue;
|
||||
WorkLogItem currentWorkLog = null;
|
||||
List<WorkLogItem> workLog = new List<WorkLogItem>();
|
||||
|
||||
foreach (string line in allLines)
|
||||
{
|
||||
string lineAux = line.Trim();
|
||||
if (string.IsNullOrEmpty(lineAux)) { continue; }
|
||||
|
||||
if (lineAux.StartsWith("--- "))
|
||||
{
|
||||
string strDate = lineAux.Substring(4);
|
||||
string[] strDateParts = strDate.Split('-');
|
||||
if (strDateParts.Length >= 3 && strDateParts[0].Length == 4 && strDateParts[1].Length == 2 && strDateParts[2].Length == 2)
|
||||
{
|
||||
currentDateStart = new DateTime(Convert.ToInt32(strDateParts[0]), Convert.ToInt32(strDateParts[1]), Convert.ToInt32(strDateParts[2]), 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (lineAux.StartsWith("--"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Match match = regex.Match(lineAux);
|
||||
if (match.Groups.Count < 7)
|
||||
{
|
||||
if (currentWorkLog != null)
|
||||
{
|
||||
currentWorkLog.Description += lineAux + "\n";
|
||||
}
|
||||
continue;
|
||||
}
|
||||
int startDay = Convert.ToInt32(match.Groups[1].Value);
|
||||
int startHour = Convert.ToInt32(match.Groups[2].Value);
|
||||
int startMinute = Convert.ToInt32(match.Groups[3].Value);
|
||||
int endDay = Convert.ToInt32(match.Groups[4].Value);
|
||||
int endHour = Convert.ToInt32(match.Groups[5].Value);
|
||||
int endMinute = Convert.ToInt32(match.Groups[6].Value);
|
||||
string activity = match.Groups[7].Value;
|
||||
|
||||
DateTime dateTime = currentDateStart;
|
||||
if (dateTime.Day > startDay)
|
||||
{
|
||||
dateTime.AddMonths(1);
|
||||
}
|
||||
|
||||
currentWorkLog = new WorkLogItem
|
||||
{
|
||||
DateStart = new DateTime(dateTime.Year, dateTime.Month, startDay, startHour, startMinute, 0),
|
||||
DateEnd = new DateTime(dateTime.Year, dateTime.Month, endDay, endHour, endMinute, 0),
|
||||
Activity = activity,
|
||||
Description = string.Empty,
|
||||
};
|
||||
workLog.Add(currentWorkLog);
|
||||
}
|
||||
}
|
||||
|
||||
return workLog;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
VAR.Toolbox/UI/Tools/WorkLog/WorkLogImporterFactory.cs
Normal file
8
VAR.Toolbox/UI/Tools/WorkLog/WorkLogImporterFactory.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using VAR.Toolbox.Code;
|
||||
|
||||
namespace VAR.Toolbox.UI.Tools.WorkLog
|
||||
{
|
||||
public class WorkLogImporterFactory : BaseFactory<IWorkLogImporter>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -196,10 +196,10 @@
|
||||
<DependentUpon>FrmWebcam.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UI\IToolForm.cs" />
|
||||
<Compile Include="UI\Tools\FrmWorkLog.cs">
|
||||
<Compile Include="UI\Tools\WorkLog\FrmWorkLog.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="UI\Tools\FrmWorkLog.Designer.cs">
|
||||
<Compile Include="UI\Tools\WorkLog\FrmWorkLog.Designer.cs">
|
||||
<DependentUpon>FrmWorkLog.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UI\Tools\PnlActivity.cs">
|
||||
@@ -220,6 +220,9 @@
|
||||
<Compile Include="UI\Tools\PnlSuspension.Designer.cs">
|
||||
<DependentUpon>PnlSuspension.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UI\Tools\WorkLog\IWorkLogImporter.cs" />
|
||||
<Compile Include="UI\Tools\WorkLog\VARTextWorkLogImporter.cs" />
|
||||
<Compile Include="UI\Tools\WorkLog\WorkLogImporterFactory.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.manifest" />
|
||||
|
||||
Reference in New Issue
Block a user