public List <Models.Treino> GetTreinos() { try { if (connection() == true) { List <Models.Treino> ListObjectTreinos = new List <Models.Treino>(); using (var comm = new SQLiteCommand("SELECT * FROM dataTreino", db_connect)) { SQLiteDataReader reader = comm.ExecuteReader(); while (reader.Read()) { Models.Treino treinoAUX = new Models.Treino(); treinoAUX = JsonDeserializer(reader[1].ToString()); ListObjectTreinos.Add(treinoAUX); } return(ListObjectTreinos); } } else { return(null); } } catch (Exception e) { throw e; } }
public bool removeTreino(Models.Treino objTreino) { try { if (treinosCACHE.removeTreino(objTreino) && treinosDAO.removeTreino(objTreino)) { MessageBox.Show("Sucesso ao remover o treino", "INSERT", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } else { string errorCode = ""; if (!treinosCACHE.removeTreino(objTreino)) { errorCode += "RMV#TC&"; } if (!treinosDAO.removeTreino(objTreino)) { errorCode += "&RMVDB#TC"; } MessageBox.Show("Erro inesperado->EC: " + errorCode, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } catch { throw; } }
public bool updateTreino(Models.Treino objTreino) { try { if (treinosCACHE.updateTreino(objTreino) && treinosDAO.updateTreino(objTreino)) { MessageBox.Show("Sucesso ao atualizar o treino", "UPDATE", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } else { string errorCode = ""; if (!treinosCACHE.updateTreino(objTreino)) { errorCode += "UP#TC&"; } if (!treinosDAO.updateTreino(objTreino)) { errorCode += "&UPDB#TC"; } MessageBox.Show("Erro inesperado->EC: " + errorCode, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } catch { throw; } }
public bool insertTreino(Models.Treino objTreino) { try { ListObjectTreinos.Add(objTreino); return(true); } catch { return(false); } }
public string JsonSerializer(Models.Treino objTreino) { try { var serializer = new JavaScriptSerializer(); string json = serializer.Serialize(objTreino); return(json); } catch { throw; } }
public Models.Treino JsonDeserializer(string json) { try { var serializer = new JavaScriptSerializer(); Models.Treino treino = new Models.Treino(); treino = serializer.Deserialize <Models.Treino>(json); return(treino); } catch { throw; } }
public bool removeTreino(Models.Treino objTreino) { try { foreach (Models.Treino treino in ListObjectTreinos) { if (treino.matricula == objTreino.matricula) { ListObjectTreinos.Remove(treino); return(true); } } return(false); } catch (Exception e) { throw e; } }
public bool updateTreino(Models.Treino objTreino) { try { foreach (Models.Treino treino in ListObjectTreinos) { if (treino.matricula == objTreino.matricula) { treino.columns = objTreino.columns; return(true); } } return(false); } catch (Exception e) { throw e; } }
public bool removeTreino(Models.Treino treino) { try { if (connection() == true) { using (var comm = new SQLiteCommand(db_connect)) { comm.CommandText = string.Format("DELETE FROM dataTREINO WHERE ID = {0}", treino.matricula); } return(true); } else { return(false); } } catch (Exception e) { throw e; } }
public bool updateTreino(Models.Treino treino) { try { if (connection() == true) { using (var comm = new SQLiteCommand(db_connect)) { comm.CommandText = string.Format("UPDATE dataTreino set TREINO = \"{0}\" WHERE ID = {1}", JsonSerializer(treino), treino.matricula); comm.ExecuteNonQuery(); db_connect.Close(); return(true); } } else { return(false); } } catch (Exception e) { throw e; } }
public bool insertTreino(Models.Treino treino) { try { if (connection() == true) { using (var comm = new SQLiteCommand(db_connect)) { comm.CommandText = "INSERT INTO dataTreino(ID,TREINO) Values(\"" + treino.matricula + "\",\'" + JsonSerializer(treino) + "\')";; comm.ExecuteNonQuery(); db_connect.Close(); return(true); } } else { return(false); } } catch (Exception e) { throw e; } }