public IQueryAdapter GetQueryReactor() { try { IDatabaseClient DbConnection = new DatabaseConnection(this._connectionStr); DbConnection.connect(); return(DbConnection.GetQueryReactor()); } catch (Exception e) { SystemLogging.SendErrorLog(e.ToString()); return(null); } }
public static ObservableCollection <BaySettings> GetBaySettings(int id) { ObservableCollection <BaySettings> settingsResult = new ObservableCollection <BaySettings>(); DataTable linkTable = null; DataRow settingsRow = null; bool enabled = true; //TODO using (IQueryAdapter dbClient = Core.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("SELECT * FROM link_ajustes_bay WHERE bay_id = @thisid;"); dbClient.AddParameter("thisid", id); linkTable = dbClient.getTable(); if (linkTable.Rows.Count > 0) { foreach (DataRow dr in linkTable.Rows) { try { enabled = Convert.ToBoolean(dr["status"]); dbClient.SetQuery("SELECT * FROM ajustes_bay WHERE id = @targetid LIMIT 1;"); dbClient.AddParameter("targetid", dr["settings_id"]); settingsRow = dbClient.getRow(); if (settingsRow == null) { SystemLogging.SendErrorLog("Falha ao carregar ajuste para o religador: ID " + id + ". Entre em contato com o administrador do banco"); continue; } settingsResult.Add(new BaySettings( Convert.ToInt32(settingsRow["id"]), enabled, Convert.ToString(settingsRow["creation_service"]), Convert.ToInt32(settingsRow["ftemp_pickup"]), Convert.ToDouble(settingsRow["ftemp_tap"]), Convert.ToInt32(settingsRow["ftemp_curve"]), Convert.ToDouble(settingsRow["ftemp_dial"]), Convert.ToDouble(settingsRow["ftemp_mrt"]), Convert.ToDouble(settingsRow["ftemp_timeadd"]), Convert.ToInt32(settingsRow["ntemp_pickup"]), Convert.ToInt32(settingsRow["ntemp_tap"]), Convert.ToInt32(settingsRow["ntemp_curve"]), Convert.ToDouble(settingsRow["ntemp_dial"]), Convert.ToDouble(settingsRow["ntemp_mrt"]), Convert.ToDouble(settingsRow["ntemp_timeadd"]), Convert.ToInt32(settingsRow["num_op"]), Convert.ToInt32(settingsRow["temp_op_1"]), Convert.ToInt32(settingsRow["temp_op_2"]), Convert.ToInt32(settingsRow["temp_op_3"]), Convert.ToInt32(settingsRow["temp_rearm"]), Convert.ToInt32(settingsRow["finst_pickup"]), Convert.ToInt32(settingsRow["ninst_pickup"]), Convert.ToDouble(settingsRow["finst_tap"]), Convert.ToDouble(settingsRow["ninst_tap"]))); settingsRow = null; } catch (Exception ex) { SystemLogging.SendFatalErrorLog(ex.ToString()); } } return(settingsResult); } else { SystemLogging.SendWarningLog("Nenhum ajuste encontrado para o Bay " + Core.GetBayManager().GetBayById(id).CircuitCode); return(null); } } }
public static ObservableCollection <RecloserSettings> GetRecloserSettings(int id) { ObservableCollection <RecloserSettings> settingsResult = new ObservableCollection <RecloserSettings>(); DataTable linkTable = null; DataRow settingsRow = null; DateTime creationTime; using (IQueryAdapter dbClient = Core.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("SELECT * FROM link_ajustes_linha WHERE recloser_id = @thisid ORDER BY CASE link_ajustes_linha.`status` WHEN 0 THEN 1 ELSE 0 END,link_ajustes_linha.`status`;"); dbClient.AddParameter("thisid", id); linkTable = dbClient.getTable(); if (linkTable.Rows.Count > 0) { foreach (DataRow dr in linkTable.Rows) { try { dbClient.SetQuery("SELECT * FROM ajustes_linha WHERE id = @targetid LIMIT 1;"); dbClient.AddParameter("targetid", dr["settings_id"]); settingsRow = dbClient.getRow(); if (settingsRow == null) { SystemLogging.SendErrorLog("Falha ao carregar ajuste para o religador: ID " + id + ". Entre em contato com o administrador do banco"); continue; } settingsResult.Add(new RecloserSettings( Convert.ToInt32(settingsRow["id"]), Convert.ToInt32(dr["status"]), Convert.ToString(settingsRow["creation_service"]), Convert.ToInt32(settingsRow["ftemp_pickup"]), Convert.ToInt32(settingsRow["ftemp_curve"]), Convert.ToDouble(settingsRow["ftemp_dial"]), Convert.ToDouble(settingsRow["ftemp_mrt"]), Convert.ToDouble(settingsRow["ftemp_timeadd"]), Convert.ToInt32(settingsRow["ntemp_pickup"]), Convert.ToInt32(settingsRow["ntemp_curve"]), Convert.ToDouble(settingsRow["ntemp_dial"]), Convert.ToDouble(settingsRow["ntemp_mrt"]), Convert.ToDouble(settingsRow["ntemp_timeadd"]), Convert.ToString(settingsRow["class"]), Convert.ToInt32(settingsRow["num_op"]), Convert.ToInt32(settingsRow["temp_op_1"]), Convert.ToInt32(settingsRow["temp_op_2"]), Convert.ToInt32(settingsRow["temp_op_3"]), Convert.ToInt32(settingsRow["temp_rearm"]), DateTime.Parse(dr["ts"].ToString()) )); settingsRow = null; } catch (Exception ex) { SystemLogging.SendFatalErrorLog(ex.ToString()); } //SystemLogging.SendProcessLog("Ajuste:" + dr["settings_id"] + " carregado"); } return(settingsResult); } else { SystemLogging.SendWarningLog("Nenhum ajuste encontrado para o religador " + Core.GetRecloserManager().GetRecloserById(id).Number); return(null); } } }