Ejemplo n.º 1
0
        public int InsertLogData(Indihiang.DomainObject.LogData obj)
        {
            SQLiteConnection con = null;
            int id = -1;

            try
            {
                con = new SQLiteConnection(GetConnectionStrng());
                con.Open();

                string query = String.Format("insert into logdata(logdate,logtime) values('{0}','{1}');select last_insert_rowid();", obj.LogDate, obj.LogTime);
                using (SQLiteCommand cmd = new SQLiteCommand(query, con))
                {
                    id = Convert.ToInt32(cmd.ExecuteScalar());
                }
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.StackTrace);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }

            return(id);
        }
Ejemplo n.º 2
0
        public List <Indihiang.DomainObject.LogData> GetLogDataByFilter(string filter)
        {
            SQLiteConnection con = null;
            SQLiteDataReader rd  = null;
            List <Indihiang.DomainObject.LogData> list = new List <Indihiang.DomainObject.LogData>();

            try
            {
                con = new SQLiteConnection(GetConnectionStrng());
                con.Open();

                string        query = string.Format("select id,logdate,logtime from logdata where {0}", filter);
                SQLiteCommand cmd   = new SQLiteCommand(query, con);
                rd = cmd.ExecuteReader();
                while (rd.Read())
                {
                    Indihiang.DomainObject.LogData obj = new Indihiang.DomainObject.LogData();
                    if (!rd.IsDBNull(rd.GetOrdinal("id")))
                    {
                        obj.Id = Convert.ToInt32(rd["id"].ToString());
                    }
                    else
                    {
                        obj.Id = -1;
                    }
                    if (!rd.IsDBNull(rd.GetOrdinal("logdate")))
                    {
                        obj.LogDate = (string)rd["logdate"];
                    }
                    if (!rd.IsDBNull(rd.GetOrdinal("logtime")))
                    {
                        obj.LogTime = (string)rd["logtime"];
                    }

                    list.Add(obj);
                }
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.StackTrace);
            }
            finally
            {
                if (rd != null)
                {
                    rd.Close();
                }
                if (con != null)
                {
                    con.Close();
                }
            }

            return(list);
        }