public static void saveParameters(parametry_anteny par) { using (IDbConnection cnn = new SQLiteConnection(loadConnectionString())) { cnn.Execute("insert into Antena (nazwa, zysk_dBi, czestotliwosc_MHz, id_zlacza) values (@nazwa, @zysk_dBi, @czestotliwosc_MHz, @id_zlacza)", par); } }
private void button1_Click(object sender, EventArgs e) { switch (comboBox1.SelectedItem.ToString()) { case "Urządzenie": case "Devices": string value1 = textBox3.Text; string value2 = textBox4.Text; string value3 = textBox5.Text; string query1 = "SELECT Zlacze.id FROM Zlacze WHERE Zlacze.symbol = '" + value1 + "'"; string query2 = "SELECT Kabel.id FROM Kabel WHERE Kabel.symbol = '" + value2 + "'"; string query3 = "SELECT Antena.id FROM Antena WHERE Antena.nazwa = '" + value3 + "'"; int id_kab = 0, id_zlacz = 0, id_ant = 0; using (var cnn = new SQLiteConnection(loadConnectionString())) { var a = cnn.ExecuteScalar <int>(query1); id_kab = a; } using (var cnn = new SQLiteConnection(loadConnectionString())) { var b = cnn.ExecuteScalar <int>(query2); id_zlacz = b; } using (var cnn = new SQLiteConnection(loadConnectionString())) { var c = cnn.ExecuteScalar <int>(query3); id_ant = c; } if (id_kab != 0 && id_zlacz != 0 && id_ant != 0) { try { Urzadzenie urz = new Urzadzenie { nazwa = textBox1.Text, moc = Convert.ToInt32(textBox2.Text), id_kabla = id_kab, id_zlacza = id_zlacz, id_anteny = id_ant, czulosc = Convert.ToDouble(textBox6.Text) }; label8.ForeColor = Color.Green; label8.Text = "Dodano do bazy"; label8.Show(); SqliteDataAccess.saveDevices(urz); lista_urz = SqliteDataAccess.ListUrzadzenie(); dataGridView1.DataSource = lista_urz; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = ""; } catch (Exception ex) when(ex is ArgumentNullException || ex is FormatException) { label8.ForeColor = Color.Red; label8.Text = "Wprowadzono błędne dane"; label8.Show(); } } else { label8.ForeColor = Color.Red; label8.Text = "Złe dane."; label8.Show(); } break; case "Materiały": case "Materials": try { tl_materialow mat = new tl_materialow { nazwa = textBox1.Text, tlumiennosc_db = Convert.ToDouble(textBox2.Text), grubosc_cm = Convert.ToDouble(textBox3.Text), czestotliwosc_MHz = Convert.ToDouble(textBox4.Text) }; SqliteDataAccess.saveMaterials(mat); label8.ForeColor = Color.Green; label8.Text = "Dodano do bazy"; label8.Show(); lista_mat = SqliteDataAccess.listMaterials(); dataGridView1.DataSource = lista_mat; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; } catch (Exception ex) when(ex is ArgumentNullException || ex is FormatException) { label8.ForeColor = Color.Red; label8.Text = "Wprowadzono błędne dane"; label8.Show(); } break; case "Anteny": case "Antennas": string zlacze_id = textBox4.Text; string query_zlacze = "SELECT Zlacze.id FROM Zlacze WHERE Zlacze.symbol = '" + zlacze_id + "'"; int id_zlacza = 0; using (var cnn = new SQLiteConnection(loadConnectionString())) { var a = cnn.ExecuteScalar <int>(query_zlacze); id_zlacza = a; } if (id_zlacza != 0) { try { parametry_anteny par = new parametry_anteny { zysk_dBi = Convert.ToDouble(textBox2.Text), nazwa = textBox1.Text, czestotliwosc_MHz = Convert.ToInt32(textBox3.Text), id_zlacza = id_zlacza }; SqliteDataAccess.saveParameters(par); label8.ForeColor = Color.Green; label8.Text = "Dodano do bazy"; label8.Show(); lista_ant = SqliteDataAccess.ListParameters(); dataGridView1.DataSource = lista_ant; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; } catch (Exception ex) when(ex is ArgumentNullException || ex is FormatException) { label8.ForeColor = Color.Red; label8.Text = "Wprowadzono błędne dane"; label8.Show(); } } else { label8.ForeColor = Color.Red; label8.Text = "Nie znaleziono takiego zlacza"; } break; case "Kable": case "Cables": string symbol = textBox4.Text; string query_zlaczee = "SELECT id FROM zlacze WHERE symbol = '" + symbol + "'"; int id = 0; using (var cnn = new SQLiteConnection(loadConnectionString())) { var a = cnn.ExecuteScalar <int>(query_zlaczee); id = a; } if (id != 0) { try { kabel kab = new kabel { czestotliwosc_MHz = Convert.ToInt32(textBox1.Text), symbol = textBox2.Text, tlumiennosc_db1m = Convert.ToDouble(textBox3.Text), id_zlacza = id }; SqliteDataAccess.saveCables(kab); label8.ForeColor = Color.Green; label8.Text = "Dodano do bazy"; label8.Show(); lista_kab = SqliteDataAccess.ListCables(); dataGridView1.DataSource = lista_kab; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; } catch (Exception ex) { label8.ForeColor = Color.Red; label8.Text = "Wprowadzono błędne dane"; label8.Show(); } } else { label8.ForeColor = Color.Red; label8.Text = "Wprowadzono błędne dane"; label8.Show(); } break; case "Złącza": case "Connectors": var lines = File.ReadAllLines("available_connectors.txt"); if (lines.Contains(textBox1.Text)) { try { zlacze zl = new zlacze { symbol = textBox1.Text, tlumiennosc_db = Convert.ToDouble(textBox2.Text), czestotliwosc_MHz = Convert.ToInt32(textBox3.Text) }; SqliteDataAccess.saveZlacza(zl); label8.ForeColor = Color.Green; label8.Text = "Dodano do bazy"; label8.Show(); lista_zla = SqliteDataAccess.ListZlacza(); dataGridView1.DataSource = lista_zla; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; } catch (Exception ex) when(ex is ArgumentNullException || ex is FormatException) { label8.ForeColor = Color.Red; label8.Text = "Wprowadzono błędne dane"; label8.Show(); } } else { label8.ForeColor = Color.Red; label8.Text = "Wprowadzono błędne dane"; label8.Show(); } break; case "Budżet łącza": case "Link Budget": try { Budzet_lacza budzet = new Budzet_lacza { fsl_db = Convert.ToDouble(textBox1.Text), odleglosc_km = Convert.ToDouble(textBox2.Text), czestotliwosc_MHz = Convert.ToInt32(textBox3.Text), }; label8.ForeColor = Color.Green; label8.Text = "Dodano do bazy"; label8.Show(); SqliteDataAccess.saveBudget(budzet); lista_bud = SqliteDataAccess.ListBudzet(); dataGridView1.DataSource = lista_bud; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; } catch (Exception ex) when(ex is ArgumentNullException || ex is FormatException) { label8.ForeColor = Color.Red; label8.Text = "Wprowadzono błędne dane"; label8.Show(); } break; } }