⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pashostconfig.pas

📁 一个电力企业的后台管理程序
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  Actiondelete.enabled:=false;
  Actionappend.enabled:=false;
  statusbar.panels[0].text:='修改记录';
  If Assigned(tvstructure.Selected) then
    Begin
      SelNode:=tvstructure.Selected;
      streenode:=tvstructure.Selected;
      str1:=selnode.text;
      case selnode.Level of
        0: application.MessageBox('此操作违法','消息框',MB_ICONASTERISK+MB_OK);
        1: begin
             ed_hostname.readonly:=false;
             ed_hostname.text:=selnode.text;
             svarity:=ed_hostname.text;
             ed_hostname.setfocus;
             vselect:=11;
           end;
        2:  with DM_hostconfig.qryhostconfig do
              try
                begin
                  close;
                  sql.Clear;
                  strsql:='(select * from hostconfig where item =';
                  strsql:=strsql+#39+str1+#39+''+'and'+''+' hostname'+'='
                             +#39+selnode.parent.text+#39+')';
                  sql.Add(strsql);
                  open;
                  if recordcount>0 then
                     begin
                       ed_hostname.text:=fieldbyname('hostname').asstring;
                       ed_item.text:=fieldbyname('item').asstring;
                       ed_text.text:=fieldbyname('text').asstring;
                       mem_note.text:=fieldbyname('note').asstring;
                       ed_item.readonly:=false;
                       ed_text.readonly:=false;
                       mem_note.readonly:=false;
                       ed_item.readonly:=false;
                       ed_item.text:=selnode.text;
                       svarity:=ed_item.text;
                       ed_item.setfocus;
                       vselect:=12;
                     end;
                end;
              except
                 application.MessageBox('系统查询有误,请重试','消息框',MB_ICONASTERISK+MB_OK);
                 exit;
              end;
      end;
    end
  else application.MessageBox('必须选择要修改的虚拟主机名','消息框',
                                MB_ICONQUESTION+MB_OKCANCEL);
end;

procedure TFrm_hostconfig.ActionCancelExecute(Sender: TObject);
begin
  Actionappend.enabled:=true;
  Actiondelete.enabled:=true;
  Actionamend.enabled:=true;
  Actionsave.enabled:=false;
  Actioncancel.Enabled:=false;
  ed_hostname.text:='';
  ed_item.text:='';
  ed_text.text:='';
  mem_note.text:=''; 
end;

procedure TFrm_hostconfig.ActionsaveExecute(Sender: TObject);
var
  selnode,tempnode,strtreeNode:ttreenode;
  str1,str2,strname,stritem,strtext,strnote,StrSql:string;
  re:integer;
begin
  statusbar.panels[0].text:='存储改条记录';
  case vselect{全局变量} of
    10: begin
         if ed_hostname.text='' then
           begin
             application.MessageBox('主机名称不允许为空','消息框',MB_ICONSTOP+MB_OK);
             ed_hostname.SetFocus;
             exit;
           end    //判断主机名称
         else
           if ed_item.text<>'' then
             with DM_hostconfig.qryhostconfig do
               begin
                 str1:='select hostname,item from hostconfig where hostname=';
                 str1:=str1+#39+ed_hostname.text+#39;
                 str1:=str1+'and item=';
                 str1:=str1+#39+ed_item.text+#39;
                 try
                   close;
                   sql.Clear;
                   sql.add(str1);
                   open;
                 except
                   exit;
                 end;
                 if recordcount>0 then
                  begin
                    application.MessageBox('有相同的主机名与配置项','消息框',MB_ICONSTOP+MB_OK);
                    ed_item.text:='';
                    ed_item.SetFocus;
                    exit;
                  end;
               end
           else
             begin
               application.MessageBox('虚拟设备名称不允许为空','消息框',MB_ICONSTOP+MB_OK);
               ed_item.SetFocus;
               exit;
             end;   //判断虚拟主机名称
         If Assigned(tvstructure.Selected) then
           Begin
             SelNode:=tvstructure.Selected;
             tempnode:=tvstructure.Selected;
             //strtreeNode:=tvstructure.Selected;
             case tempnode.level of
               0:begin
                   re:=application.messagebox('是否确认上述信息','消息框',
                                        MB_ICONQUESTION+MB_OKCANCEL);
                   if re=1 then
                    with DM_hostconfig.qryhostconfig do
                      begin
                       strname:=ed_hostname.text;
                       stritem:=ed_item.text;
                       strtext:=ed_text.text;
                       strnote:=mem_note.text;
                       str1:='select hostname,item from hostconfig where hostname=';
                       str1:=str1+#39+ed_hostname.text+#39;
                       close;
                       sql.clear;
                       sql.add(str1);
                       open;
                       if recordcount>0 then
                         begin
                           strtreenode:=selnode.getFirstChild;
                           while ed_hostname.text<>strtreenode.text do
                             strtreenode:=strtreenode.GetNext;
                           tvstructure.items.addchild(strtreenode,stritem);
                         end
                       else
                         begin
                           tempnode:=tvstructure.items.addchild(selnode,strname);
                           if stritem<>'' then tvstructure.items.addchild(tempnode,stritem)
                           else  tempnode.free;
                         end;
                        try
                          begin
                            Close;
                            sql.clear;
                            StrSql:='insert hostconfig(hostname,item,text,note) values(';
                            strsql:=strsql+#39+strname+#39+','+#39+stritem+#39+
                                  ','+#39+strtext+#39+','+#39+strnote+#39+')';
                            sql.add(strsql);
                            Execsql;
                         end;
                       except
                         application.MessageBox('此操作发生错误请重试','消息框',MB_ICONSTOP+MB_OK);
                         exit;
                       end;
                      end
                   else ed_hostname.setfocus;
                 end;
               1: begin
                    re:=application.messagebox('是否确认上述信息','消息框',
                                        MB_ICONQUESTION+MB_OKCANCEL);
                    if re=1 then
                      with DM_hostconfig.qryhostconfig do
                        begin
                          strname:=ed_hostname.text;
                          stritem:=ed_item.text;
                          strtext:=ed_text.text;
                          strnote:=mem_note.text;
                          try
                            begin
                              Close;
                              sql.clear;
                              StrSql:='insert hostconfig(hostname,item,text,note) values(';
                              strsql:=strsql+#39+strname+#39+','+#39+stritem+#39+
                                        ','+#39+strtext+#39+','+#39+strnote+#39+')';
                              sql.add(strsql);
                              Execsql;
                           end;
                         except
                           application.MessageBox('此操作发生错误请重试','消息框',MB_ICONSTOP+MB_OK);
                           exit;
                         end;
                         tvstructure.items.addchild(selnode,stritem);
                        end
                    else ed_item.setfocus;
                  end;
           end;
        end;
     end;
  11: begin    //查询
       str2:='select hostname from hostconfig where hostname=';
       str2:=str2+#39+ed_hostname.text+#39;
       with DM_hostconfig.qryhostconfig do
           begin
             close;
             sql.Clear;
             sql.add(str2);
             open;
             if recordcount>0 then
               begin    //判断
                 application.MessageBox('有相同的主机名','消息框',MB_ICONSTOP+MB_OK);
                 ed_hostname.setfocus;
                 abort;
               end
             else
               begin   //保存
                 streenode.text:=ed_hostname.text;
                 str2:='update hostconfig set hostname=';
                 str2:=str2+#39+ed_hostname.text+#39;
                 str2:=str2+' where hostname=';
                 str2:=str2+#39+svarity+#39;  
                 with DM_hostconfig.qryhostconfig do
                  try
                    begin
                      close;
                      sql.Clear;
                      sql.add(str2);
                      ExecSQL;
                    end;
                  except
                    application.MessageBox('此操作发生错误请重试','消息框',MB_ICONSTOP+MB_OK);
                    exit;
                  end;
               end;
           end;
           vselect:=10;
      end;
  12: begin
        strname:=ed_hostname.text;
        str2:='select hostname,item from hostconfig where hostname=';
        str2:=str2+#39+ed_hostname.text+#39;
        str2:=str2+' and item=';
        str2:=str2+#39+svarity+#39;   showmessage(str2);
        with DM_hostconfig.qryhostconfig do
          begin
            close;
            sql.Clear;
            sql.Add(str2);
            open;
            if recordcount>0 then
              begin
                str2:='update hostconfig set item=';
                str2:=str2+#39+ed_item.text+#39+' ,text=';
                str2:=str2+#39+ed_text.text+#39+' ,note=';
                str2:=str2+#39+mem_note.text+#39+' where hostname=';
                str2:=str2+#39+ed_hostname.text+#39+' and item=';
                str2:=str2+#39+svarity+#39; showmessage(str2);  
                close;
                sql.clear;
                sql.Add(str2);
                ExecSQL;
                streenode.text:=ed_item.Text;
              end
            else
               application.MessageBox('此操作发生错误请重试','消息框',MB_ICONSTOP+MB_OK);
               exit;             
          end;
       end;
 end;
  ed_hostname.readonly:=true;
  ed_item.readonly:=true;
  ed_text.readonly:=true;
  mem_note.readonly:=true;
  vselect:=10;
  Actionappend.enabled:=true;
  Actiondelete.enabled:=true;
  Actionamend.enabled:=true;
  Actionsave.enabled:=false;
  Actioncancel.enabled:=false;
end;

procedure TFrm_hostconfig.ActionexitExecute(Sender: TObject);
begin
  close;
end;

procedure TFrm_hostconfig.ed_hostnameKeyPress(Sender: TObject;
  var Key: Char);
begin
  if key=#13 then ed_item.setfocus;
end;

procedure TFrm_hostconfig.ed_itemKeyPress(Sender: TObject; var Key: Char);
begin
  if key=#13 then ed_text.setfocus;
end;

procedure TFrm_hostconfig.ed_textKeyPress(Sender: TObject; var Key: Char);
begin
   if key=#13 then mem_note.setfocus;
end;

procedure TFrm_hostconfig.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  if screen.FormCount=2 then WebIsHide(0);
  Action:=CaFree;
  Frm_HostConfig:=nil;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -