private void selectRepair(object sender, RoutedEventArgs e) { Int64 Nice = 0; try { Repair selected_id = (Repair)RepairTable.SelectedItems[0]; Nice = (Int64)selected_id.IssueID; RepairInfo repairLoader = new RepairInfo((int)Nice); repairLoader.Show(); } catch (Exception Ex) { MessageBox.Show("No item selected! Error: " + Ex, "Alert", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.Cancel); return; } }
private void search(object sender, RoutedEventArgs e) { // validation of input try { ID = Convert.ToInt64(Input.Text); } catch (Exception ex) { if (string.IsNullOrEmpty(Input.Text)) { MessageBox.Show("Input cannot be empty!", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation); } else { MessageBox.Show("Input contains non-number characters!", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation); } return; } // prepare databas using (SQLiteConnection cnn = new SQLiteConnection(database.LoadConnectionString())) { cnn.Open(); string stm; // if the 3rd case was selected then we will do this rather than the other logic // below if (id_type == "Duplicate") { MessageBoxResult result = MessageBox.Show("Are you sure you want to create a duplicate of this ID? This will create a copy of the ID and will place it make it in stock.", "Caution", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel); try { if (result == MessageBoxResult.Yes) { // get the ID stm = "SELECT * FROM stock WHERE ItemID = '" + ID + "'"; using (SQLiteCommand cmd = new SQLiteCommand(stm, cnn)) { using (SQLiteDataReader rdr = cmd.ExecuteReader()) { if (!rdr.HasRows) { MessageBox.Show("ID does not exist.", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.Cancel); return; } } } // duplicate the item using the exsisting information stm = "INSERT INTO stock (ItemName, Type, Price, RAMSize, Brand, Model, OS, Processor, Graphics, HDD, Bluetooth, WiFi, inStock, Details) SELECT ItemName, Type, Price, RAMSize, Brand, Model, OS, Processor, Graphics, HDD, Bluetooth, WiFi, '1', Details FROM stock WHERE stock.ItemID = '" + ID + "'"; using (SQLiteCommand cmd = new SQLiteCommand(stm, cnn)) { cmd.ExecuteNonQuery(); } } else if (result == MessageBoxResult.No) { MessageBox.Show("Operation canceled, database was not modified", "Attention!", MessageBoxButton.OK, MessageBoxImage.Information); } MessageBox.Show("Operation complete", "Attention!", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); // return this method so that we don't continue with the logic below return; } catch (Exception Ex) { // TODO: clean this error up MessageBox.Show("Error: " + Ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.Cancel); } } // a multi-purpose query which can react to whatever case is selected stm = "SELECT * FROM " + table + " WHERE " + id_type + "ID = '" + ID + "'"; using (SQLiteCommand cmd = new SQLiteCommand(stm, cnn)) { using (SQLiteDataReader rdr = cmd.ExecuteReader()) { if (rdr.HasRows) { //open the respective windows switch (mode_global) { case 0: ClientInfo clientLoader = new ClientInfo((int)ID); clientLoader.Login(); this.Close(); break; case 1: StockInfo stockLoader = new StockInfo((int)ID, false); stockLoader.Show(); this.Close(); break; case 2: RepairInfo repairLoader = new RepairInfo((int)ID); repairLoader.Show(); this.Close(); break; case 4: CreateOrders orderLoader = new CreateOrders((int)ID); orderLoader.Show(); this.Close(); break; } } else { // tell the user that ID doesn't exsist MessageBoxResult result = MessageBox.Show("Unable to find " + id_type.ToLowerInvariant() + " from provided ID!", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation); } } } } }