?? invaccountage.pas
字號:
Column := ListView.Columns.Add;
Column.Width := ListView.Font.Size * 10;
Column.Alignment := taRightJustify;
Column.Caption := '2年期';
Inc(FColumnCount);
Column := ListView.Columns.Add;
Column.Width := ListView.Font.Size * 10;
Column.Alignment := taRightJustify;
Column.Caption := '3年期';
Inc(FColumnCount);
Column := ListView.Columns.Add;
Column.Width := ListView.Font.Size * 10;
Column.Alignment := taRightJustify;
Column.Caption := '4年期';
Inc(FColumnCount);
Column := ListView.Columns.Add;
Column.Width := ListView.Font.Size * 10;
Column.Alignment := taRightJustify;
Column.Caption := '5年期';
Inc(FColumnCount);
Column := ListView.Columns.Add;
Column.Width := ListView.Font.Size * 10;
Column.Alignment := taRightJustify;
Column.Caption := '5年以上';
Inc(FColumnCount);
end;
end;
procedure TfrmAccountAge.Read_InvAgeInfo;
begin
SetListColumn(rdogrpView.ItemIndex);
dm_inventory.Read_InvAgeInfo(FInvAgeList, rdogrpView.ItemIndex);
Screen.Cursor := crHourGlass;
try
SetListView(rdogrpView.ItemIndex);
finally
Screen.Cursor := crDefault;
end;
end;
procedure TfrmAccountAge.SetListView(iMode: integer);
var i, j: Integer;
lcP: PInvAgeInfo;
Item: TListItem;
Tmp: string;
begin
Screen.Cursor := crHourGlass;
with ListView.Items do begin
BeginUpdate;
Clear;
EndUpdate;
end;
//////////////////////////////////
ListView.Items.BeginUpdate;
try
FInvAgeList.Sort(TListSortCompare(@ListSortCompare));
for i:=0 to FInvAgeList.Count-1 do begin
lcP := FInvAgeList.Items[i];
if not Set_QryCondition(lcp) then continue;
Item := ListView.Items.Add;
for j:=0 to FColumnCount-1 do Item.Subitems.Add('');
Item.Data := lcP;
MakeItemCaption(Item, iMode);
end;
finally
ListView.Items.EndUpdate;
ListView.Items.EndUpdate;
if ListView.Items.Count > 0 then
begin
ListView.TopItem.Selected := True;
ListView.Selected.Selected := true;
end;
Screen.Cursor := crDefault;
stsBarCnt.Panels[0].Text := '符合條件的記錄有:'+ IntToStr(ListView.Items.Count)+' 條';
end;
end;
function TfrmAccountAge.Set_QryCondition(lcP: PInvAgeInfo): Boolean;
var
iMatAttr: Integer;
WMtlCode: array[0..1] of string;
WDate: array[0..1] of TDateTime;
begin
Result := True;
//////////////////////
if chkStkLess0.Checked then begin
if RoundTo(lcp^.curr_qty,-2)<=0.00 then
begin
result := false;
exit;
end;
end;
if trim(edtMatCode.Text)<>'' then
if NOT(dm_Inventory.GetMaterialRID(trim(edtMatCode.Text))=lcp^.mat_rec_id) then
begin
result := false;
exit;
end;
end;
procedure TfrmAccountAge.MakeItemCaption(Item: TListItem; iMode: integer);
var lcP: PInvAgeInfo;
begin
if Item = nil then Exit;
if Item.Data = nil then Exit;
lcP := Item.Data;
Item.Caption := dm_inventory.GetMaterialCode(lcP^.mat_rec_id);
Item.SubItems[00] := dm_inventory.GetMaterialName(lcp^.mat_rec_id);
Item.SubItems[01] := IntToStr(lcp^.guage_id);
Item.SubItems[02] := dm_inventory.Get_GuageName(lcp^.mat_rec_id, lcp^.guage_id);
Item.SubItems[03] := dm_inventory.GetUnitTypeName(lcP^.mat_rec_id);
Item.SubItems[04] := FormatFloat('#,##0.00', lcP^.curr_qty);
Item.SubItems[05] := FormatFloat('#,##0.00', lcP^.curr_amount);
Item.SubItems[06] := FormatFloat('#,##0.00', lcP^.Month1);
Item.SubItems[07] := FormatFloat('#,##0.00', lcP^.Month2);
Item.SubItems[08] := FormatFloat('#,##0.00', lcP^.Month3);
Item.SubItems[09] := FormatFloat('#,##0.00', lcP^.Month4);
Item.SubItems[10] := FormatFloat('#,##0.00', lcP^.Month5);
Item.SubItems[11] := FormatFloat('#,##0.00', lcP^.Month6);
if (iMode=0) then begin
Item.SubItems[12] := FormatFloat('#,##0.00', lcP^.Month7);
Item.SubItems[13] := FormatFloat('#,##0.00', lcP^.Month8);
Item.SubItems[14] := FormatFloat('#,##0.00', lcP^.Month9);
Item.SubItems[15] := FormatFloat('#,##0.00', lcP^.Month10);
Item.SubItems[16] := FormatFloat('#,##0.00', lcP^.Month11);
Item.SubItems[17] := FormatFloat('#,##0.00', lcP^.Month12);
Item.SubItems[18] := FormatFloat('#,##0.00', lcP^.Month13);
Item.SubItems[19] := FormatFloat('#,##0.00', lcP^.Month14);
Item.SubItems[20] := FormatFloat('#,##0.00', lcP^.Month15);
Item.SubItems[21] := FormatFloat('#,##0.00', lcP^.Month16);
Item.SubItems[22] := FormatFloat('#,##0.00', lcP^.Month17);
Item.SubItems[23] := FormatFloat('#,##0.00', lcP^.Month18);
Item.SubItems[24] := FormatFloat('#,##0.00', lcP^.Month19);
Item.SubItems[25] := FormatFloat('#,##0.00', lcP^.Month20);
Item.SubItems[26] := FormatFloat('#,##0.00', lcP^.Month21);
Item.SubItems[27] := FormatFloat('#,##0.00', lcP^.Month22);
Item.SubItems[28] := FormatFloat('#,##0.00', lcP^.Month23);
Item.SubItems[29] := FormatFloat('#,##0.00', lcP^.Month24);
Item.SubItems[30] := FormatFloat('#,##0.00', lcP^.Month_mass24);
end;
end;
/////////////////////////////////////////////////////////////////////////
procedure TfrmAccountAge.ListViewColumnClick(Sender: TObject; Column: TListColumn);
////////////////////////////////////////
function StrToFloatEx(S: string): Double;
begin
S := StringReplace(S, ',', '', [rfReplaceAll]);
S := StringReplace(S, '\', '', [rfReplaceAll]);
try Result := StrToFloat(S);
except Result := 0;
end;
end;
var WSB_Pos: Integer;
begin
if ListView.Items.Count = 0 then Exit;
WSB_Pos := GetScrollPos(ListView.Handle, SB_HORZ);
ListSortKey := Column.Index + 1;
with ListView do
case ListSortKey of
1: if Items[0].Caption < Items[Items.Count-1].Caption then
ListSortKey := ListSortKey * -1;
6..7: //--
if StrToFloatEx(Items[0].SubItems[ListSortKey-2]) <
StrToFloatEx(Items[Items.Count-1].SubItems[ListSortKey-2]) then
ListSortKey := ListSortKey * -1;
else if Items[0].SubItems[ListSortKey-2] <
Items[Items.Count-1].SubItems[ListSortKey-2] then
ListSortKey := ListSortKey * -1;
end;
FInvAgeList.Sort(TListSortCompare(@ListSortCompare));
SetListView(rdogrpView.ItemIndex);
ListView.Scroll(WSB_Pos, 0);
end;
/////////////////////////////////////////////////////
procedure TfrmAccountAge.BitBtn1Click(Sender: TObject);
begin
Screen.Cursor := crHourGlass;
Read_InvAgeInfo;
Screen.Cursor := crDefault;
end;
{*********************************************************************}
procedure TfrmAccountAge.PrintProc;
var
V: OleVariant;
RecCnt, ColCnt: Integer;
i,k,L: Integer;
S,AreaS,DD: string;
ireport,isheet: integer;
begin
try
V := CreateOleObject('Excel.Application');
except
MessageDlg('Excel Application is Created Error!', mtError, [mbOk], 0);
Exit;
end;
V.Visible := True;
V.WorkBooks.Add;
V.WorkBooks[1].Activate;
V.WorkSheets[1].Activate;
V.WorkSheets[1].Name := 'InventoryAcountYear';
V.ActiveSheet.Cells[1, 2].Value := ' ' +'庫存帳齡分析表';
RecCnt := 0;
ColCnt := 0;
ClipBoard.asText := CopyToClipBoard(RecCnt, ColCnt);
//--
V.ActiveSheet.PageSetUp.Orientation := xlPortrait; //xlLandscape;(縱向)
V.ActiveSheet.PageSetUp.PrintTitleRows := '$1:$3'; //--
V.ActiveSheet.PageSetUp.RightHeader := //--
'&9 '+FormatDateTime('yyyy/mm/dd hh:nn', Now) + ' ' +
'Print Date';
V.ActiveSheet.PageSetUp.CenterFooter := '&9&P/&N Page'; //--
V.ActiveSheet.PageSetUp.Order := xlOverThenDown; //--
//page format
V.ActiveSheet.PageSetUp.LeftMargin := V.InchesToPoints(10/25.4); // 15mm
V.ActiveSheet.PageSetUp.RightMargin := V.InchesToPoints(10/25.4); // 15mm
V.ActiveSheet.PageSetUp.TopMargin := V.InchesToPoints(15/25.4); // 15mm
V.ActiveSheet.PageSetUp.BottomMargin := V.InchesToPoints(15/25.4); // 15mm
V.ActiveSheet.PageSetUp.HeaderMargin := V.InchesToPoints(10/25.4); // 10mm
V.ActiveSheet.PageSetUp.FooterMargin := V.InchesToPoints(10/25.4); // 10mm
//-- report title caption stytle
V.ActiveSheet.Cells.Font.Size := 9;
V.ActiveSheet.Cells[1, 1].HorizontalAlignment := xlLeft;
V.ActiveSheet.Cells[1, 1].Font.Size := 16;
V.ActiveSheet.Cells[1, 1].Font.Bold := True;
V.ActiveSheet.Cells[1, 1].Font.Italic := True;
V.ActiveSheet.Rows[3].HorizontalAlignment := xlCenter;
V.ActiveSheet.Rows[3].Font.Size := 11;
V.ActiveSheet.Rows[3].Font.Bold := True;
///--
V.ActiveSheet.Columns[3].NumberFormatLocal := '@'; //--
V.ActiveSheet.Columns[6].NumberFormatLocal := '@'; //--
V.ActiveSheet.Columns[7].NumberFormatLocal := '@'; //--
V.ActiveSheet.Columns[8].NumberFormatLocal := '@'; //--
V.ActiveSheet.Columns[9].NumberFormatLocal := '@'; //--
V.ActiveSheet.Columns[10].NumberFormatLocal := '@'; //--
//--
k := Ord('A')+(ColCnt-1); //Chr(Ord('A')+(ColCnt-1)) A->65 Z->89
//showMessage(inttostr(ord('A')));
if K > 90 then begin
L := (K-89);
AreaS := 'A'+chr(64+L);
end
else begin
AreaS := Chr(Ord('A')+(ColCnt-1));
end;
S := 'A3:'+AreaS+IntToStr(RecCnt+3);
V.ActiveSheet.Range[S].Borders[xlDiagonalDown].LineStyle := xlNone;
V.ActiveSheet.Range[S].Borders[xlDiagonalUp].LineStyle := xlNone;
V.ActiveSheet.Range[S].Borders[xlEdgeLeft].LineStyle := xlContinuous;
V.ActiveSheet.Range[S].Borders[xlEdgeLeft].Weight := xlThin;
V.ActiveSheet.Range[S].Borders[xlEdgeLeft].ColorIndex := xlAutomatic;
V.ActiveSheet.Range[S].Borders[xlEdgeTop].LineStyle := xlContinuous;
V.ActiveSheet.Range[S].Borders[xlEdgeTop].Weight := xlThin;
V.ActiveSheet.Range[S].Borders[xlEdgeTop].ColorIndex := xlAutomatic;
V.ActiveSheet.Range[S].Borders[xlEdgeBottom].LineStyle := xlContinuous;
V.ActiveSheet.Range[S].Borders[xlEdgeBottom].Weight := xlThin;
V.ActiveSheet.Range[S].Borders[xlEdgeBottom].ColorIndex := xlAutomatic;
V.ActiveSheet.Range[S].Borders[xlEdgeRight].LineStyle := xlContinuous;
V.ActiveSheet.Range[S].Borders[xlEdgeRight].Weight := xlThin;
V.ActiveSheet.Range[S].Borders[xlEdgeRight].ColorIndex := xlAutomatic;
V.ActiveSheet.Range[S].Borders[xlInsideVertical].LineStyle := xlDot;
V.ActiveSheet.Range[S].Borders[xlInsideVertical].Weight := xlThin;
V.ActiveSheet.Range[S].Borders[xlInsideVertical].ColorIndex := xlAutomatic;
V.ActiveSheet.Range[S].Borders[xlInsideHorizontal].LineStyle := xlDot;
V.ActiveSheet.Range[S].Borders[xlInsideHorizontal].Weight := xlThin;
V.ActiveSheet.Range[S].Borders[xlInsideHorizontal].ColorIndex := xlAutomatic;
S := 'A3:'+AreaS+'3';
V.ActiveSheet.Range[S].Borders[xlDiagonalDown].LineStyle := xlNone;
V.ActiveSheet.Range[S].Borders[xlDiagonalUp].LineStyle := xlNone;
V.ActiveSheet.Range[S].Borders[xlEdgeLeft].LineStyle := xlContinuous;
V.ActiveSheet.Range[S].Borders[xlEdgeLeft].Weight := xlThin;
V.ActiveSheet.Range[S].Borders[xlEdgeLeft].ColorIndex := xlAutomatic;
V.ActiveSheet.Range[S].Borders[xlEdgeTop].LineStyle := xlContinuous;
V.ActiveSheet.Range[S].Borders[xlEdgeTop].Weight := xlThin;
V.ActiveSheet.Range[S].Borders[xlEdgeTop].ColorIndex := xlAutomatic;
V.ActiveSheet.Range[S].Borders[xlEdgeBottom].LineStyle := xlContinuous;
V.ActiveSheet.Range[S].Borders[xlEdgeBottom].Weight := xlThin;
V.ActiveSheet.Range[S].Borders[xlEdgeBottom].ColorIndex := xlAutomatic;
V.ActiveSheet.Range[S].Borders[xlEdgeRight].LineStyle := xlContinuous;
V.ActiveSheet.Range[S].Borders[xlEdgeRight].Weight := xlThin;
V.ActiveSheet.Range[S].Borders[xlEdgeRight].ColorIndex := xlAutomatic;
//--
V.ActiveSheet.Cells[3, 1].PasteSpecial;
V.ActiveSheet.Cells[3, 1].Select;
//--
//DD := 'A:'+Chr(Ord('A')+(ColCnt-1));
DD := 'A:'+AreaS;
V.ActiveSheet.Columns[DD].EntireColumn.AutoFit;
for i:=1 to ColCnt do
V.ActiveSheet.Columns[i].ColumnWidth := V.ActiveSheet.Columns[i].ColumnWidth + 2;
if frmMain.IniData.isExcelPrint then V.Print;
end;
///////////////////////////////////////////////////////////////////
function TfrmAccountAge.CopyToClipBoard(var RecCnt, ColCnt: Integer): string;
var i, j: Integer;
Buf: string;
begin
RecCnt := 0; ColCnt := 0;
Buf := '';
for i:=0 to FColumnCount-1 do begin
Buf := Buf + ListView.Column[i].Caption + #9;
Inc(ColCnt);
end;
Buf := Buf + #13#10;
for i:=0 to ListView.Items.Count-1 do begin
for j:=0 to FColumnCount-1 do
if j = 0 then Buf := Buf + Trim(ListView.Items[i].Caption) + #9
else Buf := Buf + Trim(ListView.Items[i].SubItems[j-1]) + #9;
Buf := Buf + #13#10;
Inc(RecCnt);
end;
Result := Buf;
end;
procedure TfrmAccountAge.btnCloseClick(Sender: TObject);
begin
if ListView.Items.Count > 0 then PrintProc;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -