欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python+mysql實現(xiàn)個人論文管理系統(tǒng)

 更新時間:2019年10月25日 11:02:11   作者:YONGYI~WISE  
這篇文章主要為大家詳細介紹了python+mysql實現(xiàn)個人論文管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了python mysql個人論文管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

1.mysql數(shù)據(jù)庫建表

在mysql數(shù)據(jù)庫里面建立兩個表,分別是用戶表和論文表。建表的方式有很多,可以直接用sql語句進行建表,也可以在Navicat里面直接建,在Navicat里面可以清楚的看到我們建表的類型和表中的數(shù)據(jù)。

上圖是用戶表的數(shù)據(jù)類型

上圖是論文表的數(shù)據(jù)類型

上圖是論文表的樣例

上圖是用戶表的樣例

2.流程實現(xiàn)展示

本次系統(tǒng)的實現(xiàn)主要用到python的pymysql庫來連接mysql數(shù)據(jù)庫,用wxpython庫來實現(xiàn)可視化界面,通過自己定義的db.py的類庫來實現(xiàn)對數(shù)據(jù)庫的增刪改查等基本的功能。主體的程序主要用到類的繼承來實現(xiàn)整個流程。

1.登錄界面展示

2.管理員權(quán)限進入系統(tǒng)展示

3.普通用戶進入系統(tǒng)展示

3.代碼展示

db.py

#導(dǎo)入pymysql模塊
import pymysql

#創(chuàng)建數(shù)據(jù)庫操作類
class Sql_operation(object):
 '''
 數(shù)據(jù)庫操作
 '''
 #用構(gòu)造函數(shù)實現(xiàn)數(shù)據(jù)庫連接,并引入mydb參數(shù),實現(xiàn)調(diào)用不同的數(shù)據(jù)庫
 def __init__(self,mydb): 
 #實例變量
 self.mydb = mydb
 #打開數(shù)據(jù)庫連接
 self.db = pymysql.connect(host = "localhost",user = "root",password = "123698745",db = self.mydb,charset = "utf8")
 #創(chuàng)建游標對象
 self.cursor = self.db.cursor()
 
 #定義查看數(shù)據(jù)表信息函數(shù),并引入table_field、table_name參數(shù),實現(xiàn)查看不同數(shù)據(jù)表的建表語句
 def FindAll(self,table_name):
 #實例變量
 self.table_name = table_name
 #定義SQL語句
 sql = "select * from %s"%(self.table_name)
 try:
 #執(zhí)行數(shù)據(jù)庫操作
 self.cursor.execute(sql)
 #處理結(jié)果
 data = self.cursor.fetchall()
 return data 
 except Exception as err:
 print("SQL執(zhí)行錯誤,原因:",err)

 #定義添加表數(shù)據(jù)函數(shù)
 def InsertUser(self,user_name,user_password):
 id = 2
 self.user_name = user_name
 self.user_password = user_password
 
 sql = "insert into users(id,user_name,user_password)values('%s','%s','%s')"%(int(id),self.user_name,self.user_password)
 try:
 #執(zhí)行數(shù)據(jù)庫操作
 self.cursor.execute(sql)
 #事務(wù)提交
 self.db.commit()
 except Exception as err:
 #事務(wù)回滾
 self.db.rollback()
 print("SQL執(zhí)行錯誤,原因:",err)
 def Insert(self,stu_name,stu_gender,stu_age,stu_cid,stu_classid,stu_phone,stu_id):
 #實例變量
 self.stu_name = stu_name
 self.stu_gender = stu_gender
 self.stu_age = stu_age
 self.stu_cid = stu_cid
 self.stu_classid = stu_classid
 self.stu_phone = stu_phone
 self.stu_id = stu_id
 #定義SQL語句
 sql = "insert into Paper(Papername,author,date,keyword,abstract,journal,id) values('%s','%s','%s','%s','%s','%s','%d')"%(self.stu_name,self.stu_gender,self.stu_age,self.stu_cid,self.stu_classid,self.stu_phone,int(self.stu_id))
 try:
 #執(zhí)行數(shù)據(jù)庫操作
 self.cursor.execute(sql)
 #事務(wù)提交
 self.db.commit()
 except Exception as err:
 #事務(wù)回滾
 self.db.rollback()
 print("SQL執(zhí)行錯誤,原因:",err)

 #定義刪除表數(shù)據(jù)函數(shù)
 def Del(self,stu_id):
 #實例變量
 self.stu_id = stu_id
 #定義SQL語句
 sql = "delete from Paper where id=%d"%(self.stu_id)
 try:
 #執(zhí)行數(shù)據(jù)庫操作
 self.cursor.execute(sql)
 #事務(wù)提交
 self.db.commit()
 except Exception as err:
 #事務(wù)回滾
 self.db.rollback()
 print("SQL執(zhí)行錯誤,原因:",err)
 
 #定義修改表數(shù)據(jù)函數(shù)
 def Update(self,id,amend_name,amend_value):
 self.id = id
 self.amend_name = amend_name
 self.amend_value = amend_value
 
 sql = "update Paper set %s=%s where id=%d"%(self.amend_name,self.amend_value,int(self.id)) 
 
 try:
 #執(zhí)行數(shù)據(jù)庫操作
 self.cursor.execute(sql)
 #事務(wù)提交
 self.db.commit()
 except Exception as err:
 #事務(wù)回滾
 self.db.rollback()
 print("SQL執(zhí)行錯誤,原因:",err)
 #用析構(gòu)函數(shù)實現(xiàn)數(shù)據(jù)庫關(guān)閉
 def __del__(self):
 #關(guān)閉數(shù)據(jù)庫連接
 self.db.close()

main2.py

#導(dǎo)入wx模塊
import wx
import wx.grid
from db import Sql_operation
import os
#import pymysql


class UserLogin(wx.Frame):
 
 #初始化登錄界面
 def __init__(self,*args,**kw):
 # ensure the parent's __init__ is called
 super(UserLogin,self).__init__(*args, **kw)
 #設(shè)置窗口屏幕居中
 self.Center()
 #創(chuàng)建窗口
 self.pnl = wx.Panel(self)
 #調(diào)用登錄界面函數(shù)
 self.LoginInterface()

 def LoginInterface(self):
 #創(chuàng)建垂直方向box布局管理器
 vbox = wx.BoxSizer(wx.VERTICAL)
 #################################################################################
 #創(chuàng)建logo靜態(tài)文本,設(shè)置字體屬性
 logo = wx.StaticText(self.pnl,label="論文管理系統(tǒng)")
 font = logo.GetFont()
 font.PointSize += 30
 font = font.Bold()
 logo.SetFont(font)
 #添加logo靜態(tài)文本到vbox布局管理器
 vbox.Add(logo,proportion=0,flag=wx.FIXED_MINSIZE | wx.TOP | wx.CENTER,border=180)
 #################################################################################
 #創(chuàng)建靜態(tài)框
 sb_username = wx.StaticBox(self.pnl,label="用戶名")
 sb_password = wx.StaticBox(self.pnl,label="密 碼") 
 #創(chuàng)建水平方向box布局管理器
 hsbox_username = wx.StaticBoxSizer(sb_username,wx.HORIZONTAL)
 hsbox_password = wx.StaticBoxSizer(sb_password,wx.HORIZONTAL)
 #創(chuàng)建用戶名、密碼輸入框
 self.user_name = wx.TextCtrl(self.pnl,size=(210,25))
 self.user_password = wx.TextCtrl(self.pnl,size=(210,25))
 #添加用戶名和密碼輸入框到hsbox布局管理器
 hsbox_username.Add(self.user_name,0,wx.EXPAND | wx.BOTTOM,5)
 hsbox_password.Add(self.user_password,0,wx.EXPAND | wx.BOTTOM,5)
 #將水平box添加到垂直box
 vbox.Add(hsbox_username,proportion=0,flag=wx.CENTER)
 vbox.Add(hsbox_password,proportion=0,flag=wx.CENTER)
 #################################################################################
 #創(chuàng)建水平方向box布局管理器
 hbox = wx.BoxSizer()
 #創(chuàng)建登錄按鈕、綁定事件處理
 login_button = wx.Button(self.pnl,label="登錄",size=(80,25))
 regis_button = wx.Button(self.pnl,label="注冊",size=(80,25))
 login_button.Bind(wx.EVT_BUTTON,self.LoginButton)
 regis_button.Bind(wx.EVT_BUTTON,self.RegisButton)
 #添加登錄按鈕到hbox布局管理器
 hbox.Add(login_button,0,flag=wx.EXPAND | wx.TOP,border=5)
 hbox.Add(regis_button,0,flag=wx.EXPAND | wx.TOP,border=5)
 
 #將水平box添加到垂直box
 vbox.Add(hbox,proportion=0,flag=wx.CENTER)
 #################################################################################
 #設(shè)置面板的布局管理器vbox 
 self.pnl.SetSizer(vbox) 

 def RegisButton(self,event):
 #連接student_db數(shù)據(jù)庫
 op = Sql_operation("student_db")
 user_name = self.user_name.GetValue()
 user_password = self.user_password.GetValue()
 np = op.InsertUser(user_name,user_password)
 print("注冊成功")
 
 def LoginButton(self,event):
 #連接student_db數(shù)據(jù)庫
 op = Sql_operation("student_db")
 #獲取users表中的用戶名和密碼信息,返回為二維元組
 np = op.FindAll("users")
 #匹配標記
 login_sign = 0
 #匹配用戶名和密碼
 for i in np: 
 if (i[1] == self.user_name.GetValue()) and (i[2] == self.user_password.GetValue() and i[0] == 1):
 login_sign = 1
 break
 elif (i[1] == self.user_name.GetValue()) and (i[2] == self.user_password.GetValue() and i[0] == 2):
 login_sign = 2
 break
 if login_sign == 0:
 print("用戶名或密碼錯誤!")
 elif (login_sign) == 1:
 print("登錄成功!") 
 operation = UserOperation(None,title="論文管理系統(tǒng)(管理員)",size=(1024,668))
 operation.Show()
 self.Close(True)
 elif (login_sign) == 2:
 os.system(r"python C:\Users\Administrator\Desktop\Holiday\Paper\main3.py")

class UserOperation(wx.Frame):
 '''
 操作界面
 '''
 def __init__(self,*args,**kw):
 # ensure the parent's __init__ is called
 super(UserOperation,self).__init__(*args, **kw)
 #設(shè)置窗口屏幕居中
 self.Center()
 #創(chuàng)建窗口
 self.pnl = wx.Panel(self)
 #調(diào)用操作界面函數(shù)
 self.OperationInterface()

 def OperationInterface(self):
 #創(chuàng)建垂直方向box布局管理器
 self.vbox = wx.BoxSizer(wx.VERTICAL) 
 #################################################################################
 #創(chuàng)建logo靜態(tài)文本,設(shè)置字體屬性
 logo = wx.StaticText(self.pnl,label="論文管理系統(tǒng)(管理員)")
 font = logo.GetFont()
 font.PointSize += 30
 font = font.Bold()
 logo.SetFont(font)
 #添加logo靜態(tài)文本到vbox布局管理器
 self.vbox.Add(logo,proportion=0,flag=wx.FIXED_MINSIZE | wx.TOP | wx.CENTER,border=5)
 #################################################################################
 #創(chuàng)建靜態(tài)框
 sb_button = wx.StaticBox(self.pnl,label="選擇操作")
 #創(chuàng)建垂直方向box布局管理器
 vsbox_button = wx.StaticBoxSizer(sb_button,wx.VERTICAL)
 #創(chuàng)建操作按鈕、綁定事件處理
 check_button = wx.Button(self.pnl,id=10,label="查看論文信息",size=(150,50))
 add_button = wx.Button(self.pnl,id=11,label="添加論文信息",size=(150,50))
 delete_button = wx.Button(self.pnl,id=12,label="刪除論文信息",size=(150,50))
 update_button = wx.Button(self.pnl,id=13,label="修改論文信息",size=(150,50))
 quit_button = wx.Button(self.pnl,id=14,label="退出系統(tǒng)",size=(150,50))
 self.Bind(wx.EVT_BUTTON,self.ClickButton,id=10,id2=14)
 #添加操作按鈕到vsbox布局管理器
 vsbox_button.Add(check_button,0,wx.EXPAND | wx.BOTTOM,20)
 vsbox_button.Add(add_button,0,wx.EXPAND | wx.BOTTOM,20)
 vsbox_button.Add(delete_button,0,wx.EXPAND | wx.BOTTOM,20)
 vsbox_button.Add(update_button,0,wx.EXPAND | wx.BOTTOM,20)
 vsbox_button.Add(quit_button,0,wx.EXPAND | wx.BOTTOM,20) 
 #創(chuàng)建靜態(tài)框
 sb_show_operation = wx.StaticBox(self.pnl,label="顯示/操作窗口",size=(800,1000))
 #創(chuàng)建垂直方向box布局管理器
 self.vsbox_show_operation = wx.StaticBoxSizer(sb_show_operation,wx.VERTICAL)
 #創(chuàng)建水平方向box布局管理器
 hbox = wx.BoxSizer()
 hbox.Add(vsbox_button,0,wx.EXPAND | wx.BOTTOM,5)
 hbox.Add(self.vsbox_show_operation,0,wx.EXPAND | wx.BOTTOM,5)
 #將hbox添加到垂直box 
 self.vbox.Add(hbox,proportion=0,flag=wx.CENTER) 
 #################################################################################
 self.pnl.SetSizer(self.vbox)

 def ClickButton(self,event):
 source_id = event.GetId()
 if source_id == 10:
 print("查詢操作!")
 inquire_button = InquireOp(None,title="論文管理系統(tǒng)(管理員)",size=(1024,668))
 inquire_button.Show()
 self.Close(True) 
 elif source_id == 11:
 print("添加操作!")
 add_button = AddOp(None,title="論文管理系統(tǒng)(管理員)",size=(1024,668))
 add_button.Show()
 self.Close(True) 
 elif source_id == 12:
 print("刪除操作!")
 del_button = DelOp(None,title="論文管理系統(tǒng)(管理員)",size=(1024,668))
 del_button.Show()
 self.Close(True) 
 elif source_id == 13:
 print("修改操作!")
 del_button = UpdOp(None,title="論文管理系統(tǒng)(管理員)",size=(1024,668))
 del_button.Show()
 self.Close(True)
 elif source_id == 14:
 self.Close(True)

#繼承UserOperation類,實現(xiàn)初始化操作界面
class InquireOp(UserOperation):
#class InquireOp(InquireOp):
 def __init__(self,*args,**kw):
 # ensure the parent's __init__ is called
 super(InquireOp,self).__init__(*args, **kw)
 #創(chuàng)建論文列表信息網(wǎng)格
 self.stu_grid = self.CreateGrid()
 self.stu_grid.Bind(wx.grid.EVT_GRID_LABEL_LEFT_CLICK,self.OnLabelleftClick)
 #添加到vsbox_show_operation布局管理器
 self.vsbox_show_operation.Add(self.stu_grid,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,30) 

 def ClickButton(self,event):
 source_id = event.GetId()
 if source_id == 10:
 pass 
 elif source_id == 11:
 print("添加操作!")
 add_button = AddOp(None,title="論文管理系統(tǒng)(管理員)",size=(1024,668))
 add_button.Show()
 self.Close(True) 
 elif source_id == 12:
 print("刪除操作!")
 del_button = DelOp(None,title="論文管理系統(tǒng)(管理員)",size=(1024,668))
 del_button.Show()
 self.Close(True)
 elif source_id == 13:
 print("修改操作!")
 del_button = UpdOp(None,title="論文管理系統(tǒng)(管理員)",size=(1024,668))
 del_button.Show()
 self.Close(True)
 elif source_id == 14:
 self.Close(True)

 def CreateGrid(self):
 #連接student_db數(shù)據(jù)庫
 op = Sql_operation("student_db")
 #獲取Paper表中的論文信息,返回為二維元組
 np = op.FindAll("Paper")
 column_names = ("Papername","author","date","keyword","abstract","journal")
 stu_grid = wx.grid.Grid(self.pnl)
 stu_grid.CreateGrid(len(np),len(np[0])-1)
 for row in range(len(np)):
 stu_grid.SetRowLabelValue(row,str(np[row][0]))#確保網(wǎng)格序列號與數(shù)據(jù)庫id保持一致
 for col in range(1,len(np[row])):
 stu_grid.SetColLabelValue(col-1,column_names[col-1])
 stu_grid.SetCellValue(row,col-1,str(np[row][col])) 
 stu_grid.AutoSize()
 return stu_grid

 def OnLabelleftClick(self,event):
 #連接student_db數(shù)據(jù)庫
 op = Sql_operation("student_db")
 #獲取users表中的用戶名和密碼信息,返回為二維元組
 np = op.FindAll("users")
 print("RowIdx: {0}".format(event.GetRow()))
 print("ColIdx: {0}".format(event.GetRow()))
 print(np[event.GetRow()])
 event.Skip()

#繼承UserOperation類,實現(xiàn)初始化操作界面
class AddOp(UserOperation):
#class AddOp(InquireOp):
 def __init__(self,*args,**kw):
 # ensure the parent's __init__ is called
 super(AddOp,self).__init__(*args, **kw)
 #創(chuàng)建添加論文息輸入框、添加按鈕
 self.id = wx.TextCtrl(self.pnl,size = (210,25))
 self.Papername = wx.TextCtrl(self.pnl,size = (210,25))
 self.author = wx.TextCtrl(self.pnl,size = (210,25))
 self.date = wx.TextCtrl(self.pnl,size = (210,25))
 self.keyword = wx.TextCtrl(self.pnl,size = (210,25))
 self.abstract = wx.TextCtrl(self.pnl,size = (210,25))
 self.journal = wx.TextCtrl(self.pnl,size = (210,25))
 self.add_affirm = wx.Button(self.pnl,label="添加",size=(80,25))
 #為添加按鈕組件綁定事件處理
 self.add_affirm.Bind(wx.EVT_BUTTON,self.AddAffirm)
 #################################################################################
 #創(chuàng)建靜態(tài)框
 sb_id = wx.StaticBox(self.pnl,label="id")
 sb_name = wx.StaticBox(self.pnl,label="Papername")
 sb_gender = wx.StaticBox(self.pnl,label="author")
 sb_age = wx.StaticBox(self.pnl,label="date")
 sb_cid = wx.StaticBox(self.pnl,label="keyword")
 sb_classid = wx.StaticBox(self.pnl,label="abstract")
 sb_phone = wx.StaticBox(self.pnl,label="journal") 
 #創(chuàng)建水平方向box布局管理器
 hsbox_id = wx.StaticBoxSizer(sb_id,wx.HORIZONTAL)
 hsbox_name = wx.StaticBoxSizer(sb_name,wx.HORIZONTAL)
 hsbox_gender = wx.StaticBoxSizer(sb_gender,wx.HORIZONTAL)
 hsbox_age = wx.StaticBoxSizer(sb_age,wx.HORIZONTAL)
 hsbox_cid = wx.StaticBoxSizer(sb_cid,wx.HORIZONTAL)
 hsbox_classid = wx.StaticBoxSizer(sb_classid,wx.HORIZONTAL)
 hsbox_phone = wx.StaticBoxSizer(sb_phone,wx.HORIZONTAL)
 #添加到hsbox布局管理器
 hsbox_id.Add(self.id,0,wx.EXPAND | wx.BOTTOM,5)
 hsbox_name.Add(self.Papername,0,wx.EXPAND | wx.BOTTOM,5)
 hsbox_gender.Add(self.author,0,wx.EXPAND | wx.BOTTOM,5)
 hsbox_age.Add(self.date,0,wx.EXPAND | wx.BOTTOM,5)
 hsbox_cid.Add(self.keyword,0,wx.EXPAND | wx.BOTTOM,5)
 hsbox_classid.Add(self.abstract,0,wx.EXPAND | wx.BOTTOM,5)
 hsbox_phone.Add(self.journal,0,wx.EXPAND | wx.BOTTOM,5)
 #################################################################################
 #添加到vsbox_show_operation布局管理器
 self.vsbox_show_operation.Add(hsbox_id,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(hsbox_name,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(hsbox_gender,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(hsbox_age,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(hsbox_cid,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(hsbox_classid,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(hsbox_phone,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(self.add_affirm,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)

 def ClickButton(self,event):
 source_id = event.GetId()
 if source_id == 10:
 print("查詢操作!")
 inquire_button = InquireOp(None,title="論文管理系統(tǒng)(管理員)",size=(1024,668))
 inquire_button.Show()
 self.Close(True) 
 elif source_id == 11:
 pass 
 elif source_id == 12:
 print("刪除操作!")
 del_button = DelOp(None,title="論文管理系統(tǒng)(管理員)",size=(1024,668))
 del_button.Show()
 self.Close(True)
 elif source_id == 13:
 print("修改操作!")
 del_button = UpdOp(None,title="論文管理系統(tǒng)(管理員)",size=(1024,668))
 del_button.Show()
 self.Close(True)
 elif source_id == 14:
 self.Close(True)

 def AddAffirm(self,event):
 #連接student_db數(shù)據(jù)庫
 op = Sql_operation("student_db")
 #向Paper表添加論文信息
 Papername = self.Papername.GetValue()
 print(Papername)
 author = self.author.GetValue()
 print(author)
 date = self.date.GetValue()
 print(date)
 keyword = self.keyword.GetValue()
 print(keyword)
 abstract = self.abstract.GetValue()
 print(abstract)
 journal = self.journal.GetValue()
 print(journal)
 #np = op.Insert(Papername,author,date,keyword,abstract,journal)
 id = self.id.GetValue()
 print(id)
 np = op.Insert(Papername,author,date,keyword,abstract,journal,id)

#繼承InquireOp類,實現(xiàn)初始化操作界面
class DelOp(InquireOp):
 def __init__(self,*args,**kw):
 # ensure the parent's __init__ is called
 super(DelOp,self).__init__(*args, **kw)
 #創(chuàng)建刪除學員信息輸入框、刪除按鈕
 self.del_id = wx.TextCtrl(self.pnl,pos = (407,78),size = (210,25))
 self.del_affirm = wx.Button(self.pnl,label="刪除",pos=(625,78),size=(80,25))
 #為刪除按鈕組件綁定事件處理
 self.del_affirm.Bind(wx.EVT_BUTTON,self.DelAffirm)
 #################################################################################
 #創(chuàng)建靜態(tài)框
 sb_del = wx.StaticBox(self.pnl,label="請輸入需要刪除的論文的ID")
 #創(chuàng)建水平方向box布局管理器
 hsbox_del = wx.StaticBoxSizer(sb_del,wx.HORIZONTAL)
 #添加到hsbox_name布局管理器
 hsbox_del.Add(self.del_id,0,wx.EXPAND | wx.BOTTOM,5)
 #添加到vsbox_show_operation布局管理器
 self.vsbox_show_operation.Add(hsbox_del,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(self.del_affirm,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)

 def ClickButton(self,event):
 source_id = event.GetId()
 if source_id == 10:
 print("查詢操作!")
 inquire_button = InquireOp(None,title="論文管理系統(tǒng)",size=(1024,668))
 inquire_button.Show()
 self.Close(True) 
 elif source_id == 11:
 print("添加操作!")
 add_button = AddOp(None,title="論文管理系統(tǒng)",size=(1024,668))
 add_button.Show()
 self.Close(True) 
 elif source_id == 12:
 pass
 elif source_id == 13:
 print("修改操作!")
 del_button = UpdOp(None,title="論文管理系統(tǒng)",size=(1024,668))
 del_button.Show()
 self.Close(True)
 elif source_id == 14:
 self.Close(True)

 def DelAffirm(self,event):
 #連接student_db數(shù)據(jù)庫
 op = Sql_operation("student_db")

 del_id = self.del_id.GetValue()
 print(del_id)
 np = op.Del(int(del_id))
 
 del_button = DelOp(None,title="論文管理系統(tǒng)",size=(1024,668))
 del_button.Show()
 self.Close(True)

class UpdOp(InquireOp):
 def __init__(self,*args,**kw):
 # ensure the parent's __init__ is called
 super(UpdOp,self).__init__(*args, **kw)
 #創(chuàng)建添加論文息輸入框、添加按鈕
 self.id = wx.TextCtrl(self.pnl,size = (210,25))
 self.update_name = wx.TextCtrl(self.pnl,size = (210,25))
 self.update_acc = wx.TextCtrl(self.pnl,size = (210,25))
 self.add_affirm = wx.Button(self.pnl,label="確認更新",pos=(550,520),size=(80,25))
 #為添加按鈕組件綁定事件處理
 self.add_affirm.Bind(wx.EVT_BUTTON,self.UpdateAffirm)
 #################################################################################
 #創(chuàng)建靜態(tài)框
 sb_id = wx.StaticBox(self.pnl,label="需要更新的論文id")
 sb_name = wx.StaticBox(self.pnl,label="需要更新的內(nèi)容標題")
 sb_acc = wx.StaticBox(self.pnl,label="更新的內(nèi)容")
 
 #創(chuàng)建水平方向box布局管理器
 hsbox_id = wx.StaticBoxSizer(sb_id,wx.HORIZONTAL)
 hsbox_name = wx.StaticBoxSizer(sb_name,wx.HORIZONTAL)
 hsbox_acc = wx.StaticBoxSizer(sb_acc,wx.HORIZONTAL)
 
 #添加到hsbox布局管理器
 hsbox_id.Add(self.id,0,wx.EXPAND | wx.BOTTOM,5)
 hsbox_name.Add(self.update_name,0,wx.EXPAND | wx.BOTTOM,5)
 hsbox_acc.Add(self.update_acc,0,wx.EXPAND | wx.BOTTOM,5)
 
 #################################################################################
 #添加到vsbox_show_operation布局管理器
 self.vsbox_show_operation.Add(hsbox_id,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(hsbox_name,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(hsbox_acc,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 

 def ClickButton(self,event):
 source_id = event.GetId()
 if source_id == 10:
 print("查詢操作!")
 inquire_button = InquireOp(None,title="論文管理系統(tǒng)(管理員)",size=(1024,668))
 inquire_button.Show()
 self.Close(True) 
 elif source_id == 11:
 pass 
 elif source_id == 12:
 print("刪除操作!")
 del_button = DelOp(None,title="論文管理系統(tǒng)(管理員)",size=(1024,668))
 del_button.Show()
 self.Close(True)
 elif source_id == 13:
 pass
 elif source_id == 14:
 self.Close(True)

 def UpdateAffirm(self,event):
 #連接student_db數(shù)據(jù)庫
 op = Sql_operation("student_db")
 
 update_name = self.update_name.GetValue()
 print(update_name)
 update_acc = self.update_acc.GetValue()
 print(update_acc)
 id = self.id.GetValue()
 print(id)
 np = op.Update(id,update_name,update_acc)
 
if __name__ == '__main__':
 app = wx.App()
 login = UserLogin(None,title="論文管理系統(tǒng)(管理員)",size=(1024,668))
 login.Show()
 app.MainLoop()

main3.py

#導(dǎo)入mx模塊
import wx
import wx.grid
from db import Sql_operation



class UserOperation(wx.Frame):
 '''
 操作界面
 '''
 def __init__(self,*args,**kw):
 # ensure the parent's __init__ is called
 super(UserOperation,self).__init__(*args, **kw)
 #設(shè)置窗口屏幕居中
 self.Center()
 #創(chuàng)建窗口
 self.pnl = wx.Panel(self)
 #調(diào)用操作界面函數(shù)
 self.OperationInterface()

 def OperationInterface(self):
 #創(chuàng)建垂直方向box布局管理器
 self.vbox = wx.BoxSizer(wx.VERTICAL) 
 #################################################################################
 #創(chuàng)建logo靜態(tài)文本,設(shè)置字體屬性
 logo = wx.StaticText(self.pnl,label="論文管理系統(tǒng)(普通用戶)")
 font = logo.GetFont()
 font.PointSize += 30
 font = font.Bold()
 logo.SetFont(font)
 #添加logo靜態(tài)文本到vbox布局管理器
 self.vbox.Add(logo,proportion=0,flag=wx.FIXED_MINSIZE | wx.TOP | wx.CENTER,border=5)
 #################################################################################
 #創(chuàng)建靜態(tài)框
 sb_button = wx.StaticBox(self.pnl,label="選擇操作")
 #創(chuàng)建垂直方向box布局管理器
 vsbox_button = wx.StaticBoxSizer(sb_button,wx.VERTICAL)
 #創(chuàng)建操作按鈕、綁定事件處理
 check_button = wx.Button(self.pnl,id=10,label="查看論文信息",size=(150,50))
 add_button = wx.Button(self.pnl,id=11,label="添加論文信息",size=(150,50))
 #delete_button = wx.Button(self.pnl,id=12,label="刪除論文信息",size=(150,50))
 quit_button = wx.Button(self.pnl,id=13,label="退出系統(tǒng)",size=(150,50))
 self.Bind(wx.EVT_BUTTON,self.ClickButton,id=10,id2=13)
 #添加操作按鈕到vsbox布局管理器
 vsbox_button.Add(check_button,0,wx.EXPAND | wx.BOTTOM,40)
 vsbox_button.Add(add_button,0,wx.EXPAND | wx.BOTTOM,40)
 #vsbox_button.Add(delete_button,0,wx.EXPAND | wx.BOTTOM,40)
 vsbox_button.Add(quit_button,0,wx.EXPAND | wx.BOTTOM,200) 
 #創(chuàng)建靜態(tài)框
 sb_show_operation = wx.StaticBox(self.pnl,label="顯示/操作窗口",size=(800,800))
 #創(chuàng)建垂直方向box布局管理器
 self.vsbox_show_operation = wx.StaticBoxSizer(sb_show_operation,wx.VERTICAL)
 #創(chuàng)建水平方向box布局管理器
 hbox = wx.BoxSizer()
 hbox.Add(vsbox_button,0,wx.EXPAND | wx.BOTTOM,5)
 hbox.Add(self.vsbox_show_operation,0,wx.EXPAND | wx.BOTTOM,5)
 #將hbox添加到垂直box 
 self.vbox.Add(hbox,proportion=0,flag=wx.CENTER) 
 #################################################################################
 self.pnl.SetSizer(self.vbox)

 def ClickButton(self,event):
 source_id = event.GetId()
 if source_id == 10:
 print("查詢操作!")
 inquire_button = InquireOp(None,title="論文管理系統(tǒng)(普通用戶)",size=(1024,668))
 inquire_button.Show()
 self.Close(True) 
 elif source_id == 11:
 print("添加操作!")
 add_button = AddOp(None,title="論文管理系統(tǒng)(普通用戶)",size=(1024,668))
 add_button.Show()
 self.Close(True) 
 elif source_id == 12:
 print("刪除操作!")
 del_button = DelOp(None,title="論文管理系統(tǒng)(普通用戶)",size=(1024,668))
 del_button.Show()
 self.Close(True) 
 elif source_id == 13:
 self.Close(True)

#繼承UserOperation類,實現(xiàn)初始化操作界面
class InquireOp(UserOperation):
 def __init__(self,*args,**kw):
 # ensure the parent's __init__ is called
 super(InquireOp,self).__init__(*args, **kw)
 #創(chuàng)建論文列表信息網(wǎng)格
 self.stu_grid = self.CreateGrid()
 self.stu_grid.Bind(wx.grid.EVT_GRID_LABEL_LEFT_CLICK,self.OnLabelleftClick)
 #添加到vsbox_show_operation布局管理器
 self.vsbox_show_operation.Add(self.stu_grid,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,30) 

 def ClickButton(self,event):
 source_id = event.GetId()
 if source_id == 10:
 pass 
 elif source_id == 11:
 print("添加操作!")
 add_button = AddOp(None,title="論文管理系統(tǒng)(普通用戶)",size=(1024,668))
 add_button.Show()
 self.Close(True) 
 elif source_id == 12:
 print("刪除操作!")
 del_button = DelOp(None,title="論文管理系統(tǒng)(普通用戶)",size=(1024,668))
 del_button.Show()
 self.Close(True) 
 elif source_id == 13:
 self.Close(True)

 def CreateGrid(self):
 #連接student_db數(shù)據(jù)庫
 op = Sql_operation("student_db")
 #獲取Paper表中的論文信息,返回為二維元組
 np = op.FindAll("Paper")
 column_names = ("Papername","author","date","keyword","abstract","journal")
 stu_grid = wx.grid.Grid(self.pnl)
 stu_grid.CreateGrid(len(np),len(np[0])-1)
 for row in range(len(np)):
 stu_grid.SetRowLabelValue(row,str(np[row][0]))#確保網(wǎng)格序列號與數(shù)據(jù)庫id保持一致
 for col in range(1,len(np[row])):
 stu_grid.SetColLabelValue(col-1,column_names[col-1])
 stu_grid.SetCellValue(row,col-1,str(np[row][col])) 
 stu_grid.AutoSize()
 return stu_grid

 def OnLabelleftClick(self,event):
 #連接student_db數(shù)據(jù)庫
 op = Sql_operation("student_db")
 #獲取users表中的用戶名和密碼信息,返回為二維元組
 np = op.FindAll("users")
 print("RowIdx: {0}".format(event.GetRow()))
 print("ColIdx: {0}".format(event.GetRow()))
 print(np[event.GetRow()])
 event.Skip()

#繼承UserOperation類,實現(xiàn)初始化操作界面
class AddOp(UserOperation):
 def __init__(self,*args,**kw):
 # ensure the parent's __init__ is called
 super(AddOp,self).__init__(*args, **kw)
 #創(chuàng)建添加論文息輸入框、添加按鈕
 self.id = wx.TextCtrl(self.pnl,size = (210,25))
 self.Papername = wx.TextCtrl(self.pnl,size = (210,25))
 self.author = wx.TextCtrl(self.pnl,size = (210,25))
 self.date = wx.TextCtrl(self.pnl,size = (210,25))
 self.keyword = wx.TextCtrl(self.pnl,size = (210,25))
 self.abstract = wx.TextCtrl(self.pnl,size = (210,25))
 self.journal = wx.TextCtrl(self.pnl,size = (210,25))
 self.add_affirm = wx.Button(self.pnl,label="添加",size=(80,25))
 #為添加按鈕組件綁定事件處理
 self.add_affirm.Bind(wx.EVT_BUTTON,self.AddAffirm)
 #################################################################################
 #創(chuàng)建靜態(tài)框
 sb_id = wx.StaticBox(self.pnl,label="id")
 sb_name = wx.StaticBox(self.pnl,label="Papername")
 sb_gender = wx.StaticBox(self.pnl,label="author")
 sb_age = wx.StaticBox(self.pnl,label="date")
 sb_cid = wx.StaticBox(self.pnl,label="keyword")
 sb_classid = wx.StaticBox(self.pnl,label="abstract")
 sb_phone = wx.StaticBox(self.pnl,label="journal") 
 #創(chuàng)建水平方向box布局管理器
 hsbox_id = wx.StaticBoxSizer(sb_id,wx.HORIZONTAL)
 hsbox_name = wx.StaticBoxSizer(sb_name,wx.HORIZONTAL)
 hsbox_gender = wx.StaticBoxSizer(sb_gender,wx.HORIZONTAL)
 hsbox_age = wx.StaticBoxSizer(sb_age,wx.HORIZONTAL)
 hsbox_cid = wx.StaticBoxSizer(sb_cid,wx.HORIZONTAL)
 hsbox_classid = wx.StaticBoxSizer(sb_classid,wx.HORIZONTAL)
 hsbox_phone = wx.StaticBoxSizer(sb_phone,wx.HORIZONTAL)
 #添加到hsbox布局管理器
 hsbox_id.Add(self.id,0,wx.EXPAND | wx.BOTTOM,5)
 hsbox_name.Add(self.Papername,0,wx.EXPAND | wx.BOTTOM,5)
 hsbox_gender.Add(self.author,0,wx.EXPAND | wx.BOTTOM,5)
 hsbox_age.Add(self.date,0,wx.EXPAND | wx.BOTTOM,5)
 hsbox_cid.Add(self.keyword,0,wx.EXPAND | wx.BOTTOM,5)
 hsbox_classid.Add(self.abstract,0,wx.EXPAND | wx.BOTTOM,5)
 hsbox_phone.Add(self.journal,0,wx.EXPAND | wx.BOTTOM,5)
 #################################################################################
 #添加到vsbox_show_operation布局管理器
 self.vsbox_show_operation.Add(hsbox_id,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(hsbox_name,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(hsbox_gender,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(hsbox_age,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(hsbox_cid,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(hsbox_classid,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(hsbox_phone,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 self.vsbox_show_operation.Add(self.add_affirm,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)

 def ClickButton(self,event):
 source_id = event.GetId()
 if source_id == 10:
 print("查詢操作!")
 inquire_button = InquireOp(None,title="論文管理系統(tǒng)(普通用戶)",size=(1024,668))
 inquire_button.Show()
 self.Close(True) 
 elif source_id == 11:
 pass 
 elif source_id == 12:
 print("刪除操作!")
 del_button = DelOp(None,title="論文管理系統(tǒng)(普通用戶)",size=(1024,668))
 del_button.Show()
 self.Close(True) 
 elif source_id == 13:
 self.Close(True)

 def AddAffirm(self,event):
 #連接student_db數(shù)據(jù)庫
 op = Sql_operation("student_db")
 #向Paper表添加論文信息
 Papername = self.Papername.GetValue()
 print(Papername)
 author = self.author.GetValue()
 print(author)
 date = self.date.GetValue()
 print(date)
 keyword = self.keyword.GetValue()
 print(keyword)
 abstract = self.abstract.GetValue()
 print(abstract)
 journal = self.journal.GetValue()
 print(journal)
 #np = op.Insert(Papername,author,date,keyword,abstract,journal)
 id = self.id.GetValue()
 print(id)
 np = op.Insert(Papername,author,date,keyword,abstract,journal,id)

#繼承InquireOp類,實現(xiàn)初始化操作界面
# class DelOp(InquireOp):
 # def __init__(self,*args,**kw):
 # # ensure the parent's __init__ is called
 # super(DelOp,self).__init__(*args, **kw)
 # #創(chuàng)建刪除學員信息輸入框、刪除按鈕
 # self.del_id = wx.TextCtrl(self.pnl,pos = (407,78),size = (210,25))
 # self.del_affirm = wx.Button(self.pnl,label="刪除",pos=(625,78),size=(80,25))
 # #為刪除按鈕組件綁定事件處理
 # self.del_affirm.Bind(wx.EVT_BUTTON,self.DelAffirm)
 # #################################################################################
 # #創(chuàng)建靜態(tài)框
 # sb_del = wx.StaticBox(self.pnl,label="請輸入需要刪除的論文的ID")
 # #創(chuàng)建水平方向box布局管理器
 # hsbox_del = wx.StaticBoxSizer(sb_del,wx.HORIZONTAL)
 # #添加到hsbox_name布局管理器
 # hsbox_del.Add(self.del_id,0,wx.EXPAND | wx.BOTTOM,5)
 # #添加到vsbox_show_operation布局管理器
 # self.vsbox_show_operation.Add(hsbox_del,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)
 # self.vsbox_show_operation.Add(self.del_affirm,0,wx.CENTER | wx.TOP | wx.FIXED_MINSIZE,5)

 # def ClickButton(self,event):
 # source_id = event.GetId()
 # if source_id == 10:
 # print("查詢操作!")
 # inquire_button = InquireOp(None,title="論文管理系統(tǒng)",size=(1024,668))
 # inquire_button.Show()
 # self.Close(True) 
 # elif source_id == 11:
 # print("添加操作!")
 # add_button = AddOp(None,title="論文管理系統(tǒng)",size=(1024,668))
 # add_button.Show()
 # self.Close(True) 
 # elif source_id == 12:
 # pass 
 # elif source_id == 13:
 # self.Close(True)

 # def DelAffirm(self,event):
 # #連接student_db數(shù)據(jù)庫
 # op = Sql_operation("student_db")

 # del_id = self.del_id.GetValue()
 # print(del_id)
 # np = op.Del(int(del_id))
 
 # del_button = DelOp(None,title="論文管理系統(tǒng)",size=(1024,668))
 # del_button.Show()
 # self.Close(True)

if __name__ == '__main__':
 app = wx.App()
 operation = UserOperation(None,title="論文管理系統(tǒng)(普通用戶)",size=(1024,668))
 #login = UserLogin(None,title="論文管理系統(tǒng)",size=(1024,668))
 operation.Show()
 app.MainLoop()

4.總結(jié)

這個小系統(tǒng)其實還有不很多不完善的地方,可視化做的也不是很好,要是用H5來實現(xiàn)可視化的話會更好。

更多學習資料請關(guān)注專題《管理系統(tǒng)開發(fā)》。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論