// "Constructor." Takes in an instrument object and a checkout type public Checkout_Data(Instrument instrument, Checkout.Type type) { InitializeComponent(); // Assigns an id to coInstrument //coInstrument = instrument.id; // Selects the fall semester button fallButton.Select(); // Selects the current day checkoutDate.Select(); this.checkType = type; ////////////////// fullData.bow = instrument.bow; fullData.brand = instrument.brand; fullData.cabinate = instrument.cabinate; fullData.id = instrument.id; fullData.model = instrument.model; fullData.name = instrument.name; fullData.note = instrument.note; fullData.serialNumber = instrument.serialNumber; fullData.type = instrument.type; fullData.value = instrument.value; fullData.vendor = instrument.vendor; ////////////////// // Sets the check in/out button text depending on whether this is // a check in or check out switch (checkType) { case (Checkout.Type.checkin): { checkoutButton.Text = "Check In"; break; } case (Checkout.Type.checkout): { checkoutButton.Text = "Check Out"; break; } } // Autofills the employee box staffBox.Text = Form1.currentEmployee.eName; // Moves the user focus to enter the student id // Technically not necessary, but makes the card scanner more convenient // as you don't have to do anything besides open the form then sIDBox.Select(); 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; } } } }