This commit is contained in:
Tyrel Souza 2022-09-28 23:48:04 -04:00
parent ac2a10ee01
commit 97bf00c0f9
4 changed files with 82 additions and 58 deletions

View File

@ -23,7 +23,7 @@
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.ofdFile = new System.Windows.Forms.OpenFileDialog();
this.btnFile = new System.Windows.Forms.Button();
this.lblFilename = new System.Windows.Forms.Label();
this.btnParse = new System.Windows.Forms.Button();
@ -31,10 +31,10 @@
this.lblContents = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// openFileDialog1
// ofdFile
//
this.openFileDialog1.FileName = "openFileDialog1";
this.openFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.openFileDialog1_FileOk);
this.ofdFile.FileName = "openFileDialog1";
this.ofdFile.FileOk += new System.ComponentModel.CancelEventHandler(this.openFileDialog1_FileOk);
//
// btnFile
//
@ -45,6 +45,7 @@
this.btnFile.TabIndex = 0;
this.btnFile.Text = "Open File";
this.btnFile.UseVisualStyleBackColor = true;
this.btnFile.Click += new System.EventHandler(this.btnFile_Click);
//
// lblFilename
//
@ -111,7 +112,7 @@
#endregion
private OpenFileDialog openFileDialog1;
private OpenFileDialog ofdFile;
private Button btnFile;
private Label lblFilename;
private Button btnParse;

View File

@ -1,6 +1,8 @@
using BenchtopParser;
namespace BTD_PDF {
// Easy enum for switches
enum Parser {
ProgramConfig,
TransducerVerify,
@ -11,14 +13,16 @@ namespace BTD_PDF {
string? fileName = null;
Parser? parser = null;
private void setParseEnabled() {
if (fileName != null && fileName.Length > 0) {
if (parser != null) {
btnParse.Enabled = true;
}
}
/* Initialization */
public ConfigToPDF() {
InitializeComponent();
this.AllowDrop = true;
this.DragEnter += new DragEventHandler(ConfigToPDF_DragEnter);
this.DragDrop += new DragEventHandler(ConfigToPDF_DragDrop);
this.ofdFile.Title = "Select a File";
}
/* Events */
void ConfigToPDF_DragEnter(object sender, DragEventArgs e) {
if (!e.Data.GetDataPresent(DataFormats.FileDrop)) {
return;
@ -30,62 +34,23 @@ namespace BTD_PDF {
void ConfigToPDF_DragDrop(object sender, DragEventArgs e) {
IDataObject? data = e.Data;
string[] files = (string[])data.GetData(DataFormats.FileDrop);
fileName = files[0];
if (fileName != null) {
lblFilename.Text = fileName;
parser = null;
comboParser.SelectedItem = null;
}
setFilename(files[0]);
}
public ConfigToPDF() {
InitializeComponent();
this.AllowDrop = true;
this.DragEnter += new DragEventHandler(ConfigToPDF_DragEnter);
this.DragDrop += new DragEventHandler(ConfigToPDF_DragDrop);
}
/* Interactions */
private void openFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e) {
this.Activate();
string[] files = ofdFile.FileNames;
setFilename(files[0]);
}
private void btnParse_Click(object sender, EventArgs e) {
if (fileName == null) {
return;
}
var contents = File.ReadAllText(Path.Combine(fileName));
switch (parser) {
case Parser.ProgramConfig:
parseProgramConfig(contents);
break;
case Parser.HardwareCalibrationReport:
parseHardwareCalibrationReport(contents);
break;
case Parser.TransducerVerify:
parseTransducerVerify(contents);
break;
if (fileName != null) {
parse();
}
}
private void parseProgramConfig(string contents) {
ProgramConfig pc = new ProgramConfig(contents);
Console.WriteLine("Parsed PC");
lblContents.Text = pc.Programs["P1"].ProgramNumber;
}
private void parseHardwareCalibrationReport(string contents) {
HardwareCalibrationReport hr = new HardwareCalibrationReport(contents);
Console.WriteLine("Parsed HR");
lblContents.Text = hr.Instrument.Name;
}
private void parseTransducerVerify(string contents) {
TransducerVerify tv = new TransducerVerify(contents);
Console.WriteLine("Parsed TV");
lblContents.Text = tv.Transducers[1].Name;
}
private void comboParser_SelectedIndexChanged(object sender, EventArgs e) {
string value = comboParser.Text;
switch (value) {
@ -102,7 +67,58 @@ namespace BTD_PDF {
setParseEnabled();
}
private void btnFile_Click(object sender, EventArgs e) {
ofdFile.ShowDialog();
}
/* Methods */
private void setParseEnabled() {
if (fileName != null && fileName.Length > 0) {
if (parser != null) {
btnParse.Enabled = true;
}
}
}
private void setFilename(string? _fileName) {
if (_fileName != null) {
fileName = _fileName;
lblFilename.Text = fileName;
parser = null;
comboParser.SelectedItem = null;
}
}
private void parse() {
var contents = File.ReadAllText(fileName);
switch (parser) {
case Parser.ProgramConfig:
parseProgramConfig(contents);
break;
case Parser.HardwareCalibrationReport:
parseHardwareCalibrationReport(contents);
break;
case Parser.TransducerVerify:
parseTransducerVerify(contents);
break;
}
}
private void parseProgramConfig(string contents) {
ProgramConfig pc = new ProgramConfig(contents);
Console.WriteLine("Parsed PC");
lblContents.Text = pc.Programs["P1"].ProgramNumber;
}
private void parseHardwareCalibrationReport(string contents) {
HardwareCalibrationReport hr = new HardwareCalibrationReport(contents);
Console.WriteLine("Parsed HR");
lblContents.Text = hr.Instrument.Name;
}
private void parseTransducerVerify(string contents) {
TransducerVerify tv = new TransducerVerify(contents);
Console.WriteLine("Parsed TV");
lblContents.Text = tv.Transducers[1].Name;
}
}
}

View File

@ -57,7 +57,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="ofdFile.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

7
LICENSE Normal file
View File

@ -0,0 +1,7 @@
Copyright 2022 Tyrel Souza
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.