private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { lblProcAprasymas.Text = dataGridView1.SelectedCells[0].Value.ToString(); string connString = @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\Marius\source\repos\Priminimai\Priminimai\PriminimuDB.mdf; Integrated Security = True"; using (SqlConnection conn = new SqlConnection(connString)) { var querry = @"SELECT aprasymas FROM " + MasinosPavadinimoStringKeitimas.TarpasBruksnelis(comboBox1.SelectedItem.ToString()) + " WHERE pavadinimas='" + lblProcAprasymas.Text + "';"; using (SqlCommand command = new SqlCommand(querry, conn)) { conn.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { if (reader[0].ToString() == string.Empty) { lblProcAprPilnas.Text = "Aprašymo nėra. Pridėkite aprašymą redaguodami įrenginio techninį aprašymą."; } else { lblProcAprPilnas.Text = reader[0].ToString(); } } conn.Close(); } } }
private void btnIstrintiIrengini_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Ištrinsite šį įrenginį ir prarasite visas jo procedūras bei duomenis. Ar norite tęsti?", "Įspėjimas", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (dialogResult == DialogResult.OK) { string connString = @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\Marius\source\repos\Priminimai\Priminimai\PriminimuDB.mdf; Integrated Security = True"; try { using (SqlConnection conn = new SqlConnection(connString)) { var querry = @"DROP TABLE " + MasinosPavadinimoStringKeitimas.TarpasBruksnelis(lblIrenginioPavadinimas.Text) + ";"; using (SqlCommand command = new SqlCommand(querry, conn)) { conn.Open(); command.ExecuteNonQuery(); conn.Close(); } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Klaida", MessageBoxButtons.OK, MessageBoxIcon.Error); } try { using (SqlConnection conn = new SqlConnection(connString)) { var querry = @"DELETE FROM Masinos WHERE MasinosPavadinimas='" + MasinosPavadinimoStringKeitimas.TarpasBruksnelis(lblIrenginioPavadinimas.Text) + "';"; using (SqlCommand command = new SqlCommand(querry, conn)) { conn.Open(); command.ExecuteNonQuery(); conn.Close(); } MessageBox.Show("Įrenginys ištrintas.", "Pranešimas", MessageBoxButtons.OK, MessageBoxIcon.Information); } GriztiAction(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Klaida", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
//Combobox itemo keitimas private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { dt.Rows.Clear(); lblProcAprasymas.Text = "----"; lblProcAprPilnas.Text = "----"; string connString = @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\Marius\source\repos\Priminimai\Priminimai\PriminimuDB.mdf; Integrated Security = True"; using (SqlConnection conn = new SqlConnection(connString)) { var querry = @"SELECT pavadinimas, periodiskumas FROM " + MasinosPavadinimoStringKeitimas.TarpasBruksnelis(comboBox1.SelectedItem.ToString()) + ";"; try { using (SqlCommand command = new SqlCommand(querry, conn)) { conn.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { DataRow workRow = dt.NewRow(); workRow["Techninės operacijos aprašymas"] = reader[0].ToString(); for (int i = 1; i < 53; i++) { if (i % Convert.ToInt32(reader[1]) == 0) { workRow[i] = "X"; } } dt.Rows.Add(workRow); } conn.Close(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
private void btnIssaugotiPocedura_Click(object sender, EventArgs e) { string connString = @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\Marius\source\repos\Priminimai\Priminimai\PriminimuDB.mdf; Integrated Security = True"; using (SqlConnection conn = new SqlConnection(connString)) { var querry = @"UPDATE " + MasinosPavadinimoStringKeitimas.TarpasBruksnelis(lblIrenginioPavadinimas.Text) + " SET pavadinimas='" + txtKeistiPavadinima.Text + "', aprasymas='" + txtKeistiAprasyma.Text + "', periodiskumas='" + listPeriodiškumas.SelectedItem.ToString() + "' WHERE pavadinimas='" + listProceduros.SelectedItem.ToString() + "';"; using (SqlCommand command = new SqlCommand(querry, conn)) { conn.Open(); command.ExecuteNonQuery(); conn.Close(); } MessageBox.Show("Išsaugota sėkmingai!", "Pranešimas", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void UzpildytiProceduruList() { string connString = @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\Marius\source\repos\Priminimai\Priminimai\PriminimuDB.mdf; Integrated Security = True"; using (SqlConnection conn = new SqlConnection(connString)) { var querry = @"SELECT pavadinimas FROM " + MasinosPavadinimoStringKeitimas.TarpasBruksnelis(lblIrenginioPavadinimas.Text) + ";"; using (SqlCommand command = new SqlCommand(querry, conn)) { conn.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { listProceduros.Items.Add(reader[0].ToString()); } conn.Close(); } } }
public string SiustiPavadinima() { return(MasinosPavadinimoStringKeitimas.TarpasBruksnelis(textBox1.Text)); }
private void listProceduros_SelectedIndexChanged(object sender, EventArgs e) { string connString = @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\Marius\source\repos\Priminimai\Priminimai\PriminimuDB.mdf; Integrated Security = True"; try { using (SqlConnection conn = new SqlConnection(connString)) { var querry = @"SELECT pavadinimas, aprasymas, periodiskumas FROM " + MasinosPavadinimoStringKeitimas.TarpasBruksnelis(lblIrenginioPavadinimas.Text) + " WHERE pavadinimas='" + listProceduros.SelectedItem.ToString() + "';"; using (SqlCommand command = new SqlCommand(querry, conn)) { conn.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { txtKeistiPavadinima.Text = reader[0].ToString(); txtKeistiAprasyma.Text = reader[1].ToString(); listPeriodiškumas.SelectedIndex = Convert.ToInt32(reader[2]) + 1; } conn.Close(); } } } catch (Exception) { MessageBox.Show("Įvyko klaida nuskaitant procedūras.", "Klaida", MessageBoxButtons.OK, MessageBoxIcon.Error); } }