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

📄 invhisreport.~pas

📁 文件包含程序源原文件
💻 ~PAS
📖 第 1 页 / 共 4 页
字号:
unit InvHisReport;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, Grids, ComCtrls, InvDef, ComObj, xlsConst,
  EnhLV, GLLV, ImgList, ClipBrd, Math, dpConst;

type
  TfrmHisReport = class(TForm)
    pnlCon: TPanel;
    Panel2: TPanel;
    ClientReport: TPanel;
    rdoReport: TRadioGroup;
    Panel4: TPanel;
    btnExcel: TBitBtn;
    TabClientData: TTabControl;
    rdoTitle: TRadioGroup;
    LstViewQry: TGradLineListView;
    ImageList: TImageList;
    rdoManager: TRadioGroup;
    btnQuery: TBitBtn;
    btnClose: TBitBtn;
    rdoSortID: TRadioGroup;
    Panel1: TPanel;
    lblFDate: TLabel;
    edtFDate: TDateTimePicker;
    lblEDate: TLabel;
    edtEDate: TDateTimePicker;
    Image1: TImage;
    edtMoldID: TLabeledEdit;
    edtStkID: TLabeledEdit;
    edtStkName: TEdit;
    cbxStk: TComboBox;
    edtMatCode: TLabeledEdit;
    Panel3: TPanel;
    cbxSuplier: TComboBox;
    edtSuplier: TLabeledEdit;
    edtSuplierName: TEdit;
    edtIssPaper: TLabeledEdit;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure rdoReportClick(Sender: TObject);
    procedure btnQueryClick(Sender: TObject);
    procedure TabClientDataChange(Sender: TObject);
    procedure btnCloseClick(Sender: TObject);
    procedure rdoManagerClick(Sender: TObject);
    procedure rdoSortIDClick(Sender: TObject);
    procedure btnExcelClick(Sender: TObject);
    procedure rdoTitleClick(Sender: TObject);
    procedure cbxStkChange(Sender: TObject);
    procedure edtStkIDChange(Sender: TObject);
    procedure cbxSuplierDropDown(Sender: TObject);
    procedure cbxSuplierChange(Sender: TObject);
    procedure edtSuplierChange(Sender: TObject);
  private
    { Private declarations }


    Procedure SetListViewColumn;
    Procedure SetListView;
    procedure MakeItemCaption(Item: TListItem);

    Procedure SetListViewColumn_InOutStk(sIndex: integer);
    Procedure SetListView_InOutStk(sIndex: integer);
    procedure MakeItemCaption_InOutStk(Item: TListItem; sIndex: integer);

    procedure SetMultilingual;

  public
    { Public declarations }
    Function  Set_QueryedList(sList: TList): TList;
    Procedure CreateTabs_ByGroup(rdoIndex: integer; sList: TList);
    Procedure Set_QryList_FromTabs(iTab: integer);

    Function  CheckViewData(lcP: PINVENTORY; rdoTitleIndex,TabIndex: integer): boolean;

    Procedure PrintProc(iReport: Integer);
    Procedure Excel_inpaperList(sList: TList);
    Procedure Excel_outpaperList(sList: TList);
    function  CopyToClipBoard(var RecCnt, ColCnt: Integer): string;


  end;

var
  frmHisReport: TfrmHisReport;
  FAllRptList,                   //-- all inventory_sheet data
  FQueryList: TList;             //-- query result list

  FColumnCnt: integer;          //-- List Column 的计数
  FOnMakeItemCaption: Boolean;  //-- 是否改变Column caption
  FColumnCaptionType: integer;


  FGroupValue: array[0..120000] of variant;  //-- TabControl tabs group value
  iKind: integer;                         //-- inventory_sheet kind field value control
  ListSortKey: Integer;

implementation

uses InvDM, Main;

{$R *.dfm}

function ListSortCompare(Item1, Item2: Pointer): Longint;
var DataType: Integer;
    Str1, Str2: string;
    Int1, Int2: Integer;
    Dbl1, Dbl2: Double;
begin
  Result := 0;
  Str1 := ''; Str2 := '';
  Int1 := 0;  Int2 := 0;
  Dbl1 := 0;  Dbl2 := 0;
  case Abs(ListSortKey) of
    1: begin //-- in/out date
        Str1 := formatdatetime('yy/mm/dd hh:mm',TINVENTORY(Item1^).DATE);
        Str2 := formatdatetime('yy/mm/dd hh:mm',TINVENTORY(Item1^).DATE);
        DataType := 0;
       end;
    2: begin //-- in/out type
        Int1 := TINVENTORY(Item1^).KIND;
        Int2 := TINVENTORY(Item2^).KIND;
        DataType := 1;
       end;
    3: begin //-- material rec_id
        Str1 := dm_inventory.GetMaterialCode(TINVENTORY(Item1^).MAT_RID);
        Str2 := dm_inventory.GetMaterialCode(TINVENTORY(Item2^).MAT_RID);
        DataType := 0;
       end;
    4: begin //
        Str1 := TINVENTORY(Item1^).PaperNo;
        Str2 := TINVENTORY(Item2^).PaperNo;
        DataType := 0;
       end;
    5: begin //
        Dbl1 := TINVENTORY(Item1^).TTL_PRICE;
        Dbl2 := TINVENTORY(Item2^).TTL_PRICE;
        DataType := 2;
       end;
    else Exit;
  end;

  case DataType of
    0: if Str1 < Str2 then  Result := -1
       else if Str1 > Str2 then Result := 1
       else Result := 0;
    1: if Int1 < Int2 then  Result := -1
       else if Int1 > Int2 then Result := 1
       else Result := 0;
    2: if Dbl1 < Dbl2 then  Result := -1
       else if Dbl1 > Dbl2 then Result := 1
       else Result := 0;
  else Result := 0;
  end;
  if ListSortKey < 0 then Result := Result * -1;
end;


procedure TfrmHisReport.FormCreate(Sender: TObject);
begin
  Top  := (Height - ClientHeight) + 100;
  Left := 0;
  Width := Screen.Width;


  FAllRptList := TList.Create;
  FAllRptList.Clear;
  FQueryList := TList.Create;
  FQueryList.Clear;

  SetMultilingual;
end;

procedure TfrmHisReport.FormShow(Sender: TObject);
begin
  Top  := 0;
  Left := frmMain.Width;
  Height := Screen.Height-(Height - ClientHeight);
  Width := Screen.Width- frmMain.Width;

  pnlCon.SetFocus;
  case rdoReport.ItemIndex of
    0: iKind := 0;
    1: iKind := 1;
    2: iKind := 2;
    3: iKind := 3;
    4: iKind := 0;
    5: iKind := 1;
    6: iKind := 2;
    7: iKind := 3;
    8: iKind := 99;
    else iKind := 99;
  end;

  edtFDate.Date := strToDate(FormatDatetime('yy/mm/dd',Now-1));
  edtEDate.Date := strToDate(FormatDatetime('yy/mm/dd',Now));
  rdoReport.ItemIndex := 8;
  rdoTitle.ItemIndex  := 11;
  rdoManager.ItemIndex := -1;
  rdoTitle.Enabled     := true;
  rdoSortID.ItemIndex  := 1;
  rdoSortID.Enabled    := true;
  FColumnCaptionType := 1;             //-- 标准 ListColumn caption 格式

  dm_inventory.Read_InventoryHisRpt(FALSE, FAllRptList,0);
  SetListView;
end;

procedure TfrmHisReport.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caHide;
end;

procedure TfrmHisReport.rdoReportClick(Sender: TObject);
begin
  case rdoReport.ItemIndex of
    0: iKind := 0;
    1: iKind := 1;
    2: iKind := 2;
    3: iKind := 3;
    4: iKind := 0;
    5: iKind := 1;
    6: iKind := 2;
    7: iKind := 3;
    8: iKind := 99;
    else iKind := 99;
  end;
  case rdoReport.ItemIndex of
    0..3: FColumnCaptionType := 1;
    4..7: FColumnCaptionType := 2;
    else FColumnCaptionType := 1;
  end;

  rdoManager.ItemIndex := -1;
  rdoTitle.Enabled     := true;
  rdoSortID.Enabled    := true;
  btnQuery.Click;
end;

procedure TfrmHisReport.CreateTabs_ByGroup(rdoIndex: integer; sList: TList);
var tmpTabIndex: integer;
    i,j: integer;
    lcp: PINVENTORY;
    tmpGroupTitle: variant;
    iGroupFind: Boolean;
begin
  tmpTabIndex := 0;
  TabClientData.Tabs.Clear;

  for i := 0 to sList.Count - 1 do
  begin
    lcp := sList[i];
    if lcp = nil then continue;

    case rdoIndex of
      0: tmpGroupTitle := formatDatetime('yy/mm/dd',lcp^.DATE);
      1: tmpGroupTitle := dm_inventory.GetMaterialCode(lcp^.MAT_RID);
      2: tmpGroupTitle := dm_inventory.Get_Shizai_KubunName(dm_inventory.GetMaterialTypeID(lcp^.MAT_RID));
      3: tmpGroupTitle := strpas(lcp^.paperno);
      4: tmpGroupTitle := dm_inventory.GetOrderNo(lcP^.ODR_RID);
      5: tmpGroupTitle := inttostr(lcp^.SUP_CD);
      6: tmpGroupTitle := inttostr(lcp^.MAK_CD);
      7: tmpGroupTitle := dm_inventory.Get_EmpName(lcp^.recieve_EmpID);
      8: tmpGroupTitle := dm_inventory.Get_EmpName(lcp^.input_empid);
      9: begin
           case lcp^.KIND of
             0: tmpGroupTitle := dm_inventory.Get_IOIDName(lcp^.Inout_id,1);
             1: tmpGroupTitle := dm_inventory.Get_IOIDName(lcp^.Inout_id,2);
             2: tmpGroupTitle := dm_inventory.Get_IOIDName(lcp^.Inout_id,3);
             3: tmpGroupTitle := dm_inventory.Get_IOIDName(lcp^.Inout_id,4);
             4: tmpGroupTitle := GetMultiLingalMsg(90249,'Balance stock in');
             else tmpGroupTitle := dm_inventory.Get_IOIDName(lcp^.Inout_id,0);
           end;
         end;
      10: tmpGroupTitle := dm_inventory.GetDepartName_fromEmpID(lcp^.RECIEVE_EMPID);
      11: tmpGroupTitle := 'ALL';
    end;

    //-- 判断是否有找到抬头信息
    iGroupFind := false;
    for j := 0 to tmpTabIndex - 1 do
    begin
      try
        if tmpGroupTitle = FGroupValue[j] then begin
          iGroupFind := true;
          break;
        end;
      except
      end;
    end;

    if not iGroupFind then begin   //-- 没找到当前资料的抬头则新增tabs
      FGroupValue[tmpTabIndex] := tmpGroupTitle;
      inc(tmpTabIndex);

      TabClientData.Tabs.Add(tmpGroupTitle);
    end;

  end;
  //////////////////////////////////////////////
  //-- 初始化TabClientData.TabIndex value
  if tmpTabIndex >0 then TabClientData.TabIndex := 0
  else TabClientData.TabIndex := -1;
end;


////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
Function TfrmHisReport.Set_QueryedList(sList: TList): TList;
  function SetQryCheck(lcP: PINVENTORY): Boolean;
  var i: Integer;
      WDate: array[0..1] of TDateTime;
  begin
    Result := True;
    //--
    WDate[0] := edtFDate.Date;
    WDate[1] := edtEDate.Date;
    if ((WDate[0] > 2)and(formatdatetime('yy/mm/dd',WDate[0]) > formatdatetime('yy/mm/dd',lcP^.DATE)))or
       ((WDate[1] > 2)and(formatdatetime('yy/mm/dd',WDate[1]) < formatdatetime('yy/mm/dd',lcP^.DATE)))then begin
      Result := False;
      Exit;
    end;

    if trim(edtMatCode.Text)<>'' then
      if not(dm_Inventory.GetMaterialRID(trim(edtMatCode.Text))=lcp^.MAT_RID) then begin
        result := false;
        exit;
      end;

    if trim(edtMoldID.Text)<>'' then
      if NOT(dm_Inventory.GetOrderRID(trim(edtMoldID.Text))=lcp^.ODR_RID) then begin
        result := false;
        exit;
      end;

    if trim(edtStkID.Text)<>'' then
      if not(lcp^.STK_ID=trim(edtStkID.Text)) then  begin
        result := false;
        exit;
      end;

    if (trim(edtSuplier.Text)<>'') then
      if not (IntToStr(lcp^.SUP_CD) = trim(edtSuplier.Text)) then begin
        result := false;
        exit;
      end;

    if trim(edtIssPaper.Text)<>'' then
      if not(trim(edtIssPaper.Text)=lcp^.ISS_PAPERNO) then begin
        result := false;
        exit;
      end;

    if iKind <> 99 then begin
      if (lcp^.KIND <> iKind) then begin
        result := false;
        exit;
      end;
    end;
  end;
var
  ix: integer;
  lcpA: PINVENTORY;
begin

   sList.Clear;
   for ix := 0 to FAllRptList.Count - 1 do
   begin
     lcpA := FAllRptList[ix];
     if not SetQryCheck(lcpA) then continue;
     sList.Add(lcpA);
   end;
   result := sList
end;


procedure TfrmHisReport.Set_QryList_FromTabs(iTab: integer);
  function SetQryCheck(lcP: PINVENTORY): Boolean;
  var i: Integer;
      WDate: array[0..1] of TDateTime;
  begin
    Result := True;
    //--
    WDate[0] := strtodatetime(formatdatetime('yyyy/mm/dd',edtFDate.Date)+' 00:00:00');
    WDate[1] := strtodatetime(formatdatetime('yyyy/mm/dd',edtEDate.Date)+' 23:59:59');
    if ((WDate[0] > 2)and(formatdatetime('yyyy/mm/dd',WDate[0]) > formatdatetime('yyyy/mm/dd',lcP^.DATE)))or
       ((WDate[1] > 2)and(formatdatetime('yyyy/mm/dd',WDate[1]) < formatdatetime('yyyy/mm/dd',lcP^.DATE)))then begin
      Result := False;
      Exit;
    end;

    if trim(edtMatCode.Text)<>'' then
      if not(dm_Inventory.GetMaterialRID(trim(edtMatCode.Text))=lcp^.MAT_RID) then begin
        result := false;
        exit;
      end;

    if trim(edtMoldID.Text)<>'' then
      if NOT(dm_Inventory.GetOrderRID(trim(edtMoldID.Text))=lcp^.ODR_RID) then begin
        result := false;
        exit;
      end;

    if trim(edtStkID.Text)<>'' then
      if not(lcp^.STK_ID=trim(edtStkID.Text)) then  begin
        result := false;

⌨️ 快捷键说明

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