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 ResetMachineHoursForm : Form { private NcAdapter Nc; private String Matricola; private int MatricolaNum; public ResetMachineHoursForm() { InitializeComponent(); } public void setNcData(String matr, NcAdapter Nch) { this.Matricola = matr; SupportFunctions.ConvertStringMachineNumberIntoNumber(matr, out bool containsLetters, out this.MatricolaNum); 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) { if (e.KeyCode == Keys.Enter) checkPSW(TextBox_Password.Text); } private void Reload_Button_Click(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; } 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, MatricolaNum, 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(); } } } }