Пример #1
0
        static public List <JournalEntry> GetAll(int commander         = -999, DateTime?after = null, DateTime?before = null,
                                                 JournalTypeEnum[] ids = null, DateTime?allidsafter = null)
        {
            Dictionary <long, TravelLogUnit> tlus = TravelLogUnit.GetAll().ToDictionary(t => t.id);

            List <JournalEntry> list = new List <JournalEntry>();

            using (SQLiteConnectionUser cn = new SQLiteConnectionUser(utc: true))
            {
                using (DbCommand cmd = cn.CreateCommand("select * from JournalEntries"))
                {
                    string cnd = "";
                    if (commander != -999)
                    {
                        cnd = cnd.AppendPrePad("CommanderID = @commander", " and ");
                        cmd.AddParameterWithValue("@commander", commander);
                    }
                    if (after != null)
                    {
                        cnd = cnd.AppendPrePad("EventTime >= @after", " and ");
                        cmd.AddParameterWithValue("@after", after.Value);
                    }
                    if (before != null)
                    {
                        cnd = cnd.AppendPrePad("EventTime <= @before", " and ");
                        cmd.AddParameterWithValue("@before", before.Value);
                    }
                    if (ids != null)
                    {
                        int[] array = Array.ConvertAll(ids, x => (int)x);
                        if (allidsafter != null)
                        {
                            cmd.AddParameterWithValue("@idafter", allidsafter.Value);
                            cnd = cnd.AppendPrePad("(EventTypeId in (" + string.Join(",", array) + ") Or EventTime>=@idafter)", " and ");
                        }
                        else
                        {
                            cnd = cnd.AppendPrePad("EventTypeId in (" + string.Join(",", array) + ")", " and ");
                        }
                    }

                    if (cnd.HasChars())
                    {
                        cmd.CommandText += " where " + cnd;
                    }

                    cmd.CommandText += " Order By EventTime ASC";

                    DataSet ds = cn.SQLQueryText(cmd);

                    if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                    {
                        return(list);
                    }

                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        JournalEntry sys = JournalEntry.CreateJournalEntry(dr);
                        sys.beta = tlus.ContainsKey(sys.TLUId) ? tlus[sys.TLUId].Beta : false;
                        list.Add(sys);
                    }

                    return(list);
                }
            }
        }