RTFormwork/项目代码/RTBasicsV1/B03基础物料仓库/U_BSPrtOutEdit.pas

413 lines
13 KiB
ObjectPascal
Raw Permalink Normal View History

2024-07-07 09:35:27 +08:00
unit U_BSPrtOutEdit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
cxEdit, DB, cxDBData, cxCalendar, cxDropDownEdit, ComCtrls, ToolWin,
cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
cxClasses, cxControls, cxGridCustomView, cxGrid, cxGridCustomPopupMenu,
cxGridPopupMenu, ADODB, DBClient, cxButtonEdit, cxTextEdit, cxSpinEdit,
StdCtrls, ExtCtrls, cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore,
dxSkinsDefaultPainters, cxNavigator, dxDateRanges, dxBarBuiltInMenu,
U_BaseInput, System.ImageList, Vcl.ImgList;
type
TfrmBSPrtOutEdit = class(TfrmBaseInput)
ToolBar1: TToolBar;
TBAdd: TToolButton;
TBDel: TToolButton;
TBSave: TToolButton;
TBClose: TToolButton;
DataSource3: TDataSource;
CDS_Sub: TClientDataSet;
ADOQueryCmd: TADOQuery;
ADOQueryMain: TADOQuery;
ADOQueryTemp: TADOQuery;
cxGridPopupMenu2: TcxGridPopupMenu;
cxGrid1: TcxGrid;
Tv1: TcxGridDBTableView;
v1Column6: TcxGridDBColumn;
v1Column2: TcxGridDBColumn;
v1CRType: TcxGridDBColumn;
v2Column1: TcxGridDBColumn;
v1Column8: TcxGridDBColumn;
v2Column6: TcxGridDBColumn;
v1Column3: TcxGridDBColumn;
v1Column12: TcxGridDBColumn;
cxGrid1Level1: TcxGridLevel;
v1Column1: TcxGridDBColumn;
v1Column5: TcxGridDBColumn;
v1Column7: TcxGridDBColumn;
v1Column10: TcxGridDBColumn;
ToolButton1: TToolButton;
Tv1Column2: TcxGridDBColumn;
Tv1Column3: TcxGridDBColumn;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure TBAddClick(Sender: TObject);
procedure TBCloseClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure TBDelClick(Sender: TObject);
procedure TBSaveClick(Sender: TObject);
procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure ToolButton1Click(Sender: TObject);
procedure Tv1Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
private
{ Private declarations }
function SaveCKData(): Boolean;
public
{ Public declarations }
FBCId, FStkName, FKHName: string;
end;
var
frmBSPrtOutEdit: TfrmBSPrtOutEdit;
implementation
uses
U_DataLink, U_RTFun, U_ZDYHelp, U_BSPrtStkSel, U_CompanySel;
{$R *.dfm}
procedure TfrmBSPrtOutEdit.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inherited;
Action := caFree;
end;
procedure TfrmBSPrtOutEdit.TBAddClick(Sender: TObject);
begin
try
frmBSPrtStkSel := TfrmBSPrtStkSel.Create(Application);
with frmBSPrtStkSel do
begin
FstkName := Self.FstkName;
if ShowModal = 1 then
begin
frmBSPrtStkSel.CDS_Main.DisableControls;
with frmBSPrtStkSel.CDS_Main do
begin
First;
while frmBSPrtStkSel.CDS_Main.Locate('SSel', True, []) do
begin
with Self.CDS_Sub do
begin
Append;
FieldByName('IOTime').Value := Trim(FormatDateTime('yyyy-MM-dd', Now));
FieldByName('STKID').Value := frmBSPrtStkSel.CDS_Main.fieldbyname('BPIOID').Value;
FieldByName('IOType').Value := '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
FieldByName('FromCoNo').Value := frmBSPrtStkSel.CDS_Main.fieldbyname('FromCoNo').Value;
FieldByName('FromCoName').Value := frmBSPrtStkSel.CDS_Main.fieldbyname('FromCoName').Value;
FieldByName('StkCoNo').Value := frmBSPrtStkSel.CDS_Main.fieldbyname('StkCoNo').Value;
FieldByName('StkCoName').Value := frmBSPrtStkSel.CDS_Main.fieldbyname('StkCoName').Value;
FieldByName('ToCoNo').Value := frmBSPrtStkSel.CDS_Main.fieldbyname('StkCoNo').Value;
FieldByName('ToCoName').Value := frmBSPrtStkSel.CDS_Main.fieldbyname('StkCoName').Value;
FieldByName('P_Name').Value := frmBSPrtStkSel.CDS_Main.fieldbyname('P_Name').Value;
FieldByName('P_Code').Value := frmBSPrtStkSel.CDS_Main.fieldbyname('P_Code').Value;
FieldByName('P_Spec').Value := frmBSPrtStkSel.CDS_Main.fieldbyname('P_Spec').Value;
FieldByName('QtyUnit').Value := frmBSPrtStkSel.CDS_Main.fieldbyname('QtyUnit').Value;
FieldByName('Qty').Value := frmBSPrtStkSel.CDS_Main.fieldbyname('STKQTY').Value;
FieldByName('BatchNo').Value := frmBSPrtStkSel.CDS_Main.fieldbyname('BatchNo').Value;
FieldByName('FromOrdNo').Value := frmBSPrtStkSel.CDS_Main.fieldbyname('FromOrdNo').Value;
FieldByName('Workshop').Value := frmBSPrtStkSel.CDS_Main.fieldbyname('Workshop').Value;
end;
frmBSPrtStkSel.CDS_Main.Delete;
end;
end;
frmBSPrtStkSel.CDS_Main.EnableControls;
end;
end;
finally
frmBSPrtStkSel.Free;
end;
end;
function TfrmBSPrtOutEdit.SaveCKData(): Boolean;
var
MBPIOID, Maxno: string;
begin
try
ADOQueryCmd.Connection.BeginTrans;
CDS_Sub.DisableControls;
with CDS_Sub do
begin
First;
while not eof do
begin
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from BS_Product_IO where BPIOID=''' + Trim(CDS_Sub.fieldbyname('BPIOID').AsString) + '''');
Open;
end;
MBPIOID := Trim(ADOQueryTemp.fieldbyname('BPIOID').AsString);
if Trim(MBPIOID) = '' then
begin
if not GetLSNo(ADOQueryCmd, Maxno, 'PC', 'BS_Product_IO', 3, 1) then
raise Exception.Create('ȡȾɫ<C8BE><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>');
end
else
begin
Maxno := Trim(MBPIOID);
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select * from BS_Product_IO where BPIOID=''' + Trim(Maxno) + '''');
Open;
end;
with ADOQueryCmd do
begin
if Trim(MBPIOID) = '' then
begin
Append;
FieldByName('Filler').Value := Trim(DName)
end
else
begin
Edit;
FieldByName('Editer').Value := Trim(DName);
FieldByName('EditTime').Value := SGetServerDate(ADOQueryTemp);
end;
RTSetSaveDataCDS(ADOQueryCmd, Tv1, CDS_Sub, 'BS_Product_IO', 0);
FieldByName('STKName').Value := FSTKName;
FieldByName('BPIOID').Value := Trim(Maxno);
FieldByName('IOFlag').Value := '<27><><EFBFBD><EFBFBD>';
FieldByName('IOQtyFlag').Value := -1;
FieldByName('STKID').Value := CDS_Sub.fieldbyname('STKID').Value;
FieldByName('FromCoNo').Value := CDS_Sub.fieldbyname('FromCoNo').Value;
FieldByName('FromCoName').Value := CDS_Sub.fieldbyname('FromCoName').Value;
FieldByName('StkCoNo').Value := CDS_Sub.fieldbyname('StkCoNo').Value;
FieldByName('ToCoNo').Value := CDS_Sub.fieldbyname('ToCoNo').Value;
Post;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('Update BS_Product_IO Set STKQty=(select Sum(isnull(Qty,0)*IOQtyFlag) from BS_Product_IO A where A.STKID=BS_Product_IO.BPIOID )');
sql.Add('where BPIOID=''' + Trim(CDS_Sub.fieldbyname('STKID').AsString) + '''');
ExecSQL;
end;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from BS_Product_IO where BPIOID=''' + Trim(CDS_Sub.fieldbyname('STKID').AsString) + '''');
Open;
end;
if ADOQueryTemp.FieldByName('STKQty').Value < 0 then
raise Exception.Create('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܱ<EFBFBD><DCB1>棡');
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('insert into Finance_Need_Up(UType,UDataId,UOperation,UOperator,UModule,UDetails) ');
sql.Add('values(' + quotedstr(FSTKName + '<27><><EFBFBD><EFBFBD>'));
sql.Add(',' + quotedstr(Maxno));
sql.Add(',''<27><><EFBFBD><EFBFBD>'' ');
sql.Add(',' + quotedstr(DName));
sql.Add(',' + quotedstr(trim(self.Caption)));
sql.Add(',' + quotedstr(Maxno));
sql.Add(') ');
ExecSQL;
end;
Edit;
FieldByName('BPIOID').Value := Trim(Maxno);
Post;
Next;
end;
end;
CDS_Sub.EnableControls;
ADOQueryCmd.Connection.CommitTrans;
Result := True;
except
Result := False;
ADOQueryCmd.Connection.RollbackTrans;
application.MessageBox(PChar(Exception(ExceptObject).Message), '<27><>ʾ<EFBFBD><CABE>Ϣ', 0);
end;
end;
procedure TfrmBSPrtOutEdit.TBCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfrmBSPrtOutEdit.FormShow(Sender: TObject);
var
fsj: string;
begin
inherited;
ReadCxGrid(FSTKName + '<27><><EFBFBD><EFBFBD><EFBFBD>Ǽ<EFBFBD>', Tv1, '<27><><EFBFBD>ϲֿ<CFB2>');
self.Caption := FSTKName + '<27><><EFBFBD><EFBFBD><EFBFBD>Ǽ<EFBFBD>';
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add(' select A.* ');
sql.Add(' from BS_Product_IO A');
sql.Add(' where BPIOID=''' + Trim(FBCId) + '''');
Open;
end;
SCreateCDS(ADOQueryTemp, CDS_Sub);
SInitCDSData(ADOQueryTemp, CDS_Sub);
end;
procedure TfrmBSPrtOutEdit.TBDelClick(Sender: TObject);
begin
if CDS_Sub.IsEmpty then
Exit;
if Trim(CDS_Sub.fieldbyname('BPIOID').AsString) <> '' then
begin
if Application.MessageBox(<><C8B7>Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ', 32 + 4) <> IDYES then
Exit;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('exec P_Fin_Flow_Judge ');
Sql.Add(' @FFIDS=' + quotedstr(Trim(CDS_Sub.fieldbyname('BPIOID').AsString)));
Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
Sql.Add(',@DName=' + quotedstr(Trim(DName)));
Open;
end;
if ADOQueryTemp.FieldByName('intReturn').AsInteger = -1 then
begin
Application.MessageBox(PChar(ADOQueryTemp.fieldbyname('ShowMsg').AsString), '<27><>ʾ', 0);
exit;
end;
try
ADOQueryCmd.Connection.BeginTrans;
with ADOQueryCmd do
begin
Close;
Sql.Clear;
sql.Add('insert into Finance_Need_Up(UType,UDataId,UOperation,UOperator,UModule,UDetails) ');
sql.Add('values(' + quotedstr(FSTKName + '<27><><EFBFBD><EFBFBD>'));
sql.Add(',' + quotedstr(Trim(CDS_Sub.fieldbyname('BPIOID').AsString)));
sql.Add(','<><C9BE>'' ');
sql.Add(',' + quotedstr(DName));
sql.Add(',' + quotedstr(trim(self.Caption)));
sql.Add(',' + quotedstr(Trim(CDS_Sub.fieldbyname('BPIOID').AsString)));
sql.Add(') ');
Sql.Add('exec P_BS_Product_Out_Del ');
Sql.Add(' @BPIOIDS=' + quotedstr(Trim(CDS_Sub.fieldbyname('BPIOID').AsString)));
Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
Sql.Add(',@DName=' + quotedstr(Trim(DName)));
Open;
end;
if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
ADOQueryCmd.Connection.CommitTrans;
CDS_Sub.Delete;
except
ADOQueryCmd.Connection.RollbackTrans;
application.MessageBox(PChar(Exception(ExceptObject).Message), '<27><>ʾ<EFBFBD><CABE>Ϣ', 0);
end;
end
else
CDS_Sub.Delete;
end;
procedure TfrmBSPrtOutEdit.TBSaveClick(Sender: TObject);
begin
if CDS_Sub.IsEmpty then
Exit;
if CDS_Sub.Locate('IOTime', null, []) = True then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><E4B2BB>Ϊ<EFBFBD><CEAA>!', '<27><>ʾ', 0);
Exit;
end;
if CDS_Sub.Locate('IOType', null, []) = True then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><CDB2><EFBFBD>Ϊ<EFBFBD><CEAA>!', '<27><>ʾ', 0);
Exit;
end;
if CDS_Sub.Locate('Qty', null, []) = True then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>!', '<27><>ʾ', 0);
Exit;
end;
if SaveCKData() then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>!', '<27><>ʾ', 0);
//ModalResult:=1;
Exit;
end;
end;
procedure TfrmBSPrtOutEdit.ToolButton1Click(Sender: TObject);
begin
WriteCxGrid(fSTKName + '<27><><EFBFBD><EFBFBD><EFBFBD>Ǽ<EFBFBD>', Tv1, '<27><><EFBFBD>ϲֿ<CFB2>');
end;
procedure TfrmBSPrtOutEdit.Tv1Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
try
frmCompanySel := TfrmCompanySel.Create(Application);
with frmCompanySel do
begin
FCoType := '<27><>Ӧ<EFBFBD><D3A6>';
if ShowModal = 1 then
begin
with Self.CDS_Sub do
begin
Edit;
FieldByName('ToCoNo').Value := Trim(CDS_1.fieldbyname('CoCode').AsString);
FieldByName('ToCoName').Value := Trim(CDS_1.fieldbyname('CoAbbrName').AsString);
end;
end;
end;
finally
frmCompanySel.Free;
end;
end;
procedure TfrmBSPrtOutEdit.Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
FFSPID: string;
begin
if CDS_Sub.IsEmpty then
Exit;
if Trim(CDS_Sub.fieldbyname('BPIOID').AsString) <> '' then
begin
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from BS_Product_IO where BPIOID=''' + Trim(CDS_Sub.fieldbyname('BPIOID').AsString) + '''');
Open;
end;
FFSPID := Trim(ADOQueryTemp.fieldbyname('BPIOID').AsString);
if Trim(FFSPID) <> '' then
begin
v1CRType.Options.Editing := False;
end
else
begin
v1CRType.Options.Editing := True;
end;
end
else
begin
v1CRType.Options.Editing := True;
end;
end;
end.