public static DataTable LoadTemplateFirmati(TemplateLinq template) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } string strQuery = string.Format(@"SELECT TEMPLATE_LINQ.DESCR, TEMPLATE_LINQ.PATH, TEMPLATE_LINQ.DTSIGN FROM TEMPLATE_LINQ INNER JOIN Users ON Users.KEY_USER = TEMPLATE_LINQ.KEY_USER WHERE Users.KEY_USER = {0} ORDER BY TEMPLATE_LINQ.DTSIGN DESC", template.KEY_USER.ToString()); var mySqlDataAdapter = new MySqlDataAdapter(strQuery, GestioneMySql.connection); DataTable dataTable = new DataTable(); mySqlDataAdapter.Fill(dataTable); if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } return(dataTable); } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); return(null); } }
public static void SaveTemplate_Linq(TemplateLinq templateLinq, Users user) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } var sb = new StringBuilder(); sb.AppendLine("SELECT *"); sb.AppendLine("FROM TEMPLATE_LINQ"); sb.AppendLine("WHERE KEY_USER = @KEY_USER AND KEY_TEMPL_L = @KEY_TEMPL_L"); MySqlCommand cmd = new MySqlCommand(sb.ToString(), GestioneMySql.connection); cmd.Parameters.Add(new MySqlParameter("KEY_USER", templateLinq.KEY_USER)); cmd.Parameters.Add(new MySqlParameter("KEY_TEMPL_L", templateLinq.KEY_TEMPL_L)); MySqlDataReader dr = cmd.ExecuteReader(); if (!dr.Read()) { dr.Close(); MySqlCommand comm = GestioneMySql.connection.CreateCommand(); comm.CommandText = "INSERT INTO TEMPLATE_LINQ(KEY_USER,DTSIGN,DESCR,PATH,KEY_TEMPL) VALUES(@KEY_USER,@DTSIGN,@DESCR,@PATH,@KEY_TEMPL)"; comm.Parameters.AddWithValue("@KEY_USER", templateLinq.KEY_USER); comm.Parameters.AddWithValue("@DTSIGN", DateTime.Now.ToString("yyyyMMddHHmm")); comm.Parameters.AddWithValue("@DESCR", templateLinq.DESCR); comm.Parameters.AddWithValue("@PATH", templateLinq.PATH); comm.Parameters.AddWithValue("@KEY_TEMPL", templateLinq.KEY_TEMPL); comm.ExecuteNonQuery(); } dr.Close(); //deve essere gestita la parte delle check box //Deve aggiornare la KEY PERM della ute //UtenzeDB.SaveUtenze(ute); if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); } }