/// <summary> /// 检查是否为第一次使用和是否有id记录 /// </summary> /// <returns></returns> public void checkUserId() { bool isUserIdRec = false; SqlLiteConn conn = new SqlLiteConn(); DataTable dt = conn.GetSchema(); if (dt.Rows.Count > 0) { //是否有记录 SQLiteParameter[] pars = new SQLiteParameter[] { new SQLiteParameter("", "") }; string sql = "select count() from user where id >0"; SQLiteDataReader r = conn.ExecuteReader(sql, pars); if (r.Read() && (r.GetInt32(0) > 0)) { r.Close(); isUserIdRec = true; } else { isUserIdRec = false; } } else { //空数据库初始化 string sql = @" DROP TABLE IF EXISTS 'main'.'user'; CREATE TABLE 'user' ( 'id' INTEGER NOT NULL, 'userid' INTEGER, 'username' TEXT NOT NULL, 'userpassword' TEXT NOT NULL, 'moni' REAL, PRIMARY KEY ('id') );"; conn.ExecuteNonQuery(sql); } if (!isUserIdRec) { login loginform = new login(); loginform.Show(); } }
private void button_userManage_Click(object sender, EventArgs e) { login loginform = new login(); loginform.Show(); }