Files
activestep/Step.UI/Dialogs/ResetSpindleForm.cs
2020-09-12 16:11:43 +02:00

125 lines
3.9 KiB
C#

using Step.NC;
using Step.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Step.UI
{
public partial class ResetSpindleForm : Form
{
private NcAdapter Nc;
private String Matricola;
private int MatricolaNum;
public ResetSpindleForm()
{
InitializeComponent();
}
public void setNcData(String matr, NcAdapter Nch)
{
this.Matricola = matr;
SupportFunctions.ConvertStringMachineNumberIntoNumber(matr, out bool containsLetters, out this.MatricolaNum);
this.Text = "Reset Spindle Active Time - " + this.Matricola;
this.Nc = Nch;
}
private void Cancel_Pwd_Button_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
private void OK_Pwd_Button_Click(object sender, EventArgs e)
{
checkPSW(TextBox_Password.Text);
}
private void PasswordForm_Load(object sender, EventArgs e)
{
TextBox_Password.Text = "";
comboBoxSpindle.SelectedIndex = 0;
this.ActiveControl = comboBoxSpindle;
}
private void TextBox_Password_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
checkPSW(TextBox_Password.Text);
}
}
private void comboBoxSpindle_SelectedIndexChanged(object sender, EventArgs e)
{
ReadHours();
}
private void checkPSW(String psw)
{
if(Matricola== null || Matricola.Trim() == "" || MatricolaNum <= 0)
{
MessageBox.Show("Machine ID non correct", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxSpindle.SelectedIndex == 0)
{
MessageBox.Show("Head must be selected", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!Utils.CandiesController.HeadsPasswordCheck(psw, MatricolaNum, comboBoxSpindle.SelectedIndex))
{
MessageBox.Show("Wrong password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!Nc.ResetHeadWTime(comboBoxSpindle.SelectedIndex))
{
MessageBox.Show("Error While Resetting time", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
MessageBox.Show("Time resetted", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
ReadHours();
TextBox_Password.Text = "";
}
private void ReadHours()
{
if (comboBoxSpindle.SelectedIndex == 0)
textBoxHours.Text = "";
else
{
uint secs = 0;
uint hours = 0;
;
if (!Nc.ReadHeadWTime(comboBoxSpindle.SelectedIndex, out secs))
{
MessageBox.Show("Error While reading time", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
uint min = Convert.ToUInt32(Math.Floor((double)secs / 60));
secs = secs % 60;
if (min >= 60)
{
hours = Convert.ToUInt32(Math.Floor((double)min / 60));
min = min % 60;
}
textBoxHours.Text = hours.ToString() + "h " + min.ToString() + "m " + secs.ToString() + "s";
}
}
}
}
}