From 924bdf1c9fb74babf2438d5545db3594756625d1 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 22 六月 2020 20:06:39 +0800
Subject: [PATCH] '完善信息'

---
 WindowsFormsApp1/utils/SQLiteDataBaseUtil.cs |   46 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/WindowsFormsApp1/utils/SQLiteDataBaseUtil.cs b/WindowsFormsApp1/utils/SQLiteDataBaseUtil.cs
index 2517418..c3e1dfe 100644
--- a/WindowsFormsApp1/utils/SQLiteDataBaseUtil.cs
+++ b/WindowsFormsApp1/utils/SQLiteDataBaseUtil.cs
@@ -13,6 +13,10 @@
     class SQLiteDataBaseUtil
     {
 
+        public SQLiteConnection getConnection() {
+            return new SQLiteConnection("Data Source=BKZ;Version=3;");
+        }
+
         SQLiteConnection con;
         private static SQLiteDataBaseUtil instance;
         public static SQLiteDataBaseUtil getInstance() {
@@ -35,6 +39,16 @@
         }
 
 
+        public void execUpdate(String sql) {
+            con.Open();
+            SQLiteCommand command = new SQLiteCommand(sql, con);
+            command.ExecuteNonQuery();
+            con.Close();
+        }
+
+ 
+
+
 
         /*
          * 
@@ -43,7 +57,7 @@
          */
 
         private void CreateTBAccountTable() {
-            this.con = new SQLiteConnection("Data Source=record.sqlite;Version=3;");
+            SQLiteConnection con = getConnection();
             con.Open();
             string sql = "CREATE TABLE  IF NOT EXISTS tb_account_info (`index` int, accountName varchar(256), tbUid varchar(128), loginState int)";
             SQLiteCommand command = new SQLiteCommand(sql, con);
@@ -56,6 +70,7 @@
             List<TBAccountLogin> list= GetByTBUid(account.TbUid);
             if (list != null && list.Count > 0)
                 return;
+            SQLiteConnection con = getConnection();
             con.Open();
             string sql = "insert into tb_account_info (`index`,accountName, tbUid,loginState) values ("+ account .Index+ ", '"+ account .NickName+ "',"+account.TbUid+", "+(account.Login?1:0)+")";
             SQLiteCommand command = new SQLiteCommand(sql, con);
@@ -65,6 +80,7 @@
 
         //鎺夌嚎
         public void TBOffLine(int index) {
+            SQLiteConnection con= getConnection();
             con.Open();
             string sql = "update tb_account_info set loginState=0 where `index`=" + index;
             SQLiteCommand command = new SQLiteCommand(sql, con);
@@ -72,20 +88,28 @@
             con.Close();
         }
 
-        //涓婄嚎
-        public void TBOnLine(TBAccountLogin account) {
-            AddTaoBaoAccount(account);
+
+        public void TBDelete(int index)
+        {
+            SQLiteConnection con = getConnection();
             con.Open();
-            string sql = "update tb_account_info set loginState=1 where tbUid=" + account.TbUid;
+            string sql = "delete from tb_account_info  where `index`=" + index;
             SQLiteCommand command = new SQLiteCommand(sql, con);
             command.ExecuteNonQuery();
             con.Close();
+        }
+
+        //涓婄嚎
+        public void TBOnLine(TBAccountLogin account) {
+            TBDelete(account.Index);
+            AddTaoBaoAccount(account);
         }
 
 
         //鏍规嵁娣樺疂UID鏌ヨ
         public List<TBAccountLogin> GetByTBUid(String tbUid) {
             List<TBAccountLogin> list = new List<TBAccountLogin>();
+            SQLiteConnection con = getConnection();
             con.Open();
             string sql = "select * from tb_account_info where tbUid="+tbUid;
             if (tbUid == null) {
@@ -113,7 +137,7 @@
 
 
         private void CreateLoginTable() {
-            this.con = new SQLiteConnection("Data Source=record.sqlite;Version=3;");
+            SQLiteConnection con = getConnection();
             con.Open();
             string sql = "CREATE TABLE  IF NOT EXISTS account_info (`account` varchar(256) PRIMARY KEY, `token` varchar(256), expireTime varchar(64),login_state int)";
             SQLiteCommand command = new SQLiteCommand(sql, con);
@@ -125,7 +149,7 @@
         //娣诲姞璐︽埛
         public void AddAccount(UserInfo userInfo) {
             DeleteByAccount(userInfo.Account);
-            this.con = new SQLiteConnection("Data Source=record.sqlite;Version=3;");
+            SQLiteConnection con = getConnection();
             con.Open();
             string sql = "insert into  account_info(`account`,`token`,expireTime,login_state) values('" + userInfo.Account+ "','"+ userInfo.Token+ "','"+ TimeUtil.GetGeneralTime(userInfo.SdljShareExpireTime,"yyyyMMdd HH:mm:ss")+ "',1)";
             SQLiteCommand command = new SQLiteCommand(sql, con);
@@ -136,6 +160,7 @@
         //鍒犻櫎璐︽埛
         public void DeleteByAccount(String account)
         {
+            SQLiteConnection con = getConnection();
             con.Open();
             string sql = "delete from account_info where `account`='" + account + "'";
             SQLiteCommand command = new SQLiteCommand(sql, con);
@@ -146,6 +171,7 @@
         //鏌ヨ璐︽埛
         public UserInfo GetLoginAccount()
         {
+            SQLiteConnection con = getConnection();
             con.Open();
             string sql = "select * from account_info where login_state=1 limit 1";
             SQLiteCommand command = new SQLiteCommand(sql, con);
@@ -174,7 +200,7 @@
 
         private void CreateConfigTable()
         {
-            this.con = new SQLiteConnection("Data Source=record.sqlite;Version=3;");
+            SQLiteConnection con = getConnection();
             con.Open();
             string sql = "CREATE TABLE  IF NOT EXISTS config (`key` varchar(256) PRIMARY KEY, `value` varchar(256))";
             SQLiteCommand command = new SQLiteCommand(sql, con);
@@ -187,7 +213,7 @@
         public void AddConfig(Config config)
         {
             DeleteConfig(config.Key);
-            this.con = new SQLiteConnection("Data Source=record.sqlite;Version=3;");
+            SQLiteConnection con = getConnection();
             con.Open();
             string sql = "insert into  config(`key`,`value`) values('" + config.Key + "','" + config.Value + "')";
             SQLiteCommand command = new SQLiteCommand(sql, con);
@@ -198,6 +224,7 @@
         //鍒犻櫎璐︽埛
         public void DeleteConfig(String key)
         {
+            SQLiteConnection con = getConnection();
             con.Open();
             string sql = "delete from config where `key`='" + key + "'";
             SQLiteCommand command = new SQLiteCommand(sql, con);
@@ -208,6 +235,7 @@
         //鏌ヨ璐︽埛
         public Config GetConfig(String key)
         {
+            SQLiteConnection con = getConnection();
             con.Open();
             string sql = "select * from config where `key`='"+ key + "'";
             SQLiteCommand command = new SQLiteCommand(sql, con);

--
Gitblit v1.8.0