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

📄 mainunit.pas

📁 华海成本核算辅助系统是基于用友U8企业资源管理系统开发的一套半成品成本统计分析软件。本软件界面美观、初始化简单、操作快捷、功能全面、报表多样等优点
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit MainUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,ConfigObjectUnit,ADODB,AdoConEd, DB,IniFiles, StdCtrls, Mask,
  RzEdit, RzBckgnd, RzSplit, ExtCtrls, RzPanel, ComCtrls, RzDTP, RzLabel,
  cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, cxDBData, cxGridLevel, cxClasses, cxControls, cxGridCustomView,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid,
  RzButton, ImgList, EXLReportExcelTLB, EXLReportBand, EXLReport, Grids,
  DBGrids, RzCmboBx, QRExport, Menus, jpeg,ShellApi ;

type
  Tfrm_main = class(TForm)
    RzPanel1: TRzPanel;
    RzSizePanel1: TRzSizePanel;
    RzSeparator1: TRzSeparator;
    edtdep: TRzNumericEdit;
    lbl1: TRzLabel;
    rzgrpbx1: TRzGroupBox;
    RzLabel1: TRzLabel;
    RzLabel2: TRzLabel;
    dtpBegin: TRzDateTimePicker;
    dtpEnd: TRzDateTimePicker;
    lblCurDate: TRzLabel;
    lblDepreciation: TRzLabel;
    RzToolbar1: TRzToolbar;
    ilList: TImageList;
    btnDataBaseSet: TRzToolButton;
    btnExecute: TRzToolButton;
    btnBtnExport: TRzToolButton;
    btnPrint: TRzToolButton;
    rzspcr1: TRzSpacer;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    btnExit: TRzToolButton;
    dsResult: TDataSource;
    cxgrdbclmncode: TcxGridDBColumn;
    cxgrdbclmnname: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxstyl1: TcxStyle;
    GridTableViewStyleSheetDevExpress: TcxGridTableViewStyleSheet;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle3: TcxStyle;
    cxStyle4: TcxStyle;
    cxStyle5: TcxStyle;
    cxStyle6: TcxStyle;
    cxStyle7: TcxStyle;
    cxStyle8: TcxStyle;
    cxStyle9: TcxStyle;
    cxStyle10: TcxStyle;
    cxStyle11: TcxStyle;
    cxStyle12: TcxStyle;
    cxStyle13: TcxStyle;
    cxStyle14: TcxStyle;
    cxgrdbclmntheunit: TcxGridDBColumn;
    minute: TcxGridDBColumn;
    cxgrdbclmnyuan: TcxGridDBColumn;
    cxgrdbclmnoutfee: TcxGridDBColumn;
    cxgrdbclmnblack: TcxGridDBColumn;
    cxgrdbclmnother: TcxGridDBColumn;
    cxgrdbclmnplan: TcxGridDBColumn;
    cxgrdbclmncost: TcxGridDBColumn;
    cxgrdbclmnscost: TcxGridDBColumn;
    cxgrdbclmncount: TcxGridDBColumn;
    cxgrdbclmnallcost: TcxGridDBColumn;
    cxgrdbclmnwork: TcxGridDBColumn;
    cxGrid1DBTableView1DBColumn1: TcxGridDBColumn;
    cxgrdbclmnGrid1DBTableView1DBColumn2: TcxGridDBColumn;
    cxgrdbclmnGrid1DBTableView1DBColumn3: TcxGridDBColumn;
    cbbType: TRzComboBox;
    RzLabel3: TRzLabel;
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    N4: TMenuItem;
    W1: TMenuItem;
    R1: TMenuItem;
    R2: TMenuItem;
    N5: TMenuItem;
    P1: TMenuItem;
    ExcelE1: TMenuItem;
    Z1: TMenuItem;
    R3: TMenuItem;
    ExcelE2: TMenuItem;
    N6: TMenuItem;
    P2: TMenuItem;
    ExcelE3: TMenuItem;
    W2: TMenuItem;
    P3: TMenuItem;
    ExcelE4: TMenuItem;
    pmreport: TPopupMenu;
    N7: TMenuItem;
    pmexcel: TPopupMenu;
    N8: TMenuItem;
    N9: TMenuItem;
    N10: TMenuItem;
    N11: TMenuItem;
    N12: TMenuItem;
    N13: TMenuItem;
    N14: TMenuItem;
    N15: TMenuItem;
    P4: TMenuItem;
    ExcelE5: TMenuItem;
    N16: TMenuItem;
    N17: TMenuItem;
    N18: TMenuItem;
    N19: TMenuItem;
    RzToolButton1: TRzToolButton;
    rzspcr2: TRzSpacer;
    RzSpacer1: TRzSpacer;
    RzSpacer2: TRzSpacer;
    Image1: TImage;
    H1: TMenuItem;
    H2: TMenuItem;
    procedure btnDataBaseSetClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure dtpEndChange(Sender: TObject);
    procedure edtdepExit(Sender: TObject);
    procedure btnExecuteClick(Sender: TObject);
    procedure btnExitClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure P1Click(Sender: TObject);
    procedure ExcelE1Click(Sender: TObject);
    procedure R3Click(Sender: TObject);
    procedure ExcelE2Click(Sender: TObject);
    procedure P3Click(Sender: TObject);
    procedure ExcelE4Click(Sender: TObject);
    procedure P2Click(Sender: TObject);
    procedure ExcelE3Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure R1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure P4Click(Sender: TObject);
    procedure ExcelE5Click(Sender: TObject);
    procedure N19Click(Sender: TObject);
    procedure H2Click(Sender: TObject);
  private
    { Private declarations }
    FConfig : TConfig ;
    FIniFile : TIniFile ;
    FPath : string ;
    FCalculated : Boolean ;
    procedure ReadConfig();
    procedure IniForm();
    procedure doCalculate();
    procedure doPrint();
    procedure doExportToExcel();
    function SetConnection(aPath : String):Boolean ;
    function GetIniFile(aPath : string ) : Boolean  ;
  public
    { Public declarations }
  end;

var
  frm_main: Tfrm_main;

implementation

uses ConfigUnit, CommonUnit, DMsemiUnit, CalculateThreadUnit, EventUnit,
  InformationUnit, ReportUnit, report2Unit, Report3Unit, Report4Unit,
  Report5Unit;

{$R *.dfm}

{ Tfrm_main }

function Tfrm_main.GetIniFile(aPath: string): Boolean  ;
begin
  FIniFile := TIniFile.Create(aPath);
  IniOptions.LoadSettings(FIniFile);
  Result := True ;
end;

procedure Tfrm_main.ReadConfig;
begin
  FPath := ExtractFilePath(Application.ExeName);
  FPath := IncludeTrailingPathDelimiter(FPath )+ 'config.ini';
  FConfig := TConfig.Create ;
  if not FileExists(FPath ) then
     FileCreate(FPath );
  GetIniFile(FPath) ;
  FConfig.Path := IniOptions.databasepath ;
  FConfig.BeginDate := IniOptions.parambegindate ;
  FConfig.EndDate := IniOptions.paramenddate ;
  FConfig.DepreValue := IniOptions.paramdepreciation ;
end;

function Tfrm_main.SetConnection(aPath : String): Boolean;
var
  lConStr : string ;
  liniFile : TIniFile ;
begin
 // liniFile := TIniFile.Create(FPath );
  try
    DMSemi.conDatabase.Close ;
    DMSemi.conDatabase.ConnectionString := '';
    if EditConnectionString(DMSemi.conDatabase) then
    begin
     // Sleep(1000);
      lConStr := DMSemi.conDatabase.ConnectionString ;
      IniOptions.databasepath := lConStr ;
    end;
  finally
  //  liniFile.Free ;
  end;
end;

procedure Tfrm_main.btnDataBaseSetClick(Sender: TObject);
begin
  SetConnection(FPath);
end;

procedure Tfrm_main.IniForm;
var
  lInx : Integer ;
begin
   gCalculateEvent := TAttendanceEvent.Create ;
   ReadConfig();
   if(IniOptions.parambegindate<>'') then
   begin
      try
        dtpBegin.Date := StrToDate(IniOptions.parambegindate) ;
        dtpEnd.Date := StrToDate(IniOptions.paramenddate);
        lblCurDate.Caption := '当前会计区间:从 [' + IniOptions.parambegindate
                             +'] 到 [' + IniOptions.paramenddate +']';
      except
      end;
   end
   else
      lblCurDate.Caption := '当前没有设置会计区间';
    edtdep.Value := IniOptions.paramdepreciation ;
    lblDepreciation.Caption := '当前折旧费用:' + FloatToStr(edtdep.Value );
    cbbtype.Items.Clear ;
    for linx := Low(aryDepName) to High(aryDepName)  do
      cbbType.Items.Add(aryDepName[linx]);
    cbbType.ItemIndex := 0 ;
end;

procedure Tfrm_main.FormShow(Sender: TObject);
begin
//  if date()>strtodate('2008-2-28') then
//  begin
//    application.MessageBox('该程序是测试程序,已过期,请及时和开发商联系 13067960603 !','系统提示',MB_OK );
//    application.Terminate;
//  end
//  else
//  begin
//    application.MessageBox('该程序是测试程序,请在备份数据库中使用,若发现问题,请及时与我联系 13067960603 !','科海软件--系统提示',MB_OK );
//  end;

  IniForm();
end;

procedure Tfrm_main.dtpEndChange(Sender: TObject);
begin
//  IniOptions.SaveSettings(FIniFile );
end;

procedure Tfrm_main.edtdepExit(Sender: TObject);
begin
  IniOptions.paramdepreciation := edtdep.Value ;
  //IniOptions.SaveSettings(FIniFile );
end;

procedure Tfrm_main.btnExecuteClick(Sender: TObject);
begin
  try
  
  if (dtpBegin.Date > dtpEnd.Date ) then
  begin
    Application.MessageBox('会计区间开始日期不能大于结束日期!', '系统提示', 
      MB_OK);
    Exit ;  
  end;

  IniOptions.parambegindate := FormatDateTime('yyyy-mm-dd',dtpBegin.Date );
  IniOptions.paramenddate := FormatDateTime('yyyy-mm-dd',dtpEnd.Date );

    if IniOptions.databasepath ='' then
      raise ECheckException.Create('没有数据库配置信息不能执行操作!');

    if dmsemi.setInitData = false  then
        raise ECheckException.Create('数据库配置信息不正确,请重新配置!');
    case (Sender as TRzToolButton).Tag of
      1: doCalculate ;
      2: doPrint ;
      3: doExportToExcel ;
    end;
  except
    on E: Exception do
    begin
      if E is ECheckException then
        Application.MessageBox(PChar(E.message), '系统提示', MB_OK)
      else
        Application.MessageBox(PChar('系统出错,错误码代码是:'+ e.Message),
         '系统提示', MB_OK);
    end;
  end;
end;

procedure Tfrm_main.btnExitClick(Sender: TObject);
begin
  Close ;
end;

procedure Tfrm_main.doCalculate;
var
   frmInformationSyn: TfrmInformationSyn;
begin
  if (edtdep.Value =0) then
  begin
    Application.MessageBox('请输入折旧费用!', '系统提示', MB_OK);
    edtdep.SetFocus ;
    Exit ;
  end;
  IniOptions.paramdepreciation := edtdep.Value ;
  frmInformationSyn := TfrmInformationSyn.Create(Self );
  try
    FCalculated := False ;
    dsResult.DataSet := nil;
    frmInformationSyn.DepCodeIndex := cbbType.ItemIndex ;
    frmInformationSyn.ShowModal ;
    if frmInformationSyn.ModalResult = mrok then
    begin
      //IniOptions.SaveSettings(FIniFile);
      FCalculated := True ;
      DMSemi.GetResult ;
      dsResult.DataSet := DMSemi.qryTool ;
      Application.MessageBox('计算完成!', '系统提示', MB_OK);
    end
    else begin
      Application.MessageBox('计算被取消!', '系统提示', MB_OK);
    end;
  finally
    frmInformationSyn.Free ;
  end;
end;

procedure Tfrm_main.doExportToExcel;
begin
  try
    if not FCalculated then
    begin
      Application.MessageBox('请先完成计算再进行导出!', '系统提示', MB_OK);
      Exit ;
    end;
    if not DMSemi.getReport then
    begin
      raise ECheckException.Create('不能取得报表数据!');
    end;
    //exlrprt.DataSet := DMSemi.qryTool ;
    DMSemi.AllDepreciation := edtdep.Value ;
    DMSemi.exlrprt.Template := ExtractFilePath(Application.ExeName)+'report.xls' ;
    DMSemi.exlrprt.Show();
  except
    on E : Exception do
    begin
    Application.MessageBox(PChar(e.Message), '提示', MB_OK +
      MB_ICONINFORMATION);
  {  Application.MessageBox('导出Excel时出错!', '提示', MB_OK +
      MB_ICONINFORMATION);  }
    end;
  end;
end;

procedure Tfrm_main.doPrint;
begin
  if (not FCalculated) then
  begin
    Application.MessageBox('请先完成计算再进行打印!', '系统提示', MB_OK);
    Exit ;
  end;
 { if not DMSemi.getReport then
  begin
    Application.MessageBox('不能取得报表数据!', '系统提示', MB_OK);
    Exit ;
  end;  }
  try
    frm_report := Tfrm_report.Create(Self);
    try
      frm_report.qryMaster.Open ;
      frm_report.qryDetail.Open ;
      frm_report.qrlblTime.Caption := '会计区间:' + IniOptions.parambegindate
                               +' -- ' + IniOptions.paramenddate ;
      frm_report.qrlblCheckOut.Caption := '材料出库金额:' + floattostr(IniOptions.paramCheckOut);;
      frm_report.qrlblcheckin.Caption :=  '半成品入库金额:' + floattostr(IniOptions.paramCheckIn );
      frm_report.qrlblqlbldes.Caption := '总折旧金额:' + floattostr(edtdep.Value );
      frm_report.qckrpList.Preview ;
    finally
      frm_report.Free ;
    end;
  except
    on E : Exception do
    begin
      Application.MessageBox('不能取得报表数据!', '系统提示', MB_OK);
    end;
  end;

end;

procedure Tfrm_main.FormClose(Sender: TObject; var Action: TCloseAction);
var
  linifile : TIniFile ;
begin
  try
    if DMSemi.qryTool.Active then
      DMSemi.DropTable ;
    linifile := TIniFile.Create(FPath );
    try
      IniOptions.SaveSettings(liniFile);
    finally
      linifile.Free ;
    end;

  except
  end;
end;

procedure Tfrm_main.P1Click(Sender: TObject);
begin
  if (not FCalculated) then

⌨️ 快捷键说明

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