字符串通用类

简介: TMyString = class(TObject)   private     FStrBeginTran: string;     FStrEndTran: string;   protected     function GetData(myData: TMyField): st...

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.

相关文章
|
5月前
|
Dart
Dart中的String类型定义与拼接
Dart中的String类型定义与拼接
|
6月前
|
存储 C++
【C++模板】模板实现通用的数组
【C++模板】模板实现通用的数组
|
6月前
|
存储 C# 索引
C#学习相关系列之数据类型类的定义(一)
C#学习相关系列之数据类型类的定义(一)
106 0
Lambda表达式实现方式、标准格式、练习、省略模式、注意事项及和匿名内部类的区别
Lambda表达式实现方式、标准格式、练习、省略模式、注意事项及和匿名内部类的区别
127 0
|
前端开发 程序员 C#
【C#】通过扩展对象的方式,对字符串等数据类型进行数据进一步处理
在本篇文章中,我们讲一起了解下对象扩展的使用 在实际项目开发中,对象扩展使用的场景还是挺多的,比如:需要对时间值进行再处理,或者字符串中的斜杠(/)转为反斜杠(\)
112 0
|
Java
Java中的方法注意事项、通用格式及方法重载
方法注意事项、通用格式及方法重载的简单示例
85 0
Java中的方法注意事项、通用格式及方法重载
|
IDE Java 程序员
equals方法通用约定
equals方法通用约定
886 0
equals方法通用约定
8.1 类的一般形式
class ren(object):     '''this class is about ren class。类的说明,使用三个单引号'''     name='菇凉'     sex='Female'     def hello(self):         print('hello world') a=ren() print(type(a)) print(a.
576 0
|
自然语言处理 Python 索引
2018-07-19 在代码中进行中文命名(类/变量/方法等)的优势
相比英文命名, 一些中文命名的优势. Some advantages with Chinese naming compared to English naming.
797 0