📄 datamodule1.pas
字号:
unit DataModule1;
interface
uses
SysUtils, Classes, DB, DBTables, ScktComp,Stdctrls, ADODB;
const
ErrTime = '输入时间格式错误!';
ErrFloat ='输入小数格式错误!';
ErrConnect ='不能建立连接!请检查网线和服务器!';
ErrAct='操作失败!请稍后再试';
ErrLate='今天没人迟到?';
type
Maninfo = Record
MName:String;
MNo:String;
MDepart:String;
MLev:Byte;
MPicRoute:String;
MPassword:String;
M_Sort:Byte;
end;
type
TDM = class(TDataModule)
Database1: TDatabase;
TBWorker_L: TTable;
CSShu: TClientSocket;
qryKaoqin: TQuery;
DSKaoqin: TDataSource;
DSWorker: TDataSource;
TBSysParams_L: TTable;
TBJiangFa: TTable;
TBIP: TTable;
qryShoushi: TQuery;
DSShoushi: TDataSource;
DSSYsparams: TDataSource;
qryApply: TQuery;
TBBBS: TTable;
TBDepart_L: TTable;
qryWorker: TQuery;
qryPrize: TQuery;
qryInvoice: TQuery;
DSInvoice: TDataSource;
DSPrize: TDataSource;
qryJiangFa: TQuery;
DSJiangFa: TDataSource;
qryTicheng: TQuery;
ADOConnection1: TADOConnection;
TBWorker: TADOTable;
ADOTable1: TADOTable;
private
{ Private declarations }
public
function PasswordRight(AName:String;APasswd:String):Byte; //0:通过 1:密码错 2:查无此人
function GetDataFromServer:boolean;
function GetDutyMan(ADepart:String;LastName:String):String; //日期变时由部门名、顺序号求得该部门值日生名称
function GetManinfo(AStr:String):Maninfo;
function GetManinfoList:boolean;
function TrimWorkerSort:boolean;
procedure SetDBParams;
{ Public declarations }
end;
var
DM: TDM;
CurrentDutyMan:String;
CurrentWorker:String; //当前操作员
CurrentWeek:String; //当前星期
CurrentMonth:String; //当前月份
CurrentQuarter:String; //当前季度
CurrentYear:String;
CurrentLev:Byte; //当前操作权限
CurrentDepart:String; //操作员所属部门
CurrentAct:Byte; //当前操作状态 0:添加 1:修改 2:查询 3:删除
CurrentSheet:String; //当前处理的文档,在CS通讯时使用
CurrentQry:String; //SelectForm的选择
ManinfoList:array [0..40] of Maninfo; //读取所有人有用信息在此数组中!
ManSumNo:Byte; //ManinfoList的最后一个下标
AManinfo:Maninfo;
procedure GetParams;
function isTime(Atime:String):boolean;
function isFloat(Afloat:String):boolean;
procedure GetComboBoxItem(AComboBox:TComboBox);
procedure GetDepartComboBoxItem(AComboBox:TComboBox);
implementation
{$R *.dfm}
{ TDM }
function isTime(ATime:String):boolean;
begin
try
StrToTime(ATime);
Result:=True;
except
Result:=false;
end;
end;
function isFloat(AFloat:String):boolean;
begin
try
StrToFloat(AFloat);
Result:=True;
except
Result:=false;
end;
end;
procedure GetParams;
var
C_Year,C_Month,C_Day:Word;
Dow:Byte;
begin
DecodeDate(Date,C_Year,C_Month,C_Day);
case C_Month of
1:begin
CurrentMonth:='一月份';
CurrentQuarter:='第一季度';
end;
2:begin
CurrentMonth:='二月份';
CurrentQuarter:='第一季度';
end;
3:begin
CurrentMonth:='三月份';
CurrentQuarter:='第一季度';
end;
4:begin
CurrentMonth:='四月份';
CurrentQuarter:='第二季度';
end;
5:begin
CurrentMonth:='五月份';
CurrentQuarter:='第二季度';
end;
6:begin
CurrentMonth:='六月份';
CurrentQuarter:='第二季度';
end;
7:begin
CurrentMonth:='七月份';
CurrentQuarter:='第三季度';
end;
8:begin
CurrentMonth:='八月份';
CurrentQuarter:='第三季度';
end;
9:begin
CurrentMonth:='九月份';
CurrentQuarter:='第三季度';
end;
10:begin
CurrentMonth:='十月份';
CurrentQuarter:='第四季度';
end;
11:begin
CurrentMonth:='十一月份';
CurrentQuarter:='第四季度';
end;
12:begin
CurrentMonth:='十二月份';
CurrentQuarter:='第四季度';
end;
end;
CurrentYear:=IntToStr(C_year)+'年';
DOW:=DayofWeek(date);
case dow of
1:CurrentWeek:='星期日';
2:CurrentWeek:='星期一';
3:CurrentWeek:='星期二';
4:CurrentWeek:='星期三';
5:CurrentWeek:='星期四';
6:CurrentWeek:='星期五';
7:CurrentWeek:='星期六';
end;
end;
procedure GetComboBoxItem(AComboBox:TComboBox); //列举全部人员
var
I:Byte;
begin
AComboBox.Items.Clear;
for I:=0 to ManSumNo do AComboBox.Items.Add(ManinfoList[I].MName);
end;
procedure GetDepartComboBoxItem(AComboBox:TComboBox); //列举本部门人员
var
I:Byte;
begin
AComboBox.Items.Clear;
for I:=0 to ManSumNo do
begin
if ManinfoList[I].MDepart=CurrentDepart then
AComboBox.Items.Add(ManinfoList[I].MName);
end;
end;
function TDM.GetManinfo(AStr: String):Maninfo;
var
I:Byte;
begin
for I:=0 to ManSumNo do
begin
if (ManinfoList[I].MName=AStr) or (ManinfoList[I].MNo=AStr) then //输入姓名、刷卡均可
begin
Result.MName:=ManinfoList[I].MName;
Result.MDepart:=ManinfoList[I].MDepart;
Result.MNo:=ManinfoList[I].MNo;
Result.MPassword:=ManinfoList[I].MPassword;
Result.MPicRoute:=ManinfoList[I].MPicRoute;
Result.MLev:=ManinfoList[I].MLev;
Result.M_Sort:=ManinfoList[I].M_Sort;
end;
end;
end;
function TDM.GetDutyMan(ADepart:String;LastName:String):String;
var
I:Byte;
AASort:Byte;
SortMax:Byte;
begin
SortMax:=1;
for I:=0 to ManSumNo do
begin
if ManinfoList[I].MDepart =ADepart then
begin
if ManinfoList[I].M_Sort>SortMax then SortMax:=ManinfoList[I].M_Sort;
if ManinfoList[I].MName=LastName then AASort:=ManinfoList[I].M_Sort+1;
end;
end;
if AASort>SortMax then AASort:=1;
for I:=0 to ManSumNo do
begin
if (ManinfoList[I].MDepart =ADepart) and (ManinfoList[I].M_Sort=AASort) then
Result:=ManinfoList[I].MName;
end;
end;
function TDM.GetDataFromServer: boolean;
var
MS1:TMemoryStream;
TCount,I:Byte;
begin
result:=False;
with TBWorker_L do
begin
Open;
TCount:=RecordCount;
First;
if TCount<>0 then
for I:=0 to TCount-1 do Delete;
close;
Open;
end;
try //需要传图片不能用ManinfoList;
Database1.StartTransaction;
with TBWorker do
begin
Open;
First;
while not eof do
begin
if FieldByName('M_Lev').AsInteger<>2 then //管理者不下传
begin
TBWorker_L.Append;
TBWorker_L.FieldByName('M_No').AsString:=FieldByName('M_No').AsString;
TBWorker_L.FieldByName('M_Name').AsString:=FieldByName('M_Name').AsString;
TBWorker_L.FieldByName('M_Password').AsString:=FieldByName('M_Password').AsString;
TBWorker_L.FieldByName('M_Department').AsString:=FieldByName('M_Department').AsString;
MS1:=TMemoryStream.Create;
(FieldByName('M_Picture') as TBlobField).saveToStream(MS1);
MS1.Position :=0;
(TBWorker_L.FieldByName('M_Picture') as TBlobField).LoadFromStream(MS1);
MS1.free;
TBWorker_L.Post;
end;
Next;
end;
Close;
TBWorker_L.Close;
end;
database1.Commit;
Result:=True;
except
Database1.Rollback;
end;
end;
function TDM.GetManinfoList: boolean;
var
I:byte;
begin
I:=0;
with TBWorker_L do
begin
Open;
First;
while not Eof do
begin
ManinfoList[I].MName:=FieldByName('M_Name').AsString;
ManinfoList[I].MNo:=FieldByName('M_No').AsString;
ManinfoList[I].MDepart:=FieldByName('M_Department').AsString;
ManinfoList[I].MLev:=FieldByName('M_Lev').AsInteger;
// ManinfoList[I].MPicRoute:=FieldByName('M_PicRoute').AsString;
ManinfoList[I].MPassword:=FieldByName('M_Password').AsString;
ManinfoList[I].M_Sort:=FieldByName('M_Sort').AsInteger;
Next;
I:=I+1;
end;
ManSumNo:=I-1;
result:=True;
close;
end;
end;
function TDM.TrimWorkerSort: boolean;
var
Depart:String;
I:Byte;
begin
TBDepart_L.Open;
TBDepart_L.First;
while not TBDepart_L.eof do
begin
Depart:=TBDepart_L.FieldByName('D_Name').AsString;
with qryWorker do
begin
Close;
SQL.Clear;
SQL.Add('Select M_Department,M_Sort from Worker');
SQL.Add('where M_Department=:varDepart Order By M_Sort ASC');
Params[0].AsString :=Depart;
I:=1;
Open;
First;
while not eof do
begin
Edit;
FieldByName('M_Sort').AsInteger:=I;
Next;
I:=I+1;
end;
close;
end;
TBDepart_L.Next;
end;
TBDepart_L.Close;
end;
function TDM.PasswordRight(AName, APasswd: String):Byte;
var
Ainfo:Maninfo;
begin
Ainfo:=DM.GetManinfo(AName);
if Ainfo.MName<>'' then
begin
if Ainfo.MPassword=APasswd then
begin
CurrentLev:=Ainfo.MLev;
CurrentDepart:=Ainfo.MDepart;
CurrentWorker:=Ainfo.MName;
Result:=0;
end
else
Result:=1;
end
else Result:=2;
end;
procedure TDM.SetDBParams;
begin
Database1.DatabaseName:='SSData';
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -