{主打印函数} procedure Tfmmain.PrintData(Sender: TObject); var I, J,fp_int: Integer; f_p : String; Tmp_TopList, Tmp_Data : TStringList; tmpPnoList:TList;{Pno list中间用变量} tmpstList:TList;{要打印的St list中间变量} STPdInfo:TSTPdInfo; m:integer; totalPrintCount:integer;{总共打印的张数} begin totalPrintCount:=0; tmpPnoList:=TList.Create;{Pno list中间用变量} tmpstList:=TList.Create;{要打印的St list中间变量} if printList.Count = 0 then begin Application.MessageBox(Pchar('没有可打印的数据!'), '提示信息', MB_OK); Exit; end; try Printer.Orientation := poPortrait; //竖打 {*打印进度对话框:*} TfrmYBWait.Instance.ShowWaitMsg( Self, '正在处理中,请等候...', aviFindFile); Application.ProcessMessages; Printer.Title := 'ST商品盘点表'; Printer.BeginDoc; {选中的ST的个数} for I := 0 to printList.Count-1 do begin tmpstList:=TList(printList.Items[i]);//取得一个ST for j:=0 to tmpstList.Count-1 do begin tmpPnoList:=TList(tmpstList.Items[j]);{取得一个传票号的list} totalPrintCount:=totalPrintCount+1;//打印的页数 //*打印状态提示对话框:* TfrmYBWait.Instance.stMsg.Caption :='正在打印【ST商品盘点表】第'+IntToStr(totalPrintCount)+'张'; {一个传票号是一页} if totalPrintCount<> 1 then begin Printer.NewPage; end; {头信息只打印一次} {先打印头信息***把头信息放在一个list中} STPdInfo:=TSTPdInfo(tmpPnoList.Items[0]); Tmp_TopList := TStringList.Create; Tmp_TopList.Add(STPdInfo.STORE); // 0 店铺号 Tmp_TopList.Add(STPdInfo.STORE_NAME); // 1 店铺名 Tmp_TopList.Add(STPdInfo.DPT ); // 2 DPT Tmp_TopList.Add(STPdInfo.DPT_NAME ); // 3 DPT名称 Tmp_TopList.Add(FormatFloat('##0',STPdInfo.TAX_RATE/100) ); // 4 税率 Tmp_TopList.Add(STPdInfo.DCLASS); // 5 商品分类 Tmp_TopList.Add(STPdInfo.CLASS_NAME ); // 6 商品分类名称 Tmp_TopList.Add(STPdInfo.ST_CS_NO); // 7 本次的传票号 Tmp_TopList.Add(STPdInfo.TANA_DATE ); // 8 盘点日期 Tmp_TopList.Add( STPdInfo.DL_DEPOT); // 9 库 Tmp_TopList.Add( STPdInfo.DL_AREA); // 10 区 Tmp_TopList.Add( STPdInfo.DL_SHELF); // 11 架 Tmp_TopList.Add( STPdInfo.ST_USED_COUNT); // 12 使用回数 Tmp_TopList.Add( STPdInfo.ST_NO); // 13 ST机器号码 编码 //Tmp_TopList.Add(STPdInfo.DL_SIDE+'-'+STPdInfo.DL_FLOOR+'-'+STPdInfo.DL_POSITION); // 14 面 层 位号 PrintTop(Tmp_TopList);//*打印报表头信息*} FreeAndNil(Tmp_TopList); for m := 0 to 24 do begin // 25行数据 if m < tmpPnoList.Count then begin {每页打印的实际数据条数} STPdInfo:=TSTPdInfo(tmpPnoList.Items[m]); Tmp_Data := TStringList.Create; {*取得具体的信息*} Tmp_Data.Add(STPdInfo.ITEM); // 0 商品编码 Tmp_Data.Add(STPdInfo.ITEM_NAME); // 1 商品名称 Tmp_Data.Add(STPdInfo.VENDOR_NAME); // 2 供应商名称 Tmp_Data.Add(STPdInfo.COLOR_NAME); // 3 颜色 Tmp_Data.Add(STPdInfo.SIZE_NAME); // 4 尺寸 Tmp_Data.Add(STPdInfo.UNIT_TYPE); // 5 单位 Tmp_Data.Add(FormatFloat('##0.00',STPdInfo.PRICE_TAX/100)); // 6 单价 Tmp_Data.Add(FormatFloat('##0',STPdInfo.STOCK_NUM)); // 7 点检数 Tmp_Data.Add(STPdInfo.DL_SIDE+'-'+STPdInfo.DL_FLOOR+'-'+STPdInfo.DL_POSITION); // 8 面 层 位号 PrintBody(m, True, Tmp_Data); FreeAndNil(Tmp_Data); end else begin Tmp_Data := TStringList.Create; PrintBody(m, False, Tmp_Data); // False:只画星号 FreeAndNil(Tmp_Data); end; end;// 25行数据 end; PrintName; {*打印表格头信息*} PrintDraw; {*打印报表表格*} PrintFoot;{*打印报表结尾*} end;{打印完一个传票list} end;{最外层的for循环end} //关闭打印进度对话框: //TfrmYBWait.Instance.stMsg.Caption := '打印完成!'; TfrmYBWait.Instance.CloseWaitMsg(); printer.EndDoc; except TfrmYBWait.Instance.CloseWaitMsg(); printer.EndDoc; end; end; //{*打印报表头信息:*} {*打印报表头信息:*} procedure Tfmmain.PrintTop(Tmp_List : TStringList); var Print_Page,Print_Store,Print_DPT,Print_Date,Print_Tax,Print_Class,print_DL: String; begin Printer.Canvas.Pen.Width := 6; Printer.Canvas.Font.Size:=8; Printer.Canvas.Font.Style:=[fsBold]; PrintText(1580, 12,GCompanyName,18); if isAcOrAcom='com' then PrintText(1850, 19,'ST商品盘点表-通常',14); if isAcOrAcom='ac' then PrintText(1850, 19,'ST商品盘点表-财务',14); Print_Page := '字 '+Tmp_List.Strings[7]+' 号'; PrintText(3720, 20,Print_Page,14); printer.Canvas.font.Size:=10; PrintText(100, 25,'帐票编码: RCYCSC01',10); Print_Store := '店铺编码: ' + Tmp_List.Strings[0] + ' ' + Tmp_List.Strings[1]; PrintText(100, 29, Print_Store,10); Print_Date := Tmp_List.Strings[8]; Print_Date := '盘点日期: '+LeftStr(Print_Date,4) + '年' + MidStr(Print_Date,5,2) + '月' + RightBStr(LeftBstr(Print_Date,8),2) + '日'; PrintText(1777, 29, Print_Date,10); print_DL :='ST编码: '+Tmp_List.Strings[13]+' -'+Tmp_List.Strings[12]; PrintText(3720,29, print_DL,10); Print_DPT := 'DPT : ' + Tmp_List.Strings[2] + ' ' + Tmp_List.Strings[3]; PrintText(100, 33, Print_DPT,10); Print_Tax := '销售税率: ' +Tmp_List.Strings[4]+'%'; PrintText(1777, 33, Print_Tax,10); Print_Class := '陈列登录: '+'库:'+ Tmp_List.Strings[9] + ' 区:' + Tmp_List.Strings[10]+' 架:'+Tmp_List.Strings[11]; PrintText(2580, 33, Print_Class,10); end; {*打印报表字段名称:-------------*} procedure Tfmmain.PrintName; begin PrintText(252, 42,'商品编码',10); PrintText(1000, 42,'商 品 名 称',10); PrintText(1750, 42,' 供应商名称',10); PrintText(2370, 38,'颜色',10); PrintText(2370, 42,'尺寸',10); PrintText(2610, 42,'面层位',10); //PrintText(2658, 42,'尺寸',10); PrintText(2883, 38,'单',10); PrintText(2883, 42,'位',10); PrintText(3143, 42,'单价',10); PrintText(3550, 42,'点检数',10); PrintText(3895, 38,'检 输',10); PrintText(3895, 42,'查 入',10); PrintText(4180, 42,'备 注',10); end; {*打印主体数据:*} {*打印主体数据:*} procedure Tfmmain.PrintBody(Tmp_Int : Integer;Tmp_Bool : Boolean;Tmp_List : TStringList); var Tmp_Color,Tmp_Size,Tmp_Price,Tmp_Fac,Tmp_name ,Tmp_Dandian: String; double_price:double; begin if Not Tmp_Bool then begin PrintText(140, 51 + 9 * (Tmp_Int), '*************',10); PrintText(740, 51 + 9 * (Tmp_Int), '**********************',10); Exit; end; PrintText(140, 51 + 9 * Tmp_Int, Tmp_List.Strings[0],10); //商品编码 Tmp_name :=leftBstr(tmp_list.Strings[1],20); PrintText(740, 51 + 9 * Tmp_Int, Tmp_name,10); //商品名称 Tmp_Fac := LeftBStr(Tmp_List.Strings[2],12); PrintText(1725, 51 + 9 * Tmp_Int, Tmp_Fac,10); //生产厂家名称 Tmp_Color :=leftBstr(Tmp_List.Strings[3],6); PrintText(2320, 51 + 9 * Tmp_Int, Tmp_Color,10); //颜色 Tmp_Size :=leftBstr( Tmp_List.Strings[4],6); //PrintText(2610, 51 + 9 * Tmp_Int, Tmp_Size,10); //尺寸 PrintText(2320, 47 + 9 * Tmp_Int, Tmp_Size,10); //尺寸 PrintText(2610, 51 + 9 * Tmp_Int, Tmp_List.Strings[8],10); //面层位 PrintText(2880, 51 + 9 * Tmp_Int, Tmp_List.Strings[5],10); //单位 // 不足11位 补空格 Tmp_Price := Tmp_List.Strings[6]; PrintText(2995, 51 + 9 * Tmp_Int, StringOfChar(' ',11 - Length(Tmp_Price))+Tmp_Price,10); //单价 // 不足8位 补空格 Tmp_Dandian:=Tmp_List.Strings[7]; PrintText(3500, 51 + 9 * Tmp_Int, StringOfChar(' ',8 - Length(Tmp_Dandian))+Tmp_Dandian,10); //点检数 end; {*打印报表表格*} {*打印报表表格*} procedure Tfmmain.printdraw; var i : integer; begin Printer.Canvas.Pen.Width := 5; for I := 0 to 27 do DrawLine( 101, 37 + 9 * i , 4490, 37 + 9 * i); DrawLine( 101, 37, 101, 280); //1 DrawLine( 720, 37, 720, 271); //2 DrawLine( 1690, 37, 1690, 271); //3 DrawLine( 2300, 37, 2300, 271); //4 DrawLine( 2595, 37, 2595, 271); //5 DrawLine( 2870, 37, 2870, 271); //6 DrawLine( 2980, 37, 2980, 271); //7 DrawLine( 3490, 37, 3490, 280); //8 DrawLine( 3865, 37, 3865, 280); //9 DrawLine( 4000, 37, 4000, 280); //10 DrawLine( 4125, 37, 4125, 280); //11 DrawLine( 4490, 37, 4490, 280); //12 end; procedure Tfmmain.PrintFoot; begin PrintText(1301, 275, '合 计',10); PrintText(100, 284, '部长:',10); PrintText(1050, 284, '主管:',10); PrintText(2229, 284, '查核:',10); PrintText(3400, 284, '作表:',10); end;