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

📄 u_dbpublicpack.pas

📁 软件功能:下载一个网站上所有的彩铃! 铃声下载完后
💻 PAS
📖 第 1 页 / 共 4 页
字号:
      Else
        ListNull(ControlMod);
      Result:=True;
    End;
  Except
    On E:EOleException Do
    Begin
      Result:=False;
      MessageDLG('Error:'+E.Message,MtWarning,[MBOK],0);
    End;
  End;
End;
//删除表记录
Function DeleteRec(ADOQuery:TADOQuery;ControlMod:TPanel;IsHaveAutoID:Boolean):Boolean;
Var
  Count,Jump:Integer;
Begin
  if IsHaveAutoID then
    Jump := 0
  else
    Jump :=1;  
  Try
    With ADOQuery do
    Begin
      If Eof Then
        Exit;
      Delete;
      If Not Eof Then
      Begin
        For Count:=0 To Controlmod.ControlCount-1 Do
        Begin
          If Controlmod.Controls[Count].Tag=0 Then
            Continue;
          If Controlmod.Controls[Count] is TEdit Then
            (Controlmod.Controls[Count] as TEdit).Text:=Fields[(Controlmod.Controls[Count] as TEdit).Tag-Jump].AsString;
          If (Controlmod.Controls[Count] is TComboBox) Then
            (Controlmod.Controls[Count] as TComboBox).Text:=Fields[(Controlmod.Controls[Count] as TComboBox).Tag-Jump].AsString;
          If (Controlmod.Controls[Count] is TMemo) Then
            (Controlmod.Controls[Count] as TMemo).Text:=Fields[(Controlmod.Controls[Count] as TMemo).Tag-Jump].AsString;
          If (Controlmod.Controls[Count] is TSpinEdit) Then
            (Controlmod.Controls[Count] as TSpinEdit).Value:=Fields[(Controlmod.Controls[Count] as TSpinEdit).Tag-Jump].AsInteger;
          If (Controlmod.Controls[Count] is TDateTimePicker) Then
          Begin
            If Fields[(Controlmod.Controls[Count] as TDateTimePicker).Tag-Jump].IsNull Then
            Begin
              (Controlmod.Controls[Count] as TDateTimePicker).Checked:=False;
            End
            Else
            Begin
              (Controlmod.Controls[Count] as TDateTimePicker).Checked:=True;
              (Controlmod.Controls[Count] as TDateTimePicker).DateTime:=Fields[(Controlmod.Controls[Count] as TDateTimePicker).Tag-Jump].AsDateTime;
            End;
          End;
        End;
      End
      Else
        ListNull(ControlMod);
      Result:=True;
    End;
  Except
    On E:EOleException Do
    Begin
      Result:=False;
      MessageDLG('Error:'+E.Message,MtWarning,[MBOK],0);
    End;
  End;
End;
//刷新数据
Procedure FlashRec(ADOTable:TAdoTable);
Begin
  Try
    ADOTable.Active:=False;
    ADOTable.Close;
    ADOTable.Open;
    ADOTable.Active:=True;
  Except
    On E:EOleException Do
    Begin
      MessageDLG('Error:'+E.Message,MtWarning,[MBOK],0);
    End;
  End;
End;
//刷新数据
Procedure FlashRec(ADOQuery:TADOQuery);
Begin
  Try
    ADOQuery.Active:=False;
    ADOQuery.Close;
    ADOQuery.Open;
    ADOQuery.Active:=True;
  Except
    On E:EOleException Do
    Begin
      MessageDLG('Error:'+E.Message,MtWarning,[MBOK],0);
    End;
  End;
End;
//显示表数据
Procedure ListRec(ADOTable:TAdoTable;ControlMod:TPanel;ListOption:Integer);
Var
  Count:Integer;
Begin
  With ADOTable do
  Begin
    If ListOption=0 Then
      Open;
    If Not Eof Then
    Begin
      For Count:=0 To ControlMod.ControlCount-1 Do
      Begin
        If Controlmod.Controls[Count].Tag=0 Then
          Continue;
        If Controlmod.controls[Count] is TEdit Then
          (Controlmod.Controls[Count] as TEdit).Text:=Trim(Fields[(Controlmod.Controls[Count] as TEdit).Tag-1].AsString);
        If (Controlmod.controls[Count] is TComboBox) Then
        begin
          (Controlmod.Controls[Count] as TComboBox).Text:=Trim(Fields[(Controlmod.Controls[Count] as TComboBox).Tag-1].AsString);
        end;
        If (Controlmod.controls[Count] is TMemo) Then
          (Controlmod.Controls[Count] as TMemo).Text:=Trim(Fields[(Controlmod.Controls[Count] as TMemo).Tag-1].AsString);
          (Controlmod.Controls[Count] as TComboBox).Text:=Trim(Fields[(Controlmod.Controls[Count] as TComboBox).Tag-1].AsString);
        If (Controlmod.controls[Count] is TSpinEdit) Then
          (Controlmod.Controls[Count] as TSpinEdit).Value:=Fields[(Controlmod.Controls[Count] as TSpinEdit).Tag-1].AsInteger;

        If (Controlmod.Controls[Count] is TDateTimePicker) Then
        Begin
          If Fields[(Controlmod.Controls[Count] as TDateTimePicker).Tag-1].IsNull Then
          Begin
            (Controlmod.Controls[Count] as TDateTimePicker).Checked:=False;
          End
          Else
          Begin
            (Controlmod.Controls[Count] as TDateTimePicker).Checked:=True;
            (Controlmod.Controls[Count] as TDateTimePicker).DateTime:=Fields[(Controlmod.Controls[Count] as TDateTimePicker).Tag-1].AsDateTime;
          End;
        End;
      End;
    End;
  End;
End;
//显示表数据
Procedure ListRec(ADOQuery:TADOQuery;ControlMod:TPanel;ListOption:Integer;IsHaveAutoID:Boolean);
Var
  Count,jump:Integer;
//  aTag:Integer;
Begin
  if IsHaveAutoID then
    jump:=0
  else
    jump:=1;
  With ADOQuery do
  Begin
    showmessage(IntToStr(Fields.Count));
    If ListOption=0 Then
      Open;
    If Not Eof Then
    Begin
      For Count:=0 To ControlMod.ControlCount-1 Do
      Begin
        If Controlmod.Controls[Count].Tag=0 Then
          Continue;
        If Controlmod.controls[Count] is TEdit Then
          (Controlmod.Controls[Count] as TEdit).Text:=Trim(Fields[(Controlmod.Controls[Count] as TEdit).Tag-jump].AsString);
        If (Controlmod.controls[Count] is TComboBox) Then
          (Controlmod.Controls[Count] as TComboBox).Text:=Trim(Fields[(Controlmod.Controls[Count] as TComboBox).Tag-jump].AsString);
        If (Controlmod.controls[Count] is TMemo) Then
          (Controlmod.Controls[Count] as TMemo).Text:=Trim(Fields[(Controlmod.Controls[Count] as TMemo).Tag-jump].AsString);
        If (Controlmod.controls[Count] is TSpinEdit) Then
          (Controlmod.Controls[Count] as TSpinEdit).Text:=Fields[(Controlmod.Controls[Count] as TSpinEdit).Tag-jump].Text;
        If (Controlmod.Controls[Count] is TDateTimePicker) Then
        Begin
          If Fields[(Controlmod.Controls[Count] as TDateTimePicker).Tag-jump].IsNull Then
          Begin
            (Controlmod.Controls[Count] as TDateTimePicker).Checked:=False;
          End
          Else
          Begin
            (Controlmod.Controls[Count] as TDateTimePicker).Checked:=True;
            (Controlmod.Controls[Count] as TDateTimePicker).DateTime:=Fields[(Controlmod.Controls[Count] as TDateTimePicker).Tag-jump].AsDateTime;
          End;
        End;
      End;
    End;
  End;
End;
//删除给定的表
Function DropTable(ADOConnection:TADOConnection;TableName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='Drop Table '+TableName;
  If ExecSqlStr(ADOConnection,SqlStr) Then Result:=True Else Result:=False;
End;
//删除给定的表
Function DropTable(DBConnectionString,TableName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='Drop Table '+TableName;
  If ExecSqlStr(DBConnectionString,SqlStr) Then Result:=True Else Result:=False;
End;
//删除给定的数据库
Function DropDataBase(ADOConnection:TADOConnection;DataBaseName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='Drop DataBase '+DataBaseName;
  If ExecSqlStr(ADOConnection,SqlStr) Then Result:=True Else Result:=False;
End;
//删除给定的数据库
Function DropDataBase(DBConnectionString,DataBaseName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='Drop DataBase '+DataBaseName;
  If ExecSqlStr(DBConnectionString,SqlStr) Then Result:=True Else Result:=False;
End;
//备份指定的数据库到给定的路径文件
Function BackUpDataBase(ADOConnection:TADOConnection;DataBaseName,FileName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='BackUp DataBase '+DataBaseName+'To Disk='+''''+FileName+''''+' With Init';
  If ExecSqlStr(ADOConnection,SqlStr) Then Result:=True Else Result:=False;
End;
//备份指定的数据库到给定的路径文件
Function BackUpDataBase(DBConnectionString,DataBaseName,FileName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='BackUp DataBase '+DataBaseName+'To Disk='+''''+FileName+''''+' With Init';
  If ExecSqlStr(DBConnectionString,SqlStr) Then Result:=True Else Result:=False;
End;
//还原指定的路径文件到给定的数据库
Function RestoreDataBase(ADOConnection:TADOConnection;DataBaseName,FileName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='Restore DataBase '+DataBaseName+'From Disk='+''''+FileName+''''+' With NoRecovery';
  If ExecSqlStr(ADOConnection,SqlStr) Then Result:=True Else Result:=False;
End;
//还原指定的路径文件到给定的数据库
Function RestoreDataBase(DBConnectionString,DataBaseName,FileName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='Restore DataBase '+DataBaseName+'From Disk='+''''+FileName+''''+' With NoRecovery';
  If ExecSqlStr(DBConnectionString,SqlStr) Then Result:=True Else Result:=False;
End;
//删除给定的数据库用户
Function DropUser(ADOConnection:TADOConnection;UserName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='Exec SP_DropUser '+UserName;
  If ExecSqlStr(ADOConnection,SqlStr) Then Result:=True Else Result:=False;
End;
//删除给定的数据库用户
Function DropUser(DBConnectionString,UserName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='Exec SP_DropUser '+UserName;
  If ExecSqlStr(DBConnectionString,SqlStr) Then Result:=True Else Result:=False;
End;
//删除给定的触发器
Function DropTrigger(ADOConnection:TADOConnection;TriggerName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='Drop Trigger '+TriggerName;
  If ExecSqlStr(ADOConnection,SqlStr) Then Result:=True Else Result:=False;
End;
//删除给定的触发器
Function DropTrigger(DBConnectionString,TriggerName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='Drop Trigger '+TriggerName;
  If ExecSqlStr(DBConnectionString,SqlStr) Then Result:=True Else Result:=False;
End;
//删除给定的存储过程
Function DropProcedure(ADOConnection:TADOConnection;ProcedureName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='Drop Procedure '+ProcedureName;
  If ExecSqlStr(ADOConnection,SqlStr) Then Result:=True Else Result:=False;
End;
//删除给定的存储过程
Function DropProcedure(DBConnectionString,ProcedureName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='Drop Procedure '+ProcedureName;
  If ExecSqlStr(DBConnectionString,SqlStr) Then Result:=True Else Result:=False;
End;
//删除给定的视图
Function DropView(ADOConnection:TADOConnection;ViewName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='Drop View '+ViewName;
  If ExecSqlStr(ADOConnection,SqlStr) Then Result:=True Else Result:=False;
End;
//删除给定的视图
Function DropView(DBConnectionString,ViewName:String):Boolean;
Var
  SqlStr:String;
Begin
  SqlStr:='Drop View '+ViewName;
  If ExecSqlStr(DBConnectionString,SqlStr) Then Result:=True Else Result:=False;
End;
//从指定的表取出表结构
Function GetTableStruct(ADOConnection:TADOConnection;ComputeName,DataBaseName,TableName,StructTableName:String):String;
Var
  Count:Integer;
  ADOQuery:TADOQuery;
  FieldType,FieldName,FieldLength,FieldPoint,FieldSql,SqlStr:String;
begin
  Try
    ADOQuery:=TADOQuery.Create(Nil);
    With ADOQuery Do
    Begin
      SqlStr:='Select FieldType,FieldName,FieldSize,FieldPointCount From '+StructTableName;
      SqlStr:=SqlStr+' Where ServerName='+''''+ComputeName+'''';
      SqlStr:=SqlStr+' And DataBaseName='+''''+DataBaseName+'''';
      SqlStr:=SqlStr+' And TableName='+''''+TableName+'''';
      ExecSqlStr(ADOQuery,ADOConnection,SqlStr,True);
      If Not Eof Then
      Begin
        FieldSql:='(';Count:=0;
        While Count<=RecordCount-1 Do
        Begin
          Inc(Count);
          FieldType:=Trim(FieldByName('FieldType').AsString);
          FieldName:=Trim(FieldByName('FieldName').AsString);
          FieldLength:=Trim(FieldByName('FieldSize').AsString);
          FieldPoint:=Trim(FieldByName('FieldPointCount').AsString);
          If UpperCase(FieldType)='DATATIME' Then
            FieldSql:=FieldSql+FieldName+' '+FieldType;
          If UpperCase(FieldType)='VARCHAR' Then
            FieldSql:=FieldSql+FieldName+' '+FieldType+' '+'('+FieldLength+')';

⌨️ 快捷键说明

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