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

📄 untcommons.pas

📁 车辆管理系统
💻 PAS
📖 第 1 页 / 共 3 页
字号:
unit untCommons;

interface

uses
  Sysutils, DBClient, DB, ADODB, variants, untCommon, Untexecutesql, Untopensql,
  Windows, Provider, Classes, Forms;

type
  Tcommons = Class(TInterfacedObject,Icommon)
  private
    aopensql:Topensql;
    aexecsql:Texecsql;
    function vartosql(value:Variant):String;stdcall;
    procedure BeginTrans; stdcall;
    procedure CommitTrans; stdcall;
    procedure RollbackTrans; stdcall;
    function  IntransAction:boolean;Stdcall;
    function OpenindicatinnDB(DBname:String):Boolean;stdcall;

  public
    constructor create();
    destructor destroy();override;
    function GetLogin(const DBName, UserCode, PassWord: WideString): Integer;
      safecall;
    function GetAdmin(const DBName, UserCode, PassWord: WideString): WordBool;
      safecall;
    function GetUserRight(const DBName: WideString;
      UserID: Integer): OleVariant; safecall;
    function GetUserName(const DBName, UserCode,
      PassWord: WideString): WideString; safecall;
    function GetAppTitle: WideString; safecall;
    function GetLargeData(const DBName, CmdStr: WideString;
      Rcount: Integer): OleVariant; safecall;
    function GetMaxID(const DBName, TableName, KeyField: WideString): Integer;
      safecall;
    function GetServerTime: WideString; safecall;
    function GetAdminLogin(const PassWord: WideString): WordBool; safecall;
    function IsUnique(const DBName, TableName, MasterField,
      CheckValue: WideString): WordBool; safecall;
    function ExecSql(const DBName, CmdStr: WideString): WordBool; safecall;
    function SysLog(const DBName,Fstate, Fform, Fevent, Fuser,
      Fpcname: WideString): WordBool; safecall;
    function ApplyUpdateDelta(const DBName: WideString; Delta: OleVariant;
      const TableName, KeyField, UserCode, PcName: WideString): WordBool;
      safecall;
    function GetInNumber(const DBName: WideString;
      pBillTypeID: Integer): Integer; safecall;
    function GetOutNumber(const DBName: WideString;
      pBillTypeID: Integer): WideString; safecall;
    function ApplyupdateMD(const DBName: WideString; Mdelta: OleVariant;
      const MtableName, MkeyField: WideString; Ddetla: OleVariant;
      const DtableName, DkeyField, UserCode, PCname: WideString): WordBool;
      safecall;
    function WriteDraft(const DBName: WideString; pStatus: Integer;
      const pBillName, pBillNo, pBillSelfNo, pCompany, pRemark,
      pCreaUser: WideString): WordBool; safecall;
    function GetBillStatus(const DBName, pSqlTiao: WideString): OleVariant;
      safecall;
    function IsVip(const DBName: WideString; Cid: Integer): WordBool; safecall;
    function GetVIPID(const DBName: WideString; CustomerID: Integer): Integer;
      safecall;
    function ExistVip(const DBName: WideString; VIPid: Integer): WordBool;
      safecall;
    function WriteBalance(const DBName: WideString; pStatus,
      pBillStatus: Integer; const pNo, pBillName: WideString;
      pCusTomerID: Integer; const pRemark: WideString; pOverk, Poverf,
      Povert, pHire, pMortgage, pPMortgage, pPMainTain, pPBenZine,
      pPOther: Single; const pCreaUser: WideString): WordBool;
      safecall;
    function GetVehicleStatus(const DBName: WideString): OleVariant; safecall;
    function GetFinanceBalance(const DBName, Sdate,
      Edate: WideString): OleVariant; safecall;
    function GetFinanceCollect(const DBName, Sdate,
      Edate: WideString): OleVariant; safecall;
    function VehicleRent(const DBName, Vcode, Sdate,
      Edate: WideString): OleVariant; safecall;
    function CustomerRent(const DBName, CustomerNo, Sdate,
      Edate: WideString): OleVariant; safecall;
  end;

implementation

uses  untComponentFactory, untConsts, untDmServer, untMainStatusThread,
  untGlobal;

{ Tcommon }

function Tcommons.ApplyUpdateDelta(const DBName: WideString;
  Delta: OleVariant; const TableName, KeyField, UserCode,
  PcName: WideString): WordBool;
var
i:integer;
s1,s2:String;
Cmdstr:string;
FieldList:TstringList;
Cdsupdate:Tclientdataset;
ExecSQLADO:Tadoquery;
AlreadyPost:boolean;
begin

if VarisNull(delta) then
  begin
    Result:=False;
    Exit;
  end;
if OpenIndicatinnDB(DBname) then
begin
AlreadyPost:=False;
try
FieldList:=Tstringlist.Create;
Cdsupdate:=GetNewClientDataset;
ExecSQLADO:=GetNewAdoquery;

with dmServer.AdoConMain do
begin
  GetFieldNames(Tablename,FieldList);
end;
Cdsupdate.Close;
Cdsupdate.Data:=delta;
if not Cdsupdate.Active then Cdsupdate.Open;
for i:=1 to fieldList.Count do
  if Cdsupdate.FindField(FieldList[i-1])<>nil then
    cdsupdate.FindField(FieldList[i-1]).tag:=1;

if CDSupdate.RecordCount>0 then
  begin
  CDSupdate.First;
  s1:='';
  s2:='';
  while not CDSupdate.Eof do
  begin
  CmdStr:='';
  case Cdsupdate.UpdateStatus of
  usUnmodified:
    begin
    S2:=InttoStr(cdsupdate.fieldbyname(keyField).AsInteger); 
    end;
  usModified:
    begin
    s1:='';
    for i:=1 to CDSupdate.FieldCount do
      if (not cdsupdate.Fields[i-1].isNull) and (Cdsupdate.Fields[i-1].tag=1) then
      begin
        if s1='' then
        s1:=Trim(CDSupdate.Fields[i-1].FieldName)+' = '+vartosql(Cdsupdate.Fields[i-1].value)
        else
        s1:=s1+','+Trim(CDSupdate.Fields[i-1].FieldName)+' = '+vartosql(Cdsupdate.Fields[i-1].value);
        end;
        if s1<>'' then
        begin
        CmdStr:=' update '+tablename+' set '+s1+' where '+keyField+' = '+s2;
        end;
      end;
    usInserted:
      begin
      s1:='';
      s2:='';
      for i:=1 to Cdsupdate.FieldCount do
      if (not Cdsupdate.Fields[i-1].isnull) and (cdsupdate.Fields[i-1].tag=1) then
        begin
        if s1='' then
        begin
          s1:=Trim(Cdsupdate.Fields[i-1].FieldName);
          s2:=Vartosql(Cdsupdate.Fields[i-1].value);
        end
        else
        begin
          s1:=s1+','+Trim(Cdsupdate.Fields[i-1].FieldName);
          s2:=s2+','+Vartosql(Cdsupdate.Fields[i-1].value);
        end;
        end;
        if s1<>'' then
        begin
          CmdStr:=' Insert into '+Tablename+'('+s1+') values('+s2+')';
        end;
      end;
    usDeleted:
      begin
      s2:=Vartosql(Cdsupdate[keyField]);
      CmdStr:='Delete '+tablename+' where '+keyField+'='+s2;
      end;
    end;
    if CmdStr<>'' then
      begin
        if not IntransAction then
          Begintrans;
        try
        with ExecSQLADO do
          begin
          close;
          sql.Clear;
          sql.Text:=CmdStr;
          Execsql;
          AlreadyPost:=True;
          Syslog(DBName,c_Succeed,TableName,cmdStr,UserCode,PCname);
          end;
          except
            AlreadyPost:=False;
            Syslog(DBName,c_Failed,TableName,cmdStr,UserCode,PCname);
            break;
          end;
      end;

      cdsupdate.Next;
    end;
    if not AlreadyPost then
      begin
        Result:=False;
        if IntransAction then
           RollbackTrans;
      end
      else
      begin
         Result:=True;
         if IntransAction then
           CommitTrans;
      end
   end;
finally
FieldList.Free;
FreeExistAdoquery(ExecSqlado);
FreeExistClientDataset(Cdsupdate);
end;
end
else
  Result:=False;

end;


function Tcommons.ApplyupdateMD(const DBName: WideString;
  Mdelta: OleVariant; const MtableName, MkeyField: WideString;
  Ddetla: OleVariant; const DtableName, DkeyField, UserCode,
  PCname: WideString): WordBool;
var
i,j:integer;
ms1,ms2,ds1,ds2:String;
mCmdstr,dCmdstr:string;
MFieldList,DFieldList:TstringList;
MCdsupdate,DCDSupdate:Tclientdataset;
ExecMSQLADO,ExecDSQLADO:Tadoquery;
MAlreadyPost,DAlreadyPost:Boolean;
begin

if Varisnull(Mdelta) and Varisnull(Ddetla) then
  begin
    Result:=False;
    Exit;
  end;

if OpenIndicatinnDB(DBname) then
  begin
  try
    MAlreadyPost:=False;
    DAlreadyPost:=False;
    MFieldList:=TstringList.Create;
    DFieldList:=TstringList.Create;
    With DMServer.AdoConMain do
      Begin
        GetFieldNames(MTablename,MFieldList);
        GetFieldNames(DTablename,DFieldList);
      end;
    MCdsupdate:=GetNewClientDataset;
    DCDSupdate:=GetNewClientDataset;

    Mcdsupdate.Close;
    Dcdsupdate.Close;

    Mcdsupdate.Data:=Mdelta;
    Dcdsupdate.Data:=Ddetla;

    if not MCDSupdate.Active then MCDSupdate.Open;
    if not DCDSupdate.Active then DCDSupdate.Open;

    for i:=1 to MFieldList.Count do
      begin
        if MCDSupdate.FindField(MFieldList[i-1])<>nil then
          MCDSupdate.FindField(MFieldList[i-1]).tag:=1;
      end;

    for j:=1 to DFieldList.Count do
      begin
        if DCDSupdate.FindField(DFieldList[j-1])<>nil then
          Dcdsupdate.FindField(DfieldList[j-1]).tag:=1;
      end;

if MCDSupdate.RecordCount > 0 then
  begin
    MS1:='';
    Ms2:='';
    MCmdStr:='';
    case MCdsupdate.UpdateStatus of
    usUnmodified:
    begin
      MS2:=MCDSupdate[MkeyField];
    end;
    usModified:
    begin
      MS1:='';
      for i:=1 to MCDSupdate.FieldCount do
      if (not MCDSupdate.Fields[i-1].isnull) and (MCDSupdate.Fields[i-1].tag=1) then
         begin
           if MS1='' then
             MS1:=Trim(MCDSupdate.Fields[i-1].fieldName)+' = '+Vartosql(MCDSupdate.Fields[i-1].value)
             Else
             MS1:=MS1+','+Trim(MCDSupdate.Fields[i-1].fieldName)+' = '+Vartosql(MCDSupdate.Fields[i-1].value);
         end;
         if MS1<>'' then
           begin
            MCmdstr:='update '+Mtablename+' set '+MS1+'  where  '+MkeyField+'='+MS2;
           end;
    end;
    usInserted:
      begin
         MS1:='';
         MS2:='';
         for i:=1 to MCDSupdate.FieldCount do
         if (not MCDSupdate.Fields[i-1].isnull) and (MCDSupdate.Fields[i-1].tag=1) then
         begin
           if MS1='' then
           begin
           MS1:=Trim(MCDSupdate.Fields[i-1].FieldName);
           MS2:=Vartosql(MCDSupdate.Fields[i-1].value);
           end
           else
           begin
           MS1:=MS1+','+Trim(MCDSupdate.Fields[i-1].FieldName);
           MS2:=MS2+','+Vartosql(MCDSupdate.Fields[i-1].value);
           end;
         end;
         if MS1<>'' then
           begin
           MCmdstr:='Insert into '+Mtablename+'('+MS1+') values('+MS2+')';
           end;
      end;
    usDeleted:
      begin
        MS2:=vartosql(MCDSupdate[MkeyField]);
        MCmdStr:='Delete '+MtableName+' where '+MkeyField+'='+Ms2;
       end;
    end;
end;
if not IntransAction then
  BeginTrans;

try
  ExecMSQLADO:=GetNewAdoquery;
  ExecDSQLADO:=GetNewAdoquery;
  if MCmdStr<>'' then
    begin
     try
        with ExecMSQLADO do
          begin
            Close;
            sql.Clear;
            sql.Text:=MCmdStr;
            ExecSQL;
            MAlreadyPost:=True;
            Syslog(DBName,c_Succeed,MTableName,McmdStr,UserCode,PCname);
          end;
     except
       MAlreadyPost:=False;
       Result:=False;
       Exit;
     end;
    end
    else
      MAlreadyPost:=False;

if DCDSupdate.RecordCount > 0 then
  begin
    DCDSupdate.First;
    DS1:='';
    Ds2:='';
    while not DCDSupdate.Eof do
      begin
      DCmdStr:='';
      case DCdsupdate.UpdateStatus of
      usUnmodified:
        begin
        DS2:=DCDSupdate[DkeyField];
        end;
      usModified:
        begin
        DS1:='';
        for j:=1 to DCDSupdate.FieldCount do
          if (not DCDSupdate.Fields[j-1].isnull) and (DCDSupdate.Fields[j-1].tag=1) then
            begin
            if DS1='' then
              DS1:=Trim(DCDSupdate.Fields[j-1].fieldName)+' = '+Vartosql(DCDSupdate.Fields[j-1].value)
              Else
              DS1:=DS1+','+Trim(DCDSupdate.Fields[j-1].fieldName)+' = '+Vartosql(DCDSupdate.Fields[j-1].value);
            end;
            if DS1<>'' then
              begin
              DCmdstr:='update '+Dtablename+' set '+DS1+' where '+DkeyField+'='+DS2;
              end;
        end;
      usInserted:
        begin
        DS1:='';
        DS2:='';
        for j:=1 to DCDSupdate.FieldCount do
        if (not DCDSupdate.Fields[j-1].isnull) and (DCDSupdate.Fields[j-1].tag=1) then
        begin
        if DS1='' then
          begin
          DS1:=Trim(DCDSupdate.Fields[j-1].FieldName);
          DS2:=Vartosql(DCDSupdate.Fields[j-1].value);
          end
          else
          begin
          DS1:=DS1+','+Trim(DCDSupdate.Fields[j-1].FieldName);
          DS2:=DS2+','+Vartosql(DCDSupdate.Fields[j-1].value);
          end;
        end;
        if DS1<>'' then
          begin
          DCmdstr:='Insert into '+Dtablename+'('+DS1+') values('+DS2+')';
          end;
          end;
      usDeleted:
        begin
          DS2:=vartosql(DCDSupdate[DkeyField]);
          DCmdStr:='Delete '+DtableName+' where '+DkeyField+'='+Ds2;
        end;
        end;
        if DCmdStr<>'' then
          begin
            try
             with ExecDSQLADO do
             begin
             close;
             sql.Clear;
             sql.Text:=DCmdStr;
             Execsql;
             DAlreadyPost:=True;
             Syslog(DBName,c_Succeed,DTableName,DcmdStr,UserCode,PCname);
             end;
            except
             DAlreadyPost:=False;
             break;
            end;
          end
          else
            DAlreadyPost:=False;
          DCDSupdate.next;
      end;
  end;
  if MAlreadyPost and DAlreadyPost then
    begin

⌨️ 快捷键说明

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