Popular Posts
javax.net.ssl.SSLHandshakeException: Connection closed by peer in Android 5.0 Lollipop Recently, there is a error occurs when access website via ssl connection like below although it worked fine several days ago. // Enable SSL... Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i... Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement...
Stats
ServerControl : CGridView
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Web.UI.WebControls;
  6.  
  7. namespace Bruce.Web.Controls
  8. {
  9.     public class CGridView : GridView
  10.     {
  11.         private string _HoverRowStyle = "background-color:#C5DEFF;";
  12.         public string HoverRowStyle { get { return _HoverRowStyle; } set { this._HoverRowStyle = value; } }
  13.  
  14.  
  15.         protected override void OnRowDataBound(System.Web.UI.WebControls.GridViewRowEventArgs e)
  16.         {
  17.             if (e.Row.RowType == DataControlRowType.DataRow)
  18.             {
  19.                 //當滑鼠放上去的時候 先儲存目前行的背景顏色 並設定顏色
  20.                 e.Row.Attributes.Add("onmouseover", string.Format("this.setAttribute('currentStyle',this.style.cssText);this.style.cssText='{0}'", this.HoverRowStyle));
  21.                 //當滑鼠離開的時候 將背景顏色回存的以前的顏色
  22.                 e.Row.Attributes.Add("onmouseout", "this.style.cssText=this.getAttribute('currentStyle');");
  23.             }
  24.             base.OnRowDataBound(e);
  25.         }
  26.     }
  27. }
ServerControl : GridView Pager
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Drawing;
  8.  
  9. namespace Bruce.Web.Controls
  10. {
  11.     /// <summary>
  12.     /// GridViewPager 的摘要描述
  13.     /// </summary>
  14.     [ToolboxData("<{0}:GridViewPager ID=\"GridViewPager\" runat=\"server\"></{0}:GridViewPager>")]
  15.     public class GridViewPager : Control
  16.     {
  17.         #region 按鈕文字
  18.         private string _FirstPageText = "第一頁";
  19.         public string FirstPageText
  20.         {
  21.             get { return _FirstPageText; }
  22.             set { _FirstPageText = value; }
  23.         }
  24.         private string _PreviousPageText = "上一頁";
  25.         public string PreviousPageText
  26.         {
  27.             get { return _PreviousPageText; }
  28.             set { _PreviousPageText = value; }
  29.         }
  30.         private string _NextPageText = "下一頁";
  31.         public string NextPageText
  32.         {
  33.             get { return _NextPageText; }
  34.             set { _NextPageText = value; }
  35.         }
  36.         private string _LastPageText = "最後頁";
  37.         public string LastPageText
  38.         {
  39.             get { return _LastPageText; }
  40.             set { _LastPageText = value; }
  41.         }
  42.         #endregion
  43.  
  44.         /// <summary>
  45.         /// 使用圖示按鈕
  46.         /// </summary>
  47.         private bool _IsImageButton;
  48.         public bool IsImageButton
  49.         {
  50.             get { return _IsImageButton; }
  51.             set { _IsImageButton = value; }
  52.         }
  53.  
  54.         #region 按鈕圖示
  55.         private string _FirstPageImageUrl;
  56.         public string FirstPageImageUrl
  57.         {
  58.             get { return _FirstPageImageUrl; }
  59.             set { _FirstPageImageUrl = value; }
  60.         }
  61.         private string _PreviousPageImageUrl;
  62.         public string PreviousPageImageUrl
  63.         {
  64.             get { return _PreviousPageImageUrl; }
  65.             set { _PreviousPageImageUrl = value; }
  66.         }
  67.         private string _NextPageImageUrl;
  68.         public string NextPageImageUrl
  69.         {
  70.             get { return _NextPageImageUrl; }
  71.             set { _NextPageImageUrl = value; }
  72.         }
  73.         private string _LastPageImageUrl;
  74.         public string LastPageImageUrl
  75.         {
  76.             get { return _LastPageImageUrl; }
  77.             set { _LastPageImageUrl = value; }
  78.         }
  79.         #endregion
  80.  
  81.         /// <summary>
  82.         /// 使用下拉選單
  83.         /// </summary>
  84.         private bool _IsDropDownList;
  85.         public bool IsDropDownList
  86.         {
  87.             get { return _IsDropDownList; }
  88.             set { _IsDropDownList = value; }
  89.         }
  90.  
  91.         /// <summary>
  92.         /// 顯示頁碼個數
  93.         /// </summary>
  94.         private int _PagerRange = 3;
  95.         public int PagerRange
  96.         {
  97.             get { return _PagerRange; }
  98.             set
  99.             {
  100.                 if (value < 1)
  101.                 {
  102.                     _PagerRange = 1;
  103.                 }
  104.                 else if (value > 10)
  105.                 {
  106.                     _PagerRange = 10;
  107.                 }
  108.                 else
  109.                 {
  110.                     _PagerRange = value;
  111.                 }
  112.             }
  113.         }
  114.  
  115.         /// <summary>
  116.         /// 頁碼間隔
  117.         /// </summary>
  118.         private string _PagerPadding = "3px";
  119.         public string PagerPadding
  120.         {
  121.             get { return _PagerPadding; }
  122.             set { _PagerPadding = value; }
  123.         }
  124.  
  125.         /// <summary>
  126.         /// 文字顏色
  127.         /// </summary>
  128.         private Color _ForeColor;
  129.         public Color ForeColor
  130.         {
  131.             get { return _ForeColor; }
  132.             set { _ForeColor = value; }
  133.         }
  134.  
  135.         private Control indexer = new Control();
  136.         private GridView container;
  137.  
  138.         protected override void OnLoad(EventArgs e)
  139.         {
  140.             if (this.CheckContainer())
  141.             {
  142.                 this.Controls.Clear();
  143.                 #region 設定按鈕屬性
  144.                 if (IsImageButton)
  145.                 {
  146.                     ImageButton btnFirstPage = CreateImageButton("btnFirstPage",
  147.                         FirstPageText,
  148.                         "0",
  149.                         container.PageIndex > 0,
  150.                         this.FirstPageImageUrl);
  151.                     ImageButton btnPreviousPage = CreateImageButton("btnPreviousPage",
  152.                         PreviousPageText,
  153.                         (container.PageIndex - 1).ToString(),
  154.                         container.PageIndex - 1 >= 0,
  155.                         this.PreviousPageImageUrl);
  156.                     ImageButton btnNextPage = CreateImageButton("btnNextPage",
  157.                         NextPageText,
  158.                         (container.PageIndex + 1).ToString(),
  159.                         container.PageIndex + 1 < container.PageCount,
  160.                         this.NextPageImageUrl);
  161.                     ImageButton btnLastPage = CreateImageButton("btnLastPage",
  162.                         LastPageText,
  163.                         (container.PageCount - 1).ToString(),
  164.                         container.PageIndex + 1 < container.PageCount,
  165.                         this.LastPageImageUrl);
  166.  
  167.                     this.Controls.Add(btnFirstPage);
  168.                     this.Controls.Add(btnPreviousPage);
  169.  
  170.                     this.Controls.Add(this.indexer);
  171.  
  172.                     this.Controls.Add(btnNextPage);
  173.                     this.Controls.Add(btnLastPage);
  174.                 }
  175.                 else
  176.                 {
  177.                     LinkButton btnFirstPage = CreatePageButton("btnFirstPage",
  178.                         FirstPageText,
  179.                         "0",
  180.                         container.PageIndex > 0);
  181.                     LinkButton btnPreviousPage = CreatePageButton("btnPreviousPage",
  182.                         PreviousPageText,
  183.                         (container.PageIndex - 1).ToString(),
  184.                         container.PageIndex - 1 >= 0);
  185.                     LinkButton btnNextPage = CreatePageButton("btnNextPage",
  186.                         NextPageText,
  187.                         (container.PageIndex + 1).ToString(),
  188.                         container.PageIndex + 1 < container.PageCount);
  189.                     LinkButton btnLastPage = CreatePageButton("btnLastPage",
  190.                         LastPageText,
  191.                         (container.PageCount - 1).ToString(),
  192.                         container.PageIndex + 1 < container.PageCount);
  193.  
  194.                     this.Controls.Add(btnFirstPage);
  195.                     this.Controls.Add(btnPreviousPage);
  196.  
  197.                     this.Controls.Add(this.indexer);
  198.  
  199.                     this.Controls.Add(btnNextPage);
  200.                     this.Controls.Add(btnLastPage);
  201.                 }
  202.                 #endregion
  203.  
  204.                 if (IsDropDownList)
  205.                     this.RenderDrowDownListPager();
  206.                 else
  207.                     this.RenderPageNumbers();
  208.             }
  209.             base.OnLoad(e);
  210.         }
  211.  
  212.         /// <summary>
  213.         /// 位置錯誤時顯示錯誤訊息
  214.         /// </summary>
  215.         /// <param name="e"></param>
  216.         protected override void OnPreRender(EventArgs e)
  217.         {
  218.             if (!this.CheckContainer())
  219.             {
  220.                 this.Controls.Clear();
  221.                 Literal warming = new Literal();
  222.                 warming.Text = "<span style=\"color:red;\">Pager object must be in a GridView.<span>";
  223.                 this.Controls.Add(warming);
  224.             }
  225.             base.OnPreRender(e);
  226.         }
  227.  
  228.         /// <summary>
  229.         /// 檢查container
  230.         /// </summary>
  231.         /// <returns></returns>
  232.         private bool CheckContainer()
  233.         {
  234.             if (container == null)
  235.             {
  236.                 Control control = this;
  237.  
  238.                 while (control.Parent != null && !(control.Parent is GridView))
  239.                 {
  240.                     control = control.Parent;
  241.  
  242.                 }
  243.  
  244.                 if (control.Parent != null)
  245.                 {
  246.                     container = control.Parent as GridView;
  247.                     return true;
  248.                 }
  249.                 else
  250.                 {
  251.                     return false;
  252.                 }
  253.             }
  254.             else
  255.             {
  256.                 return true;
  257.             }
  258.         }
  259.  
  260.         /// <summary>
  261.         /// 建立圖形按鈕
  262.         /// </summary>
  263.         /// <param name="ID"></param>
  264.         /// <param name="AlternateText"></param>
  265.         /// <param name="CommandArgument"></param>
  266.         /// <param name="Visible"></param>
  267.         /// <param name="ImageUrl"></param>
  268.         /// <returns></returns>
  269.         private ImageButton CreateImageButton(string ID, string AlternateText, string CommandArgument, bool Visible, string ImageUrl)
  270.         {
  271.             ImageButton btn = new ImageButton();
  272.             btn.ID = ID;
  273.             btn.AlternateText = AlternateText;
  274.             btn.CommandArgument = CommandArgument;
  275.             btn.ImageUrl = ImageUrl;
  276.             btn.Visible = Visible;
  277.             btn.ImageAlign = ImageAlign.Middle;
  278.             btn.Click += PageButton_Click;
  279.             btn.Style["margin-left"] = this.PagerPadding;
  280.             btn.Style["margin-right"] = this.PagerPadding;
  281.             return btn;
  282.         }
  283.  
  284.         /// <summary>
  285.         /// 建立文字按鈕
  286.         /// </summary>
  287.         /// <param name="ID"></param>
  288.         /// <param name="Text"></param>
  289.         /// <param name="CommandArgument"></param>
  290.         /// <param name="Visible"></param>
  291.         /// <returns></returns>
  292.         private LinkButton CreatePageButton(string ID, string Text, string CommandArgument, bool Visible)
  293.         {
  294.             LinkButton btn = new LinkButton();
  295.             btn.ForeColor = this.ForeColor;
  296.             btn.ID = ID;
  297.             btn.Text = Text;
  298.             btn.CommandArgument = CommandArgument;
  299.             btn.Visible = Visible;
  300.             btn.Click += PageButton_Click;
  301.             btn.Style["margin-left"] = this.PagerPadding;
  302.             btn.Style["margin-right"] = this.PagerPadding;
  303.             return btn;
  304.         }
  305.  
  306.         /// <summary>
  307.         /// 處理頁碼
  308.         /// </summary>
  309.         private void RenderPageNumbers()
  310.         {
  311.             int start = Math.Max(0, this.container.PageIndex - this.PagerRange);
  312.             int end = Math.Min(this.container.PageCount - 1, this.container.PageIndex + this.PagerRange);
  313.             for (int i = start; i <= end; i++)
  314.             {
  315.                 if (== this.container.PageIndex)
  316.                 {
  317.                     Literal currentPage = new Literal();
  318.                     currentPage.Text = (+ 1).ToString();
  319.                     this.indexer.Controls.Add(currentPage);
  320.                 }
  321.                 else
  322.                 {
  323.                     this.indexer.Controls.Add(CreatePageButton("p" + i, (+ 1).ToString(), i.ToString(), true));
  324.                 }
  325.             }
  326.         }
  327.  
  328.         /// <summary>
  329.         /// 處理下拉選單
  330.         /// </summary>
  331.         private void RenderDrowDownListPager()
  332.         {
  333.             DropDownList ddl = this.indexer.FindControl("ddlPageSelector") as DropDownList;
  334.             if (ddl == null)
  335.             {
  336.                 ddl = new DropDownList();
  337.                 ddl.ID = "ddlPageSelector";
  338.                 ddl.AutoPostBack = true;
  339.                 ddl.SelectedIndexChanged += PageList_Select;
  340.  
  341.                 Literal txt = new Literal();
  342.                 txt.Text = "第";
  343.                 this.indexer.Controls.Add(txt);
  344.                 this.indexer.Controls.Add(ddl);
  345.                 txt = new Literal();
  346.                 txt.Text = "頁";
  347.                 this.indexer.Controls.Add(txt);
  348.             }
  349.  
  350.             if (ddl.Items.Count == 0)
  351.             {
  352.                 for (int i = 0; i < this.container.PageCount; i++)
  353.                 {
  354.                     ddl.Items.Add(new ListItem((+ 1).ToString(), i.ToString()));
  355.                 }
  356.             }
  357.             ddl.SelectedValue = this.container.PageIndex.ToString();
  358.         }
  359.  
  360.         /// <summary>
  361.         /// 換頁動作
  362.         /// </summary>
  363.         /// <param name="sender"></param>
  364.         /// <param name="e"></param>
  365.         protected void PageButton_Click(object sender, EventArgs e)
  366.         {
  367.             if (this.CheckContainer())
  368.             {
  369.  
  370.                 LinkButton btn = sender as LinkButton;
  371.                 if (btn != null)
  372.                     this.container.PageIndex = int.Parse(btn.CommandArgument);
  373.  
  374.                 ImageButton ibtn = sender as ImageButton;
  375.                 if (ibtn != null)
  376.                     this.container.PageIndex = int.Parse(ibtn.CommandArgument);
  377.             }
  378.         }
  379.         /// <summary>
  380.         /// 換頁動作
  381.         /// </summary>
  382.         /// <param name="sender"></param>
  383.         /// <param name="e"></param>
  384.         protected void PageList_Select(object sender, EventArgs e)
  385.         {
  386.             if (this.CheckContainer())
  387.             {
  388.                 DropDownList ddl = sender as DropDownList;
  389.                 this.container.PageIndex = int.Parse(ddl.SelectedValue);
  390.             }
  391.         }
  392.     }
  393. }
Eclipse axis sample
  1. package tw.gov.cp.sample;
  2.  
  3. import java.util.Scanner;
  4.  
  5. import org.apache.axis.message.MessageElement;
  6. import org.w3c.dom.Element;
  7.  
  8. import tw.gov.cp.gsp2.CP2ResponseOfRSResult;
  9. import tw.gov.cp.gsp2.GSP2_RS_Service_01Soap;
  10. import tw.gov.cp.gsp2.GSP2_RS_Service_01SoapProxy;
  11. import tw.gov.cp.gsp2.GSP2_RS_Service_01SoapStub;
  12.  
  13. public class AxisSample {
  14.  
  15.     /**
  16.      * @param args
  17.      * @throws Exception
  18.      */
  19.     public static void main(String[] args) throws Exception {
  20.         Scanner scanner = new Scanner(System.in);
  21.         // Get token1 by user input.
  22.         System.out.print("Enter token1 : ");
  23.         String token1 = scanner.next();
  24.         // Get service id by user input.
  25.         System.out.print("Enter service id : ");
  26.         String serviceId = scanner.next();
  27.  
  28.         GSP2_RS_Service_01SoapProxy proxy = new GSP2_RS_Service_01SoapProxy();
  29.         // Endpoint is defualt setted as
  30.         // 'http://www.xxx.xxx.tw/GSP2WS/RSMediator01.asmx'.
  31.         // For different endpoint. Use setEndpoint method or constructor to set
  32.         // new WSDL.
  33.  
  34.         GSP2_RS_Service_01Soap soap = proxy.getGSP2_RS_Service_01Soap();
  35.         GSP2_RS_Service_01SoapStub stub = (GSP2_RS_Service_01SoapStub) soap;
  36.         // Set toke1 and service id to soap header authorization
  37.         stub.setAuthHeader(token1, serviceId);
  38.  
  39.         // Get result from server.
  40.         CP2ResponseOfRSResult result = proxy.getProfileColumns();
  41.         System.out.printf("returned message : %s%n", result.getMessage());
  42.         System.out.printf("returned code : %d%n", result.getCode());
  43.         System.out.println();
  44.  
  45.         if (result.getResult() != null) {
  46.             MessageElement[] messages = result.getResult().getProfileCollection().get_any();
  47.             for (MessageElement msg : messages) {
  48.                 // key
  49.                 Element keyNode = ((MessageElement) msg.getFirstChild()).getAsDOM();
  50.                 // value
  51.                 Element valueNode = ((MessageElement) msg.getLastChild()).getAsDOM();
  52.                 // Print all return value
  53.                 System.out.printf("%s = %s%n", keyNode.getTextContent(), valueNode.getTextContent());
  54.             }
  55.         }
  56.     }
  57.  
  58. }
Eclipse Intellisense
Reference : 開啟Eclipse自動完成功能
String to byte array
string to byte array
  1. Encoding.UTF8.GetBytes(str);
byte array to string
  1. Encoding.UTF8.GetString(bytes);