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 ResetCountersForm : Form { private NcHandler Nc; private String Matricola; public ResetCountersForm() { InitializeComponent(); } public void setNcData(String matr, NcHandler Nch) { this.Matricola = matr; this.Text = "Reset Counters - " + 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() == "" || Convert.ToInt32(Matricola) <= 0) { MessageBox.Show("Machine ID non correct", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBoxSpindle.SelectedIndex == 0) { MessageBox.Show("Counter must be selected", 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() { if (comboBoxSpindle.SelectedIndex == 0) { labelValue.Text = ""; textBoxHours.Text = ""; } else { 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(); } } } } }