コード例 #1
0
        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);
        }
コード例 #2
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();
         }
     }
 }