%@//Script头、过程和函数定义
program procode;
%>
<%!//声明变量
function GetDataType(F: string): string;
begin
Result := GetDeliBack(F, '=');
Result := GetDeliPri(Result, '@0#');
end;
function GetAllow_NotRep(F: string): boolean;
begin
F := GetDeliBack(F, '@2#');
F := GetDeliPri(F, '@3#');
Result := '1' = F;
end;
function GetCField(F: string): string;
begin
Result := GetDeliBack(F, '@0#');
Result := GetDeliPri(Result, '@1#');
end;
function IsToMd5(F: string): boolean;
begin
F := GetDeliBack(F, '@6#');
F := GetDeliPri(F, '@7#');
Result := '1' = F;
end;
function IsToEncrypt(F: string): boolean;
begin
F := GetDeliBack(F, '@9#');
F := GetDeliPri(F, '@10#');
Result := '1' = F;
end;
function GetCreateType(F: string): string;
begin
F := GetDeliBack(F, '@7#');
F := GetDeliPri(F, '@8#');
Result := F;
end;
function GetMustCreate(F: string): boolean;
begin
F := GetDeliBack(F, '@8#');
F := GetDeliPri(F, '@9#');
Result := trim(F)='1';
end;
function GetRField(F: string): string;
begin
Result := GetDeliPri(F, '=');
Result := GetDeliBack(Result, '*');
end;
function IsIntFloat(DataType: string): boolean;
begin
DataType := GetDataType(DataType);
Result := (lowercase(datatype) = 'ftinteger') or (lowercase(datatype) = 'ftcurrency') or (lowercase(datatype) = 'ftfmtbcd') or
(lowercase(datatype) = 'ftsmallint') or (lowercase(datatype) = 'ftshortint') or
(lowercase(datatype) = 'ftlargeint') or (lowercase(datatype) = 'ftbcd') or (lowercase(datatype) = 'ftfloat');
end;
function IsDatetime(DataType: string): boolean;
begin
DataType := GetDataType(DataType);
Result := (LowerCase(DataType) = 'ftDate') or (LowerCase(DataType) = 'ftTime') or (LowerCase(DataType) = 'ftDateTime');
end;
function IsNumfromSL(SLType: TStringlist; FieldName: string): boolean;
var
lp: integer;
IsNum: boolean;
F: string;
begin
isNum := false;
for lp := 0 to SLType.Count - 1 do
begin
F := LowerCase(trim(GetRField(SLType[lp])));
if(F=LowerCase(FieldName)) then
begin
isNum := IsIntFloat(SLType[lp]);
break;
end;
end;
Result := IsNum;
end;
function GetValue(ds: THjhMemoryDataSet; Conn: TminiConnection; F, DataType: string;IsInsert: boolean;IsUpdate: boolean;FieldName: string; onlyset: boolean): string;
var
At: string;
begin
if ds = nil then
Result := Request.V(F)
else
Result := ds.V(F);
At := GetCreateType(DataType);
if (trim(At) > '0') and ((trim(Result) = '') or GetMustCreate(DataType)) then
begin
if At = '1' then
Result := GetClientUniqueCode
else
if At = '2' then
Result := formatdatetime('yyyy-mm-dd', Now)
else
if At = '3' then
Result := formatdatetime('hh:nn:ss', Now)
else
if At = '4' then
Result := formatdatetime('yyyy-mm-dd hh:nn:ss', Now)
else
if At = '5' then
Result := formatdatetime('yyyy-mm-dd hh:nn:ss.zzz', Now)
else
if At = '6' then
Result := GetSnowID()
else
if At = '7' then
Result := Request.Session.Values['set_Loginedusername']
else
if At = '8' then
begin
Result := Request.Session.Values['set_Loginedusername'];
if Conn <> nil then
if IsUpdate then
begin
if (LowerCase(Conn.DbType) = 'mssql') or (LowerCase(Conn.DbType) = 'db2') then
Result := 'isnull(' + FieldName + ','''')' + '+' + QuotedStr(',') + '+' + QuotedStr(Request.Session.Values['set_Loginedusername'])
else
if (LowerCase(Conn.DbType) = 'mysql') or (LowerCase(Conn.DbType) = 'sqlite') then
Result := 'concat(IFNULL(' + FieldName + ','''')' + ',concat(' + QuotedStr(',')+',' + QuotedStr(Request.Session.Values['set_Loginedusername']) + '))'
else
Result := FieldName + '+' + QuotedStr(',') + '+' + QuotedStr(Request.Session.Values['set_Loginedusername']);
exit;
end;
end else
if At = '9' then
begin
Result := '1';
if Conn <> nil then
if IsUpdate then
begin
if (LowerCase(Conn.DbType) = 'mssql') or (LowerCase(Conn.DbType) = 'db2') then
Result := 'isnull(' + FieldName + ',0)' + '+1'
else
if (LowerCase(Conn.DbType) = 'mysql') or (LowerCase(Conn.DbType) = 'sqlite') then
Result := 'IFNULL(' + FieldName + ',0)' + '+1'
else
Result := FieldName + '+1';
exit;
end;
end;
end;
if IsIntFloat(DataType) then
begin
if onlyset then exit;
if Result = '' then Result := 'null' else StrToFloat(Result);
end else
if IsDatetime(DataType) then
begin
if onlyset then exit;
if Result = '' then
Result := 'null'
else
if Conn <> nil then
begin
if (LowerCase(Conn.DbType) = 'mssql') or (LowerCase(Conn.DbType) = 'db2') then
Result := 'convert(datetime,' + QuotedStr(Result) + ', 20)'
else
begin
if length(Result) < 15 then
Result := 'str_to_date(' + QuotedStr(Result) + ',''%Y-%m-%d'')'
else
Result := 'str_to_date(' + QuotedStr(Result) + ',''%Y-%m-%d %H:%i:%s'')';
end;
end;
end else
begin
if (IsToMd5(DataType)) and (length(Result) <> 32) then
Result := GetMd5(Result, false);
if (IsToEncrypt(DataType)) then
Result := SetPWD(Result, '#');
if onlyset then exit;
if Conn <> nil then
if (LowerCase(Conn.DbType) = 'mysql') or (LowerCase(Conn.DbType) = 'sqlite') then
Result := StringReplace(Result, '\', '\\', [rfReplaceAll]);
Result := QuotedStr(Result);
if (LowerCase(Conn.DbType) = 'mssql') and (IsInsert or IsUpdate) then
Result := 'N' + Result;
end;
end;
function GetWhere(ds: THjhMemoryDataSet; Conn: TminiConnection; Sys_DB_Fields: string; SL: TStringlist; IsRepCall: boolean): string;
var
lp, I: integer;
SLTmp, SL2: TStringlist;
Dt, Value, One: string;
begin
SLTmp := TStringlist.Create;
SL2 := TStringlist.Create;
try
SLTmp.CommaText := Sys_DB_Fields;
SL2.CommaText := SL.Values['KEYWORD'];
Result := ' where ';
for lp := 0 to SL2.Count - 1 do
begin
Dt := '';
for I := 0 to SLTmp.Count - 1 do
begin
if SL2[lp] = GetRField(SLTmp[I]) then
begin
Dt := SLTmp[I];
break;
end;
end;
Value := GetValue(ds, Conn, SL2[lp], Dt, false, false, '', false);
if (Value = 'null') and (IsIntFloat(dt) or IsDatetime(dt)) then
begin
if IsRepCall then
One := SL2[lp] + ' is not null '
else
One := SL2[lp] + ' is null ';
end else
begin
if IsRepCall then
One := SL2[lp] + '<>' + Value
else
One := SL2[lp] + '=' + Value;
end;
if trim(Result) = 'where' then
Result := Result + One
else
Result := Result + ' and ' + One;
end;
finally
SL2.Free;
SLTmp.Free;
end;
end;
function CheckRep(IsMain: boolean; ds: THjhMemoryDataSet; Conn: TminiConnection; Query: TminiQuery; SL, SL2: TStringlist;MyName: string): boolean;
var
lp: integer;
TmpStr, TmpStr2, TmpStr3, fnew_data, Sys_DB_SQL, ErrStr, CF, V: string;
Flag, F2: boolean;
begin
Result := false;
TmpStr := '';
ErrStr := '';
Flag := false;
F2 := true;
//检查重复
TmpStr2 := GetWhere(ds, Conn, SL2.CommaText, SL, true);
///result := true; print(TmpStr2); exit ;
for lp := 0 to SL2.Count - 1 do
begin
if not GetAllow_NotRep(SL2[lp]) then Continue;
CF := GetCField(SL2[lp]);
TmpStr3 := GetRField(SL2[lp]);
V := GetValue(ds, Conn, TmpStr3, SL2[lp],false, false, '', false);
if (ds <> nil) then
fnew_data := ds.V('fnew_data')
else
fnew_data := Request.V('fnew_data');
if trim(fnew_data) = 'true' then
TmpStr3 := ' where ' + TmpStr3 + '=' + V
else
TmpStr3 := TmpStr2 + ' and ' + TmpStr3 + '=' + V;
Sys_DB_SQL := ' select count(*) as cc from ' + SL.Values['WRITE_TABLE'] + ' ' + TmpStr3;
if not Query.O(Sys_DB_SQL, ErrStr) then
begin
Print(MyName+'[%@clear@%]'); print('检查[' + CF + ']重复时出错:' + ErrStr + Sys_DB_SQL + '');
Print('');
exit;
end;
if Query.I('cc') > 0 then
begin
F2 := false;
if not Flag then
begin
Flag := true;
Print('[%@clear@%]');
end;
if (ds <> nil)and(not IsMain) then
print(MyName+'第[' + IntToStr(ds.CurRecordPos + 1) + ']行[' + CF + ']值[' + AnsiDequotedStr(V, '''') + ']重复,不能保存!
')
else
print(MyName+'[' + CF + ']值[' + AnsiDequotedStr(V, '''') + ']重复,不能保存!
');
if ds = nil then
Print(MyName+'');
end;
end;
if not F2 then exit;
Result := true;
end;
function UpdateData(IsMain: boolean; ds: THjhMemoryDataSet; var NeedExe: string; Conn: TminiConnection; Query: TminiQuery; SL, SL2: TStringlist): boolean;
var
lp: integer;
fnew_data, TmpStr, TmpStr2, TmpStr3, Sys_DB_SQL, ErrStr: string;
begin
Result := false; NeedExe := '';
//检查重复
if ds = nil then
if not CheckRep(true, ds, Conn, Query, SL, SL2,'') then exit;
if ds <> nil then
fnew_data := ds.V('fnew_data')
else
fnew_data := Request.V('fnew_data');
if (IsMain) and (trim(fnew_data) = 'true') then
begin
Print('[%@clear@%]'); print('当前是新增状态,但已存在该记录,不能保存!');
exit;
end;
TmpStr := '';
for lp := 0 to SL2.Count - 1 do
begin
if (trim(SL2[lp]) = '') or (Pos('*', GetDeliPri(SL2[lp], '=')) > 0) then Continue;
TmpStr3 := GetRField(SL2[lp]);
TmpStr3 := TmpStr3 + '=' + GetValue(ds, Conn, TmpStr3, SL2[lp], false, true, TmpStr3, false);
if TmpStr = '' then
TmpStr := TmpStr3
else
TmpStr := TmpStr + ',' + TmpStr3;
end;
TmpStr2 := GetWhere(ds, Conn, SL2.CommaText, SL, false);
Sys_DB_SQL := ' update ' + SL.Values['WRITE_TABLE'] + ' Set ' + TmpStr + TmpStr2;
if not Query.E(Sys_DB_SQL, ErrStr) then
begin
NeedExe := '1';
Print('[%@clear@%]'); print('保存数据出错:' + ErrStr + Sys_DB_SQL + '');
Print('[%@clear@%]'); print('保存数据出错:' + ErrStr + '' + Sys_DB_SQL);
Print('');
exit;
end;
Result := true;
end;
function InsertData(IsMain: boolean; ds: THjhMemoryDataSet; var NeedExe: string;Conn: TminiConnection; Query: TminiQuery; SL, SL2: TStringlist): boolean;
var
lp: integer;
fnew_data, Fields, OneValue, Values, Sys_DB_SQL, ErrStr, One: string;
begin
Result := false; NeedExe := '';
//检查重复
if ds = nil then
if not CheckRep(true, ds, Conn, Query, SL, SL2,'') then exit;
if ds <> nil then
fnew_data := ds.V('fnew_data')
else
fnew_data := Request.V('fnew_data');
if (IsMain) and (trim(fnew_data) <> 'true') then
begin
Print('[%@clear@%]'); print('当前不是新增状态,但找不到该记录,不能保存!请先找出来再修改!');
exit;
end;
Fields := '';
Values := '';
for lp := 0 to SL2.Count - 1 do
begin
if (trim(SL2[lp]) = '') or (Pos('*', trim(SL2[lp])) > 0) then Continue;
One := GetRField(SL2[lp]);
OneValue := GetValue(ds, Conn, One, SL2[lp], true, false, One, false);
if Fields = '' then
begin
Fields := One;
Values := OneValue;
end else
begin
Fields := Fields + ',' + One;
Values := Values + ',' + OneValue;
end;
end;
Sys_DB_SQL := ' insert into ' + SL.Values['WRITE_TABLE'] + '(' + Fields + ') values(' + Values + ') ';
if not Query.E(Sys_DB_SQL, ErrStr) then
begin
NeedExe := '1';
Print('[%@clear@%]'); print('插入数据出错:' + ErrStr + Sys_DB_SQL + '');
Print('[%@clear@%]'); print('增加数据出错:' + ErrStr + '' + Sys_DB_SQL);
Print('');
exit;
end;
Result := true;
end;
var
Sys_DB_Info, Sys_DB_Source, Sys_DB_SQL: string;
Query: TminiQuery;
ErrStr, TmpStr, TmpStr2, TmpStr3, TmpStr4, TmpStr5: string;
Pooler: TminiPooler;
lp, i, Sys_DB_RecordCount, Sys_DB_PageCount: integer;
SL, SL2, SL3: TStringlist;
mds, mds2: THjhMemoryDataSet;
Sys_DB_mainform: string;
Sys_DB_Fields_mainform: string;
Sys_DB_Form_ID: string;
flag: boolean;
%>
<%
Sys_DB_mainform := 'WRITE_TABLE=mainsetting,"READ_TABLE_SQL=//注意:如果是excel时,表名要这样写[页名$],如 Sys_DB_SQL := ''select * from [users$] where usercode = '' + QuotedStr(Request.V(''usercode''));'''#13#10+
'Sys_DB_SQL := '''';",KEYWORD=,SYS_DB_SOURCE=conf,SYS_DB_FORM_ID=mainform_Form';
Sys_DB_Info := 'WRITE_TABLE=mainsetting,"READ_TABLE_SQL=//注意:如果是excel时,表名要这样写[页名$],如 Sys_DB_SQL := ''select * from [users$] where usercode = '' + QuotedStr(Request.V(''usercode''));'''#13#10+
'Sys_DB_SQL := '''';",KEYWORD=,SYS_DB_SOURCE=conf,SYS_DB_FORM_ID=mainform_Form';
Sys_DB_Source := 'conf';
Sys_DB_PageCount := 0;
Sys_DB_Form_ID := 'mainform_Form';
%>
<% if Request.IsLogin('set_Logined') then
begin
if LowerCase(Request.V('logout')) = 'true' then
begin
Request.LogOut('set_Logined');
Response.Redirect('login.html');
exit;
end;
end else
begin
Response.Redirect('login.html?sourceurl=' + Urlencode(Request.URL));
exit;
end; %>
<%SL3 := TStringlist.Create;
try %>
<%Sl3.Add('mainservicepath=ftString@0#主服务目录@1#@2#0@3#0@4#0@5#@6#0@7#0@8#0@9#0@10#');%>
<%Sl3.Add('httpport=ftString@0#HTTP服务端口@1#@2#0@3#0@4#1@5#@6#0@7#0@8#0@9#0@10#');%>
<%Sl3.Add('serviceext=ftString@0#动态页面后缀@1#@2#0@3#0@4#0@5#@6#0@7#0@8#0@9#0@10#');%>
<%Sl3.Add('hosttodir=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#0@8#0@9#0@10#');%>
<%Sl3.Add('*starthttps=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#0@8#0@9#0@10#');%>
<%Sl3.Add('*usehttps=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#0@8#0@9#0@10#');%>
<%Sl3.Add('httpsport=ftString@0#服务端口@1#@2#0@3#0@4#1@5#@6#0@7#0@8#0@9#0@10#');%>
<%Sl3.Add('secretkey=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#6@8#0@9#0@10#');%>
<%Sl3.Add('cert=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#6@8#0@9#0@10#');%>
<%Sl3.Add('rootcert=ftString@0#根证书@1#@2#0@3#0@4#0@5#@6#0@7#6@8#0@9#0@10#');%>
<%Sl3.Add('*crossdomain=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#0@8#0@9#0@10#');%>
<%Sl3.Add('errorpage=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#6@8#0@9#0@10#');%>
<%Sl3.Add('threadcount=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#6@8#0@9#0@10#');%>
<%Sl3.Add('quequelength=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#6@8#0@9#0@10#');%>
<%Sl3.Add('maxsessioncount=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#6@8#0@9#0@10#');%>
<%Sl3.Add('sessiontimeout=ftString@0#会话超时@1#@2#0@3#0@4#0@5#@6#0@7#6@8#0@9#0@10#');%>
<%Sl3.Add('poolermincount=ftString@0#连接池下限@1#@2#0@3#0@4#0@5#@6#0@7#6@8#0@9#0@10#');%>
<%Sl3.Add('poolermaxcount=ftString@0#连接池上限@1#@2#0@3#0@4#0@5#@6#0@7#6@8#0@9#0@10#');%>
<%Sl3.Add('poolertimeout=ftString@0#连接池超时时间@1#@2#0@3#0@4#0@5#@6#0@7#6@8#0@9#0@10#');%>
<%Sl3.Add('*autozip=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#0@8#0@9#0@10#');%>
<%Sl3.Add('*startlog=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#0@8#0@9#0@10#');%>
<%Sl3.Add('maxlogcount=ftString@0#最大记录行数@1#@2#0@3#0@4#0@5#@6#0@7#6@8#0@9#0@10#');%>
<%Sl3.Add('clientcachefile=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#0@8#0@9#0@10#');%>
<%Sl3.Add('*servernocachefile=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#0@8#0@9#0@10#');%>
<%Sl3.Add('*autopcandmobile=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#0@8#0@9#0@10#');%>
<%Sl3.Add('autopcandmobileext=ftString@0#根证书@1#@2#0@3#0@4#0@5#@6#0@7#6@8#0@9#0@10#');%>
<%Sl3.Add('exttoserver=ftString@0#根证书@1#@2#0@3#0@4#0@5#@6#0@7#6@8#0@9#0@10#');%>
<%Sl3.Add('*openby127_0_0_1=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#0@8#0@9#0@10#');%>
<%Sl3.Add('blacklist=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#0@8#0@9#0@10#');%>
<%Sl3.Add('whitelist=ftString@0#@1#@2#0@3#0@4#0@5#@6#0@7#0@8#0@9#0@10#');%>
<% Sys_DB_Fields_mainform := SL3.CommaText;
finally SL3.Free end;%>
<%
if trim(Request.V(Sys_DB_Form_ID)) = '1' then
begin
SL := TStringlist.Create; //WRITE_TABLE
SL2 := TStringlist.Create;
try
if trim(Request.V('savetype')) = '1' then
begin
Print('[%@clear@%]');
SL.CommaText := Request.PostedData;
for lp := 0 to SL.Count - 1 do
begin
TmpStr := GetRField(SL.Names[lp]);
if TmpStr <> '' then
Request.Params.Values[TmpStr] := GetDeliBack(SL[lp], '=');
end;
end;
SL.CommaText := Sys_DB_mainform;
if not Pub.O(Sys_DB_Source, Pooler, Query, ErrStr) then
begin
Print('[%@clear@%]'); print('数据库连接出错:' + ErrStr + '');
Print('');
exit;
end;
if Pooler.DBType = 'memorytable' then
begin
ErrStr := DBMemory_Save(Request.PostedData, Pooler.DBName, Sys_DB_Fields_mainform);
if trim(ErrStr) = '' then
begin
Print('');
end else
begin
print('[%@clear@%]'); print('读取数据出错:' + ErrStr + '');
exit;
end;
end else
begin
TmpStr2 := GetWhere(nil, Pooler.Conn, Sys_DB_Fields_mainform, SL, false);
Sys_DB_SQL := 'select count(*) as cc from ' + SL.Values['WRITE_TABLE'] + TmpStr2;
try
if not Query.O(Sys_DB_SQL, ErrStr) then
begin
Print('[%@clear@%]'); print('读取数据出错:' + ErrStr + '');
exit;
end;
SL2.Sorted := true;
SL2.CommaText := Sys_DB_Fields_mainform;
if '1'='0' then if not Pooler.Conn.StartTrans(ErrStr) then begin print(ErrStr); exit; end;
if Query.I('cc') > 0 then
begin //更新 SL.Values['WRITE_TABLE']
TmpStr5 := '1';
if not UpdateData(true, nil, TmpStr3, Pooler.Conn, Query, SL, SL2) then
begin
if TmpStr3 = '1' then
begin
end;
if '1'='0' then if not Pooler.Conn.Rollback(ErrStr) then begin print(ErrStr); exit; end;
exit;
end;
Print('');
end else
begin //插入
TmpStr5 := '2';
if not InsertData(true, nil, TmpStr3, Pooler.Conn, Query, SL, SL2) then
begin
if TmpStr3 = '1' then
begin
end;
if '1'='0' then if not Pooler.Conn.Rollback(ErrStr) then begin print(ErrStr); exit; end;
exit;
end;
Print('');
end;
if '1'='0' then if not Pooler.Conn.Commit(ErrStr) then begin print(ErrStr); exit; end;
finally
Pooler.HadUsed := false; //注意: 一定要有这行,把实例还回连接池
end;
end;
finally
SL2.Free;
SL.Free;
end;
if trim(Request.V('savetype')) = '1' then exit;
end;
%>