加载数据
try
//首先打开加载框,提示正在加载
DataM.ShowLoadDataForm();
//进入到qryMatser中
with qryMatser do
//开始执行
begin
//关闭qryMatser
close;
//连接数据库
connecetion:=DataM.ConMain;
//查询操作
SQL.Text:='数据库语句';
//执行
Open;
//结束
end;
//数据加载完,关闭加载框
DataM.HideloadDataForm;
//倘若出现问题
except on vError:Exception do
//开始
begin
//关闭加载狂
DataM.HideLoadDataForm;
//显示异常界面框
MsgHint.ShowError('数据加载异常'+vError.Message);
//结束
end;
end;
窗体跳转(新增)
try
//判断指针指向是否为空;若指向非空,则让其指向空
if assigned(form2) then form2:=nil;
//创建新窗体
form2:=Tform2.Create(nil);
//展示窗体
form2.ShowModal;
//如果form2窗体点击按钮(执行完毕),然后刷新数据
if form2.ModelResult=mrok then reflashdata;
except
//如果异常,指针释放,让指向不存在
freeandnil(form2);
end;
assigned是用来判断某一指针(pointer)或过程引用是否为nil(空)如果为空则返回false防止窗体被实例化多次
窗体跳转(修改)
前提:修改是传一部分数据过去的
//判断是否有数据(连接是否打开、数据是否存在起码1条)
if (not qryMatser.Active) or (qryMatser.RecordCount<=0) then
begin
//弹窗告知
Application.messageBox('请先选中您要修改的日报','提示',0+48);
end;
else
begin
try
if assigned(form2) then form2:=nil;
form2:=Tform2.Create(nil);
//传一个数据
form2.vRB_YQ:=qryMatser.FieldByName('YQMC').AsString;
//传第二个数据
form2.vRB_Date:=qryMatser.FieldByName('vMarkDate').AsString;
//窗体展示
form2.showmodel;
//结束,刷新数据(把一些基本数据刷出来)
if form2.modelresult=mrok then reflashdata;
except
//失败了,释放指针
freeandnil(form2);
end;
end;
删除单条日报
//判断是否有数据
if (not qryMatser.Active) or (qryMatser.RecordCount<=0) then
begin
Application.MessageBox('请先选中要删除的日报','提示',0+48);
end
else
begin
with qryMatser do
begin
if FieldByName('vFlag').AsString='1' then
begin
Application.MessageBox('已提交的日报不能删除','提示',0+48);
Exit;
end;
if Application.MessageBox('确定要删除本条日报?','提示',4+48)=IDNO then
Exit;
try
DataM.ExcteSQLNoTrans_conMain('delete from M_Data_RB where
ID='''+FieldByName('ID').AsString+''' ');
Application.MessageBox('删除成功','提示',0+48);
except on vError:Exception do
begin
MsgHint.ShowError('删除出现异常'+vError.Message);
end;
end;
end;
ReflashData;
end;
刷新数据
var
vID:string;
begin
if (not qryMatser.Active) or (qryMatser.RecordCount<=0) then Exit;
try
DataM.ShowLoadDataForm();
with qryMatser do
begin
vID:=qryMatser.FieldByName('ID').AsString;
if vID<>'' then
begin
Close;
Open;
Locate('ID',vID,[]);
end;
end;
DataM.HideLoadDataForm;
except on vError:Exception do
begin
DataM.HideLoadDataForm;
MsgHint.ShowError('数据刷新出现异常'+vError.Message);
end;
end;
end;
作废
if (not qryMatser.Active) or (qryMatser.RecordCount<=0) then
begin
Application.MessageBox('请选中要作废的日报','提示',0+48);
end
else
begin
with qryMatser do
begin
if FieldByName('vFlag').AsString='1' then
begin
Application.MessageBox('已提交的日报不能作废','提示',0+48);
Exit;
end;
if Application.MessageBox('确定要作废本日报吗?','提示',4+48)=IDNO then
Exit;
try
DataM.ExcteSQLNoTrans_conMain('update M_Data_RB set vFlag=''9'' where
ID='''+FieldByName('ID').AsString+'''');
Application.MessageBox('日报作废成功!','提示',0+48);
except on vError:Exception do
begin
MsgHint.ShowError('作废日报操作出错'+vError.Message);
end;
end;
end;
ReflashData;
end;
恢复
if (not qryMatser.Active) or (qryMatser.RecordCount<=0) then
begin
Application.MessageBox('请先选中类别!','提示',0+48)
end
else
begin
if Application.MessageBox('是否恢复本日报','提示',4+48)=IDNO then Exit;
try
with qryMatser do
begin
DataM.ExcteSQLNoTrans_conMain('update M_Data_RB set vFlag=''0'' where
ID='''+fieldByName('ID').AsString+'''');
Application.MessageBox('日报已恢复!','提示',0+48);
end;
except on vError:Exception do
begin
MsgHint.ShowError('恢复日报出现异常'+vError.Message);
end;
end;
end;
ReflashData;
检查是否作废了
begin
if vRB_Date='' then
begin
Self.Caption:='新增日报';
cxTE_Date.Date:=StrToDate(FormatDateTime('yyyy-mm-dd',DataM.GetServerDate));
with DataM.qryTemp do
begin
Close;
Connection:=DataM.ConMain;
SQL.Text:='select YQMC from M_Data_RB order by YQMC';
Open;
while not Eof do
begin
cxTE_YQ.Properties.Items.Add(DataM.qryTemp.fieldByName('YQMC').AsString);
Application.ProcessMessages;
Next;
end;
end;
end
else
begin
Self.Caption:='修改日报';
cxTE_YQ.Text:=vRB_YQ;
cxTE_Date.Date:=StrToDate(vRB_Date);
cxTE_YQ.Enabled:=False;
cxTE_Date.Enabled:=False;
end;
DownLoadData;
end;
adoqry中的方法:qryMatserAfterScroll
每执行一次数据库处理,就会进行数据操作一次