现在数据库表信息如下:
  部门编号      部门名称
    001        生产一部
    002        生产二部
    003        财务部
    004        开发部问题一:有一个员工录入界面,当在Edit1中录入部门编号001时,Edit2怎么直接赋值为"生产一部"?当在Edit1中录入部门编号003时,Edit2怎么直接赋值为"财务部"?
问题二:有一个部门信息录入界面,当在Edit1中录入003,Edit2中录入"企划部",但保存时检查到部门编号已使用到004(最大值),所以写为数据库的信息自动改为:部门编号005,部门名称"企划部",同时给出更改后的提示.

解决方案 »

  1.   


    produrce Tform1.Edit1keypress(sender as object,key :char);
    begin
      if key=#13 then //回车时触发
         edit2.text:=GetBM(edit1.text);
    end;
    funtion Tform1.GetBM(BMcode:string):string;
    begin
      result:='';
      with ADOQUERY1 do //
      begin
        close;
        sql.text :='select  部门名称 from TAB1 where  部门编号 ='''+BMcode+''''; 
        open;
        if recordcount>0 then
          result:= fields[0].asstring;
      end;
    end;问题二:那你这样还不如 部门编号 自动增加好了;
      

  2.   

    [Quote=引用 1 楼 youcunzai 的回复:]
    为什么我在Edit1中录入任何值时,Edit2中都是最后一个部门名称:"开发部"?                   //我用的是Table组件
      

  3.   

    produrce Tform1.Edit1keypress(sender as object,key :char);
    begin
      if key=#13 then //回车时触发
         edit2.text:=GetBM(edit1.text);
    end;
    funtion Tform1.GetBM(BMcode:string):string;
    begin
      result:='';
      with ADOQUERY1 do //
      begin
        close;
        sql.text :='select  部门名称 from TAB1 where  部门编号 ='''+BMcode+''''; 
        open;
        if recordcount>0 then
          result:= fields[0].asstring;
      end;
    end;
      

  4.   

    针对第二个问题,这个问题处理起来很简单,但代码比较烦琐.
    希望能对你有所帮助。
    produrce Tform1.Edit1keypress(sender as object,key :char);
    var
     OperType:string;
    begin
      OperType:='A';//当前记录本是新增状态
      if key=#13 then //回车时触发
         edit2.text:=GetBM(edit1.text,OperType);
    end;funtion Tform1.GetBM(BMcode:string;Opertype:String):string;
    begin
     // opertype='A' 新增状态
    //  opertype='E' 修改状态
      result:='';
      with ADOQUERY1 do //
      begin
        close;
        IF OperType='A' then
        sql.text :='select  部门名称 from TAB1 where  部门编号 ='''+BMcode+''''
        else
        sql.text :='select  部门名称 from TAB1 where  部门编号 ='''+BMcode+''''+' and 主键字段<>'+当前主键值
        open;
        if (recordcount>0)  then
           Result:=False
       else
           Result:=true;
     
      end;
    end;
      

  5.   

    funtion应该是Function,结果中间少了一个C,试了半天代码都不行!