D7wmguihua/桂华管理系统/U_ClothContractListDH.pas
DESKTOP-E401PHE\Administrator b4b5840f18 1
2025-01-18 16:22:10 +08:00

1019 lines
33 KiB
ObjectPascal
Raw 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_ClothContractListDH;
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;
type
TfrmClothContractListDH = class(TForm)
ToolBar1: TToolBar;
TBRafresh: TToolButton;
TBFind: TToolButton;
TBClose: TToolButton;
Panel1: TPanel;
BegDate: TDateTimePicker;
EndDate: TDateTimePicker;
Label1: TLabel;
Label2: TLabel;
cxGridPopupMenu1: TcxGridPopupMenu;
ADOQueryCmd: TADOQuery;
ADOQueryMain: TADOQuery;
ADOQueryTemp: TADOQuery;
DataSource1: TDataSource;
Label3: TLabel;
ConNoM: TEdit;
Label5: TLabel;
C_CodeNameM: TEdit;
Order_Main: TClientDataSet;
Label4: TLabel;
C_Spec: TEdit;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ClientDataSet3: TClientDataSet;
DataSource2: TDataSource;
DataSource3: TDataSource;
ClientDataSet2: TClientDataSet;
ToolButton5: TToolButton;
RM1: TRMGridReport;
RMDBMain: TRMDBDataSet;
RMXLSExport1: TRMXLSExport;
cxGrid1: TcxGrid;
Tv1: TcxGridDBTableView;
v1OrderNo: TcxGridDBColumn;
v1Column2: TcxGridDBColumn;
v1DeliveryDate: TcxGridDBColumn;
v1Column5: TcxGridDBColumn;
v1FactoryNo1Name: TcxGridDBColumn;
v1PRTSpec: TcxGridDBColumn;
v1PRTMF: TcxGridDBColumn;
v1PRTKZ: TcxGridDBColumn;
v1Qty1: TcxGridDBColumn;
v1PRTOrderQty: TcxGridDBColumn;
v1OrderUnit: TcxGridDBColumn;
v1Column4: TcxGridDBColumn;
cxGrid1Level1: TcxGridLevel;
cxSplitter1: TcxSplitter;
Panel2: TPanel;
cxGrid2: TcxGrid;
Tv2: TcxGridDBTableView;
v2ComeDate: TcxGridDBColumn;
v2Column3: TcxGridDBColumn;
v2MxQty: TcxGridDBColumn;
v2MxNote: TcxGridDBColumn;
cxGrid2Level1: TcxGridLevel;
ToolBar2: TToolBar;
ToolButton8: TToolButton;
ToolButton9: TToolButton;
ToolButton10: TToolButton;
cxGridPopupMenu2: TcxGridPopupMenu;
v2Column1: TcxGridDBColumn;
v1Column1: TcxGridDBColumn;
v1Column3: TcxGridDBColumn;
v2Column2: TcxGridDBColumn;
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure TBCloseClick(Sender: TObject);
procedure TBFindClick(Sender: TObject);
procedure TBRafreshClick(Sender: TObject);
procedure ConNoMChange(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView;
APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
ANewItemRecordFocusingChanged: Boolean);
procedure Tv2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Tv3MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ToolButton4Click(Sender: TObject);
procedure Tv2CellClick(Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
procedure ToolButton5Click(Sender: TObject);
procedure ToolButton3Click(Sender: TObject);
procedure v2Column3PropertiesButtonClick(Sender: TObject;
AButtonIndex: Integer);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure ConNoMKeyPress(Sender: TObject; var Key: Char);
procedure Tv1CellClick(Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
private
FInt,PFInt:Integer;
procedure InitGrid();
procedure InitForm();
function DelData():Boolean;
function YFData():Boolean;
function DelYFData():Boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
frmClothContractListDH: TfrmClothContractListDH;
implementation
uses
U_DataLink,U_ClothContractInPut,U_Fun,U_ProductOrderList,U_ZDYHelp;
{$R *.dfm}
procedure TfrmClothContractListDH.FormDestroy(Sender: TObject);
begin
frmClothContractListDH:=nil;
end;
procedure TfrmClothContractListDH.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action:=caFree;
end;
procedure TfrmClothContractListDH.FormCreate(Sender: TObject);
begin
//BegDate.DateTime:=SGetServerDateTime(ADOQueryTemp)-7;
//EndDate.DateTime:=SGetServerDateTime(ADOQueryTemp);
end;
procedure TfrmClothContractListDH.TBCloseClick(Sender: TObject);
begin
Close;
WriteCxGrid('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>dh',Tv1,ʾ<D6B8><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
WriteCxGrid('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>dhr',Tv2,ʾ<D6B8><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
end;
procedure TfrmClothContractListDH.InitGrid();
begin
try
ADOQueryMain.DisableControls;
with ADOQueryMain do
begin
Filtered:=False;
Close;
sql.Clear;
sql.Add('exec ClothContract_QryList :MainId,:WSql');
Parameters.ParamByName('WSql').Value:=' and FillTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+''''
+' and FillTime<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.DateTime+1))+'''';
Open;
end;
SCreateCDS20(ADOQueryMain,Order_Main);
SInitCDSData20(ADOQueryMain,Order_Main);
finally
ADOQueryMain.EnableControls;
end;
end;
procedure TfrmClothContractListDH.InitForm();
begin
ReadCxGrid('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>dh',Tv1,ʾ<D6B8><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
ReadCxGrid('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>dhr',Tv2,ʾ<D6B8><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
BegDate.DateTime:=SGetServerDate10(ADOQueryTemp)-7;
EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
InitGrid();
end;
procedure TfrmClothContractListDH.TBFindClick(Sender: TObject);
begin
if ADOQueryMain.Active=False then Exit;
SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
SCreateCDS20(ADOQueryMain,Order_Main);
SInitCDSData20(ADOQueryMain,Order_Main);
end;
function TfrmClothContractListDH.DelData():Boolean;
begin
try
Result:=false;
ADOQueryCmd.Connection.BeginTrans;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('delete Contract_Sub where SubId='''+Trim(Order_Main.fieldbyname('SubId').AsString)+'''');
ExecSQL;
end;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from Contract_Sub where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
Open;
end;
if ADOQueryTemp.IsEmpty then
begin
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('delete Contract_Main where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
ExecSQL;
end;
end;
if Trim(Order_Main.fieldbyname('SubId').AsString)='' then
begin
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('delete Contract_Main where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
ExecSQL;
end;
end;
ADOQueryCmd.Connection.CommitTrans;
Result:=True;
except
ADOQueryCmd.Connection.RollbackTrans;
Result:=False;
Application.MessageBox('<27><><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><ECB3A3>','<27><>ʾ',0);
end;
end;
procedure TfrmClothContractListDH.TBRafreshClick(Sender: TObject);
begin
InitGrid();
end;
procedure TfrmClothContractListDH.ConNoMChange(Sender: TObject);
begin
if ADOQueryMain.Active=False then Exit;
SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
SCreateCDS20(ADOQueryMain,Order_Main);
SInitCDSData20(ADOQueryMain,Order_Main);
end;
procedure TfrmClothContractListDH.FormShow(Sender: TObject);
begin
InitForm();
end;
procedure TfrmClothContractListDH.ToolButton2Click(Sender: TObject);
begin
if Order_Main.IsEmpty then Exit;
{ with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from JYOrder_Main where OrderNo='''+Trim(Order_Main.fieldbyname('ConNo').AsString)+'''');
Open;
end;
if ADOQueryTemp.IsEmpty then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD>δ¼<CEB4><C2BC>!','<27><>ʾ',0);
Exit;
end else
begin
if ADOQueryTemp.RecordCount>1 then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ظ<EFBFBD>!','<27><>ʾ',0);
Exit;
end;
end; }
ClientDataSet2.Append;
ClientDataSet2.FieldByName('MXUnit').Value:=Trim(Order_Main.fieldbyname('C_Unit').AsString);
ClientDataSet2.Post;
end;
procedure TfrmClothContractListDH.Tv1FocusedRecordChanged(
Sender: TcxCustomGridTableView; APrevFocusedRecord,
AFocusedRecord: TcxCustomGridRecord;
ANewItemRecordFocusingChanged: Boolean);
begin
with ADOQueryTemp do
begin
Close;
sql.Clear;
SQL.Add('select A.*,KCSL=A.MXQty-(select isnull(Sum(TPQty),0) from Contract_Sub_Mxto B where B.MXID=A.MXID),');
sql.Add(' KCPS=A.Qty1-(select isnull(Sum(Qty1),0) from Contract_Sub_Mxto B where B.MXID=A.MXID)');
sql.Add('from Contract_Sub_Mx A');
sql.Add(' where A.SubId='''+Trim(Order_Main.fieldbyname('SubId').AsString)+'''');
Open;
end;
SCreateCDS20(ADOQueryTemp,ClientDataSet2);
SInitCDSData20(ADOQueryTemp,ClientDataSet2);
with ADOQueryTemp do
begin
Close;
sql.Clear;
SQL.Add('select A.*,C.MPRTSpec,B.PRTColor,C.MPRTCodeName,C.OrderNo ,');
sql.Add('C_Unit=(select Top 1 C_Unit from Contract_Sub AA,Contract_Sub_Mx BB where AA.SubId=BB.SubId and BB.MXid=A.Mxid)');
SQL.Add('from Contract_Sub_MxTo A inner join JYOrder_Sub B on A.OrdSubId=B.SubId');
SQL.Add(' inner join JYOrder_Main C on C.MainId=B.MainId ');
sql.Add('where A.MxId='''+Trim(ClientDataSet2.fieldbyname('MxId').AsString)+'''');
Open;
end;
SCreateCDS20(ADOQueryTemp,ClientDataSet3);
SInitCDSData20(ADOQueryTemp,ClientDataSet3);
end;
procedure TfrmClothContractListDH.Tv2MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
FInt:=2;
end;
procedure TfrmClothContractListDH.Tv1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
FInt:=1;
end;
procedure TfrmClothContractListDH.Tv3MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
FInt:=3;
end;
procedure TfrmClothContractListDH.ToolButton4Click(Sender: TObject);
var
maxno:string;
begin
if ClientDataSet2.IsEmpty then Exit;
if ClientDataSet2.Locate('ComeDate',null,[]) then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>','<27><>ʾ',0);
Exit;
end;
if ClientDataSet2.Locate('RKPlace',null,[]) then
begin
Application.MessageBox('<27><><EFBFBD>ŵص㲻<D8B5><E3B2BB>Ϊ<EFBFBD>գ<EFBFBD>','<27><>ʾ',0);
Exit;
end;
if ClientDataSet2.Locate('RKPlace','',[]) then
begin
Application.MessageBox('<27><><EFBFBD>ŵص㲻<D8B5><E3B2BB>Ϊ<EFBFBD>գ<EFBFBD>','<27><>ʾ',0);
Exit;
end;
if ClientDataSet2.Locate('MxQty',null,[]) then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>','<27><>ʾ',0);
Exit;
end;
BegDate.SetFocus;
try
ADOQueryCmd.Connection.BeginTrans;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8>
with ClientDataSet2 do
begin
First;
while not eof do
begin
if Trim(ClientDataSet2.fieldbyname('MXId').AsString)='' then
begin
if GetLSNo(ADOQueryCmd,maxno,'MX','Contract_Sub_Mx',4,1)=False then
begin
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox(<><C8A1>ϸ<EFBFBD><CFB8>ˮ<EFBFBD><CBAE>ʧ<EFBFBD>ܣ<EFBFBD>','<27><>ʾ',0);
Exit;
end;
end else
begin
maxno:=Trim(ClientDataSet2.fieldbyname('MXId').AsString);
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select * from Contract_Sub_Mx where MxId='''+Trim(ClientDataSet2.fieldbyname('MXId').AsString)+'''');
Open;
end;
with ADOQueryCmd do
begin
if Trim(ClientDataSet2.fieldbyname('MXId').AsString)='' then
Append
else
Edit;
FieldByName('MxId').Value:=Trim(maxno);
FieldByName('SubId').Value:=Trim(Order_Main.fieldbyname('SubId').AsString);
SSetSaveDataCDSNew(ADOQueryCmd,Tv2,ClientDataSet2,'Contract_Sub_Mx',2);
FieldByName('MXUnit').Value:=Trim(Order_Main.fieldbyname('C_Unit').AsString);
FieldByName('RKPLCode').Value:=Trim(ClientDataSet2.fieldbyname('RKPLCode').AsString);
if Trim(ClientDataSet2.fieldbyname('Qty1').AsString)='' then
begin
FieldByName('Qty1').Value:=0;
end;
if Trim(ClientDataSet2.fieldbyname('MxQty').AsString)='' then
begin
FieldByName('MxQty').Value:=0;
end;
if Trim(Order_Main.fieldbyname('C_Unit').AsString)='Kg' then
begin
FieldByName('MxMQty').Value:=ClientDataSet2.fieldbyname('MxQty').Value*1.00*1000
/(Order_Main.fieldbyname('MFQty').Value*1.00/100*Order_Main.fieldbyname('KZQty').Value);
end else
begin
FieldByName('MxMQty').Value:=ClientDataSet2.fieldbyname('MxQty').Value;
end;
Post;
end;
with ClientDataSet2 do
begin
Edit;
FieldByName('MxId').Value:=Trim(maxno);
Post;
end;
{ if YFData()=False then
begin
ADOQueryCmd.Connection.RollbackTrans;
Exit;
end; }
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from Contract_Cloth_DH where SubId='''+Trim(Order_Main.fieldbyname('SubId').AsString)+'''');
sql.Add(' and FirstNo='''+Trim(ClientDataSet2.fieldbyname('RKPLCode').AsString)+'''');
Open;
end;
if ADOQueryTemp.IsEmpty then
begin
if GetLSNo(ADOQueryCmd,maxno,'DH','Contract_Cloth_DH',4,1)=False then
begin
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox(<><C8A1>ϸ<EFBFBD><CFB8>ˮ<EFBFBD><CBAE>ʧ<EFBFBD>ܣ<EFBFBD>','<27><>ʾ',0);
Exit;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select * from Contract_Cloth_DH where 1<>1');
Open;
end;
with ADOQueryCmd do
begin
Append;
FieldByName('MainId').Value:=Trim(Order_Main.fieldbyname('Mainid').AsString);
FieldByName('SubId').Value:=Trim(Order_Main.fieldbyname('SubId').AsString);
FieldByName('DHId').Value:=Trim(maxno);
FieldByName('FirstNo').Value:=Trim(ClientDataSet2.fieldbyname('RKPLCode').AsString);
FieldByName('FirstName').Value:=Trim(ClientDataSet2.fieldbyname('RKPLace').AsString);
FieldByName('DHUnit').Value:=Trim(Order_Main.fieldbyname('C_Unit').AsString);
Post;
end;
end else
begin
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('Update Contract_Cloth_DH Set DHUnit='''+Trim(Order_Main.fieldbyname('C_Unit').AsString)+'''');
sql.Add(' where DHID='''+Trim(ADOQueryTemp.fieldbyname('DHID').AsString)+'''');
ExecSQL;
end;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('Update Contract_Cloth_DH Set DHQty=(select Sum(MxQty) from Contract_Sub_Mx A where A.SubId=Contract_Cloth_DH.SubId');
sql.Add(' and A.RKPLCode=Contract_Cloth_DH.FirstNo)');
sql.Add(',DHMQty=(select Sum(MxMQty) from Contract_Sub_Mx A where A.SubId=Contract_Cloth_DH.SubId');
sql.Add(' and A.RKPLCode=Contract_Cloth_DH.FirstNo)');
sql.Add(', DHPS=(select Sum(Qty1) from Contract_Sub_Mx A where A.SubId=Contract_Cloth_DH.SubId');
sql.Add(' and A.RKPLCode=Contract_Cloth_DH.FirstNo)');
sql.Add(' where SubId='''+Trim(Order_Main.fieldbyname('Subid').AsString)+'''');
sql.Add(' and FirstNo='''+Trim(ClientDataSet2.fieldbyname('RKPLCode').AsString)+'''');
ExecSQL;
end;
Next;
end;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('delete Contract_Cloth_DH ');
sql.Add('where not exists(select * from Contract_Sub_Mx A where A.SubId=Contract_Cloth_DH.SubId and A.RKPlace=Contract_Cloth_DH.firstName) ');
sql.Add(' and SubId='''+Trim(Order_Main.fieldbyname('SubId').AsString)+'''');
ExecSQL;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select * from Contract_Cloth_LLMX B where not exists(select * from ');
sql.Add(' Contract_Cloth_DH A where A.DHID=B.DHID ');
SQL.Add(' and A.SubId=B.SubId ) and B.SubId='''+Trim(Order_Main.fieldbyname('SubId').AsString)+'''');
Open;
end;
if ADOQueryCmd.IsEmpty=False then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܱ<EFBFBD><DCB1><EFBFBD>!','<27><>ʾ',0);
//begin
ADOQueryCmd.Connection.RollbackTrans;
Exit;
//end;
end;
{with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('delete YFMoney');
ExecSQL;
end;}
ADOQueryCmd.Connection.CommitTrans;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>','<27><>ʾ',0);
except
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><ECB3A3>','<27><>ʾ',0);
end;
end;
function TfrmClothContractListDH.YFData():Boolean;
var
CRID,OrdMainId,YFID,FComTaiTou,FCRID,FFactoryName:String;
begin
Result:=False;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from JYOrder_Main where OrderNo='''+Trim(Order_Main.fieldbyname('ConNo').AsString)+'''');
Open;
end;
if ADOQueryTemp.IsEmpty then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD>δ¼<CEB4><C2BC>!','<27><>ʾ',0);
Exit;
end else
begin
if ADOQueryTemp.RecordCount>1 then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ظ<EFBFBD>!','<27><>ʾ',0);
Exit;
end;
end;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from JYOrder_Main where OrderNo='''+Trim(Order_Main.fieldbyname('ConNo').AsString)+'''');
Open;
end;
OrdMainId:=Trim(ADOQueryTemp.fieldbyname('MainId').AsString);
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select OrdDefStr2 from JYOrder_Main where Mainid='''+Trim(OrdMainId)+'''');
Open;
end;
FComTaiTou:=Trim(ADOQueryTemp.fieldbyname('OrdDefStr2').AsString);
with ADOQueryTemp do
begin
Close;
SQL.Clear;
sql.Add('select * from YF_Money_KC where FactoryName='''+Trim(Order_Main.fieldbyname('FactoryNoName').AsString)+'''');
Open;
end;
if ADOQueryTemp.IsEmpty=False then
begin
CRID:=ADOQueryTemp.fieldbyname('CRID').AsString;
end else
begin
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('Update YF_Money_CRID set CRID=CRID+1');
sql.Add('select * from YF_Money_CRID ');
Open;
end;
CRID:=ADOQueryCmd.fieldbyname('CRID').AsString;
with ADOQueryCmd do
begin
Close;
SQL.Clear;
sql.Add('select * from YF_Money_KC where 1<>1');
Open;
end;
with ADOQueryCmd do
begin
Append;
FieldByName('CRID').Value:=StrToInt(CRID);
FieldByName('FactoryName').Value:=Trim(Order_Main.fieldbyname('FactoryNoName').AsString);
FieldByName('ZdyStr1').Value:=<><D3A6><EFBFBD><EFBFBD>';
Post;
end;
end;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from YF_Money_CR where FactoryName='''+Trim(Order_Main.fieldbyname('FactoryNoName').AsString)+'''');
sql.Add(' and YFTypeId='''+Trim(ClientDataSet2.fieldbyname('MXId').AsString)+'''');
Open;
end;
//if ADOQueryTemp.IsEmpty then
begin
if ADOQueryTemp.IsEmpty then
begin
if GetLSNo(ADOQueryCmd,YFID,'PF','YF_Money_CR',3,1)=False then
begin
Application.MessageBox(<><C8A1><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>!','<27><>ʾ',0);
Exit;
end;
end else
begin
YFID:=Trim(ADOQueryTemp.fieldbyname('YFID').AsString);
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select * from YF_Money_CR where YFID='''+Trim(YFID)+'''');
Open;
end;
with ADOQueryCmd do
begin
if ADOQueryTemp.IsEmpty then
Append
else
Edit;
FieldByName('YFID').Value:=Trim(YFID);
FieldByName('YFTypeId').Value:=Trim(ClientDataSet2.fieldbyname('MXId').AsString);
FieldByName('CRID').Value:=StrToInt(CRID);
FieldByName('Filler').Value:=Trim(DName);
FieldByName('CRType').Value:=<><D3A6><EFBFBD><EFBFBD><EFBFBD>Ǽ<EFBFBD>';
FieldByName('CRFlag').Value:=<><D3A6><EFBFBD><EFBFBD>';
FieldByName('QtyFlag').Value:=1;
FieldByName('FactoryName').Value:=Trim(Order_Main.fieldbyname('FactoryNoName').AsString);
FieldByName('CRTime').Value:=ClientDataSet2.fieldbyname('ComeDate').Value;
FieldByName('Qty').Value:=ClientDataSet2.fieldbyname('MXQty').Value;
FieldByName('PS').Value:=ClientDataSet2.fieldbyname('Qty1').Value;
FieldByName('YFType').Value:='<27>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>';
FieldByName('Price').Value:=Order_Main.fieldbyname('Price').Value;
FieldByName('HuiLv').Value:=1;
FieldByName('BZType').Value:='<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
FieldByName('ComTaiTou').Value:=Trim(FComTaiTou);
FieldByName('QtyUnit').Value:=Trim(Order_Main.fieldbyname('C_Unit').AsString);
FieldByName('YFName').Value:='<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
FieldByName('MainId').Value:=Trim(OrdMainId);
Post;
end;
end;
{with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('update YF_Money_CR Set Qty=(select isnull(Sum(MXQty),0) from Contract_Sub_MX A inner join');
SQL.Add('Contract_Sub B on A.SubId=B.SubId where B.MainId=YF_Money_CR.YFTypeId)');
sql.Add(',PS=(select isnull(Sum(A.Qty1),0) from Contract_Sub_MX A inner join');
SQL.Add('Contract_Sub B on A.SubId=B.SubId where B.MainId=YF_Money_CR.YFTypeId)');
sql.Add(' where YFTypeId='''+Trim(Order_Main.fieldbyname('Mainid').AsString)+'''');
ExecSQL;
end;}
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('Update YF_Money_CR Set Money=Price*Qty,BBMoney=Price*Qty');
sql.Add(' where YFID='''+Trim(YFID)+'''');
ExecSQL;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('Update YF_Money_KC Set KCMoney=(select isnull(Sum(Money*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)');
sql.Add(',KCBBMoney=(select isnull(Sum(BBMoney*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)');
sql.Add(' where CRID='+CRID);
ExecSQL;
end;
Result:=True;
end;
function TfrmClothContractListDH.DelYFData():Boolean;
var
CRID,OrdMainId,YFID:String;
begin
Result:=False;
with ADOQueryTemp do
begin
Close;
SQL.Clear;
sql.Add('select * from YF_Money_KC where FactoryName='''+Trim(Order_Main.fieldbyname('FactoryNoName').AsString)+'''');
Open;
end;
if ADOQueryTemp.IsEmpty=False then
begin
CRID:=ADOQueryTemp.fieldbyname('CRID').AsString;
end else
begin
Exit;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('delete YF_Money_CR where FactoryName='''+Trim(Order_Main.fieldbyname('FactoryNoName').AsString)+'''');
sql.Add(' and YFTypeId='''+Trim(ClientDataSet2.fieldbyname('MXId').AsString)+'''');
ExecSQL;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('Update YF_Money_KC Set KCMoney=(select isnull(Sum(Money*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)');
sql.Add(',KCBBMoney=(select isnull(Sum(BBMoney*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)');
sql.Add(' where CRID='+CRID);
ExecSQL;
end;
Result:=True;
end;
procedure TfrmClothContractListDH.Tv2CellClick(
Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
begin
with ADOQueryTemp do
begin
Close;
sql.Clear;
SQL.Add('select A.*,C.MPRTSpec,B.PRTColor,C.MPRTCodeName,C.OrderNo ,');
sql.Add('C_Unit=(select Top 1 C_Unit from Contract_Sub AA,Contract_Sub_Mx BB where AA.SubId=BB.SubId and BB.MXid=A.Mxid)');
SQL.Add(' from Contract_Sub_MxTo A inner join JYOrder_Sub B on A.OrdSubId=B.SubId ');
SQL.Add(' inner join JYOrder_Main C on C.MainId=B.MainId ');
sql.Add('where A.MxId='''+Trim(ClientDataSet2.fieldbyname('MxId').AsString)+'''');
Open;
end;
SCreateCDS20(ADOQueryTemp,ClientDataSet3);
SInitCDSData20(ADOQueryTemp,ClientDataSet3);
end;
procedure TfrmClothContractListDH.ToolButton5Click(Sender: TObject);
var
maxno:string;
begin
if ClientDataSet3.IsEmpty then Exit;
if ClientDataSet2.IsEmpty then Exit;
if Trim(ClientDataSet2.fieldbyname('MXId').AsString)='' then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δȷ<CEB4><C8B7><EFBFBD><EFBFBD>','<27><>ʾ',0);
Exit;
end;
if ClientDataSet3.Locate('OrderNo',null,[]) then
begin
Application.MessageBox(<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD><C5B2><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>','<27><>ʾ',0);
Exit;
end;
BegDate.SetFocus;
try
ADOQueryCmd.Connection.BeginTrans;
//<2F><><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD>
with ClientDataSet3 do
begin
First;
while not eof do
begin
if Trim(ClientDataSet3.fieldbyname('ToId').AsString)='' then
begin
if GetLSNo(ADOQueryCmd,maxno,'To','Contract_Sub_MxTo',4,1)=False then
begin
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('ȡȥ<C8A1><C8A5><EFBFBD><EFBFBD>ˮ<EFBFBD><CBAE>ʧ<EFBFBD>ܣ<EFBFBD>','<27><>ʾ',0);
Exit;
end;
end else
begin
maxno:=Trim(ClientDataSet3.fieldbyname('ToId').AsString);
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select * from Contract_Sub_MxTo where ToId='''+Trim(ClientDataSet3.fieldbyname('ToId').AsString)+'''');
Open;
end;
with ADOQueryCmd do
begin
if Trim(ClientDataSet3.fieldbyname('ToId').AsString)='' then
Append
else
Edit;
FieldByName('MxId').Value:=Trim(ClientDataSet2.fieldbyname('MxId').AsString);
FieldByName('ToId').Value:=Trim(maxno);
FieldByName('OrdSubId').Value:=Trim(ClientDataSet3.fieldbyname('OrdSubId').AsString);
FieldByName('TPDate').Value:=ClientDataSet3.fieldbyname('TPDate').Value;
FieldByName('TPPerson').Value:=ClientDataSet3.fieldbyname('TPPerson').Value;
FieldByName('TPNote').Value:=ClientDataSet3.fieldbyname('TPNote').Value;
if Trim(ClientDataSet3.fieldbyname('TPQty').AsString)<>'' then
FieldByName('TPQty').Value:=ClientDataSet3.fieldbyname('TPQty').Value
else
FieldByName('TPQty').Value:=0;
if Trim(ClientDataSet3.fieldbyname('Qty1').AsString)<>'' then
FieldByName('Qty1').Value:=ClientDataSet3.fieldbyname('Qty1').Value
else
FieldByName('Qty1').Value:=0;
if Trim(ClientDataSet3.fieldbyname('Qty2').AsString)<>'' then
FieldByName('Qty2').Value:=ClientDataSet3.fieldbyname('Qty2').Value
else
FieldByName('Qty2').Value:=0;
if Trim(ClientDataSet3.fieldbyname('Qty3').AsString)<>'' then
FieldByName('Qty3').Value:=ClientDataSet3.fieldbyname('Qty3').Value
else
FieldByName('Qty3').Value:=0;
Post;
end;
with ClientDataSet3 do
begin
Edit;
FieldByName('ToId').Value:=Trim(maxno);
Post;
end;
Next;
end;
end;
ADOQueryCmd.Connection.CommitTrans;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>','<27><>ʾ',0);
except
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><ECB3A3>','<27><>ʾ',0);
end;
end;
procedure TfrmClothContractListDH.ToolButton3Click(Sender: TObject);
begin
//if FInt=2 then
//begin
if ClientDataSet2.IsEmpty then Exit;
if Application.MessageBox(<><C8B7>Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><>ʾ',32+4)<>IDYES then Exit;
try
ADOQueryCmd.Connection.BeginTrans;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('delete Contract_Sub_Mx where MxId='''+Trim(ClientDataSet2.fieldbyname('MxId').AsString)+'''');
ExecSQL;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('Update Contract_Cloth_DH Set DHQty=(select isnull(Sum(MxQty),0) from Contract_Sub_Mx A where A.SubId=Contract_Cloth_DH.SubId');
sql.Add(' and A.RKPLCode=Contract_Cloth_DH.FirstNo)');
sql.Add(', DHMQty=(select isnull(Sum(MxMQty),0) from Contract_Sub_Mx A where A.SubId=Contract_Cloth_DH.SubId');
sql.Add(' and A.RKPLCode=Contract_Cloth_DH.FirstNo)');
sql.Add(', DHPS=(select isnull(Sum(Qty1),0) from Contract_Sub_Mx A where A.SubId=Contract_Cloth_DH.SubId');
sql.Add(' and A.RKPLCode=Contract_Cloth_DH.FirstNo)');
sql.Add(' where SubId='''+Trim(Order_Main.fieldbyname('Subid').AsString)+'''');
sql.Add(' and FirstNo='''+Trim(ClientDataSet2.fieldbyname('RKPLCode').AsString)+'''');
ExecSQL;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('delete Contract_Cloth_DH ');
sql.Add('where not exists(select * from Contract_Sub_Mx A where A.SubId=Contract_Cloth_DH.SubId and A.RKPlace=Contract_Cloth_DH.firstName) ');
sql.Add(' and SubId='''+Trim(Order_Main.fieldbyname('SubId').AsString)+'''');
ExecSQL;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select * from Contract_Cloth_LLMX B where not exists(select * from ');
sql.Add(' Contract_Cloth_DH A where A.DHID=B.DHID ');
SQL.Add(' and A.SubId=B.SubId ) and B.SubId='''+Trim(Order_Main.fieldbyname('SubId').AsString)+'''');
Open;
end;
if ADOQueryCmd.IsEmpty=False then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>!','<27><>ʾ',0);
//begin
ADOQueryCmd.Connection.RollbackTrans;
Exit;
//end;
end;
DelYFData();
ClientDataSet2.Delete;
ADOQueryCmd.Connection.CommitTrans;
except
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox(<><C9BE><EFBFBD>쳣!','<27><>ʾ',0);
end;
//end;
end;
procedure TfrmClothContractListDH.v2Column3PropertiesButtonClick(
Sender: TObject; AButtonIndex: Integer);
begin
try
frmZDYHelp:=TfrmZDYHelp.Create(Application);
with frmZDYHelp do
begin
//flag:='RKPlace';
flag:='FactoryNo1Name';
flagname:='<27><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>';
MainType:=<><C8BE>';
if ShowModal=1 then
begin
with ClientDataSet2 do
begin
Edit;
FieldByName('RKPlace').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZDYName').AsString);
FieldByName('RKPlCode').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZDYNo').AsString);
end;
end;
end;
finally
frmZDYHelp.Free;
end;
end;
procedure TfrmClothContractListDH.Button1Click(Sender: TObject);
begin
ToolButton2.Click;
end;
procedure TfrmClothContractListDH.Button2Click(Sender: TObject);
begin
ToolButton3.Click;
end;
procedure TfrmClothContractListDH.Button3Click(Sender: TObject);
begin
ToolButton4.Click;
end;
procedure TfrmClothContractListDH.ConNoMKeyPress(Sender: TObject;
var Key: Char);
begin
if Key=#13 then
begin
if Length(Trim(ConNoM.Text))<4 then Exit;
try
ADOQueryMain.DisableControls;
with ADOQueryMain do
begin
Filtered:=False;
Close;
sql.Clear;
sql.Add('exec ClothContract_QryList :MainId,:WSql');
Parameters.ParamByName('WSql').Value:=' and OM.conNo like '''+'%'+Trim(ConNoM.Text)+'%'+'''';
Open;
end;
SCreateCDS20(ADOQueryMain,Order_Main);
SInitCDSData20(ADOQueryMain,Order_Main);
finally
ADOQueryMain.EnableControls;
end;
end;
end;
procedure TfrmClothContractListDH.Tv1CellClick(
Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
begin
with ADOQueryTemp do
begin
Close;
sql.Clear;
SQL.Add('select A.*,KCSL=A.MXQty-(select isnull(Sum(TPQty),0) from Contract_Sub_Mxto B where B.MXID=A.MXID),');
sql.Add(' KCPS=A.Qty1-(select isnull(Sum(Qty1),0) from Contract_Sub_Mxto B where B.MXID=A.MXID)');
sql.Add('from Contract_Sub_Mx A');
sql.Add(' where A.SubId='''+Trim(Order_Main.fieldbyname('SubId').AsString)+'''');
Open;
end;
SCreateCDS20(ADOQueryTemp,ClientDataSet2);
SInitCDSData20(ADOQueryTemp,ClientDataSet2);
with ADOQueryTemp do
begin
Close;
sql.Clear;
SQL.Add('select A.*,C.MPRTSpec,B.PRTColor,C.MPRTCodeName,C.OrderNo ,');
sql.Add('C_Unit=(select Top 1 C_Unit from Contract_Sub AA,Contract_Sub_Mx BB where AA.SubId=BB.SubId and BB.MXid=A.Mxid)');
SQL.Add('from Contract_Sub_MxTo A inner join JYOrder_Sub B on A.OrdSubId=B.SubId');
SQL.Add(' inner join JYOrder_Main C on C.MainId=B.MainId ');
sql.Add('where A.MxId='''+Trim(ClientDataSet2.fieldbyname('MxId').AsString)+'''');
Open;
end;
SCreateCDS20(ADOQueryTemp,ClientDataSet3);
SInitCDSData20(ADOQueryTemp,ClientDataSet3);
end;
end.