public void SaveOfflineAction(string sqlCommand) { MySqlCommand command = new MySqlCommand(); command.Connection = conn; command.CommandType = CommandType.Text; command.CommandText = sqlCommand; try { conn.Open(); command.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { //Creates the INSERT command to save in a file in case the connection drops var queryTest = CommandAsSql(command); IO io = new IO(); io.WriteToFile(ConfigurationManager.AppSettings["BackupPath"], queryTest); throw new Exception("Error en conexion. Se ha registrado la actividad en forma local.\n\r" + ex.Message); } }
public void SaveAction(string sqlCommand, int userId, Enums.Actions action, string currentTime, string observaciones, string station) { MySqlCommand command = new MySqlCommand(); command.Connection = conn; command.CommandType = CommandType.Text; command.CommandText = sqlCommand; string query = sqlCommand; Thread.CurrentThread.CurrentCulture = new CultureInfo("es-AR"); DateTime dt = DateTime.ParseExact(currentTime, ConfigurationManager.AppSettings["DateTimeFormat"], CultureInfo.CurrentCulture); command.Parameters.AddWithValue("@userId", userId); command.Parameters.AddWithValue("@fecha", dt.ToShortDateString()); command.Parameters.AddWithValue("@hora", dt.ToString("HH:mm")); command.Parameters.AddWithValue("@actionId", action); command.Parameters.AddWithValue("@station", station); command.Parameters.AddWithValue("@observaciones", observaciones == "Observaciones..." ? null : observaciones); Log.Info("Id de Usuario para insert = " + userId.ToString()); try { conn.Open(); //conn.Open(); // ... other parameters command.ExecuteNonQuery(); conn.Close(); } catch(Exception ex) { //Creates the INSERT command to save in a file in case the connection drops var queryTest = CommandAsSql(command); IO io = new IO(); io.WriteToFile(ConfigurationManager.AppSettings["BackupPath"], queryTest); throw new Exception("Error en conexion. Se ha registrado la actividad en forma local.\n\r" + ex.Message); } }
public void GetRecords(string storedProcedure, string Filename, string date1, string date2, int userId = 0) { conn.Open(); SqlCommand command = new SqlCommand(storedProcedure, conn); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@userId", SqlDbType.Int).Value = userId; command.Parameters.Add("@dateFrom", SqlDbType.DateTime).Value = DateTime.ParseExact(date1, ConfigurationManager.AppSettings["DateFormat"], CultureInfo.InvariantCulture); command.Parameters.Add("@dateTo", SqlDbType.DateTime).Value = DateTime.ParseExact(date2, ConfigurationManager.AppSettings["DateFormat"], CultureInfo.InvariantCulture); SqlDataReader dr = command.ExecuteReader(); IO io = new IO(); io.WriteToFile(Filename, dr); }