Changeset 51 for oup/current/Code
- Timestamp:
- Dec 23, 2006, 11:16:42 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
oup/current/Code/OniDataClass.pas
r46 r51 2 2 interface 3 3 uses Data, DataStructures, Classes, SysUtils, StrUtils, 4 Dialogs, ABSDecUtil, ABSMain, DB ;4 Dialogs, ABSDecUtil, ABSMain, DB, Windows; 5 5 6 6 type … … 103 103 FDatabase: TABSDatabase; 104 104 FQuery: TABSQuery; 105 Fdat_files: TFiles; 106 Fdat_extensionsmap: TExtensionsMap; 105 107 protected 106 108 public … … 108 110 procedure Close; override; 109 111 112 procedure UpdateListCache; 110 113 // function GetDatLinks(srcid:LongWord):TDatLinks; 111 114 function GetFileInfo(fileid: LongWord): TFileInfo; override; … … 849 852 FQuery.Close; 850 853 854 UpdateListCache; 855 851 856 Result := True; 852 857 FBackend := ODB_ADB; … … 865 870 866 871 867 868 function TOniDataADB.GetFileInfo(fileid: LongWord): TFileInfo; 869 begin 870 if fileid < Self.GetFilesCount then 871 begin 872 FQuery.SQL.Text := 'SELECT * FROM datfiles WHERE id=' + IntToStr( 873 fileid) + ' ORDER BY id ASC;'; 874 FQuery.Open; 875 if FQuery.RecordCount = 1 then 876 begin 877 FQuery.First; 878 Result.ID := FQuery.FieldByName('id').AsInteger; 879 Result.Name := FQuery.FieldByName('name').AsString; 880 Result.Extension := FQuery.FieldByName('extension').AsString; 881 Result.FileName := FormatNumber(Result.ID, 5, '0') + '-' + Result.Name + '.' + 882 Result.Extension; 883 Result.Size := FQuery.FieldByName('size').AsInteger; 884 Result.FileType := HexToLong(FQuery.FieldByName('contenttype').AsString); 885 Result.DatAddr := 0; 886 Result.opened := False; 887 end; 888 FQuery.Close; 889 end 890 else 891 begin 892 Result.ID := -1; 893 end; 894 end; 895 896 897 898 899 function TOniDataADB.GetFilesList(ext: String; pattern: String; 900 NoEmptyFiles: Boolean; sort: TSortType): TStringArray; 872 procedure TOniDataADB.UpdateListCache; 901 873 var 902 874 i: LongWord; 903 where: String; 904 where_ext: String; 905 order: String; 906 begin 907 where := ''; 908 if Length(ext) > 0 then 909 begin 910 if Length(where) > 0 then 911 where := where + ' AND '; 912 if Pos(',', ext) > 0 then 913 begin 914 i := 1; 915 where_ext := ''; 916 while i < Length(ext) do 917 begin 918 if Length(where_ext) > 0 then 919 where_ext := where_ext + ' OR '; 920 where_ext := where_ext + '(extension="' + MidStr(ext, i, 4) + '")'; 921 i := i + 5; 922 end; 923 where := where + '(' + where_ext + ')'; 924 end 925 else 926 begin 927 where := where + '(extension="' + ext + '")'; 928 end; 929 end; 930 if Length(pattern) > 0 then 931 begin 932 if Length(where) > 0 then 933 where := where + ' AND '; 934 where := where + '(name LIKE "%' + pattern + '%")'; 935 end; 936 if NoEmptyFiles then 937 begin 938 if Length(where) > 0 then 939 where := where + ' AND '; 940 where := where + '(contenttype<>2)'; 941 end; 942 if Length(where) > 0 then 943 where := ' WHERE ' + where; 944 case sort of 945 stIDAsc: order := ' ORDER BY id ASC'; 946 stIDDesc: order := ' ORDER BY id DESC'; 947 stNameAsc: order := ' ORDER BY name ASC, id ASC'; 948 stNameDesc: order := ' ORDER BY name DESC, id ASC'; 949 stExtAsc: order := ' ORDER BY extension ASC, id ASC'; 950 stExtDesc: order := ' ORDER BY extension DESC, id ASC'; 951 end; 952 FQuery.SQL.Text := 'SELECT id,name,extension FROM datfiles' + where + order + ';'; 875 temps: String; 876 begin 877 FQuery.SQL.Text := 'SELECT id,name,extension,[size],contenttype FROM datfiles ORDER BY id ASC;'; 953 878 FQuery.Open; 954 879 if FQuery.RecordCount > 0 then 955 880 begin 956 881 FQuery.First; 957 SetLength( Result, FQuery.RecordCount);882 SetLength(Fdat_files, FQuery.RecordCount); 958 883 i := 0; 959 884 repeat 960 Result[i] := FormatNumber(FQuery.FieldByName('id').AsInteger, 5, '0') + '-' + 961 FQuery.FieldByName('name').AsString + '.' + FQuery.FieldByName('extension').AsString; 885 Fdat_files[i].ID := FQuery.FieldByName('id').AsInteger; 886 Fdat_files[i].Name := FQuery.FieldByName('name').AsString; 887 Fdat_files[i].Extension := FQuery.FieldByName('extension').AsString; 888 Fdat_files[i].FileName := FormatNumber(Fdat_files[i].ID, 5, '0') + '-' + 889 Fdat_files[i].Name + '.' + Fdat_files[0].Extension; 890 Fdat_files[i].FileNameHex := IntToHex(Fdat_files[i].ID, 4) + '-' + 891 Fdat_files[i].Name + '.' + Fdat_files[0].Extension; 892 Fdat_files[i].Size := FQuery.FieldByName('size').AsInteger; 893 Fdat_files[i].FileType := HexToLong(FQuery.FieldByName('contenttype').AsString); 894 Fdat_files[i].DatAddr := 0; 895 Fdat_files[i].opened := False; 962 896 Inc(i); 963 897 FQuery.Next; … … 965 899 end; 966 900 FQuery.Close; 967 end; 968 969 970 971 972 function TOniDataADB.GetFilesCount: LongWord; 973 begin 974 FQuery.SQL.Text := 'SELECT Count(*) AS cnumber FROM datfiles;'; 975 FQuery.Open; 976 if FQuery.RecordCount > 0 then 977 begin 978 FQuery.First; 979 Result := FQuery.FieldByName('cnumber').AsInteger; 980 end 981 else 982 Result := 0; 983 FQuery.Close; 984 end; 985 986 987 988 989 function TOniDataADB.GetExtensionsList: TStringArray; 990 var 991 i: LongWord; 992 begin 993 SetLength(Result, 0); 901 902 SetLength(Fdat_extensionsmap, 0); 994 903 FQuery.SQL.Text := 995 904 'SELECT extension,count(extension) AS x FROM datfiles GROUP BY extension ORDER BY extension ASC;'; … … 997 906 if FQuery.RecordCount > 0 then 998 907 begin 999 SetLength( Result, FQuery.RecordCount);908 SetLength(Fdat_extensionsmap, FQuery.RecordCount); 1000 909 i := 0; 1001 910 repeat 1002 Result[i] := FQuery.FieldByName('extension').AsString + ' (' + 1003 IntToStr(FQuery.FieldByName('x').AsInteger) + ')'; 911 temps := FQuery.FieldByName('extension').AsString[1]; 912 Fdat_extensionsmap[i].Extension[3] := temps[1]; 913 Fdat_extensionsmap[i].Extension[2] := temps[2]; 914 Fdat_extensionsmap[i].Extension[1] := temps[3]; 915 Fdat_extensionsmap[i].Extension[0] := temps[4]; 916 Fdat_extensionsmap[i].ExtCount := FQuery.FieldByName('x').AsInteger; 1004 917 Inc(i); 1005 918 FQuery.Next; … … 1007 920 end; 1008 921 FQuery.Close; 922 end; 923 924 925 function TOniDataADB.GetFileInfo(fileid: LongWord): TFileInfo; 926 var 927 i: Integer; 928 begin 929 if fileid < Self.GetFilesCount then 930 begin 931 for i := 0 to High(Fdat_files) do 932 if Fdat_files[i].ID = fileid then 933 Break; 934 if i < Length(Fdat_files) then 935 Result := Fdat_files[i] 936 else 937 Result.ID := -1; 938 end 939 else 940 begin 941 Result.ID := -1; 942 end; 943 end; 944 945 946 947 948 function TOniDataADB.GetFilesList(ext: String; pattern: String; 949 NoEmptyFiles: Boolean; sort: TSortType): TStringArray; 950 var 951 i: LongWord; 952 list: TStringList; 953 id, name, extension: String; 954 fields: TStrings; 955 956 procedure getfields; 957 begin 958 fields.CommaText := StringReplace(AnsiQuotedStr(list.Strings[i], '"'), ';', '","', [rfReplaceAll]); 959 if sort in [stIDAsc, stIDDesc] then 960 begin 961 id := fields.Strings[0]; 962 name := fields.Strings[1]; 963 extension := fields.Strings[2]; 964 end; 965 if sort in [stNameAsc, stNameDesc] then 966 begin 967 id := fields.Strings[1]; 968 name := fields.Strings[0]; 969 extension := fields.Strings[2]; 970 end; 971 if sort in [stExtAsc, stExtDesc] then 972 begin 973 id := fields.Strings[1]; 974 name := fields.Strings[2]; 975 extension := fields.Strings[0]; 976 end; 977 end; 978 979 begin 980 list := TStringList.Create; 981 list.Sorted := True; 982 for i := 0 to High(Fdat_files) do 983 begin 984 if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and 985 ((Length(pattern) = 0) or 986 (Pos(UpperCase(pattern), UpperCase(Fdat_files[i].Name)) > 0)) then 987 begin 988 if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then 989 begin 990 if AppSettings.FilenumbersAsHex then 991 id := IntToHex(Fdat_files[i].ID, 4) 992 else 993 id := FormatNumber(Fdat_files[i].ID, 5, '0'); 994 name := Fdat_files[i].Name; 995 extension := Fdat_files[i].Extension; 996 997 case sort of 998 stIDAsc, stIDDesc: list.Add(id + ';' + name + ';' + extension); 999 stNameAsc, stNameDesc: list.Add(name + ';' + id + ';' + extension); 1000 stExtAsc, stExtDesc: list.Add(extension + ';' + id + ';' + name); 1001 end; 1002 end; 1003 end; 1004 end; 1005 SetLength(Result, list.Count); 1006 fields := TStringList.Create; 1007 if sort in [stIDAsc, stNameAsc, stExtAsc] then 1008 for i := 0 to list.Count - 1 do 1009 begin 1010 getfields; 1011 Result[i] := id + '-' + name + '.' + extension; 1012 end 1013 else 1014 for i := list.Count - 1 downto 0 do 1015 begin 1016 getfields; 1017 Result[list.Count - i - 1] := id + '-' + name + '.' + extension; 1018 end; 1019 list.Free; 1020 fields.Free; 1021 end; 1022 1023 1024 1025 1026 function TOniDataADB.GetFilesCount: LongWord; 1027 begin 1028 Result := Length(Fdat_files); 1029 end; 1030 1031 1032 1033 1034 function TOniDataADB.GetExtensionsList: TStringArray; 1035 var 1036 i: LongWord; 1037 begin 1038 SetLength(Result, Length(Fdat_extensionsmap)); 1039 for i := 0 to High(Result) do 1040 begin 1041 with Fdat_extensionsmap[i] do 1042 begin 1043 Result[i] := Extension[3] + Extension[2] + Extension[1] + Extension[0] + 1044 ' (' + IntToStr(ExtCount) + ')'; 1045 end; 1046 end; 1009 1047 end; 1010 1048 … … 1139 1177 mem.Seek(0, soFromBeginning); 1140 1178 FQuery.SQL.Text := 'UPDATE datfiles SET data=MimeToBin("' + 1141 MimeCoder.StrTo(mem.Memory, mem.Size) + '") WHERE id=' + IntToStr(fileid) + ';'; 1179 MimeCoder.StrTo(mem.Memory, mem.Size) + '"), size=' + IntToStr(mem.Size) + 1180 ' WHERE id=' + IntToStr(fileid) + ';'; 1142 1181 FQuery.ExecSQL; 1143 1182 mem.Free; 1144 1183 mimecoder.Free; 1145 1184 end; 1185 UpdateListCache; 1146 1186 end; 1147 1187
Note:
See TracChangeset
for help on using the changeset viewer.