本文共 4666 字,大约阅读时间需要 15 分钟。
1.设置初始条件。
private:
addflag:boolean
modiflag:boolean
var:
strSQLCondition,strOrderCondition:string;
(保存按钮)btnsave.enabled := false;
(取消按钮)btncancel.enabled := false;
(添加,删除,更改)按钮 button.enabled := false;
2.设置添加(add)
addflag:=true;
modiflag:=false;
(保存按钮)btnsave.enabled := true;
(取消按钮)btncancel.enabled := true;
3.设置修改(ALTER)
modiflag:=true;
addflag := false;
(保存按钮)btnsave.enabled := true;
(取消按钮)btncancel.enabled := true;
4.设置删除(delete)
if addflag = True then
begin Application.MessageBox('正处于新增状态,请选择要删除的项目', '项目设置',mb_OK+MB_ICONinformation); abort; end; //新增状态下不予删除alterflag := true;
addflag := False;判断删除条件,符合后进行删除。
if dbgrdh1.FieldColumns['项目名称'].DisplayText = '' then
begin Application.MessageBox('请选择要删除的项目', '项目设置',mb_OK+MB_ICONinformation); abort; end;if MessageBox(self.Handle,pchar('你确定将'+trim(dbgrdh1.FieldColumns['项目名称'].DisplayText)+' 项目删除吗?'),'提示信息',MB_ICONQUESTION+MB_YESNO)=ID_YES then
begin str_sql := 'select fl from zd_flzd where flmc = ' + quotedstr(trim(dbgrdh1.FieldColumns['分类名称'].DisplayText)); with qry_alter do begin close; sql.clear; sql.add(str_sql); open; end; qry_alter.first; Fl := qry_alter.fieldbyname('fl').asstring; str_sql := 'delete from zd_gbxx where code = ' + quotedstr(trim(dbgrdh1.FieldColumns['编码'].DisplayText)) + ' and xm = ' + quotedstr(trim(dbgrdh1.FieldColumns['项目名称'].DisplayText)) + ' and fl = ' + quotedstr(Fl); with qry_alter do begin close; sql.clear; sql.add(str_sql); execsql; end; dxbrbtn34Click(Sender);//查询按钮5.设置保存按钮(save)
if edt_flmc.text = '' then
begin Application.MessageBox('分类名称不能为空!已取消。', '设置',mb_OK+MB_ICONinformation); abort; end; if edt_xm_2.text = '' then begin Application.MessageBox('项目名称不能为空!已取消。', '设置',mb_OK+MB_ICONinformation); abort; end;
if (edt_flmc.Text <> '') then
begin str_sql := 'select fl from zd_flzd where flmc = ' + quotedstr(trim(edt_flmc.text)); with qry_alter do begin close; sql.clear; sql.add(str_sql); open; end; qry_alter.first; Fl := qry_alter.fieldbyname('fl').asstring; str_sql := 'select code,xm from zd_gbxx where code = ' + quotedstr(Trim(edt_code.Text))+ ' and xm= '+ quotedstr(Trim(edt_xm.Text)); with qry_alter do begin close; sql.clear; sql.add(str_sql); open; end; if qry_alter.RecordCount >= 1 then begin Application.MessageBox('该项目已存在!已取消添加。', '设置',mb_OK+MB_ICONinformation); abort; end else if qry_alter.RecordCount = 0 then begin str_sql := 'insert into zd_gbxx(code,Fl,XM,DM,WBX) values(' + QuotedStr(Trim(edt_code.Text))+',' +QuotedStr(fl)+',' +QuotedStr(Trim(edt_XM_2.Text))+',' +QuotedStr(Trim(edt_DM.Text))+',' +QuotedStr(Trim(edt_wbx.Text)) + ')'; with qry_alter do begin Close; SQL.Clear; SQL.Add(str_sql); ExecSQL; end; end; dxbrbtn34Click(Sender);if alterflag = True then
begin if edt_flmc.text = '' then begin Application.MessageBox('分类名称不能为空!已取消。', '设置',mb_OK+MB_ICONinformation); abort; end; if edt_xm_2.text = '' then begin Application.MessageBox('项目名称不能为空!已取消。', '设置',mb_OK+MB_ICONinformation); abort; end; if (edt_flmc.Text <> '') then begin str_sql := 'select fl from zd_flzd where flmc = ' + quotedstr(trim(edt_flmc.text)); with qry_alter do begin close; sql.clear; sql.add(str_sql); open; end; qry_alter.first; Fl := qry_alter.fieldbyname('fl').asstring; str_sql := 'update zd_gbxx set code = ' + quotedstr(Trim(edt_code.Text)) + ' where fl = ' + quotedstr(fl) + ' and xm = ' + quotedstr(trim(dbgrdh1.FieldColumns['项目名称'].DisplayText)) + ' and DM = ' + QuotedStr(Trim(dbgrdh1.FieldColumns['拼音代码'].DisplayText)); with qry_alter do begin close; sql.clear; sql.add(str_sql); execsql; end; dxbrbtn34Click(Sender); end; end;6.设置取消按钮。
addflag := false;
alterflag := False; edt_code.Text := ''; edt_DM.Text := ''; edt_XM_2.Text := ''; edt_flmc.Text := ''; edt_wbx.Text := '';7.另一种添加,更改,删除的方法。利用parameters.parambyname('').value := ..
with adoquery do
begin close; sql.Clear; sql.Add('insert into gzyb (姓名,职务) values(:xm,:zw)'); Parameters.ParamByName('xm').Value:=trim(xmedit.Text); Parameters.ParamByName('zw').Value:=trim(zwedit.Text); execsql; showmessage('添加成功!'); xmedit.Text:=''; zwedit.Text:=''; end;try
with adoquery do begin close; sql.Clear; sql.Add('delete from gzyb where 姓名=:xm'); Parameters.ParamByName('xm').Value:=trim(xmedit.Text); execsql; showmessage('删除成功!'); xmedit.Text:=''; zwedit.Text:=''; end; except showmessage('删除失败!'); end;///
try
with adoquery do begin close; sql.Clear; sql.Add('update gzyb set 职务=:zw where 姓名=:xm'); Parameters.ParamByName('xm').Value:=trim(xmedit.Text); Parameters.ParamByName('zw').Value:=trim(zwedit.Text); execsql; showmessage('修改成功!'); xmedit.Text:=''; zwedit.Text:=''; end; except showmessage('修改失败!'); end;
本文转自鹅倌51CTO博客,原文链接: http://blog.51cto.com/kaixinbuliao/955993,如需转载请自行联系原作者