private void RemoveRezervare(Aparat aparat) { string query = "DELETE FROM Rezervari WHERE Aparat1=@id or Aparat2=@id"; using (SqliteConnection connection = new SqliteConnection(connectionString)) { SqliteCommand command = new SqliteCommand(query, connection); command.Parameters.AddWithValue("@id", aparat.Id); connection.Open(); command.ExecuteNonQuery(); List <Rezervare> copieRezervari = new List <Rezervare>(rezervari); foreach (Rezervare rezervare in copieRezervari) { if (rezervare.Aparat1 == aparat) { rezervari.Remove(rezervare); } else if (rezervare.Aparat2 != null) { if (rezervare.Aparat2 == aparat) { rezervari.Remove(rezervare); } } } } }
private void LoadRezervari() { string query = "SELECT * FROM Rezervari"; using (SqliteConnection connection = new SqliteConnection(connectionString)) { SqliteCommand command = new SqliteCommand(query, connection); connection.Open(); using (SqliteDataReader reader = command.ExecuteReader()) { while (reader.Read()) { long id = (long)reader["Id"]; DateTime data = DateTime.Parse((string)reader["Data"]); long durata = (long)reader["Durata"]; long idClient = (long)reader["Client"]; long idAparat1 = (long)reader["Aparat1"]; long idAparat2 = (long)reader["Aparat2"]; Client client = null; foreach (Client clientAux in clienti) { if (clientAux.Id == idClient) { client = clientAux; } } Aparat aparat1 = null; foreach (Aparat aparatAux in aparate) { if (aparatAux.Id == idAparat1) { aparat1 = aparatAux; } } Aparat aparat2 = null; if (idAparat2 != 0) { foreach (Aparat aparatAux in aparate) { if (aparatAux.Id == idAparat2) { aparat2 = aparatAux; } } } else { aparat2 = null; } Rezervare rezervare = new Rezervare(data, (int)durata, aparat1, aparat2, client, (int)id); rezervari.Add(rezervare); } } } }
public Rezervare(DateTime data, int durata, Aparat aparat1, Aparat aparat2, Client client, int id) { Data = data; Durata = durata; Aparat1 = aparat1; Aparat2 = aparat2; Client = client; Id = id; }
private void UpdateAparat(Aparat aparat) { string query = "UPDATE Aparate SET Denumire=@denumire WHERE Id=@id"; using (SqliteConnection connection = new SqliteConnection(connectionString)) { SqliteCommand command = new SqliteCommand(query, connection); command.Parameters.AddWithValue("@denumire", aparat.Denumire); command.Parameters.AddWithValue("@id", aparat.Id); connection.Open(); command.ExecuteNonQuery(); } }
private void RemoveAparat(Aparat aparat) { string query = "DELETE FROM Aparate WHERE Id=@id"; using (SqliteConnection connection = new SqliteConnection(connectionString)) { SqliteCommand command = new SqliteCommand(query, connection); command.Parameters.AddWithValue("@id", aparat.Id); connection.Open(); command.ExecuteNonQuery(); aparate.Remove(aparat); } }
private void AddAparat(Aparat aparat) { string query = "INSERT INTO Aparate(Denumire) VALUES(@denumire); SELECT last_insert_rowid()"; using (SqliteConnection connection = new SqliteConnection(connectionString)) { SqliteCommand command = new SqliteCommand(query, connection); command.Parameters.AddWithValue("@denumire", aparat.Denumire); connection.Open(); long id = (long)command.ExecuteScalar(); aparat.Id = (int)id; aparate.Add(aparat); } }
private void cbAparat2_Validating(object sender, CancelEventArgs e) { if (cbAparat2.SelectedItem.ToString() == cbAparat1.SelectedItem.ToString()) { errorProvider.SetError(cbAparat2, "Alegeti un aparat2 diferit fata de aparat1!"); e.Cancel = true; } else { Aparat aparat = (Aparat)cbAparat2.SelectedItem; if (!aparat.IsAvailable(rezervari, dtpData.Value, int.Parse(cbDurata.SelectedItem.ToString()))) { errorProvider.SetError(cbAparat2, "Aparatul nu este disponibil!"); e.Cancel = true; } } }
private void cbAparat1_Validating(object sender, CancelEventArgs e) { if (cbAparat1.SelectedItem == null) { errorProvider.SetError(cbAparat1, "Cel putin un aparat trebuie selectat"); e.Cancel = true; } else { Aparat aparat = (Aparat)cbAparat1.SelectedItem; if (!aparat.IsAvailable(rezervari, dtpData.Value, int.Parse(cbDurata.SelectedItem.ToString()))) { errorProvider.SetError(cbAparat1, "Aparatul nu este disponibil!"); e.Cancel = true; } } }
private void editeazaToolStripMenuItem_Click(object sender, EventArgs e) { if (lvAparate.SelectedItems.Count == 0) { MessageBox.Show("Niciun aparat nu a fost selectat!", "Aparat invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ListViewItem lvItem = lvAparate.SelectedItems[0]; Aparat aparat = (Aparat)lvItem.Tag; FormAparateEdit formAparateEdit = new FormAparateEdit(aparat); if (formAparateEdit.ShowDialog() == DialogResult.OK) { DisplayAparate(); } }
private void btnAdaugaAparat_Click(object sender, EventArgs e) { Aparat aparat = new Aparat(); aparat.Denumire = tbDenumire.Text.Trim(); aparat.Id = 1; if (aparat.Denumire.Length > 3) { errorProvider.SetError(tbDenumire, null); AddAparat(aparat); tbDenumire.ResetText(); DisplayAparate(); } else { errorProvider.SetError(tbDenumire, "Denumire invalida!"); } }
private void stergeToolStripMenuItem_Click(object sender, EventArgs e) { if (lvAparate.SelectedItems.Count == 0) { MessageBox.Show("Niciun aparat nu a fost selectat!", "Aparat invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ListViewItem lvItem = lvAparate.SelectedItems[0]; Aparat aparat = (Aparat)lvItem.Tag; DialogResult result = MessageBox.Show("Sigur doriti sa stergeti aparatul: " + aparat.ToString() + " ?\nStergand un aparat veti sterge si toate rezervarile pentru acesta.\nAceasta optiune este ireversibila!", "Stergere aparat", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { RemoveAparat(aparat); RemoveRezervare(aparat); DisplayAparate(); } }
private void LoadAparate() { string query = "SELECT * FROM Aparate"; using (SqliteConnection connection = new SqliteConnection(connectionString)) { SqliteCommand command = new SqliteCommand(query, connection); connection.Open(); using (SqliteDataReader reader = command.ExecuteReader()) { while (reader.Read()) { long id = (long)reader["Id"]; string denumire = (string)reader["Denumire"]; Aparat aparat = new Aparat(denumire, (int)id); aparate.Add(aparat); } } } }
public FormAparateEdit(Aparat aparat) { InitializeComponent(); this.aparat = aparat; }
private void btnAdaugaRezervare_Click(object sender, EventArgs e) { Rezervare rezervare = new Rezervare(); if (dtpData.Value < DateTime.Now) { errorProvider.SetError(dtpData, "Data este invalida!"); return; } else { errorProvider.SetError(dtpData, null); rezervare.Data = dtpData.Value; } if (cbDurata.SelectedItem == null) { errorProvider.SetError(cbDurata, "Selecteaza durata rezervarii!"); return; } else { errorProvider.SetError(cbDurata, null); rezervare.Durata = int.Parse(cbDurata.SelectedItem.ToString()); } if (cbClienti.SelectedItem == null) { errorProvider.SetError(cbClienti, "Selecteaza clientul!"); return; } else { errorProvider.SetError(cbClienti, null); rezervare.Client = (Client)cbClienti.SelectedItem; } Aparat aparat1 = (Aparat)cbAparat1.SelectedItem; if (cbAparat1.SelectedItem == null) { errorProvider.SetError(cbAparat1, "Cel putin un aparat trebuie selectat"); return; } else if (!aparat1.IsAvailable(rezervari, dtpData.Value, int.Parse(cbDurata.SelectedItem.ToString()))) { errorProvider.SetError(cbAparat1, "Aparatul nu este disponibil!"); return; } else { errorProvider.SetError(cbAparat1, null); rezervare.Aparat1 = (Aparat)cbAparat1.SelectedItem; } Aparat aparat2 = (Aparat)cbAparat2.SelectedItem; if (cbAparat2.SelectedItem == null) { rezervare.Aparat2 = null; } else if (!aparat2.IsAvailable(rezervari, dtpData.Value, int.Parse(cbDurata.SelectedItem.ToString()))) { errorProvider.SetError(cbAparat2, "Aparatul nu este disponibil!"); return; } else if (cbAparat2.SelectedItem.ToString() == cbAparat1.SelectedItem.ToString()) { errorProvider.SetError(cbAparat2, "Alegeti un aparat2 diferit fata de aparat1!"); return; } else { errorProvider.SetError(cbAparat2, null); rezervare.Aparat2 = (Aparat)cbAparat2.SelectedItem; } dtpData.ResetText(); cbDurata.SelectedIndex = -1; cbClienti.SelectedIndex = -1; cbAparat1.SelectedIndex = -1; cbAparat2.SelectedIndex = -1; AddRezervare(rezervare); DisplayRezervari(); rezervare.Client.NrRezervari++; }