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

📄 commonunit.pas

📁 是一个Delphi的教材管理系统,内容很全面详细
💻 PAS
字号:
unit CommonUnit;

interface

uses
   Inifiles,Forms ,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
  Dialogs,StdCtrls, Mask; // Buttons,



type
    TOperator=Class    //操作员信息
    public
      OperatorID:string[8];
      OperatorPWD:string[8];
      OperatorName:string[8];
      OperatorPower:Array[1..4] of boolean;
    end;
    //清空输入的值
    TClearValue=Class(Tobject)
    public
      procedure Clear(form:TForm);
    end;

    TSetupConfig=Class(Tobject) //系统配置
    private
      FileName:string;
      iniFile:TIniFile;
      ConnString:string;
      OperatorID:string;
      bgImg:string;
      LeftBar:boolean;
      ToolBar:boolean;
      LogoImg:boolean;
      LeftBarStyle:integer;
      ImgNo:integer;
      host:string;
      DataBaseName:string;

    public
      procedure ReadConfig(); //读取配置信息
      procedure SaveConfig(); //保存配置信息
      constructor Create(filename:string);
      property LastOperatorID:string read OperatorID write OperatorID;  //上次登录用户
      property ConnectionString:string read connString write connString;//连接字符串
      property BackGroundImage:string read bgImg write bgImg;//背景图片
      property ShowLeftBar:boolean read LeftBar write LeftBar;//是否显示左边的工具栏
      property ShowToolBar:boolean read ToolBar write ToolBar;//是否显示工具栏
      property ShowLogoImg:boolean read LogoImg write logoImg;//是否显示Logo
      property SetLeftBarStyle:integer read leftBarStyle write leftBarStyle; //左侧工具栏样式
      property SetImgNo:integer read ImgNo write ImgNo; //左侧工具栏样式
      property SetHost:string read Host write Host;
      property SetDataBaseName:string read DataBaseName write DataBaseName;
    end;
type     //检查Edit中的值是否为0
  TCheckValue=Class(Tobject)
  public
    procedure checkEditValue(Edit1:TEdit;flag:string);
    procedure checkMaskEditValue(MaskEdit1:TMaskEdit);
end;

implementation
//检查合法性
procedure TCheckValue.checkEditValue(Edit1:TEdit;flag:string);
var
  v1:integer;
  v2:real;
begin
   v1:=0;v2:=0;
  //判断是否为空
   if trim(Edit1.Text)='' then
   begin
     Application.MessageBox('输入的值不能为空格','提示',mb_ok);
     Edit1.SetFocus;
   end;
  if flag='int' then
     v1:=StrToIntDef(edit1.Text,0)
  else
     v2:=StrToFloatDef(edit1.Text,0) ;
//判断值是否为0
   if ((v1=0) or (v2=0)) then
   begin
     Application.MessageBox('输入的值非法,或为0!','提示',mb_ok);
     Edit1.SetFocus;     
   end;
end;
//
procedure TCheckValue.checkMaskEditValue(MaskEdit1:TMaskEdit);
var
  V:real;
begin
   v:=0;
   if MaskEdit1.Text='' then
   begin
     Application.MessageBox('输入的值不能为空格','提示',mb_ok);
     MaskEdit1.SetFocus;
   end
   else
     V:=StrtoIntDef(MaskEdit1.Text,0);
   if v=0 then
   begin

   end
   else
   begin

   end;
end;
procedure TClearValue.Clear(Form:TForm);
var
  i:integer;
begin
   for i:=0 to Form.ComponentCount-1 do
   begin
      {if Form.Components[i] is TEdit then
        (Form.Components[i] as TEdit).Text:=''
      else
      if Form.Components[i] is TCheckBox then
        (Form.Components[i] as TCheckBox).Checked:=false;   }
   end;
end;


//定义配置文件类的方法
Constructor TSetupConfig.Create(fileName:string);
begin
   self.FileName:=fileName;
   iniFile:=TIniFile.Create(fileName);
end;
//读取配置信息
procedure TSetupConfig.ReadConfig();
var
  connstr:string;
begin
   // connstr:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Book;Data Source=127.0.0.1';
    DataBaseName:=iniFile.ReadString('DataBaseSetting','DataBaseName','book');
    Host:=iniFile.ReadString('DataBaseSetting','Host','127.0.0.1');
    LastOperatorID:=iniFile.ReadString('LastOperator','OperatorID','admin');

    BackGroundImage:=iniFile.ReadString('BackGroundImage','bgImg','bgImages\bgImage1.jpg');
    ShowLeftBar:=iniFile.ReadBool('Settings','LeftBar',true);
    ShowToolBar:=iniFile.ReadBool('Settings','ToolBar',false);
    ShowLogoImg:=iniFile.ReadBool('Settings','LogoImg',true);
    SetLeftBarStyle:=iniFile.ReadInteger('LeftBarStyles','Style',1);
    ImgNo:=iniFile.ReadInteger('BgImageNo','No',-1); //-1:无背景,1-3:背景1-3 ,0:自定义背景
    connstr:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog='+DataBaseName+';Data Source='+Host;
    ConnectionString:=iniFile.ReadString('Connection','ConnectionString',connstr);
end;
 //保存配置信息
procedure TSetupConfig.SaveConfig();
begin
    iniFile.WriteString('LastOperator','OperatorID',LastOperatorID);
    iniFile.WriteString('Connection','ConnectionString',ConnectionString);
    iniFile.WriteString('BackGroundImage','bgImg',BackGroundImage);
    iniFile.WriteBool('Settings','LeftBar',ShowLeftBar);
    iniFile.WriteBool('Settings','ToolBar',ShowToolBar);
    iniFile.WriteBool('Settings','LogoImg',ShowLogoImg);
    iniFile.WriteInteger('LeftBarStyles','Style',LeftBarStyle);
    iniFile.WriteInteger('BgImageNo','No',ImgNo);
    iniFile.WriteString('DataBaseSetting','DataBaseName',DataBaseName);
    iniFile.WriteString('DataBaseSetting','Host',Host);
end;

end.

⌨️ 快捷键说明

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