RTFormwork/项目代码/RTBasicsV1/T01贸易生产计划/U_TradeCardInStk.pas
“ddf” 61630656e9 1
2024-07-07 09:35:27 +08:00

501 lines
14 KiB
ObjectPascal
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

unit U_TradeCardInStk;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
cxGrid, DBClient, cxCalendar, cxButtonEdit, cxSplitter, RM_Common, RM_Class,
RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, cxTextEdit, cxCheckBox,
BtnEdit, cxPC, MovePanel, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
dxBarBuiltInMenu, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges,
U_BaseList, Vcl.Menus, U_BaseInput, System.ImageList, Vcl.ImgList, StrUtils,
dxSkinWXI, dxScrollbarAnnotations, cxContainer, cxMaskEdit, cxDropDownEdit;
type
TfrmTradeCardInStk = class(TfrmBaseInput)
GPM_1: TcxGridPopupMenu;
ADOQueryCmd: TADOQuery;
ADOQueryMain: TADOQuery;
ADOQueryTemp: TADOQuery;
DS_1: TDataSource;
CDS_1: TClientDataSet;
PM_1: TPopupMenu;
cxStyleRepository1: TcxStyleRepository;
cxStyle1: TcxStyle;
cxGrid1: TcxGrid;
Tv1: TcxGridDBTableView;
v3Column8: TcxGridDBColumn;
Tv1Column7: TcxGridDBColumn;
Tv1Column3: TcxGridDBColumn;
Tv1Column4: TcxGridDBColumn;
Tv1Column5: TcxGridDBColumn;
Tv1Column6: TcxGridDBColumn;
cxGridLevel2: TcxGridLevel;
Panel3: TPanel;
Label1: TLabel;
Label12: TLabel;
Label13: TLabel;
Label16: TLabel;
Label17: TLabel;
Label2: TLabel;
Label3: TLabel;
Label6: TLabel;
Label5: TLabel;
Label8: TLabel;
C_Name: TcxTextEdit;
C_Code: TcxTextEdit;
ConNo: TcxTextEdit;
GC_Name: TcxTextEdit;
CraftCode: TcxTextEdit;
C_Color: TcxTextEdit;
C_Pattern: TcxTextEdit;
C_ColorConfirm: TcxTextEdit;
C_ColorNo: TcxTextEdit;
OrderNo: TcxTextEdit;
ToolBar1: TToolBar;
ToolButton12: TToolButton;
TBClose: TToolButton;
ADO_1: TADOQuery;
RM1: TRMGridReport;
ADOQueryPrint: TADOQuery;
RMDB_1: TRMDBDataSet;
btnRK: TToolButton;
Panel1: TPanel;
Label9: TLabel;
Label20: TLabel;
PCMeter: TcxTextEdit;
PCWeight: TcxTextEdit;
Tv1Column1: TcxGridDBColumn;
Tv1Column2: TcxGridDBColumn;
Label4: TLabel;
BatchNo: TcxTextEdit;
Tv1Column8: TcxGridDBColumn;
ToolButton1: TToolButton;
Label27: TLabel;
PCGrade: TcxComboBox;
Tv1Column9: TcxGridDBColumn;
Label7: TLabel;
PCTare: TcxTextEdit;
Tv1Column10: TcxGridDBColumn;
Tv1Column11: TcxGridDBColumn;
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure TBCloseClick(Sender: TObject);
procedure TBRafreshClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure cxTabControl1Change(Sender: TObject);
procedure ToolButton12Click(Sender: TObject);
procedure PCMeterKeyPress(Sender: TObject; var Key: Char);
procedure ToolButton1Click(Sender: TObject);
procedure btnRKClick(Sender: TObject);
procedure Tv1DblClick(Sender: TObject);
private
procedure InitOrd();
procedure InitGrid1();
procedure PrtData(MCIID: string);
procedure SaveCard(MCardQty: Integer; MBatchNo: string);
{ Private declarations }
public
FMainId, FSubId: string;
{ Public declarations }
end;
var
frmTradeCardInStk: TfrmTradeCardInStk;
implementation
uses
U_DataLink, U_RTFun, U_ZDYHelp, U_InputBoxCard, U_LabelPrint, U_TradePlanSel;
{$R *.dfm}
procedure TfrmTradeCardInStk.PrtData(MCIID: string);
var
fPrintFile, FLabVolume: string;
Txt, fImagePath, Txt2, fImagePath2: string;
Moudle: THandle;
Makebar: TMakebar;
Mixtext: TMixtext;
begin
with ADOQueryPrint do
begin
Close;
SQL.Clear;
sql.Add(' EXEC P_Trade_Card_Prt1 ');
SQL.Add(' @Filtration=''' + Trim(MCIID) + '''');
// ShowMessage(sql.Text);
Open;
end;
if ADOQueryPrint.IsEmpty then
begin
application.MessageBox('<27><>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD>δ<EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>', '<27><>ʾ<EFBFBD><CABE>Ϣ', MB_ICONERROR);
exit;
end;
FLabVolume := Trim(ADOQueryPrint.fieldbyname('LabVolume').AsString);
ExportFtErpFile(FLabVolume + '.rmf', ADOQueryTemp);
fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + FLabVolume + '.rmf';
if FileExists(fPrintFile) then
begin
RM1.LoadFromFile(fPrintFile);
RM1.DefaultCopies := 1;
RM1.PrintReport;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('update Trade_Plan_Card ');
sql.Add('set PRTer=' + quotedstr(DName));
sql.Add(', PRTCount=PRTCount+1');
sql.Add(', PRTDate=getdate()');
sql.Add(' where EXISTS(select X.RTValue from [dbo].[F_Tool_SplitString](' + QuotedStr(MCIID) + ','','') X where Trade_Plan_Card.PCID=X.RTValue ) ');
ExecSQL;
end;
end
else
begin
Application.MessageBox(PChar(<><C3BB><EFBFBD><EFBFBD>' + fPrintFile), '<27><>ʾ', 0);
end;
end;
procedure TfrmTradeCardInStk.InitOrd();
begin
with ADOQueryMain do
begin
Close;
sql.Clear;
sql.Add(' select A.*,B.*');
sql.Add(' ,YAPPS=ISNULL((select count(*) from Trade_Plan_Card X where X.MainId=A.MainId),0)');
sql.Add(' ,WAPPS=OrdPiece-ISNULL((select count(*) from Trade_Plan_Card X where X.MainId=A.MainId),0)');
sql.Add(' from Trade_Plan_Main A');
sql.Add(' inner join Trade_Plan_Sub B on A.MainId=B.MainId ');
sql.Add(' where B.SubId=' + QuotedStr(FSubId));
// ShowMessage(sql.Text);
Open;
end;
SCSHData(ADOQueryMain, Panel3, 0);
end;
procedure TfrmTradeCardInStk.InitGrid1();
var
Msql: string;
SqlStr: string;
begin
if trim(BatchNo.Text) <> '' then
Msql := ' BatchNo=' + QuotedStr(BatchNo.Text);
SqlStr := ' select *,PCWeight1=PCWeight-PCTare from Trade_Plan_Card A where Subid =''' + trim(FSubid) + '''';
InitCDSData(ADO_1, CDS_1, Tv1, SqlStr, Msql, '');
end;
procedure TfrmTradeCardInStk.FormDestroy(Sender: TObject);
begin
inherited;
frmTradeCardInStk := nil;
end;
procedure TfrmTradeCardInStk.PCMeterKeyPress(Sender: TObject; var Key: Char);
var
MPCID: string;
begin
if Key = #13 then
begin
if Trim(BatchNo.Text) = '' then
begin
application.MessageBox('<27><><EFBFBD><EFBFBD>дѡ<D0B4><D1A1><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD>', '<27><>ʾ<EFBFBD><CABE>Ϣ');
Exit;
end;
if StrToFloatDef(PCMeter.Text, 0) + StrToFloatDef(PCWeight.Text, 0) = 0 then
begin
application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ<EFBFBD><CABE>Ϣ');
Exit;
end;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add(' select top 1 * from Trade_Plan_Card A ');
sql.Add(' where Subid =''' + trim(FSubid) + '''');
sql.Add(' and BatchNo=' + QuotedStr(BatchNo.Text));
sql.Add(' and isnull(Status,''0'')=''0'' ');
sql.Add(' order by PCNo ');
Open;
end;
MPCID := ADOQueryTemp.FieldByName('PCID').AsString;
ADOQueryCmd.Connection.BeginTrans;
try
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('update Trade_Plan_Card ');
sql.Add(' set Status=''10'' ');
sql.Add(' , PCMeter=' + FloatToStr(StrToFloatDef(PCMeter.Text, 0)));
sql.Add(' , PCWeight=' + FloatToStr(StrToFloatDef(PCWeight.Text, 0)));
sql.Add(' , PCTare=' + FloatToStr(StrToFloatDef(PCTare.Text, 0)));
sql.Add(' , PCGrade=' + QuotedStr(PCGrade.Text));
sql.Add('where PCID=' + QuotedStr(MPCID));
ExecSQL;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('insert into Trade_Need_Up(UType,UDataId,UOperation,UOperator,UModule,UDetails) ');
sql.Add('values('<>׳<EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>'' ');
sql.Add(',' + quotedstr(MPCID));
sql.Add(',''<27><><EFBFBD><EFBFBD>'' ');
sql.Add(',' + quotedstr(DName));
sql.Add(',' + quotedstr(trim(self.Caption)));
sql.Add(',' + quotedstr(MPCID));
sql.Add(') ');
execsql;
end;
with ADOQueryCmd do
begin
Close;
Sql.Clear;
Sql.Add('exec P_Trade_Card_In_Stk ');
Sql.Add('@PCID=' + quotedstr(trim(MPCID)));
// Sql.Add(',@IOTime=' + Quotedstr(FormatDateTime('yyyy-MM-dd', SGetServerDate(ADOTmp))));
// Sql.Add(',@IOType=' + Quotedstr('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'));
// Sql.Add(',@IONO=' + Quotedstr(MINo));
// Sql.Add(',@StkPosition=' + Quotedstr(''));
// Sql.Add(',@FillId=' + Quotedstr(DCode));
// Sql.Add(',@Filler=' + Quotedstr(DName));
Open;
end;
if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
begin
raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
end;
ADOQueryCmd.Connection.CommitTrans;
application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>', '<27><>ʾ<EFBFBD><CABE>Ϣ');
except
ADOQueryCmd.Connection.RollbackTrans;
application.MessageBox(PChar(Exception(ExceptObject).Message), '<27><>ʾ<EFBFBD><CABE>Ϣ', 0);
end;
PCMeter.Text := '';
PCWeight.Text := '';
InitGrid1();
end;
end;
procedure TfrmTradeCardInStk.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inherited;
Action := caFree;
end;
procedure TfrmTradeCardInStk.TBCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfrmTradeCardInStk.TBRafreshClick(Sender: TObject);
begin
InitGrid1();
end;
procedure TfrmTradeCardInStk.FormShow(Sender: TObject);
begin
inherited;
ReadCxGrid(trim(self.Caption) + 'Tv1', Tv1, ʾ<D6B8><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
InitOrd();
InitGrid1();
end;
procedure TfrmTradeCardInStk.cxTabControl1Change(Sender: TObject);
begin
InitGrid1();
end;
procedure TfrmTradeCardInStk.ToolButton12Click(Sender: TObject);
begin
WriteCxGrid(trim(self.Caption) + 'Tv1', Tv1, ʾ<D6B8><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
end;
procedure TfrmTradeCardInStk.ToolButton1Click(Sender: TObject);
begin
InitGrid1();
end;
procedure TfrmTradeCardInStk.Tv1DblClick(Sender: TObject);
begin
BatchNo.Text := CDS_1.FieldByName('BatchNo').AsString;
end;
procedure TfrmTradeCardInStk.btnRKClick(Sender: TObject);
var
MINo, MStkIds: string;
begin
if CDS_1.IsEmpty then
exit;
btnRK.Enabled := False;
with CDS_1 do
begin
DisableControls;
First;
while not eof do
begin
MStkIds := MStkIds + Trim(CDS_1.FieldByName('PCID').AsString) + ',';
next;
end;
EnableControls;
end;
MStkIds := copy(MStkIds, 1, Length(MStkIds) - 1);
with ADOQueryTemp do
begin
Close;
SQL.Clear;
sql.Add(' select * from Trade_Cloth_IO A where IOFlag=''<27><><EFBFBD><EFBFBD>'' ');
SQL.Add(' and EXISTS(select X.RTValue from [dbo].[F_Tool_SplitString](' + quotedstr(MStkIds) + ','','') X where X.RTValue=A.StkID )');
Open;
end;
if not ADOQueryTemp.IsEmpty then
begin
application.MessageBox('<27><EFBFBD><EBB3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⣡', '<27><>ʾ<EFBFBD><CABE>Ϣ');
Exit;
end;
if GetLSNo(ADOQueryCmd, MINo, '9', 'Trade_Cloth_IO', 4, 1) = False then
begin
Application.MessageBox(<><C8A1><EFBFBD><EFBFBD><E2B5A5>ʧ<EFBFBD><CAA7>!', '<27><>ʾ', 0);
Exit;
end;
ADOQueryCmd.Connection.BeginTrans;
try
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('insert into Trade_Need_Up(UType,UDataId,UOperation,UOperator,UModule,UDetails) ');
sql.Add('values('<>׳<EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>'' ');
sql.Add(',' + quotedstr(MStkIds));
sql.Add(',''<27><><EFBFBD><EFBFBD>'' ');
sql.Add(',' + quotedstr(DName));
sql.Add(',' + quotedstr(trim(self.Caption)));
sql.Add(',' + quotedstr(MStkIds));
sql.Add(') ');
execsql;
end;
with ADOQueryCmd do
begin
Close;
Sql.Clear;
Sql.Add('exec P_Trade_Cloth_In ');
Sql.Add('@StkIds=' + quotedstr(trim(MStkIds)));
Sql.Add(',@IOTime=' + Quotedstr(FormatDateTime('yyyy-MM-dd', SGetServerDate(ADOQueryTemp))));
Sql.Add(',@IOType=' + Quotedstr('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'));
Sql.Add(',@IONO=' + Quotedstr(MINo));
Sql.Add(',@StkPosition=' + Quotedstr(''));
Sql.Add(',@FillId=' + Quotedstr(DCode));
Sql.Add(',@Filler=' + Quotedstr(DName));
Open;
end;
if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
begin
raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
end;
ADOQueryCmd.Connection.CommitTrans;
application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>', '<27><>ʾ<EFBFBD><CABE>Ϣ');
btnRK.Enabled := True;
except
btnRK.Enabled := True;
ADOQueryCmd.Connection.RollbackTrans;
application.MessageBox(PChar(Exception(ExceptObject).Message), '<27><>ʾ<EFBFBD><CABE>Ϣ', 0);
end;
end;
procedure TfrmTradeCardInStk.SaveCard(MCardQty: Integer; MBatchNo: string);
var
maxno, maxPCId, WSql: string;
i, j, MPCNo: integer;
begin
if MCardQty = 0 then
Exit;
try
ADOQueryCmd.Connection.BeginTrans;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select PCNo=isnull(Max(PCNo),0) ');
sql.Add('from Trade_Plan_Card A ');
sql.Add('where A.Subid=' + Quotedstr(Trim(FSubid)));
sql.Add('and A.BatchNo=' + Quotedstr(Trim(MBatchNo)));
Open;
end;
if ADOQueryTemp.IsEmpty then
MPCNo := 1
else
MPCNo := ADOQueryTemp.FieldByName('PCNo').AsInteger + 1;
////////////////// <20><><EFBFBD>벼Ʊ //////////////////////
if GetLSNo(ADOQueryTemp, maxno, 'PC', 'Trade_Plan_Mach', 2, 1) = False then
begin
raise Exception.Create(<><C8A1>Ʊ<EFBFBD><C6B1>ˮ<EFBFBD><CBAE>ʧ<EFBFBD><CAA7>!');
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add(' insert into Trade_Plan_Card(MainId,SubId,PCId,PCNo,PCDate,Filler,BatchNo) values');
for j := 1 to MCardQty do
begin
maxPCId := maxno + RightStr('00' + inttostr(j), 3);
if j > 1 then
sql.Add(',');
sql.Add(' (' + Quotedstr(Trim(FMainId)));
sql.Add(',' + Quotedstr(Trim(FSubId)));
sql.Add(',' + Quotedstr(maxPCId));
sql.Add(',' + Quotedstr(IntToStr(MPCNo)));
sql.Add(',getdate() ');
sql.Add(',' + Quotedstr(Trim(DName)));
sql.Add(',' + Quotedstr(Trim(MBatchNo)));
sql.Add(' )');
MPCNo := MPCNo + 1;
if WSql <> '' then
begin
WSql := WSql + ',' + QuotedStr(Trim(maxPCId));
end
else
begin
WSql := QuotedStr(Trim(maxPCId));
end;
end;
ExecSQL;
end;
ADOQueryCmd.Connection.CommitTrans;
PrtData(WSql);
except
ADOQueryCmd.Connection.RollbackTrans;
if GetLSNo(ADOQueryTemp, maxPCId, 'PC', 'Trade_Plan_Mach', 3, 1) = False then
begin
// raise Exception.Create('ȡ<><C8A1>Ʊ<EFBFBD><C6B1>ˮ<EFBFBD><CBAE>ʧ<EFBFBD><CAA7>!');
end;
application.MessageBox(PChar(Exception(ExceptObject).Message), '<27><>ʾ<EFBFBD><CABE>Ϣ', 0);
end;
InitGrid1();
end;
end.