Exemplo n.º 1
0
 public DynaRecord(QryDef qryDef)
 {
     qry_name = qryDef.qry_name;
     //dynamic properties
     FieldDict = new Dictionary <String, IDynaField>(16);
     //ordinal properties
     ReadList = new List <IDynaField>(16);
     lockObj  = new Object();
 }
Exemplo n.º 2
0
 public DynaRecord GetDynaRecord(string key)
 {
     lock (lockObj)
     {
         DynaRecord dynaRecord = null;
         //поискать в кэше объектов
         if (recDict.TryGetValue(key, out dynaRecord))
         {
             return(dynaRecord);
         }
         //иначе создать DynaRecord
         QryDef qryDef = qryList.Find(qry => qry.qry_name == key);
         if (qryDef == null)
         {
             dataMod.lastError = string.Format("Запрос {0} не найден!", key);
             return(null);
         }
         dynaRecord = new DynaRecord(qryDef)
         {
             //Адаптер для работы с DB
             Query = new DataQuery(GetConnection(), key),
             //Для чтения json-потока
             StreamReader = new JsonStreamReader(),
             //Для записи в json-поток
             StreamWriter = new TextStreamWriter()
         };
         //загрузить описания всех колонок
         foreach (FldDef fldDef in fldList.Where(fld => fld.qry_name == qryDef.fld_dict))
         {
             dynaRecord.CreateField(fldDef);
         }
         //добавить в кэш объектов
         recDict.Add(key, dynaRecord);
         return(dynaRecord);
     }
 }
Exemplo n.º 3
0
        public bool LoadMeta()
        {
            loaded = false;
            IDbConnection dbConn = null;
            IDbCommand    qryComm = null, fldComm = null;
            IDataReader   qryReader = null, fldReader = null;

            try
            {
                recDict.Clear();
                //get connection from pool
                dbConn = GetConnection();
                dbConn.Open();
                //qryDict
                qryComm             = dbConn.CreateCommand();
                qryComm.CommandType = CommandType.Text;
                qryComm.CommandText = "select Qry_Name, Qry_Head, Qry_Lord, Fld_Dict, Qry_Mask from T_QryDict";
                qryReader           = qryComm.ExecuteReader();
                qryList.Clear();
                while (qryReader.Read())
                {
                    QryDef qryDef = new QryDef();
                    qryDef.qry_name = qryReader.GetString(0);
                    qryDef.qry_head = qryReader.GetString(1);
                    qryDef.qry_lord = qryReader.GetString(2);
                    qryDef.fld_dict = qryReader.GetString(3);
                    qryDef.qry_mask = qryReader.GetInt32(4);
                    qryList.Add(qryDef);
                }
                qryReader.Close();
                //fldList
                fldComm             = dbConn.CreateCommand();
                fldComm.CommandType = CommandType.Text;
                fldComm.CommandText = "select Qry_Name, Fld_Name, Fld_Head, Fld_Type, Fld_Size, Inp_Mask, Out_Mask, Def_Val from T_FldDict";
                fldReader           = fldComm.ExecuteReader();
                fldList.Clear();
                while (fldReader.Read())
                {
                    FldDef fldDef = new FldDef();
                    fldDef.qry_name = fldReader.GetString(0);
                    fldDef.fld_name = fldReader.GetString(1);
                    fldDef.fld_head = fldReader.GetString(2);
                    fldDef.fld_type = fldReader.GetInt32(3);
                    fldDef.fld_size = fldReader.GetInt32(4);
                    fldDef.inp_mask = fldReader.GetInt32(5);
                    fldDef.out_mask = fldReader.GetInt32(6);
                    fldDef.def_val  = fldReader.GetString(7);
                    fldList.Add(fldDef);
                }
                fldReader.Close();
                loaded = true;
            }
            catch (DbException sx)
            {
                //if (ShowError != null) ShowError(sx.Message);
                lastError = sx.Message;
            }
            catch (Exception ex)
            {
                //if (ShowError != null) ShowError(ex.Message);
                lastError = ex.Message;
            }
            finally
            {
                if (fldReader != null)
                {
                    fldReader.Close();
                }
                if (qryReader != null)
                {
                    qryReader.Close();
                }
                if (dbConn != null)
                {
                    dbConn.Close();
                }
            }
            return(loaded);
        }