RtTool/Delphi7/开发档案/马国钢开发代码/ThreeFun/helpForm/U_custHelp.pas
2025-01-08 11:55:07 +08:00

342 lines
9.9 KiB
ObjectPascal
Raw Permalink 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_custHelp;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxPC, cxControls, ImgList, ComCtrls, ToolWin, StdCtrls, ExtCtrls,
U_LeftHelptree, DB, ADODB, cxStyles, cxCustomData, cxGraphics, cxFilter,
cxData, cxDataStorage, cxEdit, cxDBData, cxGridCustomTableView,
cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses,
cxGridCustomView, cxGrid;
type
PMyRec = ^TMyRec;
TMyRec = record
wbcode: string;
Tvtem_str: string;
end;
type
TfrmCustHelp = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Edit1: TEdit;
ImageList24: TImageList;
cxPageControl1: TcxPageControl;
cxTabSheet1: TcxTabSheet;
cxTabSheet2: TcxTabSheet;
TreeView1: TTreeView;
frameLeftHelpTree1: TframeLeftHelpTree;
ADOQueryTmp: TADOQuery;
ADOConnection1: TADOConnection;
ADOQueryHelp: TADOQuery;
DS_Help: TDataSource;
tv1: TcxGridDBTableView;
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
tv1customNo: TcxGridDBColumn;
tv1shortName: TcxGridDBColumn;
ADOQueryChild: TADOQuery;
ToolBar1: TToolBar;
BtnOk: TToolButton;
BtnCancel: TToolButton;
tv1customName: TcxGridDBColumn;
procedure FormCreate(Sender: TObject);
procedure BtnCancelClick(Sender: TObject);
procedure BtnOkClick(Sender: TObject);
procedure frameLeftHelpTree1tt1CellClick(
Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
procedure TreeView1Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure tv1DblClick(Sender: TObject);
procedure frameLeftHelpTree1tt1FocusedRecordChanged(
Sender: TcxCustomGridTableView; APrevFocusedRecord,
AFocusedRecord: TcxCustomGridRecord;
ANewItemRecordFocusingChanged: Boolean);
procedure FormShow(Sender: TObject);
private
LoadFlag:Boolean;
fSqlStr:string;
procedure inti_nodeA();
procedure InitGrid(mSql:string);
procedure AddChildNode(parentNode:TtreeNode;mNo:string);
public
fValidCustFlag:Boolean; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD>ʾ<EFBFBD><CABE>Ч<EFBFBD>ͻ<EFBFBD>
fDispCustomName:Boolean; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD>ʾȫ<CABE><C8AB>
end;
var
frmCustHelp: TfrmCustHelp;
implementation
uses
U_global;
{$R *.dfm}
procedure TfrmCustHelp.FormCreate(Sender: TObject);
begin
with ADOConnection1 do
begin
Connected:=false;
ConnectionString:=gConString;
Connected:=true;
end;
fSqlStr:='select a.CustomNo,a.ShortName,a.CustomName,a.CustomNameEn,'+
'a.Contactor,ywyCode from V_BC_customer A where 1=1 ';
try
LoadFlag:=false;
frameLeftHelpTree1.InitLTree(ADOQueryTmp,'','USER','YWY','',false);
finally
LoadFlag:=true;
end;
if gIsYwy then
cxPageControl1.Tabs[0].Visible:=false;
inti_nodeA();
cxGrid1.Align :=alClient;
InitGrid(fSqlStr);
end;
procedure TfrmCustHelp.BtnCancelClick(Sender: TObject);
begin
close;
end;
procedure TfrmCustHelp.BtnOkClick(Sender: TObject);
begin
if ADOQueryHelp.IsEmpty then exit;
ModalResult := 1;
end;
//////////////////////////////////////////////////////////////
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// CusType<70><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD> CusTypeName<6D><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//////////////////////////////////////////////////////////////
procedure TfrmCustHelp.inti_nodeA();
var
MyRecPtr: PMyRec;
tmpstr :string;
NodeXX,CNode :TTreeNode;
array_Node:array of TTreeNOde;
i:integer;
begin
try
New(MyRecPtr);
MyRecPtr^.wbcode := 'ALL';
MyRecPtr^.Tvtem_str := <><C8AB><EFBFBD>ͻ<EFBFBD>';
//treetop := 'ALL';
with TreeView1 do
begin
Items.Clear;
CNode := Items.AddObject(nil, MyRecPtr^.Tvtem_str, MyRecPtr);
CNode.ImageIndex := 1;
CNode.SelectedIndex := 2;
end;
with TreeView1,ADOQueryTmp do
begin
close;
sql.Add('select code,name from xc_code');
sql.Add('where flag = ''CUSTYPE'' AND valid = ''Y''');
//sql.Add('and Name not like ''%ҵ<><D2B5>Ա%''');
sql.Add('order by code');
Open;
if recordcount = 0 then
begin
application.MessageBox('<27>Բ<EFBFBD><D4B2><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:CUSTYPE!','<27><>ʾ<EFBFBD><CABE>Ϣ',0);
exit;
end;
setLength(array_Node, RecordCount);
i:=0;
while not Eof do
begin
New(MyRecPtr);
MyRecPtr^.wbcode := trim(fieldbyname('code').Asstring);
MyRecPtr^.Tvtem_str := trim(fieldbyname('name').Asstring);
NodeXX := Items.AddChildObject(TreeView1.Items[0], MyRecPtr^.Tvtem_str, MyRecPtr);
NodeXX.ImageIndex := 1;
NodeXX.SelectedIndex := 2;
array_Node[i]:=NodeXX;
INC(i);
next;
end;
Close;
end;
///////////////////////////////////////
with ADOQueryChild do
begin
close;
filtered:=false;
sql.Clear ;
sql.Add('select * from xc_code');
sql.Add('where Note=''CUST'' and valid=''Y''');
sql.Add('and Name not like ''%ҵ<><D2B5>Ա%''');
Open;
end;
for i:=0 to Length(array_Node)-1 do
begin
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
AddChildNode(array_Node[i],PMyRec(array_Node[i].Data)^.wbcode);
end;
TreeView1.Items[0].Selected := True;
TreeView1.Items[0].Expanded:=true;
except
;
end;
end;
//////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////
procedure TfrmCustHelp.InitGrid(mSql:string);
begin
try
with ADOQueryHelp do
begin
close;
sql.Clear ;
sql.Add(mSql);
if cxPageControl1.ActivePageIndex=0 then
begin
if trim(frameLeftHelpTree1.fLeftSelCaption)<>'' then
sql.Add('and A.contactor='+quotedStr(frameLeftHelpTree1.fLeftSelCaption));
end;
if gIsYwy then
sql.Add('and A.contactor='+quotedStr(guserName));
if fValidCustFlag then
sql.Add('and A.valid=''Y''');
//sql.Add('order by CustomNoId');
Open;
end;
finally
end;
end;
procedure TfrmCustHelp.frameLeftHelpTree1tt1CellClick(
Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
begin
end;
//////////////////////////////////////////////////////////////////
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽڵ<D3BD>
//////////////////////////////////////////////////////////////////
procedure TfrmCustHelp.AddChildNode(parentNode:TtreeNode;mNo:string);
var
NodeInfo: PMyRec;
mNode:TtreeNode;
i:integer;
array_Node:array of TTreeNode;
begin
with ADOQueryChild do
begin
filtered:=false;
filter:='flag ='''+PMyRec(parentNode.Data)^.wbcode+'''';
filtered:=true;
Open;
if RecordCount<=0 then exit;
//////////////////////
setLength(array_Node, RecordCount);
i:=0;
while not Eof do
begin
with treeView1 do
begin
New(NodeInfo);
//<2F><><EFBFBD><EFBFBD>
NodeInfo^.wbcode:=trim(fieldByName('code').AsString);
//<2F><><EFBFBD><EFBFBD>
NodeInfo^.Tvtem_str :=fieldByName('Name').AsString
+'('+trim(fieldByName('code').AsString)+')';
mNode:=Items.AddChildObject(parentNode, NodeInfo^.Tvtem_str, NodeInfo);
array_Node[i]:=mNode;
INC(i);
end;
Next;
end;
for i:=0 to Length(array_Node)-1 do
begin
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
AddChildNode(array_Node[i],PMyRec(array_Node[i].Data)^.wbcode);
end;
end;
end;
procedure TfrmCustHelp.TreeView1Click(Sender: TObject);
var
NodeXX :TTreeNode;
TmpDept:string;
begin
//if not LoadFlag then exit;
NodeXX := TreeView1.Selected;
TmpDept := trim(PMyRec(NodeXX.Data).wbcode);
//treetop := TmpDept;
fSqlStr := 'select a.CustomNo,a.ShortName,a.CustomName,a.CustomNameEn,a.Contactor,ywyCode ' ;
if (TmpDept <> 'ALL') then //<2F><><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD>ͻ<EFBFBD>
begin
ADOQueryTmp.Close;
ADOQueryTmp.SQL.Clear;
ADOQueryTmp.SQL.Add('select flag from xc_code where code = '''+TmpDept+''' and valid = ''Y'' ' );
ADOQueryTmp.Open;
if trim(ADOQueryTmp.fieldbyname('flag').asstring) = 'CUSTYPE' then //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ
begin
fSqlStr := fSqlStr + ' from V_BC_customer A ,md_class_type B '+
'where ((b.typeno = '''+TmpDept+''' ) or (b.class = '''+TmpDept+''')) and '+
' a.customno = b.datano ';
InitGrid(fSqlStr);
end
else //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ
begin
fSqlStr := fSqlStr + ' from V_BC_customer A ,md_class_type B '+
' where b.typeno = '''+TmpDept+''' and '+
' a.customno = b.datano ';
InitGrid(fSqlStr);
end;
end
else
begin
fSqlStr:='select a.CustomNo,a.ShortName,a.CustomName,a.CustomNameEn,a.Contactor,ywyCode from V_BC_customer A where 1=1 ';
InitGrid(fSqlStr); //ȫ<><C8AB><EFBFBD><EFBFBD>Ʒ
end;
end;
procedure TfrmCustHelp.Edit1Change(Sender: TObject);
var
TmpSql:string;
begin
TmpSql := 'SELECT CustomNo,ShortName,CustomName,a.Contactor,ywyCode FROM V_BC_Customer A'
+ ' where (A.CustomName Like '+quotedStr('%'+trim(edit1.Text)+'%')+
' or A.ShortName Like '+quotedStr('%'+trim(edit1.Text)+'%')+
' or A.CustomNo Like '+quotedStr('%'+trim(edit1.Text)+'%')+ ')';
InitGrid(TmpSql);
end;
procedure TfrmCustHelp.tv1DblClick(Sender: TObject);
begin
BtnOk.Click ;
end;
procedure TfrmCustHelp.frameLeftHelpTree1tt1FocusedRecordChanged(
Sender: TcxCustomGridTableView; APrevFocusedRecord,
AFocusedRecord: TcxCustomGridRecord;
ANewItemRecordFocusingChanged: Boolean);
begin
if not LoadFlag then exit;
frameLeftHelpTree1.tt1FocusedRecordChanged(Sender,
APrevFocusedRecord, AFocusedRecord, ANewItemRecordFocusingChanged);
fSqlStr:='select a.CustomNo,a.ShortName,a.CustomName,a.CustomNameEn,a.Contactor,ywyCode from V_BC_customer A where 1=1 ';
InitGrid(fSqlStr);
end;
procedure TfrmCustHelp.FormShow(Sender: TObject);
begin
tv1customName.Visible := fDispCustomName;
end;
end.