471 lines
12 KiB
ObjectPascal
471 lines
12 KiB
ObjectPascal
![]() |
unit U_FDINVOICE_Sub;
|
|||
|
|
|||
|
interface
|
|||
|
|
|||
|
uses
|
|||
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|||
|
Dialogs, ComCtrls, ToolWin, cxStyles, cxCustomData, cxGraphics, cxFilter,
|
|||
|
cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxClasses,
|
|||
|
cxControls, cxGridCustomView, cxGridCustomTableView, cxGridTableView,
|
|||
|
cxGridDBTableView, cxGrid, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB,
|
|||
|
DBClient, ExtCtrls, StdCtrls, BtnEdit, cxButtonEdit, cxTextEdit;
|
|||
|
|
|||
|
type
|
|||
|
TFrmInvoice_Sub = class(TForm)
|
|||
|
DataSource1: TDataSource;
|
|||
|
FP_Sub: TClientDataSet;
|
|||
|
cxGridPopupMenu1: TcxGridPopupMenu;
|
|||
|
ToolBar1: TToolBar;
|
|||
|
TSave: TToolButton;
|
|||
|
TBClose: TToolButton;
|
|||
|
ToolBar2: TToolBar;
|
|||
|
TADD: TToolButton;
|
|||
|
TDEl: TToolButton;
|
|||
|
Panel1: TPanel;
|
|||
|
cxGrid1: TcxGrid;
|
|||
|
Tv1: TcxGridDBTableView;
|
|||
|
v1P_CodeName: TcxGridDBColumn;
|
|||
|
v1P_Spec: TcxGridDBColumn;
|
|||
|
v1Qty: TcxGridDBColumn;
|
|||
|
v1Price: TcxGridDBColumn;
|
|||
|
v1QtyUnit: TcxGridDBColumn;
|
|||
|
v1Money: TcxGridDBColumn;
|
|||
|
v1PriceUnit: TcxGridDBColumn;
|
|||
|
v1note: TcxGridDBColumn;
|
|||
|
cxGridLevel1: TcxGridLevel;
|
|||
|
Label1: TLabel;
|
|||
|
InvoiceNo: TEdit;
|
|||
|
Label2: TLabel;
|
|||
|
Label3: TLabel;
|
|||
|
InvoiceDate: TDateTimePicker;
|
|||
|
Note: TMemo;
|
|||
|
InvoiceType: TBtnEditA;
|
|||
|
ToFactoryName: TBtnEditA;
|
|||
|
FactoryName: TBtnEditA;
|
|||
|
Label4: TLabel;
|
|||
|
Label5: TLabel;
|
|||
|
Label6: TLabel;
|
|||
|
Label7: TLabel;
|
|||
|
Filler: TEdit;
|
|||
|
ADOQueryTmp: TADOQuery;
|
|||
|
ADOQueryCmd: TADOQuery;
|
|||
|
procedure TBCloseClick(Sender: TObject);
|
|||
|
procedure FormShow(Sender: TObject);
|
|||
|
procedure ToFactoryNameBtnClick(Sender: TObject);
|
|||
|
procedure TSaveClick(Sender: TObject);
|
|||
|
procedure FactoryNameBtnClick(Sender: TObject);
|
|||
|
procedure v1P_CodeNamePropertiesButtonClick(Sender: TObject;
|
|||
|
AButtonIndex: Integer);
|
|||
|
procedure InvoiceTypeBtnClick(Sender: TObject);
|
|||
|
procedure v1P_SpecPropertiesButtonClick(Sender: TObject;
|
|||
|
AButtonIndex: Integer);
|
|||
|
procedure v1QtyUnitPropertiesButtonClick(Sender: TObject;
|
|||
|
AButtonIndex: Integer);
|
|||
|
procedure v1PriceUnitPropertiesButtonClick(Sender: TObject;
|
|||
|
AButtonIndex: Integer);
|
|||
|
procedure TADDClick(Sender: TObject);
|
|||
|
procedure TDElClick(Sender: TObject);
|
|||
|
procedure v1QtyPropertiesEditValueChanged(Sender: TObject);
|
|||
|
procedure v1MoneyPropertiesEditValueChanged(Sender: TObject);
|
|||
|
private
|
|||
|
procedure initGrid();
|
|||
|
procedure SaveDate();
|
|||
|
{ Private declarations }
|
|||
|
public
|
|||
|
FInvoiceNO: string;
|
|||
|
fInvoiceFlag:string;
|
|||
|
{ Public declarations }
|
|||
|
end;
|
|||
|
|
|||
|
var
|
|||
|
FrmInvoice_Sub: TFrmInvoice_Sub;
|
|||
|
|
|||
|
implementation
|
|||
|
|
|||
|
uses U_Fun,U_ZDYHelp, U_ZdyAttachment,U_dataLink, U_ZdyAttachGYS;
|
|||
|
{$R *.dfm}
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.SaveDate();
|
|||
|
var FInvoiceID: string;
|
|||
|
begin
|
|||
|
ADOQueryCmd.Connection.BeginTrans;
|
|||
|
try
|
|||
|
with ADOQueryCmd do
|
|||
|
begin
|
|||
|
close;
|
|||
|
sql.Clear;
|
|||
|
sql.add('select * from FD_Invoice where InvoiceNo='''+trim(InvoiceNo.Text)+'''');
|
|||
|
open;
|
|||
|
if isempty then
|
|||
|
begin
|
|||
|
append;
|
|||
|
fieldbyname('filltime').AsDateTime:=SGetServerDate(ADOQueryTmp);
|
|||
|
end
|
|||
|
else
|
|||
|
edit;
|
|||
|
SSetsaveSqlnew(ADOQueryCmd,'FD_Invoice',panel1,0);
|
|||
|
fieldbyname('Invoiceflag').Value:=strtoint(FInvoiceflag);
|
|||
|
fieldbyname('chkstatus').AsString:='0';
|
|||
|
post;
|
|||
|
end;
|
|||
|
|
|||
|
with ADOQueryCmd do
|
|||
|
begin
|
|||
|
close;
|
|||
|
sql.Clear;
|
|||
|
sql.add('delete from FD_InvoiceSub where InvoiceNo='''+trim(InvoiceNo.Text)+''' ');
|
|||
|
execsql;
|
|||
|
end;
|
|||
|
with FP_Sub do
|
|||
|
begin
|
|||
|
first;
|
|||
|
while not eof do
|
|||
|
begin
|
|||
|
if fieldbyname('invoiceID').AsString='' then
|
|||
|
begin
|
|||
|
if GetLSNo(ADOQueryTmp,FInvoiceID,'FP','FD_InvoiceSub',4,1)=False then
|
|||
|
begin
|
|||
|
Application.MessageBox('ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>','<27><>ʾ',0);
|
|||
|
Exit;
|
|||
|
end;
|
|||
|
end
|
|||
|
else
|
|||
|
FInvoiceID:=FP_Sub.fieldbyname('invoiceID').AsString;
|
|||
|
with ADOQueryCmd do
|
|||
|
begin
|
|||
|
close;
|
|||
|
sql.Clear;
|
|||
|
sql.add('select * from FD_InvoiceSub where InvoiceNo='''+trim(InvoiceNo.Text)+''' ');
|
|||
|
sql.add('and InvoiceID='''+trim(FInvoiceID)+'''');
|
|||
|
open;
|
|||
|
end;
|
|||
|
if ADOQueryCmd.IsEmpty then
|
|||
|
begin
|
|||
|
ADOQueryCmd.append;
|
|||
|
end
|
|||
|
else
|
|||
|
begin
|
|||
|
ADOQueryCmd.edit;
|
|||
|
end;
|
|||
|
ADOQueryCmd.fieldbyname('InvoiceNo').Value:=trim(InvoiceNo.Text);
|
|||
|
ADOQueryCmd.fieldbyname('InvoiceID').Value:=FInvoiceID;
|
|||
|
SSetSaveDataCDSNew(ADOQueryCmd,Tv1,FP_Sub,'FD_InvoiceSub',0);
|
|||
|
ADOQueryCmd.fieldbyname('Qty').Value:=FP_Sub.fieldbyname('Qty').AsFloat;
|
|||
|
ADOQueryCmd.fieldbyname('Price').Value:=FP_Sub.fieldbyname('Price').AsFloat;
|
|||
|
ADOQueryCmd.fieldbyname('Money').Value:=FP_Sub.fieldbyname('Money').AsFloat;
|
|||
|
ADOQueryCmd.Post;
|
|||
|
next;
|
|||
|
end;
|
|||
|
end;
|
|||
|
ADOQueryCmd.Connection.CommitTrans;
|
|||
|
application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>','<27><>ʾ');
|
|||
|
Modalresult:=1;
|
|||
|
except
|
|||
|
ADOQueryCmd.Connection.RollbackTrans;
|
|||
|
application.MessageBox('<27><><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>','<27><>ʾ',MB_ICONERROR);
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.initGrid();
|
|||
|
begin
|
|||
|
with ADOQueryTmp do
|
|||
|
begin
|
|||
|
close;
|
|||
|
sql.Clear;
|
|||
|
sql.Add('select * from FD_Invoice where InvoiceNo='''+trim(FInvoiceNo)+'''');
|
|||
|
open;
|
|||
|
end;
|
|||
|
if ADOQueryTmp.isempty=False then
|
|||
|
begin
|
|||
|
SCSHDataNew(ADOQueryTmp,Panel1,0);
|
|||
|
end
|
|||
|
else
|
|||
|
begin
|
|||
|
Filler.Text:=trim(DName);
|
|||
|
InvoiceDate.DateTime:=SGetServerDate(ADOQueryCmd);
|
|||
|
end;
|
|||
|
with ADOQueryTmp do
|
|||
|
begin
|
|||
|
close;
|
|||
|
sql.Clear;
|
|||
|
sql.Add('select * from FD_InvoiceSub where InvoiceNo='''+trim(FInvoiceNo)+'''');
|
|||
|
open;
|
|||
|
end;
|
|||
|
SCreateCDS20(ADOQueryTmp,FP_Sub);
|
|||
|
SInitCDSData20(ADOQueryTmp,FP_Sub);
|
|||
|
end;
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.TBCloseClick(Sender: TObject);
|
|||
|
begin
|
|||
|
WriteCxGrid('<27><>Ʊ¼<C6B1><C2BC>',Tv1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
|||
|
Close;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.FormShow(Sender: TObject);
|
|||
|
begin
|
|||
|
ReadCxGrid('<27><>Ʊ¼<C6B1><C2BC>',Tv1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
|||
|
initGrid();
|
|||
|
end;
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.ToFactoryNameBtnClick(Sender: TObject);
|
|||
|
begin
|
|||
|
try
|
|||
|
frmZdyAttachment:=TfrmZdyAttachment.Create(Application);
|
|||
|
with frmZdyAttachment do
|
|||
|
begin
|
|||
|
if ShowModal=1 then
|
|||
|
begin
|
|||
|
ToFactoryName.Text:=Trim(CDS_HZ.fieldbyname('ZdyName').AsString);
|
|||
|
end;
|
|||
|
end;
|
|||
|
finally
|
|||
|
frmZdyAttachment.Free;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.TSaveClick(Sender: TObject);
|
|||
|
begin
|
|||
|
if trim(InvoiceNo.Text)='' then
|
|||
|
begin
|
|||
|
application.MessageBox('<27><>Ʊ<EFBFBD>Ų<EFBFBD><C5B2><EFBFBD>Ϊ<EFBFBD><CEAA>','<27><>ʾ');
|
|||
|
exit;
|
|||
|
end;
|
|||
|
{ if trim(InvoiceType.Text)='' then
|
|||
|
begin
|
|||
|
application.MessageBox('<27><>Ʊ<EFBFBD><C6B1><EFBFBD>Ͳ<EFBFBD><CDB2><EFBFBD>Ϊ<EFBFBD><CEAA>','<27><>ʾ');
|
|||
|
exit;
|
|||
|
end; }
|
|||
|
{if trim(ToFactoryName.Text)='' then
|
|||
|
begin
|
|||
|
application.MessageBox('<27>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>','<27><>ʾ');
|
|||
|
exit;
|
|||
|
end; }
|
|||
|
if trim(FactoryName.Text)='' then
|
|||
|
begin
|
|||
|
application.MessageBox('<27><>Ʊ<EFBFBD><C6B1>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>','<27><>ʾ');
|
|||
|
exit;
|
|||
|
end;
|
|||
|
if trim(FInvoiceNo)='' then
|
|||
|
begin
|
|||
|
with ADOQueryTmp do
|
|||
|
begin
|
|||
|
close;
|
|||
|
sql.clear;
|
|||
|
sql.add('select * from FD_Invoice where InvoiceNo='''+trim(InvoiceNo.Text)+''' ');
|
|||
|
open;
|
|||
|
end;
|
|||
|
if ADOQueryTmp.IsEmpty=False then
|
|||
|
begin
|
|||
|
application.MessageBox('<27><>Ʊ<EFBFBD>Ų<EFBFBD><C5B2><EFBFBD><EFBFBD>ظ<EFBFBD>','<27><>ʾ');
|
|||
|
exit;
|
|||
|
end;
|
|||
|
end;
|
|||
|
SaveDate();
|
|||
|
end;
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.FactoryNameBtnClick(Sender: TObject);
|
|||
|
begin
|
|||
|
IF fInvoiceflag='0' then
|
|||
|
begin
|
|||
|
try
|
|||
|
frmZdyAttachGYS:=TfrmZdyAttachGYS.Create(Application);
|
|||
|
with frmZdyAttachGYS do
|
|||
|
begin
|
|||
|
if ShowModal=1 then
|
|||
|
begin
|
|||
|
FactoryName.Text:=Trim(CDS_HZ.fieldbyname('ZdyName').AsString);
|
|||
|
end;
|
|||
|
end;
|
|||
|
finally
|
|||
|
frmZdyAttachGYS.Free;
|
|||
|
end;
|
|||
|
end
|
|||
|
else
|
|||
|
begin
|
|||
|
try
|
|||
|
frmZdyAttachment:=TfrmZdyAttachment.Create(Application);
|
|||
|
with frmZdyAttachment do
|
|||
|
begin
|
|||
|
if ShowModal=1 then
|
|||
|
begin
|
|||
|
FactoryName.Text:=Trim(CDS_HZ.fieldbyname('ZdyName').AsString);
|
|||
|
end;
|
|||
|
end;
|
|||
|
finally
|
|||
|
frmZdyAttachment.Free;
|
|||
|
end;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.v1P_CodeNamePropertiesButtonClick(
|
|||
|
Sender: TObject; AButtonIndex: Integer);
|
|||
|
begin
|
|||
|
try
|
|||
|
frmZDYHelp:=TfrmZDYHelp.Create(Application);
|
|||
|
with frmZDYHelp do
|
|||
|
begin
|
|||
|
flag:='MPRTCodeName';
|
|||
|
flagname:='<27><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>';
|
|||
|
if ShowModal=1 then
|
|||
|
begin
|
|||
|
Self.FP_Sub.Edit;
|
|||
|
Self.FP_Sub.FieldByName('P_CodeName').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
|
|||
|
Self.FP_Sub.FieldByName('P_Code').Value:=Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
|
|||
|
end;
|
|||
|
end;
|
|||
|
finally
|
|||
|
frmZDYHelp.Free;
|
|||
|
end;
|
|||
|
//self.tv1.Controller.EditingController.ShowEdit();
|
|||
|
end;
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.InvoiceTypeBtnClick(Sender: TObject);
|
|||
|
begin
|
|||
|
try
|
|||
|
frmZDYHelp:=TfrmZDYHelp.Create(Application);
|
|||
|
with frmZDYHelp do
|
|||
|
begin
|
|||
|
flag:='InvoiceType';
|
|||
|
flagname:='<27><>Ʊ<EFBFBD><C6B1><EFBFBD><EFBFBD>';
|
|||
|
if ShowModal=1 then
|
|||
|
begin
|
|||
|
InvoiceType.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
|
|||
|
end;
|
|||
|
end;
|
|||
|
finally
|
|||
|
frmZDYHelp.Free;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.v1P_SpecPropertiesButtonClick(Sender: TObject;
|
|||
|
AButtonIndex: Integer);
|
|||
|
begin
|
|||
|
try
|
|||
|
frmZDYHelp:=TfrmZDYHelp.Create(Application);
|
|||
|
with frmZDYHelp do
|
|||
|
begin
|
|||
|
flag:='P_Spec';
|
|||
|
flagname:='<27><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>';
|
|||
|
if ShowModal=1 then
|
|||
|
begin
|
|||
|
Self.FP_Sub.Edit;
|
|||
|
Self.FP_Sub.FieldByName('P_Spec').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
|
|||
|
end;
|
|||
|
end;
|
|||
|
finally
|
|||
|
frmZDYHelp.Free;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.v1QtyUnitPropertiesButtonClick(Sender: TObject;
|
|||
|
AButtonIndex: Integer);
|
|||
|
begin
|
|||
|
try
|
|||
|
frmZDYHelp:=TfrmZDYHelp.Create(Application);
|
|||
|
with frmZDYHelp do
|
|||
|
begin
|
|||
|
flag:='QtyUnit';
|
|||
|
flagname:='<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ';
|
|||
|
if ShowModal=1 then
|
|||
|
begin
|
|||
|
Self.FP_Sub.Edit;
|
|||
|
Self.FP_Sub.FieldByName('QtyUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
|
|||
|
end;
|
|||
|
end;
|
|||
|
finally
|
|||
|
frmZDYHelp.Free;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.v1PriceUnitPropertiesButtonClick(Sender: TObject;
|
|||
|
AButtonIndex: Integer);
|
|||
|
begin
|
|||
|
try
|
|||
|
frmZDYHelp:=TfrmZDYHelp.Create(Application);
|
|||
|
with frmZDYHelp do
|
|||
|
begin
|
|||
|
flag:='PriceUnit';
|
|||
|
flagname:='<27><><EFBFBD><EFBFBD>';
|
|||
|
if ShowModal=1 then
|
|||
|
begin
|
|||
|
Self.FP_Sub.Edit;
|
|||
|
Self.FP_Sub.FieldByName('PriceUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
|
|||
|
end;
|
|||
|
end;
|
|||
|
finally
|
|||
|
frmZDYHelp.Free;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.TADDClick(Sender: TObject);
|
|||
|
begin
|
|||
|
with FP_Sub do
|
|||
|
begin
|
|||
|
append;
|
|||
|
fieldbyname('PriceUnit').AsString:='RMB';
|
|||
|
fieldbyname('QtyUnit').AsString:='M';
|
|||
|
post;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.TDElClick(Sender: TObject);
|
|||
|
begin
|
|||
|
if FP_Sub.IsEmpty then exit;
|
|||
|
if application.MessageBox('ȷ<><C8B7>Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD>','<27><>ʾ',1)=2 then exit;
|
|||
|
with ADOQueryTmp do
|
|||
|
begin
|
|||
|
close;
|
|||
|
sql.clear;
|
|||
|
sql.add('delete from FD_Invoicesub where InvoiceID='''+trim(FP_Sub.fieldbyname('InvoiceID').asstring)+''' ');
|
|||
|
execsql;
|
|||
|
end;
|
|||
|
FP_Sub.delete;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.v1QtyPropertiesEditValueChanged(Sender: TObject);
|
|||
|
var
|
|||
|
mvalue,FFieldName:string;
|
|||
|
begin
|
|||
|
mvalue:=TcxTextEdit(Sender).EditingText;
|
|||
|
if Trim(mvalue)='' then
|
|||
|
begin
|
|||
|
mvalue:='0';
|
|||
|
end;
|
|||
|
FFieldName:=Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
|
|||
|
with FP_Sub do
|
|||
|
begin
|
|||
|
Edit;
|
|||
|
FieldByName(FFieldName).Value:=Trim(mvalue);
|
|||
|
FieldbyName('Money').Value:=format('%.2f',[FieldByName('Qty').AsFloat * FieldByName('Price').AsFloat]);
|
|||
|
Post;
|
|||
|
end;
|
|||
|
tv1.Controller.EditingController.ShowEdit();
|
|||
|
|
|||
|
end;
|
|||
|
|
|||
|
procedure TFrmInvoice_Sub.v1MoneyPropertiesEditValueChanged(
|
|||
|
Sender: TObject);
|
|||
|
var
|
|||
|
mvalue,FFieldName:string;
|
|||
|
begin
|
|||
|
mvalue:=TcxTextEdit(Sender).EditingText;
|
|||
|
if Trim(mvalue)='' then
|
|||
|
begin
|
|||
|
mvalue:='0';
|
|||
|
end;
|
|||
|
with FP_Sub do
|
|||
|
begin
|
|||
|
Edit;
|
|||
|
FieldByName('Money').Value:=Trim(mvalue);
|
|||
|
IF fieldbyname('Qty').AsFloat>0 then
|
|||
|
FieldbyName('price').Value:=format('%.4f',[FieldByName('money').AsFloat / FieldByName('Qty').AsFloat])
|
|||
|
else
|
|||
|
FieldbyName('price').Value:=0;
|
|||
|
Post;
|
|||
|
end;
|
|||
|
tv1.Controller.EditingController.ShowEdit();
|
|||
|
|
|||
|
end;
|
|||
|
|
|||
|
end.
|