D7wmguihua/坯布码单待检(PBMDDJ.dll)/U_SXDZList.pas
DESKTOP-E401PHE\Administrator b4b5840f18 1
2025-01-18 16:22:10 +08:00

613 lines
17 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_SXDZList;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
cxDataStorage, cxEdit, DB, cxDBData, cxGridCustomTableView,
cxGridTableView, cxGridBandedTableView, cxGridDBBandedTableView,
cxGridLevel, cxClasses, cxControls, cxGridCustomView, cxGridDBTableView,
cxGrid, StdCtrls, ComCtrls, ExtCtrls, ToolWin, cxGridCustomPopupMenu,
cxGridPopupMenu, ADODB, DBClient, cxDropDownEdit, cxCheckBox, RM_Common,
RM_Class, RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, Menus,
cxCalendar, cxButtonEdit, cxTextEdit, cxPC;
type
TfrmSXDZList = class(TForm)
ToolBar1: TToolBar;
TBRafresh: TToolButton;
TBFind: TToolButton;
TBExport: TToolButton;
TBClose: TToolButton;
Panel1: TPanel;
ADOQueryCmd: TADOQuery;
ADOQueryMain: TADOQuery;
ADOQueryTemp: TADOQuery;
DataSource1: TDataSource;
cxGridPopupMenu1: TcxGridPopupMenu;
Label1: TLabel;
Label2: TLabel;
BegDate: TDateTimePicker;
EndDate: TDateTimePicker;
CDS_Main: TClientDataSet;
TBRKCX: TToolButton;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
Label3: TLabel;
Label4: TLabel;
MPRTCodeName: TEdit;
FactoryName: TEdit;
cxGrid1: TcxGrid;
Tv1: TcxGridDBTableView;
v1Column2: TcxGridDBColumn;
v2Column1: TcxGridDBColumn;
v1Column14: TcxGridDBColumn;
v1Column9: TcxGridDBColumn;
v2Column6: TcxGridDBColumn;
v1Column3: TcxGridDBColumn;
v1Column1: TcxGridDBColumn;
v1Column12: TcxGridDBColumn;
cxGrid1Level1: TcxGridLevel;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
cxTabControl1: TcxTabControl;
v1Column4: TcxGridDBColumn;
v1Column5: TcxGridDBColumn;
ToolButton5: TToolButton;
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure TBRafreshClick(Sender: TObject);
procedure ConNoMChange(Sender: TObject);
procedure TBCloseClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure TBExportClick(Sender: TObject);
procedure TBFindClick(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure TBRKCXClick(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure FactoryNameChange(Sender: TObject);
procedure cxTabControl1Change(Sender: TObject);
procedure ToolButton3Click(Sender: TObject);
procedure ToolButton4Click(Sender: TObject);
procedure ToolButton5Click(Sender: TObject);
private
procedure InitGrid();
function YFHZData(FDZID:string):Boolean;
function DelYFHZData():Boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
frmSXDZList: TfrmSXDZList;
implementation
uses
U_DataLink,U_RTFun,U_SXDZInPut,U_SXDZViewSCList;
{$R *.dfm}
procedure TfrmSXDZList.FormDestroy(Sender: TObject);
begin
frmSXDZList:=nil;
end;
procedure TfrmSXDZList.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action:=caFree;
end;
procedure TfrmSXDZList.FormCreate(Sender: TObject);
begin
//cxGrid1.Align:=alClient;
EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
BegDate.DateTime:=EndDate.DateTime-15;
end;
procedure TfrmSXDZList.InitGrid();
begin
try
ADOQueryMain.DisableControls;
with ADOQueryMain do
begin
Filtered:=False;
Close;
sql.Clear;
sql.Add(' select A.* ');
sql.Add(' from JYOrder_Main_MD_DuiZhang A');
sql.Add(' where isnull(DZType,'''')='<><C9B4>''');
if cxTabControl1.TabIndex=0 then
begin
sql.Add(' and isnull(Status,'''')=''<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'' ');
end else
begin
sql.Add(' and isnull(Status,'''')=''<27>Ѷ<EFBFBD><D1B6><EFBFBD>'' ');
end;
if cxTabControl1.TabIndex<>0 then
begin
sql.add(' and A.DZDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+'''');
sql.Add(' and A.DZDate<='''+Trim(FormatDateTime('yyyy-MM-dd',enddate.DateTime+1))+'''');
end;
if Trim(FactoryName.Text)<>'' then
begin
SQL.Add(' and isnull(A.FactoryName,'''') like '''+'%'+Trim(FactoryName.Text)+'%'+'''');
end;
if Trim(MPRTCodeName.Text)<>'' then
begin
SQL.Add(' and isnull(A.MPRTCodeName,'''') like '''+'%'+Trim(MPRTCodeName.Text)+'%'+'''');
end;
Open;
//ShowMessage(SQL.Text);
end;
SCreateCDS20(ADOQueryMain,CDS_Main);
SInitCDSData20(ADOQueryMain,CDS_Main);
finally
ADOQueryMain.EnableControls;
end;
end;
procedure TfrmSXDZList.TBRafreshClick(Sender: TObject);
begin
BegDate.SetFocus;
InitGrid();
end;
procedure TfrmSXDZList.ConNoMChange(Sender: TObject);
begin
if ADOQueryMain.Active then
begin
SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
end;
end;
procedure TfrmSXDZList.TBCloseClick(Sender: TObject);
begin
WriteCxGrid(<>߶<EFBFBD><DFB6><EFBFBD><EFBFBD>б<EFBFBD>',Tv1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
Close;
end;
procedure TfrmSXDZList.FormShow(Sender: TObject);
begin
ReadCxGrid(<>߶<EFBFBD><DFB6><EFBFBD><EFBFBD>б<EFBFBD>',Tv1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
//InitGrid();
end;
procedure TfrmSXDZList.TBExportClick(Sender: TObject);
begin
if ADOQueryMain.IsEmpty then exit;
TcxGridToExcel(<>߶<EFBFBD><DFB6><EFBFBD><EFBFBD>б<EFBFBD>',cxGrid1);
end;
procedure TfrmSXDZList.TBFindClick(Sender: TObject);
begin
if ADOQueryMain.Active then
begin
SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
SCreateCDS20(ADOQueryMain,CDS_Main);
SInitCDSData20(ADOQueryMain,CDS_Main);
end;
end;
procedure TfrmSXDZList.N1Click(Sender: TObject);
begin
SelOKNo(CDS_Main,True);
end;
procedure TfrmSXDZList.N2Click(Sender: TObject);
begin
SelOKNo(CDS_Main,False);
end;
procedure TfrmSXDZList.TBRKCXClick(Sender: TObject);
begin
if CDS_Main.IsEmpty then exit;
if cxTabControl1.TabIndex<>0 then Exit;
if CDS_Main.Locate('SSel',True,[])=False then
begin
Application.MessageBox(<><C3BB>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!','<27><>ʾ',0);
Exit;
end;
if Application.MessageBox(<><C8B7>Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><>ʾ',32+4)<>IDYES then Exit;
try
ADOQueryCmd.Connection.BeginTrans;
CDS_Main.DisableControls;
with CDS_Main do
begin
First;
while Locate('SSel',True,[]) do
begin
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('delete from JYOrder_Main_MD_DuiZhang where DZID='''+Trim(CDS_Main.fieldbyname('DZID').AsString)+'''');
ExecSQL;
end;
CDS_Main.Delete;
end;
end;
CDS_Main.EnableControls;
ADOQueryCmd.Connection.CommitTrans;
except
ADOQueryCmd.Connection.RollbackTrans;
CDS_Main.EnableControls;
Application.MessageBox(<><C9BE><EFBFBD>쳣!','<27><>ʾ',0);
end;
end;
procedure TfrmSXDZList.ToolButton1Click(Sender: TObject);
begin
try
frmSXDZInPut:=TfrmSXDZInPut.Create(Application);
with frmSXDZInPut do
begin
FBCId:='';
if ShowModal=1 then
begin
Self.InitGrid();
end;
end;
finally
frmSXDZInPut.Free;
end;
end;
procedure TfrmSXDZList.ToolButton2Click(Sender: TObject);
begin
if cxTabControl1.TabIndex<>0 then Exit;
try
frmSXDZInPut:=TfrmSXDZInPut.Create(Application);
with frmSXDZInPut do
begin
FBCId:=Trim(CDS_Main.fieldbyname('DZID').AsString);
TBDel.Visible:=False;
TBAdd.Visible:=False;
if ShowModal=1 then
begin
Self.InitGrid();
end;
end;
finally
frmSXDZInPut.Free;
end;
end;
procedure TfrmSXDZList.FactoryNameChange(Sender: TObject);
begin
TBFind.Click;
end;
procedure TfrmSXDZList.cxTabControl1Change(Sender: TObject);
begin
InitGrid();
end;
procedure TfrmSXDZList.ToolButton3Click(Sender: TObject);
begin
if CDS_Main.IsEmpty then exit;
if cxTabControl1.TabIndex<>0 then Exit;
if CDS_Main.Locate('SSel',True,[])=False then
begin
Application.MessageBox(<><C3BB>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!','<27><>ʾ',0);
Exit;
end;
if Application.MessageBox(<><C8B7>Ҫִ<D2AA>ж<EFBFBD><D0B6>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><>ʾ',32+4)<>IDYES then Exit;
try
ADOQueryCmd.Connection.BeginTrans;
CDS_Main.DisableControls;
with CDS_Main do
begin
First;
while Locate('SSel',True,[]) do
begin
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select * from JYOrder_Main_MD_DuiZhang where DZID='''+Trim(CDS_Main.fieldbyname('DZID').AsString)+'''');
Open;
end;
with ADOQueryCmd do
begin
Edit;
FieldByName('DuiZhangPerson').Value:=Trim(DName);
FieldByName('DuiZhangTime').Value:=SGetServerDateTime(ADOQueryTemp);
FieldByName('Status').Value:='<27>Ѷ<EFBFBD><D1B6><EFBFBD>';
Post;
end;
YFHZData(Trim(CDS_Main.fieldbyname('DZID').AsString));
CDS_Main.Delete;
end;
end;
CDS_Main.EnableControls;
ADOQueryCmd.Connection.CommitTrans;
except
ADOQueryCmd.Connection.RollbackTrans;
CDS_Main.EnableControls;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>쳣!','<27><>ʾ',0);
end;
end;
function TfrmSXDZList.YFHZData(FDZID:string):Boolean;
var
CRID,OrdMainId,FYFID,MaxNo,FComTaiTou,FCRID,FFactoryName,CWFactoryNo,CWFactoryName:String;
begin
Result:=False;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from JYOrder_Main_MD_DuiZhang where DZID='''+Trim(FDZID)+'''');
Open;
end;
CWFactoryNo:=Trim(ADOQueryTemp.fieldbyname('FactoryNo').AsString);
CWFactoryName:=Trim(ADOQueryTemp.fieldbyname('FactoryName').AsString);
with ADOQueryTemp do
begin
Close;
SQL.Clear;
sql.Add('select * from YF_Money_KC where FactoryNo='''+Trim(CWFactoryNo)+'''');
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(CWFactoryName);
FieldByName('FactoryNo').Value:=Trim(CWFactoryNo);
FieldByName('ZdyStr1').Value:=<><D3A6><EFBFBD><EFBFBD>';
Post;
end;
end;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from YF_Money_CR where FactoryNo='''+Trim(CWFactoryNo)+'''');
sql.Add(' and MHID='''+Trim(CDS_Main.fieldbyname('DZID').AsString)+'''');
Open;
end;
FYFID:=Trim(ADOQueryTemp.fieldbyname('YFID').AsString);
if Trim(FYFID)='' then
begin
if GetLSNo(ADOQueryCmd,MaxNo,'SX','YF_Money_CR',3,1)=False then
begin
Application.MessageBox('ȡɴ<C8A1><C9B4>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>!','<27><>ʾ',0);
Exit;
end;
end else
begin
MaxNo:=Trim(FYFID);
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select * from YF_Money_CR where YFID='''+Trim(MaxNo)+'''');
Open;
end;
with ADOQueryCmd do
begin
if Trim(FYFID)='' then
Append
else
Edit;
FieldByName('YFID').Value:=Trim(MaxNo);
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('FactoryNo').Value:=Trim(CWFactoryNo);
FieldByName('FactoryName').Value:=Trim(CWFactoryName);
FieldByName('HZFactoryNo').Value:=Trim(CWFactoryNo);
FieldByName('HZFactoryName').Value:=Trim(CWFactoryName);
{if Trim(CDS_Main.fieldbyname('PS').AsString)<>'' then
begin
FieldByName('PS').Value:=CDS_Main.fieldbyname('PS').Value;
end else
begin
FieldByName('PS').Value:=0;
end;}
//FieldByName('CRTime').Value:=CDS_Main.fieldbyname('DZDate').Value;
//FieldByName('Qty').Value:=CDS_Main.fieldbyname('Qty').Value;
//FieldByName('Price').Value:=CDS_Main.fieldbyname('Price').Value;
//FieldByName('Money').Value:=CDS_Main.fieldbyname('Money').Value;
//FieldByName('BBMoney').Value:=CDS_Main.fieldbyname('Money').Value;
//FieldByName('CPName').Value:=Trim(CDS_Main.fieldbyname('MPRTCodeName').AsString);
FieldByName('QtyUnit').Value:='Kg';
FieldByName('YFType').Value:='<27>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>';
FieldByName('HuiLv').Value:=1;
FieldByName('BZType').Value:='<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
FieldByName('YFName').Value:=<><C9B4>';
//FieldByName('PSName').Value:='ɴ<><C9B4>';
FieldByName('MHID').Value:=Trim(CDS_Main.fieldbyname('DZID').AsString);
Post;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('UPdate YF_Money_CR Set PS=(select PS from JYOrder_Main_MD_DuiZhang where DZID='''+Trim(FDZID)+''')');
sql.Add(', Qty=(select Qty from JYOrder_Main_MD_DuiZhang where DZID='''+Trim(FDZID)+''')');
sql.Add(', Price=(select Price from JYOrder_Main_MD_DuiZhang where DZID='''+Trim(FDZID)+''')');
sql.Add(',Money=(select Money from JYOrder_Main_MD_DuiZhang where DZID='''+Trim(FDZID)+''')');
sql.Add(',BBMoney=(select Money from JYOrder_Main_MD_DuiZhang where DZID='''+Trim(FDZID)+''')');
sql.Add(',CPName=(select MPRTCodeName from JYOrder_Main_MD_DuiZhang where DZID='''+Trim(FDZID)+''')');
sql.Add(',CRTime=(select DZDate from JYOrder_Main_MD_DuiZhang where DZID='''+Trim(FDZID)+''')');
sql.Add(',OrderNo=(select OrderNo from JYOrder_Main_MD_DuiZhang where DZID='''+Trim(FDZID)+''')');
sql.Add(',Note=(select Note from JYOrder_Main_MD_DuiZhang where DZID='''+Trim(FDZID)+''')');
sql.Add(' where YFID='''+Trim(MaxNo)+'''');
ExecSQL;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('Update JYOrder_Main_MD_DuiZhang Set YFID='''+Trim(MaxNo)+'''');
sql.Add(' where DZID='''+Trim(CDS_Main.fieldbyname('DZID').AsString)+'''');
ExecSQL;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('Update YF_Money_KC Set ');
sql.Add(' KCMoney=(select isnull(Sum(Money*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID and A.Valid=''Y'')');
sql.Add(',KCBBMoney=(select isnull(Sum(BBMoney*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID and A.Valid=''Y'' )');
sql.Add(' where CRID='+CRID);
ExecSQL;
end;
Result:=True;
end;
function TfrmSXDZList.DelYFHZData():Boolean;
var
CRID:String;
begin
Result:=False;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from YF_Money_CR where MHID='''+Trim(CDS_Main.fieldbyname('DZID').AsString)+'''');
Open;
end;
CRID:=Trim(ADOQueryTemp.fieldbyname('CRID').AsString);
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add(' delete YF_Money_CR where ');
sql.Add(' MHID='''+Trim(CDS_Main.fieldbyname('DZID').AsString)+'''');
sql.Add(' Update JYOrder_Main_MD_DuiZhang Set YFID=Null where ');
sql.Add(' DZID='''+Trim(CDS_Main.fieldbyname('DZID').AsString)+'''');
ExecSQL;
end;
if Trim(CRID)<>'' then
begin
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('Update YF_Money_KC Set ');
sql.Add(' KCMoney=(select isnull(Sum(Money*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID and A.Valid=''Y'')');
sql.Add(',KCBBMoney=(select isnull(Sum(BBMoney*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID and A.Valid=''Y'' )');
sql.Add(' where CRID='+CRID);
ExecSQL;
end;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from YF_Money_CR where CRID='+CRID);
Open;
end;
if ADOQueryTemp.IsEmpty then
begin
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add(' delete YF_Money_KC where CRID='+CRID);
ExecSQL;
end;
end;
end;
Result:=True;
end;
procedure TfrmSXDZList.ToolButton4Click(Sender: TObject);
begin
if CDS_Main.IsEmpty then exit;
if cxTabControl1.TabIndex<>1 then Exit;
if CDS_Main.Locate('SSel',True,[])=False then
begin
Application.MessageBox(<><C3BB>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!','<27><>ʾ',0);
Exit;
end;
if Application.MessageBox(<><C8B7>Ҫִ<D2AA>г<EFBFBD><D0B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><>ʾ',32+4)<>IDYES then Exit;
try
ADOQueryCmd.Connection.BeginTrans;
CDS_Main.DisableControls;
with CDS_Main do
begin
First;
while Locate('SSel',True,[]) do
begin
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select * from JYOrder_Main_MD_DuiZhang where DZID='''+Trim(CDS_Main.fieldbyname('DZID').AsString)+'''');
Open;
end;
with ADOQueryCmd do
begin
Edit;
FieldByName('DuiZhangPerson').Value:=Null;
FieldByName('DuiZhangTime').Value:=Null;
FieldByName('Status').Value:='<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
Post;
end;
DelYFHZData();
CDS_Main.Delete;
end;
end;
CDS_Main.EnableControls;
ADOQueryCmd.Connection.CommitTrans;
except
ADOQueryCmd.Connection.RollbackTrans;
CDS_Main.EnableControls;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>쳣!','<27><>ʾ',0);
end;
end;
procedure TfrmSXDZList.ToolButton5Click(Sender: TObject);
begin
try
frmSXDZViewSCList:=TfrmSXDZViewSCList.Create(Application);
with frmSXDZViewSCList do
begin
if ShowModal=1 then
begin
end;
end;
finally
frmSXDZViewSCList.Free;
end;
end;
end.