// Editing actions to take on double click private void content_DoubleClick(object sender, DataGridViewCellEventArgs e) { if (checkoutGrid.CurrentCell != null && checkoutGrid.CurrentCell.Value != null) { // If the last column if (checkoutGrid.CurrentCell.ColumnIndex.Equals(7) && e.RowIndex != -1) { if (instrument == null) { noteEntry noteView = new noteEntry(studentCheckouts[checkoutGrid.CurrentCell.RowIndex].note, studentCheckouts[checkoutGrid.CurrentCell.RowIndex].instrument.name, checkoutGrid.CurrentCell.RowIndex); noteView.noteTextBox.Enabled = false; noteView.noteLabel.Text = ""; noteView.saveButton.Hide(); noteView.cancelButton.Location = new Point(110, 260); noteView.ShowDialog(); } else { // View note noteEntry noteView = new noteEntry(instrument.checkouts[checkoutGrid.CurrentCell.RowIndex].note, instrument.name, checkoutGrid.CurrentCell.RowIndex); noteView.ShowDialog(); } } // If the first column else if (instrument != null && (checkoutGrid.CurrentCell.ColumnIndex.Equals(0) && e.RowIndex != -1) && Form1.currentEmployee != null) { // Initializes and assigns variables for the starting and ending // values of the transaction type string cStart = "Check Out"; string cEnd = "Check In"; // Doing it this way saves two stirng parses // If it was originally a check in, it sets it to a check out switch (checkoutGrid.CurrentCell.Value.ToString()) { case "Check In": cStart = "Check In"; cEnd = "Check Out"; break; } // Assigns cell text value checkoutGrid.CurrentCell.Value = cEnd; // Notification notificationForm nF = new notificationForm(cStart, cEnd); nF.ShowDialog(); nF.Refresh(); } } }
// When cell is done being edited private void checkoutGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (Form1.currentEmployee != null) { // If the string in the first column is "Check In" if ((string)checkoutGrid[0, selectedIndex[1]].Value == "Check In") { cBackward = 0; } else { cBackward = (Checkout.Type) 1; } foreach (Instrument nInstrument in Form1.allInstruments) { if (nInstrument.id == instrument.id) { // Save information to the instrument nInstrument.checkouts[selectedIndex[1]].type = cBackward; nInstrument.checkouts[selectedIndex[1]].sName = (string)checkoutGrid[1, selectedIndex[1]].Value.ToString(); int temp1; // Makes sure that the user inputed an actual intger if (!Int32.TryParse(checkoutGrid[2, selectedIndex[1]].Value.ToString(), out temp1) | temp1.ToString().Length != 7) { checkoutGrid[2, selectedIndex[1]].Value = nInstrument.checkouts[selectedIndex[1]].sID; notificationForm nF = new notificationForm("You must enter a 7-digit, number-only input"); nF.ShowDialog(); nF.Refresh(); } else { nInstrument.checkouts[selectedIndex[1]].sID = Int32.Parse(checkoutGrid[2, selectedIndex[1]].Value.ToString()); } nInstrument.checkouts[selectedIndex[1]].emailAddress = (string)checkoutGrid[3, selectedIndex[1]].Value.ToString(); DateTime temp2; // Makes sure that the user inputed an actual date if (!DateTime.TryParse(checkoutGrid[4, selectedIndex[1]].Value.ToString(), out temp2)) { checkoutGrid[4, selectedIndex[1]].Value = nInstrument.checkouts[selectedIndex[1]].date; notificationForm nF = new notificationForm("You must enter a correct date format"); nF.ShowDialog(); nF.Refresh(); } else { nInstrument.checkouts[selectedIndex[1]].date = checkoutGrid[4, selectedIndex[1]].Value.ToString(); } nInstrument.checkouts[selectedIndex[1]].staff = (string)checkoutGrid[5, selectedIndex[1]].Value.ToString(); nInstrument.checkouts[selectedIndex[1]].semester = (string)checkoutGrid[6, selectedIndex[1]].Value.ToString(); // Update the instrument variable in this class instrument = nInstrument; // Sort out instruments with the new value Form1.sortInstruments(); break; } } } }