当前位置:网站首页>C return multiple values getter setter queries the database and adds the list return value to the window
C return multiple values getter setter queries the database and adds the list return value to the window
2022-07-02 02:13:00 【weixin_ forty million nine hundred and thirty-eight thousand th】
Reference article C# Medium setter and getter
C# Medium setter and getter
How to use it? return Returns two or more values ?
Create a storage data object suoyou
class suoyou {
//private string utime;
// private string uin;
//private int flag;
// //private string unum;
// private string qnum;
// private string qtime;
// private string qname;
public string qname
{
get;
set;
}
public string qtime
{
get;
set;
}
public string qnum
{
get;
set;
}
public string unum
{
get;
set;
}
public string utime {
get;
set;
}
public string uin {
get;
set;
}
public int flag {
get;
set;
}
}
Create query object cha
class cha {
public List<suoyou> chasuoyou(string wenpath){
string qunp;
db b = new db();
List<suoyou> s=new List<suoyou>();
// Create connection string
string path = wenpath;
//string databaseFileName = "C:/QQ.db";
//string connectionString = "data source = " + databaseFileName;
// Linked database
//SQLiteConnection dbConnection = new SQLiteConnection(connectionString);
// Open database
//dbConnection.Open();
//sql sentence
string sql = "select name from sqlite_master where type='table' order by name;";
// load sql
SQLiteCommand cd = new SQLiteCommand(sql, b.lian(path));
// perform
SQLiteDataReader dr = cd.ExecuteReader();
//
// Query all table names
while (dr.Read())// Read
{
try
{
//Console.Write(dr["name"]+"\n");
string str = dr["name"].ToString();
if (str.Length > 12)// Filter less than 9 Table name of , Because the table names of user messages and group messages are greater than 9
{
qunp = str.Substring(0, 12);
string pan = str.Substring(0, 9);
//Console.Write(pan + "\n" + " I am a ");
if (pan == "tb_c2cMsg")
{
// Determine whether it is a user message or a group message
string pp = str;
//string str1 = dr["name"].ToString();
//string pan1 = str1.Substring(0, 9);
//Console.Write(str + "\n");
string sqls = "select * from '" + str + "';";
// load sql
SQLiteCommand cds = new SQLiteCommand(sqls, b.lian(path));
// perform
SQLiteDataReader drs = cds.ExecuteReader();
if (drs.Read())// Read
{
string count;
string sqlc = "select count(*) as num from '" + str + "';";// Get the number of messages
// load sql
SQLiteCommand cdsc = new SQLiteCommand(sqlc, b.lian(path));
// perform
SQLiteDataReader drc = cdsc.ExecuteReader();
if (drc.Read())
{
count = drc["num"].ToString();
//Console.Write(count+"\n");
}
//Console.Write(drs["uin"]);
DateTime d = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));// Turn the timestamp to mm / DD / yyyy
long t = long.Parse(drs["time"] + "0000000");
TimeSpan to = new TimeSpan(t);
//Console.Write(d.Add(to) + "\n");
var time6 = d.Add(to);
suoyou y = new suoyou();
y.uin = drs["uin"].ToString();
y.utime = time6.ToString();
y.unum = drc["num"].ToString();
s.Add(y);
ListViewItem lt = new ListViewItem();
// Convert database data into ListView A row of data of type
}
}
else if (qunp == "tb_TroopMsg_" && str.Length > 16)// The filter table name starts with troopm But less than 12 Characters , Because this is not a table with content
{
// It's a group message
//if (str.Length > 16 && qunp == "tb_TroopMsg_")
//{
string qun;
try
{
Console.Write(str + ".." + str.Length + "\n");
//string pan1 = str.Substring(9, 12);
qun = str.Substring(12);
Console.Write(qun + "\n");
}
catch (Exception e2)
{
Console.Write(e2 + " Group Fault ");
}
//}
string pp = str.Substring(0, 12);
if (pp == "tb_TroopMsg_" && str.Length > 12)
{
//string pan1 = str.Substring(0, str.Length);
//Console.Write(pan1 + "\n"+str.Length+"\n");
//string qun = str.Substring(4, str.Length);
//Console.Write(str+"\n");
string sqls = "select * from '" + str + "';";
// load sql
SQLiteCommand cds = new SQLiteCommand(sqls, b.lian(path));
// perform
SQLiteDataReader drs = cds.ExecuteReader();
if (drs.Read())// Read
{
string count;
string sqlc = "select count(*) as num from '" + str + "';";// Get the number of messages
// load sql
SQLiteCommand cdsc = new SQLiteCommand(sqlc, b.lian(path));
// perform
SQLiteDataReader drc = cdsc.ExecuteReader();
if (drc.Read())
{
count = drc["num"].ToString();
//Console.Write(count+"\n");
}
//Console.Write(drs["uin"]);
DateTime d = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));// Turn the timestamp to mm / DD / yyyy
long t = long.Parse(drs["MsgTime"] + "0000000");
TimeSpan to = new TimeSpan(t);
//Console.Write(d.Add(to) + "\n");
var time6 = d.Add(to);
suoyou y = new suoyou();
y.qname = " Group " + str.Substring(12);
y.qtime = time6.ToString();
y.qnum = drc["num"].ToString();
}
}
//string str1 = dr["name"].ToString();
//string pan1 = str1.Substring(0, 9);
//Console.Write(str + "\n");
// pan1 = pp.Substring(0, pp.Length);
//Console.Write(pan1+"\n");
}
else
{
Console.Write(str + " Group mismatch ");
}
}
else
{
Console.Write(str + " User messages do not match ");
}
}
catch (Exception e1)
{
Console.Write(e1 + " The following error ");
}
}
return s;
}
}
cha in chasuoyou Method return value is list , Save the queried data into the object , Then put the object into list
Here is the extracted value
cha c = new cha();
List<suoyou> s=c.chasuoyou(wenpath);
for (int i = 0; i < s.Count;i++ )
{
ListViewItem lt = new ListViewItem();
lt.Text = s[i].uin;
lt.SubItems.Add(s[i].utime);
lt.SubItems.Add(s[i].unum);
// take lt Data added to listView1 Control
listView1.Items.Add(lt);
Console.Write(s[0].unum);
}
Here is the complete code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SQLite;
using System.IO;
namespace qq
{
public partial class Form1 : Form
{
class db
{
private SQLiteConnection dbConnection;
//private SQLiteCommand cd;
//private SQLiteDataReader read;
public SQLiteConnection lian(string path)
{
// Create connection string
try
{
string databaseFileName = path;
string connectionString = "data source = " + databaseFileName;
// Linked database
dbConnection = new SQLiteConnection(connectionString);
dbConnection.Open();
}
catch (Exception e)
{
Console.Write(e + " object ");
}
return dbConnection;
}
}
class suoyou {
//private string utime;
// private string uin;
//private int flag;
// //private string unum;
// private string qnum;
// private string qtime;
// private string qname;
public string qname
{
get;
set;
}
public string qtime
{
get;
set;
}
public string qnum
{
get;
set;
}
public string unum
{
get;
set;
}
public string utime {
get;
set;
}
public string uin {
get;
set;
}
public int flag {
get;
set;
}
}
class cha {
public List<suoyou> chasuoyou(string wenpath){
string qunp;
db b = new db();
List<suoyou> s=new List<suoyou>();
// Create connection string
string path = wenpath;
//string databaseFileName = "C:/QQ.db";
//string connectionString = "data source = " + databaseFileName;
// Linked database
//SQLiteConnection dbConnection = new SQLiteConnection(connectionString);
// Open database
//dbConnection.Open();
//sql sentence
string sql = "select name from sqlite_master where type='table' order by name;";
// load sql
SQLiteCommand cd = new SQLiteCommand(sql, b.lian(path));
// perform
SQLiteDataReader dr = cd.ExecuteReader();
//
// Query all table names
while (dr.Read())// Read
{
try
{
//Console.Write(dr["name"]+"\n");
string str = dr["name"].ToString();
if (str.Length > 12)// Filter less than 9 Table name of , Because the table names of user messages and group messages are greater than 9
{
qunp = str.Substring(0, 12);
string pan = str.Substring(0, 9);
//Console.Write(pan + "\n" + " I am a ");
if (pan == "tb_c2cMsg")
{
// Determine whether it is a user message or a group message
string pp = str;
//string str1 = dr["name"].ToString();
//string pan1 = str1.Substring(0, 9);
//Console.Write(str + "\n");
string sqls = "select * from '" + str + "';";
// load sql
SQLiteCommand cds = new SQLiteCommand(sqls, b.lian(path));
// perform
SQLiteDataReader drs = cds.ExecuteReader();
if (drs.Read())// Read
{
string count;
string sqlc = "select count(*) as num from '" + str + "';";// Get the number of messages
// load sql
SQLiteCommand cdsc = new SQLiteCommand(sqlc, b.lian(path));
// perform
SQLiteDataReader drc = cdsc.ExecuteReader();
if (drc.Read())
{
count = drc["num"].ToString();
//Console.Write(count+"\n");
}
//Console.Write(drs["uin"]);
DateTime d = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));// Turn the timestamp to mm / DD / yyyy
long t = long.Parse(drs["time"] + "0000000");
TimeSpan to = new TimeSpan(t);
//Console.Write(d.Add(to) + "\n");
var time6 = d.Add(to);
suoyou y = new suoyou();
y.uin = drs["uin"].ToString();
y.utime = time6.ToString();
y.unum = drc["num"].ToString();
s.Add(y);
ListViewItem lt = new ListViewItem();
// Convert database data into ListView A row of data of type
}
}
else if (qunp == "tb_TroopMsg_" && str.Length > 16)// The filter table name starts with troopm But less than 12 Characters , Because this is not a table with content
{
// It's a group message
//if (str.Length > 16 && qunp == "tb_TroopMsg_")
//{
string qun;
try
{
Console.Write(str + ".." + str.Length + "\n");
//string pan1 = str.Substring(9, 12);
qun = str.Substring(12);
Console.Write(qun + "\n");
}
catch (Exception e2)
{
Console.Write(e2 + " Group Fault ");
}
//}
string pp = str.Substring(0, 12);
if (pp == "tb_TroopMsg_" && str.Length > 12)
{
//string pan1 = str.Substring(0, str.Length);
//Console.Write(pan1 + "\n"+str.Length+"\n");
//string qun = str.Substring(4, str.Length);
//Console.Write(str+"\n");
string sqls = "select * from '" + str + "';";
// load sql
SQLiteCommand cds = new SQLiteCommand(sqls, b.lian(path));
// perform
SQLiteDataReader drs = cds.ExecuteReader();
if (drs.Read())// Read
{
string count;
string sqlc = "select count(*) as num from '" + str + "';";// Get the number of messages
// load sql
SQLiteCommand cdsc = new SQLiteCommand(sqlc, b.lian(path));
// perform
SQLiteDataReader drc = cdsc.ExecuteReader();
if (drc.Read())
{
count = drc["num"].ToString();
//Console.Write(count+"\n");
}
//Console.Write(drs["uin"]);
DateTime d = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));// Turn the timestamp to mm / DD / yyyy
long t = long.Parse(drs["MsgTime"] + "0000000");
TimeSpan to = new TimeSpan(t);
//Console.Write(d.Add(to) + "\n");
var time6 = d.Add(to);
suoyou y = new suoyou();
y.qname = " Group " + str.Substring(12);
y.qtime = time6.ToString();
y.qnum = drc["num"].ToString();
}
}
//string str1 = dr["name"].ToString();
//string pan1 = str1.Substring(0, 9);
//Console.Write(str + "\n");
// pan1 = pp.Substring(0, pp.Length);
//Console.Write(pan1+"\n");
}
else
{
Console.Write(str + " Group mismatch ");
}
}
else
{
Console.Write(str + " User messages do not match ");
}
}
catch (Exception e1)
{
Console.Write(e1 + " The following error ");
}
}
return s;
}
}
public Form1()
{
InitializeComponent();
}
string wenpath;
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog P_File_Folder = new OpenFileDialog();
P_File_Folder.Multiselect = true;// This value determines whether multiple files can be selected
P_File_Folder.Title = " Please select a folder ";
P_File_Folder.Filter = "QQ.db(QQ.db)|QQ.db";
if (P_File_Folder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string file = P_File_Folder.FileName;
wenpath = file;
Console.Write(file);
}
}
private void button3_Click(object sender, EventArgs e)
{
// Find data Show all tables
if (wenpath != null && wenpath != "")
{
cha c = new cha();
List<suoyou> s=c.chasuoyou(wenpath);
for (int i = 0; i < s.Count;i++ )
{
ListViewItem lt = new ListViewItem();
lt.Text = s[i].uin;
lt.SubItems.Add(s[i].utime);
lt.SubItems.Add(s[i].unum);
// take lt Data added to listView1 Control
listView1.Items.Add(lt);
Console.Write(s[0].unum);
}
}
else
{
MessageBox.Show(" I haven't chosen the corresponding QQ.db file ");
}
}
}
}
/* // Create connection string db b = new db(); // Create connection string string path = "C:/QQ.db"; //string s = "tb_c2cMsg_1030031037"; //sql sentence string s = "tb_c2cMsg_1030331506"; string count; int c; string sqlc = "select count(*) as num from '" + s + "';";// Get the number of messages // load sql SQLiteCommand cdsc = new SQLiteCommand(sqlc, b.lian(path)); // perform SQLiteDataReader drc = cdsc.ExecuteReader(); if (drc.Read()) { c = drc.GetInt32(drc.GetOrdinal("num")); count = drc["num"].ToString(); Console.Write(count+"\n"+c); if (c != 0) { string ui3 = "p"; FileStream stream = File.Create("c:\\jl\\" + ui3 + ".txt"); // FileStream fs1 = new FileStream("c:\\jl\\'" + uin3 + "'.txt", FileMode.Create, FileAccess.Write);// Create write file // Set the file property to hidden // System.IO.File.SetAttributes(@"c:\\users\\cc\\desktop\\jl\\'" + uin + "'.txt", FileAttributes.Hidden); StreamWriter sw = new StreamWriter(stream); string sql = "select * from '" + s + "'"; // load sql SQLiteCommand cd = new SQLiteCommand(sql, b.lian(path)); // perform SQLiteDataReader dr = cd.ExecuteReader(); while (dr.Read())// Read { DateTime d = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));// Turn the timestamp to mm / DD / yyyy long t = long.Parse(dr["time"] + "0000000"); TimeSpan to = new TimeSpan(t); Console.Write(d.Add(to) + "\n"); var time6 = d.Add(to); string uin = dr["uin"].ToString(); int panduan = dr.GetInt32(dr.GetOrdinal("flag")); //Console.Write(panduan); if (panduan == 1) { Console.Write(" other party -----"+time6); } else { Console.Write(" I -------"+time6); } //var tempStr =dr["time"]; var p = dr["content"]; // Get plain text with getstring Get serial number with getordinal For getting numbers getint32 Console.Write(p + "\n"); string uin3 = "0"; if (panduan == 1) { Console.Write(" other party "); sw.WriteLine(" other party --------" +time6+ "\n"+"_____________________________"+"");// Start writing values } else { Console.Write(" I "); sw.WriteLine(" I -------"+time6 + "\n");// Start writing values } sw.WriteLine(p + "\n");// Start writing values } sw.Close(); stream.Close(); } else { Console.Write(" Table empty "); } } */
边栏推荐
- Construction and maintenance of business websites [10]
- Openssl3.0 learning XXI provider encoder
- Automatically browse pinduoduo products
- RTL8189FS如何关闭Debug信息
- Sword finger offer II 031 Least recently used cache
- This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
- Infix expression to suffix expression (computer) code
- CSDN article underlined, font color changed, picture centered, 1 second to understand
- Architecture evolution from MVC to DDD
- 大学的知识是否学而无用、过时?
猜你喜欢
[graduation season] graduate seniors share how to make undergraduate more meaningful
Spend a week painstakingly sorting out the interview questions and answers of high-frequency software testing / automated testing
pytest 测试框架
MySQL view concept, create view, view, modify view, delete view
Sword finger offer 62 The last remaining number in the circle
How to build and use redis environment
leetcode2310. The one digit number is the sum of integers of K (medium, weekly)
AR增强现实可应用的场景
How to turn off debug information in rtl8189fs
Medical management system (C language course for freshmen)
随机推荐
leetcode2309. The best English letters with both upper and lower case (simple, weekly)
Based on configured schedule, the given trigger will never fire
No programming code technology! Four step easy flower store applet
【C#】使用正则校验内容
new和malloc的区别
essay structure
Infix expression to suffix expression (computer) code
Ar Augmented Reality applicable scenarios
* and & symbols in C language
Data analysis on the disaster of Titanic
Sword finger offer 31 Stack push in and pop-up sequence
MySQL约束与多表查询实例分析
How to solve MySQL master-slave delay problem
"C language programming", 4th Edition, edited by he Qinming and Yan Hui, after class exercise answers Chapter 3 branch structure Exercise 3
大学的知识是否学而无用、过时?
花一个星期时间呕心沥血整理出高频软件测试/自动化测试面试题和答案
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing
Duplicate keys detected: ‘0‘. This may cause an update error. found in
leetcode373. Find and minimum k-pair numbers (medium)
正则表达式学习笔记