RTFormwork/public10/ThreeFun/Form/U_ZDYHelpSM.pas
“ddf” 61630656e9 1
2024-07-07 09:35:27 +08:00

540 lines
16 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_ZDYHelpSM;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
cxDataStorage, cxEdit, DB, cxDBData, ToolWin, ComCtrls,
cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGridLevel,
cxClasses, cxControls, cxGridCustomView, cxGrid, DBClient, ADODB, ImgList,
StdCtrls, ExtCtrls, cxTextEdit, cxGridCustomPopupMenu, cxGridPopupMenu;
type
TfrmZDYHelpSM = class(TForm)
TV1: TcxGridDBTableView;
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
V1Code: TcxGridDBColumn;
V1Name: TcxGridDBColumn;
ToolBar1: TToolBar;
ADOQueryMain: TADOQuery;
ADOQueryTemp: TADOQuery;
ADOQueryCmd: TADOQuery;
DataSource1: TDataSource;
ClientDataSet1: TClientDataSet;
TBAdd: TToolButton;
TBSave: TToolButton;
TBDel: TToolButton;
TBClose: TToolButton;
ToolButton1: TToolButton;
TBEdit: TToolButton;
V1Note: TcxGridDBColumn;
ADOConnection1: TADOConnection;
Panel1: TPanel;
Label1: TLabel;
ZDYName: TEdit;
ThreeImgList: TImageList;
Label2: TLabel;
cxGridPopupMenu1: TcxGridPopupMenu;
V1ZdyFlag: TcxGridDBColumn;
V1HelpType: TcxGridDBColumn;
V1note1: TcxGridDBColumn;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure TBAddClick(Sender: TObject);
procedure TBSaveClick(Sender: TObject);
procedure TBDelClick(Sender: TObject);
procedure TBCloseClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
procedure TBEditClick(Sender: TObject);
procedure TV1CellDblClick(Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
procedure ZDYNameChange(Sender: TObject);
procedure V1NamePropertiesEditValueChanged(Sender: TObject);
procedure V1Column1PropertiesEditValueChanged(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
procedure InitGrid();
{ Private declarations }
public
flag,flagname,snote,MainType:string;
fnote,forderno,fZdyFlag,ViewFlag,fnote1:Boolean;
PPSTE:integer;
{ Public declarations }
end;
var
frmZDYHelpSM: TfrmZDYHelpSM;
implementation
uses
U_DataLink,U_RTFun;
{$R *.dfm}
procedure TfrmZDYHelpSM.FormCreate(Sender: TObject);
begin
try
cxGrid1.Align:=alClient;
with ADOConnection1 do
begin
Connected:=false;
ConnectionString:=DConString;
Connected:=true;
end;
except
frmZDYHelpSM.Free;
end;
end;
procedure TfrmZDYHelpSM.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
ZDYName.SetFocus;
Action:=cahide;
end;
procedure TfrmZDYHelpSM.InitGrid();
begin
try
ADOQueryMain.DisableControls;
with ADOQueryMain do
begin
Close;
sql.Clear;
sql.Add('select A.*,ZJM=dbo.getPinYin(A.ZdyName) ');
sql.Add('from KH_ZDY'+DSMFlag+' A ');
sql.Add('where A.Type='''+flag+'''');
if Trim(MainType)<>'' then
begin
sql.Add(' and A.MainType='''+Trim(MainType)+'''');
end;
Open;
end;
SCreateCDS20(ADOQueryMain,ClientDataSet1);
SInitCDSData20(ADOQueryMain,ClientDataSet1);
finally
ADOQueryMain.EnableControls;
end;
end;
procedure TfrmZDYHelpSM.TBAddClick(Sender: TObject);
var
i:Integer;
begin
ZDYName.SetFocus;
TV1.OptionsData.Editing:=True;
TV1.OptionsSelection.CellSelect:=True;
for i:=0 to 5 do
begin
with ClientDataSet1 do
begin
Append;
Post;
end;
end;
end;
procedure TfrmZDYHelpSM.TBSaveClick(Sender: TObject);
var
maxno:string;
begin
if ClientDataSet1.IsEmpty then Exit;
ZDYName.SetFocus;
if ClientDataSet1.Locate('ZDYName',null,[]) then
begin
Application.MessageBox('<27><><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>','<27><>ʾ',0);
Exit;
end;
if ClientDataSet1.Locate('ZDYName','',[]) then
begin
Application.MessageBox('<27><><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>','<27><>ʾ',0);
Exit;
end;
try
ADOQueryCmd.Connection.BeginTrans;
with ADOQueryTemp do
begin
Close;
SQL.Clear;
SQL.Add('select * from KH_ZDY where ZdyNo='''+Trim(flag)+'''');
open;
end;
if ADOQueryTemp.IsEmpty then
begin
with ADOQueryCmd do
begin
close;
sql.Clear;
sql.Add('select * from KH_ZDY where 1=2');
open;
ADOQueryCmd.Append;
ADOQueryCmd.FieldByName('ZDYNo').Value:=Trim(flag);
ADOQueryCmd.FieldByName('ZDYName').Value:=trim(flagname);
ADOQueryCmd.FieldByName('Type').Value:='Main';
ADOQueryCmd.FieldByName('MainType').Value:=Trim(MainType);
ADOQueryCmd.Post;
end;
end;
with ADOQueryCmd do
begin
ClientDataSet1.DisableControls;
with ClientDataSet1 do
begin
First;
while not eof do
begin
if Trim(ClientDataSet1.FieldByName('ZDYNO').AsString)='' then
begin
if GetLSNo(ADOQueryTemp,maxno,'SY','KH_ZDY',3,1)=False then
begin
ADOQueryCmd.Connection.RollbackTrans;
ClientDataSet1.EnableControls;
Application.MessageBox(<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>','<27><>ʾ',0);
Exit;
end;
end else
begin
maxno:=Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
end;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.add('select * from KH_Zdy where Type='''+Trim(flag)+'''');
if Trim(MainType)<>'' then
SQL.Add(' and MainType='''+Trim(MainType)+'''');
sql.Add(' and ZdyName='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
Open;
end;
if ADOQueryTemp.IsEmpty=False then
begin
if ADOQueryTemp.RecordCount>1 then
begin
ADOQueryCmd.Connection.RollbackTrans;
ClientDataSet1.EnableControls;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>','<27><>ʾ',0);
Exit;
end;
if Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString)='' then
begin
ADOQueryCmd.Connection.RollbackTrans;
ClientDataSet1.EnableControls;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>','<27><>ʾ',0);
Exit;
end else
begin
if Trim(ADOQueryTemp.fieldbyname('ZdyNo').AsString)<>Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString) then
begin
ADOQueryCmd.Connection.RollbackTrans;
ClientDataSet1.EnableControls;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>','<27><>ʾ',0);
Exit;
end;
end;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
SQL.Add('delete KH_ZDY where ZDYNO='''+Trim(ClientDataSet1.fieldbyname('ZDYNO').AsString)+'''');
ExecSQL;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select * from KH_ZDY where 1<>1');
Open;
end;
ADOQueryCmd.Append;
ADOQueryCmd.FieldByName('ZDYNo').Value:=Trim(maxno);
ADOQueryCmd.FieldByName('ZDYName').Value:=ClientDataSet1.fieldbyname('ZDYName').Value;
ADOQueryCmd.FieldByName('note').Value:=Trim(snote);
//ADOQueryCmd.FieldByName('orderno').Value:=ClientDataSet1.fieldbyname('Name').AsString;
ADOQueryCmd.FieldByName('Type').Value:=flag;
ADOQueryCmd.FieldByName('valid').Value:='Y';
if Trim(MainType)<>'' then
ADOQueryCmd.FieldByName('MainType').Value:=Trim(MainType);
//ADOQueryCmd.FieldByName('sel').Value:=0;
ADOQueryCmd.Post;
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('ZDYNo').Value:=Trim(maxno);
ClientDataSet1.Post;
Next;
end;
end;
ClientDataSet1.EnableControls;
end;
ADOQueryCmd.Connection.CommitTrans;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>','<27><>ʾ',0);
TV1.OptionsData.Editing:=False;
TV1.OptionsSelection.CellSelect:=False;
except
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('<27><><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>','<27><>ʾ',0);
end;
end;
procedure TfrmZDYHelpSM.TBDelClick(Sender: TObject);
begin
if ClientDataSet1.IsEmpty then Exit;
if (Trim(ClientDataSet1.FieldByName('ZDYNo').AsString)<>'') or
(Trim(ClientDataSet1.FieldByName('ZDYname').AsString)<>'') then
begin
if application.MessageBox(<><C8B7>Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD>?','<27><>ʾ<EFBFBD><CABE>Ϣ',1)=2 then exit;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('delete KH_ZDY'+DSMFlag+' where ZDYNo='''+Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString)+'''');
SQL.Add(' and Type='''+Trim(flag)+'''');
ExecSQL;
end;
end;
ClientDataSet1.Delete;
end;
procedure TfrmZDYHelpSM.TBCloseClick(Sender: TObject);
begin
ModalResult:=2;
ZDYName.SetFocus;
Close;
end;
procedure TfrmZDYHelpSM.FormShow(Sender: TObject);
var
fsj,fsj1:string;
begin
InitGrid();
fsj:=Trim(flag)+'01';
fsj1:=Trim(flagname)+'01';
ReadCxGrid('<27>Զ<EFBFBD><D4B6><EFBFBD>'+Trim(flag),TV1);
frmZDYHelpSM.Caption:=Trim(flagname);
V1Note.Visible:=fnote;
v1note1.Visible:=fnote1;
if ViewFlag=True then
begin
TBAdd.Visible:=False;
TBSave.Visible:=False;
TBDel.Visible:=False;
TBEdit.Visible:=False;
Label2.Visible:=False;
end;
end;
procedure TfrmZDYHelpSM.ToolButton1Click(Sender: TObject);
begin
ZDYName.SetFocus;
ModalResult:=1;
end;
procedure TfrmZDYHelpSM.TBEditClick(Sender: TObject);
begin
TV1.OptionsData.Editing:=True;
TV1.OptionsSelection.CellSelect:=True;
end;
procedure TfrmZDYHelpSM.TV1CellDblClick(Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
begin
if TV1.OptionsData.Editing=False then
begin
ModalResult:=1;
end;
end;
procedure TfrmZDYHelpSM.ZDYNameChange(Sender: TObject);
var
fsj:String;
begin
if Trim(ZDYName.Text)<>'' then
begin
fsj:=' zdyname like '''+'%'+Trim(ZDYName.Text)+'%'+''''
+' or Note like '''+'%'+Trim(ZDYName.Text)+'%'+''''
+' or ZJM like '''+'%'+Trim(ZDYName.Text)+'%'+'''';
end;
if ADOQueryMain.Active then
begin
SDofilter(ADOQueryMain,fsj);
SCreateCDS20(ADOQueryMain,ClientDataSet1);
SInitCDSData20(ADOQueryMain,ClientDataSet1);
end;
end;
procedure TfrmZDYHelpSM.V1NamePropertiesEditValueChanged(Sender: TObject);
var
maxno,mvalue:string;
begin
mvalue:=TcxTextEdit(Sender).EditingText;
if Trim(mvalue)='' then Exit;
with ClientDataSet1 do
begin
Edit;
FieldByName('ZdyName').Value:=Trim(mvalue);
//Post;
end;
try
ADOQueryCmd.Connection.BeginTrans;
with ADOQueryTemp do
begin
Close;
SQL.Clear;
SQL.Add('select * from KH_ZDY'+DSMFlag+' where ZdyNo='''+Trim(flag)+'''');
open;
end;
if ADOQueryTemp.IsEmpty then
begin
with ADOQueryCmd do
begin
close;
sql.Clear;
sql.Add('select * from KH_ZDY'+DSMFlag+' where 1=2');
open;
ADOQueryCmd.Append;
ADOQueryCmd.FieldByName('ZDYNo').Value:=Trim(flag);
ADOQueryCmd.FieldByName('ZDYName').Value:=trim(flagname);
ADOQueryCmd.FieldByName('Type').Value:='Main';
ADOQueryCmd.FieldByName('MainType').Value:=Trim(MainType);
ADOQueryCmd.FieldByName('SMFlag').Value:=trim(DSmflag);
ADOQueryCmd.Post;
end;
end;
with ADOQueryCmd do
begin
//ClientDataSet1.DisableControls;
//with ClientDataSet1 do
//begin
//First;
//while not eof do
//begin
if Trim(ClientDataSet1.FieldByName('ZDYNO').AsString)='' then
begin
if GetLSNo(ADOQueryTemp,maxno,'SY','KH_ZDY'+trim(DSMFlag),3,1)=False then
begin
ADOQueryCmd.Connection.RollbackTrans;
//ClientDataSet1.EnableControls;
Application.MessageBox(<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>','<27><>ʾ',0);
Exit;
end;
end else
begin
maxno:=Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
end;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.add('select * from KH_Zdy'+DSMFlag+' ');
sql.add('where Type='''+Trim(flag)+'''');
if Trim(MainType)<>'' then
SQL.Add(' and MainType='''+Trim(MainType)+'''');
sql.Add(' and ZdyName='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
sql.Add(' and note='''+Trim(ClientDataSet1.fieldbyname('note').AsString)+'''');
Open;
end;
if ADOQueryTemp.IsEmpty=False then
begin
if ADOQueryTemp.RecordCount>1 then
begin
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>','<27><>ʾ',0);
Exit;
end;
if Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString)='' then
begin
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>','<27><>ʾ',0);
Exit;
end else
begin
if Trim(ADOQueryTemp.fieldbyname('ZdyNo').AsString)<>Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString) then
begin
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>','<27><>ʾ',0);
Exit;
end;
end;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
SQL.Add('delete KH_ZDY'+DSMFlag+' where ZDYNO='''+Trim(ClientDataSet1.fieldbyname('ZDYNO').AsString)+'''');
ExecSQL;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select * from KH_ZDY'+DSMFlag+' where 1=2 ');
Open;
end;
ADOQueryCmd.Append;
ADOQueryCmd.FieldByName('ZDYNo').Value:=Trim(maxno);
ADOQueryCmd.FieldByName('ZDYName').Value:=ClientDataSet1.fieldbyname('ZDYName').AsString;
ADOQueryCmd.FieldByName('note').Value:=Trim(snote);
ADOQueryCmd.FieldByName('Type').Value:=flag;
ADOQueryCmd.FieldByName('valid').Value:='Y';
ADOQueryCmd.FieldByName('SMFlag').Value:=trim(DSmflag);
if Trim(MainType)<>'' then
ADOQueryCmd.FieldByName('MainType').Value:=Trim(MainType);
//ADOQueryCmd.FieldByName('sel').Value:=0;
ADOQueryCmd.Post;
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('ZDYNo').Value:=Trim(maxno);
end;
ADOQueryCmd.Connection.CommitTrans;
except
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('<27><><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>','<27><>ʾ',0);
end;
end;
procedure TfrmZDYHelpSM.V1Column1PropertiesEditValueChanged(Sender: TObject);
var
mvalue:String;
fieldname:string;
begin
fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
if Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)='' then
begin
Application.MessageBox('<27><><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD>Ϊ<EFBFBD><CEAA>!','<27><>ʾ',0);
Exit;
end;
mvalue:=TcxTextEdit(Sender).EditingText;
with ClientDataSet1 do
begin
Edit;
FieldByName(fieldname).Value:=mvalue;
Post;
end;
with ADOQueryCmd do
begin
Close;
SQL.Clear;
sql.Add('Update KH_Zdy'+DSMFlag+' Set '+fieldname+'='''+Trim(mvalue)+''' ');
sql.Add('where ZdyNo='''+Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString)+'''');
ExecSQL;
end;
end;
procedure TfrmZDYHelpSM.FormDestroy(Sender: TObject);
begin
frmZDYHelpSM:=nil;
WriteCxGrid('<27>Զ<EFBFBD><D4B6><EFBFBD>'+Trim(flag),TV1);
end;
end.