D7XHshengfang/盛纺贸易管理/U_OrderSel.pas

264 lines
11 KiB
ObjectPascal
Raw Normal View History

2025-04-30 23:58:03 +08:00
unit U_OrderSel;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
cxDataStorage, cxEdit, DB, cxDBData, StdCtrls, ADODB, DBClient, ComCtrls,
ExtCtrls, cxGridLevel, cxGridCustomTableView, cxGridTableView,
cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid,
cxGridCustomPopupMenu, cxGridPopupMenu, cxCheckBox, Menus,
cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore, dxSkinBlack,
dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle,
dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary,
dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin,
dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine,
dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter,
cxNavigator;
type
TfrmOrderSel = class(TForm)
cxGrid1: TcxGrid;
Tv2: TcxGridDBTableView;
v1OrderNo: TcxGridDBColumn;
cxGridDBColumn2: TcxGridDBColumn;
v1Column10: TcxGridDBColumn;
v1Column14: TcxGridDBColumn;
v1PRTMF: TcxGridDBColumn;
v1PRTKZ: TcxGridDBColumn;
cxGrid1Level1: TcxGridLevel;
Panel1: TPanel;
Label2: TLabel;
OrderNoM: TEdit;
Label3: TLabel;
PRTColor: TEdit;
CDS_OrderSel: TClientDataSet;
DataSource1: TDataSource;
ADOQueryTemp: TADOQuery;
ADOQueryCmd: TADOQuery;
ADOQueryMain: TADOQuery;
Button1: TButton;
Button2: TButton;
Button3: TButton;
cxGridPopupMenu1: TcxGridPopupMenu;
v2Column2: TcxGridDBColumn;
Label8: TLabel;
CustomerNoName: TEdit;
v2Column3: TcxGridDBColumn;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
v2Column1: TcxGridDBColumn;
v2Column4: TcxGridDBColumn;
v2Column5: TcxGridDBColumn;
v2Column6: TcxGridDBColumn;
cxStyleRepository1: TcxStyleRepository;
cxStyle1: TcxStyle;
cxStyleRepository2: TcxStyleRepository;
cxStyle2: TcxStyle;
cxStyleRepository3: TcxStyleRepository;
cxStyle3: TcxStyle;
v2KHConno: TcxGridDBColumn;
v2ZPJZ: TcxGridDBColumn;
v2CPJZ: TcxGridDBColumn;
v2Column9: TcxGridDBColumn;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button2Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure OrderNoMChange(Sender: TObject);
procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
procedure N1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
private
{ Private declarations }
procedure InitGrid();
public
{ Public declarations }
end;
var
frmOrderSel: TfrmOrderSel;
implementation
uses
U_DataLink,U_Fun ;
{$R *.dfm}
procedure TfrmOrderSel.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action:=caFree;
end;
procedure TfrmOrderSel.Button2Click(Sender: TObject);
var
KHName:String;
begin
if CDS_OrderSel.Locate('SSel',True,[])=False then
begin
Application.MessageBox(<><C3BB>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>','<27><>ʾ',0);
Exit;
end;
CDS_OrderSel.DisableControls;
KHName:='';
with CDS_OrderSel do
begin
First;
while not Eof do
begin
if FieldByName('SSel').AsBoolean=True then
begin
if Trim(KHName)='' then
begin
KHName:=Trim(fieldbyname('CustomerNo').AsString);
end else
begin
if Trim(fieldbyname('CustomerNo').AsString)<>KHName then
begin
CDS_OrderSel.EnableControls;
Application.MessageBox('<27><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>ͬ<EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>','<27><>ʾ',0);
Exit;
end;
end;
end;
Next;
end;
end;
CDS_OrderSel.EnableControls;
ModalResult:=1;
end;
procedure TfrmOrderSel.FormDestroy(Sender: TObject);
begin
frmOrderSel:=nil;
end;
procedure TfrmOrderSel.Button3Click(Sender: TObject);
begin
ModalResult:=-1;
WriteCxGrid('<27><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>11',Tv2,'<27><>Ʒ<EFBFBD>ֿ<EFBFBD>');
Close;
end;
procedure TfrmOrderSel.FormShow(Sender: TObject);
begin
ReadCxGrid('<27><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>11',Tv2,'<27><>Ʒ<EFBFBD>ֿ<EFBFBD>');
InitGrid();
end;
procedure TfrmOrderSel.InitGrid();
begin
try
ADOQueryMain.DisableControls;
// with ADOQueryMain do
// begin
// Filtered:=False;
// Close;
// sql.Clear;
// sql.Add('select AA.KHConNO,AA.OrderNoM,AA.CustomerNoName,AA.CustomerNo,AA.MPrtCodeName,AA.ConSubid,AA.PRTColor,AA.OrderUnit,AA.PRTOrderQty');
// sql.Add(',AA.MPRTMF,AA.MPRTKZ,AA.PRTHX,AA.Mainid,AA.Subid,AA.ZPPS,');
// sql.add('AA.ZPQty,AA.CPPS,AA.CPQty,Sum(AA.CPJZ) CPJZ,sum(AA.ZPJZ) ZPJZ');
// Sql.add(' from (select C.KHConNO,C.ConNO OrderNoM,A.CustomerNoName,A.CustomerNo,B.PRTCodeName MPRTCodeName,B.PRTMF MPRTMF,B.PRTKZ MPRTKZ');
// sql.Add(',B.PRTColor,B.OrderUnit,B.PRTOrderQty,B.PRTHX,Cast('''' as varchar(80)) Mainid,Cast('''' as varchar(80)) Subid,B.Subid Consubid');
// sql.add(',ZPJZ=(case when C.CPType=''<27><>Ʒ'' then C.KGQty else 0 end)');
// sql.add(',CPJZ=(case when C.CPType=''<27><>Ʒ'' then C.KGQty else 0 end)');
// sql.Add(',ZPPS=(select Count(CR.MJID) from CK_BanCP_CR CR ');
// sql.Add('where CR.CRFlag=''<27><><EFBFBD><EFBFBD>'' and CR.CPType=''<27><>Ʒ'' and CR.ConID=C.ConID and not exists(select AA.MJID from CK_BanCP_CR AA where AA.MJID=CR.MJID and AA.CRFlag=''<27><><EFBFBD><EFBFBD>''))');
// sql.Add(',ZPQty=(select sum(Qty) from CK_BanCP_CR CR ');
// sql.Add('where CR.CRFlag=''<27><><EFBFBD><EFBFBD>'' and CR.CPType=''<27><>Ʒ'' and CR.ConID=C.ConID and not exists(select AA.MJID from CK_BanCP_CR AA where AA.MJID=CR.MJID and AA.CRFlag=''<27><><EFBFBD><EFBFBD>''))');
// sql.Add(',CPPS=(select Count(CR.MJID) from CK_BanCP_CR CR ');
// sql.Add('where CR.CRFlag=''<27><><EFBFBD><EFBFBD>'' and CR.CPType=''<27><>Ʒ'' and CR.ConID=C.ConID and not exists(select AA.MJID from CK_BanCP_CR AA where AA.MJID=CR.MJID and AA.CRFlag=''<27><><EFBFBD><EFBFBD>''))');
// sql.Add(',CPQty=(select sum(Qty) from CK_BanCP_CR CR ');
// sql.Add('where CR.CRFlag=''<27><><EFBFBD><EFBFBD>'' and CR.CPType=''<27><>Ʒ'' and CR.ConID=C.ConID and not exists(select AA.MJID from CK_BanCP_CR AA where AA.MJID=CR.MJID and AA.CRFlag=''<27><><EFBFBD><EFBFBD>''))');
// sql.Add('from CK_BanCP_CR C left join JYOrderCon_Sub B on C.ConID=B.Subid');
// sql.add(' left join JYOrderCon_Main A on B.MainId=A.Mainid');
// sql.Add(' where C.CRFlag=''<27><><EFBFBD><EFBFBD>'' and not exists(select AA.MJID from CK_BanCP_CR AA where AA.MJID=C.MJID and AA.CRFlag=''<27><><EFBFBD><EFBFBD>''))AA');
// sql.Add(' Group by AA.KHConNO,AA.OrderNoM,AA.CustomerNoName,AA.CustomerNo,AA.MPrtCodeName,AA.ConSubid,AA.PRTColor,AA.OrderUnit,AA.PRTOrderQty');
// sql.Add(',AA.MPRTMF,AA.MPRTKZ,AA.PRTHX,AA.Mainid,AA.Subid,AA.ZPPS,AA.ZPQty,AA.CPPS,AA.CPQty');
// Open;
// end;
with ADOQueryMain do
begin
Close;
Filtered:=False;
sql.Clear;
sql.Add('select AA.KHConNO,AA.OrderNoM,AA.CustomerNoName,AA.CustomerNo,AA.MPrtCodeName,AA.ConSubid,AA.PRTColor,AA.OrderUnit,AA.PRTOrderQty');
sql.Add(',AA.MPRTMF,AA.MPRTKZ,AA.PRTHX,AA.Mainid,AA.Subid');
sql.add(',sum(ZPPS) as ZPPS,sum(ZPQty) as ZPQty,sum(AA.ZPJZ) ZPJZ,sum(CPPS) as CPPS,sum(CPQty) as CPQty,Sum(AA.CPJZ) CPJZ');
Sql.add(' from (select C.KHConNO,C.ConNO OrderNoM,A.CustomerNoName,A.CustomerNo,B.PRTCodeName MPRTCodeName,B.PRTMF MPRTMF,B.PRTKZ MPRTKZ');
sql.Add(',B.PRTColor,B.OrderUnit,B.PRTOrderQty,B.PRTHX,Cast('''' as varchar(80)) Mainid,Cast('''' as varchar(80)) Subid,B.Subid Consubid');
sql.add(',ZPPS=(case when C.CPType=''<27><>Ʒ'' then 1 else 0 end)');
sql.add(',ZPQty=(case when C.CPType=''<27><>Ʒ'' then C.Qty else 0 end)');
sql.add(',ZPJZ=(case when C.CPType=''<27><>Ʒ'' then C.KGQty else 0 end)');
sql.add(',CPPS=(case when C.CPType=''<27><>Ʒ'' then 1 else 0 end)');
sql.add(',CPQty=(case when C.CPType=''<27><>Ʒ'' then C.Qty else 0 end)');
sql.add(',CPJZ=(case when C.CPType=''<27><>Ʒ'' then C.KGQty else 0 end)');
{ sql.Add(',ZPPS=(select Count(CR.MJID) from CK_BanCP_CR CR ');
sql.Add('where CR.CRFlag=''<27><><EFBFBD><EFBFBD>'' and CR.CPType=''<27><>Ʒ'' and CR.ConID=C.ConID and not exists(select AA.MJID from CK_BanCP_CR AA where AA.MJID=CR.MJID and AA.CRFlag=''<27><><EFBFBD><EFBFBD>''))');
sql.Add(',ZPQty=(select sum(Qty) from CK_BanCP_CR CR ');
sql.Add('where CR.CRFlag=''<27><><EFBFBD><EFBFBD>'' and CR.CPType=''<27><>Ʒ'' and CR.ConID=C.ConID and not exists(select AA.MJID from CK_BanCP_CR AA where AA.MJID=CR.MJID and AA.CRFlag=''<27><><EFBFBD><EFBFBD>''))');
sql.Add(',CPPS=(select Count(CR.MJID) from CK_BanCP_CR CR ');
sql.Add('where CR.CRFlag=''<27><><EFBFBD><EFBFBD>'' and CR.CPType=''<27><>Ʒ'' and CR.ConID=C.ConID and not exists(select AA.MJID from CK_BanCP_CR AA where AA.MJID=CR.MJID and AA.CRFlag=''<27><><EFBFBD><EFBFBD>''))');
sql.Add(',CPQty=(select sum(Qty) from CK_BanCP_CR CR ');
sql.Add('where CR.CRFlag=''<27><><EFBFBD><EFBFBD>'' and CR.CPType=''<27><>Ʒ'' and CR.ConID=C.ConID and not exists(select AA.MJID from CK_BanCP_CR AA where AA.MJID=CR.MJID and AA.CRFlag=''<27><><EFBFBD><EFBFBD>''))'); }
sql.Add('from CK_BanCP_CR C left join JYOrderCon_Sub B on C.ConID=B.Subid');
sql.add(' left join JYOrderCon_Main A on B.MainId=A.Mainid');
sql.Add(' where C.CRTime>=''2024-01-01'' and C.CRFlag=''<27><><EFBFBD><EFBFBD>'' and not exists(select AA.MJID from CK_BanCP_CR AA where AA.MJID=C.MJID and AA.CRFlag=''<27><><EFBFBD><EFBFBD>''))AA');
sql.Add(' Group by AA.KHConNO,AA.OrderNoM,AA.CustomerNoName,AA.CustomerNo,AA.MPrtCodeName,AA.ConSubid,AA.PRTColor,AA.OrderUnit,AA.PRTOrderQty');
sql.Add(',AA.MPRTMF,AA.MPRTKZ,AA.PRTHX,AA.Mainid,AA.Subid');
// showmessage(sql.text);
Open;
end;
SCreateCDS20(ADOQueryMain,CDS_OrderSel);
SInitCDSData20(ADOQueryMain,CDS_OrderSel);
finally;
ADOQueryMain.EnableControls;
end;
end;
procedure TfrmOrderSel.Button1Click(Sender: TObject);
begin
InitGrid();
end;
procedure TfrmOrderSel.OrderNoMChange(Sender: TObject);
begin
SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
SCreateCDS20(ADOQueryMain,CDS_OrderSel);
SInitCDSData20(ADOQueryMain,CDS_OrderSel);
end;
procedure TfrmOrderSel.Tv2CellDblClick(Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
begin
ModalResult:=1;
end;
procedure TfrmOrderSel.N1Click(Sender: TObject);
begin
SelOKNo(CDS_OrderSel,True);
end;
procedure TfrmOrderSel.N2Click(Sender: TObject);
begin
SelOKNo(CDS_OrderSel,False);
end;
end.