⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 erpmain.pas.svn-base

📁 这是一个功能齐全的,代码完整的ERP企业信息管理系统,现在上传和大家分享
💻 SVN-BASE
字号:
unit ErpMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Menus, DB, ADODB, ComCtrls, WinSkinData,
  SkinCaption, StdCtrls;

type
  TErpMainForm = class(TForm)
    ADOQuery1: TADOQuery;
    StatusBar1: TStatusBar;
    SkinData1: TSkinData;
    SkinCaption1: TSkinCaption;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure MenuItemClick(Sender: TObject);
    procedure FormCanResize(Sender: TObject; var NewWidth,
      NewHeight: Integer; var Resize: Boolean);
    procedure FormShow(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    ANameList:TStringList;
    procedure SetInterface;
    procedure SetWindowsMenu(ANameList:TStringList);
    procedure UnloadModuleFormInstances(AModule: Longword);
    function CreateForm(AFormName:string):string;
    { Private declarations }
  public
    { Public declarations }
    procedure ActiveFormChange(Sender: TObject);
    procedure DisplayHint(Sender: TObject);
    function AppHtmlHelp(Command: Word; Data: Longint;
      var CallHelp: Boolean): Boolean;
  end;

//重新登录
procedure ReLogin;
procedure ShowChildForm;

var
  ErpMainForm: TErpMainForm;

implementation

uses SYSDATA, CommFun, SysW00_01, CshW00_01, CwaW00_01, HrmW00_01,
  PayW00_01, Welcome, Wait, Sys700_01, TasW00_01, SerW00_01, ResW00_01,
  OrdW00_01, OrdW01_01, InvW00_01, PurW00_01, Sys800_01;

{$R *.dfm}

//重新登录
procedure ReLogin;
begin
  Screen.Cursor:=crHourGlass;
  AStartTime:=GetTickCount;
  Sys700_01Form:=TSys700_01Form.Create(Application);
  ShowRunTime;  //显示程序执行时间
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('delete from SYS500E where S500E_001='+IntToStr(AUserID));
  SYSDM.qryQuery.ExecSQL;
  Screen.Cursor:=crDefault;
  if Sys700_01Form.ShowModal=1 then
  begin
    ErpMainForm.SetInterface;
    ShowChildForm;
  end else
  begin
    Application.Terminate;
  end;
end;

procedure TErpMainForm.DisplayHint(Sender: TObject);
begin
  if Application.Hint<>'' then
  begin
    if Pos(GetDBString('HWERP100058'),Application.Hint)=0 then ARunTime:=0;
    StatusBar1.Panels[0].Text:=GetDBString('HWERP100047')+Application.Hint  //'状态:'
  end else
  begin
    if ARunTime=0 then StatusBar1.Panels[0].Text:=GetDBString('HWERP100043');  //'状态:就绪'
  end;
end;

function TErpMainForm.AppHtmlHelp(Command: Word; Data: Longint;
  var CallHelp: Boolean): Boolean;
var
  Ret:Integer;
begin
  Ret:=0;
  Result:=False;
  if not CallHelp then Exit;
  case Command of
    HELP_FINDER, HELP_CONTENTS: Ret := HtmlHelp(Application.Handle, PChar(AHelpFile), $0001, nil);
    HELP_QUIT:                  Ret := HtmlHelp(Application.Handle, '', $0012, nil);
    HELP_CONTEXT:               Ret := HtmlHelp(Application.Handle, PChar(AHelpFile), $000f, DWORD_PTR(Data));  //Data:HelpContext的值
  end;
  Result:=Ret<>0;
  CallHelp:=False;
end;

procedure TErpMainForm.ActiveFormChange(Sender: TObject);
begin
//  SetCaption(Self,GetDBString('HWERP100001')+' - '+ACompanyName+' - ['+Screen.ActiveForm.Caption+']');  //浩晖企业管理系统
end;

procedure TErpMainForm.SetInterface;
begin
  //设置公司名称
  Screen.OnActiveFormChange:=ActiveFormChange;
//  SetCaption(Self,GetDBString('HWERP100001')+' - '+ACompanyName);  //浩晖企业管理系统
  Caption:=GetDBString('HWERP100001')+' - '+ACompanyName;   //'浩晖企业管理系统'
  StatusBar1.Panels[0].Text:=GetDBString('HWERP100043');  //'状态:就绪'
  StatusBar1.Panels[1].Text:=GetDBString('HWERP100044')+AUserName;  //'用户名:'
  StatusBar1.Panels[2].Text:=GetDBString('HWERP100045');  //热线电话:0769-6896757
  StatusBar1.Panels[3].Text:=GetDBString('HWERP100046')+FormatDateTime('yyyy-mm-dd', Date);  //'日期:'
end;

procedure TErpMainForm.SetWindowsMenu(ANameList:TStringList);
var
  I,J,K:Integer;
  AMenuItem,AWindowMenu:TMenuItem;
  AForm1,AForm2:TForm;
begin
  for I:=0 to ANameList.Count-1 do
  begin
    AForm1:=nil;
    AForm2:=nil;
    for K:=0 to MDIChildCount-1 do
      if MDIChildren[K].Name=ANameList[I] then AForm1:=MDIChildren[K];
    AWindowMenu:=AForm1.WindowMenu;
    if AWindowMenu=nil then Continue;
    AMenuItem:=TMenuItem.Create(AWindowMenu);
    AMenuItem.Caption:='-';
    AWindowMenu.Add(AMenuItem);
    for J:=0 to ANameList.Count-1 do
    begin
      for K:=0 to MDIChildCount-1 do
        if MDIChildren[K].Name=ANameList[J] then AForm2:=MDIChildren[K];
      AMenuItem:=TMenuItem.Create(AWindowMenu);
      AMenuItem.Caption:=AForm2.Caption;
      AMenuItem.Name:=ANameList[J];
      AMenuItem.OnClick:=MenuItemClick;
      if AForm2.Name=AForm1.Name then
        AMenuItem.Checked:=True
      else
        AMenuItem.Checked:=False;
      AWindowMenu.Add(AMenuItem);
    end;
    SkinData1.AddNestForm(Self,AForm1);
  end;
end;

procedure TErpMainForm.UnloadModuleFormInstances(AModule: Longword);
var
  I:integer;
begin
  if Application.Terminated then Exit;
  for I:=0 to Application.ComponentCount-1 do
  begin
    if FindClassHInstance(Application.Components[I].ClassType)=AModule then
      Components[I].Free;
  end;
end;

//自动备份数据
procedure AutoBackupData;
var
  AFile,APath:string;
  ADate:TDateTime;
begin
  if GetSysParams('SYS0016')<>'Y' then Exit;
  APath:=GetSysParams('SYS0017');
  if copy(APath,Length(APath),1)<>'\' then APath:=APath+'\';
  if trim(APath)='' then APath:=ASystemPath+'Data\';
  if not DirectoryExists(APath) then
  begin
    ShowMsg('UMS10000343');  //无法连接到备份数据的路径,无法备份数据,如果再次出现该问题请联系系统管理员
    Exit;
  end;

  ADate:=GetServerDate;
  AFile:=GetBackupFile(ADate);
  if FileExists(APath+AFile+'.dat') then
  begin
    //文件已存在,是否覆盖原文件?
    if ShowDialog('['+AFile+'.dat]'+GetDBString('UMS10000109'),1)=IDNO then Exit;
    DeleteFile(APath+AFile+'.dat');
  end;
  case ADatabase of  //0=Access,1=SQL Server
    0:BackupAccessDB(APath+AFile+'.dat',ADate);
    1:BackupSQLDB(AFile,ADate);
  end;
end;

procedure TErpMainForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
//var
//  I:Integer;
begin
  if AIsExit then
  begin
    if ActiveMDIChild<>nil then WriteReg('WorkBench',ActiveMDIChild.Name,1);
{    LockWindowUpdate(Handle);
    Hide;
    for I:=0 to MDIChildCount-1 do
    begin
      MDIChildren[I].Close;
    end;   }
    Action := caFree;
    Exit;
  end;
  if ShowDialog('UMS10000026')=IDYES then   //是否退出浩晖企业管理系统?
  begin
    Update;
    //删除当前用户的在线信息
    SYSDM.qryQuery.Close;
    SYSDM.qryQuery.SQL.Clear;
    SYSDM.qryQuery.SQL.Add('delete from SYS500E where S500E_001='+IntToStr(AUserID));
    SYSDM.qryQuery.ExecSQL;
    WriteReg('LoginOut','Y',1);
    //自动备份数据
    AutoBackupData;
    if ActiveMDIChild<>nil then WriteReg('WorkBench',ActiveMDIChild.Name,1);
{    LockWindowUpdate(Handle);
    Hide;
    for I:=0 to MDIChildCount-1 do
    begin
      MDIChildren[I].Close;
    end;
    LockWindowUpdate(0);  }
    Action := caFree;
  end else
    Action := caNone;
end;

procedure TErpMainForm.FormDestroy(Sender: TObject);
var
  I:Integer;
begin
  if APackageHandle=nil then Exit;
  for I:=0 to APackageHandle.Count-1 do
  begin
    UnloadModuleFormInstances(StrToInt(APackageHandle[I]));
    UnRegisterModuleClasses(StrToInt(APackageHandle[I]));
    UnloadPackage(StrToInt(APackageHandle[I]));
  end;
  APackageHandle.Free;
  FreeLibrary(AHandle);
end;

procedure TErpMainForm.MenuItemClick(Sender: TObject);
var
  AProgram:string;
begin
  Screen.Cursor:=crHourGlass;
  LockWindowUpdate(Handle);
  AProgram:=copy(TMenuItem(Sender).Name,1,6);
  IsWorkBench(AProgram);
  LockWindowUpdate(0);
  Screen.Cursor:=crDefault;
end;

function TErpMainForm.CreateForm(AFormName:string):string;
begin
  Result:='';
  AModule:=copy(UpperCase(AFormName),1,3);
  if UpperCase(AFormName)='SYSW00' then
  begin
    if Assigned(SysW00_01Form) then SysW00_01Form.Free;
    SysW00_01Form:=TSysW00_01Form.Create(Application);
    SysW00_01Form.Show;
    Result:=SysW00_01Form.Name;
  end else
  if UpperCase(AFormName)='CSHW00' then
  begin
    if Assigned(CshW00_01Form) then CshW00_01Form.Free;
    CshW00_01Form:=TCshW00_01Form.Create(Application);
    CshW00_01Form.Show;
    Result:=CshW00_01Form.Name;
  end else
  if UpperCase(AFormName)='HRMW00' then
  begin
    if Assigned(HrmW00_01Form) then HrmW00_01Form.Free;
    HrmW00_01Form:=THrmW00_01Form.Create(Application);
    HrmW00_01Form.Show;
    Result:=HrmW00_01Form.Name;
  end else
  if UpperCase(AFormName)='CWAW00' then
  begin
    if Assigned(CwaW00_01Form) then CwaW00_01Form.Free;
    CwaW00_01Form:=TCwaW00_01Form.Create(Application);
    CwaW00_01Form.Show;
    Result:=CwaW00_01Form.Name;
  end else
  if UpperCase(AFormName)='PAYW00' then
  begin
    if Assigned(PayW00_01Form) then PayW00_01Form.Free;
    PayW00_01Form:=TPayW00_01Form.Create(Application);
    PayW00_01Form.Show;
    Result:=PayW00_01Form.Name;
  end else
  if UpperCase(AFormName)='TASW00' then
  begin
    if Assigned(TasW00_01Form) then TasW00_01Form.Free;
    TasW00_01Form:=TTasW00_01Form.Create(Application);
    TasW00_01Form.Show;
    Result:=TasW00_01Form.Name;
  end else
  if UpperCase(AFormName)='SERW00' then
  begin
    if Assigned(SerW00_01Form) then SerW00_01Form.Free;
    SerW00_01Form:=TSerW00_01Form.Create(Application);
    SerW00_01Form.Show;
    Result:=SerW00_01Form.Name;
  end else

  if UpperCase(AFormName)='DDMW00' then
  begin
//    if Assigned(DdmW00_01Form) then DdmW00_01Form.Free;
//    DdmW00_01Form:=TDdmW00_01Form.Create(Application);
//    DdmW00_01Form.Show;
//    Result:=DdmW00_01Form.Name;
  end else
  if UpperCase(AFormName)='RESW00' then
  begin
    if Assigned(ResW00_01Form) then ResW00_01Form.Free;
    ResW00_01Form:=TResW00_01Form.Create(Application);
    ResW00_01Form.Show;
    Result:=ResW00_01Form.Name;
  end else
  if UpperCase(AFormName)='ORDW00' then
  begin
    if Assigned(OrdW00_01Form) then OrdW00_01Form.Free;
    OrdW00_01Form:=TOrdW00_01Form.Create(Application);
    OrdW00_01Form.Show;
    Result:=OrdW00_01Form.Name;
  end else
  if UpperCase(AFormName)='ORDW01' then
  begin
    if Assigned(OrdW01_01Form) then OrdW01_01Form.Free;
    OrdW01_01Form:=TOrdW01_01Form.Create(Application);
    OrdW01_01Form.Show;
    Result:=OrdW01_01Form.Name;
  end else
  if UpperCase(AFormName)='INVW00' then
  begin
    if Assigned(InvW00_01Form) then InvW00_01Form.Free;
    InvW00_01Form:=TInvW00_01Form.Create(Application);
    InvW00_01Form.Show;
    Result:=InvW00_01Form.Name;
  end else
  if UpperCase(AFormName)='PURW00' then
  begin
    if Assigned(PurW00_01Form) then PurW00_01Form.Free;
    PurW00_01Form:=TPurW00_01Form.Create(Application);
    PurW00_01Form.Show;
    Result:=PurW00_01Form.Name;
  end;
end;

procedure TErpMainForm.FormCreate(Sender: TObject);
begin
  Application.HelpFile:=AHelpFile;
  Application.OnHelp:=AppHtmlHelp;
  Application.OnHint:=DisplayHint;
  SetInterface;
  StatusBar1.Panels[0].Width:=Width-StatusBar1.Panels[1].Width-
                              StatusBar1.Panels[2].Width-StatusBar1.Panels[3].Width;
end;

procedure TErpMainForm.FormCanResize(Sender: TObject; var NewWidth,
  NewHeight: Integer; var Resize: Boolean);
begin
  StatusBar1.Panels[0].Width:=Width-StatusBar1.Panels[1].Width-
                              StatusBar1.Panels[2].Width-StatusBar1.Panels[3].Width;
end;

procedure ShowChildForm;
var
  AFormName,S:String;
  I:Integer;
begin
  with ErpMainForm do
  begin
    for I:=MDIChildCount-1 downto 0 do
    begin
      MDIChildren[I].WindowMenu.Clear;
      MDIChildren[I].Close;
    end;
    ANameList:=TStringList.Create;
    S:=CreateForm('SYSW00');
    if S<>'' then ANameList.Add(S);
    ADOQuery1.Close;
    ADOQuery1.SQL.Clear;
    if ASuper then
      ADOQuery1.SQL.Add('select B.S500D_001 from SYS500B A,SYS500D B where A.S500B_002=B.S500D_011 and B.S500D_006='+GetBoolean(True)+' and B.S500D_010=''W'' and A.S500B_001='+IntToStr(AUserID))
    else
      ADOQuery1.SQL.Add('select B.S500D_001 from SYS500B A,SYS500D B where A.S500B_002=B.S500D_011 and B.S500D_006='+GetBoolean(True)+' and B.S500D_010=''W'' and A.S500B_004='+GetBoolean(True)+' and A.S500B_001='+IntToStr(AUserID));
    ADOQuery1.Open;
    while not ADOQuery1.Eof do
    begin
      AFormName:=ADOQuery1.Fields[0].AsString;
      S:=CreateForm(AFormName);
      if S<>'' then ANameList.Add(S);
      ADOQuery1.Next;
    end;
    SetWindowsMenu(ANameList);
    ANameList.Free;
    AFormName:=ReadReg('WorkBench',1);
    IsWorkBench(copy(AFormName,1,6));
  end;
end;

procedure TErpMainForm.FormShow(Sender: TObject);
begin
  Screen.Cursor:=crHourGlass;
  ShowWindow(Handle,SW_HIDE);
  LockWindowUpdate(Handle);
  ShowChildForm;
  LockWindowUpdate(0);
  ShowWindow(Handle,SW_SHOW);
  AFormColor:=SkinData1.Colors[csButtonFace];
  ADisableColor:=$00DDDDDD;  //$00D7A88E SkinData1.Colors[csMenuBar];
  AEnableColor:=clWindow;
  Screen.Cursor:=crDefault;
end;

procedure TErpMainForm.FormActivate(Sender: TObject);
begin
  SYSDM.qrySys800.Close;
  SYSDM.qrySys800.SQL.Clear;
  SYSDM.qrySys800.SQL.Add('select * from HwSystem where FInstall=-1');
  SYSDM.qrySys800.Open;
  if (SYSDM.qrySys800.IsEmpty) and (not Application.Terminated) then
  begin
    Sys800_01Form:=TSys800_01Form.Create(Application);
    if Sys800_01Form.ShowModal=1 then Application.Terminate;
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -