D7wmguihua/样品/U_JWLInList.pas
DESKTOP-E401PHE\Administrator b4b5840f18 1
2025-01-18 16:22:10 +08:00

258 lines
6.5 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_JWLInList;
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, cxCalendar, cxButtonEdit, cxDropDownEdit,
DBClient;
type
TfrmJWLInList = class(TForm)
ToolBar1: TToolBar;
TBRafresh: TToolButton;
TBFind: TToolButton;
TBAdd: TToolButton;
TBEdit: TToolButton;
TBDel: TToolButton;
TBPrint: TToolButton;
TBClose: TToolButton;
cxGridPopupMenu1: TcxGridPopupMenu;
ADOQueryCmd: TADOQuery;
ADOQueryMain: TADOQuery;
ADOQueryTemp: TADOQuery;
DataSource1: TDataSource;
TBExport: TToolButton;
CDS_Main: TClientDataSet;
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure TBCloseClick(Sender: TObject);
procedure TBFindClick(Sender: TObject);
procedure TBEditClick(Sender: TObject);
procedure TBDelClick(Sender: TObject);
procedure TBExportClick(Sender: TObject);
procedure TBPrintClick(Sender: TObject);
procedure TBAddClick(Sender: TObject);
procedure TBRafreshClick(Sender: TObject);
procedure YCLNameChange(Sender: TObject);
procedure FormShow(Sender: TObject);
private
procedure InitGrid();
procedure InitForm();
function DelData():Boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
frmJWLInList: TfrmJWLInList;
implementation
uses
U_DataLink,U_Fun,U_JWLIn;
{$R *.dfm}
procedure TfrmJWLInList.FormDestroy(Sender: TObject);
begin
frmJWLInList:=nil;
end;
procedure TfrmJWLInList.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action:=caFree;
end;
procedure TfrmJWLInList.FormCreate(Sender: TObject);
begin
cxgrid1.Align:=alClient;
end;
procedure TfrmJWLInList.TBCloseClick(Sender: TObject);
begin
Close;
WriteCxGrid('<27><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>',Tv1,'<27><>˹<EFBFBD>ֿ<EFBFBD>');
end;
procedure TfrmJWLInList.InitGrid();
begin
try
ADOQueryMain.DisableControls;
with ADOQueryMain do
begin
Filtered:=False;
Close;
sql.Clear;
sql.Add('select A.*,B.*,GYSName=C.ZDYName from CK_YCL_Main A inner join CK_YCL_Sub B on A.MainId=B.MainId ');
sql.Add(' left join KH_ZDY C on A.GYS=C.ZDYNO');
SQL.Add(' where CRTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+'''');
SQL.Add(' and CRTime<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.DateTime+1))+'''');
sql.Add(' and CKName='''+Trim(DParameters1)+'''');
Open;
end;
SCreateCDS20(ADOQueryMain,CDS_Main);
SInitCDSData20(ADOQueryMain,CDS_Main);
finally
ADOQueryMain.EnableControls;
end;
end;
procedure TfrmJWLInList.InitForm();
begin
ReadCxGrid('<27><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>',Tv1,<><D4AD><EFBFBD>ϲֿ<CFB2>');
EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
BegDate.DateTime:=EndDate.DateTime-7;
InitGrid();
end;
procedure TfrmJWLInList.TBFindClick(Sender: TObject);
begin
if ADOQueryMain.IsEmpty then Exit;
SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
SCreateCDS20(ADOQueryMain,CDS_Main);
SInitCDSData20(ADOQueryMain,CDS_Main);
end;
procedure TfrmJWLInList.TBEditClick(Sender: TObject);
begin
if ADOQueryMain.IsEmpty then Exit;
with ADOQueryTemp do
begin
Close;
SQL.Clear;
sql.Add('select * from CK_YCL_Sub where CRID='+Trim(ADOQueryMain.fieldbyname('CRID').AsString));
sql.Add(' and MainId like ''MC%'' ');
open;
if ADOQueryTemp.RecordCount>0 then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD>Ʒ<EFBFBD>Ѿ<EFBFBD><D1BE>г<EFBFBD><D0B3><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>ܽ<EFBFBD><DCBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD>','<27><>ʾ',0);
Exit;
end;
end;
try
frmJWLIn:=TfrmJWLIn.Create(Application);
with frmJWLIn do
begin
FMainId:=Trim(self.CDS_Main.fieldbyname('MainId').AsString);
ToolButton1.Visible:=False;
ToolButton2.Visible:=False;
ToolButton3.Visible:=False;
ToolButton4.Visible:=False;
if ShowModal=1 then
begin
Self.InitGrid();
Self.TBFind.Click;
Self.CDS_Main.Locate('MainId',FMainID,[]);
end;
end;
finally
frmJWLIn.Free;
end;
end;
procedure TfrmJWLInList.TBDelClick(Sender: TObject);
begin
if CDS_Main.IsEmpty then Exit;
with ADOQueryTemp do
begin
Close;
SQL.Clear;
sql.Add('select * from CK_YCL_Sub where CRID='+Trim(ADOQueryMain.fieldbyname('CRID').AsString));
sql.Add(' and MainId like ''MC%'' ');
open;
if ADOQueryTemp.RecordCount>0 then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD>Ʒ<EFBFBD>Ѿ<EFBFBD><D1BE>г<EFBFBD><D0B3><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>ܽ<EFBFBD><DCBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD>','<27><>ʾ',0);
Exit;
end;
end;
if Application.MessageBox(<><C8B7>Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><>ʾ',32+4)<>IDYES then Exit;
if DelData() then
begin
CDS_Main.Delete;
end;
end;
function TfrmJWLInList.DelData():Boolean;
var
FInt:Integer;
begin
try
Result:=false;
ADOQueryCmd.Connection.BeginTrans;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('delete CK_YCL_Main where MainId='''+Trim(CDS_Main.fieldbyname('MainId').AsString)+'''');
sql.Add(' delete CK_YCL_Sub where MainId='''+Trim(CDS_Main.fieldbyname('MainId').AsString)+'''');
sql.Add(' delete CK_YCL_KC where CRID='+Trim(CDS_Main.fieldbyname('CRID').AsString));
ExecSQL;
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 TfrmJWLInList.TBExportClick(Sender: TObject);
begin
if CDS_Main.IsEmpty then Exit;
TcxGridToExcel('<27><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>',cxGrid1);
end;
procedure TfrmJWLInList.TBPrintClick(Sender: TObject);
begin
if ADOQueryMain.IsEmpty then Exit;
end;
procedure TfrmJWLInList.TBAddClick(Sender: TObject);
begin
try
frmJWLIn:=TfrmJWLIn.Create(Application);
with frmJWLIn do
begin
if ShowModal=1 then
begin
Self.InitGrid();
Self.TBFind.Click;
Self.CDS_Main.Locate('MainId',FMainID,[]);
end;
end;
finally
frmJWLIn.Free;
end;
end;
procedure TfrmJWLInList.TBRafreshClick(Sender: TObject);
begin
InitGrid();
end;
procedure TfrmJWLInList.YCLNameChange(Sender: TObject);
begin
if ADOQueryMain.Active=False then Exit;
SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
SCreateCDS20(ADOQueryMain,CDS_Main);
SInitCDSData20(ADOQueryMain,CDS_Main);
end;
procedure TfrmJWLInList.FormShow(Sender: TObject);
begin
InitForm();
end;
end.