private void m_updateButton_Click(object sender, EventArgs e) { string rezult = (string)m_updateDataComboBox.SelectedItem; switch (rezult) { case "Modelis": SqlDataAdapter adapter = new SqlDataAdapter("select * from Modelis", System.Configuration.ConfigurationManager.ConnectionStrings["AutomobiliuSalonasDataBase"].ConnectionString); SqlCommand updcmd = new SqlCommand(); updcmd.CommandText = "update modelis set Pavadinimas = @Pavadinimas, Galia = @Galia, VietuSkaicius = @VietuSkaicius, Kuras = @Kuras where Nr = @Nr"; updcmd.Parameters.Add("@Pavadinimas", SqlDbType.VarChar).SourceColumn = "Pavadinimas"; updcmd.Parameters.Add("@Galia", SqlDbType.SmallInt).SourceColumn = "Galia"; updcmd.Parameters.Add("@VietuSkaicius", SqlDbType.SmallInt).SourceColumn = "VietuSkaicius"; updcmd.Parameters.Add("@Kuras", SqlDbType.VarChar).SourceColumn = "Kuras"; updcmd.Parameters.Add("@Nr", SqlDbType.Int).SourceColumn = "Nr"; updcmd.Connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["AutomobiliuSalonasDataBase"].ConnectionString); adapter.UpdateCommand = updcmd; DataTable table = dataTables.ModelisTable; foreach (DataRow row in table.Rows) { if ((int)row["Nr"] == (int)m_updateDataListBox.SelectedValue) { row["Pavadinimas"] = m_updateDataTextBox1.Text; row["Galia"] = short.Parse(m_updateDataMaskedTextBox2.Text); row["VietuSkaicius"] = short.Parse(m_updateDataMaskedTextBox3.Text); row["Kuras"] = (string)m_updateDataComboBox4.SelectedItem; adapter.Update(table); break; } } break; case "Automobilis": Automobilis automobilisToUpdate = dataBase.Automobilis.Find(m_updateDataListBox.SelectedValue); automobilisToUpdate.Kaina = int.Parse(m_updateDataMaskedTextBox2.Text); automobilisToUpdate.Spalva = m_updateDataTextBox3.Text; dataBase.SaveChanges(); break; case "Pardavejas": Pardavejas pardavejasToUpdate = dataBase.Pardavejas.Find(m_updateDataListBox.SelectedValue); pardavejasToUpdate.Vardas = m_updateDataTextBox1.Text; pardavejasToUpdate.Pavarde = m_updateDataTextBox2.Text; pardavejasToUpdate.AK = m_updateDataTextBox3.Text; dataBase.SaveChanges(); break; case "Klientas": Klientas klientasToUpdate = dataBase.Klientas.Find(m_updateDataListBox.SelectedValue); klientasToUpdate.Vardas = m_updateDataTextBox1.Text; klientasToUpdate.Pavarde = m_updateDataTextBox2.Text; klientasToUpdate.AK = m_updateDataTextBox3.Text; klientasToUpdate.Elpastas = m_updateDataTextBox4.Text; klientasToUpdate.TelNr = m_updateDataMaskedTextBox5.Text; dataBase.SaveChanges(); break; } m_updateDataComboBox.SelectedIndex = -1; }
private void m_deleteButton_Click(object sender, EventArgs e) { string rezult = (string)m_updateDataComboBox.SelectedItem; switch (rezult) { case "Modelis": SqlDataAdapter adapter = new SqlDataAdapter("select * from Modelis", System.Configuration.ConfigurationManager.ConnectionStrings["AutomobiliuSalonasDataBase"].ConnectionString); SqlCommand delcmd = new SqlCommand(); delcmd.CommandText = "delete from modelis where Nr = @Nr"; delcmd.Parameters.Add("@Nr", SqlDbType.Int).SourceColumn = "Nr"; delcmd.Connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["AutomobiliuSalonasDataBase"].ConnectionString); adapter.DeleteCommand = delcmd; DataTable table = dataTables.ModelisTable; foreach (DataRow row in table.Rows) { if ((int)row["Nr"] == (int)m_updateDataListBox.SelectedValue) { row.Delete(); adapter.Update(table); break; } } break; case "Automobilis": Automobilis automobilisToRemove = dataBase.Automobilis.Find(m_updateDataListBox.SelectedValue); dataBase.Automobilis.Remove(automobilisToRemove); dataBase.SaveChanges(); break; case "Pardavejas": Pardavejas pardavejasToRemove = dataBase.Pardavejas.Find(m_updateDataListBox.SelectedValue); dataBase.Pardavejas.Remove(pardavejasToRemove); dataBase.SaveChanges(); break; case "Klientas": Klientas klientasToRemove = dataBase.Klientas.Find(m_updateDataListBox.SelectedValue); dataBase.Klientas.Remove(klientasToRemove); dataBase.SaveChanges(); break; } m_updateDataComboBox.SelectedIndex = -1; }
private void m_klientoAKOKButton_Click(object sender, EventArgs e) { Klientas klientas = dataBase.Klientas.Where(b => b.AK == m_klientoAKTextBox.Text).SingleOrDefault(); if (klientas != null) { m_klientoVardasTextBox.Text = klientas.Vardas; m_klientoPavardeTextBox.Text = klientas.Pavarde; m_klientoTelNrMaskedTextBox.Text = klientas.TelNr; m_klientoElPastasTextBox.Text = klientas.Elpastas; } else { m_klientoVardasTextBox.Enabled = true; m_klientoPavardeTextBox.Enabled = true; m_klientoElPastasTextBox.Enabled = true; m_klientoTelNrMaskedTextBox.Enabled = true; } }
private void m_pardavimasSaveButton_Click(object sender, EventArgs e) { Klientas klientas = dataBase.Klientas.Where(b => b.AK == m_klientoAKTextBox.Text).SingleOrDefault(); if (klientas == null) { klientas = new Klientas(); klientas.AK = m_klientoAKTextBox.Text; klientas.Vardas = m_klientoVardasTextBox.Text; klientas.Pavarde = m_klientoPavardeTextBox.Text; klientas.TelNr = m_klientoTelNrMaskedTextBox.Text; klientas.Elpastas = m_klientoElPastasTextBox.Text; dataBase.Klientas.Add(klientas); dataBase.SaveChanges(); } Pardavimas naujasPardavimas = new Pardavimas(); naujasPardavimas.Klientas = klientas.Nr; naujasPardavimas.Pardavejas = (int)m_pardavejuComboBox.SelectedValue; naujasPardavimas.Automobilis = (int)m_automobiliuComboBox.SelectedValue; naujasPardavimas.Data = DateTime.Today; dataBase.Pardavimas.Add(naujasPardavimas); dataBase.SaveChanges(); }
private void m_updateDataListBox_SelectedIndexChanged(object sender, EventArgs e) { foreach (Control control in m_updateDataPanel.Controls) { control.Visible = false; } if (m_updateDataListBox.SelectedIndex >= 0) { string rezult = (string)m_updateDataComboBox.SelectedItem; switch (rezult) { case "Modelis": Modelis modelis = dataBase.Modelis.Find(m_updateDataListBox.SelectedValue); m_updateDataLabel1.Text = "Pavadinimas:"; m_updateDataLabel1.Visible = true; m_updateDataTextBox1.Text = modelis.Pavadinimas; m_updateDataTextBox1.Visible = true; m_updateDataLabel2.Text = "Galia:"; m_updateDataLabel2.Visible = true; m_updateDataMaskedTextBox2.Text = "" + modelis.Galia; m_updateDataMaskedTextBox2.Visible = true; m_updateDataLabel3.Text = "Vietų skaičius:"; m_updateDataLabel3.Visible = true; m_updateDataMaskedTextBox3.Text = "" + modelis.VietuSkaicius; m_updateDataMaskedTextBox3.Visible = true; m_updateDataLabel4.Text = "Kuras:"; m_updateDataLabel4.Visible = true; m_updateDataComboBox4.Text = modelis.Kuras; m_updateDataComboBox4.Visible = true; break; case "Automobilis": Automobilis automobilis = dataBase.Automobilis.Find(m_updateDataListBox.SelectedValue); m_updateDataLabel1.Text = "Modelio Nr:"; m_updateDataLabel1.Visible = true; m_updateDataMaskedTextBox1.Text = "" + automobilis.Modelis; m_updateDataMaskedTextBox1.Visible = true; m_updateDataMaskedTextBox1.Enabled = false; m_updateDataLabel2.Text = "Kaina:"; m_updateDataLabel2.Visible = true; m_updateDataMaskedTextBox2.Text = "" + automobilis.Kaina; m_updateDataMaskedTextBox2.Visible = true; m_updateDataLabel3.Text = "Spalva:"; m_updateDataLabel3.Visible = true; m_updateDataTextBox3.Text = automobilis.Spalva; m_updateDataTextBox3.Visible = true; break; case "Pardavejas": Pardavejas pardavejas = dataBase.Pardavejas.Find(m_updateDataListBox.SelectedValue); m_updateDataLabel1.Text = "Vardas"; m_updateDataLabel1.Visible = true; m_updateDataTextBox1.Text = pardavejas.Vardas; m_updateDataTextBox1.Visible = true; m_updateDataLabel2.Text = "Pavardė"; m_updateDataLabel2.Visible = true; m_updateDataTextBox2.Text = "" + pardavejas.Pavarde; m_updateDataTextBox2.Visible = true; m_updateDataLabel3.Text = "Asmens kodas:"; m_updateDataLabel3.Visible = true; m_updateDataTextBox3.Text = "" + pardavejas.AK; m_updateDataTextBox3.Visible = true; break; case "Klientas": Klientas klientas = dataBase.Klientas.Find(m_updateDataListBox.SelectedValue); m_updateDataLabel1.Text = "Vardas:"; m_updateDataLabel1.Visible = true; m_updateDataTextBox1.Text = klientas.Vardas; m_updateDataTextBox1.Visible = true; m_updateDataLabel2.Text = "Pavardė:"; m_updateDataLabel2.Visible = true; m_updateDataTextBox2.Text = "" + klientas.Pavarde; m_updateDataTextBox2.Visible = true; m_updateDataLabel3.Text = "Asmens kodas:"; m_updateDataLabel3.Visible = true; m_updateDataTextBox3.Text = "" + klientas.AK; m_updateDataTextBox3.Visible = true; m_updateDataLabel4.Text = "El.Paštas:"; m_updateDataLabel4.Visible = true; m_updateDataTextBox4.Text = klientas.Elpastas; m_updateDataTextBox4.Visible = true; m_updateDataLabel5.Text = "Tel. Nr.:"; m_updateDataLabel5.Visible = true; m_updateDataMaskedTextBox5.Text = klientas.TelNr; m_updateDataMaskedTextBox5.Visible = true; break; } } }