int GetPool(GmConnection conn, int tableId)
        {
            int recordId;

            conn.DbConnection.Open();
            IDbTransaction tr    = conn.DbConnection.BeginTransaction(IsolationLevel.Serializable);
            string         query = string.Format("select RecordId from [{0}] where TableId=@TableId", tableName);
            GmCommand      cmd   = conn.CreateCommand(query);

            cmd.AddInt("TableId", tableId);
            cmd.DbCommand.Transaction = tr;
            try
            {
                object obj = cmd.ExecuteScalar();
                if (obj is int)
                {
                    recordId        = (int)obj;
                    cmd.CommandText = string.Format("update [{0}] set RecordId=@RecordId where TableId=@TableId", tableName);
                }
                else
                {
                    recordId        = minRecordId;
                    cmd.CommandText = string.Format("insert into [{0}] values (@TableId, @RecordId)", tableName);
                }
                cmd.AddInt("RecordId", recordId + poolSize);
                cmd.ExecuteNonQuery();
                tr.Commit();
            }
            catch (Exception ex)
            {
                tr.Rollback();
                throw ex;
            }
            return(recordId);
        }
        public void Load(GmConnection conn)
        {
            string query = string.Format("select * from [{0}]", tableName);

            using (IDataReader dr = conn.ExecuteReader(query))
            {
                while (dr.Read())
                {
                    ids.Add(dr.GetInt32(0), dr.GetInt32(1));
                }
            }
        }
/*		public void Save(GmConnection conn)
 *              {
 *                      int count = ids.Count;
 *                      if (count > 0)
 *                      {
 *                              int[] keys = new int[count];
 *                              int[] vals = new int[count];
 *                              ids.Keys.CopyTo(keys, 0);
 *                              ids.Values.CopyTo(vals, 0);
 *                              for (int i = 0; i < count; i++)
 *                              {
 *                                      DbCommand cmd = context.Conn.CreateCommandById("insertIntoGisIds");
 *                                      cmd.AddInt("TableId", keys[i]);
 *                                      cmd.AddInt("RecordId", vals[i]);
 *                                      cmd.ExecuteNonQuery();
 *                              }
 *                      }
 *              }*/
        #endregion

        #region Generation
        public int Get(GmConnection conn, int tableId)
        {
            int  recordId = minRecordId;
            bool hasKey   = ids.ContainsKey(tableId);

            if (hasKey)
            {
                recordId = (int)ids[tableId];
            }
            if (!hasKey || recordId % poolSize == 0)
            {
                recordId = GetPool(conn, tableId);
            }
            recordId++;
            ids[tableId] = recordId;
            return(recordId);
        }
Esempio n. 4
0
 public void Write(LogType logType, string subType, string msg)
 {
     if (connFactory != null)
     {
         using (GmConnection conn = connFactory.CreateConnection())
         {
             GmCommand cmd = conn.CreateCommand("insert into Log values (@Time,@TerminalId,@UserId,@LogType,@SubType,@Message)");
             cmd.AddDateTime("Time", DateTime.Now);
             cmd.AddInt("TerminalId", App.TerminalId);
             IDbDataParameter par = cmd.AddInt("UserId", App.UserId);
             if (App.UserId == 0)
             {
                 par.Value = DBNull.Value;
             }
             cmd.AddInt("LogType", (int)logType);
             cmd.AddString("SubType", subType, FieldLength.subType);
             cmd.AddString("Message", msg, FieldLength.message);
             cmd.ExecuteNonQuery();
         }
     }
 }
Esempio n. 5
0
 public GmCommand(GmConnection conn, string cmdText) : this(conn)
 {
     SetCommandText(cmdText);
 }
Esempio n. 6
0
 public GmCommand(GmConnection conn)
 {
     this.conn = conn;
     this.cmd  = conn.DbConnection.CreateCommand();
     this.DbCommand.CommandTimeout = conn.ConnectionFactory.CommandTimeout;
 }