Ejemplo n.º 1
0
        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());
            }
        }