zoukankan      html  css  js  c++  java
  • 字符串通用类

    TMyString = class(TObject)

      private

        FStrBeginTran: string;

        FStrEndTran: string;

      protected

        function GetData(myData: TMyField): string; virtual;

        function GetFields(myData: TData): string; virtual;

      public

        property StrBeginTran: string read FStrBeginTran;

        property StrEndTran: string read FStrEndTran;

        class procedure Split(const A, OldPattern: string; var Str: TStringList);

        class function SetInsert(tbName, strData, strFields: string): string;

        class function SetUpdate(tbName, strData, strFields: string): string;

        class function SetDelete(tbName, strData, strFields: string): string;

        class function GetStrUnion(str: TStringList): string;

        class procedure StrListCompare(s1, s2: TStringList; var s3, s4: TStringList);

        procedure SetInsertList(tbName: string; strDataList: TStringList; strFields: string; var

          strList: TStringList); virtual;

        procedure SetUpdateList(tbName: string; strDataList: TStringList; strFields: string; var

          strList: TStringList); virtual;

        procedure SetDeleteList(tbName: string; strDataList: TStringList; strFields: string; var

          strList: TStringList); virtual;

        procedure SetInsertListByDept(tbName: string; strDataList: TStringList; strFields: string; var

          strList: TStringList; Dept: string); virtual;

        procedure SetInsertListByDept1(tbName: string; strDataList: TStringList; strFields: string; var

          strList: TStringList; DeptNo, DeptName: string); virtual;

        procedure SetUpdateListByDept(tbName: string; strDataList: TStringList; strFields: string; var

          strList: TStringList; Dept: string); virtual;

        procedure SetDeleteListByDept(tbName: string; strDataList: TStringList; strFields: string; var

          strList: TStringList; Dept: string); virtual;

        constructor Create; virtual;

      end;

    implementation

    { TMyString }

    constructor TMyString.Create;

    begin

      FStrBeginTran := 'Begin Tran';

      FStrEndTran := 'Commit Tran';

    end;

    /// <summary>

    /// 获得数据

    /// </summary>

    /// <param name="myData"> </param>

    /// <returns> 数据</returns>

    function TMyString.GetData(myData: TMyField): string;

    begin

      Result := '';

    end;

    /// <summary>

    /// 获得字段

    /// </summary>

    /// <param name="myData"> </param>

    /// <returns> 字段值</returns>

    function TMyString.GetFields(myData: TData): string;

    begin

      Result := '';

    end;

    class function TMyString.GetStrUnion(str: TStringList): string;

    var

      i: Integer;

      stlTemp, stlTemp1: TStringList;

      s, temp: string;

    begin

      s := '';

      stlTemp := TStringList.Create;

      stlTemp1 := TStringList.Create;

      for i := 0 to str.Count - 1 do

      begin

        if Trim(str[i]) = '' then

          Continue;

        s := s + str[i] + ',';

      end;

      s := copy(s, 1, Length(s) - 1);

      stlTemp.CommaText := s;

      stlTemp.Sorted := True;

      for i := 0 to stlTemp.Count - 1 do

      begin

        temp := stlTemp[i];

        if stlTemp1.IndexOf(temp) = -1 then

          stlTemp1.Add(temp);

      end;

      Result := stlTemp1.CommaText;

      stlTemp.Free;

      stlTemp1.Free;

    end;

    class function TMyString.SetDelete(tbName, strData, strFields: string): string;

    var

      i: Integer;

      DataList, FieldsList: TStringList;

      str: string;

    begin

      DataList := TStringList.Create;

      FieldsList := TStringList.Create;

      Split(strData, ',', DataList);

      Split(strFields, ',', FieldsList);

      str := 'Delete from ' + tbName + ' where 1=1 ';

      for i := 0 to DataList.Count - 1 do

      begin

        str := str + ' and ' + FieldsList[i] + '=' + DataList[i];

      end;

      //str :=Copy(str,1,Length(str)-1);

      DataList.Free;

      FieldsList.Free;

      Result := str;

    end;

    procedure TMyString.SetDeleteList(tbName: string; strDataList: TStringList;

      strFields: string; var strList: TStringList);

    var

      i: Integer;

    begin

      for i := 0 to strDataList.Count - 1 do

      begin

        strList.Add(SetDelete(tbName, strDataList[i], strFields));

      end;

    end;

    procedure TMyString.SetDeleteListByDept(tbName: string;

      strDataList: TStringList; strFields: string; var strList: TStringList;

      Dept: string);

    var

      i: Integer;

    begin

      for i := 0 to strDataList.Count - 1 do

      begin

        strList.Add(SetDelete(tbName, strDataList[i], strFields));

      end;

    end;

    class function TMyString.SetInsert(tbName, strData, strFields: string): string;

    var

      str: string;

    begin

      str := 'insert into ' + tbName + '(' + strFields + ') values(' + strData + ')';

      Result := str;

    end;

    procedure TMyString.SetInsertList(tbName: string; strDataList: TStringList;

      strFields: string; var strList: TStringList);

    var

      i: Integer;

    begin

      for i := 0 to strDataList.Count - 1 do

      begin

        strList.Add(SetInsert(tbName, strDataList[i], strFields));

      end;

    end;

    procedure TMyString.SetInsertListByDept(tbName: string;

      strDataList: TStringList; strFields: string; var strList: TStringList;

      Dept: string);

    var

      i: Integer;

      sList: TStringList;

    begin

      for i := 0 to strDataList.Count - 1 do

      begin

        strDataList[0] := Dept;

        strList.Add(SetInsert(tbName, strDataList[i], strFields));

      end;

    end;

    procedure TMyString.SetInsertListByDept1(tbName: string;

      strDataList: TStringList; strFields: string; var strList: TStringList;

      DeptNo, DeptName: string);

    var

      i: Integer;

      sList: TStringList;

    begin

      for i := 0 to strDataList.Count - 1 do

      begin

        strDataList[0] := DeptNo;

        strDataList[1] := DeptName;

        strList.Add(SetInsert(tbName, strDataList[i], strFields));

      end;

    end;

    class function TMyString.SetUpdate(tbName, strData, strFields: string): string;

    var

      i: Integer;

      DataList, FieldsList: TStringList;

      str: string;

    begin

      DataList := TStringList.Create;

      FieldsList := TStringList.Create;

      Split(strData, ',', DataList);

      Split(strFields, ',', FieldsList);

      str := 'update ' + tbName + ' set ';

      for i := 0 to DataList.Count - 1 do

      begin

        str := str + FieldsList[i] + '=' + DataList[i] + ',';

      end;

      str := Copy(str, 1, Length(str) - 1);

      DataList.Free;

      FieldsList.Free;

      Result := str;

    end;

    procedure TMyString.SetUpdateList(tbName: string; strDataList: TStringList;

      strFields: string; var strList: TStringList);

    var

      i: Integer;

    begin

      //strList.Add(StrBeginTran);

      for i := 0 to strDataList.Count - 1 do

      begin

        strList.Add(SetUpdate(tbName, strDataList[i], strFields));

      end;

      //strList.Add(StrEndTran);

    end;

    procedure TMyString.SetUpdateListByDept(tbName: string;

      strDataList: TStringList; strFields: string; var strList: TStringList;

      Dept: string);

    begin

    end;

    class procedure TMyString.Split(const A, OldPattern: string; var Str: TStringList);

    begin

      Str.Text := Stringreplace(A, OldPattern, sLineBreak, [rfReplaceAll]);

    end;

    class procedure TMyString.StrListCompare(s1, s2: TStringList; var s3,

      s4: TStringList);

    var

      i: Integer;

    begin

      s1.Sort;

      s2.Sort;

      if s3.Count > 0 then

        s3.Clear;

      if s4.Count > 0 then

        s4.Clear;

      for i := 0 to s1.Count - 1 do

      begin

        if s2.IndexOf(s1[i]) = -1 then

          s3.Add(s1[i]);

      end;

      for i := 0 to s2.Count - 1 do

      begin

        if s1.IndexOf(s2[i]) = -1 then

          s4.Add(s2[i]);

      end;

    end;

    end.

  • 相关阅读:
    R_Studio(关联)使用apriori函数简单查看数据存在多少条关联规则,并按支持度降序排序输出
    Unity3D_(游戏)2D坦克大战 像素版
    R_Studio(cart算法决策树)对book3.csv数据用测试集进行测试并评估模型
    R_Studio(决策树算法)鸢尾花卉数据集Iris是一类多重变量分析的数据集【精】
    R_针对churn数据用id3、cart、C4.5和C5.0创建决策树模型进行判断哪种模型更合适
    R_Studio(教师经济信息)逻辑回归分析的方法和技巧
    JavaWeb_Get和Post方法传输数据区别
    JavaWeb_响应和请求数据包
    JavaWeb_使用dom4j解析、生成XML文件
    JavaWeb_ XML文件
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2035707.html
Copyright © 2011-2022 走看看