⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wwfltdlg.pas

📁 胜天进销存源码,国产优秀的进销存
💻 PAS
📖 第 1 页 / 共 5 页
字号:
            else
               querysql.insert(i, 'Where');
         end
      end;

      for j:= 0 to whereClause.count-1 do
         querysql.insert(i+j+1, whereClause[j]);
      ReplaceRemoteSQL(querySQL);

   finally
      if SQLStringtype then querySQL.Free;

      { 4/8/99 - Make sure its TParams, so virtual datasets that don't use TParams won't throw an exception }
      if (tempParams<>nil) and
        wwIsClass(tempParams.ClassType, 'TParams') then
      begin
        if (tempParams<>nil) and (tempParams.count>=0) then { 10/1/98 }
           wwSetParamsProp(datasource.dataset, tempParams);
        tempParams.Free;
      end
//      wwSetParamCheck(datasource.dataset, tempParamCheck);
   end;

end;

procedure TwwFilterDialog.InitFields;
begin
   { Initializes FieldDefs for dataset}
   if (FilterMethod=fdByQueryModify) then
      InitQueryFields
   else begin
      InitTableFields;
   end
end;

Function TwwFilterDlg.IsValueField(ADisplayLabel: string): boolean;
begin
   result:= isValueType(GetFieldType(ADisplayLabel));
end;

Function TwwFilterDlg.IsValueType(AFieldType: TFieldType): boolean;
begin
   result:=
       (AFieldType in
       [ftDate, ftDateTime, ftSmallInt, ftInteger, ftWord, ftFloat, ftCurrency, ftBoolean,
        {$ifdef wwDelphi6Up}
        ftFMTBcd, ftTimeStamp, ftLargeInt,
        {$endif}
        ftBCD]);
   {$ifdef win32}
   if AFieldType=ftAutoInc then result:= True;
   {$endif}

   if ((DlgComponent as TwwFilterDialog).FilterMethod=fdByQueryModify) and
      (AFieldType in [ftDateTime, ftTime]) then result:= True;
end;

Procedure TwwFilterDialog.InitTableFields;
var i: integer;
    newFldItem: TwwDBFieldInfo;
    curField: TField;
begin
   for i:= 0 to FFldList.count-1 do TwwDBFieldInfo(FFldList[i]).Free; {4/22/98}
   FFldList.clear;

   if (DataSource<>Nil) and (DataSource.DataSet<>Nil) then
   begin
      { No peristent fields and not active }
{      if (DataSource.DataSet is TwwQuery) or (DataSource.DataSet is TwwQBE) then
      begin
         if (DataSource.DataSet.FieldCount=0) and (not DataSource.DataSet.active) then
         begin
            MessageDlg('No persistent fields found.  InfoPower requires ' +
              'persistent fields when using fdByFilter on an inactive Query or QBE. '+
              'Dbl-click the TwwQuery or TwwQBE component to make your field''s persistent ' +
              'or make your query active before calling this dialog', mtError,
              [mbOK], 0);
            exit;
         end
      end
}
   end;

{   for i:= 0 to FieldDefs.count-1 do begin
      newFldItem:= TwwDBFieldInfo.create;
      with newFldItem do
      begin
         LogicalFieldName:= FieldDefs.items[i].Name;
         PhysicalFieldName:= FieldDefs.items[i].Name;
         TableName:= '';
         FieldType:= FieldDefs.items[i].DataType;

         curField:=DataSource.DataSet.FindField(PhysicalFieldName);
         if curField=nil then DisplayLabel:= PhysicalFieldName
         else DisplayLabel:= curField.DisplayLabel;
      end;
      FFldList.add(newFldItem);
   end;
}

   for i:= 0 to datasource.dataset.FieldCount-1 do begin
      newFldItem:= TwwDBFieldInfo.create;
      with newFldItem do
      begin
         curField:= DataSource.DataSet.Fields[i];
         LogicalFieldName:= curField.FieldName;
         PhysicalFieldName:= LogicalFieldName;
         TableName:= '';  { Not used witih this filter method}
         FieldType:= curField.DataType;
         DisplayLabel:= curField.DisplayLabel;;
         Size:= curField.size;
      end;
      FFldList.add(newFldItem);
   end;

end;

Function TwwFilterDialog.AddFieldInfo: TwwFieldInfo;
begin
   result:= TwwFieldInfo.create;
   FieldInfo.add(result);
end;

Function TwwFilterDialog.AddDBFieldInfo: TwwDBFieldInfo;
begin
   result:= TwwDBFieldInfo.create;
   FFldList.add(result);
end;

Procedure TwwFilterDialog.DoInitTempDataSet(OrigDataSet, TempDataset: TDataSet);
begin
    If Assigned(FOnInitTempDataSet) then
       FOnInitTempDataSet(self, OrigDataset, TempDataSet);
end;

function TwwFilterDialog.IsWideSql(dataSet: TDataSet; propInfo: PPropInfo): boolean;
var o: Tobject;
begin
    o:= GetObjectProp(dataSet, PropInfo);
    if o.ClassName='TWideStringList' then result:= true
    else result:= false;
end;

Procedure TwwFilterDialog.InitQueryFields;
var {query: TQuery;}
    querysql: TStrings;
    {$ifdef wwDelphi3Up}
    querysql2: TStrings;
    {$endif}
    PropInfo: PPropInfo;
    table: TTable;
    tempDataSet: TDataSet;
    i, j, Apos: integer;
    line, word: string;
    tableName: wwSmallString;
    tempFldList, TempAllFldList: TStringList;
    PhysFieldName : wwSmallString;
    FieldDef: TFieldDef;
    newFldItem: TwwDBFieldInfo;
    tempField: TField;
    RemoteFieldInfo: TStrings;
    parts: TStrings;
    TableAliasList, TableNameList: TStrings;
    tnidx: integer;
    tempTableName, tempAliasName: string;
    SQLSTringType: boolean;
    widequerySQL: TWideStringList;
    widequerySQL2: TWideStrings;
    querySQLString: string;
    iswide: boolean;

   Function FldInList(TempFldName: wwSmallString): boolean;
   var i: integer;
   begin
      result:= False;
      for i:= 0 to FFldList.count-1 do begin
         if wwEqualStr(tempFldName, TwwDBFieldInfo(FFldList[i]).LogicalFieldName) then
         begin
            result:= True;
            exit;
         end
      end
   end;

   Function ComputeFieldName(TempFldName: wwSmallString): string;
   var FirstTime: boolean;
   begin
       FirstTime:= True;
       while FldInList(TempFldName) do begin
          if FirstTime then
              TempFldName:= TempFldName + '_' + '1'
          else begin
              TempFldName[length(TempFldName[j])]:=
                 char(ord(TempFldName[length(TempFldName)])+1);
          end
       end;
       result:= TempFldName;
    end;

  Procedure UpdateFromFieldOrigin(curField: TField;
     var APhysicalFieldName, ATablename: string);
  var  Options: TwwGetWordOptions;
       APos, DotPos: integer;
       word: string;
  begin
      if (curfield.origin='') or (patch[2]=true) then exit
      else begin
         APos:= 1;
         ATableName:= '';
         APhysicalFieldName:= '';
         repeat
            Options:= [wwgwSkipLeadingBlanks, wwgwQuotesAsWords, wwgwStripQuotes, wwgwSpacesInWords];
            word:= wwGetWord(curfield.Origin, APos, Options, ['.']);
            if (word<>'.') and (word<>'') then begin
               if APhysicalFieldName<>'' then ATableName:= APhysicalFieldName;
               dotpos:= pos('.', ATableName);
               if dotpos>0 then ATableName:= copy(ATableName, 1, DotPos-1);
               APhysicalFieldName:= word;
            end
         until word='';
      end;
  end;

begin
   if (Datasource=nil) or (Datasource.dataset=nil) then exit;

   if (FieldsFetchMethod = fmUseTFields) then
   begin
      FFldList.Clear;
      with DataSource.Dataset do begin
         FieldDefs.update;
         for i:= 0 to Fields.count-1 do
         begin
             newFldItem:= TwwDBFieldInfo.create;
             with newFldItem do
             begin
                 LogicalFieldName:= Fields[i].FieldName;
                 if SQLTables.count>0 then begin { 12/3/99 - Don't use i for items index }
                     TableName:= TwwSQLTablesCollectionItem(SQLTables.Items[0]).TableAliasName;
                     if TableName='' then
                        TableName:= TwwSQLTablesCollectionItem(SQLTables.Items[0]).TableName;
                 end;

                 PhysicalFieldName:= Fields[i].FieldName;
//                 FieldDef:= FieldDefs.Find(PhysicalFieldName);
                 { 2/9/2000 - Use TDefCollection Find so that FieldDef = nil does not throw exception }
                 FieldDef:= TFieldDef(tDefCollection(FieldDefs).Find(PhysicalFieldName));

                 { 2/01/2000 - Use origin information if available }
                 UpdateFromFieldOrigin(Fields[i], PhysicalFieldName, TableName);

                 if FieldDef<>nil then
                 begin
                     FieldType:= FieldDef.DataType;
                     Size:= FieldDef.size;
                 end
                 else if Fields[i]<>nil then begin
                     FieldType:= Fields[i].DataType;
                     Size:= Fields[i].Size;
                 end;
                 tempField:=Fields[i];
                 DisplayLabel:= tempField.DisplayLabel;
             end;
            FFldList.Add(newFldItem);
         end
      end;
      exit;
   end;


//    TableNameList:= nil;
//    TableAliasList:= nil;

    { Search for From clause }
    SQLSTringType:= False;
//    PropInfo:= Typinfo.GetPropInfo(DataSource.DataSet.ClassInfo,GetSQLPropertyName);
    PropInfo:= Typinfo.GetPropInfo(GetCommandTextDataSet.ClassInfo,GetSQLPropertyName);
    if PropInfo<>Nil then
    begin
       if (PropInfo^.Proptype^.Kind in [tkString, tklstring, tkwstring]) then
       begin
          querysqlstring:=  GetStrProp(GetCommandTextDataSet, PropInfo);
          SQLStringType:=True;
          querysql:= TStringlist.create;
          querysql.Add(querysqlstring);
       end
       else begin
          if IsWideSql(GetCommandTextDataSet, propInfo) then
          begin
             widequerysql:= TWideStringList(GetObjectProp(GetCommandTextDataSet, PropInfo));
             SQLStringType:= true;
             querysql:= TStringlist.create;
             for i:= 0 to widequerysql.Count - 1 do
             begin
                querysql.Add(widequerysql[i]);
             end;
             iswide:= true;
          end
          else begin
             querysql:= TStrings(GetOrdProp(GetCommandTextDataSet, PropInfo));
          end;

       end;
    end
    else exit;

//    PropInfo:= Typinfo.GetPropInfo(DataSource.DataSet.ClassInfo,GetSQLPropertyName);
//    if PropInfo<>Nil then querysql:= TStrings(GetOrdProp(DataSource.DataSet, PropInfo))
//    else exit;

    for i:= 0 to FFldList.count-1 do TwwDBFieldInfo(FFldList[i]).Free; {4/22/98}
    FFldList.Clear;

    for i:= 0 to querysql.count-1 do begin
       line:= uppercase(querysql[i]);
       APos:= 1;
       repeat
          word:= GetWord(line, APos);
       until (word='FROM') or (word='');
       if word='FROM' then break;
    end;


    if datasource.dataset is TBDEDataSet and
       (FieldsFetchMethod = fmUseTTable) then
    begin
       table:= TTable.create(Nil);
       tempDataSet:= table;
    end
    else if wwIsClass(datasource.dataset.classType, 'TClientDataSet') then
    begin
       table:= nil;
       TempDataSet:= nil;
    end
    else begin
       table:=nil;
       TempDataSet:= TDataSet(TComponentClass(datasource.dataset.classType).create(self)); { 2/23/99 - Give owner for 3rd party engines}
    end;

//    { 7/6/99 -Give user's of 3rd party engines a chance to override tempdataset properties }
//    DoInitTempDataSet(DataSource.dataset, TempDataSet);

    TempFldList:= TStringList.create;
    TempAllFldList:= TStringList.create;

    TableNameList:= TStringList.create;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -