public void ReadNames() { Logger.info(String.Format("Чтение наименований за {0} по объекту [{1}-{2}]", DateStart.ToString("dd.MM.yyyy"), Source.Obj, Source.ObjType)); Names = new Dictionary<string, string>(); Data = new Dictionary<string, DataRecord>(); /*for (int i = 0; i <= 50; i++) { string name = "Parametr" + i.ToString(); string codeStr = String.Format("{0}_{1}_{2}", Source.Obj, Source.ObjType, i); Names.Add(codeStr, name); DataRecord rec = new DataRecord(); rec.Key = codeStr; rec.Name = name; rec.Source = SourceInfo.getFullInfo(codeStr); rec.Values = new Dictionary<DateTime, string>(); foreach (DateTime date in Dates) { rec.Values.Add(date, "---"); } Data.Add(codeStr, rec); } return;*/ try { SqlConnection con = getConnection(); con.Open(); string comSTR = ""; if (Source.ObjType == 0) { int stationID = Source.Obj == 8737 ? 2 : Source.Obj == 8738 ? 1 : Source.Obj == 8739 ? 3 : Source.Obj == 8740 ? 4 : -1; comSTR = String.Format("SELECT NAME,CODE FROM SENSORS WHERE STATIONID={0} order by code", stationID); } else { comSTR = String.Format("SELECT NAME,CODE FROM CLIENTS order by code"); } SqlCommand command = new SqlCommand(comSTR, con); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { string name = reader.GetString(0); int code = reader.GetInt32(1); name = String.Format("{0}: {1}", code, name); string codeStr = String.Format("{0}_{1}_{2}", Source.Obj, Source.ObjType, code); Names.Add(codeStr, name); DataRecord rec = new DataRecord(); rec.Key = codeStr; rec.Name = name; rec.Source = SourceInfo.getFullInfo(codeStr); rec.Values = new Dictionary<DateTime, string>(); foreach (DateTime date in Dates) { rec.Values.Add(date, "---"); } Data.Add(codeStr, rec); } reader.Close(); con.Close(); } catch (Exception e) { Logger.info("Ошибка при чтении наименований источника " + e.ToString()); } }
public void ReadNames() { Logger.info(String.Format("Чтение наименований ")); Names = new Dictionary <string, string>(); Data = new Dictionary <string, DataRecord>(); /*for (int i = 0; i <= 50; i++) { * string name = "Parametr" + i.ToString(); * string codeStr = String.Format("{0}_{1}_{2}", Source.Obj, Source.ObjType, i); * Names.Add(codeStr, name); * * DataRecord rec = new DataRecord(); * rec.Key = codeStr; * rec.Name = name; * rec.Source = SourceInfo.getFullInfo(codeStr); * rec.Values = new Dictionary<DateTime, string>(); * foreach (DateTime date in Dates) { * rec.Values.Add(date, "---"); * } * Data.Add(codeStr, rec); * } * return;*/ try { SqlConnection con = getConnection(); con.Open(); string comSTR = ""; if (ObjType == 0) { comSTR = String.Format("select dev.name+' '+sen.name,sen.code,dev.code from devices as dev left join sensors as sen on dev.id=sen.stationid where dev.code in ({0}) order by dev.name+' '+sen.name", String.Join(",", Objs)); } else { comSTR = String.Format("SELECT NAME,CODE,0 FROM CLIENTS order by code"); } SqlCommand command = new SqlCommand(comSTR, con); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { string name = reader.GetString(0); int code = reader.GetInt32(1); int obj = reader.GetInt32(2); name = String.Format("{0}_{1}: {2}", obj, code, name); string codeStr = String.Format("{0}_{1}_{2}", obj, ObjType, code); Names.Add(codeStr, name); DataRecord rec = new DataRecord(); rec.Key = codeStr; rec.Name = name; rec.Source = SourceInfo.getFullInfo(codeStr); rec.Values = new Dictionary <DateTime, string>(); foreach (DateTime date in Dates) { rec.Values.Add(date, "---"); } Data.Add(codeStr, rec); } reader.Close(); con.Close(); } catch (Exception e) { Logger.info("Ошибка при чтении наименований источника " + e.ToString()); } }