python: more Layer Architecture and its Implementation in Python

sql server:

--学生表
DROP TABLE DuStudentList
GO
create table DuStudentList
(StudentId INT IDENTITY(1,1) PRIMARY KEY,StudentName nvarchar(50),StudentNO varchar(50),                    --学号StudentBirthday datetime                  --学生生日     )
go

model

"""
StudentListInfo.py
学生类
date 2023-06-16
edit: Geovin Du,geovindu, 涂聚文
ide:  PyCharm 2023.1 python 11
"""import datetime
from datetime import date
import sys
import os
import Commonclass StudentList(object):"""学生实体类"""def __init__(self,StudentId:int,StudentName:str, StudentNO:str,StudentBirthday:datetime.datetime):""":param StudentName::param StudentNO::param StudentBirthday:"""self._StudentName=StudentNameself._StudentNO=StudentNOself._StudentBirthday=StudentBirthdayself._StudentId=StudentIdself._age=0 #date.today().year-StudentBirthday.year #date.today().year-StudentBirthday.year #Common.Commond.calculateAge(date(StudentBirthday.year,StudentBirthday.month,StudentBirthday.day))def __init__(self,StudentId:int,StudentName:str, StudentNO:str,StudentBirthday:datetime.datetime,age:int):""":param StudentName::param StudentNO::param StudentBirthday:"""self._StudentName=StudentNameself._StudentNO=StudentNOself._StudentBirthday=StudentBirthdayself._StudentId=StudentIdself._age=age #date.today().year-StudentBirthday.year #date.today().year-StudentBirthday.year #Common.Commond.calculateAge(date(StudentBirthday.year,StudentBirthday.month,StudentBirthday.day))def __del__(self):""":return:"""print(f"{self._StudentName}")def setStudentName(self,StudentName):""":param StudentName::return:"""self._StudentName = StudentNamedef getStudentName(self):""":return:"""return self._StudentNamedef setStudentNO(self,StudentNO):""":param StudentNO::return:"""self._StudentNO=StudentNOdef getStudentNO(self):""":return:"""return self._StudentNOdef setStudentId(self,StudentId):""":param StudentId::return:"""self._StudentId=StudentIddef getStudentId(self):""":return:"""return  self._StudentIddef setStudentBirthday(self,StudentBirthday):""":param StudentBirthday::return:"""self._StudentBirthday = StudentBirthdaydage =date.today().year-StudentBirthday.year# Common.Commond.calculate_age(StudentBirthday)self._age=dagedef getStudentBirthday(self):""":return:"""return self._StudentBirthdaydef setAge(self,age):""":param age::return:"""dage=1 #Common.Commond.calculate_age(StudentBirthday)self._age = agedef getAge(self):""":return:"""return self._agedef __str__(self):""":return:"""return f"{self._StudentId},{self._StudentName},{self._StudentNO},{self._StudentBirthday}{self._age}"

DAL

"""
StudentDALListDAL.py
数据业务处理层 Data Access Layer (DAL)
SQL Server 数据库操作
date 2023-06-21
edit: Geovin Du,geovindu, 涂聚文
ide: PyCharm 2023.1 python 11
"""import os
import sys
from pathlib import Path
import re
import pymssql  #sql server
import Model.StudentListInfo
import UtilitieDB.MsSQLHelper
import Interface.IStudentListclass StudentDal(Interface.IStudentList.IStudentList):"""数据业务处理层  学生数据库连接可以放在这里,通过配置读取数据连接参数"""def __init__(self):"""构造函数,方法:param strserver::param struser::param strpwd::param strdatabase:"""self._strserver = ""self._struser = ""self._strpwd = ""self._strdatabase =""def selectSql(self):"""查询数据 self._strserver, self._struser, self._strpwd, self._strdatabase:return:"""myms = UtilitieDB.MsSQLHelper.MsSqlHelper()row=myms.execute('select *,DATEDIFF(hour,StudentBirthday,GETDATE())/8766 as Age from DuStudentList;')return rowdef selectSqlOrder(self,order:str)->list:""":param order:  studenName desc/asc:return:"""students=[]myms = UtilitieDB.MsSQLHelper.MsSqlHelper()strsql=f"select * from DuStudentList order by {order};"row=myms.execute(f'select *,DATEDIFF(hour,StudentBirthday,GETDATE())/8766 as Age from DuStudentList order by {order};')return rowdef selectIdSql(self,StudentId:int):""":param StudentId: 主键ID:return:"""myms = UtilitieDB.MsSQLHelper.MsSqlHelper()row=myms.execute(f'select * from DuStudentList where StudentId={StudentId};')return rowdef selectProc(self):"""存储过程:return:"""myms = UtilitieDB.MsSQLHelper.MsSqlHelper()args = ()row = myms.executeCallProc("proc_Select_StudentListAll",args)return rowdef selectIdProc(self,StudentId:int):"""存储过程:param StudentId: 主键ID:return:"""myms = UtilitieDB.MsSQLHelper.MsSqlHelper()args = (StudentId,)row = myms.executeCallProc('dbo.proc_Select_StudentList', args)return rowdef addSql(self,info:Model.StudentListInfo.StudentList):"""添加,要考虑添加返回ID值:param info:学生实体类:return:"""myms=UtilitieDB.MsSQLHelper.MsSqlHelper();column=("StudentName","StudentNO","StudentBirthday")vales=[info.getStudentName(),info.getStudentNO(),info.getStudentBirthday()]myms.insertByColumnaAndValues("dbo.DuStudentList",column,vales)def addProc(self,info:Model.StudentListInfo.StudentList):"""添加,要考虑添加返回ID值:param info:学生实体类:return:"""myms = UtilitieDB.MsSQLHelper.MsSqlHelper();args=(info.getStudentName(),info.getStudentNO(),info.getStudentBirthday())myms.insertCallProc("dbo.proc_Insert_StudentList",args)def addOutProc(self,info:Model.StudentListInfo.StudentList):"""添加,要考虑添加返回ID值:param info:学生实体类:return: 返回增加的学生的ID"""id=0myms = UtilitieDB.MsSQLHelper.MsSqlHelper();outid = pymssql.output(int)args = (info.getStudentName(), info.getStudentNO(), info.getStudentBirthday(),outid)print(args)id=myms.insertOutCallProc("dbo.proc_Insert_StudentListOutput", args)return iddef editSql(self,info:Model.StudentListInfo.StudentList):""":param info:学生实体类:return:"""myms = UtilitieDB.MsSQLHelper.MsSqlHelper();args = {"StudentName":f"{info.getStudentName()}","StudentNO":f"{info.getStudentNO()}","StudentBirthday":f"{info.getStudentBirthday()}"}  #"StudentId":6where = f"StudentId={info.getStudentId()}" ##print(args,where)myms.updateByKeyValues("DuStudentList",where,args)def editProc(self, info: Model.StudentListInfo.StudentList):""":param info: 学生实体类:return:"""myms = UtilitieDB.MsSQLHelper.MsSqlHelper();args = (info.getStudentId(),info.getStudentName(),info.getStudentNO(),info.getStudentBirthday())myms.updateProc("[dbo].[proc_Update_StudentList]",args)def delSql(self,StudentId:int):"""sql语句删除:param StudentId: 主键ID:return:"""myms = UtilitieDB.MsSQLHelper.MsSqlHelper();where={f"StudentId":StudentId}myms.deleteByKeyValues("DuStudentList",where)def delProc(self, studentId):"""删除 存储过程 删除多个ID,后面增加:param StudentId: 主键ID:return:"""myms = UtilitieDB.MsSQLHelper.MsSqlHelper();args =studentIdmyms.deleteProc("dbo.proc_Delete_StudentList",args)

IDAL

"""
IStudentList.py
接口层 Interface Data Access Layer
IDAL(Interface Data Access Layer)DAL的接口层
date 2023-06-19
edit: Geovin Du,geovindu, 涂聚文
ide:  PyCharm 2023.1 python 11
"""
from __future__ import annotations
from abc import ABC, abstractmethod
import os
import sys
import Model.StudentListInfoclass IStudentList(ABC):""""""@classmethoddef __subclasshook__(cls, subclass):return (hasattr(subclass, 'load_data_source') andcallable(subclass.load_data_source) andhasattr(subclass, 'extract_text') andcallable(subclass.extract_text) orNotImplemented)@abstractmethoddef selectSql(self):""":return:"""pass@abstractmethoddef selectSqlOrder(self, order: str) -> list:""":param order::return:"""pass@abstractmethoddef selectIdSql(self, StudentId: int):""":param StudentId::return:"""pass@abstractmethoddef selectProc(self):""":return:"""pass@abstractmethoddef selectIdProc(self, StudentId: int):""":param StudentId::return:"""pass@abstractmethoddef addSql(self, info: Model.StudentListInfo.StudentList):""":param info::return:"""pass@abstractmethoddef addProc(self, info: Model.StudentListInfo.StudentList):""":param info::return:"""pass@abstractmethoddef addOutProc(self, info: Model.StudentListInfo.StudentList):""":param info::return:"""pass@abstractmethoddef editSql(self, info: Model.StudentListInfo.StudentList):""":param info::return:"""pass@abstractmethoddef editProc(self, info: Model.StudentListInfo.StudentList):""":param info::return:"""pass@abstractmethoddef delSql(self, StudentId: int):""":param StudentId::return:"""pass@abstractmethoddef delProc(self, studentId):""":param studentId::return:"""pass

BLL

"""
StudentListBLL.py
业务层 Business Logic Layer (BLL)
date 2023-06-19
edit: Geovin Du,geovindu, 涂聚文
ide:  PyCharm 2023.1 python 11
"""import os
import sys
from pathlib import Path
import re
import pymssql  #sql server
from datetime import date
import DAL.StudentListDAL
#import DAL.ConfigDAL
import Model.StudentListInfo
import Interface.IStudentList
import Factory.AbstractFactoryclass StudentBll(object):"""学生信息操作业务类"""dal=Factory.AbstractFactory.AbstractFactory.createStudentList#dal =DAL.StudentListDAL.StudentDal() #Factory.AbstractFactory.AbstractFactory.createStudentList()#"""类属性 操作DAL"""def __init__(self):""""""self._name = "geovindu"def __del__(self):print(f"{self._name}挂失了")def selectSql(cls)->list:"""元组数据:return: list 学生列表"""students = []data = cls.dal().selectSql()stus = list(data)  # 如C# 强制转换'''for a in data:for i in a:print("II",i[0],i[1],i[2],i[3],i[4])'''#print(stus)for ii in stus:for i in ii:students.append(Model.StudentListInfo.StudentList(i[0],i[1],i[2],i[3],i[4]))return studentsdef selectSqlOrder(cls, order: str)->list:"""元组数据:param order: studenName desc/asc:return:"""studentsorder = []students=[]data = cls.dal().selectSqlOrder(order)(studentsorder) = data # 如C# 强制转换'''for i in range(len(studentsorder)):print("rrr",type(studentsorder[i]))for duobj in studentsorder[i]:print(type(duobj))print(duobj)'''for obj in studentsorder:for i in obj:students.append(Model.StudentListInfo.StudentList(i[0], i[1], i[2], i[3],i[4]))return studentsdef selectIdSql(cls,StudentId:int)->list:""":param StudentId:学生ID:return:"""students = []data = cls.dal().selectIdSql(StudentId)students=datafor ii in students:for i in ii:students.append(Model.StudentListInfo.StudentList(i[0],i[1],i[2],i[3]))return studentsdef selectProc(cls):""":return:"""students=[]data = cls.dal().selectProc()for i in data:students.append(Model.StudentListInfo.StudentList(i[0],i[1],i[2],i[3],i[4]))return studentsdef selectIdProc(cls,StudentId:int)->list:""":param StudentId::return:"""students = []data = cls.dal().selectIdProc(StudentId)for i in data:students.append(Model.StudentListInfo.StudentList(i[0],i[1],i[2],i[3]))return studentsdef addSql(cls,info:Model.StudentListInfo.StudentList):""":param info:学生实体类:return:"""cls.dal.addSql(info)def addProc(cls,info:Model.StudentListInfo.StudentList):""":param info:学生实体类:return:"""#print(info)cls.dal().addProc(info)def addOutProc(cls,info:Model.StudentListInfo.StudentList)->int:""":param info: 学生实体类:return: 返回增加的学生ID"""print(info)return cls.dal().addOutProc(info)def editSql(cls,info:Model.StudentListInfo.StudentList):""":param info:学生实体类:return:"""#print(info)cls.dal().editSql(info)def editProc(cls, info: Model.StudentListInfo.StudentList):""":param info:学生实体类:return:"""cls.dal().editProc(info)def delSql(cls, StudentId: int):""":param StudentId::return:"""cls.dal().delSql(StudentId)def delProc(cls, StudentId):""":param StudentId::return:"""cls.dal().delProc(StudentId)

UI

"""
StudentUI.py
读文件类
date 2023-06-24
edit: Geovin Du,geovindu, 涂聚文
ide:  PyCharm 2023.1 python 11"""import datetime
import sys
import os
from tkinter import ttk
from tkinter import *
from tkinter.ttk import *
from ttkbootstrap import Style  # pip install ttkbootstrap
import random
import Model.StudentListInfo
import BLL.StudentListBLLclass StudentUi(object):global treestubll = BLL.StudentListBLL.StudentBll()def __init__(self):self.name="geovindu"def __del__(self):print(f"{self.name}")def delete(cls):#global treecurItem = cls.tree.focus()val=cls.tree.item(curItem)['values'][0]  #idprint(val)print(cls.tree.selection())cls.tree.delete(cls.tree.selection())cls.stubll.delSql(val)  #需要删除关联的数据才可以删除#cls.stubll.delSql()def main(cls):"""窗体绑定数据:return:"""style=Style(theme='darkly') #定义窗口样式window=style.masterwindow.title("学生管理")# win = Tk()screenWidth = window.winfo_screenwidth()screenHeight = window.winfo_screenheight()width=100height=600x=int((screenWidth-width)/2)y=int((screenHeight-height)/2)window.geometry('{}x{}+{}+{}'.format(width,height,x,y))#Treeview 控件cls.tree=ttk.Treeview(master=window,style='success.Treeview',height=25,show='headings')cls.tree.pack()#定义列cls.tree['columns']=("StudentId","StudentName","StudentNO","StudentBirthday","Age")#设置列属性,列不显示cls.tree.column("StudentId",width=150,minwidth=100,anchor=S)cls.tree.column("StudentName", width=150, minwidth=100, anchor=S)cls.tree.column("StudentNO", width=150, minwidth=100, anchor=S)cls.tree.column("StudentBirthday", width=150, minwidth=100, anchor=S)cls.tree.column("Age", width=150, minwidth=100, anchor=S)#设置表头cls.tree.heading("StudentId",text="序号")cls.tree.heading("StudentName", text="姓名")cls.tree.heading("StudentNO", text="学号")cls.tree.heading("StudentBirthday", text="出生日期")cls.tree.heading("Age", text="年龄")# stubll = BLL.StudentListBLL.StudentBll()geovindu = cls.stubll.selectSqlOrder("Age asc")  # list()#treeView控件绑定数据i=1for Model.StudentListInfo.StudentList in geovindu:cls.tree.insert("",i,text="2",values=(Model.StudentListInfo.StudentList.getStudentId(),Model.StudentListInfo.StudentList.getStudentName(),Model.StudentListInfo.StudentList.getStudentNO(),Model.StudentListInfo.StudentList.getStudentBirthday(),Model.StudentListInfo.StudentList.getAge()))i+=1#删除按钮ttk.Button(window,text="删除",style='success,TButton',command=cls.delete).pack(side='left',padx=5,pady=10)window.mainloop()

输出“

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/4566.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

UE4 Cesium离线生成地形

地理空间数据云 首先进这个网址,下载对应的tif以及高程(DEM) 下载CesiumLab2 在地形切片中点击添加,将黑白图像数据,添加,选择存储类型为散列文件,选择输出路径 再选择影像切片,选择…

Sublime Text 初步使用

Sublime Text ,最初被设计为一个具有丰富扩展功能的Vim。 Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括&#xf…

PyTorch开放神经网络交换(Open Neural Network Exchange)ONNX通用格式模型的熟悉

我们在深度学习中可以发现有很多不同格式的模型文件,比如不同的框架就有各自的文件格式:.model、.h5、.pb、.pkl、.pt、.pth等等,各自有标准就带来互通的不便,所以微软、Meta和亚马逊在内的合作伙伴社区一起搞一个ONNX(Open Neura…

jupyter notebook优化

一.这个是jupyter notebook主题设置的相关教程,如果经常看着高亮的屏幕,对于眼睛会是一种损伤! https://blog.csdn.net/qq_41566627/article/details/104984796?utm_mediumdistribute.pc_relevant.none-task-blog-2%7Edefault%7…

乐鑫线上研讨会|探索 LCD 屏在物联网中的发展趋势

LCD 屏通过显示实时信息并提供交互式体验,现已成为各类设备的重要组成部分。在当下的 AIoT 时代,随着物联网技术的快速发展和应用场景的不断拓展,LCD 作为人机交互的主要输入输出设备,在智能家居、智能安防、工业控制、智慧城市等…

react封装jsoneditor

1、安装: api文档:jsoneditor npm install jsoneditor2、代码: JsonEditor/index.tsx: import { useMemoizedFn } from ahooks; import JSONEditor from jsoneditor; import { useEffect, useState } from react; import ./index.less;in…

redis 主从复制 哨兵 安装部署

学习开始前先了解一下 Redis是一个开源的内存数据结构存储系统,它支持多种数据结构,如字符串、哈希表、列表、集合、有序集合等。Redis最大的特点是数据存储在内存中,因此读写速度非常快,同时也支持数据持久化,可以将数…

【K8S系列】如何高效查看 k8s日志

序言 你只管努力,其他交给时间,时间会证明一切。 文章标记颜色说明: 黄色:重要标题红色:用来标记结论绿色:用来标记一级论点蓝色:用来标记二级论点 Kubernetes (k8s) 是一个容器编排平台&#x…

AndroidStudio xml布局文件输入没有提示

AndroidStudio xml布局文件输入没有提示,如下图: 原因是老的AndroidStudio与新的sdk版本不一致 方法1:修改compileSdkVersion低于33即可,不建议 方法2:升级AndroidStudio版本,建议 如下是我的AndroidStu…

Docker部署(1)——将jar包打成docker镜像并启动容器

在代码编写完成即将部署的时候,如果采用docker容器的方法,需要将jar包打成docker镜像并通过镜像将容器启动起来。具体的步骤如下。 一、首先下载java镜像 先使用docker search java命令进行搜索。 然而在拉取镜像的时候要注意不能直接去选择pull java ,…

改进的白鲸优化算法

改进的白鲸优化算法 一、算法灵感二、算法介绍2.1 初始化2.2 探索阶段2.3 开发阶段2.4 鲸落阶段 三、改进的白鲸优化算法3.1 集体行动策略3.2 小孔成像策略3.3 二次插值策略3.4 IBWO伪代码 一、算法灵感 白鲸优化算法(Beluga whale optimization, BWO)是2022年提出的一种元启发…

需求分析引言:架构漫谈(三)可用性专题

前文介绍了非功能性需求的各个指标和一些业界的标准。 非功能性需求里有一项可靠性,与之关联的一个指标叫可用性 本文对非功能性需求里的可用性、可靠性,进行一些详细的说明。 概念 我们在网上的云服务商处,经常看到产品介绍里会有这种字样…