private void GetInfoByTableName(int pageIndex) { string tabname = TableNameNow; if (tabname != null && tabname != "") { try { ShouPageInfo(tabname, pageIndex); //开始位置 string sql = String.Empty; int StartIndex = 1; if (pageIndex == 1) { StartIndex = 1; } else { StartIndex = PageCount * pageIndex; } if (StartIndex == 1) //解决一条时差不到 { StartIndex--; sql = String.Format("select * from '{0}' LIMIT {1},{2}; ", tabname, StartIndex, PageCount); } else { sql = String.Format("select * from '{0}' LIMIT {1},{2}; ", tabname, PageCount, StartIndex); } MyDB.SQLiteDBHelper db = new MyDB.SQLiteDBHelper(dbpath); DataTable dt = db.ExecuteDataTable(sql, null); rtb_chatRecord.Text = ""; bool IsGroup = IsGroupChat(dt); foreach (DataRow item in dt.Rows) { MessageInfo info = new MessageInfo(); info.Content = item["Content"].ToString(); info.MessageType = Convert.ToInt32(item["Type"].ToString()); info.time = item["Time"].ToString(); info.FriendNick = tabname; AddMessage("我", "", info, IsGroup); } } catch (Exception ex) { this.rtb_chatRecord.Text = ""; } } }
/// <summary> /// 根据数据库地址加载聊天记录 /// </summary> /// <param name="dbapth"></param> private void initDataLog(string dbapth) { if (File.Exists(dbapth) == false) { return; } MyDB.SQLiteDBHelper db = new MyDB.SQLiteDBHelper(dbapth); DataTable dt = db.GetSchema(); foreach (DataRow item in dt.Rows) { if (item["TABLE_TYPE"].ToString() == "table" && item["TABLE_NAME"].ToString() != "" && item["TABLE_NAME"].ToString() != "好友列表") { lb_friend.Items.Add(item["TABLE_NAME"].ToString()); } } }
/// <summary> /// 显示当前表的聊天记录信息 包含页数和条数 当前的页数。 /// </summary> /// <param name="tablename"></param> private void ShouPageInfo(string tablename, int pageIndex) { string sql = String.Format("select Count(*) 'Count' from '{0}'", tablename); MyDB.SQLiteDBHelper db = new MyDB.SQLiteDBHelper(dbpath); DataTable dt = db.ExecuteDataTable(sql, null); string SumCount = dt.Rows[0]["Count"].ToString(); if (Convert.ToInt32(SumCount) < PageCount) //不足一页的条目 { SumCountPage = 1; } else { SumCountPage = Convert.ToInt32(SumCount) / PageCount + 1; } label2_PageShow.Text = String.Format("共{0}条记录,当前第{1}页,共{2}页", SumCount, pageIndex, SumCountPage); }