当前位置:网站首页>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 "); } } */
边栏推荐
- The concept, function, characteristics, creation and deletion of MySQL constraints
- new和malloc的区别
- flutter 中间一个元素,最右边一个元素
- leetcode2309. 兼具大小写的最好英文字母(简单,周赛)
- essay structure
- Pytest testing framework
- 剑指 Offer 62. 圆圈中最后剩下的数字
- 大厂裁员潮不断,双非本科出身的我却逆风翻盘挺进阿里
- Decipher the AI black technology behind sports: figure skating action recognition, multi-mode video classification and wonderful clip editing
- A quick understanding of analog electricity
猜你喜欢

花一个星期时间呕心沥血整理出高频软件测试/自动化测试面试题和答案

What are the necessary things for students to start school? Ranking list of Bluetooth headsets with good sound quality

leetcode2312. 卖木头块(困难,周赛)

A quick understanding of digital electricity

剑指 Offer 62. 圆圈中最后剩下的数字

医药管理系统(大一下C语言课设)

Five skills of adding audio codec to embedded system

Comparative analysis of MVC, MVP and MVVM, source code analysis

【视频】马尔可夫链蒙特卡罗方法MCMC原理与R语言实现|数据分享

Opengauss database backup and recovery guide
随机推荐
[C #] use regular verification content
"C language programming", 4th Edition, edited by he Qinming and Yan Hui, after class exercise answers Chapter 3 branch structure Exercise 3
Sword finger offer 47 Maximum value of gifts
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
软件开发生命周期 --瀑布模型
Design and implementation of key value storage engine based on LSM tree
【OpenCV】-5种图像滤波的综合示例
MySQL中一条SQL是怎么执行的
Flutter un élément au milieu, l'élément le plus à droite
Start from scratch - Web Host - 01
leetcode2305. Fair distribution of biscuits (medium, weekly, shaped pressure DP)
As a software testing engineer, will you choose the bank post? Laolao bank test post
The wave of layoffs in big factories continues, but I, who was born in both non undergraduate schools, turned against the wind and entered Alibaba
2022 Q2 - résumé des compétences pour améliorer les compétences
MySQL如何解决delete大量数据后空间不释放的问题
Duplicate keys detected: ‘0‘. This may cause an update error. found in
oracle创建只读权限的用户简单四步走
Construction and maintenance of business websites [10]
研发中台拆分过程的一些心得总结
leetcode2312. 卖木头块(困难,周赛)