unit U_code;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, ComCtrls, StdCtrls, ExtCtrls, ValEdit, DBGrids, DB, ADODB,
DBCtrls, RM_dset, RM_dbset, RM_class, RM_BarC, RM_Desgn, RM_Barcode;
type
TFrm_code = class(TForm)
Panel1: TPanel;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
ADOConnection1: TADOConnection;
DBNavigator1: TDBNavigator;
RMReport1: TRMReport;
RMDBDataSet1: TRMDBDataSet;
RMBarCodeObject1: TRMBarCodeObject;
RMDesigner1: TRMDesigner;
cbType: TComboBox;
SaveDialog1: TSaveDialog;
ADODataSet2: TADODataSet;
ADOTable1: TADOTable;
ADOTable1BarCode: TWideStringField;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure cbTypeChange(Sender: TObject);
function getRMBarcodeTypeFromRpt: TRMBarcodeType;
procedure setRMBarcodeTypeToCMB(v: TRMBarcodeType);
function getRMBarcodeTypeFromCMB: TRMBarcodeType;
procedure Button2Click(Sender: TObject);
private
exePath: string;
DataFileName: string;
rptFileName: string;
public
{ Public declarations }
end;
var
Frm_code: TFrm_code;
implementation
{$R *.dfm}
procedure TFrm_code.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree;
end;
function TFrm_code.getRMBarcodeTypeFromRpt: TRMBarcodeType;
var
i, j: integer;
begin
for i := 0 to RMReport1.Pages.Count - 1do
for j := 0 to RMReport1.Pages
.Objects.Count - 1do
begin
if TRMView(RMReport1.Pages.Objects[j]) is TRMBarCodeView then
begin
result := TRMbarCodeView(RMReport1.Pages.Objects[j]).Param.cBarType;
exit;
end;
end;
end;
procedure TFrm_code.FormCreate(Sender: TObject);
var
cBarType, iType: TRMBarcodeType;
i, j: integer;
strCon: string;
begin
exePath := ExtractFilePath(Application.ExeName);
DataFileName := exePath + 'barCode.xls';
strCon := 'Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=' + DataFileName + ';Mode=Share Deny None;Extended Properties=Excel 8.0;Jet OLEDB:System database="";'
+ 'Jet OLEDB:Registry Path="";Jet OLEDBatabase Password="";Jet OLEDB:Engine Type=35;Jet OLEDBatabase Locking Mode=0;'
+ 'Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;'
+ 'Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDBon''t Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False';
ADOConnection1.ConnectionString := strCon;
ADOConnection1.Open;
ADOTable1.Open;
rptFileName := exePath + 'rpt.rmf';
if not FileExists(rptFileName) then
RMReport1.SaveToFile(rptFileName);
RMReport1.LoadFromFile(rptFileName);
for iType := bcCode_2_5_interleaved to bcCodeEAN128Cdo
cbType.Items.Add(bcData[iType].Name);
cbType.ItemIndex := 0;
cBarType := getRMBarcodeTypeFromRpt;
setRMBarcodeTypeToCMB(cBarType);
end;
procedure TFrm_code.setRMBarcodeTypeToCMB(v: TRMBarcodeType);
var
i: integer;
iType: TRMBarcodeType;
str: string;
begin
str := '';
for iType := bcCode_2_5_interleaved to bcCodeEAN128Cdo
if iType = v then
begin
str := bcData[iType].Name;
break;
end;
i := cbType.Items.IndexOf(str);
if i >= 0 then
cbType.ItemIndex := i;
end;
function TFrm_code.getRMBarcodeTypeFromCMB: TRMBarcodeType;
var
iType: TRMBarcodeType;
str: string;
begin
str := cbType.Text;
for iType := bcCode_2_5_interleaved to bcCodeEAN128Cdo
if bcData[iType].Name = str then
begin
result := iType;
exit;
end;
end;
procedure TFrm_code.Button5Click(Sender: TObject);
begin
close;
end;
procedure TFrm_code.Button4Click(Sender: TObject);
begin
RMReport1.ShowReport;
end;
procedure TFrm_code.Button3Click(Sender: TObject);
begin
if RMReport1.DesignReport = mrok then
RMReport1.SaveToFile(rptFileName);
setRMBarcodeTypeToCMB(getRMBarcodeTypeFromRpt);
end;
procedure TFrm_code.cbTypeChange(Sender: TObject);
var
cBarType: TRMBarcodeType;
i, j: integer;
begin
cBarType := getRMBarcodeTypeFromCMB;
for i := 0 to RMReport1.Pages.Count - 1do
for j := 0 to RMReport1.Pages.Objects.Count - 1do
begin
if TRMView(RMReport1.Pages.Objects[j]) is TRMBarCodeView then
begin
TRMbarCodeView(RMReport1.Pages.Objects[j]).Param.cBarType := cBarType;
end;
end;
RMReport1.SaveToFile(rptFileName);
end;
procedure TFrm_code.Button2Click(Sender: TObject);
var
outFileName: string;
procedure saveToTxt;
var
sl: TstringList;
begin
sl := TstringList.Create;
ADODataSet2.Clone(ADOTable1);
sl.Text := ADODataSet2.Recordset.GetString(2, 9999, #9, #13#10, '');
sl.SaveToFile(outFileName);
ADODataSet2.Close;
freeandnil(sl);
end;
begin
if SaveDialog1.Execute then
begin
outFileName := uppercase(SaveDialog1.FileName);
if SaveDialog1.FilterIndex = 1 then
begin
if pos('.', outFileName) = 0 then
outFileName := outFileName + '.txt';
saveToTxt;
end;
end;
end;
end.
object Frm_code: TFrm_code
Left = 153
Top = 117
BorderIcons = [biSystemMenu]
BorderStyle = bsSingle
Caption = #26465#30721
ClientHeight = 423
ClientWidth = 592
Color = clBtnFace
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = #23435#20307
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
Scaled = False
OnClose = FormClose
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 16
object Panel1: TPanel
Left = 0
Top = 382
Width = 592
Height = 41
Align = alBottom
BevelOuter = bvLowered
TabOrder = 0
object Button2: TButton
Left = 14
Top = 8
Width = 75
Height = 25
Caption = #23548#20986
TabOrder = 0
OnClick = Button2Click
end
object Button3: TButton
Left = 164
Top = 8
Width = 75
Height = 25
Caption = #35774#35745
TabOrder = 1
OnClick = Button3Click
end
object Button4: TButton
Left = 89
Top = 8
Width = 75
Height = 25
Caption = #25171#21360
TabOrder = 2
OnClick = Button4Click
end
object Button5: TButton
Left = 498
Top = 8
Width = 75
Height = 25
Caption = #20851#38381
TabOrder = 3
OnClick = Button5Click
end
object cbType: TComboBox
Left = 253
Top = 8
Width = 174
Height = 24
Style = csDropDownList
ItemHeight = 16
TabOrder = 4
OnChange = cbTypeChange
end
end
object DBGrid1: TDBGrid
Left = 0
Top = 0
Width = 592
Height = 357
Align = alClient
DataSource = DataSource1
Options = [dgEditing, dgAlwaysShowEditor, dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgAlwaysShowSelection, dgCancelOnExit]
TabOrder = 1
TitleFont.Charset = GB2312_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -16
TitleFont.Name = #23435#20307
TitleFont.Style = []
end
object DBNavigator1: TDBNavigator
Left = 0
Top = 357
Width = 592
Height = 25
DataSource = DataSource1
VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast, nbInsert, nbEdit, nbPost]
Align = alBottom
Flat = True
Ctl3D = False
ParentCtl3D = False
ConfirmDelete = False
TabOrder = 2
end
object DataSource1: TDataSource
DataSet = ADOTable1
Left = 112
Top = 96
end
object ADOConnection1: TADOConnection
ConnectionString =
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:/'#23581#35797'/'#26465#30721'/BarCode.xl' +
's;Mode=Share Deny None;Extended Properties=Excel 8.0;Persist Sec' +
'urity Info=False'
LoginPrompt = False
Mode = cmShareDenyNone
Provider = 'Microsoft.Jet.OLEDB.4.0'
Left = 112
Top = 32
end
object RMReport1: TRMReport
InitialZoom = pzPageWidth
PreviewButtons = [pbZoom, pbLoad, pbSave, pbPrint, pbFind, pbHelp, pbExit]
StoreInDFM = True
Left = 248
Top = 104
ReportForm = {
26000000930100002600000000000000000A00C4ACC8CFB4F2D3A1BBFA00FF00
0400466F726D00000000DC000000780000007C0100002C0100000F0000800304
0900000034080000990B000024000000240000002400000024000000000000FF
FF0100000000000000FFFF0000000000006D00000000000000000000000200F3
0000000B004D61737465724461746131000000000000002C000000F002000045
00000030040500010031000000000000000000020000000200FFFFFF1F000000
00000C00524D4442446174615365743100000000000000000000FFFF00000000
000000000100000003000000C800000000000000000203000000000A0E005452
4D426172436F6465566965770000840100000400426172310000002600000030
0000008E0000003D000000000C00000100310000000000000000000200000002
00FFFFFF1F002E020000000000010015005B41444F5461626C65312E22426172
436F6465225D00000000000000FFFF0000000000010100030100000000000000
000000400000000000000000FC0100000000000000000000000000}
end
object RMDBDataSet1: TRMDBDataSet
DataSet = ADOTable1
Left = 248
Top = 72
end
object RMBarCodeObject1: TRMBarCodeObject
Left = 248
Top = 136
end
object RMDesigner1: TRMDesigner
HelpFile = 'rmuser.hlp'
Left = 248
Top = 168
end
object SaveDialog1: TSaveDialog
DefaultExt = 'data.txt'
Filter = #25991#26412#25991#20214'|*.txt'
Left = 248
Top = 200
end
object ADODataSet2: TADODataSet
Parameters = <>
Left = 128
Top = 216
end
object ADOTable1: TADOTable
Connection = ADOConnection1
CursorLocation = clUseServer
CursorType = ctStatic
TableDirect = True
TableName = 'BarCode$'
Left = 112
Top = 64
object ADOTable1BarCode: TWideStringField
FieldName = 'BarCode'
Size = 255
end
end
end