| | |
| | | class SQLiteDataBaseUtil |
| | | { |
| | | |
| | | public SQLiteConnection getConnection() { |
| | | return new SQLiteConnection("Data Source=BKZ;Version=3;"); |
| | | } |
| | | |
| | | SQLiteConnection con; |
| | | private static SQLiteDataBaseUtil instance; |
| | | public static SQLiteDataBaseUtil getInstance() { |
| | |
| | | } |
| | | |
| | | |
| | | public void execUpdate(String sql) { |
| | | con.Open(); |
| | | SQLiteCommand command = new SQLiteCommand(sql, con); |
| | | command.ExecuteNonQuery(); |
| | | con.Close(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /* |
| | | * |
| | |
| | | */ |
| | | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | |
| | | //掉线 |
| | | 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); |
| | |
| | | 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) { |
| | |
| | | |
| | | |
| | | 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); |
| | |
| | | //添加账户 |
| | | 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); |
| | |
| | | //删除账户 |
| | | 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); |
| | |
| | | //查询账户 |
| | | 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); |
| | |
| | | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | //删除账户 |
| | | public void DeleteConfig(String key) |
| | | { |
| | | SQLiteConnection con = getConnection(); |
| | | con.Open(); |
| | | string sql = "delete from config where `key`='" + key + "'"; |
| | | SQLiteCommand command = new SQLiteCommand(sql, con); |
| | |
| | | //查询账户 |
| | | public Config GetConfig(String key) |
| | | { |
| | | SQLiteConnection con = getConnection(); |
| | | con.Open(); |
| | | string sql = "select * from config where `key`='"+ key + "'"; |
| | | SQLiteCommand command = new SQLiteCommand(sql, con); |