📄 common.pas
字号:
unit Common;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, DB, ADODB,IniFiles;
//-->票内容结构(包括标题和内容)
type
TKcontent=record
Title:string;
Body:TStrings;
B_Type:string;
end;
type
TFrm_Com = class(TForm)
ADOConnection: TADOConnection;
ADOQuery: TADOQuery;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure AddCoBoItem(ComboBox:TComboBox;FieldName:string;ADOQ:TADOQuery);//添加Item 到下拉框
function WriteINI(TableName:string):bool;
function GetData(qjnum,cznum,MidStr:string):TKContent;
function WriteData(Content:TKContent):bool;
end;
var
Frm_Com: TFrm_Com;
content:TKContent;
implementation
uses
Main;
function TFrm_Com.WriteData(Content:TKContent):bool;
var
num,str:string;
i:integer;
begin
Result:=False;
ADOQuery.Close;
ADOQuery.SQL.Text:='delete from CZNR';
ADOQuery.ExecSQL;
for i:=0 to Content.Body.Count-1 do
begin
///
num:=inttostr(i);
str:=Content.Body[i];
ADOQuery.SQL.Text:='insert into CZNR values('+num+','''+str+''')';
ADOQuery.ExecSQL;
end;
num:=inttostr(Content.Body.Count);
str:=Content.Title;
ADOQuery.SQL.Text:='insert into CZNR values('+num+','''+str+''')';
ADOQuery.ExecSQL;
ADOQuery.Close;
end;
function TFrm_Com.GetData(qjnum,cznum,MidStr:string):TKContent;
var
s:string;
begin
//获取操作内容
ADOQuery.Close;
ADOQuery.SQL.Text:='select * from CZZH where 器件编号='''+qjnum+''' and 操作编号='''+cznum+''' order by 序号';
ADOQuery.Open;
//如果没有相关记录则提取默认值
if ADOQuery.RecordCount=0 then
begin
ADOQuery.Close;
ADOQuery.SQL.Text:='select * from CZZH where 器件编号=''0'' and 操作编号='''+cznum+''' order by 序号';
ADOQuery.Open;
end;
content.Body.Clear;
ADOQuery.First;
while not ADOQuery.Eof do
begin
s:=trim(ADOQuery.FieldByName('前缀').AsString)+MidStr+trim(ADOQuery.FieldByName('操作内容').AsString);
//s:=trim(adoquery.Fields[4].AsString)+'一、十九联络41174'+trim(adoquery.Fields[3].AsString);
content.Body.Add(s);
ADOQuery.Next;
end;
ADOQuery.Close;
Result:=Content;
end;
function TFrm_Com.WriteINI(TableName:string):bool;
var
IniFile:TIniFile;
FileName:string;
begin
//写入配置信息到InI文件
FileName:=ExtractFilePath(Application.ExeName)+'Config\TableName.ini'; //获取INI文件路径
if FileExists(FileName) then
begin
IniFile:=TIniFile.Create(FileName);
try
IniFile.WriteString('Table','Name',TableName);
finally
IniFile.Free;
end;
result:=True;
end
else
begin
result:=false;
end;
end;
procedure TFrm_Com.AddCoBoItem(ComboBox:TComboBox;FieldName:string;ADOQ:TADOQuery);
var
S:string;
begin
try
ADOQ.First;
ComboBox.Clear;
while not ADOQ.Eof do
begin
S:=ADOQ.FieldByName(FieldName).AsString;
ComboBox.Items.Add(s);
ADOQ.Next;
end;
ComboBox.ItemIndex:=0;
except
//-->出错处理
if Application.MessageBox('读取数据失败,数据库文件可能丢失或损坏!要继续吗?点击“是”继续,点击“否”退出','错误!', MB_YESNO)=IDNO then
Frm_Main.Close;
end;
end;
{$R *.dfm}
procedure TFrm_Com.FormCreate(Sender: TObject);
var
DBPath:string;
begin
DBPath:=ExtractFilePath(Application.ExeName)+'DATA\DDCZP.mdb'; //获取数据库路径
try
Self.ADOConnection.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+DBPath+';Persist Security Info=False';
Self.ADOConnection.Connected:=true;
except
//-->出错处理
if Application.MessageBox('连接数据库失败,数据库文件可能丢失或损坏!要继续吗?点击“是”继续,点击“否”退出','错误!', MB_YESNO)=IDNO then
Frm_Main.Close;
end;
content.Body:=TStringList.Create;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -