private void insertEquipmentMenuItem_Click(object sender, EventArgs e) { if (insertEquipmentMenuItem.Text == "New") { Scanning.StartRead(); cancelActionEquipmentMenuItem.Enabled = true; insertEquipmentMenuItem.Text = "Insert"; } else { try { SQLiteCommand addEquipmentCommand = new SQLiteCommand(kumpotDBConnection); addEquipmentCommand.CommandText = "INSERT INTO EquipInventory (SerialNumber, PartNumber) VALUES ('" + serialNumberTextBox.Text.Trim() + "', '" + productComboBox.SelectedValue.ToString().Trim() + "')"; kumpotDBConnection.Open(); addEquipmentCommand.ExecuteScalar(); kumpotDBConnection.Close(); MessageBox.Show("Equipment Added"); insertEquipmentMenuItem.Text = "New"; cancelActionEquipmentMenuItem.Enabled = false; populateTreeView(); Scanning.StopRead(); } catch (SQLiteException ex) { MessageBox.Show(ex.Message); //switch (ex.ErrorCode) //{ // case SQLiteErrorCode.Constraint: // MessageBox.Show("Serial number is already added.", "Invalid Serial", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); // break; //} } finally { kumpotDBConnection.Close(); } } }
private void cancelMenuItem_Click(object sender, EventArgs e) { if (insertPersonnelMenuItem.Text == "Insert") { insertPersonnelMenuItem.Text = "New"; Scanning.StopRead(); togglePersonnelForm(false); clearPersonnelForm(); refreshPersonnelDetails(personnelListBox.SelectedValue.ToString()); editPersonnelMenuItem.Enabled = true; } else if (editPersonnelMenuItem.Text == "Update") { editPersonnelMenuItem.Text = "Edit"; togglePersonnelForm(false); clearPersonnelForm(); refreshPersonnelDetails(personnelListBox.SelectedValue.ToString()); insertPersonnelMenuItem.Enabled = true; ediTextBox.Enabled = true; } personnelListBox.Enabled = true; cancelMenuItem.Enabled = false; deletePersonnelMenuItem.Enabled = true; }
private void cancelActionEquipmentMenuItem_Click(object sender, EventArgs e) { insertEquipmentMenuItem.Text = "New"; cancelActionEquipmentMenuItem.Enabled = false; Scanning.StopRead(); }
private void insertPersonnelMenuItem_Click(object sender, EventArgs e) { if (insertPersonnelMenuItem.Text == "New") { togglePersonnelForm(true); personnelListBox.Enabled = false; insertPersonnelMenuItem.Text = "Insert"; deletePersonnelMenuItem.Enabled = false; cancelMenuItem.Enabled = true; editPersonnelMenuItem.Enabled = false; clearPersonnelForm(); Scanning.StartRead(); } else if (MessageBox.Show("Are you sure you want to commit this information to the database?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { if (lastNameTextBox.Text != "" && firstNameTextBox.Text != "" && ediTextBox.Text != "" && rankTextBox.Text != "") { try { SQLiteCommand addPersonnelCommand = new SQLiteCommand(etDBConnection); addPersonnelCommand.CommandText = "INSERT INTO Personnel (PersonnelEDI, FirstName, LastName, Rank, Branch, MiddleInitial) " + "VALUES ($EDI,$FirstName,$LastName,$Rank,$Branch,$MiddleInitial)"; addPersonnelCommand.Parameters.AddWithValue("$EDI", ediTextBox.Text.Trim()); addPersonnelCommand.Parameters.AddWithValue("$FirstName", firstNameTextBox.Text.Trim()); addPersonnelCommand.Parameters.AddWithValue("$LastName", lastNameTextBox.Text.Trim()); addPersonnelCommand.Parameters.AddWithValue("$Rank", rankTextBox.Text.Trim()); addPersonnelCommand.Parameters.AddWithValue("$Branch", branchComboBox.SelectedValue.ToString()); addPersonnelCommand.Parameters.AddWithValue("$MiddleInitial", middleInitialTextBox.Text.Trim()); //Open database and execute command etDBConnection.Open(); addPersonnelCommand.ExecuteNonQuery(); etDBConnection.Close(); MessageBox.Show("Personnel Added"); insertPersonnelMenuItem.Text = "New"; cancelMenuItem.Enabled = false; deletePersonnelMenuItem.Enabled = true; editPersonnelMenuItem.Enabled = true; personnelListBox.Enabled = true; togglePersonnelForm(false); clearPersonnelForm(); refreshPersonnelListbox(); Scanning.StopRead(); } catch (SQLiteException sqliteException) { MessageBox.Show(sqliteException.Message); //if (sqliteException.ErrorCode == SQLiteErrorCode.Constraint) //{ // MessageBox.Show("Entered EDI number is not unique and already added. User is possibly already added.", "Invalid EDI", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); //} } finally { etDBConnection.Close(); } } else { MessageBox.Show("Missing required information"); } } }