// 账号合区处理过程
procedure TFrmMain.AccountAllOne;
var
FIDInfo: TAccountDBRecord; // 账号数据库记录结构
FDBRecord, FNewDBRecord: TMirRecord; // 数据库文件操作对象
nIndex, I, nRecordCount: Integer; // 索引、循环计数、记录总数
NewName: string; // 新账号名称
IdHeader: TIdHeader; // ID数据库文件头
begin
// 检查主区ID.DB是否存在
if FileExists(EdtMainID.Text) then
FDBRecord := TMirRecord.Create(EdtMainID.Text, fmShareDenyNone)
else begin
Application.MessageBox('主区ID数据库不存在!', '提示信息', MB_ICONQUESTION);
Exit;
end;
// 如果目标目录存在ID.DB则删除
if FileExists(EdtSavePath.Text + '\LoginSrv\IDDB\ID.DB') then
DeleteFile(EdtSavePath.Text + '\LoginSrv\IDDB\ID.DB');
// 创建新的ID.DB文件
FNewDBRecord := TMirRecord.Create(EdtSavePath.Text + '\LoginSrv\IDDB\ID.DB', fmCreate);
try
// 设置记录大小
FNewDBRecord.RecSize := SizeOf(FIDInfo);
try
// 处理主区数据
FDBRecord.RecSize := SizeOf(FIDInfo);
// 读取并写入文件头
FDBRecord.Seek(0, 0);
FDBRecord.Read(IdHeader, SizeOf(IdHeader));
FNewDBRecord.Seek(0, 0);
FNewDBRecord.Write(IdHeader, SizeOf(IdHeader));
nRecordCount := FDBRecord.NumRecs;
FDBRecord.First;
StatusBar1.Panels[0].Text := '正在把主区ID写入新库';
StatusBar1.Panels[1].Text := '';
Application.ProcessMessages;
// 复制主区所有账号记录
for i := 1 to FDBRecord.NumRecs do
begin
FDBRecord.ReadRec(FIDInfo);
AccountList.AddRecord(FIDInfo.UserEntry.sAccount, i); // 添加到账号列表
FNewDBRecord.AppendRec(FIDinfo); // 写入新数据库
// 更新进度条
StatusBar1.Panels[1].Text := '完成:' + inttostr(round((i / nRecordCount) * 100)) + '%';
Application.ProcessMessages;
FDBRecord.NextRec;
end;
finally
FDBRecord.Free;
end;
// 处理从区数据
if FileExists(EdtSlaveID.Text) then
FDBRecord := TMirRecord.Create(EdtSlaveID.Text, fmShareDenyNone)
else begin
Application.MessageBox('从库ID数据库不存在!', '提示信息', MB_ICONQUESTION);
Exit;
end;
try
FDBRecord.RecSize := SizeOf(FIDInfo);
nRecordCount := FDBRecord.NumRecs;
FDBRecord.First;
StatusBar1.Panels[0].Text := '正在把从库ID写入新库';
StatusBar1.Panels[1].Text := '';
Application.ProcessMessages;
// 处理从区所有账号记录
for i := 1 to FDBRecord.NumRecs do
begin
FDBRecord.ReadRec(FIDInfo);
// 检查账号是否重名
nIndex := AccountList.GetIndex(FIDInfo.UserEntry.sAccount);
if nIndex <> -1 then
begin
NewName := '';
// 生成新账号名称
if CheckName(FIDInfo.UserEntry.sAccount, 10, NewName, 0) then
begin
FIDInfo.Header.sAccount := NewName; // 更新账号头
FIDInfo.UserEntry.sAccount := NewName; // 更新账号记录
end else begin
FDBRecord.NextRec;
StatusBar1.Panels[1].Text := '完成:' + inttostr(round((i / nRecordCount) * 100)) + '%';
Continue;
end;
end;
AccountList.AddRecord(FIDInfo.UserEntry.sAccount, i); // 添加到账号列表
FNewDBRecord.AppendRec(FIDinfo); // 写入新数据库
// 更新进度条
StatusBar1.Panels[1].Text := '完成:' + inttostr(round((i / nRecordCount) * 100)) + '%';
Application.ProcessMessages;
FDBRecord.NextRec;
end;
// 更新文件头中的记录总数
FDBRecord.Seek(0, 0);
FDBRecord.Read(IdHeader, SizeOf(IdHeader));
IdHeader.nIDCount := FNewDBRecord.NumRecs;
FNewDBRecord.Seek(0, 0);
FNewDBRecord.Write(IdHeader, SizeOf(IdHeader));
finally
FDBRecord.Free;
end;
finally
FNewDBRecord.Free;
end;
end;