Setup base form

This commit is contained in:
Jannick van Ballegooijen
2015-10-04 13:56:48 +02:00
parent 3da8a0cbf2
commit 0f87314642
22 changed files with 437 additions and 597 deletions
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
VisualStudioVersion = 14.0.22823.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ErgometerApplication", "ErgometerApplication\ErgometerApplication.csproj", "{1191E100-AA1B-4F41-85E2-EC2BE8ED39FD}"
EndProject
@@ -0,0 +1,102 @@
using System.IO.Ports;
namespace ErgometerApplication
{
partial class ClientApplicatie
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.updateTimer = new System.Windows.Forms.Timer(this.components);
this.writeTimer = new System.Windows.Forms.Timer(this.components);
this.panelLogin = new System.Windows.Forms.Panel();
this.lblUsername = new System.Windows.Forms.Label();
this.lblPassword = new System.Windows.Forms.Label();
this.panelLogin.SuspendLayout();
this.SuspendLayout();
//
// updateTimer
//
this.updateTimer.Interval = 1500;
//
// writeTimer
//
this.writeTimer.Interval = 10000;
//
// panelLogin
//
this.panelLogin.Controls.Add(this.lblUsername);
this.panelLogin.Controls.Add(this.lblPassword);
this.panelLogin.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelLogin.Location = new System.Drawing.Point(0, 0);
this.panelLogin.Name = "panelLogin";
this.panelLogin.Size = new System.Drawing.Size(800, 600);
this.panelLogin.TabIndex = 0;
//
// lblUsername
//
this.lblUsername.Anchor = System.Windows.Forms.AnchorStyles.None;
this.lblUsername.AutoSize = true;
this.lblUsername.Location = new System.Drawing.Point(243, 255);
this.lblUsername.Name = "lblUsername";
this.lblUsername.Size = new System.Drawing.Size(84, 13);
this.lblUsername.TabIndex = 1;
this.lblUsername.Text = "Gebruikersnaam";
//
// lblPassword
//
this.lblPassword.Anchor = System.Windows.Forms.AnchorStyles.None;
this.lblPassword.AutoSize = true;
this.lblPassword.Location = new System.Drawing.Point(243, 291);
this.lblPassword.Name = "lblPassword";
this.lblPassword.Size = new System.Drawing.Size(68, 13);
this.lblPassword.TabIndex = 0;
this.lblPassword.Text = "Wachtwoord";
//
// ClientApplicatie
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 600);
this.Controls.Add(this.panelLogin);
this.Name = "ClientApplicatie";
this.Text = "Client Applicatie";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.panelLogin.ResumeLayout(false);
this.panelLogin.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Timer updateTimer;
private System.Windows.Forms.Timer writeTimer;
private System.Windows.Forms.Panel panelLogin;
private System.Windows.Forms.Label lblUsername;
private System.Windows.Forms.Label lblPassword;
}
}
@@ -0,0 +1,282 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
using System.IO;
//using ErgometerLibrary;
using System.Net.Sockets;
using System.Net;
using System.Timers;
namespace ErgometerApplication
{
public partial class ClientApplicatie : Form
{
//private ComPort comPort;
//private List<Meting> _data;
//private int i = 0;
//NetCommand command;
//private ServerCommunicator communicator = new ServerCommunicator();
//List<Meting> readFile = new List<Meting>();
public ClientApplicatie()
{
InitializeComponent();
// comPort = new ComPort();
// _data = new List<Meting>();
// communicator.data = _data;
}
//private void connectButton_Click(object sender, EventArgs e)
//{
// if (!comPort.IsOpen())
// {
// if (comPort.Connect(ComPortBox.Text))
// {
// connectButton.Text = "Disconnect";
// statusButton.Enabled = true;
// resetButton.Enabled = true;
// timerStatus.Enabled = true;
// inputTextBox.Enabled = true;
// timeButton.Enabled = true;
// distanceButton.Enabled = true;
// powerButton.Enabled = true;
// energyButton.Enabled = true;
// ComPortBox.Enabled = false;
// comPort.Write("RS");
// comPort.Read();
// Thread.Sleep(200);
// comPort.Write("CM");
// comPort.Read();
// Thread.Sleep(200);
// comPort.Write("ST");
// string response = comPort.Read();
// Console.WriteLine(response);
// Meting m = Meting.Parse(response);
// SaveData(m);
// // richTextBox1.Text = m.ToString();
// }
// }
// else
// {
// if (comPort.Disconnect())
// {
// connectButton.Text = "Connect";
// timerStatus.Checked = false;
// statusButton.Enabled = false;
// resetButton.Enabled = false;
// timerStatus.Enabled = false;
// inputTextBox.Enabled = false;
// timeButton.Enabled = false;
// distanceButton.Enabled = false;
// powerButton.Enabled = false;
// energyButton.Enabled = false;
// ComPortBox.Enabled = true;
// richTextBox1.Text = "";
// WriteFile();
// }
// }
// communicator.client = new TcpClient();
// communicator.client.Connect("127.0.0.1", 8888);
// Thread thread = new Thread(ServerCommunication);
// thread.Start(communicator);
//}
//private void statusButton_Click(object sender, EventArgs e)
//{
// comPort.Write("ST");
// string response = comPort.Read();
// Console.WriteLine(response);
// Meting m = Meting.Parse(response, '\t');
// Console.WriteLine(m);
// SaveData(m);
// communicator.data.Add(m);
// command = new NetCommand(m, communicator.sessionId);
// NetHelper.SendNetCommand(communicator.client, command);
// richTextBox1.Text = m.ToString();
// WriteFile();
//}
//static void ServerCommunication(object obj)
//{
// ServerCommunicator communicator = obj as ServerCommunicator;
// NetCommand net = NetHelper.ReadNetCommand(communicator.client);
// if (net.Type == NetCommand.CommandType.SESSION)
// communicator.sessionId = net.Session;
// NetCommand command = new NetCommand("name", false, "pass", communicator.sessionId);
// NetHelper.SendNetCommand(communicator.client, command);
//}
//private void resetButton_Click(object sender, EventArgs e)
//{
// comPort.Write("RS");
// comPort.Read();
// Thread.Sleep(200);
// comPort.Write("CM");
// comPort.Read();
//}
//private void updateTimer_Tick(object sender, EventArgs e)
//{
// if (timerStatus.Checked)
// {
// comPort.Write("ST");
// string response = comPort.Read();
// Console.WriteLine(response);
// Meting m = Meting.Parse(response);
// SaveData(m);
// communicator.data.Add(m);
// command = new NetCommand(m, communicator.sessionId);
// NetHelper.SendNetCommand(communicator.client, command);
// richTextBox1.Text = m.ToString();
// command = new NetCommand(communicator.data[0], communicator.sessionId);
// NetHelper.SendNetCommand(communicator.client, command);
// }
//}
//private void timeButton_Click(object sender, EventArgs e)
//{
// comPort.Write("RS");
// comPort.Read();
// Thread.Sleep(200);
// string[] temp = inputTextBox.Text.Split(':');
// comPort.Write("PT " + temp[0] + temp[1]);
// Console.WriteLine("PT " + temp[0] + temp[1]);
// inputTextBox.Text = "";
// comPort.Read();
//}
//private void distanceButton_Click(object sender, EventArgs e)
//{
// comPort.Write("RS");
// comPort.Read();
// Thread.Sleep(200);
// int temp = int.Parse(inputTextBox.Text);
// comPort.Write("PD " + temp.ToString());
// inputTextBox.Text = "";
// comPort.Read();
//}
//private void powerButton_Click(object sender, EventArgs e)
//{
// int temp = int.Parse(inputTextBox.Text);
// comPort.Write("PW " + temp.ToString());
// inputTextBox.Text = "";
// comPort.Read();
//}
//private void energyButton_Click(object sender, EventArgs e)
//{
// comPort.Write("RS");
// comPort.Read();
// Thread.Sleep(200);
// int temp = int.Parse(inputTextBox.Text);
// comPort.Write("PE " + temp.ToString());
// inputTextBox.Text = "";
// comPort.Read();
//}
//private void timerStatus_CheckedChanged(object sender, EventArgs e)
//{
// if (timerStatus.Checked)
// {
// statusButton.Enabled = false;
// updateTimer.Start();
// writeTimer.Start();
// }
// else
// {
// statusButton.Enabled = true;
// updateTimer.Stop();
// writeTimer.Stop();
// }
//}
//private void readButton_Click(object sender, EventArgs e)
//{
// ReadFile();
// if (readFile != null)
// {
// metingNextButton.Enabled = true;
// metingBackButton.Enabled = true;
// }
//}
//private void metingBackButton_Click(object sender, EventArgs e)
//{
// if (i > 0)
// { i--;
// metingNextButton.Enabled = true;
// }
// if (i == 0)
// {
// metingBackButton.Enabled = false;
// }
// richTextBox1.Text = readFile.ElementAt(i).ToString();
//}
//private void metingNextButton_Click(object sender, EventArgs e)
//{
// if (i < (readFile.Count - 1))
// { i++;
// metingBackButton.Enabled = true;
// }
// if (i == (readFile.Count - 1))
// {
// metingNextButton.Enabled = false;
// }
// richTextBox1.Text = readFile.ElementAt(i).ToString();
//}
//private void writeTimer_Tick(object sender, EventArgs e)
//{
// WriteFile();
//}
//private void WriteFile()
//{
// string json = Newtonsoft.Json.JsonConvert.SerializeObject(_data);
// string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "ErgometerSessionData.ergo");
// System.IO.File.WriteAllText(path, json);
// Console.WriteLine("Writing file: " + path);
//}
//private void SaveData(Meting meting)
//{
// _data.Add(meting);
//}
//private void ReadFile()
//{
// string path;
// OpenFileDialog file = new OpenFileDialog();
// file.Filter = "Ergometer files(*.ergo) | *.ergo | All files(*.*) | *.*";
// if (file.ShowDialog() == DialogResult.OK)
// {
// path = file.FileName;
// readFile = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Meting>>(System.IO.File.ReadAllText(path));
// richTextBox1.Text = readFile.ElementAt(i).ToString();
// }
// else
// {
// readFile = null;
// }
//}
}
}
@@ -123,10 +123,7 @@
<metadata name="writeTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>147, 19</value>
</metadata>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>276, 19</value>
</metadata>
<metadata name="timer2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>377, 19</value>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value>
</metadata>
</root>
@@ -5,41 +5,41 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ErgometerLibrary;
//using ErgometerLibrary;
namespace ErgometerApplication
{
class DataSaving
{
List<Meting> local_data = null;
private List<Meting> ReadFile()
{
string path;
OpenFileDialog file = new OpenFileDialog();
file.Filter = "Ergometer files(*.ergo) | *.ergo | All files(*.*) | *.*";
if (file.ShowDialog() == DialogResult.OK)
{
path = file.FileName;
List<Meting> readFile = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Meting>>(System.IO.File.ReadAllText(path));
return readFile;
}
else
{
return null;
}
}
private List<Meting> SaveData(Meting meting, List<Meting> _data)
{
List<Meting> local_data = _data;
local_data.Add(meting);
return local_data;
}
private void WriteFile(List<Meting> _data)
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(_data);
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "ErgometerSessionData.ergo");
System.IO.File.WriteAllText(path, json);
Console.WriteLine("Writing file: " + path);
}
//List<Meting> local_data = null;
//private List<Meting> ReadFile()
//{
// string path;
// OpenFileDialog file = new OpenFileDialog();
// file.Filter = "Ergometer files(*.ergo) | *.ergo | All files(*.*) | *.*";
// if (file.ShowDialog() == DialogResult.OK)
// {
// path = file.FileName;
// List<Meting> readFile = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Meting>>(System.IO.File.ReadAllText(path));
// return readFile;
// }
// else
// {
// return null;
// }
//}
//private List<Meting> SaveData(Meting meting, List<Meting> _data)
//{
// List<Meting> local_data = _data;
// local_data.Add(meting);
// return local_data;
//}
//private void WriteFile(List<Meting> _data)
//{
// string json = Newtonsoft.Json.JsonConvert.SerializeObject(_data);
// string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "ErgometerSessionData.ergo");
// System.IO.File.WriteAllText(path, json);
// Console.WriteLine("Writing file: " + path);
//}
}
@@ -1,270 +0,0 @@
using System.IO.Ports;
namespace ErgometerApplication
{
partial class Ergometer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.connectButton = new System.Windows.Forms.Button();
this.ComPortBox = new System.Windows.Forms.ComboBox();
this.statusButton = new System.Windows.Forms.Button();
this.resetButton = new System.Windows.Forms.Button();
this.updateTimer = new System.Windows.Forms.Timer(this.components);
this.timerStatus = new System.Windows.Forms.CheckBox();
this.powerButton = new System.Windows.Forms.Button();
this.timeButton = new System.Windows.Forms.Button();
this.energyButton = new System.Windows.Forms.Button();
this.distanceButton = new System.Windows.Forms.Button();
this.writeTimer = new System.Windows.Forms.Timer(this.components);
this.metingNextButton = new System.Windows.Forms.Button();
this.metingBackButton = new System.Windows.Forms.Button();
this.readButton = new System.Windows.Forms.Button();
this.inputTextBox = new System.Windows.Forms.MaskedTextBox();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(13, 42);
this.richTextBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.ReadOnly = true;
this.richTextBox1.Size = new System.Drawing.Size(203, 243);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
// connectButton
//
this.connectButton.Location = new System.Drawing.Point(115, 290);
this.connectButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.connectButton.Name = "connectButton";
this.connectButton.Size = new System.Drawing.Size(101, 26);
this.connectButton.TabIndex = 1;
this.connectButton.Text = "Connect";
this.connectButton.UseVisualStyleBackColor = true;
this.connectButton.Click += new System.EventHandler(this.connectButton_Click);
//
// ComPortBox
//
this.ComPortBox.FormattingEnabled = true;
this.ComPortBox.Items.AddRange(SerialPort.GetPortNames());
this.ComPortBox.Location = new System.Drawing.Point(12, 290);
this.ComPortBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.ComPortBox.Name = "ComPortBox";
this.ComPortBox.Size = new System.Drawing.Size(97, 24);
this.ComPortBox.TabIndex = 11;
//
// statusButton
//
this.statusButton.Enabled = false;
this.statusButton.Location = new System.Drawing.Point(127, 12);
this.statusButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.statusButton.Name = "statusButton";
this.statusButton.Size = new System.Drawing.Size(89, 26);
this.statusButton.TabIndex = 3;
this.statusButton.Text = "Status";
this.statusButton.UseVisualStyleBackColor = true;
this.statusButton.Click += new System.EventHandler(this.statusButton_Click);
//
// resetButton
//
this.resetButton.Enabled = false;
this.resetButton.Location = new System.Drawing.Point(12, 12);
this.resetButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.resetButton.Name = "resetButton";
this.resetButton.Size = new System.Drawing.Size(97, 26);
this.resetButton.TabIndex = 4;
this.resetButton.Text = "Reset";
this.resetButton.UseVisualStyleBackColor = true;
this.resetButton.Click += new System.EventHandler(this.resetButton_Click);
//
// updateTimer
//
this.updateTimer.Interval = 1500;
this.updateTimer.Tick += new System.EventHandler(this.updateTimer_Tick);
//
// timerStatus
//
this.timerStatus.AutoSize = true;
this.timerStatus.Enabled = false;
this.timerStatus.Location = new System.Drawing.Point(223, 12);
this.timerStatus.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.timerStatus.Name = "timerStatus";
this.timerStatus.Size = new System.Drawing.Size(113, 21);
this.timerStatus.TabIndex = 5;
this.timerStatus.Text = "Auto Refresh";
this.timerStatus.UseVisualStyleBackColor = true;
this.timerStatus.CheckedChanged += new System.EventHandler(this.timerStatus_CheckedChanged);
//
// powerButton
//
this.powerButton.Enabled = false;
this.powerButton.Location = new System.Drawing.Point(223, 134);
this.powerButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.powerButton.Name = "powerButton";
this.powerButton.Size = new System.Drawing.Size(113, 26);
this.powerButton.TabIndex = 7;
this.powerButton.Text = "Set Power";
this.powerButton.UseVisualStyleBackColor = true;
this.powerButton.Click += new System.EventHandler(this.powerButton_Click);
//
// timeButton
//
this.timeButton.Enabled = false;
this.timeButton.Location = new System.Drawing.Point(223, 70);
this.timeButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.timeButton.Name = "timeButton";
this.timeButton.Size = new System.Drawing.Size(113, 26);
this.timeButton.TabIndex = 8;
this.timeButton.Text = "Set Time";
this.timeButton.UseVisualStyleBackColor = true;
this.timeButton.Click += new System.EventHandler(this.timeButton_Click);
//
// energyButton
//
this.energyButton.Enabled = false;
this.energyButton.Location = new System.Drawing.Point(223, 166);
this.energyButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.energyButton.Name = "energyButton";
this.energyButton.Size = new System.Drawing.Size(113, 26);
this.energyButton.TabIndex = 9;
this.energyButton.Text = "Set Energy";
this.energyButton.UseVisualStyleBackColor = true;
this.energyButton.Click += new System.EventHandler(this.energyButton_Click);
//
// distanceButton
//
this.distanceButton.Enabled = false;
this.distanceButton.Location = new System.Drawing.Point(223, 102);
this.distanceButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.distanceButton.Name = "distanceButton";
this.distanceButton.Size = new System.Drawing.Size(113, 26);
this.distanceButton.TabIndex = 10;
this.distanceButton.Text = "Set Distance";
this.distanceButton.UseVisualStyleBackColor = true;
this.distanceButton.Click += new System.EventHandler(this.distanceButton_Click);
//
// writeTimer
//
this.writeTimer.Interval = 10000;
this.writeTimer.Tick += new System.EventHandler(this.writeTimer_Tick);
//
// metingNextButton
//
this.metingNextButton.Enabled = false;
this.metingNextButton.Location = new System.Drawing.Point(223, 289);
this.metingNextButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.metingNextButton.Name = "metingNextButton";
this.metingNextButton.Size = new System.Drawing.Size(113, 26);
this.metingNextButton.TabIndex = 16;
this.metingNextButton.Text = "Next ->";
this.metingNextButton.UseVisualStyleBackColor = true;
this.metingNextButton.Click += new System.EventHandler(this.metingNextButton_Click);
//
// metingBackButton
//
this.metingBackButton.Enabled = false;
this.metingBackButton.Location = new System.Drawing.Point(223, 258);
this.metingBackButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.metingBackButton.Name = "metingBackButton";
this.metingBackButton.Size = new System.Drawing.Size(113, 26);
this.metingBackButton.TabIndex = 15;
this.metingBackButton.Text = "<- Back";
this.metingBackButton.UseVisualStyleBackColor = true;
this.metingBackButton.Click += new System.EventHandler(this.metingBackButton_Click);
//
// readButton
//
this.readButton.Location = new System.Drawing.Point(223, 228);
this.readButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.readButton.Name = "readButton";
this.readButton.Size = new System.Drawing.Size(113, 26);
this.readButton.TabIndex = 17;
this.readButton.Text = "Read File";
this.readButton.UseVisualStyleBackColor = true;
this.readButton.Click += new System.EventHandler(this.readButton_Click);
//
// inputTextBox
//
this.inputTextBox.Location = new System.Drawing.Point(223, 43);
this.inputTextBox.Mask = "0L0L0L0";
this.inputTextBox.Name = "inputTextBox";
this.inputTextBox.Size = new System.Drawing.Size(106, 22);
this.inputTextBox.TabIndex = 18;
this.inputTextBox.ValidatingType = typeof(int);
//
// Ergometer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(351, 326);
this.Controls.Add(this.inputTextBox);
this.Controls.Add(this.readButton);
this.Controls.Add(this.metingNextButton);
this.Controls.Add(this.metingBackButton);
this.Controls.Add(this.distanceButton);
this.Controls.Add(this.energyButton);
this.Controls.Add(this.timeButton);
this.Controls.Add(this.powerButton);
this.Controls.Add(this.timerStatus);
this.Controls.Add(this.resetButton);
this.Controls.Add(this.statusButton);
this.Controls.Add(this.ComPortBox);
this.Controls.Add(this.connectButton);
this.Controls.Add(this.richTextBox1);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.MaximumSize = new System.Drawing.Size(369, 373);
this.MinimumSize = new System.Drawing.Size(369, 373);
this.Name = "Ergometer";
this.Text = "Ergometer";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Button connectButton;
private System.Windows.Forms.ComboBox ComPortBox;
private System.Windows.Forms.Button statusButton;
private System.Windows.Forms.Button resetButton;
private System.Windows.Forms.Timer updateTimer;
private System.Windows.Forms.CheckBox timerStatus;
private System.Windows.Forms.Button powerButton;
private System.Windows.Forms.Button timeButton;
private System.Windows.Forms.Button energyButton;
private System.Windows.Forms.Button distanceButton;
private System.Windows.Forms.Timer writeTimer;
private System.Windows.Forms.Button metingNextButton;
private System.Windows.Forms.Button metingBackButton;
private System.Windows.Forms.Button readButton;
private System.Windows.Forms.MaskedTextBox inputTextBox;
}
}
@@ -1,282 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
using System.IO;
using ErgometerLibrary;
using System.Net.Sockets;
using System.Net;
using System.Timers;
namespace ErgometerApplication
{
public partial class Ergometer : Form
{
private ComPort comPort;
private List<Meting> _data;
private int i = 0;
NetCommand command;
private ServerCommunicator communicator = new ServerCommunicator();
List<Meting> readFile = new List<Meting>();
public Ergometer()
{
InitializeComponent();
comPort = new ComPort();
_data = new List<Meting>();
communicator.data = _data;
}
private void connectButton_Click(object sender, EventArgs e)
{
if (!comPort.IsOpen())
{
if (comPort.Connect(ComPortBox.Text))
{
connectButton.Text = "Disconnect";
statusButton.Enabled = true;
resetButton.Enabled = true;
timerStatus.Enabled = true;
inputTextBox.Enabled = true;
timeButton.Enabled = true;
distanceButton.Enabled = true;
powerButton.Enabled = true;
energyButton.Enabled = true;
ComPortBox.Enabled = false;
comPort.Write("RS");
comPort.Read();
Thread.Sleep(200);
comPort.Write("CM");
comPort.Read();
Thread.Sleep(200);
comPort.Write("ST");
string response = comPort.Read();
Console.WriteLine(response);
Meting m = Meting.Parse(response);
SaveData(m);
// richTextBox1.Text = m.ToString();
}
}
else
{
if (comPort.Disconnect())
{
connectButton.Text = "Connect";
timerStatus.Checked = false;
statusButton.Enabled = false;
resetButton.Enabled = false;
timerStatus.Enabled = false;
inputTextBox.Enabled = false;
timeButton.Enabled = false;
distanceButton.Enabled = false;
powerButton.Enabled = false;
energyButton.Enabled = false;
ComPortBox.Enabled = true;
richTextBox1.Text = "";
WriteFile();
}
}
communicator.client = new TcpClient();
communicator.client.Connect("127.0.0.1", 8888);
Thread thread = new Thread(ServerCommunication);
thread.Start(communicator);
}
private void statusButton_Click(object sender, EventArgs e)
{
comPort.Write("ST");
string response = comPort.Read();
Console.WriteLine(response);
Meting m = Meting.Parse(response, '\t');
Console.WriteLine(m);
SaveData(m);
communicator.data.Add(m);
command = new NetCommand(m, communicator.sessionId);
NetHelper.SendNetCommand(communicator.client, command);
richTextBox1.Text = m.ToString();
WriteFile();
}
static void ServerCommunication(object obj)
{
ServerCommunicator communicator = obj as ServerCommunicator;
NetCommand net = NetHelper.ReadNetCommand(communicator.client);
if (net.Type == NetCommand.CommandType.SESSION)
communicator.sessionId = net.Session;
NetCommand command = new NetCommand("name", false, "pass", communicator.sessionId);
NetHelper.SendNetCommand(communicator.client, command);
}
private void resetButton_Click(object sender, EventArgs e)
{
comPort.Write("RS");
comPort.Read();
Thread.Sleep(200);
comPort.Write("CM");
comPort.Read();
}
private void updateTimer_Tick(object sender, EventArgs e)
{
if (timerStatus.Checked)
{
comPort.Write("ST");
string response = comPort.Read();
Console.WriteLine(response);
Meting m = Meting.Parse(response);
SaveData(m);
communicator.data.Add(m);
command = new NetCommand(m, communicator.sessionId);
NetHelper.SendNetCommand(communicator.client, command);
richTextBox1.Text = m.ToString();
command = new NetCommand(communicator.data[0], communicator.sessionId);
NetHelper.SendNetCommand(communicator.client, command);
}
}
private void timeButton_Click(object sender, EventArgs e)
{
comPort.Write("RS");
comPort.Read();
Thread.Sleep(200);
string[] temp = inputTextBox.Text.Split(':');
comPort.Write("PT " + temp[0] + temp[1]);
Console.WriteLine("PT " + temp[0] + temp[1]);
inputTextBox.Text = "";
comPort.Read();
}
private void distanceButton_Click(object sender, EventArgs e)
{
comPort.Write("RS");
comPort.Read();
Thread.Sleep(200);
int temp = int.Parse(inputTextBox.Text);
comPort.Write("PD " + temp.ToString());
inputTextBox.Text = "";
comPort.Read();
}
private void powerButton_Click(object sender, EventArgs e)
{
int temp = int.Parse(inputTextBox.Text);
comPort.Write("PW " + temp.ToString());
inputTextBox.Text = "";
comPort.Read();
}
private void energyButton_Click(object sender, EventArgs e)
{
comPort.Write("RS");
comPort.Read();
Thread.Sleep(200);
int temp = int.Parse(inputTextBox.Text);
comPort.Write("PE " + temp.ToString());
inputTextBox.Text = "";
comPort.Read();
}
private void timerStatus_CheckedChanged(object sender, EventArgs e)
{
if (timerStatus.Checked)
{
statusButton.Enabled = false;
updateTimer.Start();
writeTimer.Start();
}
else
{
statusButton.Enabled = true;
updateTimer.Stop();
writeTimer.Stop();
}
}
private void readButton_Click(object sender, EventArgs e)
{
ReadFile();
if (readFile != null)
{
metingNextButton.Enabled = true;
metingBackButton.Enabled = true;
}
}
private void metingBackButton_Click(object sender, EventArgs e)
{
if (i > 0)
{ i--;
metingNextButton.Enabled = true;
}
if (i == 0)
{
metingBackButton.Enabled = false;
}
richTextBox1.Text = readFile.ElementAt(i).ToString();
}
private void metingNextButton_Click(object sender, EventArgs e)
{
if (i < (readFile.Count - 1))
{ i++;
metingBackButton.Enabled = true;
}
if (i == (readFile.Count - 1))
{
metingNextButton.Enabled = false;
}
richTextBox1.Text = readFile.ElementAt(i).ToString();
}
private void writeTimer_Tick(object sender, EventArgs e)
{
WriteFile();
}
private void WriteFile()
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(_data);
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "ErgometerSessionData.ergo");
System.IO.File.WriteAllText(path, json);
Console.WriteLine("Writing file: " + path);
}
private void SaveData(Meting meting)
{
_data.Add(meting);
}
private void ReadFile()
{
string path;
OpenFileDialog file = new OpenFileDialog();
file.Filter = "Ergometer files(*.ergo) | *.ergo | All files(*.*) | *.*";
if (file.ShowDialog() == DialogResult.OK)
{
path = file.FileName;
readFile = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Meting>>(System.IO.File.ReadAllText(path));
richTextBox1.Text = readFile.ElementAt(i).ToString();
}
else
{
readFile = null;
}
}
}
}
@@ -56,16 +56,16 @@
<ItemGroup>
<Compile Include="ServerCommunicator.cs" />
<Compile Include="DataSaving.cs" />
<Compile Include="Ergometer.cs">
<Compile Include="ClientApplicatie.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Ergometer.Designer.cs">
<DependentUpon>Ergometer.cs</DependentUpon>
<Compile Include="ClientApplicatie.Designer.cs">
<DependentUpon>ClientApplicatie.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Ergometer.resx">
<DependentUpon>Ergometer.cs</DependentUpon>
<EmbeddedResource Include="ClientApplicatie.resx">
<DependentUpon>ClientApplicatie.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
@@ -17,7 +17,7 @@ namespace ErgometerApplication
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Ergometer());
Application.Run(new ClientApplicatie());
}
}
}
@@ -5,7 +5,7 @@ using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using ErgometerLibrary;
//using ErgometerLibrary;
namespace ErgometerApplication
{
@@ -13,6 +13,6 @@ namespace ErgometerApplication
{
public TcpClient client { get; set; }
public int sessionId { get; set; }
public List<Meting> data { get; set; }
// public List<Meting> data { get; set; }
}
}
@@ -19,3 +19,14 @@ C:\Users\sander\Documents\GitHub\ErgometerApplication\ErgometerApplication\Ergom
C:\Users\sander\Documents\GitHub\ErgometerApplication\ErgometerApplication\ErgometerApplication\obj\Debug\ErgometerApplication.csproj.GenerateResource.Cache
C:\Users\sander\Documents\GitHub\ErgometerApplication\ErgometerApplication\ErgometerApplication\bin\Debug\ErgometerLibrary.dll
C:\Users\sander\Documents\GitHub\ErgometerApplication\ErgometerApplication\ErgometerApplication\bin\Debug\ErgometerLibrary.pdb
C:\Users\startklaar\Source\Repos\ErgometerApplication\ErgometerApplication\ErgometerApplication\bin\Debug\ErgometerApplication.exe.config
C:\Users\startklaar\Source\Repos\ErgometerApplication\ErgometerApplication\ErgometerApplication\bin\Debug\ErgometerApplication.exe
C:\Users\startklaar\Source\Repos\ErgometerApplication\ErgometerApplication\ErgometerApplication\bin\Debug\ErgometerApplication.pdb
C:\Users\startklaar\Source\Repos\ErgometerApplication\ErgometerApplication\ErgometerApplication\bin\Debug\Newtonsoft.Json.dll
C:\Users\startklaar\Source\Repos\ErgometerApplication\ErgometerApplication\ErgometerApplication\bin\Debug\Newtonsoft.Json.xml
C:\Users\startklaar\Source\Repos\ErgometerApplication\ErgometerApplication\ErgometerApplication\obj\Debug\ErgometerApplication.csprojResolveAssemblyReference.cache
C:\Users\startklaar\Source\Repos\ErgometerApplication\ErgometerApplication\ErgometerApplication\obj\Debug\ErgometerApplication.Properties.Resources.resources
C:\Users\startklaar\Source\Repos\ErgometerApplication\ErgometerApplication\ErgometerApplication\obj\Debug\ErgometerApplication.csproj.GenerateResource.Cache
C:\Users\startklaar\Source\Repos\ErgometerApplication\ErgometerApplication\ErgometerApplication\obj\Debug\ErgometerApplication.exe
C:\Users\startklaar\Source\Repos\ErgometerApplication\ErgometerApplication\ErgometerApplication\obj\Debug\ErgometerApplication.pdb
C:\Users\startklaar\Source\Repos\ErgometerApplication\ErgometerApplication\ErgometerApplication\obj\Debug\ErgometerApplication.ClientApplicatie.resources