Ejemplo n.º 1
0
        private void InitDataBase(int version)
        {
            int result = db.ExecuteScalar("SELECT count(*) from sqlite_master where type='table' and name='" + TABLE_NAME + "'");

            if (result == 0)
            {
                //表不存在
                string[] colNames = { "KEY", "VALUE" };
                string[] colTypes = { "TEXT", "TEXT" };
                db.CreateTable(TABLE_NAME, colNames, colTypes);
                db.InsertValues(TABLE_NAME, new string[] { "version", version + "" });
            }
            else
            {
                //判断数据库是否需要升级
                DataTable dt = db.GetTable("select * from " + TABLE_NAME + " where KEY='version'");
                if (dt != null && dt.Rows.Count > 0)
                {
                    int OldVersion = Convert.ToInt32(dt.Rows[0]["VALUE"]);
                    if (OldVersion < version)
                    {
                        UpdateDB();
                        db.UpdateValues(TABLE_NAME, new string[] { "VALUE" }, new string[] { version + "" }, "KEY", "version", "=");
                    }
                }
            }
            CreateAllTables();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加聊天记录
        /// </summary>
        /// <param name="Seq"></param>
        /// <param name="Content"></param>
        /// <param name="IsSend"></param>
        /// <param name="FileName"></param>
        /// <param name="MsgType"></param>
        /// <param name="FileSize"></param>
        public void InsertMessage(Message msg, string Seq)
        {
            bool   IsSend   = msg.IsSend;
            string Content  = msg.Content;
            string FileName = msg.fileName;
            int    MsgType  = msg.MsgType;
            string FileSize = msg.FileSize;

            object[] values = { null, Seq, Content, IsSend, FileName, DateTime.Now, MsgType, FileSize, msg.MsgId };
            Helper.InsertValues(TABLE_NAME, values);
        }