401 lines
10 KiB
ObjectPascal
401 lines
10 KiB
ObjectPascal
|
unit U_ZdyAttachCP;
|
|||
|
|
|||
|
interface
|
|||
|
|
|||
|
uses
|
|||
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ComObj,
|
|||
|
Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
|
|||
|
cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin,
|
|||
|
StdCtrls, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
|
|||
|
cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
|
|||
|
cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
|
|||
|
cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
|
|||
|
RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
|
|||
|
IdTCPClient, IdFTP,ShellAPI,IniFiles, cxCheckBox, cxCalendar,
|
|||
|
cxButtonEdit, cxTextEdit;
|
|||
|
|
|||
|
type
|
|||
|
|
|||
|
FdDy=record
|
|||
|
inc: integer; //<2F>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><D7BD>־<EFBFBD><D6BE><EFBFBD>
|
|||
|
FDdys:string[32]; //<2F>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD>
|
|||
|
FdDysName:string[32]; //<2F>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD>
|
|||
|
end;
|
|||
|
TfrmZdyAttachCP = class(TForm)
|
|||
|
ToolBar1: TToolBar;
|
|||
|
TBRafresh: TToolButton;
|
|||
|
TBClose: TToolButton;
|
|||
|
ADOQueryTemp: TADOQuery;
|
|||
|
ADOQueryCmd: TADOQuery;
|
|||
|
Panel1: TPanel;
|
|||
|
ToolButton2: TToolButton;
|
|||
|
ADOQueryMain: TADOQuery;
|
|||
|
ToolButton1: TToolButton;
|
|||
|
RM1: TRMGridReport;
|
|||
|
RMDB_Main: TRMDBDataSet;
|
|||
|
Label3: TLabel;
|
|||
|
ZdyName: TEdit;
|
|||
|
cxGrid2: TcxGrid;
|
|||
|
Tv2: TcxGridDBTableView;
|
|||
|
cxGridLevel1: TcxGridLevel;
|
|||
|
cxGridPopupMenu2: TcxGridPopupMenu;
|
|||
|
DS_HZ: TDataSource;
|
|||
|
CDS_HZ: TClientDataSet;
|
|||
|
v2Column6: TcxGridDBColumn;
|
|||
|
v2Column1: TcxGridDBColumn;
|
|||
|
v2Column2: TcxGridDBColumn;
|
|||
|
v2Column3: TcxGridDBColumn;
|
|||
|
v2Column4: TcxGridDBColumn;
|
|||
|
v2Column5: TcxGridDBColumn;
|
|||
|
v2Column9: TcxGridDBColumn;
|
|||
|
Label1: TLabel;
|
|||
|
ZdyCode: TEdit;
|
|||
|
Label2: TLabel;
|
|||
|
DEFstr5: TComboBox;
|
|||
|
v2Column7: TcxGridDBColumn;
|
|||
|
v2Column8: TcxGridDBColumn;
|
|||
|
v2Column10: TcxGridDBColumn;
|
|||
|
v2Column11: TcxGridDBColumn;
|
|||
|
v2Column13: TcxGridDBColumn;
|
|||
|
OpenDialog1: TOpenDialog;
|
|||
|
ToolButton5: TToolButton;
|
|||
|
v2Mrate: TcxGridDBColumn;
|
|||
|
v2Column14: TcxGridDBColumn;
|
|||
|
v2Column15: TcxGridDBColumn;
|
|||
|
v2Column16: TcxGridDBColumn;
|
|||
|
v2Column17: TcxGridDBColumn;
|
|||
|
v2defflt1: TcxGridDBColumn;
|
|||
|
procedure FormDestroy(Sender: TObject);
|
|||
|
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
|||
|
procedure TBCloseClick(Sender: TObject);
|
|||
|
procedure TBDelClick(Sender: TObject);
|
|||
|
procedure FormShow(Sender: TObject);
|
|||
|
procedure TBRafreshClick(Sender: TObject);
|
|||
|
procedure ToolButton2Click(Sender: TObject);
|
|||
|
procedure ZdyNameChange(Sender: TObject);
|
|||
|
procedure ToolButton1Click(Sender: TObject);
|
|||
|
procedure ToolButton4Click(Sender: TObject);
|
|||
|
procedure ToolButton3Click(Sender: TObject);
|
|||
|
procedure ToolButton5Click(Sender: TObject);
|
|||
|
procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
|
|||
|
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
|
|||
|
AShift: TShiftState; var AHandled: Boolean);
|
|||
|
private
|
|||
|
{ Private declarations }
|
|||
|
procedure InitGrid();
|
|||
|
|
|||
|
public
|
|||
|
fkhType:string;
|
|||
|
dFdDy: array[0..20] of FdDy; //<2F>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
end;
|
|||
|
|
|||
|
var
|
|||
|
frmZdyAttachCP: TfrmZdyAttachCP;
|
|||
|
|
|||
|
implementation
|
|||
|
uses
|
|||
|
U_DataLink,U_RTFun,U_ZDYHelp;
|
|||
|
|
|||
|
{$R *.dfm}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
procedure TfrmZdyAttachCP.InitGrid();
|
|||
|
begin
|
|||
|
try
|
|||
|
ADOQueryMain.DisableControls;
|
|||
|
with ADOQueryMain do
|
|||
|
begin
|
|||
|
Filtered:=False;
|
|||
|
Close;
|
|||
|
SQL.Clear;
|
|||
|
sql.Add(' select * from KH_Zdy_Attachment where Type=''CP'' ');
|
|||
|
sql.Add(' and isnull(khType,'''')='+quotedstr(trim(fkhType)));
|
|||
|
sql.Add(' order by zdyCode ');
|
|||
|
Open;
|
|||
|
end;
|
|||
|
SCreateCDS(ADOQueryMain,CDS_HZ);
|
|||
|
SInitCDSData(ADOQueryMain,CDS_HZ);
|
|||
|
finally
|
|||
|
ADOQueryMain.EnableControls;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
|
|||
|
procedure TfrmZdyAttachCP.FormDestroy(Sender: TObject);
|
|||
|
begin
|
|||
|
frmZdyAttachCP:=nil;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmZdyAttachCP.FormClose(Sender: TObject; var Action: TCloseAction);
|
|||
|
begin
|
|||
|
Action:=caFree;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmZdyAttachCP.TBCloseClick(Sender: TObject);
|
|||
|
begin
|
|||
|
WriteCxGrid('<27><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>',Tv2,'<27>ͻ<EFBFBD><CDBB>Զ<EFBFBD><D4B6><EFBFBD>');
|
|||
|
Close;
|
|||
|
end;
|
|||
|
procedure TfrmZdyAttachCP.TBDelClick(Sender: TObject);
|
|||
|
begin
|
|||
|
|
|||
|
if CDS_HZ.IsEmpty then Exit;
|
|||
|
if Application.MessageBox('ȷ<><C8B7>Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><>ʾ',32+4)<>IDYES then Exit;
|
|||
|
if Trim(CDS_HZ.fieldbyname('ATID').AsString)<>'' then
|
|||
|
begin
|
|||
|
with ADOQueryCmd do
|
|||
|
begin
|
|||
|
Close;
|
|||
|
SQL.Clear;
|
|||
|
sql.Add('delete KH_Zdy_Attachment where ATID='''+Trim(CDS_HZ.fieldbyname('ATID').AsString)+'''');
|
|||
|
sql.Add('delete KH_Zdy where ZdyNo='''+Trim(CDS_HZ.fieldbyname('ATID').AsString)+'''');
|
|||
|
ExecSQL;
|
|||
|
end;
|
|||
|
end;
|
|||
|
CDS_HZ.Delete;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmZdyAttachCP.FormShow(Sender: TObject);
|
|||
|
begin
|
|||
|
ReadCxGrid('<27><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>',Tv2,'<27>ͻ<EFBFBD><CDBB>Զ<EFBFBD><D4B6><EFBFBD>');
|
|||
|
InitGrid();
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmZdyAttachCP.TBRafreshClick(Sender: TObject);
|
|||
|
begin
|
|||
|
InitGrid();
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmZdyAttachCP.ToolButton2Click(Sender: TObject);
|
|||
|
begin
|
|||
|
if ADOQueryMain.Active then
|
|||
|
begin
|
|||
|
SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
|
|||
|
SCreateCDS(ADOQueryMain,CDS_HZ);
|
|||
|
SInitCDSData(ADOQueryMain,CDS_HZ);
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmZdyAttachCP.ZdyNameChange(Sender: TObject);
|
|||
|
begin
|
|||
|
ToolButton2.Click;
|
|||
|
end;
|
|||
|
|
|||
|
|
|||
|
procedure TfrmZdyAttachCP.ToolButton1Click(Sender: TObject);
|
|||
|
begin
|
|||
|
if ADOQueryMain.IsEmpty then Exit;
|
|||
|
TcxGridToExcel(self.Caption,cxgrid2);
|
|||
|
// SelExportData(Tv2,ADOQueryMain,'<27><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>');
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmZdyAttachCP.ToolButton4Click(Sender: TObject);
|
|||
|
begin
|
|||
|
{ try
|
|||
|
frmZdyAttInputCP:=TfrmZdyAttInputCP.Create(Application);
|
|||
|
with frmZdyAttInputCP do
|
|||
|
begin
|
|||
|
FCYID:=Trim(Self.CDS_HZ.fieldbyname('ATID').AsString);
|
|||
|
fkhType:=self.fkhType;
|
|||
|
if ShowModal=1 then
|
|||
|
begin
|
|||
|
TBRafresh.Click;
|
|||
|
end;
|
|||
|
end;
|
|||
|
finally
|
|||
|
frmZdyAttInputCP.Free;
|
|||
|
end; }
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmZdyAttachCP.ToolButton3Click(Sender: TObject);
|
|||
|
begin
|
|||
|
{ try
|
|||
|
frmZdyAttInputCP:=TfrmZdyAttInputCP.Create(Application);
|
|||
|
with frmZdyAttInputCP do
|
|||
|
begin
|
|||
|
FCYID:='';
|
|||
|
fkhType:=self.fkhType;
|
|||
|
if ShowModal=1 then
|
|||
|
begin
|
|||
|
TBRafresh.Click;
|
|||
|
end;
|
|||
|
end;
|
|||
|
finally
|
|||
|
frmZdyAttInputCP.Free;
|
|||
|
end; }
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmZdyAttachCP.ToolButton5Click(Sender: TObject);
|
|||
|
var
|
|||
|
excelApp,WorkBook:Variant;
|
|||
|
i,j,k,ExcelRowCount:integer;
|
|||
|
maxId:string;
|
|||
|
begin
|
|||
|
|
|||
|
try
|
|||
|
ExcelApp := CreateOleObject('Excel.Application');
|
|||
|
openDialog1.Filter:='*.CSV;*.xls';
|
|||
|
if opendialog1.Execute then
|
|||
|
begin
|
|||
|
WorkBook :=ExcelApp.WorkBooks.Open(OpenDialog1.FileName);
|
|||
|
end
|
|||
|
else
|
|||
|
exit;
|
|||
|
|
|||
|
ExcelApp.Visible := false;
|
|||
|
ExcelRowCount := WorkBook.WorkSheets[1].UsedRange.Rows.Count;
|
|||
|
except
|
|||
|
application.MessageBox('<27><><EFBFBD><EFBFBD>EXCEL<45><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ',MB_ICONERROR);
|
|||
|
exit;
|
|||
|
end;
|
|||
|
|
|||
|
try
|
|||
|
k:=0;
|
|||
|
for i:=1 to 20 do
|
|||
|
begin
|
|||
|
if trim(excelapp.Cells[1,i].value)='' then break;
|
|||
|
if trim(excelapp.Cells[1,i].value)='<27><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>' then
|
|||
|
begin
|
|||
|
dFdDy[k].inc:=i;
|
|||
|
dFdDy[k].FDdys:='ZdyCode';
|
|||
|
dFdDy[k].FdDysName:='<27><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>';
|
|||
|
end;
|
|||
|
|
|||
|
if trim(excelapp.Cells[1,i].value)='<27><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>' then
|
|||
|
begin
|
|||
|
dFdDy[k].inc:=i;
|
|||
|
dFdDy[k].FDdys:='ZdyName';
|
|||
|
dFdDy[k].FdDysName:='<27><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>';
|
|||
|
end;
|
|||
|
|
|||
|
if trim(excelapp.Cells[1,i].value)='<27><><EFBFBD><EFBFBD>' then
|
|||
|
begin
|
|||
|
dFdDy[k].inc:=i;
|
|||
|
dFdDy[k].FDdys:='defNote1';
|
|||
|
dFdDy[k].FdDysName:='<27><><EFBFBD><EFBFBD>';
|
|||
|
end;
|
|||
|
|
|||
|
if trim(excelapp.Cells[1,i].value)='<27><>ɫ' then
|
|||
|
begin
|
|||
|
dFdDy[k].inc:=i;
|
|||
|
dFdDy[k].FDdys:='DEFstr3';
|
|||
|
dFdDy[k].FdDysName:='<27><><EFBFBD><EFBFBD>';
|
|||
|
end;
|
|||
|
|
|||
|
if trim(excelapp.Cells[1,i].value)='<27><><EFBFBD><EFBFBD>' then
|
|||
|
begin
|
|||
|
dFdDy[k].inc:=i;
|
|||
|
dFdDy[k].FDdys:='defNote2';
|
|||
|
dFdDy[k].FdDysName:='<27><><EFBFBD><EFBFBD>';
|
|||
|
end;
|
|||
|
if trim(excelapp.Cells[1,i].value)='<27><><EFBFBD><EFBFBD>' then
|
|||
|
begin
|
|||
|
dFdDy[k].inc:=i;
|
|||
|
dFdDy[k].FDdys:='DEFstr5';
|
|||
|
dFdDy[k].FdDysName:='<27><><EFBFBD><EFBFBD>';
|
|||
|
end;
|
|||
|
if trim(excelapp.Cells[1,i].value)='<27><><EFBFBD><EFBFBD>' then
|
|||
|
begin
|
|||
|
dFdDy[k].inc:=i;
|
|||
|
dFdDy[k].FDdys:='DEFstr1';
|
|||
|
dFdDy[k].FdDysName:='<27><><EFBFBD><EFBFBD>';
|
|||
|
end;
|
|||
|
if trim(excelapp.Cells[1,i].value)='<27>ɷ<EFBFBD>' then
|
|||
|
begin
|
|||
|
dFdDy[k].inc:=i;
|
|||
|
dFdDy[k].FDdys:='DEFstr2';
|
|||
|
dFdDy[k].FdDysName:='<27>ɷ<EFBFBD>';
|
|||
|
end;
|
|||
|
k:=k+1;
|
|||
|
end;
|
|||
|
except
|
|||
|
end;
|
|||
|
|
|||
|
ADOQueryCmd.Connection.BeginTrans;
|
|||
|
try
|
|||
|
for i := 2 to excelrowcount do
|
|||
|
begin
|
|||
|
if GetLSNo(ADOQueryCmd,maxId,'AT','KH_Zdy_Attachment',4,1)=False then
|
|||
|
begin
|
|||
|
ADOQueryCmd.Connection.RollbackTrans;
|
|||
|
Application.MessageBox('ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>','<27><>ʾ',0);
|
|||
|
Exit;
|
|||
|
end;
|
|||
|
|
|||
|
with ADOQueryCmd do
|
|||
|
begin
|
|||
|
close;
|
|||
|
sql.Clear;
|
|||
|
sql.Add('select * from KH_Zdy_Attachment where 1=2');
|
|||
|
open;
|
|||
|
end;
|
|||
|
ADOQueryCmd.Append;
|
|||
|
for j:=0 to k-1 do
|
|||
|
begin
|
|||
|
ADOQueryCmd.fieldbyname(dFdDy[j].FDdys).Value:=excelapp.Cells[i,dFdDy[j].inc].Value;
|
|||
|
end;
|
|||
|
ADOQueryCmd.FieldByName('ATID').Value:=Trim(maxId);
|
|||
|
ADOQueryCmd.FieldByName('Type').Value:='CP';
|
|||
|
ADOQueryCmd.FieldByName('Filler').Value:=Trim(DName);
|
|||
|
ADOQueryCmd.Post;
|
|||
|
|
|||
|
|
|||
|
with ADOQueryTemp do
|
|||
|
begin
|
|||
|
close;
|
|||
|
sql.Clear;
|
|||
|
sql.Add('select * from KH_Zdy_Attachment where ATID='''+trim(maxId)+''' ');
|
|||
|
open;
|
|||
|
end;
|
|||
|
|
|||
|
with ADOQueryCmd do
|
|||
|
begin
|
|||
|
Close;
|
|||
|
SQL.Clear;
|
|||
|
sql.Add('select * from KH_Zdy where ZdyNo='''+Trim(maxId)+'''');
|
|||
|
Open;
|
|||
|
end;
|
|||
|
with ADOQueryCmd do
|
|||
|
begin
|
|||
|
if ADOQueryCmd.IsEmpty then
|
|||
|
begin
|
|||
|
Append;
|
|||
|
end else
|
|||
|
begin
|
|||
|
Edit;
|
|||
|
end;
|
|||
|
FieldByName('ZdyNo').Value:=Trim(maxId);
|
|||
|
FieldByName('ZdyName').Value:=Trim(ADOQueryTemp.fieldbyname('ZdyName').AsString);
|
|||
|
FieldByName('Type').Value:='CP';
|
|||
|
FieldByName('MainType').Value:=Trim(ADOQueryTemp.fieldbyname('DEFstr5').AsString);
|
|||
|
Post;
|
|||
|
end;
|
|||
|
end;
|
|||
|
WorkBook.Close;
|
|||
|
ExcelApp.Quit;
|
|||
|
ExcelApp := Unassigned;
|
|||
|
WorkBook := Unassigned;
|
|||
|
ADOQueryCmd.Connection.CommitTrans;
|
|||
|
InitGrid();
|
|||
|
except
|
|||
|
WorkBook.Close;
|
|||
|
ExcelApp.Quit;
|
|||
|
ExcelApp := Unassigned;
|
|||
|
WorkBook := Unassigned;
|
|||
|
ADOQueryCmd.Connection.RollbackTrans;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmZdyAttachCP.Tv2CellDblClick(Sender: TcxCustomGridTableView;
|
|||
|
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
|
|||
|
AShift: TShiftState; var AHandled: Boolean);
|
|||
|
begin
|
|||
|
IF cds_Hz.IsEmpty then exit;
|
|||
|
ModalResult:=1;
|
|||
|
end;
|
|||
|
|
|||
|
end.
|
|||
|
|
|||
|
|