public static MySqlDataAdapter LoadComuni(int idKey) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter(string.Format(@"SELECT * FROM COMUNI WHERE ID_PROV = {0} ORDER BY COMUNE ASC", idKey), GestioneMySql.StringaConnessione); if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } return(mySqlDataAdapter); } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); return(null); } }
public static void SaveConfig(Config.ParamValues paramValues, string value) { try { MySqlCommand comm = GestioneMySql.connection.CreateCommand(); if (LoadConfig(paramValues).CONF_VALUE == null) { comm.CommandText = "INSERT INTO CONFIG(CONF_PARAM,CONF_VALUE) VALUES(@CONF_PARAM,@CONF_VALUE)"; } else { comm.CommandText = "UPDATE CONFIG SET CONF_VALUE=@CONF_VALUE WHERE CONF_PARAM=@CONF_PARAM"; } comm.Parameters.AddWithValue("@CONF_PARAM", paramValues.ToString()); comm.Parameters.AddWithValue("@CONF_VALUE", value); if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } comm.ExecuteNonQuery(); if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); } }
public static void SaveTemplate(TemplateXml templateXml) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } if (!string.IsNullOrEmpty(templateXml.FILE_NM)) { MySqlCommand comm = GestioneMySql.connection.CreateCommand(); comm.CommandText = "INSERT INTO TEMPLATEXML(FILE_NM,FILE_PATH,DTINS) VALUES(@FILE_NM,@FILE_PATH,@DTINS)"; comm.Parameters.AddWithValue("@FILE_NM", templateXml.FILE_NM); comm.Parameters.AddWithValue("@FILE_PATH", templateXml.FILE_PATH); comm.Parameters.AddWithValue("@DTINS", DateTime.Now.ToString("yyyyMMddHHmm")); comm.ExecuteNonQuery(); } if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); } }
public static bool Exists(string strFileName) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } MySqlCommand cmd = new MySqlCommand("SELECT * FROM TEMPLATEXML", GestioneMySql.connection); cmd.Parameters.Add(new MySqlParameter("FILE_NM", strFileName)); MySqlDataReader dr = cmd.ExecuteReader(); bool res = false; while (dr.Read()) { res = (dr["FILE_NM"] != DBNull.Value) ? true : false; } if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } return(res); } catch (Exception ex) { throw ex; } }
public static void SaveTemplateLinq(int idKeyUte) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } MySqlCommand comm = GestioneMySql.connection.CreateCommand(); comm.CommandText = "INSERT INTO TEMPLATE_LINQ(KEY_USER,DTSIGN) VALUES(@KEY_USER,@DTSIGN)"; comm.Parameters.AddWithValue("@KEY_USER", idKeyUte); comm.Parameters.AddWithValue("@DTSIGN", DateTime.Now.ToString("yyyyMMddHHmm")); comm.ExecuteNonQuery(); if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); } }
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 SaveNewLogin(Login login) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } MySqlCommand comm = GestioneMySql.connection.CreateCommand(); comm.CommandText = "INSERT INTO LOGIN (USER_ID, PASSWORD_ID, X_TEMPLATE, X_FIRST_LOG, DATE_EXPIRED, NAME, SURNAME) VALUES (@USER_ID, @PASSWORD_ID, @X_TEMPLATE, @X_FIRST_LOG, @DATE_EXPIRED, @NAME, @SURNAME)"; comm.Parameters.AddWithValue("@USER_ID", login.USER_ID); comm.Parameters.AddWithValue("@PASSWORD_ID", ToSha256(login.PASSWORD_ID)); comm.Parameters.AddWithValue("@X_TEMPLATE", login.X_TEMPLATE); comm.Parameters.AddWithValue("@X_FIRST_LOG", login.X_FIRST_LOG); comm.Parameters.AddWithValue("@DATE_EXPIRED", login.DATE_EXPIRED.Date.ToString("yyyyMMdd").StringOrNull()); comm.Parameters.AddWithValue("@NAME", login.NAME); comm.Parameters.AddWithValue("@SURNAME", login.SURNAME); comm.ExecuteNonQuery(); if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); throw ex; } }
public static LoginAccess LoadLoginAccess() { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } LoginAccess loginAccess; using (MySqlCommand cmd = new MySqlCommand("SELECT DT_LOGIN, KEY_LOG, USER_ID FROM LOGIN_ACCESS INNER JOIN LOGIN ON LOGIN.KEY_LOG = KEY_LOG_ACC ORDER BY DT_LOGIN DESC LIMIT 1", GestioneMySql.connection)) { loginAccess = new LoginAccess(); MySqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { loginAccess.USER_ID = dr.GetString("USER_ID"); loginAccess.DT_LOGIN = DateTime.ParseExact(dr.GetString("DT_LOGIN"), "yyyyMMddHHmmss", null, System.Globalization.DateTimeStyles.None); loginAccess.KEY_LOG = dr.GetUInt16("KEY_LOG"); } dr.Close(); } GestioneMySql.CloseConnection(); return(loginAccess); } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); return(null); } }
public static void SaveLoginAccess(int?intKeyLog) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } MySqlCommand comm = GestioneMySql.connection.CreateCommand(); comm.CommandText = "INSERT INTO LOGIN_ACCESS (KEY_LOG_ACC, DT_LOGIN) VALUES (@KEY_LOG_ACC, @DT_LOGIN)"; comm.Parameters.AddWithValue("@KEY_LOG_ACC", intKeyLog); comm.Parameters.AddWithValue("@DT_LOGIN", DateTime.Now.ToString("yyyyMMddHHmmss")); comm.ExecuteNonQuery(); if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); } }
public static MySqlDataAdapter LoadLocalita(int idKey) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter(string.Format(@"SELECT 0 ID, NULL LOCALITA, NULL ID_COMU UNION SELECT ID, LOCALITA, ID_COMU FROM LOCALITA WHERE ID_COMU = {0} ORDER BY LOCALITA ASC", idKey), GestioneMySql.StringaConnessione); if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } return(mySqlDataAdapter); } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); return(null); } }
public static Comuni LoadComuni(int?keyCom) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } var sb = new StringBuilder(); Comuni comuni = new Comuni(); sb.AppendLine("SELECT *"); sb.AppendLine("FROM COMUNI "); sb.AppendLine("WHERE ID = @ID"); MySqlCommand cmd = new MySqlCommand(sb.ToString(), GestioneMySql.connection); cmd.Parameters.Add(new MySqlParameter("ID", keyCom)); MySqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { if (!dr.IsDBNull(dr.GetOrdinal("ID"))) { comuni.ID = dr.GetInt32("ID"); } ; if (!dr.IsDBNull(dr.GetOrdinal("CAP"))) { if (!string.IsNullOrEmpty(dr.GetString("CAP"))) { comuni.CAP = dr.GetString("CAP"); } } ; if (!dr.IsDBNull(dr.GetOrdinal("COMUNE"))) { if (!string.IsNullOrEmpty(dr.GetString("COMUNE"))) { comuni.COMUNE = dr.GetString("COMUNE"); } } ; } dr.Close(); GestioneMySql.CloseConnection(); return(comuni); } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); return(null); } }
public static List <Flag> LoadSingleFlagSignature(string strKeyTempl, string strTypFlag) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } string strQuery = string.Format(@"SELECT X_CORD, Y_CORD, WIDTH, N_PAGE FROM FLAG WHERE FLAG.KEY_TEMPL = {0} AND FLAG.TYP_FLAG = '{1}'", strKeyTempl, strTypFlag); MySqlCommand cmd = new MySqlCommand(strQuery, GestioneMySql.connection); MySqlDataReader dr = cmd.ExecuteReader(); List <Flag> flagsList = new List <Flag>(); while (dr.Read()) { Flag flag = new Flag(); if (!dr.IsDBNull(dr.GetOrdinal("X_CORD"))) { flag.X_CORD = dr.GetInt32("X_CORD"); } if (!dr.IsDBNull(dr.GetOrdinal("WIDTH"))) { flag.WIDTH = dr.GetInt32("WIDTH"); } ; if (!dr.IsDBNull(dr.GetOrdinal("Y_CORD"))) { flag.Y_CORD = dr.GetInt32("Y_CORD"); } ; if (!dr.IsDBNull(dr.GetOrdinal("N_PAGE"))) { flag.N_PAGE = dr.GetInt32("N_PAGE"); } ; flagsList.Add(flag); } dr.Close(); GestioneMySql.CloseConnection(); return(flagsList); } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); return(null); } }
public static Citta LoadCitta(int intkeyLoc) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } var sb = new StringBuilder(); Citta citta = new Citta(); sb.AppendLine("SELECT *"); sb.AppendLine("FROM LOCALITA"); sb.AppendLine("WHERE ID = @ID"); MySqlCommand cmd = new MySqlCommand(sb.ToString(), GestioneMySql.connection); cmd.Parameters.Add(new MySqlParameter("ID", intkeyLoc)); MySqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { if (!dr.IsDBNull(dr.GetOrdinal("ID"))) { citta.ID = dr.GetInt32("ID"); } ; if (!dr.IsDBNull(dr.GetOrdinal("ID_COMU"))) { citta.ID_COMU = dr.GetInt32("ID_COMU"); } ; if (!dr.IsDBNull(dr.GetOrdinal("LOCALITA"))) { if (!string.IsNullOrEmpty(dr.GetString("LOCALITA"))) { citta.LOCALITA = dr.GetString("LOCALITA"); } } } dr.Close(); GestioneMySql.CloseConnection(); return(citta); } 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); } }
public static MySqlDataReader LoadNazione() { try { var command = new MySqlCommand("SELECT * FROM NAZIONE", GestioneMySql.connection); var reader = command.ExecuteReader(); return(reader); } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); return(null); } }
public static EricsoftGuestData LoadEricsoft(Users user) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } EricsoftGuestData ericsoft = new EricsoftGuestData(); Header header = new Header(); header.SourceGenerator = "Riferimento programma"; header.Date = DateTime.Now.ToString("yyyy-MM-dd"); Body body = new Body(); body.Name = user.NOME; body.Surname = user.COGNOME; body.Gender = user.SEX; body.Residence = GetResidence(user.SST, user.STRADA, user.NCN); body.Residence.City = GetCity(user.KEY_COM, user.KEY_LOC); body.Residence.Nation = GetNation(user.KEY_NAZ); body.BirthData = GetBirthDate(user.DTNAS); body.BirthData.City = GetCity(user.KEY_COM_NAS, user.KEY_LOC_NAS); body.BirthData.Nation = GetNation(user.KEY_NAZ_NAS); body.Nationality = GetNationality(user.KEY_NAZ_NAS); body.IdentificationDocument = GetIdentificationDocument(user.KEY_DOC); body.Authorization = GetAuthorization(); ericsoft.Header = header; ericsoft.Body = body; if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } return(ericsoft); } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); return(null); } }
public static Template LoadTemplate(int strKeyTempl) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } var sb = new StringBuilder(); Template template = new Template(); sb.AppendLine("SELECT *"); sb.AppendLine("FROM TEMPLATE"); sb.AppendLine("WHERE KEY_TEMPL = @KEY_TEMPL"); MySqlCommand cmd = new MySqlCommand(sb.ToString(), GestioneMySql.connection); cmd.Parameters.Add(new MySqlParameter("KEY_TEMPL", strKeyTempl)); MySqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { template.KEY_TEMPL = dr.GetInt16("KEY_TEMPL"); if (!string.IsNullOrEmpty(dr.GetString("PATH"))) { template.PATH = dr.GetString("PATH"); } if (!string.IsNullOrEmpty(dr.GetString("DESCR"))) { template.DESCR = dr.GetString("DESCR"); } } dr.Close(); GestioneMySql.CloseConnection(); return(template); } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); return(null); } }
public static void RunScriptTemplate(int intKeyTempl, string strName) { StringBuilder strQuery = new StringBuilder(); try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } strQuery.AppendLine(string.Format(@"DELETE FROM PDFASSOCIATION WHERE KEY_TEMPL = {0};", intKeyTempl)); string strInsert = " INSERT INTO PDFASSOCIATION (KEY_TEMPL, PDF_FIELD, TYPE, FIELD, BIOMETRIC, NUM_PAGE) VALUES "; switch (strName) { case "Informativa Clienti Antico Convento ITA": strQuery.AppendLine(strInsert + string.Format(@"({0}, 'txtNameSurname', 'TXT', 'user.COGNOME,user.NOME', NULL, NULL);", intKeyTempl)); strQuery.AppendLine(strInsert + string.Format(@"({0}, 'txtCell', 'TXT', 'user.CELL', NULL, NULL);", intKeyTempl)); strQuery.AppendLine(strInsert + string.Format(@"({0}, 'txtDate', 'TXT', NULL, NULL, NULL);", intKeyTempl)); strQuery.AppendLine(strInsert + string.Format(@"({0}, 'txtMail', 'TXT', 'user.MAIL', NULL, NULL);", intKeyTempl)); strQuery.AppendLine(strInsert + string.Format(@"({0}, 'txtSignature', 'SIG', NULL, NULL, 2);", intKeyTempl)); break; } MySqlCommand comm = GestioneMySql.connection.CreateCommand(); comm.CommandText = strQuery.ToString(); comm.ExecuteNonQuery(); if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); } }
public static Config LoadConfig(Config.ParamValues paramValues) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } Config config = new Config(); MySqlCommand cmd = new MySqlCommand("SELECT * FROM CONFIG WHERE CONF_PARAM = @CONF_PARAM", GestioneMySql.connection); cmd.Parameters.Add(new MySqlParameter("CONF_PARAM", paramValues.ToString())); MySqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { if (!dr.IsDBNull(dr.GetOrdinal("CONF_VALUE"))) { if (!string.IsNullOrEmpty(dr.GetString("CONF_VALUE"))) { config.CONF_VALUE = dr.GetString("CONF_VALUE"); } } } dr.Close(); if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } return(config); } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); return(null); } }
public static void DeleteTemplate(int?intKeyTempl) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } if (intKeyTempl.HasValue) { GestioneMySql.TransazioneBegin(); MySqlCommand comm = GestioneMySql.connection.CreateCommand(); comm.CommandText = "DELETE FROM TEMPLATE WHERE KEY_TEMPL = @KEY_TEMPL"; comm.Parameters.AddWithValue("@KEY_TEMPL", intKeyTempl); comm.ExecuteNonQuery(); comm.CommandText = "UPDATE USERS SET KEY_TEMPL = NULL WHERE KEY_TEMPL = @KEY_TEMPL"; comm.Parameters.AddWithValue("@KEY_TEMPL", intKeyTempl); comm.ExecuteNonQuery(); comm.CommandText = "DELETE FROM TEMPLATE_LINQ WHERE KEY_TEMPL = @KEY_TEMPL"; comm.Parameters.AddWithValue("@KEY_TEMPL", intKeyTempl); comm.ExecuteNonQuery(); GestioneMySql.TransazioneCommit(); } if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } } catch (Exception ex) { GestioneMySql.TransazioneRollback(); GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); } }
private void LoadGridTemplate() { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } using (MySqlConnection con = new MySqlConnection(GestioneMySql.StringaConnessione)) { var sb = new StringBuilder(); using (MySqlCommand cmd = new MySqlCommand("SELECT KEY_TEMPL, DESCR 'NOME FILE', PATH, DATE_FORMAT(DTINS,'%d/%m/%Y %H:%i') 'DATA INSERIMENTO' FROM TEMPLATE ", con)) { cmd.CommandType = CommandType.Text; using (MySqlDataAdapter sda = new MySqlDataAdapter(cmd)) { dataTableTemplate = new DataTable(); sda.Fill(dataTableTemplate); dataTableTemplate.Columns["KEY_TEMPL"].ColumnMapping = MappingType.Hidden; DataRow dr = dataTableTemplate.NewRow(); dr["NOME FILE"] = "Aggiungi Template"; dataTableTemplate.Rows.Add(dr); dataGridView2.DataSource = dataTableTemplate; LoadGridTemplate(dataGridView2); } } } if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore caricamento griglia utenze: " + ex.Message); } }
public static Document SaveDocument(Document document) { try { MySqlCommand comm = GestioneMySql.connection.CreateCommand(); if (document.KEY_DOC.Equals(0)) { comm.CommandText = "INSERT INTO DOCUMENT(TYP_DOC, NUM_DOC, ISS_DOC, CITY_DOC, ID_DOC) VALUES (@TYP_DOC, @NUM_DOC, @ISS_DOC, @CITY_DOC, @ID_DOC)"; } else { comm.CommandText = " UPDATE DOCUMENT SET TYP_DOC=@TYP_DOC, NUM_DOC=@NUM_DOC, ISS_DOC=@ISS_DOC, CITY_DOC=@CITY_DOC, ID_DOC=@ID_DOC WHERE KEY_DOC=@KEY_DOC"; comm.Parameters.AddWithValue("@KEY_DOC", document.KEY_DOC); } comm.Parameters.AddWithValue("@TYP_DOC", document.TYP_DOC); comm.Parameters.AddWithValue("@NUM_DOC", document.NUM_DOC); comm.Parameters.AddWithValue("@ISS_DOC", document.ISS_DOC.Date.ToString("yyyyMMdd").StringOrNull()); comm.Parameters.AddWithValue("@CITY_DOC", document.CITY_DOC); comm.Parameters.AddWithValue("@ID_DOC", document.ID_DOC); comm.ExecuteNonQuery(); MySqlCommand cmd = new MySqlCommand("SELECT LAST_INSERT_ID() AS KEY_DOC", GestioneMySql.connection); MySqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { document.KEY_DOC = dr.GetInt16("KEY_DOC"); } dr.Close(); return(document); } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); return(null); } }
public static void SaveTemplate(Template template) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } if (template.KEY_TEMPL.Equals(0)) { MySqlCommand comm = GestioneMySql.connection.CreateCommand(); comm.CommandText = "INSERT INTO TEMPLATE(DESCR,PATH,DTINS,X_SIGN) VALUES(@DESCR,@PATH,@DTINS,@X_SIGN)"; comm.Parameters.AddWithValue("@DESCR", template.DESCR); comm.Parameters.AddWithValue("@PATH", template.PATH); comm.Parameters.AddWithValue("@DTINS", DateTime.Now.ToString("yyyyMMddHHmmss")); comm.Parameters.AddWithValue("@X_SIGN", template.X_SIGN); comm.ExecuteNonQuery(); } MySqlCommand cmd = new MySqlCommand("SELECT LAST_INSERT_ID() AS KEY_TEMPL", GestioneMySql.connection); MySqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { template.KEY_TEMPL = dr.GetInt16("KEY_TEMPL"); } dr.Close(); if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); } }
private void LoadGridUtenze(string strQuery) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } using (MySqlConnection con = new MySqlConnection(GestioneMySql.StringaConnessione)) { using (MySqlCommand cmd = new MySqlCommand(strQuery, con)) { cmd.CommandType = CommandType.Text; using (MySqlDataAdapter sda = new MySqlDataAdapter(cmd)) { dataTableUser = new DataTable(); sda.Fill(dataTableUser); dataTableUser.Columns["KEY_USER"].ColumnMapping = MappingType.Hidden; DataRow dr = dataTableUser.NewRow(); dr["NOME"] = "Aggiungi Utenza"; dataTableUser.Rows.Add(dr); dataGridView1.DataSource = dataTableUser; LoadGridUtenze(dataGridView1); } } } if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore caricamento griglia utenze: " + ex.Message); } }
public static void SaveLogin(int?intKeyLog, string strPassword, string strFirstAccess) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } var sb = new StringBuilder(); MySqlCommand comm = GestioneMySql.connection.CreateCommand(); sb.AppendLine("UPDATE LOGIN SET X_FIRST_LOG=@X_FIRST_LOG, DATE_EXPIRED=@DATE_EXPIRED "); if (!string.IsNullOrEmpty(strPassword)) { sb.AppendLine(",PASSWORD_ID = @PASSWORD_ID "); } sb.AppendLine("WHERE KEY_LOG = @KEY_LOG"); MySqlCommand cmd = new MySqlCommand(sb.ToString(), GestioneMySql.connection); cmd.Parameters.AddWithValue("@KEY_LOG", intKeyLog); cmd.Parameters.AddWithValue("@PASSWORD_ID", ToSha256(strPassword)); cmd.Parameters.AddWithValue("@X_FIRST_LOG", strFirstAccess.StringOrNull()); cmd.Parameters.AddWithValue("@DATE_EXPIRED", DateTime.Now.AddDays(90).ToString("yyyyMMdd")); cmd.ExecuteNonQuery(); if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); throw ex; } }
public static DataTable LoadTemplate(int?intKey, string strXSign) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } string strQuery = "SELECT KEY_TEMPL, DESCR, PATH, DTINS FROM TEMPLATE WHERE 1 = 1 "; if (intKey != null) { strQuery = strQuery + string.Format(@"AND KEY_TEMPL = {0}", intKey); } if (!string.IsNullOrEmpty(strXSign)) { strQuery = strQuery + "AND X_SIGN != 'X'"; } 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 DeleteUser(int intKeyUte) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } MySqlCommand comm = GestioneMySql.connection.CreateCommand(); comm.CommandText = "DELETE FROM Users WHERE KEY_USER = @KEY_USER"; comm.Parameters.AddWithValue("@KEY_USER", intKeyUte); comm.ExecuteNonQuery(); GestioneMySql.CloseConnection(); } catch (Exception e) { GestioneMySql.CloseConnection(); Console.WriteLine(e.Message); } }
private static void SaveReservation(List <RESERVATION> entityList) { try { //if (!GestioneMySql.OpenConnection()) // throw new Exception("Errore nell'apertura della connessione."); foreach (var datiReservation in entityList) { MySqlCommand comm = GestioneMySql.connection.CreateCommand(); string query; query = "INSERT INTO RESERVATION( PMSID, GROUPNAME, ARRIVAL, DEPARTURE, ROOM, ROOMTYPE, RATE, ADULT, CHILD )"; query = query + " VALUES ( @PMSID, @GROUPNAME, @ARRIVAL, @DEPARTURE, @ROOM, @ROOMTYPE, @RATE, @ADULT, @CHILD )"; comm.CommandText = query; comm.Parameters.AddWithValue("@PMSID", datiReservation.PmsID); comm.Parameters.AddWithValue("@GROUPNAME", datiReservation.GroupName.StringOrNull()); comm.Parameters.AddWithValue("@ARRIVAL", datiReservation.Arrival.StringOrNull()); comm.Parameters.AddWithValue("@DEPARTURE", datiReservation.Departure.StringOrNull()); comm.Parameters.AddWithValue("@ROOM", datiReservation.Room.StringOrNull()); comm.Parameters.AddWithValue("@ROOMTYPE", datiReservation.RoomType.StringOrNull()); comm.Parameters.AddWithValue("@RATE", datiReservation.Rate.StringOrNull()); comm.Parameters.AddWithValue("@ADULT", datiReservation.Adult.ToIntOrDbNull()); comm.Parameters.AddWithValue("@CHILD", datiReservation.Child.ToIntOrDbNull()); comm.ExecuteNonQuery(); } //if (!GestioneMySql.CloseConnection()) // throw new Exception("Errore nella chiusura della connessione."); } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); } }
public static Users SaveUser(Users user) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } MySqlCommand comm = GestioneMySql.connection.CreateCommand(); string query; if (user.KEY_USER.Equals(0)) { query = "INSERT INTO Users(NOME, COGNOME, DTINS, DTNAS, SST, STRADA, KEY_NAZ, KEY_REG, KEY_PRO, KEY_COM, KEY_LOC, TYP_UTE, SEX, COD_FIS, P_IVA, NCN, CELL, MAIL, KEY_TEMPL, PERS1, PERS2, PERS3, PERS4, PERS5, PERS6, KEY_NAZ_NAS, KEY_REG_NAS, KEY_PRO_NAS, KEY_COM_NAS, KEY_LOC_NAS, TEL, KEY_DOC )"; query = query + " VALUES (@NOME, @COGNOME, @DTINS, @DTNAS, @SST, @STRADA, @KEY_NAZ, @KEY_REG, @KEY_PRO, @KEY_COM, @KEY_LOC, @TYP_UTE, @SEX, @COD_FIS, @P_IVA, @NCN, @CELL, @MAIL, @KEY_TEMPL, @PERS1, @PERS2, @PERS3, @PERS4, @PERS5, @PERS6, @KEY_NAZ_NAS, @KEY_REG_NAS, @KEY_PRO_NAS, @KEY_COM_NAS, @KEY_LOC_NAS, @TEL, @KEY_DOC )"; comm.CommandText = query; } else { query = "UPDATE Users SET "; query = query + " NOME=@NOME, COGNOME=@COGNOME, DTINS=@DTINS, DTNAS=@DTNAS, SST=@SST, STRADA=@STRADA, KEY_NAZ=@KEY_NAZ, KEY_REG=@KEY_REG, KEY_PRO=@KEY_PRO, KEY_COM=@KEY_COM, KEY_LOC=@KEY_LOC, TYP_UTE=@TYP_UTE, SEX=@SEX, COD_FIS=@COD_FIS, P_IVA=@P_IVA, NCN=@NCN, CELL=@CELL, MAIL=@MAIL, KEY_TEMPL=@KEY_TEMPL, PERS1=@PERS1, PERS2=@PERS2, PERS3=@PERS3, PERS4=@PERS4, PERS5=@PERS5, PERS6=@PERS6, KEY_NAZ_NAS=@KEY_NAZ_NAS, KEY_REG_NAS=@KEY_REG_NAS, KEY_PRO_NAS=@KEY_PRO_NAS, KEY_COM_NAS=@KEY_COM_NAS, KEY_LOC_NAS=@KEY_LOC_NAS, TEL=@TEL, KEY_DOC=@KEY_DOC "; query = query + " WHERE KEY_USER=@KEY_USER"; comm.CommandText = query; comm.Parameters.AddWithValue("@KEY_USER", user.KEY_USER); } comm.Parameters.AddWithValue("@NOME", user.NOME); comm.Parameters.AddWithValue("@COGNOME", user.COGNOME); comm.Parameters.AddWithValue("@DTINS", DateTime.Now.ToString("yyyyMMdd")); comm.Parameters.AddWithValue("@DTNAS", user.DTNAS.Date.ToString("yyyyMMdd").StringOrNull()); comm.Parameters.AddWithValue("@SST", user.SST.StringOrNull()); comm.Parameters.AddWithValue("@STRADA", user.STRADA.StringOrNull()); comm.Parameters.AddWithValue("@KEY_NAZ", user.KEY_NAZ); comm.Parameters.AddWithValue("@KEY_REG", user.KEY_REG); comm.Parameters.AddWithValue("@KEY_PRO", user.KEY_PRO); comm.Parameters.AddWithValue("@KEY_COM", user.KEY_COM); comm.Parameters.AddWithValue("@KEY_LOC", user.KEY_LOC); comm.Parameters.AddWithValue("@TYP_UTE", user.TYP_UTE.StringOrNull()); comm.Parameters.AddWithValue("@SEX", user.SEX.StringOrNull()); comm.Parameters.AddWithValue("@COD_FIS", user.COD_FIS.StringOrNull()); comm.Parameters.AddWithValue("@P_IVA", user.P_IVA.StringOrNull()); comm.Parameters.AddWithValue("@NCN", user.NCN.StringOrNull()); comm.Parameters.AddWithValue("@CELL", user.CELL.StringOrNull()); comm.Parameters.AddWithValue("@TEL", user.TEL.StringOrNull()); comm.Parameters.AddWithValue("@MAIL", user.MAIL.StringOrNull()); comm.Parameters.AddWithValue("@KEY_TEMPL", user.KEY_TEMPL); comm.Parameters.AddWithValue("@PERS1", user.PERS1.StringOrNull()); comm.Parameters.AddWithValue("@PERS2", user.PERS2.StringOrNull()); comm.Parameters.AddWithValue("@PERS3", user.PERS3.StringOrNull()); comm.Parameters.AddWithValue("@PERS4", user.PERS4.StringOrNull()); comm.Parameters.AddWithValue("@PERS5", user.PERS5.StringOrNull()); comm.Parameters.AddWithValue("@PERS6", user.PERS6.StringOrNull()); comm.Parameters.AddWithValue("@KEY_NAZ_NAS", user.KEY_NAZ_NAS); comm.Parameters.AddWithValue("@KEY_REG_NAS", user.KEY_REG_NAS); comm.Parameters.AddWithValue("@KEY_PRO_NAS", user.KEY_PRO_NAS); comm.Parameters.AddWithValue("@KEY_COM_NAS", user.KEY_COM_NAS); comm.Parameters.AddWithValue("@KEY_LOC_NAS", user.KEY_LOC_NAS); comm.Parameters.AddWithValue("@KEY_DOC", user.KEY_DOC); comm.ExecuteNonQuery(); MySqlCommand cmd = new MySqlCommand("SELECT LAST_INSERT_ID() AS KEY_USER", GestioneMySql.connection); MySqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { user.KEY_USER = dr.GetInt16("KEY_USER"); } dr.Close(); if (!GestioneMySql.CloseConnection()) { throw new Exception("Errore nella chiusura della connessione."); } return(user); } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); return(null); } }
public static List <Users> LoadUser(int?intKeyUte) { try { if (!GestioneMySql.OpenConnection()) { throw new Exception("Errore nell'apertura della connessione."); } var sb = new StringBuilder(); List <Users> listUsers = new List <Users>(); sb.AppendLine("SELECT *"); sb.AppendLine("FROM Users"); if (intKeyUte.HasValue) { sb.AppendLine("WHERE KEY_USER = @KEY_USER"); } MySqlCommand cmd = new MySqlCommand(sb.ToString(), GestioneMySql.connection); cmd.Parameters.Add(new MySqlParameter("KEY_USER", intKeyUte)); MySqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Users user = new Users(); user.KEY_USER = dr.GetInt16("KEY_USER"); if (!string.IsNullOrEmpty(dr.GetString("Nome"))) { user.NOME = dr.GetString("Nome"); } if (!string.IsNullOrEmpty(dr.GetString("Cognome"))) { user.COGNOME = dr.GetString("Cognome"); } if (!dr.IsDBNull(dr.GetOrdinal("DTNAS"))) { user.DTNAS = DateTime.ParseExact(dr.GetString("DTNAS"), "yyyyMMdd", null, System.Globalization.DateTimeStyles.None); } if (!dr.IsDBNull(dr.GetOrdinal("TYP_UTE"))) { if (!string.IsNullOrEmpty(dr.GetString("TYP_UTE"))) { user.TYP_UTE = dr.GetString("TYP_UTE"); } } if (!dr.IsDBNull(dr.GetOrdinal("P_IVA"))) { if (!string.IsNullOrEmpty(dr.GetString("P_IVA"))) { user.P_IVA = dr.GetString("P_IVA"); } } if (!dr.IsDBNull(dr.GetOrdinal("COD_FIS"))) { if (!string.IsNullOrEmpty(dr.GetString("COD_FIS"))) { user.COD_FIS = dr.GetString("COD_FIS"); } } if (!dr.IsDBNull(dr.GetOrdinal("KEY_NAZ"))) { if (!string.IsNullOrEmpty(dr.GetString("KEY_NAZ"))) { user.KEY_NAZ = dr.GetInt16("KEY_NAZ"); } } if (!dr.IsDBNull(dr.GetOrdinal("KEY_REG"))) { if (!string.IsNullOrEmpty(dr.GetString("KEY_REG"))) { user.KEY_REG = dr.GetInt16("KEY_REG"); } } if (!dr.IsDBNull(dr.GetOrdinal("KEY_PRO"))) { if (!string.IsNullOrEmpty(dr.GetString("KEY_PRO"))) { user.KEY_PRO = dr.GetInt16("KEY_PRO"); } } if (!dr.IsDBNull(dr.GetOrdinal("KEY_COM"))) { if (!string.IsNullOrEmpty(dr.GetString("KEY_COM"))) { user.KEY_COM = dr.GetInt16("KEY_COM"); } } if (!dr.IsDBNull(dr.GetOrdinal("KEY_LOC"))) { if (!string.IsNullOrEmpty(dr.GetString("KEY_LOC"))) { user.KEY_LOC = dr.GetInt16("KEY_LOC"); } } if (!dr.IsDBNull(dr.GetOrdinal("KEY_NAZ_NAS"))) { if (!string.IsNullOrEmpty(dr.GetString("KEY_NAZ_NAS"))) { user.KEY_NAZ_NAS = dr.GetInt16("KEY_NAZ_NAS"); } } if (!dr.IsDBNull(dr.GetOrdinal("KEY_REG_NAS"))) { if (!string.IsNullOrEmpty(dr.GetString("KEY_REG_NAS"))) { user.KEY_REG_NAS = dr.GetInt16("KEY_REG_NAS"); } } if (!dr.IsDBNull(dr.GetOrdinal("KEY_PRO_NAS"))) { if (!string.IsNullOrEmpty(dr.GetString("KEY_PRO_NAS"))) { user.KEY_PRO_NAS = dr.GetInt16("KEY_PRO_NAS"); } } if (!dr.IsDBNull(dr.GetOrdinal("KEY_COM_NAS"))) { if (!string.IsNullOrEmpty(dr.GetString("KEY_COM_NAS"))) { user.KEY_COM_NAS = dr.GetInt16("KEY_COM_NAS"); } } if (!dr.IsDBNull(dr.GetOrdinal("KEY_LOC_NAS"))) { if (!string.IsNullOrEmpty(dr.GetString("KEY_LOC_NAS"))) { user.KEY_LOC_NAS = dr.GetInt16("KEY_LOC_NAS"); } } if (!dr.IsDBNull(dr.GetOrdinal("KEY_TEMPL"))) { if (!string.IsNullOrEmpty(dr.GetString("KEY_TEMPL"))) { user.KEY_TEMPL = dr.GetInt16("KEY_TEMPL"); } } if (!dr.IsDBNull(dr.GetOrdinal("Sst"))) { if (!string.IsNullOrEmpty(dr.GetString("Sst"))) { user.SST = dr.GetString("Sst"); } } if (!dr.IsDBNull(dr.GetOrdinal("STRADA"))) { if (!string.IsNullOrEmpty(dr.GetString("STRADA"))) { user.STRADA = dr.GetString("STRADA"); } } if (!dr.IsDBNull(dr.GetOrdinal("NCN"))) { if (!string.IsNullOrEmpty(dr.GetString("NCN"))) { user.NCN = dr.GetString("NCN"); } } if (!dr.IsDBNull(dr.GetOrdinal("CELL"))) { if (!string.IsNullOrEmpty(dr.GetString("CELL"))) { user.CELL = dr.GetString("CELL"); } } if (!dr.IsDBNull(dr.GetOrdinal("TEL"))) { if (!string.IsNullOrEmpty(dr.GetString("TEL"))) { user.TEL = dr.GetString("TEL"); } } if (!dr.IsDBNull(dr.GetOrdinal("MAIL"))) { if (!string.IsNullOrEmpty(dr.GetString("MAIL"))) { user.MAIL = dr.GetString("MAIL"); } } if (!dr.IsDBNull(dr.GetOrdinal("PERS1"))) { if (!string.IsNullOrEmpty(dr.GetString("PERS1"))) { user.PERS1 = dr.GetString("PERS1"); } } if (!dr.IsDBNull(dr.GetOrdinal("PERS2"))) { if (!string.IsNullOrEmpty(dr.GetString("PERS2"))) { user.PERS2 = dr.GetString("PERS2"); } } if (!dr.IsDBNull(dr.GetOrdinal("PERS3"))) { if (!string.IsNullOrEmpty(dr.GetString("PERS3"))) { user.PERS3 = dr.GetString("PERS3"); } } if (!dr.IsDBNull(dr.GetOrdinal("PERS4"))) { if (!string.IsNullOrEmpty(dr.GetString("PERS4"))) { user.PERS4 = dr.GetString("PERS4"); } } if (!dr.IsDBNull(dr.GetOrdinal("PERS5"))) { if (!string.IsNullOrEmpty(dr.GetString("PERS5"))) { user.PERS5 = dr.GetString("PERS5"); } } if (!dr.IsDBNull(dr.GetOrdinal("PERS6"))) { if (!string.IsNullOrEmpty(dr.GetString("PERS6"))) { user.PERS6 = dr.GetString("PERS6"); } } if (!dr.IsDBNull(dr.GetOrdinal("KEY_DOC"))) { if (!string.IsNullOrEmpty(dr.GetString("KEY_DOC"))) { user.KEY_DOC = dr.GetInt16("KEY_DOC"); } } if (!dr.IsDBNull(dr.GetOrdinal("SEX"))) { if (!string.IsNullOrEmpty(dr.GetString("SEX"))) { user.SEX = dr.GetString("SEX"); } } listUsers.Add(user); } dr.Close(); GestioneMySql.CloseConnection(); return(listUsers); } catch (Exception ex) { GestioneMySql.CloseConnection(); MessageBox.Show("Errore: " + ex.Message); return(null); } }