コード例 #1
0
 /// <summary>
 /// Start the training session
 /// </summary>
 /// <returns></returns>
 public int StartTrainingSession()
 {
     User.LastCommand = DateTime.Now;
     if (MM_Database_Connector.oConn == null)
     {
         return(-1);
     }
     else
     {
         try
         {
             using (DbCommand dCmd = MM_Database_Connector.CreateCommand(Settings.Default.DatabaseTrainingStartCommand, MM_Database_Connector.oConn))
             {
                 MM_Database_Connector.AddParameter(dCmd, "UserName", User.UserName);
                 MM_Database_Connector.AddParameter(dCmd, "CurrentDate", DateTime.Now);
                 MM_Database_Connector.AddParameter(dCmd, "MachineName", Environment.MachineName);
                 DbParameter Param = MM_Database_Connector.AddParameter(dCmd, "ID", null);
                 Object      Resp  = dCmd.ExecuteScalar();
                 if (Resp == null)
                 {
                     return(Convert.ToInt32(Param.Value));
                 }
                 else
                 {
                     return(Convert.ToInt32(Resp));
                 }
             }
         }
         catch (Exception ex)
         { return(-1); }
     }
 }
コード例 #2
0
 /// <summary>
 /// Write out our traning game HTML file
 /// </summary>
 /// <param name="state"></param>
 private static void WriteTrainingGameHtmlFile(object state)
 {
     while (true)
     {
         StringBuilder sB = new StringBuilder();
         using (DbCommand dCmd = MM_Database_Connector.CreateCommand(Settings.Default.TrainingGameQuery, MM_Database_Connector.oConn))
             using (DbDataReader dRd = dCmd.ExecuteReader())
                 while (dRd.Read())
                 {
                     sB.Append(ParseLine(Settings.Default.TrainingGameOutputLine, dRd));
                 }
         File.WriteAllText(Settings.Default.TrainingGameHtmlFile, Resources.TrainingGameHtmlContent.Replace("{Content}", sB.ToString()));
         Thread.Sleep(TimeSpan.FromMinutes(1));
     }
 }
コード例 #3
0
 /// <summary>
 /// Update a training informational point
 /// </summary>
 /// <param name="Title"></param>
 /// <param name="NewValue"></param>
 /// <param name="SessionId"></param>
 public bool UpdateTrainingInformation(string Title, float NewValue, int SessionId)
 {
     User.LastCommand = DateTime.Now;
     using (DbCommand dCmd = MM_Database_Connector.CreateCommand(Settings.Default.DatabaseTrainingUpdateCommand.Replace("{Title}", Title), MM_Database_Connector.oConn))
     {
         Object TitleValue = null;
         if (NewValue != 0)
         {
             TitleValue = NewValue;
         }
         MM_Database_Connector.AddParameter(dCmd, "Title", TitleValue);
         MM_Database_Connector.AddParameter(dCmd, "LastUpdate", DateTime.Now);
         MM_Database_Connector.AddParameter(dCmd, "Id", SessionId);
         return(dCmd.ExecuteNonQuery() == 1);
     }
 }
コード例 #4
0
        /// <summary>
        /// Load in the collection of notes
        /// </summary>
        /// <returns></returns>
        public MM_Note[] LoadNotes()
        {
            User.LastReceivedMessage = DateTime.Now;

            if (MM_Database_Connector.oConn == null || MM_Database_Connector.oConn.State != System.Data.ConnectionState.Open)
            {
                return(new MM_Note[0]);
            }
            List <MM_Note> OutNotes = new List <MM_Note>();

            using (DbCommand oCmd = MM_Database_Connector.CreateCommand("SELECT * FROM MM_NOTE", MM_Database_Connector.oConn))
                using (DbDataReader oRd = oCmd.ExecuteReader())
                    while (oRd.Read())
                    {
                        OutNotes.Add(new MM_Note(oRd));
                    }
            return(OutNotes.ToArray());
        }
コード例 #5
0
 #pragma warning disable 0618
 /// <summary>
 /// Report the most recent note date
 /// </summary>
 /// <returns></returns>
 public DateTime GetMostRecentNoteDate()
 {
     User.LastReceivedMessage = DateTime.Now;
     try
     {
         object Resp;
         using (DbCommand oCmd = MM_Database_Connector.CreateCommand("SELECT MAX(CreatedOn) FROM MM_Note", MM_Database_Connector.oConn))
             Resp = oCmd.ExecuteScalar();
         if (Resp is DateTime)
         {
             return((DateTime)Resp);
         }
         else
         {
             return(DateTime.MinValue);
         }
     }
     catch { return(DateTime.MinValue); }
 }
コード例 #6
0
        /// <summary>
        /// Upload a note, and return the new ID
        /// </summary>
        /// <param name="Note"></param>
        /// <returns></returns>
        public int UploadNote(MM_Note Note)
        {
            User.LastCommand = DateTime.Now;

            if (MM_Database_Connector.oConn == null || MM_Database_Connector.oConn.State != System.Data.ConnectionState.Open)
            {
                return(new Random().Next());
            }
            using (DbCommand oCmd = MM_Database_Connector.CreateCommand(Settings.Default.DatabaseNoteInsertCommand, MM_Database_Connector.oConn))
            {
                oCmd.Prepare();

                MM_Database_Connector.AddParameter(oCmd, "CreatedOn", Note.CreatedOn);
                MM_Database_Connector.AddParameter(oCmd, "Author", Note.Author);
                MM_Database_Connector.AddParameter(oCmd, "Note", Note.Note);
                MM_Database_Connector.AddParameter(oCmd, "AssociatedElement", Note.AssociatedElement);
                MM_Database_Connector.AddParameter(oCmd, "Acknowledged", Note.Acknowledged);
                DbParameter Param = MM_Database_Connector.AddParameter(oCmd, "ID", null);
                Param.Direction = System.Data.ParameterDirection.Output;
                Param.DbType    = System.Data.DbType.Int32;
                oCmd.ExecuteNonQuery();
                return(Convert.ToInt32(oCmd.Parameters["ID"].Value));
            }
        }