Ejemplo n.º 1
0
        public bool Insert(EraModel this_)
        {
            string           connStr = Config.GetDstConstr();
            SQLiteConnection conn    = new SQLiteConnection(connStr);

            try
            {
                conn.Open();

                string        sql = "insert into user (id,name,pwd,acc,telephonenumber) values (@id,@name,@pwd,@acc,@telephonenumber)";
                SQLiteCommand cmd = new SQLiteCommand(sql, conn);
                cmd.Parameters.AddWithValue("@name", this_.name);
                cmd.Parameters.AddWithValue("@era", this_.era);
                cmd.Parameters.AddWithValue("@year", this_.year);
                cmd.Parameters.AddWithValue("@fromTime", this_.fromTime);
                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
Ejemplo n.º 2
0
        public EraModel GetById(string id)
        {
            string           connStr = Config.GetDstConstr();
            SQLiteConnection conn    = new SQLiteConnection(connStr);
            EraModel         result  = null;

            try
            {
                conn.Open();

                string        sql = "select * from user where id=@id";
                SQLiteCommand cmd = new SQLiteCommand(sql, conn);
                cmd.Parameters.AddWithValue("@id", id);
                SQLiteDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    if (reader.HasRows)
                    {
                        result          = new EraModel();
                        result.name     = DBUtils.GetString(reader, "name");
                        result.era      = DBUtils.GetString(reader, "era");
                        result.year     = DBUtils.GetString(reader, "year");
                        result.fromTime = DBUtils.GetString(reader, "fromTime");
                    }
                }
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(result);
        }