2018年3月9日 星期五

62進位 使用 Bigintger 轉 10進制 轉回 62進制

public String getNextsubDocNum(String docnum) throws Exception {
String[] evnval = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c",
"d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x",
"y", "z" }; // MAPPING   << 
String jonstr62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; // 對應 文字的數字

String rexStr = "^[\\w]+$"; // 驗證 字串 是否 是數字 與 英文

if (!Pattern.matches(rexStr, docnum)) {
return "0-ERROR FORMATE"; // 若不是指定的格式 則回傳
}

BigInteger bei_chu_shu = new BigInteger("0");
for (int i = 0; i < docnum.length(); i++) {
int cop = (docnum.length() - i) - 1; // 次方
int log = jonstr62.indexOf(docnum.charAt(i)); // 位數值
BigInteger id = new BigInteger("62").pow(cop);// 62進制 N 次方
bei_chu_shu = bei_chu_shu.add(new BigInteger(String.valueOf(log)).multiply(id)); // 算出 10進制
}

bei_chu_shu = bei_chu_shu.add(BigInteger.ONE); // 下一個值 +1
BigInteger chu_shu = new BigInteger("62"); // 準備 62進制
BigInteger yu = BigInteger.ZERO; //

String shang = "";// 商
String sum = "";// 最後顯示的結果

while (!bei_chu_shu.equals(BigInteger.ZERO)) {
yu = bei_chu_shu.divide(chu_shu);// 餘數=被除數 / 除數
shang = String.valueOf(yu.subtract(yu.subtract(bei_chu_shu.mod(chu_shu))));// 餘數
bei_chu_shu = yu;// 讓下次迴圈的 被除數= 目前的 餘數
sum = evnval[Integer.valueOf(shang)] + sum;// 答案
}

return sum;
} 

2018年2月6日 星期二

關於 使用JQUERY FILE UPLOAD 一次submit 上傳

 <!-- Fonts -->
<link href="../css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="../css/manage.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<link rel="stylesheet" href="../css/style.css">
<!-- CSS to style the file input field as button and adjust the Bootstrap progress bars -->
<link rel="stylesheet" href="../css/jquery.fileupload.css">
<!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included -->
<script src="../js/vendor/jquery.ui.widget.js"></script>
<!-- The Load Image plugin is included for the preview images and image resizing functionality -->
<script src="https://blueimp.github.io/JavaScript-Load-Image/js/load-image.all.min.js"></script>
<!-- The Canvas to Blob plugin is included for image resizing functionality -->
<script src="https://blueimp.github.io/JavaScript-Canvas-to-Blob/js/canvas-to-blob.min.js"></script>
<!-- Bootstrap JS is not required, but included for the responsive demo navigation -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
<script src="../js/jquery.iframe-transport.js"></script>
<!-- The basic File Upload plugin -->
<script src="../js/jquery.fileupload.js"></script>
<script src="../js/jquery.fileupload.js"></script>
<!-- The File Upload processing plugin -->
<script src="../js/jquery.fileupload-process.js"></script>
<!-- The File Upload image preview & resize plugin -->
<script src="../js/jquery.fileupload-image.js"></script>
<!-- The File Upload audio preview plugin -->
<script src="../js/jquery.fileupload-audio.js"></script>
<!-- The File Upload video preview plugin -->
<script src="../js/jquery.fileupload-video.js"></script>
<!-- The File Upload validation plugin -->
<script src="../js/jquery.fileupload-validate.js"></script>

 var filesList = new Array();
       $(function () {
           $('#fileupload').fileupload({
               autoUpload: false
           }).on('fileuploadadd', function (e, data) {
               data.context = $('<div/><br/>', { class: 'thumbnail pull-left' }).appendTo('#files');
               $.each(data.files, function (index, file) {
                   filesList.push(data.files[index]);
                   console.log("Added: " + data.files[index].name);
                   var node = $('<p/>').append($('<span/>').text(file.name).data(data));
                   node.appendTo(data.context);
               });
           }).on('fileuploadprocessalways', function (e, data) {
               var index = data.index,
                   file = data.files[index],
                   node = $(data.context.children()[index]);
               if (file.preview) {
                   node.prepend('<br>').prepend(file.preview);
               }
               if (file.error) {
                   node.append('<br>').append($('<span class="text-danger"/>').text(file.error));
               }
           }).prop('disabled', !$.support.fileInput)
               .parent().addClass($.support.fileInput ? undefined : 'disabled');
           
           $("#uploadform").submit(function(event) {
               if (filesList.length > 0) {
                   console.log("multi file submit");
                   event.preventDefault();
                   $('#fileupload').fileupload('send', {files: filesList})
                       .success(function (result, textStatus, jqXHR) { console.log('success'); })
                       .error(function (jqXHR, textStatus, errorThrown) { console.log('error'); })
                       .complete(function (result, textStatus, jqXHR) { 
                           console.log('complete: ' + JSON.stringify(result));
                           // window.location='back to view-page after submit?'
                       });
               } else {
                   console.log("plain default form submit");
               }
           });
       });

<form id="uploadform" method="POST" enctype="multipart/form-data">
 <span class="btn btn-success fileinput-button"> 
 <i class="glyphicon glyphicon-plus"></i> 
 <span>增加檔案</span> 
 <input id="fileupload" type="file" name="files" multiple="multiple">
 </span>
</form > 

2018年1月28日 星期日

關於 Spring 多筆上傳

HTML <form id="id" name="name" method="POST" enctype="multipart/form-data" > <input multiple="multiple" name="file" type="file" /> // </form> JAVA
import org.springframework.web.multipart.MultipartFile; 
import org.springframework.web.multipart.MultipartHttpServletRequest;

@RequestMapping(value = "/url/name", method = RequestMethod.POST)
public ModelAndView modthName(HttpServletRequest request, HttpServletResponse response,
@RequestParam String htmval) throws Exception {

MultipartHttpServletRequest reqfile = (MultipartHttpServletRequest) request;
List<MultipartFile> files = reqfile.getFiles("file");


}

2018年1月25日 星期四

關於 HTML EDIT Trumbowyg 的使用

官方網站
   HTML 元件 
   
        <script src="自訂位置/trumbowyg.min.js"></script> //主要的功能
        <script src="自訂位置/plugins/upload/trumbowyg.cleanpaste.min.js"></script> //乾淨的黏貼功能 
        <script src="自訂位置/plugins/upload/trumbowyg.pasteimage.min.js"></script> //貼上圖片功能 
        <script src="自訂位置/langs/zh_tw.min.js"></script> //在地化元件
        <body>
        <div id="htmEdit"></div>
   簡單的文件 自訂化

$('#htmEdit').trumbowyg(
   {
    lang : 'zh_tw', //設定繁體中文 需要另外引入 /TrumbowygHtmlEditorSrc/langs/zh_tw.min.js.....
    btns : [
      [ 'undo', 'redo' ], // 設定按鈕 
      [ 'formatting' ],
      [ 'strong', 'em', 'del' ],
      [ 'superscript', 'subscript' ],
      [ 'link' ],
      [ 'insertImage' ],
      [ 'justifyLeft', 'justifyCenter', 'justifyRight',
        'justifyFull' ],
      [ 'unorderedList', 'orderedList' ],
      [ 'horizontalRule' ], [ 'removeformat' ],
      [ 'fullscreen' ] ]
   //Focus on editor: tbwfocus 焦點  
   //Blur on editor: tbwblur 離開 焦點  
   }).on('tbwinit', function() { // 若是修改 內文 的update 使用 INIT EVENT
  //Keep 當前輸入的值 。  
  $('#htmEdit').trumbowyg('html', '${vo.content}'); //有資料 則顯示 
 });


2018年1月16日 星期二

關於 Jqery Ajax 參數 簡單說明

  

   $.ajax({
         url: "", //網址
         type: 'POST', // 預設為 get
         data: null, // 傳送檔案 
         async: false, //是否為同步
         cache: false, //是否可暫存
         dataType : "json", //回傳 檔案 型別
         contentType: false, // 設定使用原定的傳輸協定
         processData: false, // 傳送檔案是否為序列化資料
         success: function (data) { // 成功時
          alert(data.XXX);
          
         },
         error : function(jqXHR, textStatus, errorThrown) { //發生錯誤時
                alert("發生錯誤:" + errorThrown);
         },
          beforeSend:function(){ //送出前
        //alert('show londing');
  },
  complete:function(){//完成後 不管有無錯誤
       //alert('unshow londing');
  }

});

2016年8月21日 星期日

關於 PL SQL if 的結構

關於PLSQL  if 的結構
if v_var is not null and v_var = 'b' then 
 s_var := 1;
elsif v_var is not null and  v_var = 'c' then
s_var := 2;  else 
 s_var := 3; 
end if;

2016年8月15日 星期一

關於 oracle sql 的遞迴查詢

各個常常會愈到階層關係比如










這時候 可以使用 查詢
 

 -- 向上查詢階層
   select * from org o 
   start with o.id = 123
   connect by o.id = prior o.parent_id;

--  向下查詢階層
   select * from org o 
   start with o.id = 123
   connect by prior o.id = o.parent_id;

2016年8月10日 星期三

PLSQL使用字串執行SQL

PL SQL 針對字串執行 SQL有著 特定的語法  可以針對CODE 較小的對應表 使用。
   function F_GET_CODE_TABLE_DESC(i_sql varchar2) return varchar2 is 
   o_desc varchar2(1000) := 'select * from XX  WHERE c_id = :id';
   c_columnName number :=1000;
  begin
   -- into 查詢結果回傳
   execute immediate i_sql  into o_desc using c_columnName ;
  return o_desc ;
  end;

2016年8月2日 星期二

JAVA-String編碼轉換

字串UTF-8編碼 轉Byte 數較少 的編碼例如 Big5 編碼會有失真的問題,難字也有其困難完整的轉換,將字串重新放回Write 重寫 會是解
   
   public String Convertendcode(String content){
     ByteArrayInputStream bais = new ByteArrayInputStream(content.getBytes("utf-8"));
     BufferedReader br = new BufferedReader (new InputStreanReader(bais));
     ByteArrayOutputStream boas =new ByteArrayOutputStream ();
     OutputStreamWriter osw =new OutputStreamWriter(boas,"big5");
     String buffer = null;
     if ((buufer = br.readLine())!=null){
       osw.write(buufer);
     }
     osw.flush();
     return boas.toString("big5");
   }

2016年8月1日 星期一

javaScript replace-ALL

這個方法是利用正規劃,的方式  : /g 表示全域 所以可替換所有字串內容
   

var ns=s.replace(/\你要置換的字串/g,'');

2016年7月31日 星期日

Oracle SQL 查詢 Left join 針對右表條件

Oracle 查詢時,常常會使用到JOIN 但是 針對右表 的過濾條件
放置where 條件 會因為右表 不存在而導致 查詢 失敗。




    select * from a  left join b 
    on a.id = b.id 
    where a.c1 = 2 
    and b.c1 = 3 
    --查詢會造成B表的欄位不存在時,查詢會造成0結果 需特別改成,因為where語法,是用於LEFT JOIN 的結果過濾
    
    --以下查詢會依照 a表為主表 b表的過濾條件當成 join 條件
    select * from a left join b
    on a.id =b.id and b.c1 =3 
    where a.c1=2;
    

2016年7月27日 星期三

關於PLSQL日期工具


myear number;
mmonth number; 

myear := extract(month from to_date(obj,'yyyyMM')) -- 取出年
mmonth := extract(year from to_date(obj,'yyyyMM')) -- 取出月

2016年7月25日 星期一

JQuery 選擇器

取得所有 checkbox 選擇的長度   並且全部打勾 
 





取得查詢畫面查詢內容 可利用 下列 function 觸發可由按鈕進行觸發
 //取得checkbox  
 var checklength =  $("input[name='checkbox']:checked").length;
                    //intput :輸入型別
                    //name :名稱
                    //checked:動作 
                    //length:長度

  $("input[name='checkbox']:checked").each(function(){
     $(this).attr("checked",true);
  });
 //取得所有 有 checked 的按鈕checkbox
 //each() --每個

Qrcode 建立




使用Google zxing.EncodeHintType
 下載的Jar檔理論上只要下載core(核心就好)

package com.joey.test;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Hashtable;

import javax.imageio.ImageIO;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.CharacterSetECI;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;

public class Test {
 public static void main(String[] args){
  BufferedImage buggimg = new BufferedImage(1200, 1200, BufferedImage.TYPE_INT_RGB);
  //指定寫出的資料夾  可由設定檔設定 位置
  File outFule = new File("D:/Qrcode.png");
  //建立QRCODE 相關設定。
  Hashtable hitmap = new Hashtable();
  QRCodeWriter qrwrite = new QRCodeWriter();
  hitmap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
  //建立圖片的繪版
  Graphics2D g2d = buggimg.createGraphics();
  
  g2d.setColor(Color.WHITE);
  g2d.fillRect(0,0,1200,1200);
  g2d.setColor(Color.black);
   try {
   //取得圖片的 點 的大小 圖片大小設定 1200 1200 px s 圖片
   BitMatrix x = qrwrite.encode("yourMassage", BarcodeFormat.QR_CODE, 1200, 1200,hitmap);
   for(int i =0;i<1200;i++){
    for(int j=0;j<1200;j++){
     if(x.get(i, j)){
      g2d.fillRect(i, j, 1, 1);
     }
    }
   }
   //寫出圖片..
   ImageIO.write(buggimg,"png", outFule);
  } catch (Exception e) {
   e.printStackTrace();
  }


2016年7月24日 星期日

jQuery使用Selecter移動Option 內容。

//取得某Select 畫面所有的Option
function optionMoveAdd(移動的Val[]){
$('select[name="selectName"]').find('option').each(function(){
  ///簡易的畫面將所有的OPTION的內容一放到另一個 select  
   for(var i =0;i<obj.length;i++){
     if(obj[i]==$(this).val()){
       $('select[name="sourceSelect"]').append($(this));
      }
   }
 }

 }); }
function optionMovedlect(移動的Val[]){
$('select[name="selectName"]').find('option').each(function(){
  ///簡易的畫面將所有的OPTION的內容一放到另一個 select   
   for(var i =0;i<obj.length;i++){
     if(obj[i]==$(this).val()){
       $('select[name="sourceSelect"]').append($(this));
      }
   }
 }

 });
select 需要增加屬性  multiple="multiple"是可多選的意思  
size = 顯示 ---比數 
    
    
     //或許可加上增加或是刪除扭
    

2016年6月19日 星期日

第一隻Andorid

設定 Linear Layout 方向為垂直 設定物件的擺放為 置中
 
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    tools:context="com.example.test.MainActivity" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="328dp"
        android:layout_height="392dp"
        android:layout_margin="10sp"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10sp"
        android:layout_weight="0.16"
        android:src="@drawable/madoka" />

    <Button
        android:id="@+id/changeImge1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/changeImg" />

</LinearLayout>

建立自定意圖片res  的 drawable 資料夾放置圖片。

撰寫程式

imgview.getDrawable().getConstantState() == 取得目前這個畫面的圖片格式判斷現在的圖片。

public class MainActivity extends Activity {
 Button changeImgbutton;
 ImageView  imgview;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  changeImgbutton =  (Button)findViewById(R.id.changeImge1);
  imgview = (ImageView)findViewById(R.id.imageView1);
  changeImgbutton.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
    if(imgview.getDrawable().getConstantState().equals(getResources().getDrawable(R.drawable.madoka,getApplicationContext().getTheme()).getConstantState())){
     imgview.setImageResource(R.drawable.i55963);
    }else{
     imgview.setImageResource(R.drawable.madoka);
    }
   }
  } );
 }