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

📄 uglobe.pas

📁 delphi7.0 源码 学籍管理系统源码
💻 PAS
字号:
unit uGlobe;

interface

uses
  Classes, Forms, SysUtils, Dialogs, IniFiles, ADODB;

type
  TSchoolInfo = record
    City: string;
    Name: string;
    Address: string;
    Rector: string;
    Tel: string;
    HasElementary: Boolean;
    HasJunior: Boolean;
    ElementaryCourse: string;
    JuniorCourse: string;
    Events: string;
    Family: string;
  end;

  TExpression = record
    Name: string;
    Value: string;
  end;

const
  Ini_Section_School = 'School';
  Ini_Section_Setup = 'Setup';
  Ini_Section_Default = 'Default';
  Ini_Section_Rows = 'Rows';
  gDelimiter = ';';
  gLevels = '小学;初中';
  ElementaryGrades = '一年级;二年级;三年级;四年级;五年级;六年级';
  JuniorGrades = '初一;初二;初三';
  UnknowClass = '(未分班)';
  ClassFormat = '%s:%s(%s)';

var
  IniFileName: string;
  ClassIniFileName: string;
  GradeTreeFileName: string;
  ReportFileName: string;
  CurClass: string;
  ConStr: string;
  SchoolInfo: TSchoolInfo;
  DefalutValue: array of TExpression;
  DefalutRows: array of TExpression;

procedure SetGlobeVar;
procedure GetDefalutValue;
procedure SetDefalutValue;
procedure GetDefalutRows;
function GetLocalValueList(DataSet: TCustomADODataSet; FieldName: string; TopCount: Integer=50): string;
function GetFieldName(DataSet: TCustomADODataSet; FieldCaption: string): string;

implementation

procedure SetGlobeVar;
begin
  IniFileName := ChangeFileExt(Application.ExeName, '.INI');
  ClassIniFileName := ExtractFilePath(Application.ExeName) + 'Class.INI';
  GradeTreeFileName := ExtractFilePath(Application.ExeName) + 'GradeTree.tv';
  ReportFileName := ExtractFilePath(Application.ExeName)+'Card.frf';
  ConStr := ChangeFileExt(Application.ExeName, '.MDB');

  with TIniFile.Create(IniFileName) do
  try
    SchoolInfo.City := ReadString(Ini_Section_School, 'City', '');
    SchoolInfo.Name := ReadString(Ini_Section_School, 'Name', '');
    SchoolInfo.Address := ReadString(Ini_Section_School, 'Address', '');
    SchoolInfo.Rector := ReadString(Ini_Section_School, 'Rector', '');
    SchoolInfo.Tel := ReadString(Ini_Section_School, 'Tel', '');
    SchoolInfo.HasElementary :=ReadBool(Ini_Section_School, 'HasElementary', True);
    SchoolInfo.HasJunior := ReadBool(Ini_Section_School, 'HasJunior', True);
    SchoolInfo.ElementaryCourse := ReadString(Ini_Section_Setup, 'ElementaryCourse', '');
    SchoolInfo.JuniorCourse := ReadString(Ini_Section_Setup, 'JuniorCourse', '');
    SchoolInfo.Events := ReadString(Ini_Section_Setup, 'Events', '');
    SchoolInfo.Family := ReadString(Ini_Section_Setup, 'Family', '');
  finally
    Free;
  end;
  
  GetDefalutValue;
  GetDefalutRows;
end;

procedure GetDefalutValue;
var
  DefaultFields: TStrings;
  IniFile: TIniFile;
  i: integer;
begin
  DefaultFields := TStringList.Create;
  IniFile := TIniFile.Create(IniFileName);
  try
    IniFile.ReadSection(Ini_Section_Default, DefaultFields);
    SetLength(DefalutValue, DefaultFields.Count);
    for i:=Low(DefalutValue) to High(DefalutValue) do begin
      DefalutValue[i].Name := DefaultFields[i];
      DefalutValue[i].Value := IniFile.ReadString(Ini_Section_Default, DefaultFields[i], '');
    end;
  finally
    FreeAndNil(IniFile);
    FreeAndNil(DefaultFields);
  end;
end;

procedure GetDefalutRows;
var
  DefaultTables: TStrings;
  IniFile: TIniFile;
  i: integer;
begin
  DefaultTables := TStringList.Create;
  IniFile := TIniFile.Create(IniFileName);
  try
    IniFile.ReadSection(Ini_Section_Rows, DefaultTables);
    SetLength(DefalutRows, DefaultTables.Count);
    for i:=Low(DefalutRows) to High(DefalutRows) do begin
      DefalutRows[i].Name := DefaultTables[i];
      DefalutRows[i].Value := IniFile.ReadString(Ini_Section_Rows, DefaultTables[i], '1');
    end;
  finally
    FreeAndNil(IniFile);
    FreeAndNil(DefaultTables);
  end;
end;

procedure SetDefalutValue;
var
  IniFile: TIniFile;
  i: integer;
begin
  IniFile := TIniFile.Create(IniFileName);
  try
    for i:=Low(DefalutValue) to High(DefalutValue) do
      IniFile.WriteString(Ini_Section_Default, DefalutValue[i].Name, DefalutValue[i].Value);
  finally
    FreeAndNil(IniFile);
  end;
end;

function GetLocalValueList(DataSet: TCustomADODataSet; FieldName: string; TopCount: Integer=50): string;
var
  FValueList: TStrings;
  FDataset: TCustomADODataSet;
begin
  FValueList := TStringList.Create;
  FDataset := TCustomADODataSet.Create(Application);
  try
    FDataset.Clone(Dataset);
    FDataset.First;
    while (not FDataset.eof) and (FValueList.Count < TopCount) do begin
      if (not FDataset.FieldByName(Fieldname).IsNull)
      and (FValueList.IndexOf(FDataset.FieldValues[Fieldname]) = -1) then
        FValueList.Append(FDataset.FieldValues[Fieldname]);
      FDataset.Next;
    end;
    Result := FValueList.Text;
  finally
    FreeAndNil(FValueList);
    FreeAndNil(FDataset);
  end;
end;

function GetFieldName(DataSet: TCustomADODataSet; FieldCaption: string): string;
var i: integer;
begin
  for i:=0 to DataSet.FieldCount-1 do
    if DataSet.Fields[i].DisplayLabel = FieldCaption then begin
      Result := DataSet.Fields[i].FieldName;
      Exit;
    end;
end;

end.

⌨️ 快捷键说明

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