📄 main.pas
字号:
unit Main;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
BaseIme, ComCtrls, Menus, ExtCtrls, StdCtrls, Base_Common, Inifiles, Jpeg,
Db, AdODB, ActnList, DBClient, Grids, DBGrids, MConnect, XPmenu;
Type
TFrm_Main = Class(TFrm_BaseIme)
StatusBar1: TStatusBar;
MainMenu1: TMainMenu;
AdoConnectMain: TAdOConnection;
AdoQry_SysMenu: TAdoQuery;
AdoQry_SysMenuAccessCtrl: TAdoQuery;
AdoQry_Tmp: TAdoQuery;
ActionList1: TActionList;
Action1: TAction;
Image1: TImage;
XPmenu1: TXPmenu;
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure Action1Execute(Sender: TObject);
private
T1,T2,T3:Tdatetime;
F_LoginId:string;
F_LoginName:string;
F_LoginDate:string;
F_ModuleCode:string;
FPriceLen,FQtyLen:integer;
FClientInstance : TFarProc;
FPrevClientProc : TFarProc;
ShowPictrue:boolean;
procedure ClientWndProc(var Message: TMessage); //加图
function MenuIdIsActive(MenuId:string):Boolean; //判断FORM是否被激活
function getwindir:string;
procedure InserTMenuItem(father: TMenuItem;fidstring:string);
procedure newmenuclick(Sender: TObject);
procedure SysMenuClick(Sender: TObject);
//procedure ShowRMrpFlag();
function newnumber(number:integer):string;
procedure GetMenuColor;
procedure displayHint(sender:Tobject);
{ Private declarations }
public
//显示statusBar上的时钟
Currentmenuid:string;
procedure createmenu;
procedure Getnewmenuclick(SysModuleCode:string);
procedure GetPuTongMenuclick(TmpId,TmpName:string);
procedure EnableLab(Lb:TLabel;Img:TImage;TmpId:string);
procedure AppException(Sender: TObject; E: Exception);
{ Public declarations }
end;
var
Frm_Main:TFrm_Main;
ApMoudle:Thandle;
QcMoudle:Thandle;
BasMoudle:Thandle;
PmMoudle:Thandle;
SfcMoudle:Thandle;
MrpMoudle:Thandle;
InvMoudle:Thandle;
StkMoudle:Thandle;
SalMoudle:Thandle;
SysMoudle:Thandle;
ArMoudle:Thandle;
GlMoudle:Thandle;
AdMoudle:Thandle;
ScMoudle:Thandle;
ApCallForm:procedure(Formu:TForm;FormName:string;conn:TAdOConnection;LoginId,ModuleCode,TmpSysMenuid,LoginDate,Param1, Param2, Param3, Param4, Param5, Param6:string);stdcall;
QcCallForm:procedure(Formu:TForm;FormName:string;conn:TAdOConnection;LoginId,ModuleCode,TmpSysMenuid,LoginDate,Param1, Param2, Param3, Param4, Param5, Param6:string);stdcall;
BasCallForm:procedure(Formu:TForm;FormName:string;conn:TAdOConnection;LoginId,ModuleCode,TmpSysMenuid,LoginDate,Param1, Param2, Param3, Param4, Param5, Param6:string);stdcall;
PmCallForm:procedure(Formu:TForm;FormName:string;conn:TAdOConnection;LoginId,ModuleCode,TmpSysMenuid,LoginDate,Param1, Param2, Param3, Param4, Param5, Param6:string);stdcall;
SfcCallForm:procedure(Formu:TForm;FormName:string;conn:TAdOConnection;LoginId,ModuleCode,TmpSysMenuid,LoginDate,Param1, Param2, Param3, Param4, Param5, Param6:string);stdcall;
MrpCallForm:procedure(Formu:TForm;FormName:string;conn:TAdOConnection;LoginId,ModuleCode,TmpSysMenuid,LoginDate,Param1, Param2, Param3, Param4, Param5, Param6:string);stdcall;
InvCallForm:procedure(Formu:TForm;FormName:string;conn:TAdOConnection;LoginId,ModuleCode,TmpSysMenuid,LoginDate,Param1, Param2, Param3, Param4, Param5, Param6:string);stdcall;
StkCallForm:procedure(Formu:TForm;FormName:string;conn:TAdOConnection;LoginId,ModuleCode,TmpSysMenuid,LoginDate,Param1, Param2, Param3, Param4, Param5, Param6:string);stdcall;
SalCallForm:procedure(Formu:TForm;FormName:string;conn:TAdOConnection;LoginId,ModuleCode,TmpSysMenuid,LoginDate,Param1, Param2, Param3, Param4, Param5, Param6:string);stdcall;
SyScallForm:procedure(Formu:TForm;FormName:string;conn:TAdOConnection;LoginId,ModuleCode,TmpSysMenuid,LoginDate,Param1, Param2, Param3, Param4, Param5, Param6:string);stdcall;
ArCallForm:procedure(Formu:TForm;FormName:string;conn:TAdOConnection;LoginId,ModuleCode,TmpSysMenuid,LoginDate,Param1, Param2, Param3, Param4, Param5, Param6:string);stdcall;
GlCallForm:procedure(Formu:TForm;FormName:string;conn:TAdOConnection;LoginId,ModuleCode,TmpSysMenuid,LoginDate,Param1, Param2, Param3, Param4, Param5, Param6:string);stdcall;
AdCallForm:procedure(Formu:TForm;FormName:string;conn:TAdOConnection;LoginId,ModuleCode,TmpSysMenuid,LoginDate,Param1, Param2, Param3, Param4, Param5, Param6:string);stdcall;
ScCallForm:procedure(Formu:TForm;FormName:string;conn:TAdOConnection;LoginId,ModuleCode,TmpSysMenuid,LoginDate,Param1, Param2, Param3, Param4, Param5, Param6:string);stdcall;
implementation
uses Sys_Global,Sys_Login, Sys_SysMenu,Sys_Main, Sys_ChangePassword;
{$R *.DFM}
procedure TFrm_Main.FormCreate(Sender: TObject);
var
S:string;
I:Integer;
Tmp_Inifile:tInifile; //操作ini文件的对象
Tmp_lserverip:string; //服务器IP地址
Tmp_ldataBaseName:string; //数据库名
Tmp_ldbuserid:string; //用户名
Tmp_ldbPass:string; //密码
begin
Application.OnHint:=displayHint;
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle,GWL_WNDPROC));
SetWindowLong(ClientHandle,GWL_WNDPROC, LongInt(FClientInstance));
Application.OnException := AppException;
try
AdMoudle:=LoadLibrary('.\Admdl.dll');
AdCallForm:=GetProcAddress(AdMoudle,'AdCallForm');
ApMoudle:=LoadLibrary('.\Apmdl.dll');
ApCallForm:=GetProcAddress(ApMoudle,'ApCallForm');
QcMoudle:=LoadLibrary('.\Qcmdl.dll');
QcCallForm:=GetProcAddress(QcMoudle,'QcCallForm');
BasMoudle:=LoadLibrary('.\Basmdl.dll');
BasCallForm:=GetProcAddress(BasMoudle,'BasCallForm');
PmMoudle:=LoadLibrary('.\Pmmdl.dll');
PmCallForm:=GetProcAddress(PmMoudle,'PmCallForm');
SfcMoudle:=LoadLibrary('.\Sfcmdl.dll');
SfcCallForm:=GetProcAddress(SfcMoudle,'SfcCallForm');
MrpMoudle:=LoadLibrary('.\Mrpmdl.dll');
MrpCallForm:=GetProcAddress(MrpMoudle,'MrpCallForm');
InvMoudle:=LoadLibrary('.\Invmdl.dll');
InvCallForm:=GetProcAddress(InvMoudle,'InvCallForm');
StkMoudle:=LoadLibrary('.\Stkmdl.dll');
StkCallForm:=GetProcAddress(StkMoudle,'StkCallForm');
SalMoudle:=LoadLibrary('.\Salmdl.dll');
SalCallForm:=GetProcAddress(SalMoudle,'SalCallForm');
SysMoudle:=LoadLibrary('.\Sysmdl.dll');
SyScallForm:=GetProcAddress(SysMoudle,'SyScallForm');
ArMoudle:=LoadLibrary('.\Armdl.dll');
ArCallForm:=GetProcAddress(ArMoudle,'ArCallForm');
GlMoudle:=LoadLibrary('.\Glmdl.dll');
GlCallForm:=GetProcAddress(GlMoudle,'GlCallForm');
ScMoudle:=LoadLibrary('.\Scmdl.dll');
ScCallForm:=GetProcAddress(ScMoudle,'ScCallForm');
except
DispInfo('装载DLL出错!',1);
end;
DateSeparator:='.';
Shortdateformat:='yyyy.mm.dd';
Frm_Main.Height:=Screen.Height;
Frm_Main.Width:=Screen.Width;
Frm_Main.refresh;
//从INI获取口令
//Tmp_Inifile:=TInifile.Create(ExtractFilePath(Application.ExeName)+'Mrpii.ini');
//Tmp_lserverip:=Tmp_Inifile.reAdstring('System','serverip','');
//Tmp_ldataBaseName:=Tmp_Inifile.reAdstring('System','dataBaseName','');
//Tmp_ldbuserid:=Tmp_Inifile.reAdstring('System','dbuserid','');
//Tmp_ldbPass:=Tmp_Inifile.reAdstring('System','dbPass','');
//For i:=1 to Length(Tmp_ldbPass) do
// Tmp_ldbPass[i] := ChAr(170-ord(Tmp_ldbPass[i])+i) ;
//Tmp_Inifile.free;
//测试连接数据库
with AdoConnectMain do
begin
ConnectionString:='FILE Name=Mrpii.udl';
//'Provider=SQLOLEDB.1;'+
//'Password='+Tmp_ldbPass+';'+
//'Persist Security Info=True;'+
//'User ID='+Tmp_ldbuserid+';'+
//'Initial Catalog='+Tmp_ldataBaseName+';'+
//'Data Source='+Tmp_lserverip+'';
T1:=now(); //T1连接数据库的开始时间
end;
//连接数据库
if AdoConnectMain.Connected=False then
begin
Try
AdoConnectMain.Connected:=True;
Except
DispInfo('不能连接后台数据库,请与系统管理员联系',1);
end;
T2:=now(); //T2连接数据库的结束时间
T3:=T2-T1;
end;
//改变运行时Windows 状态栏上的Icon和TitleName
Application.Icon:=Frm_Main.Icon;
//获得 SysParamValueC以便给 Application.title,Frm_Main.Caption赋值
S:='select SysParamValueC from SysParam where SysParamCode=''Name0''';
if AdoQry_tmp.Active then AdoQry_tmp.Close;
AdoQry_tmp.SQL.clear;
AdoQry_tmp.SQL.Add(S);
AdoQry_tmp.Open;
Application.title:=AdoQry_tmp.fieldbyname('SysParamValueC').asstring+'制造资源计划管理系统';
AdoQry_tmp.Close;
//将SQL时的等待鼠标改成沙漏
Screen.cursors[crsqlwait]:=Screen.cursors[crhourGlass];
//定义日期格式
DateSeparator:='.';
Shortdateformat:='yyyy.mm.dd';
//局部私有变量初始化
F_LoginDate:=datetostr(date);
F_LoginId:='';
F_LoginName:='';
F_ModuleCode:='';
S:='select SysParamValueC from SysParam where SysParamCode=''Name0''';
if AdoQry_tmp.Active then AdoQry_tmp.Close;
AdoQry_tmp.SQL.clear;
AdoQry_tmp.SQL.Add(S);
AdoQry_tmp.Open;
Frm_Main.Caption:=AdoQry_tmp.fieldbyname('SysParamValueC').asstring+'制造资源计划管理系统';
AdoQry_tmp.Close;
//初始化状态栏
with StatusBar1 do
begin
Panels[0].Text :='软件提供者 info@soft.com';
Panels[2].text :='用户:';
Panels[3].text :='业务日期:';
end;
end;
procedure TFrm_Main.FormActivate(Sender: TObject);
var
S:string;
begin
//建立菜单
if MainMenu1.Items.Count=0 then
begin
with TFrm_Sys_Login.Create(Application) do
begin
InitForm(AdoConnectMain);
ShowModal;
if ModalResult=Mrok then
begin
repaint;
F_LoginId:=EmployeeCode;
F_LoginName:=EmployeeName;
createmenu; //创建菜单
StatusBar1.panels[2].text:='用户:'+F_LoginId+F_LoginName;
StatusBar1.panels[3].text:='业务日期:'+F_LoginDate;
//将连接耗时写入数据库
S:='insert UserConnectionTime'+
' (EmployeeCode,Starttime,endtime,Difftime)'+
' Values('+
Quotedstr(EmployeeCode)+','+
''''+Formatdatetime('yyyy.mm.dd hh:nn:ss.zzz',T1)+''''+','+
''''+Formatdatetime('yyyy.mm.dd hh:nn:ss.zzz',T2)+''''+','+
''''+Formatdatetime('yyyy.mm.dd hh:nn:ss.zzz',T3)+''''+
')';
if AdoQry_tmp.Active then AdoQry_tmp.Close;
AdoQry_tmp.SQL.clear;
AdoQry_tmp.SQL.Add(S);
AdoQry_tmp.Prepared;
AdoQry_tmp.ExecSQL;
if ShowPictrue=True then
begin
if Frm_Sys_Main=nil then //显示流程图
begin
try
Frm_Sys_Main:=TFrm_Sys_Main.Create(Frm_Main);
Frm_Sys_Main.Show;
finally
//Frm_Sys_Main.free;
end;
end;
end;
if PassOK=True then //修改密码
begin
if CheckBox1.Checked then
begin
Frm_Sys_ChangePassword:=TFrm_Sys_ChangePassword.Create(Frm_Main);
Frm_Sys_ChangePassword.SetSysParam(F_LoginId,F_ModuleCode,'mn0105',F_LoginDate);
Frm_Sys_ChangePassword.InitForm(Frm_Main.AdoQry_Tmp.Connection,False);
Frm_Sys_ChangePassword.ShowModal;
end;
end;
end
else
begin
Close;
Frm_Main.Close;
end;
Release;
end;
end;
end;
procedure TFrm_Main.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
i:integer;
begin
//是否建立了系统菜单,是则提示是否退出,
//否则在登录时已经提示
if MainMenu1.Items.Count<>0 then
if DispInfo(' 确认退出系统吗? ',2)='n' then
canClose:=False
else
with self do
for I := MDIChildCount-1 downto 0 do
MDIChildren[I].Close;
end;
procedure TFrm_Main.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
//系统内定的Ctrl+L热键,改变登录条件
if (key=ord('L')) and (shift-[sSalt]-[ssshift]+[sSCtrl]=shift) then
Frm_Sys_Login.Showmodal;
end;
procedure TFrm_Main.Createmenu;
var
PullDown:TMenuItem;
//Count 菜单基数目
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -