public static List <TipAbonament> findAllTipAbonament() { string query = "SELECT * FROM Abonamente"; List <TipAbonament> abonamente = new List <TipAbonament>(); using (SQLiteConnection connection = new SQLiteConnection(Connection.ConnectionString)) { connection.Open(); using (SQLiteCommand command = new SQLiteCommand(query, connection)) { using (SQLiteDataReader sqlReader = command.ExecuteReader()) { while (sqlReader.Read()) { long id = (long)sqlReader["Id"]; string denumire = (string)sqlReader["Denumire"]; int minute = Convert.ToInt32((long)sqlReader["Minute"]); int mesaje = Convert.ToInt32((long)sqlReader["Mesaje"]); int net_MB = Convert.ToInt32((long)sqlReader["Net_MB"]); double pret = (double)sqlReader["Pret"]; TipAbonament abonament = new TipAbonament(id, denumire, minute, mesaje, net_MB, pret); abonamente.Add(abonament); } } } return(abonamente); } }
public static TipAbonament findTipAbonamentById(long idTipAbonament) { string query = "SELECT * FROM Abonamente where Id=@id"; TipAbonament abonament = null; using (SQLiteConnection connection = new SQLiteConnection(Connection.ConnectionString)) { connection.Open(); using (SQLiteCommand command = new SQLiteCommand(query, connection)) { command.Parameters.AddWithValue("@id", idTipAbonament); using (SQLiteDataReader sqlReader = command.ExecuteReader()) { while (sqlReader.Read()) { long id = (long)sqlReader["Id"]; string denumire = (string)sqlReader["Denumire"]; int minute = Convert.ToInt32((long)sqlReader["Minute"]); int mesaje = Convert.ToInt32((long)sqlReader["Mesaje"]); int net_MB = Convert.ToInt32((long)sqlReader["Net_MB"]); double pret = (double)sqlReader["Pret"]; abonament = new TipAbonament(id, denumire, minute, mesaje, net_MB, pret); } } } return(abonament); } }
public static void deleteAbonament(TipAbonament aboanment) { var query = "DELETE FROM Abonamente WHERE Id = @id"; using (SQLiteConnection connection = new SQLiteConnection(Connection.ConnectionString)) { connection.Open(); using (SQLiteCommand command = new SQLiteCommand(query, connection)) { command.Parameters.AddWithValue("@id", aboanment.Id); command.ExecuteNonQuery(); } } }
private void BtnEdit_Click(object sender, EventArgs e) { if (lvTipAbonament.SelectedItems.Count != 1) { MessageBox.Show("Alegeti un abonament!"); return; } ListViewItem lvi = lvTipAbonament.SelectedItems[0]; TipAbonament abonament = (TipAbonament)lvi.Tag; EditTipAbonamentForm editTipAbonamentForm = new EditTipAbonamentForm(abonament); if (editTipAbonamentForm.ShowDialog() == DialogResult.OK) { TipAbonamentRepository.updateAbonament(abonament); AfisareAbonamente(); } }
private void Delete_Click(object sender, EventArgs e) { if (lvTipAbonament.SelectedItems.Count != 1) { MessageBox.Show("Alegeti un abonament!"); return; } if (MessageBox.Show("Sunteti sigur?", "Stergere Tip Abonament", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { ListViewItem lvi = lvTipAbonament.SelectedItems[0]; TipAbonament abonament = (TipAbonament)lvi.Tag; TipAbonamentRepository.deleteAbonament(abonament); abonamente.Remove(abonament); AfisareAbonamente(); } }
public static void updateAbonament(TipAbonament abonament) { var query = "UPDATE Abonamente " + "SET Denumire = @denumire, Minute = @minute, Mesaje = @mesaje, Net_MB = @net_MB, Pret = @pret " + "WHERE Id = @id"; using (SQLiteConnection connection = new SQLiteConnection(Connection.ConnectionString)) { connection.Open(); using (SQLiteCommand command = new SQLiteCommand(query, connection)) { command.Parameters.AddWithValue("@denumire", abonament.Name); command.Parameters.AddWithValue("@minute", abonament.NoMinutes); command.Parameters.AddWithValue("@mesaje", abonament.NoMessages); command.Parameters.AddWithValue("@net_MB", abonament.NoNetMb); command.Parameters.AddWithValue("@pret", abonament.Price); command.Parameters.AddWithValue("@id", abonament.Id); command.ExecuteNonQuery(); } } }
public void AfisareClienti() { lvClienti.Items.Clear(); foreach (var client in clienti) { var lvi = new ListViewItem(client.Nume); lvi.SubItems.Add(client.Prenume); lvi.SubItems.Add(client.DataNasterii.ToShortDateString()); TipAbonament abonament = TipAbonamentRepository.findTipAbonamentById(client.IdAbonament); lvi.SubItems.Add(abonament.Name); ExtraOptiune extraOptiune = ExtraOptiuneRepository.findExtraOptiuneById(client.IdExtraOptiune); lvi.SubItems.Add(extraOptiune.Name); Plata plata = PlataRepository.findPlataById(client.IdFactura); lvi.SubItems.Add(plata.Value.ToString()); lvi.SubItems.Add(plata.DueDate.ToShortDateString()); lvi.Tag = client; lvClienti.Items.Add(lvi); } }
public EditTipAbonamentForm(TipAbonament tipAbonament) { InitializeComponent(); this.tipAbonament = tipAbonament; }
public Abonament(TipAbonament tipAbonament, uint pret) { TipAbonament = TipAbonament.AbonamentVIP; Pret = pret; }
public Abonament(TipAbonament tipAbonament) { TipAbonament = TipAbonament.AbonamentSimplu; }
private void BtnAdd_Click(object sender, EventArgs e) { bool isValid = true; string denumireAbonament = tbDenumireAb.Text.Trim(); if (denumireAbonament.Length < 3) { isValid = false; epName.SetError( tbDenumireAb, "At least 3 characters!"); } string minute = tbMinute.Text; if (minute.Length < 1 || (minute.StartsWith("0") && minute.Length > 1)) { isValid = false; epMinutes.SetError( tbMinute, "Invalid quantity!"); } string mesage = tbMesaje.Text; if (mesage.Length < 1 || (mesage.StartsWith("0") && mesage.Length > 1)) { isValid = false; epMessages.SetError( tbMesaje, "Invalid quantity!"); } string net_MB = tbNet.Text; if (net_MB.Length < 1 || (net_MB.StartsWith("0") && net_MB.Length > 1)) { isValid = false; epNetMb.SetError( tbNet, "Invalid quantity!"); } string pretAbonament = tbValoare.Text; if (pretAbonament.Length < 1 || (pretAbonament.StartsWith("0") && ((pretAbonament.Contains(".") && pretAbonament.IndexOf('.') != 1) || (!pretAbonament.Contains(".") && pretAbonament.Length > 1))) || (pretAbonament.StartsWith("0") && pretAbonament.Contains(".") && pretAbonament.IndexOf('.') == 1 && pretAbonament.Length < 3)) { isValid = false; epValoarePlati.SetError( tbValoare, "Invalid value!"); } if (!isValid) { MessageBox.Show( "Form contains errors!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { long id = TipAbonamentRepository.saveTipAbonament(denumireAbonament, int.Parse(minute), int.Parse(mesage), int.Parse(net_MB), double.Parse(pretAbonament)); var tipAbonament = new TipAbonament( id, denumireAbonament, int.Parse(minute), int.Parse(mesage), int.Parse(net_MB), double.Parse(pretAbonament)); abonamente.Add(tipAbonament); AfisareAbonamente(); ClearForm(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }