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 |  234 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 216 insertions(+), 18 deletions(-)

diff --git a/WindowsFormsApp1/utils/SQLiteDataBaseUtil.cs b/WindowsFormsApp1/utils/SQLiteDataBaseUtil.cs
index 3e7c7dc..c3e1dfe 100644
--- a/WindowsFormsApp1/utils/SQLiteDataBaseUtil.cs
+++ b/WindowsFormsApp1/utils/SQLiteDataBaseUtil.cs
@@ -5,16 +5,19 @@
 using System.Threading.Tasks;
 using System.Data.SQLite;
 using System.Windows.Forms;
+using WindowsFormsApp1.entity.tb;
+using WindowsFormsApp1.entity;
 
 namespace WindowsFormsApp1.utils
 {
     class SQLiteDataBaseUtil
     {
 
+        public SQLiteConnection getConnection() {
+            return new SQLiteConnection("Data Source=BKZ;Version=3;");
+        }
+
         SQLiteConnection con;
-
-
-
         private static SQLiteDataBaseUtil instance;
         public static SQLiteDataBaseUtil getInstance() {
             if (instance == null)
@@ -30,41 +33,236 @@
 
         //鍒濆鍖栨暟鎹簱
         private void init() {
-            this.con = new SQLiteConnection("Data Source=record.sqlite;Version=3;");
+            CreateTBAccountTable();
+            CreateLoginTable();
+            CreateConfigTable();
+        }
+
+
+        public void execUpdate(String sql) {
             con.Open();
-            string sql = "CREATE TABLE  IF NOT EXISTS tb_account_info (accountName varchar(128), loginState int)";
+            SQLiteCommand command = new SQLiteCommand(sql, con);
+            command.ExecuteNonQuery();
+            con.Close();
+        }
+
+ 
+
+
+
+        /*
+         * 
+         * 娣樺疂璐﹀彿绠$悊
+         * 
+         */
+
+        private void CreateTBAccountTable() {
+            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);
             command.ExecuteNonQuery();
             con.Close();
         }
 
         //娣诲姞鏈湴娣樺疂璐﹀彿
-        public void AddTaoBaoAccount() {
+        public void AddTaoBaoAccount(TBAccountLogin account) {
+            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 (accountName, loginState) values ('璐哄皬杈�1011', 1)";
+            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);
             command.ExecuteNonQuery();
             con.Close();
         }
 
-        //鏌ヨ娣樺疂璐﹀彿
-
-
-        public void ListTaoBaoAccount() {
+        //鎺夌嚎
+        public void TBOffLine(int index) {
+            SQLiteConnection con= getConnection();
             con.Open();
-            string sql = "select * from tb_account_info";
+            string sql = "update tb_account_info set loginState=0 where `index`=" + index;
             SQLiteCommand command = new SQLiteCommand(sql, con);
-            SQLiteDataReader reader = command.ExecuteReader();
-            while (reader.Read())
-                Console.WriteLine("accountName: " + reader["accountName"] + "\n loginState: " + reader["loginState"]);
-            Console.ReadLine();
+            command.ExecuteNonQuery();
             con.Close();
         }
 
 
-        //鍒犻櫎娣樺疂璐﹀彿
+        public void TBDelete(int index)
+        {
+            SQLiteConnection con = getConnection();
+            con.Open();
+            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) {
+                sql = "select * from tb_account_info";
+            }
+            SQLiteCommand command = new SQLiteCommand(sql, con);
+            SQLiteDataReader reader = command.ExecuteReader();
+            while (reader.Read()) {
+                TBAccountLogin account = new TBAccountLogin();
+                account.NickName = reader["accountName"].ToString();
+                account.Login = Convert.ToInt32(reader["loginState"]) == 1 ? true : false;
+                account.TbUid = reader["tbUid"].ToString();
+                account.Index =Convert.ToInt32(reader["index"].ToString());
+                list.Add(account);
+            }
+            con.Close();
+            return list;
+        }
+
+        /**
+         * 
+         * 鐧诲綍璐﹀彿绠$悊
+         * 
+         */
+
+
+        private void CreateLoginTable() {
+            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);
+            command.ExecuteNonQuery();
+            con.Close();
+        }
+
+
+        //娣诲姞璐︽埛
+        public void AddAccount(UserInfo userInfo) {
+            DeleteByAccount(userInfo.Account);
+            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);
+            command.ExecuteNonQuery();
+            con.Close();
+        }
+
+        //鍒犻櫎璐︽埛
+        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);
+            command.ExecuteNonQuery();
+            con.Close();
+        }
+
+        //鏌ヨ璐︽埛
+        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);
+            SQLiteDataReader reader = command.ExecuteReader();
+            UserInfo user = new UserInfo();
+            if (reader.Read())
+            {
+                user.Account = reader["account"].ToString();
+                user.Token = reader["token"].ToString();
+               // user.SdljShareExpireTime =new DateTime( reader["expireTime"].ToString());
+            }
+            else {
+                user = null;
+            }
+            reader.Close();
+            con.Close();
+            return user;
+        }
+
+        /*
+         *
+         *绯荤粺閰嶇疆鍙傛暟
+         * 
+         */
+
+
+        private void CreateConfigTable()
+        {
+            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);
+            command.ExecuteNonQuery();
+            con.Close();
+        }
+
+
+        //娣诲姞璐︽埛
+        public void AddConfig(Config config)
+        {
+            DeleteConfig(config.Key);
+            SQLiteConnection con = getConnection();
+            con.Open();
+            string sql = "insert into  config(`key`,`value`) values('" + config.Key + "','" + config.Value + "')";
+            SQLiteCommand command = new SQLiteCommand(sql, con);
+            command.ExecuteNonQuery();
+            con.Close();
+        }
+
+        //鍒犻櫎璐︽埛
+        public void DeleteConfig(String key)
+        {
+            SQLiteConnection con = getConnection();
+            con.Open();
+            string sql = "delete from config where `key`='" + key + "'";
+            SQLiteCommand command = new SQLiteCommand(sql, con);
+            command.ExecuteNonQuery();
+            con.Close();
+        }
+
+        //鏌ヨ璐︽埛
+        public Config GetConfig(String key)
+        {
+            SQLiteConnection con = getConnection();
+            con.Open();
+            string sql = "select * from config where `key`='"+ key + "'";
+            SQLiteCommand command = new SQLiteCommand(sql, con);
+            SQLiteDataReader reader = command.ExecuteReader();
+            Config config = new Config();
+            if (reader.Read())
+            {
+                config.Key = reader["key"].ToString();
+                config.Value = reader["value"].ToString();
+            }
+            else
+            {
+                config = null;
+            }
+            reader.Close();
+            con.Close();
+            return config;
+        }
+
+
+
+
+
+
+
+
+
 
 
 

--
Gitblit v1.8.0