<address id="ttjl9"></address>

      <noframes id="ttjl9"><address id="ttjl9"><nobr id="ttjl9"></nobr></address>
      <form id="ttjl9"></form>
        <em id="ttjl9"><span id="ttjl9"></span></em>
        <address id="ttjl9"></address>

          <noframes id="ttjl9"><form id="ttjl9"></form>

          XJ項目關于新增保險時輸入各類保險金額后計算總和插入到總費用后查詢顯示

          2019-7-31    seo達人

          如果您想訂閱本博客內容,每天自動發到您的郵箱中, 請點這里

          第一種情況
          新增框內既有各類保險金額,也有保險總費用。當輸入一類保險金額時,保險總費用自動累加顯示,點擊保存之后將所有數據插入數據庫。然后查詢查詢顯示在結果列表即可。如下圖:

          第一種情況可以在前端js中寫一個計費方法。獲取每個不同類的保險金額,值取到之后在點擊保存之前將變量中的值賦值給保險總費用,然后點擊保存。代碼如下(js中計費的方法寫在代碼一開始中的method{}中,也就是新增,查詢,刪除,修改下方即可):

          //計費方法
          Vehicle_sum:function(){
          var sum  = /^[0-9]\d{0,5}$/;
          var trafficCompulsoryInsuranceCost=$("#vehicleInsurance_add_trafficCompulsoryInsuranceCost").textbox('getValue');
          trafficCompulsoryInsuranceCost=parseInt(trafficCompulsoryInsuranceCost);
          if(!trafficCompulsoryInsuranceCost == ''){
          if(!sum.test(trafficCompulsoryInsuranceCost)){
          Message.error("請輸入正確的保險!");
          return;
          }
          }
          var commercialInsuranceCost=$("#vehicleInsurance_add_commercialInsuranceCost").textbox('getValue');
          commercialInsuranceCost=parseInt(commercialInsuranceCost);
          if(!commercialInsuranceCost == ''){
          if(!sum.test(commercialInsuranceCost)){
          Message.error("請輸入正確的保險!");
          return;
          }
          }
          var carrierInsuranceCost=$("#vehicleInsurance_add_carrierInsuranceCost").textbox('getValue');
          carrierInsuranceCost=parseInt(carrierInsuranceCost);
          if(!carrierInsuranceCost == ''){
          if(!sum.test(carrierInsuranceCost)){
          Message.error("請輸入正確的保險!");
          return;
          }
          }
          var vehicleAndVesselTaxCost=$("#vehicleInsurance_add_vehicleAndVesselTaxCost").textbox('getValue');
          vehicleAndVesselTaxCost=parseInt(vehicleAndVesselTaxCost);
          if(!vehicleAndVesselTaxCost == ''){
          if(!sum.test(vehicleAndVesselTaxCost)){
          Message.error("請輸入正確的保險!");
          return;
          }
          }
          var total = trafficCompulsoryInsuranceCost+commercialInsuranceCost+carrierInsuranceCost+vehicleAndVesselTaxCost;
          $("#vehicleInsurance_add_totalCost").textbox("setValue",total);
          },

          第二種情況
          新增的表單中只有各種類別的保險費用,并沒有保險費用合計的字段。意思是在新增時只輸入各種類別的保險金額,后臺拿到各種類型的保險金額之后,在后臺將各類保險金額累加,用set方法給totalcost(保險總費用)賦值,插入數據庫中。查詢是從數據庫查詢顯示在結果列表即可。如下圖


          第二種情況可以在后臺中寫一個計費的累加方法。用BigDecimal的add方法進行累加。首先實例化一個BigDecimal的對象totalCost,賦一個初始值為0,然后用保險的對象insurance的get方法獲取各種保險的金額,然后用totalCost.add方法將獲取每個不同類的保險金額一次加到totalCost中,然后將totalCost用insurance的set方法set到保險總費用的字段中,然后進行插入操作。代碼如下(后臺中計費的方法寫在Service中的新增方法中):

          /**
          * 車輛保險新增
          * 陳通
          * @param insurance
          * @param request
          * @return
          * @throws IOException
          */
          public Result insertVehicleInsurance(VehicleInsurance insurance,HttpServletRequest request) throws IOException{
          Result result = Result.getInstance();
          insurance.setKeyID(IDGenerator.uuid());
          //計費方法開始
          BigDecimal totalCost = new BigDecimal("0");
                  if(insurance.getTrafficCompulsoryInsuranceCost()!=null){
                  totalCost=totalCost.add(insurance.getTrafficCompulsoryInsuranceCost());
                  }
                  if(insurance.getCommercialInsuranceCost()!=null){
                  totalCost=totalCost.add(insurance.getCommercialInsuranceCost());
                  }
                  if(insurance.getCarrierInsuranceCost()!=null){
                  totalCost=totalCost.add(insurance.getCarrierInsuranceCost());
                  }
                  if(insurance.getVehicleAndVesselTaxCost()!=null){
                  totalCost=totalCost.add(insurance.getVehicleAndVesselTaxCost());
                  }
                  insurance.setTotalCost(totalCost);
                  //計費方法結束
          //插入車輛保險信息,返回受影響的行數
          int count=vehicleInsuranceDao.insertVehicleInsurance(insurance);
          //插入附件
          sysFileService.saveFile(insurance.getKeyID(), Enums.FILE_CATALOG.INSURANCEFILE.getValue(), request);
          if (count>0) {
          result.setFlag(true);
          result.setMessage("車輛保險新增成功!");
          }else{
          result.setFlag(false);
          result.setMessage("車輛保險新增失敗!");
          }
          return result;
          }

          以上是兩種計費方法(前臺和后臺)。
          --------------------- 
          作者:ct_?? 
          來源:CSDN 
          原文:https://blog.csdn.net/weixin_40418595/article/details/94736305 
          版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

          日歷

          鏈接

          個人資料

          藍藍設計的小編 http://www.syprn.cn

          存檔

          亚洲va欧美va天堂v国产综合