Ejemplo n.º 1
0
 public static void AddLogRecord(string mainInfo, string additionalInfo, LogRecord.LogColor type)
 {
     ExecuteNonQuery(string.Format(
         "insert into LOG values('{0}', '{1}', '{2}', '{3}')",
         DateTimeToSQLiteFormat(DateTime.Now), mainInfo, additionalInfo, (byte)type));
 }
Ejemplo n.º 2
0
        private static void convertQueryToLogRecord(string query, List<SQLiteParameter> parameters, LogRecord.LogColor type = LogRecord.LogColor.UnKnown)
        {
            StringBuilder additionalInfo = new StringBuilder();
            additionalInfo.Append(query.Replace("'", "\""));

            if(parameters!=null && parameters.Count!=0)
            {
                additionalInfo.Append(" [Параметры: ");
                foreach (SQLiteParameter parameter in parameters)
                {
                    additionalInfo.AppendFormat("{0} = {1}", parameter.ParameterName, parameter.Value);
                }
                additionalInfo.Append("]");
            }

            string mainInfo = "Запрос.";
            query = query.ToUpper();

            if (type == LogRecord.LogColor.UnKnown)
            {
                if (query.Contains("INSERT INTO "))
                {
                    mainInfo = string.Format(
                        "Добавление записи в таблицу {0}",
                        getTableNameFromTypedQuery(query, "INSERT INTO "));
                    type = LogRecord.LogColor.Insert;
                }
                else if (query.Contains("UPDATE "))
                {
                    mainInfo = string.Format(
                        "Обновление записи в таблице {0}",
                        getTableNameFromTypedQuery(query, "UPDATE "));
                    type = LogRecord.LogColor.Update;
                }
            }
            else
            {
                if(type == LogRecord.LogColor.Send)
                {
                    mainInfo = "Отправка обновлений по почте";
                }
            }

            AddLogRecord(mainInfo, additionalInfo.ToString().Replace("\r\n", ""), type);
        }
Ejemplo n.º 3
0
        public static List<LogRecord> GetLogRecords()
        {
            SQLiteConnection connection = new SQLiteConnection(ConnectionString);
            string command = string.Concat("select * \r\nfrom LOG");
            List<LogRecord> records = new List<LogRecord>();

            try
            {
                connection.Open();
                SQLiteCommand cmd = new SQLiteCommand(command, connection);
                SQLiteDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    LogRecord record = new LogRecord
                    {
                        LogDateTime = reader.GetString(reader.GetOrdinal("DateTime")),
                        MainInfo = reader.GetString(reader.GetOrdinal("MainInfo")),
                        AddInfo = reader.GetString(reader.GetOrdinal("Description")),
                        Color = (LogRecord.LogColor)reader.GetByte(reader.GetOrdinal("Type"))
                    };
                    records.Add(record);
                }
            }
            catch (Exception exc)
            {
                MessageWindows.Show("GetLogRecords:Exception", exc.Message);
                return records;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return records;
        }