package platform.view.build.system.manage.button;

import platform.view.build.form.control.Action;
import platform.view.build.system.manage.dao.*;
import platform.view.build.utils.*;

public class ButtonAction extends Action
{

     PtButtonBean ptbut = new PtButtonBean();
     PtResourceBean ptresBean = new PtResourceBean();

     public int doBusiness() {

          String maxCoun ="1";


            for (int i=0; i<this.req.getRecorderCount();i++ ){


                 ////////////////Çó³ö²Ëµ¥Ö÷½¡
                 maxCoun = Util.getFieldMax(this.dc,"BUTTONINDEX","ptbutton");

                 ptbut.setButtonindex(Integer.parseInt(maxCoun));


                 ptbut.setButtonid(this.req.getFieldValue(i,"buttonid"));
                 ptbut.setButtondesc(this.req.getFieldValue(i,"buttondesc"));
                 ptbut.setButtonlabel(this.req.getFieldValue(i,"buttonlab"));
                 ptbut.setParentbuttonid(this.req.getFieldValue(i,"parentbuttonid"));



                  if (ptbut.insert() <0){
                      this.res.setType(0);
                      this.res.setResult(false);
                      this.res.setMessage("Ìí¼ÓButtonÊ§°Ü");
                      return -1;
                  }


                   /////////////////Ìí¼Ó×ÊÔ´ÐÅÏ¢
                    ptresBean.setResid("b"+maxCoun);
                    ptresBean.setResdesc(this.req.getFieldValue("buttonlab"));
                    ptresBean.setParentresid("b"+this.req.getFieldValue("parentbuttonid"));
                    ptresBean.setResname(maxCoun);
                    ptresBean.setRestype("5");

                    if (ptresBean.insert() <0){
                        this.res.setType(0);
                        this.res.setResult(false);
                        this.res.setMessage("Ìí¼Ó×ÊÔ´Ê§°Ü");
                        return -1;
                   }

            }

            this.res.setType(0);
            this.res.setResult(true);
            this.res.setMessage("Ìí¼Ó¼ÇÂ¼³É¹¦");

            return 0;
   }

   ///////////////ÐÞ¸Ä
   public int editenum(){

          for (int i=0; i<this.req.getRecorderCount();i++ ){
               ptbut.setButtonid(this.req.getFieldValue(i,"buttonid"));
               ptbut.setButtondesc(this.req.getFieldValue(i,"buttondesc"));
               ptbut.setButtonlabel(this.req.getFieldValue(i,"buttonlab"));


                  if (ptbut.updateByWhere(" where (buttonindex='"+this.req.getFieldValue(i,"keycode")+"')") <0){
                       this.res.setType(0);
                       this.res.setResult(false);
                       this.res.setMessage("¸üÐÂ¼ÇÂ¼Ê§°Ü");
                       return -1;
                  }

                   /////////////////¸üÐÂ×ÊÔ´ÐÅÏ¢
                    ptresBean.setResdesc(this.req.getFieldValue(i,"buttonlab"));
                    ptresBean.setParentresid("b"+this.req.getFieldValue(i,"parentbuttonid"));

                    if (ptresBean.updateByWhere(" where (ResID='b"+this.req.getFieldValue(i,"keycode")+"')") <0){
                         this.res.setType(0);
                         this.res.setResult(false);
                         this.res.setMessage("¸üÐÂ×ÊÔ´Ê§°Ü");
                         return -1;
                    }

       }

       this.res.setType(0);
       this.res.setResult(true);
       this.res.setMessage("¸üÐÂ¼ÇÂ¼³É¹¦");

       return 0;
   }

   //////////////É¾³ý
   public int delenum(){
        for (int i=0; i<this.req.getRecorderCount();i++ ){

              //////////////É¾³ý½ÇÉ«×ÊÔ´¹ØÏµ
            this.dc.executeUpdate(" delete from  PTRoleRes where (ResID='b"+this.req.getFieldValue(i,"keycode")+"') ");

               ///////////////É¾³ý×ÊÔ´
            this.dc.executeUpdate(" delete from  ptresource where (ResID='b"+this.req.getFieldValue(i,"keycode")+"') ");


              //////////////////É¾³ý²Ëµ¥
             String SQLStr = "delete from PTButton where (buttonindex='"+this.req.getFieldValue(i,"keycode")+"')";
             int retcount =this.dc.executeUpdate(SQLStr);
             if (retcount <0){
                  this.res.setType(0);
                  this.res.setResult(false);
                  this.res.setMessage("É¾³ý¼ÇÂ¼Ê§°Ü");
                  return retcount;
             }

         }
         this.res.setType(0);
         this.res.setResult(true);
         this.res.setMessage("É¾³ý¼ÇÂ¼³É¹¦");
         return 0;

   }



}
