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

📄 mainfrm.pas

📁 供水营销打印程序源码
💻 PAS
字号:
unit MainFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, fcStatusBar, ExtCtrls, dxsbar, ImgList, ActnList, SJCustomBrowseFrm,
  Menus, ToolWin, ComCtrls, XPMenu, JvConnectNetwork, JvBaseDlg,
  PropStorageEh, JvFormWallpaper, dxDockControl, dxDockPanel, RM_FormReport;

type
  TSJBrowseFormClass = class of TSJCustomBrowseForm;

  TMainform = class(TForm)
    Statusbar: TfcStatusBar;
    SideBarStore: TdxSideBarStore;
    ActionList: TActionList;
    actCustomer: TAction;
    actWaterfee: TAction;
    ImageList: TImageList;
    actPrintInvoice: TAction;
    SideBarStoreItem1: TdxStoredSideItem;
    SideBarStoreItem2: TdxStoredSideItem;
    SideBarStoreItem3: TdxStoredSideItem;
    MainMenu: TMainMenu;
    mmiFile: TMenuItem;
    mmiEdit: TMenuItem;
    mmiTools: TMenuItem;
    mmiHelp: TMenuItem;
    ToolBar: TToolBar;
    XPMenu: TXPMenu;
    mmifSaveAs: TMenuItem;
    N1: TMenuItem;
    mmifClose: TMenuItem;
    mmifPreview: TMenuItem;
    mmifPrintSetup: TMenuItem;
    mmifPrint: TMenuItem;
    N2: TMenuItem;
    mmifLogoff: TMenuItem;
    N3: TMenuItem;
    mmifExitProgram: TMenuItem;
    mmieCut: TMenuItem;
    ActionsMenu: TActionList;
    actfSaveAs: TAction;
    actfCloseWindow: TAction;
    actfPreview: TAction;
    actfPrintSetup: TAction;
    actfPrint: TAction;
    actfLogoff: TAction;
    actfExit: TAction;
    acteCut: TAction;
    acteCopy: TAction;
    actePaste: TAction;
    acteSelectAll: TAction;
    acteFind: TAction;
    acteRefresh: TAction;
    mmieCopy: TMenuItem;
    mmiePaste: TMenuItem;
    N4: TMenuItem;
    mmieSelectAll: TMenuItem;
    N5: TMenuItem;
    mmieFind: TMenuItem;
    mmieRefresh: TMenuItem;
    acttConnectNetDriver: TAction;
    acttDisconnectNetDriver: TAction;
    C3: TMenuItem;
    D1: TMenuItem;
    actManageUser: TAction;
    actManageCode: TAction;
    SideBarStoreItem4: TdxStoredSideItem;
    SideBarStoreItem5: TdxStoredSideItem;
    actExitProgram: TAction;
    SideBarStoreItem6: TdxStoredSideItem;
    acttOptions: TAction;
    N6: TMenuItem;
    O1: TMenuItem;
    Images: TImageList;
    acttBackupfile: TAction;
    B1: TMenuItem;
    acthAbout: TAction;
    A3: TMenuItem;
    ConnectNetwork: TJvConnectNetwork;
    DisconnectNetwork: TJvDisconnectNetwork;
    tbSaveAs: TToolButton;
    ToolButton2: TToolButton;
    tbFind: TToolButton;
    tbRefresh: TToolButton;
    ToolButton5: TToolButton;
    tbCut: TToolButton;
    tbCopy: TToolButton;
    tbPaste: TToolButton;
    ToolButton9: TToolButton;
    tbExitProgram: TToolButton;
    tbPrint: TToolButton;
    tbPreview: TToolButton;
    ToolButton4: TToolButton;
    RegPropManager: TRegPropStorageManEh;
    PropStorage: TPropStorageEh;
    LeftDockPanel: TdxDockPanel;
    SideBar: TdxSideBar;
    DockingManager: TdxDockingManager;
    LeftDockSite: TdxDockSite;
    acttNavibar: TAction;
    N7: TMenuItem;
    N8: TMenuItem;
    MainDockPanel: TdxDockPanel;
    dxLayoutDockSite1: TdxLayoutDockSite;
    dxLayoutDockSite2: TdxLayoutDockSite;
    FormReport: TRMFormReport;
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure actCustomerExecute(Sender: TObject);
    procedure actWaterfeeExecute(Sender: TObject);
    procedure actPrintInvoiceExecute(Sender: TObject);
    procedure actManageCodeExecute(Sender: TObject);
    procedure actExitProgramExecute(Sender: TObject);
    procedure acttOptionsExecute(Sender: TObject);
    procedure acthAboutExecute(Sender: TObject);
    procedure acttConnectNetDriverExecute(Sender: TObject);
    procedure acttDisconnectNetDriverExecute(Sender: TObject);
    procedure acttBackupfileExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure tbExitProgramClick(Sender: TObject);
    procedure actfLogoffExecute(Sender: TObject);
    procedure acttNavibarExecute(Sender: TObject);
    procedure LeftDockPanelClose(Sender: TdxCustomDockControl);
  private
    FLogined: Boolean;
    FWinlist: TList;
    FCurrBrowse: TSJCustomBrowseForm;

    procedure ShowFormEx(FormClass: TSJBrowseFormClass; var Aform; AOwner:TComponent;
      AParent: TWinControl);
    procedure SetMainMenuAction;
  public
    procedure Login;
  end;

var
  Mainform: TMainform;

implementation

uses SJInvPrintGlobal, InvPrintDM, Registry, DatabaseConfirmPropertyFrm, sjUtils,
  LoginFrm, CustomerBrowseFrm, WaterfeeBrowseFrm, InvoicePrintBrowseFrm,
  CodeManagerPropertyFrm, OptionsPropertyFrm, AboutPropertyFrm;

{$R *.dfm}

{ TMainform }

procedure TMainform.FormActivate(Sender: TObject);
// 初始化系统
const
  ConnStr = 'Provider=MSDataShape.1;Data Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s';
begin
  // 对数据库进行配置
  {if not gCanConnect then
    with TfrmPropertyDatabaseConfirm.Create(Application) do
    try
      if ShowModal = mrCancel then
      begin
        ShowMessage('你没有正确的配置系统参数,程序将马上退出。');
        Application.Terminate;
      end;

      GCanConnect := True;
      dmInvPrint.ADOConnection.ConnectionString := Format(ConnStr, [GSysDataPath + gSysDatafile]);
      dmInvPrint.OpenCodeTable;
    finally
      Free;
    end;}
    
  // 打开系统所有的代码表
  if gCanConnect then dmInvPrint.OpenCodeTable else Application.Terminate;

  if not FLogined then
    Login;

  PropStorage.LoadProperties;
  PropStorage.Active := True;
end;

procedure TMainform.FormCreate(Sender: TObject);
//
begin
  FLogined    := False;
  gSysPath    := ExtractFilePath(Application.ExeName); // 系统安装目录
  gUserName   := 'Administrator';
  gUserID     := '00000';

  FWinlist    := TList.Create;
  FCurrBrowse := nil;
end;

procedure TMainform.Login;
// 用户进行登录或注销操作
var
  AReg: TRegistry;
begin
  AReg := TRegistry.Create;

  // 用户登录
  with TfrmPropertyLogin.Create(Application) do
  try
    if gLogined then
      Caption := '注销当前用户';

    // 如果没有通过密码验证则退出系统
    if ShowModal <> mrOK then
      Application.Terminate;

    // 记录当前用户资料
    FLogined  := True;
    GUserID   := edtUser.EditValue;
    GUserName := edtUser.EditText;
    GLogined  := True;
    GREGUserSetting := Format(GREGUserSetting, [Prefixstr('0', GUserID, 5)]);
    GSysDataPath := ExtractFilePath(Application.ExeName) + 'Data\';
    //mmisUser.Caption := gUserName;

    // 将当前用户编号写入注册表
    with AReg do
    begin
      RootKey := HKEY_LOCAL_MACHINE;
      if OpenKey(GREGsysPath, True) then
        WriteString('Default User', GUserID);
      CloseKey;
    end;

  finally
    AReg.Free;
    Free;
  end;

  Statusbar.Panels.PanelByName('pnlUsername').Text := GUsername;
end;

procedure TMainform.FormDestroy(Sender: TObject);
// 释放系统资源
{var
  I: Integer;}
begin
  //for I := Fwinlist.Count - 1 downto 0 do
  //  TSJCustomBrowseForm(Fwinlist[I]).Close;
  FreeAndNil(FWinlist);
end;

procedure TMainform.ShowFormEx(FormClass: TSJBrowseFormClass; var Aform;
  AOwner: TComponent; AParent: TWinControl);
// 打开一个窗口,如果此窗口已经存在则显示它否则创建窗口实例并将其加入窗口列表中
var
  I: Integer;
  Achild: TSJCustomBrowseForm;
begin
  Screen.Cursor:=crHourGlass;
  try
    I := FWinlist.IndexOf(Pointer(Aform));
    if I <> -1 then
    begin
      Achild := TSJCustomBrowseForm(FWinlist[I]);
      if Achild.WindowState = wsMinimized then
        ShowWindow(Achild.Handle, SW_SHOWNORMAL)
      else
        ShowWindow(Achild.Handle, SW_SHOWNA);
      if not Achild.Visible then
        Achild.Show;
      Achild.BringToFront;
      Achild.SetFocus;
      FCurrBrowse := Achild;
      TSJCustomBrowseForm(Aform) := Achild;
    end else
    begin
      Achild := TSJCustomBrowseForm(FormClass.NewInstance);
      TSJCustomBrowseForm(Aform) := Achild;
      if not GAppMDIStyle and Assigned(AParent) then
        Achild.Create(AOwner, AParent)
      else
        Achild.Create(AOwner);
      FCurrBrowse := Achild;
      FWinlist.Add(Pointer(Aform));
      Achild.BringToFront;
      Achild.Show;
    end;
  finally
    Screen.Cursor := crDefault;
  end;
end;

procedure TMainform.actCustomerExecute(Sender: TObject);
begin
  ShowFormEx(TfrmBrowseCustomer, frmBrowseCustomer, Application, MainDockPanel);
  SetMainMenuAction;
end;

procedure TMainform.actWaterfeeExecute(Sender: TObject);
begin
  ShowformEx(TfrmBrowseWaterfee, frmBrowseWaterfee, Application, MainDockPanel);
  SetMainMenuAction;
end;

procedure TMainform.actPrintInvoiceExecute(Sender: TObject);
begin
  ShowFormEx(TfrmBrowseInvoicePrint, frmBrowseInvoicePrint, Application, MainDockPanel);
  SetMainMenuAction;
end;

procedure TMainform.actManageCodeExecute(Sender: TObject);
// 系统代码管理
begin
  with TfrmPropertyCodeManager.Create(Application) do
  try
    ShowModal;
  finally
    Free;
  end;

end;

procedure TMainform.actExitProgramExecute(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TMainform.acttOptionsExecute(Sender: TObject);
// 系统选项
begin
  with TfrmPropertyOptions.Create(Application) do
  try
    ShowModal;
  finally
    Free;
  end;

end;

procedure TMainform.acthAboutExecute(Sender: TObject);
begin
  with TfrmPropertyAbout.Create(Application) do
  try
    ShowModal;
  finally
    Free;
  end;

end;

procedure TMainform.acttConnectNetDriverExecute(Sender: TObject);
// 映射网络驱动器
begin
  ConnectNetWork.Execute;
end;

procedure TMainform.acttDisconnectNetDriverExecute(Sender: TObject);
// 断开网络驱动器
begin
  DisConnectNetwork.Execute;
end;

procedure TMainform.acttBackupfileExecute(Sender: TObject);
// 备份文件
var
  Afilename, Adir: string;
begin
  Adir := ExtractFilePath(Application.ExeName) + 'Backup';
  if not DirectoryExists(Adir) then
    ForceDirectories(Adir);

  Afilename := ExtractFilePath(Application.ExeName) + 'Data\' + GSysDatafile;
  Screen.Cursor := crHourGlass;
  try
    Statusbar.Panels[0].Text := '正在备份数据,请稍后......';
    try
      CopyFile(Pchar(Afilename), Pchar(Adir + '\' + GSysDatafile), False);
    except
      ShowMessage('备份数据文件失败,请稍后再试 。');
    end;
  finally
    Statusbar.Panels[0].Text := '';
    Screen.Cursor := crDefault;
  end;

end;

procedure TMainform.FormClose(Sender: TObject; var Action: TCloseAction);
// 系统退出时自动备份数据文件
begin
  acttBackupfile.Execute;
end;

procedure TMainform.SetMainMenuAction;
// 设置主菜单的动作列表
begin
  if not Assigned(FcurrBrowse) then
    Exit;

  with FCurrBrowse do
  begin
    mmifSaveAs.Action     := actBrowseSaveAs;
    mmifPreview.Action    := actBrowsePreview;
    mmifPrintSetup.Action := actBrowsePrintSetup;
    mmifPrint.Action      := actBrowsePrint;
    mmieCut.Action        := actBrowseCut;
    mmieCopy.Action       := actBrowseCopy;
    mmiePaste.Action      := actBrowsePaste;
    mmieSelectAll.Action  := actBrowseSelectAll;
    mmieFind.Action       := actBrowseFind;
    mmieRefresh.Action    := actBrowseRefresh;

    tbSaveAs.Action       := actBrowseSaveAs;
    tbFind.Action         := actBrowseFind;
    tbRefresh.Action      := actBrowseRefresh;
    tbCut.Action          := actBrowseCut;
    tbCopy.Action         := actBrowseCopy;
    tbPaste.Action        := actBrowsePaste;
    tbPrint.Action        := actBrowsePrint;
    tbPreview.Action      := actBrowsePreview;
  end;
end;

procedure TMainform.tbExitProgramClick(Sender: TObject);
begin
  actExitProgram.Execute;
end;

procedure TMainform.actfLogoffExecute(Sender: TObject);
// 注销当前用户
begin
  Login;
end;

procedure TMainform.acttNavibarExecute(Sender: TObject);
// 显示或隐藏导航栏
begin
  acttNavibar.Checked   := not acttNavibar.Checked;
  LeftDockPanel.Visible := acttNavibar.Checked;
end;

procedure TMainform.LeftDockPanelClose(Sender: TdxCustomDockControl);
begin
  acttNavibar.Checked := False;
end;

end.

⌨️ 快捷键说明

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