📄 clsmain.~pas
字号:
unit Clsmain;
interface
uses
System.Drawing, System.Collections, System.ComponentModel,
System.Windows.Forms, System.Data, System.data.OleDb,dialogs;
type
TClass1 = class
private
{ Private Declarations }
public
constructor Create;
function ado_connect():boolean;
function cmn_ado_select(sql:string):dataset;
function cmn_ado_execute(sql: &string):boolean;
function getItemValueS(Ds:DataSet;Row:integer;ColNm:String):System.Object;
function getItemValueN(Ds:DataSet;Row:integer;Col:integer): System.Object;
procedure begintrans();
procedure commit();
procedure rollback();
function ComboBox_Load(SQL: &String;CmbName: System.Windows.Forms.ComboBox; KongHang: Boolean): Boolean;
end;
var
{==============公用变量=====================}
conn:oledbconnection; //创建连接对象
trans:oledbtransaction; //创建事物对象
winpassshowfla:boolean; //定义一个变量,判断一个窗体是否打开
username:string; //登陆用户名
YGusername:string; //员工登陆时的用户名
YGpass:string; //员工登陆时的密码=员工编号
YGbumen:string; //员工所在的部门
YGdenglucishu:integer; //员工登陆时的记录的次数
MUPtime:string; //工作时间表中的上班时间
MDOwntime:string; //工作时间表中的下班时间
myds:dataset;
quanxian:string; //用户权限 1。高级用户 0。低级用户
winreloadshowfla:boolean; //重新登陆显示标记 True:显示状态; False:关闭状态
times:integer; //关于重新登陆是否判断并且对取消按钮操作的控制
WinAboutShowFla:Boolean; //关于窗体显示标记 True:显示状态; False:关闭状态
WinusershowFla:Boolean; //用户窗体显示标记
Windepartshowfla:boolean; //部门窗体显示标记
Windiplomashowfla:boolean; //学历窗体显示标记
Winpostshowfla:boolean; //职务管理窗体显示标记
Winworktimeshowfla:boolean; //工作时间窗体显示标记
WinYuanGongshowfla:boolean; //员工信息维护窗体显示标记
Winchuqinshowfla:boolean; //出勤管理窗体显示标记
WinDelshowfla:boolean; //删除窗体显示标记
w_up:string;
w_down:string;
implementation
///****************************************************************
//* ado_connect
//*
//* [参数]
//* 无
//* [返回]
//* 实行状况
//* True:成功
//* False:失败
//****************************************************************
function TClass1.ado_connect: boolean;
var
cnnstr:string;
begin
try
//创建连接函数
conn:=oledbconnection.Create();
//生成连接字符串
cnnstr:='provider=microsoft.jet.oledb.4.0;data source='+application.startuppath+'\database\db1.mdb;';
conn.ConnectionString:=cnnstr;
conn.Open();
//返回值的设定
result:=true; //正常返回
except
on ex:exception do
begin
result:=false;
messagebox.Show('TClass1.ado_connect:('+ex.message+')','考勤管理系统');
end;
end;
end;
//****************************************************************
//* 事务开始函数
//*
//* [参数]
//* 无
//* [返回]
//* 实行状况
//* True:成功
//* False:失败
//****************************************************************
procedure TClass1.begintrans;
begin
try
trans:=conn.BeginTransaction();
except
on ex:exception do
begin
messagebox.Show('TClass1.begintrans:(' + ex.Message + ')','考勤管理系统');
end;
end;
end;
//****************************************************************
//* 事务执行函数
//*
//* [参数]
//* 无
//* [返回]
//* 实行状况
//* True:成功
//* False:失败
//****************************************************************
function TClass1.cmn_ado_execute(sql: &string): boolean;
var
MyCom:OleDbCommand; //定义Command对象
begin
try
MyCom:=OleDbCommand.Create;
MyCom.CommandText := SQL;
MyCom.Connection := Conn;
MyCom.Transaction := Trans;
MyCom.ExecuteNonQuery(); //执行SQL命令
MyCom.Dispose(); //释放资源
result:= True; //正常返回设定
except
on ex:Exception do
begin
messagebox.show('TClsMain.Cmn_Ado_Execute : (' + ex.message + ') ' , '考勤管理系统');
end;
end;
end;
//****************************************************************
//* cmn_ado_select
//*
//* [参数]
//* 无
//* [返回]
//* 实行状况
//* True:成功
//* False:失败
//****************************************************************
function TClass1.cmn_ado_select(sql:&string): dataset;
var
mycom:oledbcommand;//定义command对象
mydtp:oledbdataadapter; //定义dataadapter对象
myds:dataset;
begin
try
mycom:=oledbcommand.create;
mydtp:=oledbdataadapter.Create;
myds:=dataset.Create;
mycom.CommandText:=sql;
mycom.Connection:=conn;
mycom.Transaction:=trans;
mydtp.SelectCommand:=mycom;
mydtp.Fill(myds); //填充数据集
result:=myds;
except
on ex:exception do
begin
messagebox.Show('TClass1.cmn_ado_select:('+ex.message+')','考勤管理系统');
end;
end;
end;
//****************************************************************
//* 事务提交函数
//*
//* [参数]
//* 无
//* [返回]
//* 实行状况
//* True:成功
//* False:失败
//****************************************************************
procedure TClass1.commit;
begin
try
Trans.Commit();
except
on ex:Exception do
begin
messagebox.show('TClass1.Commit : (' + ex.message + ') ' , '考勤管理系统');
end;
end;
end;
constructor TClass1.Create;
begin
inherited Create;
// TODO: Add any constructor code here
end;
//****************************************************************
//* 取数据函数
//* [参数] 1:DataSet
//* 2:行数
//* 3:列数
//* [返回值] 字段值
//*
//* [使用示例] Value := getItemValueN(MyDs, 0, 1);
//****************************************************************
function TClass1.getItemValueN(Ds: DataSet; Row,
Col: integer): System.Object;
begin
try
result:=Ds.Tables[0].Rows.Item[Row][Col];
except
on ex:Exception do
begin
messagebox.show('TClass1.getItemValueN : (' + ex.message + ') ' , '考勤管理系统');
end;
end;
end;
//****************************************************************
//* 取数据函数
//* [参数] 1:DataSet
//* 2:行数
//* 3:列名
//* [返回值] 字段值
//*
//* [使用示例] Value := getItemValueS(MyDs, 0, "供应商编号");
//****************************************************************
function TClass1.getItemValueS(Ds: DataSet; Row: integer;
ColNm: &String): System.Object;
begin
try
result:= Ds.Tables[0].Rows[Row][ColNm];
except
on ex:Exception do
begin
messagebox.show('Tclass1.getItemValueS : (' + ex.message + ') ' , '考勤管理系统');
end;
end;
end;
//****************************************************************
//* 事务回滚函数
//*
//* [参数]
//* 无
//* [返回]
//* 实行状况
//* True:成功
//* False:失败
//****************************************************************
procedure TClass1.rollback;
begin
try
trans.Rollback();
except
on ex:Exception do
begin
messagebox.show('TClass1.rollback:(' + ex.message + ') ' , '考勤管理系统');
end;
end;
end;
//****************************************************************
//* ComboBox控件装载数据函数
//*
//* [参数]
//* 1:SQL语句
//* 2:ComboBox控件名称
//* 3:第一行是否为空行
//* [返回]
//* 1:输入ERR有无 (True:ERR没有、 False:ERR有)
//****************************************************************
function TClass1.ComboBox_Load(SQL: &String;
CmbName: System.Windows.Forms.ComboBox; KongHang: Boolean): Boolean;
var
w_SQL:String;
MyDs:DataSet;
i:integer;
begin
try
w_SQL := SQL;
MyDs := Cmn_Ado_Select(w_SQL);
If KongHang = True Then
begin
CmbName.Items.Add('');
End;
for i:=0 to MyDs.Tables[0].Rows.Count-1 do
begin
CmbName.Items.Add(getItemValueN(MyDs, i, 0));
end;
result:= True; //正常返回设定
except
on ex:Exception do
begin
messagebox.show('TClass1.ComboBox_Load : (' + ex.message + ') ' , '考勤管理系统');
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -