private void ButtonReset_Click(object sender, EventArgs e) { // make sure nothing needs to be saved if (ButtonSave.Enabled) { // switch on user choice switch (MessageBox.Show(this, "There are unsaved changes. Would you like to save them before resetting this window?", "Unsaved Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk)) { case DialogResult.Yes: ButtonSave_Click(sender, e); break; case DialogResult.Cancel: return; } } // reset gui TextBoxCardID.Clear(); TextBoxCardID.Enabled = true; ComboBoxMonth.SelectedIndex = DateTime.Today.Month - 1; ComboBoxMonth.Enabled = true; NumericUpDownYear.Value = (decimal)DateTime.Today.Year; NumericUpDownYear.Enabled = true; DataGridViewTimes.ClearSelection(); DataGridViewTimes.RowStateChanged -= new System.Windows.Forms.DataGridViewRowStateChangedEventHandler(DataGridViewTimes_RowStateChanged); DataGridViewTimes.DataSource = null; DisableUI(); DisableTimePickers(); ButtonLoad.Enabled = true; }
private void ButtonRemove_Click(object sender, EventArgs e) { // vars bool found = false; dt = sql.GetDataTable("select * from employees where employeeID=" + TextBoxCardID.Text.Trim() + ";"); // check if this is the card we're looking for if (dt.Rows.Count == 1) { // mark as found found = true; // confirm deletion of card if (MessageBox.Show(this, "Are you sure you want to delete " + dt.Rows[0].ItemArray[1].ToString() + "'s card?\n(Card/Student ID: " + dt.Rows[0].ItemArray[0].ToString() + ")", "Confirm Card Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { // write to file try { sql.Delete("employees", String.Format("employeeID = {0}", dt.Rows[0].ItemArray[0].ToString())); if (CheckBoxDelTimeLog.Checked == true) { sql.Delete("timeStamps", String.Format("employeeID = {0}", dt.Rows[0].ItemArray[0].ToString())); } } catch (Exception err) { MessageBox.Show(this, "There was an error while trying to remove the card.\n\n" + err.Message, "File Deletion Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } // notify user if card wasn't found if (!found) { MessageBox.Show(this, "The card you entered wasn't found. Are you sure you typed it in correctly?", "Card Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Error); } // reset text box TextBoxCardID.Clear(); TextBoxCardID.Focus(); }
private void TextBoxCardID_KeyDown(object sender, KeyEventArgs e) { // vars bool found = false; // check for user or scanner 'pressing' enter if (e.KeyData.ToString().Equals("Return")) { // don't let the textbox handle it further e.SuppressKeyPress = true; // don't allow changing the card id TextBoxCardID.ReadOnly = true; dt = sql.GetDataTable("select * from employees where employeeID=" + TextBoxCardID.Text.Trim() + ";"); // check if this is the card we're looking for if (dt.Rows.Count == 1) { // make note of card's position found = true; // enable editing and saving TextBoxFirstName.Enabled = true; TextBoxLastName.Enabled = true; TextBoxMI.Enabled = true; NumericUpDownHrRate.Enabled = true; RadioButtonFWS.Enabled = true; RadioButtonSWS.Enabled = true; RadioButtonMST.Enabled = true; RadioButtonHED.Enabled = true; RadioButtonHelp.Enabled = true; RadioButtonTutor1.Enabled = true; RadioButtonTutor2.Enabled = true; RadioButtonTANF.Enabled = true; ButtonSave.Enabled = true; try { // first name TextBoxFirstName.Text = dt.Rows[0].ItemArray[1].ToString(); // last name TextBoxLastName.Text = dt.Rows[0].ItemArray[2].ToString(); // middle initial TextBoxMI.Text = dt.Rows[0].ItemArray[3].ToString(); // hourly rate NumericUpDownHrRate.Value = Decimal.Parse(dt.Rows[0].ItemArray[4].ToString()); // position type switch (dt.Rows[0].ItemArray[5].ToString()) { case "FWS": RadioButtonFWS.Checked = true; break; case "SWS": RadioButtonSWS.Checked = true; break; case "MST": RadioButtonMST.Checked = true; break; case "HED": RadioButtonHED.Checked = true; break; case "Help": RadioButtonHelp.Checked = true; break; case "Tutor1": RadioButtonTutor1.Checked = true; break; case "Tutor2": RadioButtonTutor2.Checked = true; break; case "TANF": RadioButtonTANF.Checked = true; break; } // automatically go to the next text box TextBoxFirstName.Focus(); } catch (Exception err) { MessageBox.Show(this, "There was an error while trying to load your info.\nWas someone playing with the database files?\n\n" + err.Message, "Clocked Time Calculation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } // notify user if card wasn't found if (!found) { MessageBox.Show(this, "The card you entered wasn't found. Are you sure you typed it in correctly?", "Card Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Error); TextBoxCardID.Clear(); TextBoxCardID.ReadOnly = false; TextBoxCardID.Focus(); } } }