public static void addTimezone(int organizationID, int TZNumber, string v_IntervalData) { if (!ListaTimeZones.ContainsKey(organizationID)) { LENELTimeZones nuevaLNLTimeZone = new LENELTimeZones(organizationID); ListaTimeZones.Add(organizationID, nuevaLNLTimeZone); } LENELTimeZones LNLTimeZone = ListaTimeZones[organizationID]; LNLTimeZone.createTimeZoneData(TZNumber, v_IntervalData); mainApp.DataManager.addLenelTimeZone(LNLTimeZone, organizationID, TZNumber); }
/// <summary> /// addLenelTimeZone: Graba la definicion completa de una TimeZone(TZNum) a la base, para lo cual borra previamente la definicion anterior /// </summary> /// <param name="v_LNLTimeZones"></param> /// <param name="v_OrgID"></param> /// <param name="v_TZNum"></param> public void addLenelTimeZone(LENELTimeZones v_LNLTimeZones, int v_OrgID, int v_TZNum) { SqlConnection cnn = new SqlConnection(conexion); try { cnn.Open(); SqlCommand cmd = cnn.CreateCommand(); cmd.CommandText = "delete from TimeZones where idOrganizacion =" + v_OrgID.ToString() + " and TZNum = " + v_TZNum.ToString(); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); TimeZoneData TZData = v_LNLTimeZones.getTimeZoneData(); if (TZData != null) { if (TZData.TZDefinition.ContainsKey(v_TZNum)) { List<TZInterval> ReaderTZDef = TZData.TZDefinition[v_TZNum]; foreach (TZInterval intervalo in ReaderTZDef) { string rangoini = intervalo.horaIni.ToString() + ":" + intervalo.minIni.ToString(); string rangoFin = intervalo.horaFin.ToString() + ":" + intervalo.minFin.ToString(); cmd = cnn.CreateCommand(); cmd.CommandText = "insert into TimeZones (idOrganizacion,TZNum,rangoIni,rangoFin,DOW,HOL) values (" + v_OrgID.ToString() + "," + v_TZNum.ToString() + ",'" + rangoini + "','" + rangoFin + "'," + intervalo.DOW.ToString() + "," + intervalo.HOL.ToString() + ")"; cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); } } } } catch (Exception ex) { loguearString("Excepcion en addLenelTimeZone: " + ex.Message, TiposLOG.HH); } finally { cnn.Close(); } }
// Carga todas las listas de Timezones definidas para todas las organizaciones. public Dictionary<int, LENELTimeZones> LoadListaTimeZones() { Dictionary<int, LENELTimeZones> listaResultado = new Dictionary<int, LENELTimeZones>(); SqlConnection cnn = new SqlConnection(conexion); try { cnn.Open(); SqlCommand cmd = cnn.CreateCommand(); cmd.CommandText = "select * from TimeZones"; cmd.CommandType = CommandType.Text; SqlDataReader lector = cmd.ExecuteReader(); while (lector.Read()) { int idOrg = int.Parse(lector["idOrganizacion"].ToString()); if (!listaResultado.ContainsKey(idOrg)) { LENELTimeZones nuevaLista = new LENELTimeZones(idOrg); listaResultado.Add(idOrg, nuevaLista); } LENELTimeZones timeZones = listaResultado[idOrg]; string rangoIni = lector["rangoIni"].ToString(); string rangoFin = lector["rangoFin"].ToString(); int TZNum = int.Parse(lector["TZNum"].ToString()); int DOW = int.Parse(lector["DOW"].ToString()); int HOL = int.Parse(lector["HOL"].ToString()); string[] datosRangoIni = rangoIni.Split(':'); string[] datosRangoFin = rangoFin.Split(':'); string horaIni = datosRangoIni[0]; string minIni = datosRangoIni[1]; string horaFin = datosRangoFin[0]; string minFin = datosRangoFin[1]; string timeZoneDef = horaIni +"," + minIni + "," + horaFin +"," + minFin + "," + DOW.ToString() + "," + HOL.ToString(); TimeZoneData TZData = timeZones.getTimeZoneData(); TZData.addTZInterval(TZNum, new TZInterval(timeZoneDef)); } lector.Close(); } catch (Exception ex) { loguearString("Excepcion en LoadListaTimeZones: " + ex.Message, TiposLOG.HH); } finally { cnn.Close(); } return listaResultado; }