📄 ufunction.pas
字号:
unit Ufunction;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, DBCtrls, StdCtrls, Mask, ExtCtrls, Buttons, ToolWin,UDataVar,USetItem, Grids, db,
DBGridEh,adodb,checklst,USel_Goods,SYS_DataModal,uzdj,u_dm,UClass_Base,UTree_Sel,USel_Base ;
procedure reset( LstSet:TCheckListBox; TBName:string; itype,con:String);
procedure Seek(DGrid:TDBGridEh; Basetb,itype, Datatb, condi :string);
procedure readset(LstSet:TCheckListBox;TBName,itype,con:string);
procedure fresh( LstSet :TCheckListBox;itype,sort:integer;ww:string);
function MyGetCode(iType : integer;bAdd :Boolean) : string;
procedure ButEnabled(Tool:TToolBar; arr:array of boolean);
//////////////////////2002-04-09从库存中掉调入的函数
procedure SelFromTree(OwnerEdit:TCustomEdit;BackEdit:TCustomEdit;Tree_Sel:TfrmTree_Sel); overload;
//在树形窗体上选取项目
procedure SelFromTree(OwnerEdit:TCustomEdit;BackEdit:TCustomEdit;Tree_Sel:TfrmSel_Base); overload;
//在窗体上选项目
function FullGd(Qry:TADOQuery;GdEh:TDBGridEh;sTblName:String;Md:integer;Cktag:string): Boolean;
//填置DBGrid的表头——在Show事件中使用。如不用则SetItem无法使用。
function SaveCol(stblName:String;GDEh:TDBGridEh;Md:integer;Cktag:string):Boolean;
procedure FillComboBox(ComboBox:TCustomComboBox;TableName:String;FieldName:String);
//填充ComboBox
function Full_Front_Edit(Back_Edit:TCustomEdit;Front_Edit:TCustomEdit;Tree_Sel:TfrmTree_Sel):Boolean;overload;
//填前面的Edit
function Full_Front_Edit(Back_Edit:TCustomEdit;Front_Edit:TCustomEdit;Tree_Sel:TfrmSel_Base):Boolean;overload;
//填前面的Edit
function Full_Back_Edit(Back_Edit:TCustomEdit;Front_Edit:TCustomEdit;Tree_Sel:TfrmTree_Sel):Boolean; overload;
//填后面的Edit
function Full_Back_Edit(Back_Edit:TCustomEdit;Front_Edit:TCustomEdit;Tree_Sel:TfrmSel_Base):Boolean; overload;
//填后面的Edit
function HaveError(Back_Edit:TCustomEdit;Front_Edit:TCustomEdit):Boolean;
//前后Edit是否一致
procedure setDBGridEhTile(Qtemp:TADOQuery;fromidx,toidx:integer);
function GetGdCode():String;
//选择物品编码
function SetItem(Qry:TADOQuery):Boolean;
//设置GridEh的表头显示的项目
function IntToAli(i: string): TAlignment;
function FindName(TCode:String;Tree_Sel:TfrmTree_Sel):String;overload;
//已知T编号,找名
function FindName(TCode:String;Tree_Sel:TfrmSel_Base):String;overload;
//已知T编号,找名字
function FindTCode(Code:String;Tree_Sel:TfrmTree_Sel):String;overload;
function FindTCode(Code:String;Tree_Sel:TfrmSel_Base):String;overload;
//已知编号-名称,找T编号
function SplitCode(Code_Name:String;B_or_L:Boolean=true):String;
//拆分编号—名称字符串,B_or_L为真时,提取编号,否则提取名称
function GetPoint(OwnerEdit:TControl;Tree_Sel:TForm):TPoint;
function GetPrice(GoodCode:String):Real;
procedure ClearSelForm();
type
Tww = class(Tobject)
ww:string;
private
{ Private declarations }
public
{ Public declarations }
end;
//设置GridEh的表头显示的项目
implementation
var
ww:Tww;
function GetPrice(GoodCode:String):Real;
begin
With DM.ProcGetPrice do
begin
Parameters.ParamByName('@GdCode').Value:=GoodCode;
Parameters.ParamByName('@Date').Value:=frmMain.BM.bmDate;
ExecProc;
result:=Parameters.ParamByName('@Aveprice').Value;
end;
end;
function GetPoint(OwnerEdit:TControl;Tree_Sel:TForm):TPoint;
var
FormPoint:TPoint;
begin
FormPoint:=OwnerEdit.Parent.ClientToScreen(Point(OwnerEdit.Left,OwnerEdit.Top));
if (Screen.Height div 2)>FormPoint.y then
FormPoint.y:=FormPoint.y+OwnerEdit.Height
else
FormPoint.y:=FormPoint.y-Tree_Sel.Height ;
result:=FormPoint;
end;
procedure SelFromTree(OwnerEdit:TCustomEdit;BackEdit:TCustomEdit;Tree_Sel:TfrmTree_Sel);
var
FormPoint:TPoint;
begin
ClearSelForm;
//\\\\
FormPoint:=GetPoint(OwnerEdit,Tree_Sel);
Tree_Sel.Top:=FormPoint.y;
Tree_Sel.Left:=FormPoint.x;
Tree_Sel.Show;
while Tree_Sel.Active do
begin
Application.ProcessMessages;
end;
if Tree_Sel.SB<>sbHide then
begin
Tree_Sel.Close;
Tree_Sel.SB:=sbNone;
Exit;
end;
if Tree_Sel.Tv.Selected<>nil then
begin
OwnerEdit.Text:=Tree_Sel.Tv.Selected.Text;
BackEdit.Text:=String(Tree_Sel.Tv.Selected.Data);
Tree_Sel.SB:=sbNone;
end else
begin
Tree_Sel.SB:=sbNone;
Exit;
end;
end;
//==========================================================
procedure SelFromTree(OwnerEdit:TCustomEdit;BackEdit:TCustomEdit;Tree_Sel:TfrmSel_Base);
var
TmpString:String;
begin
ClearSelForm;
Tree_Sel.Show;
while Tree_Sel.active do
begin
Application.ProcessMessages;
end;
if Tree_Sel.SB<>sbHide then
begin
Tree_Sel.Close;
Tree_Sel.SB:=sbNone;
Exit;
end;
with Tree_Sel.QrySel do
begin
if Tree_Sel.QrySel.RecordCount<>0 then
begin
TmpString:=FieldByName('Code').AsString+'-'+FieldByName('Name').AsString;
BackEdit.Text:=FieldByName('Code').AsString;
OwnerEdit.Text:=TmpString;
Tree_Sel.SB:=sbNone;
end else
begin
Tree_Sel.SB:=sbNone;
Exit;
end;
end;
end;
//==========================================================
function FindName(TCode:String;Tree_Sel:TfrmSel_Base):String;overload;
begin
try
with Tree_Sel.QrySel do
begin
Filtered:=false;
if TCode<>''then
begin
Filter:='code = '+''''+TCode+'''';
Filtered:=true;
if Tree_Sel.QrySel.RecordCount=1 then
result:=FieldByName('Code').AsString+'-'+FieldByName('Name').AsString;
Filtered:=false;
end else
result:='';
end;
except
end;
end;
function Full_Front_Edit(Back_Edit:TCustomEdit;Front_Edit:TCustomEdit;Tree_Sel:TfrmSel_Base):Boolean;overload;
var
Code_name:String;
begin
result:=true;
try
Code_name:=FindName(Back_Edit.Text,Tree_Sel);
if trim(Front_Edit.Text)<>Code_name then
Front_Edit.Text:=Code_Name;
except
result:=false;
end;
end;
function Full_Back_Edit(Back_Edit:TCustomEdit;Front_Edit:TCustomEdit;Tree_Sel:TfrmSel_Base):Boolean;overload;
var
TCode:String;
begin
result:=true;
try
TCode:=FindTCode(Front_Edit.Text,Tree_Sel);
if Back_Edit.Text<>TCode then
begin
Back_Edit.Text:=TCode;
end;
except
result:=false;
end;
end;
procedure ClearSelForm();
var
i:integer;
begin
for i:=0 to Application.ComponentCount-1 do
begin
if Application.Components[i].InheritsFrom(TfrmTree_Sel) then
if TfrmTree_Sel(Application.Components[i]).Visible=true then
begin
TfrmTree_Sel(Application.Components[i]).Close;
Break;
end;
if Application.Components[i].InheritsFrom(TfrmSel_Base) then
if TfrmTree_Sel(Application.Components[i]).Visible=true then
begin
TfrmTree_Sel(Application.Components[i]).Close;
Break;
end;
end;
end;
function SplitCode(Code_Name:String;B_or_L:Boolean=true):String;
var
ThePos:integer;
begin
ThePos:=pos('-',Code_Name);
result:='';
if ThePos=0 then
begin
result:=Code_Name;
end else
begin
if B_or_L then
begin
result:=copy(Code_name,0,ThePos-1);
end else
result:=copy(Code_Name,ThePos+1,Length(code_Name)-ThePos);
end;
end;
function FindTCode(Code:String;Tree_Sel:TfrmSel_Base):String;overload;
begin
Code:=SplitCode(Code);
result:='';
with Tree_Sel.QrySel do
begin
Filtered:=false;
if Code<>''then
Filter:='code = '+''''+Code+''''
else
Exit;
Filtered:=true;
if RecordCount=1 then
result:=FieldByName('Code').AsString;
Filtered:=false;
end;
end;
function FindTCode(Code:String;Tree_Sel:TfrmTree_Sel):String;
begin
Code:=SplitCode(Code);
result:='';
Tree_Sel.ADOQry.Filtered:=false;
if Code<>''then
Tree_Sel.ADOQry.Filter:='code = '+''''+Code+''''
else
// Tree_Sel.ADOQry.Filter:='';
Exit;
Tree_Sel.ADOQry.Filtered:=true;
if Tree_Sel.ADOQry.RecordCount=1 then
result:=Tree_Sel.ADOQry.FieldByName('TCode').AsString;
Tree_Sel.ADOQry.Filtered:=false;
end;
function FindName(TCode:String;Tree_Sel:TfrmTree_Sel):String;overload;
begin
with Tree_Sel.ADOQry do
begin
Filtered:=false;
if TCode<>''then
begin
Filter:='Tcode = '+''''+TCode+'''';
Filtered:=true;
if RecordCount=1 then
result:=FieldByName('Code').AsString+'-'+FieldByName('Name').AsString;
Filtered:=false;
end else
result:='';
end;
end;
function IntToAli(i: string): TAlignment;
begin
if i='c' then
begin
result:=taCenter;
exit;
end;
if i='l' then
begin
result:=taLeftJustify;
exit;
end;
if i='r' then
begin
result:=taRightJustify;
exit;
end
else
begin
result:=taLeftJustify;
exit;
end;
end;
function FullGd(Qry:TADOQuery;GdEh:TDBGridEh;sTblName:String;Md:integer;Cktag:string): Boolean;
var
TmpCol:TColumnEh;
begin
result:=true;
GdEh.Columns.Clear;
Qry.Close;
Qry.SQL.Clear;
case md of
1:
if Cktag<>'' then
Qry.SQL.Text:='select * from S_QrDetail where (reporder='+#39+sTblName+#39+') and (location=''d'') and (kc_cktag='+#39+Cktag+#39+')'
else
Qry.SQL.Text:='select * from S_QrDetail where (reporder='+#39+sTblName+#39+') and (location=''d'') and (kc_cktag is null)';
2:Qry.SQL.Text:='select * from S_QrDetail where (reporder='+#39+sTblName+#39+') and (location<>''d'') and (kc_cktag='+#39+Cktag+#39+')';
3:Qry.SQL.Text:='select * from S_QrDetail where reporder='+#39+sTblName+#39;
end;
Qry.SQL.Add(' order by repitem asc'); //iorder
Qry.Open;
while not Qry.Eof do
begin
TmpCol:=GdEh.Columns.Add;
TmpCol.FieldName:=Qry.FieldByName('dispfield').AsString;
if not GdEh.ReadOnly then
if Qry.FieldByName('dispfield').AsString='nGoodName' then
begin
TmpCol.AlwaysShowEditButton := true;
TmpCol.ButtonStyle := (cbsEllipsis);//cbsDropDown);
end;
if Qry.FieldByName('dispfield').AsString='nFsJine' then
begin
{ if GdEh.Columns.Count > 1 then begin
GdEh.Columns[0].Footer.ValueType := (fvtStaticText);
GdEh.Columns[0].Footer.Value:='合计:';
end;}
TmpCol.Footer.FieldName := Qry.FieldByName('dispfield').AsString;
TmpCol.Footer.ValueType := (fvtSum);
end;
TmpCol.Title.Caption:=Qry.FieldByName('dispname').AsString;
TmpCol.Alignment:=IntToAli(Qry.FieldByName('align').AsString);
TmpCol.Width:=Qry.FieldByName('kc_dgwidth').AsInteger;
if not Qry.FieldByName('ifshow').AsBoolean then
TmpCol.Visible := false;
Qry.Next;
end;
end;
procedure FillComboBox(ComboBox:TCustomComboBox;TableName:String;FieldName:String);
begin
ComboBox.Items.Clear;
with DM.ADOQry do
begin
Close;
SQL.Text:='Select distinct '+FieldName+' from '+TableName+' where '+fieldName+'<>'+''''+''+'''';
Open;
ComBoBox.Items.Clear;
While not Eof do
begin
ComboBox.Items.Add(FieldByName(FieldName).AsString);
Next;
end;
end;
end;
function SaveCol(stblName:String;GDEh:TDBGridEh;Md:integer;Cktag:string):Boolean;
var
i:integer;
begin
result:=true;
try
with DM.ADOQgridset do
begin
for i:=0 to GdEh.Columns.Count-1 do
begin
Close;
SQL.Clear;
SQL.Text:='update S_QrDetail set kc_dgwidth=';
SQL.Add(inttostr(GdEh.Columns[i].width)); //iorder
SQL.Add(',dispname='+#39+GDEh.Columns[i].Title.Caption+#39);
case md of
1:SQL.add(' where (reporder='+#39+sTblName+#39+') and (location=''d'') and (kc_cktag='+#39+Cktag+#39+')');
2:SQL.add(' where (reporder='+#39+sTblName+#39+') and (location<>''d'') and (kc_cktag='+#39+Cktag+#39+')');
3:SQL.add(' where (reporder='+#39+sTblName+#39+')');
end;
SQL.Add(' and (dispfield='+#39+GdEh.Columns[i].FieldName+#39+')');
ExecSQL;
end;
end;
except
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -