当前位置:网站首页>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 "); } } */
边栏推荐
- * and & symbols in C language
- [question] - why is optical flow not good for static scenes
- How to turn off debug information in rtl8189fs
- JMeter (I) - download, installation and plug-in management
- Construction and maintenance of business websites [12]
- 跨域?同源?一次搞懂什么是跨域
- MySQL约束与多表查询实例分析
- Bash bounce shell encoding
- Calculation (computer) code of suffix expression
- SQLite 3 of embedded database
猜你喜欢

The concept, function, characteristics, creation and deletion of MySQL constraints

MySQL constraints and multi table query example analysis

How to solve MySQL master-slave delay problem

Architecture evolution from MVC to DDD

How to turn off debug information in rtl8189fs

leetcode2310. The one digit number is the sum of integers of K (medium, weekly)

leetcode2309. 兼具大小写的最好英文字母(简单,周赛)

A quick understanding of analog electricity

MySQL view concept, create view, view, modify view, delete view

OpenCASCADE7.6编译
随机推荐
【带你学c带你飞】3day第2章 用C语言编写程序(练习 2.3 计算分段函数)
Software No.1
How to hide the scroll bar of scroll view in uniapp
Construction and maintenance of business websites [13]
附加:信息脱敏;
牛客网——华为题库(51~60)
Architecture evolution from MVC to DDD
2022 Q2 - 提升技能的技巧总结
A quick understanding of analog electricity
CSDN insertion directory in 1 second
As a software testing engineer, will you choose the bank post? Laolao bank test post
[C #] use regular verification content
No programming code technology! Four step easy flower store applet
Sword finger offer 42 Maximum sum of continuous subarrays
【毕业季】研究生学长分享怎样让本科更有意义
734. Energy stone (greed, backpack)
RTL8189FS如何关闭Debug信息
The concepts and differences between MySQL stored procedures and stored functions, as well as how to create them, the role of delimiter, the viewing, modification, deletion of stored procedures and fu
Medical management system (C language course for freshmen)
Sword finger offer II 031 Least recently used cache