public static void aggiungiPresenza(Presenza pres, string idUtente) { try { if (conn == null) { initDBConnection(); } cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "INSERT INTO presenze (idutente,dataingresso,oraIn,oraOut)" + "VALUES(@idutente,@dataingresso,@oraIn,@oraOut); SELECT MAX(idpresenze) FROM presenze"; cmd.Prepare(); cmd.Parameters.AddWithValue("@idutente", idUtente); cmd.Parameters.AddWithValue("@dataingresso", pres.Data); cmd.Parameters.AddWithValue("@oraIn", pres.OraIngresso); cmd.Parameters.AddWithValue("@oraOut", pres.OraUscita); int value = (int)cmd.ExecuteScalar(); pres.IdPresenza = value; } catch (MySqlException ex) { Console.WriteLine("Error: {0}", ex.ToString()); } finally { if (rdr != null) { rdr.Close(); } } }
public static void aggiungiPresenza(Presenza pres, string idUtente) { try { m_dbConnection.Open(); string sql = "INSERT INTO presenze (idutente,dataingresso,oraIn,oraOut)" + "VALUES('" + idUtente + "','" + pres.Data + "','" + pres.OraIngresso + "','" + pres.OraUscita + "')"; SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection); command.ExecuteNonQuery(); Helper.loggerDBOperation(sql); sql = "SELECT MAX(idpresenze) as id FROM presenze"; command = new SQLiteCommand(sql, m_dbConnection); SQLiteDataReader rdr = command.ExecuteReader(); while (rdr.Read()) { pres.IdPresenza = Convert.ToInt32(rdr["id"].ToString()); } } catch (Exception ex) { Console.WriteLine("Error: {0}", ex.ToString()); } finally { m_dbConnection.Close(); } }
private void btnModificaPresenza_Click(object sender, RoutedEventArgs e) { if (utenteCorrente != null && gridPresenze.SelectedItem != null) { Presenza pres = (Presenza)gridPresenze.SelectedItem; WindowEdit windowEdit = new WindowEdit(pres); windowEdit.ShowDialog(); loadPresenzeTabella(); } }
public WindowEdit(Presenza pres) { InitializeComponent(); type = "pres"; presToEdit = pres; setVisibility(); datePickerIngressi.SelectedDate = pres.Data; textBoxOraIn.Text = pres.OraIngresso.ToString(); textBoxOraOut.Text = pres.OraUscita.ToString(); }
private void btnUscita_Click(object sender, RoutedEventArgs e) { if (utenteCorrente != null) { Presenza pres = utenteCorrente.ListPresenze[utenteCorrente.getLastKey()]; pres.OraUscita = new TimeSpan(DateTime.Now.TimeOfDay.Hours, DateTime.Now.TimeOfDay.Minutes, DateTime.Now.TimeOfDay.Seconds); btnIngresso.IsEnabled = true; btnUscita.IsEnabled = false; DBSqlLite.modificaPresenza(pres); loadPresenzeTabella(); } }
private void riempiDatiUtente() { try { if (utenteCorrente != null) { lblNomeVal.Content = utenteCorrente.Nome; lblCognomeVal.Content = utenteCorrente.Cognome; lblCFVal.Content = utenteCorrente.CodiceFiscale; lblDataNascitaVal.Content = utenteCorrente.DataDiNascita.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture); lblEmailVal.Content = utenteCorrente.Email; lblIndirizzoVal.Content = utenteCorrente.Indirizzo; lblLuogoNascitaVal.Content = utenteCorrente.LuogoNascita; lblProvinciaVal.Content = utenteCorrente.Provincia.getTestoProvincia(); lblScadAbbVal.Content = utenteCorrente.ScadenzaAbb.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture); lblSessoVal.Content = utenteCorrente.Sesso; lblStato.Content = utenteCorrente.Stato; lblTelefonoVal.Content = utenteCorrente.Telefono; lblVisitaVal.Content = utenteCorrente.ScadenzaVisitaMedica.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture); btnCI.IsEnabled = File.Exists(utenteCorrente.getDocumentPath("CI")); btnVisita.IsEnabled = File.Exists(utenteCorrente.getDocumentPath("VM")); checkAttivo.IsChecked = utenteCorrente.isAttivo(); if (utenteCorrente.ListPresenze.Count > 0) { Presenza pres = utenteCorrente.ListPresenze[utenteCorrente.getLastKey()]; if (pres.OraUscita != null) { btnIngresso.IsEnabled = true; btnUscita.IsEnabled = false; } else { btnIngresso.IsEnabled = false; btnUscita.IsEnabled = true; } } else { btnIngresso.IsEnabled = true; btnUscita.IsEnabled = false; } loadPresenzeTabella(); loadStoricoTabella(); } } catch (Exception ex) { Helper.Logger("class=MainWindow riempiDatiUtente - " + ex.Message); } }
private void btnIngresso_Click(object sender, RoutedEventArgs e) { if (utenteCorrente != null) { Presenza pres = new Presenza(); pres.Data = DateTime.Now; pres.OraIngresso = new TimeSpan(DateTime.Now.TimeOfDay.Hours, DateTime.Now.TimeOfDay.Minutes, DateTime.Now.TimeOfDay.Seconds); utenteCorrente.ListPresenze.Add(pres.Data, pres); btnIngresso.IsEnabled = false; btnUscita.IsEnabled = true; DBSqlLite.aggiungiPresenza(pres, utenteCorrente.Identifier); loadPresenzeTabella(); } }
public static void eliminaPresenza(Presenza pres) { try { m_dbConnection.Open(); string sql = " DELETE FROM presenze " + " where idpresenze = " + pres.IdPresenza; SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection); command.ExecuteNonQuery(); Helper.loggerDBOperation(sql); } catch (Exception ex) { Console.WriteLine("Error: {0}", ex.ToString()); } finally { m_dbConnection.Close(); } }
public static void modificaPresenza(Presenza pres) { try { m_dbConnection.Open(); string sql = " UPDATE presenze SET dataingresso = '" + pres.Data.ToString("yyyy-MM-dd hh:mm:ss") + "',oraIn = '" + pres.OraIngresso.ToString() + "',oraOut = '" + pres.OraUscita.ToString() + "'" + " where idpresenze = " + pres.IdPresenza; SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection); command.ExecuteNonQuery(); Helper.loggerDBOperation(sql); } catch (Exception ex) { Console.WriteLine("Error: {0}", ex.ToString()); } finally { m_dbConnection.Close(); } }
public static void modificaPresenza(Presenza pres) { try { if (conn == null) { initDBConnection(); } cmd = new MySqlCommand(); cmd.Connection = conn; //cmd.CommandText = " UPDATE presenze " // + "SET idutente = @idutente,dataingresso = '@dataingresso'," // + "oraIn = '@oraIn',oraOut = '@oraOut' " // + "where idpresenze = " + pres.IdPresenza; cmd.CommandText = "UPDATE presenze SET dataingresso = '" + pres.Data.ToString("yyyy-MM-dd hh:mm:ss") + "',oraIn = '" + pres.OraIngresso.ToString() + "',oraOut = '" + pres.OraUscita.ToString() + "'" + " where idpresenze = " + pres.IdPresenza; //cmd.CommandText = "UPDATE presenze SET dataingresso = '2017-03-20 19:59:27',oraIn = '19:59:27',oraOut = '19:59:30' where idpresenze = 9"; cmd.Prepare(); cmd.Parameters.AddWithValue("@dataingresso", pres.Data.ToString("yyyy-MM-dd hh:mm:ss")); cmd.Parameters.AddWithValue("@oraIn", pres.OraIngresso.ToString()); cmd.Parameters.AddWithValue("@oraOut", pres.OraUscita.ToString()); cmd.ExecuteNonQuery(); } catch (MySqlException ex) { Console.WriteLine("Error: {0}", ex.ToString()); } finally { if (rdr != null) { rdr.Close(); } } }
public static SortedList <string, Utente> readClienti() { SortedList <string, Utente> listClienti = new SortedList <string, Utente>(); try { if (conn == null) { initDBConnection(); } string queryString = "SELECT clienti.idcliente,clienti.nome,clienti.cognome,clienti.sesso," + "clienti.codiceFiscale,clienti.dataNascita,clienti.luogoNascita,clienti.email," + "clienti.telefono,clienti.indirizzo,province.abbr,province.nome,province.regione," + "clienti.stato,clienti.scadAbb,clienti.scadVisita,clienti.stato_cliente" + " FROM clienti inner join province on province.abbr = clienti.provincia"; cmd = new MySqlCommand(queryString, conn); rdr = cmd.ExecuteReader(); while (rdr.Read()) { Utente user = new Utente(); user.Identifier = rdr.GetString(0); user.Nome = rdr.GetString(1); user.Cognome = rdr.GetString(2); user.Sesso = rdr.GetString(3); user.CodiceFiscale = rdr.GetString(4); user.DataDiNascita = rdr.GetDateTime(5); user.LuogoNascita = rdr.GetString(6); user.Email = rdr.GetString(7); user.Telefono = rdr.GetString(8); user.Indirizzo = rdr.GetString(9); user.Provincia = new Provincia(rdr.GetString(10), rdr.GetString(11), rdr.GetString(12)); user.Stato = rdr.GetString(13); user.ScadenzaAbb = rdr.GetDateTime(14); user.ScadenzaVisitaMedica = rdr.GetDateTime(15); try { user.Status = Convert.ToInt32(rdr.GetString(16).ToString()); } catch (Exception ex) { if (Convert.ToBoolean(rdr["stato_cliente"].ToString())) { user.Status = 1; } else { user.Status = 0; } } listClienti.Add(user.Identifier, user); } if (rdr != null) { rdr.Close(); } foreach (string id in listClienti.Keys) { try { queryString = "SELECT presenze.dataingresso,presenze.oraIn,presenze.oraOut,presenze.idpresenze" + " FROM presenze INNER JOIN clienti on clienti.idcliente = presenze.idutente" + " WHERE idcliente = " + id; cmd = new MySqlCommand(queryString, conn); rdr = cmd.ExecuteReader(); while (rdr.Read()) { Utente user = listClienti[id]; Presenza pres = new Presenza(); pres.Data = rdr.GetDateTime(0); pres.OraIngresso = rdr.GetTimeSpan(1); pres.OraUscita = rdr.GetTimeSpan(2); pres.IdPresenza = rdr.GetInt32(3); user.ListPresenze.Add(pres.Data, pres); } } catch (Exception ex) { Helper.Logger("class=DBHelper readClienti.readPresenze ->" + ex.Message); } finally { if (rdr != null) { rdr.Close(); } } } } catch (Exception ex) { Helper.Logger("class=DBHelper readClienti ->" + ex.Message); } finally { if (rdr != null) { rdr.Close(); } } return(listClienti); }
public static SortedList <string, Utente> readClienti() { SortedList <string, Utente> listClienti = new SortedList <string, Utente>(); try { m_dbConnection.Open(); string sql = "SELECT idcliente,clienti.nome as nomeCl,cognome,sesso,codiceFiscale," + "dataNascita,luogoNascita,email,telefono,indirizzo,province.cod as provC,province.nome as provN," + "province.regione as provR,stato,scadAbb,scadVisita,stato_cliente" + " FROM clienti inner join province on province.cod = provincia"; SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection); SQLiteDataReader rdr = command.ExecuteReader(); while (rdr.Read()) { try { Utente user = new Utente(); user.Identifier = rdr["idcliente"].ToString(); user.Nome = rdr["nomeCl"].ToString(); user.Cognome = rdr["cognome"].ToString(); user.Sesso = rdr["sesso"].ToString(); user.CodiceFiscale = rdr["codiceFiscale"].ToString(); user.DataDiNascita = Convert.ToDateTime(rdr["dataNascita"].ToString()); user.LuogoNascita = rdr["luogoNascita"].ToString(); user.Email = rdr["email"].ToString(); user.Telefono = rdr["telefono"].ToString(); user.Indirizzo = rdr["indirizzo"].ToString(); user.Provincia = new Provincia(rdr["provC"].ToString(), rdr["provN"].ToString(), rdr["provR"].ToString()); user.Stato = rdr["stato"].ToString(); user.ScadenzaAbb = Convert.ToDateTime(rdr["scadAbb"].ToString()); user.ScadenzaVisitaMedica = Convert.ToDateTime(rdr["scadVisita"].ToString()); try { user.Status = Convert.ToInt32(rdr["stato_cliente"].ToString()); } catch (Exception ex) { if (Convert.ToBoolean(rdr["stato_cliente"].ToString())) { user.Status = 1; } else { user.Status = 0; } } listClienti.Add(user.Identifier, user); }catch (Exception ex) { Helper.Logger("class=DBSqlLite readCliente " + ex.Message); } } if (rdr != null) { rdr.Close(); } foreach (string id in listClienti.Keys) { try { sql = "SELECT presenze.dataingresso as dataIn,presenze.oraIn as oraIn,presenze.oraOut as oraOut,presenze.idpresenze as idPres" + " FROM presenze INNER JOIN clienti on clienti.idcliente = presenze.idutente" + " WHERE idcliente = " + id; command = new SQLiteCommand(sql, m_dbConnection); rdr = command.ExecuteReader(); while (rdr.Read()) { Utente user = listClienti[id]; Presenza pres = new Presenza(); pres.Data = Convert.ToDateTime(rdr["dataIn"].ToString()); pres.OraIngresso = TimeSpan.Parse(rdr["oraIn"].ToString()); pres.OraUscita = TimeSpan.Parse(rdr["oraOut"].ToString()); pres.IdPresenza = Convert.ToInt32(rdr["idPres"].ToString()); user.ListPresenze.Add(pres.Data, pres); } } catch (Exception ex) { Helper.Logger("class=DBSqlLite readClienti.readPresenze ->" + ex.Message); } finally { if (rdr != null) { rdr.Close(); } } } } catch (Exception ex) { Helper.Logger("class=DBSqlLite readClienti ->" + ex.Message); } finally { m_dbConnection.Close(); } return(listClienti); }