📄 u_print.~pas
字号:
unit u_print;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
cxDataStorage, cxEdit, cxControls, cxGridCustomView,
cxGridCustomTableView, cxGridTableView, cxClasses, cxGridLevel, cxGrid,
cxMaskEdit, cxCurrencyEdit, cxCalendar, StdCtrls, cxContainer,
cxTextEdit, cxDropDownEdit, cxLookupEdit, cxDBLookupEdit,
cxDBLookupComboBox, DB, DBTables, shareunit;
type
Tfprint = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
TView: TcxGridTableView;
Viewcomno: TcxGridColumn;
Viewmodel: TcxGridColumn;
Viewnumber: TcxGridColumn;
Viewdate: TcxGridColumn;
Viewboxnum: TcxGridColumn;
Viewpagenum: TcxGridColumn;
comMuser: TcxLookupComboBox;
comMuser2: TcxLookupComboBox;
Label1: TLabel;
Tu: TTable;
TuMuser: TStringField;
TuName: TStringField;
dsu: TDataSource;
cxStyleRepository1: TcxStyleRepository;
cxStyle1: TcxStyle;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Table1: TTable;
procedure FormCreate(Sender: TObject);
procedure comMuserExit(Sender: TObject);
procedure comMuserKeyPress(Sender: TObject; var Key: Char);
procedure comMuserPropertiesEditValueChanged(Sender: TObject);
procedure ViewnumberPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption;
var Error: Boolean);
procedure ViewmodelPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption;
var Error: Boolean);
procedure ViewcomnoPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption;
var Error: Boolean);
procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
procedure SetValueType;
procedure addmodel;
procedure setpagenum(numno: integer; comnum: Variant);
{ Private declarations }
public
{ Public declarations }
end;
Const
FViewRowCount=10;
var
fprint: Tfprint;
implementation
uses dbBasic, u_RepTsLabel;
{$R *.dfm}
procedure Tfprint.SetValueType;
begin
with TView do
begin
Columns[0].DataBinding.ValueTypeClass:=TcxStringValueType;
Columns[1].DataBinding.ValueTypeClass:=TcxStringValueType;
Columns[2].DataBinding.ValueTypeClass:=TcxFloatValueType;
Columns[3].DataBinding.ValueTypeClass:=TcxDateTimeValueType;
Columns[4].DataBinding.ValueTypeClass:=TcxFloatValueType;
Columns[5].DataBinding.ValueTypeClass:=TcxFloatValueType;
end;
end;
procedure Tfprint.addmodel;
var
i: integer;
ssql: string;
begin
for i:=0 to TView.DataController.RowCount-1 do
begin
if trim(VarToStr(Tview.DataController.Values[i,1]))='' then continue;
if not ExistData('select * from Tmodel where model='''+trim(vartostr(Tview.DataController.Values[i,1]))+'''',[]) then
begin
ssql:='insert into Tmodel(model) values('''+trim(vartostr(Tview.DataController.Values[i,1]))+''')';
ExecMySQL(ssql,[]);
end;
end;
end;
procedure Tfprint.setpagenum(numno: integer; comnum: Variant);
var
b: array[0..0] of Variant;
begin
if trim(VarToStr(TView.DataController.Values[numno,1]))<>'' then
begin
if ExistData('select * from Tmodel where model=:model',[TView.DataController.Values[numno,1]]) then
begin
if GetData(b,'select boxnum from Tmodel where model=:model and boxnum>0 and (boxnum is not null)',[TView.DataController.Values[numno,1]]) then
begin
TView.DataController.Values[numno,4]:=b[0];
if comnum/b[0]=int(comnum/b[0]) then
TView.DataController.Values[numno,5]:=int(comnum/b[0])
else TView.DataController.Values[numno,5]:=int(comnum/b[0])+1;
end;
end else TView.DataController.Values[numno,5]:=1;
end;
end;
procedure Tfprint.FormCreate(Sender: TObject);
begin
with Tu do
begin
DataBaseName:=ExtractFilePath(Application.ExeName);
if not Active then Open;
end;
SetValueType;
ClearView(TView,FViewRowCount);
end;
procedure Tfprint.comMuserExit(Sender: TObject);
begin
if VarToStr(comMuser.EditValue)='' then exit;
if not comMuser.Properties.ListSource.DataSet.Locate('muser',VarToStr(comMuser.EditValue),[]) then
begin
PromptMsg('USER not found!',1);
comMuser.SetFocus;
end;
end;
procedure Tfprint.comMuserKeyPress(Sender: TObject; var Key: Char);
var
b: Boolean;
begin
if Key=#13 then
begin
cxGrid1.SetFocus;
TView.DataController.FocusedRowIndex:=0;
TView.DataController.FocusControl(0,b);
end;
end;
procedure Tfprint.comMuserPropertiesEditValueChanged(Sender: TObject);
var
b: Boolean;
begin
comMuser2.EditValue:=comMuser.EditValue;
if Showing then
begin
cxGrid1.SetFocus;
TView.DataController.FocusedRowIndex:=0;
TView.DataController.FocusControl(0,b);
end;
end;
procedure Tfprint.ViewnumberPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
//var
// b: array[0..0] of Variant;
begin
if VarToStr(DisplayValue)='' then exit;
if VarToStr(Viewdate.EditValue)='' then Viewdate.EditValue:=date;
setpagenum(TView.DataController.GetEditingRecordIndex,DisplayValue);
end;
procedure Tfprint.ViewmodelPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
if trim(VarToStr(DisplayValue))='' then exit;
if Error then
begin
PromptMsg('Incorrect data format!',2);
abort;
end;
{if ExistData('select * from Tmodel where model=:model',[VarToStr(DisplayValue)]) then
begin
if GetData(b,'select boxnum from Tmodel where model=:model',[VarToStr(DisplayValue)]) then
begin
Viewboxnum.EditValue:=b[0];
end;
end else
begin
ssql:='insert into Tmodel(model) values('''+VarToStr(DisplayValue)+''')';
promptMsg(ssql);
ExecMySQL(ssql,[]);
end;}
end;
procedure Tfprint.ViewcomnoPropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
if Error then
begin
PromptMsg('Data format is wrong!',2);
abort;
end;
end;
procedure Tfprint.Button3Click(Sender: TObject);
begin
close;
end;
procedure Tfprint.Button1Click(Sender: TObject);
begin
ClearView(TView,FViewRowCount);
end;
procedure Tfprint.Button4Click(Sender: TObject);
var
i: integer;
// b: array[0..0] of Variant;
begin
fmodel:=Tfmodel.create(nil);
with fmodel, fmodel.LabeledEdit1 do
try
Text:=trim(vartostr(viewmodel.EditValue));
addmodel;
if Text<>'' then
begin
//LabeledEdit1KeyPress(self,'#13');
if not ds.DataSet.Locate('model',LabeledEdit1.Text,[]) then
begin
LabeledEdit1.SetFocus;
end;
end;
showmodal;
TView.DataController.Post;
for i:=0 to TView.DataController.RowCount-1 do
if trim(vartostr(TView.DataController.Values[i,2]))<>'' then setpagenum(i,TView.DataController.Values[i,2]);
finally
free;
end;
end;
procedure Tfprint.Button2Click(Sender: TObject);
var
i, j: integer;
begin
screen.Cursor:=crHourglass;
try
TView.DataController.Post;
with table1 do
begin
DataBaseName:=ExtractFilePath(Application.ExeName);
if not Active then Open;
while not Eof do Delete;
for i:=0 to TView.DataController.RowCount-1 do
begin
if (vartostr(TView.DataController.Values[i,5])='') or (vartostr(TView.DataController.Values[i,2])='') then Continue;
addmodel;
for j:=0 to TView.DataController.Values[i,5]-1 do
begin
Append;
Fields[0].AsString:=vartostr(TView.DataController.Values[i,0]);
Fields[1].AsString:=vartostr(TView.DataController.Values[i,1]);
Fields[2].AsFloat:=TView.DataController.Values[i,2];
if vartostr(TView.DataController.Values[i,3])<>'' then Fields[3].AsDateTime:=TView.DataController.Values[i,3];
Fields[4].AsString:=VarToStr(comMuser2.EditValue);
Post;
end;
end;
end;
with TRepTsLabel.Create(nil) do
try
dbs.DatabaseName:=Table1.DatabaseName;
dbs.Close;
dbs.Open;
if not dbs.IsEmpty then
begin
PrinterSetup;
PreviewModal;
end else if Sender<>nil then PromptMsg('No DATA!',0);
finally
Free;
end;
finally
screen.Cursor:=crDefault;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -