First Commit. Must be tested
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
using Step.NC;
|
||||
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 ResetMachineHoursForm : Form
|
||||
{
|
||||
private NcHandler Nc;
|
||||
private String Matricola;
|
||||
|
||||
public ResetMachineHoursForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void setNcData(String matr, NcHandler Nch)
|
||||
{
|
||||
this.Matricola = matr;
|
||||
this.Text = "Reset Machine Working-Hours - " + 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 = "";
|
||||
this.ActiveControl = textBoxNewVal;
|
||||
ReadHours();
|
||||
}
|
||||
|
||||
private void TextBox_Password_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
checkPSW(TextBox_Password.Text);
|
||||
}
|
||||
|
||||
private void Reload_Button_Click(object sender, EventArgs e)
|
||||
{
|
||||
ReadHours();
|
||||
}
|
||||
|
||||
private void checkPSW(String psw)
|
||||
{
|
||||
if(Matricola== null || Matricola.Trim() == "" || Convert.ToInt32(Matricola) <= 0)
|
||||
{
|
||||
MessageBox.Show("Machine ID non correct", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
uint val = 0;
|
||||
bool isNumber = uint.TryParse(textBoxNewVal.Text, out val);
|
||||
if (!isNumber)
|
||||
{
|
||||
MessageBox.Show("New-Value must be a number", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
// sfrutto password delle teste, passando la testa 0
|
||||
if (!Utils.CandiesController.HeadsPasswordCheck(psw, Convert.ToInt32(Matricola), 0))
|
||||
{
|
||||
MessageBox.Show("Wrong password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Nc.ResetMachineWTime(val))
|
||||
{
|
||||
MessageBox.Show("Error While Resetting time", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
MessageBox.Show("Time resetted", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
ReadHours();
|
||||
TextBox_Password.Text = "";
|
||||
textBoxNewVal.Text = "";
|
||||
}
|
||||
|
||||
private void ReadHours()
|
||||
{
|
||||
uint realVal = 0;
|
||||
uint secs = 0;
|
||||
uint hours = 0;
|
||||
;
|
||||
|
||||
if (!Nc.ReadMachineWTime(out realVal))
|
||||
{
|
||||
MessageBox.Show("Error While reading time", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint min = Convert.ToUInt32(Math.Floor((double)realVal / 60));
|
||||
secs = realVal % 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";
|
||||
labelValue.Text = realVal.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user