Popular Posts
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... Word break tag : <wbr/> (HTML5) The  HTML  <wbr>  tag  is  used  defines  a  potential  line  break  point  if  needed.  This  stands  for  Word  BReak. This  is  u... 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...
Stats
ServerControl : CGridView
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace Bruce.Web.Controls
{
    public class CGridView : GridView
    {
        private string _HoverRowStyle = "background-color:#C5DEFF;";
        public string HoverRowStyle { get { return _HoverRowStyle; } set { this._HoverRowStyle = value; } }


        protected override void OnRowDataBound(System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //當滑鼠放上去的時候 先儲存目前行的背景顏色 並設定顏色
                e.Row.Attributes.Add("onmouseover", string.Format("this.setAttribute('currentStyle',this.style.cssText);this.style.cssText='{0}'", this.HoverRowStyle));
                //當滑鼠離開的時候 將背景顏色回存的以前的顏色
                e.Row.Attributes.Add("onmouseout", "this.style.cssText=this.getAttribute('currentStyle');");
            }
            base.OnRowDataBound(e);
        }
    }
}
ServerControl : GridView Pager
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

namespace Bruce.Web.Controls
{
    /// <summary>
    /// GridViewPager 的摘要描述
    /// </summary>
    [ToolboxData("<{0}:GridViewPager ID=\"GridViewPager\" runat=\"server\"></{0}:GridViewPager>")]
    public class GridViewPager : Control
    {
        #region 按鈕文字
        private string _FirstPageText = "第一頁";
        public string FirstPageText
        {
            get { return _FirstPageText; }
            set { _FirstPageText = value; }
        }
        private string _PreviousPageText = "上一頁";
        public string PreviousPageText
        {
            get { return _PreviousPageText; }
            set { _PreviousPageText = value; }
        }
        private string _NextPageText = "下一頁";
        public string NextPageText
        {
            get { return _NextPageText; }
            set { _NextPageText = value; }
        }
        private string _LastPageText = "最後頁";
        public string LastPageText
        {
            get { return _LastPageText; }
            set { _LastPageText = value; }
        }
        #endregion

        /// <summary>
        /// 使用圖示按鈕
        /// </summary>
        private bool _IsImageButton;
        public bool IsImageButton
        {
            get { return _IsImageButton; }
            set { _IsImageButton = value; }
        }

        #region 按鈕圖示
        private string _FirstPageImageUrl;
        public string FirstPageImageUrl
        {
            get { return _FirstPageImageUrl; }
            set { _FirstPageImageUrl = value; }
        }
        private string _PreviousPageImageUrl;
        public string PreviousPageImageUrl
        {
            get { return _PreviousPageImageUrl; }
            set { _PreviousPageImageUrl = value; }
        }
        private string _NextPageImageUrl;
        public string NextPageImageUrl
        {
            get { return _NextPageImageUrl; }
            set { _NextPageImageUrl = value; }
        }
        private string _LastPageImageUrl;
        public string LastPageImageUrl
        {
            get { return _LastPageImageUrl; }
            set { _LastPageImageUrl = value; }
        }
        #endregion

        /// <summary>
        /// 使用下拉選單
        /// </summary>
        private bool _IsDropDownList;
        public bool IsDropDownList
        {
            get { return _IsDropDownList; }
            set { _IsDropDownList = value; }
        }

        /// <summary>
        /// 顯示頁碼個數
        /// </summary>
        private int _PagerRange = 3;
        public int PagerRange
        {
            get { return _PagerRange; }
            set
            {
                if (value < 1)
                {
                    _PagerRange = 1;
                }
                else if (value > 10)
                {
                    _PagerRange = 10;
                }
                else
                {
                    _PagerRange = value;
                }
            }
        }

        /// <summary>
        /// 頁碼間隔
        /// </summary>
        private string _PagerPadding = "3px";
        public string PagerPadding
        {
            get { return _PagerPadding; }
            set { _PagerPadding = value; }
        }

        /// <summary>
        /// 文字顏色
        /// </summary>
        private Color _ForeColor;
        public Color ForeColor
        {
            get { return _ForeColor; }
            set { _ForeColor = value; }
        }

        private Control indexer = new Control();
        private GridView container;

        protected override void OnLoad(EventArgs e)
        {
            if (this.CheckContainer())
            {
                this.Controls.Clear();
                #region 設定按鈕屬性
                if (IsImageButton)
                {
                    ImageButton btnFirstPage = CreateImageButton("btnFirstPage",
                        FirstPageText,
                        "0",
                        container.PageIndex > 0,
                        this.FirstPageImageUrl);
                    ImageButton btnPreviousPage = CreateImageButton("btnPreviousPage",
                        PreviousPageText,
                        (container.PageIndex - 1).ToString(),
                        container.PageIndex - 1 >= 0,
                        this.PreviousPageImageUrl);
                    ImageButton btnNextPage = CreateImageButton("btnNextPage",
                        NextPageText,
                        (container.PageIndex + 1).ToString(),
                        container.PageIndex + 1 < container.PageCount,
                        this.NextPageImageUrl);
                    ImageButton btnLastPage = CreateImageButton("btnLastPage",
                        LastPageText,
                        (container.PageCount - 1).ToString(),
                        container.PageIndex + 1 < container.PageCount,
                        this.LastPageImageUrl);

                    this.Controls.Add(btnFirstPage);
                    this.Controls.Add(btnPreviousPage);

                    this.Controls.Add(this.indexer);

                    this.Controls.Add(btnNextPage);
                    this.Controls.Add(btnLastPage);
                }
                else
                {
                    LinkButton btnFirstPage = CreatePageButton("btnFirstPage",
                        FirstPageText,
                        "0",
                        container.PageIndex > 0);
                    LinkButton btnPreviousPage = CreatePageButton("btnPreviousPage",
                        PreviousPageText,
                        (container.PageIndex - 1).ToString(),
                        container.PageIndex - 1 >= 0);
                    LinkButton btnNextPage = CreatePageButton("btnNextPage",
                        NextPageText,
                        (container.PageIndex + 1).ToString(),
                        container.PageIndex + 1 < container.PageCount);
                    LinkButton btnLastPage = CreatePageButton("btnLastPage",
                        LastPageText,
                        (container.PageCount - 1).ToString(),
                        container.PageIndex + 1 < container.PageCount);

                    this.Controls.Add(btnFirstPage);
                    this.Controls.Add(btnPreviousPage);

                    this.Controls.Add(this.indexer);

                    this.Controls.Add(btnNextPage);
                    this.Controls.Add(btnLastPage);
                }
                #endregion

                if (IsDropDownList)
                    this.RenderDrowDownListPager();
                else
                    this.RenderPageNumbers();
            }
            base.OnLoad(e);
        }

        /// <summary>
        /// 位置錯誤時顯示錯誤訊息
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreRender(EventArgs e)
        {
            if (!this.CheckContainer())
            {
                this.Controls.Clear();
                Literal warming = new Literal();
                warming.Text = "<span style=\"color:red;\">Pager object must be in a GridView.<span>";
                this.Controls.Add(warming);
            }
            base.OnPreRender(e);
        }

        /// <summary>
        /// 檢查container
        /// </summary>
        /// <returns></returns>
        private bool CheckContainer()
        {
            if (container == null)
            {
                Control control = this;

                while (control.Parent != null && !(control.Parent is GridView))
                {
                    control = control.Parent;

                }

                if (control.Parent != null)
                {
                    container = control.Parent as GridView;
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return true;
            }
        }

        /// <summary>
        /// 建立圖形按鈕
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="AlternateText"></param>
        /// <param name="CommandArgument"></param>
        /// <param name="Visible"></param>
        /// <param name="ImageUrl"></param>
        /// <returns></returns>
        private ImageButton CreateImageButton(string ID, string AlternateText, string CommandArgument, bool Visible, string ImageUrl)
        {
            ImageButton btn = new ImageButton();
            btn.ID = ID;
            btn.AlternateText = AlternateText;
            btn.CommandArgument = CommandArgument;
            btn.ImageUrl = ImageUrl;
            btn.Visible = Visible;
            btn.ImageAlign = ImageAlign.Middle;
            btn.Click += PageButton_Click;
            btn.Style["margin-left"] = this.PagerPadding;
            btn.Style["margin-right"] = this.PagerPadding;
            return btn;
        }

        /// <summary>
        /// 建立文字按鈕
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="Text"></param>
        /// <param name="CommandArgument"></param>
        /// <param name="Visible"></param>
        /// <returns></returns>
        private LinkButton CreatePageButton(string ID, string Text, string CommandArgument, bool Visible)
        {
            LinkButton btn = new LinkButton();
            btn.ForeColor = this.ForeColor;
            btn.ID = ID;
            btn.Text = Text;
            btn.CommandArgument = CommandArgument;
            btn.Visible = Visible;
            btn.Click += PageButton_Click;
            btn.Style["margin-left"] = this.PagerPadding;
            btn.Style["margin-right"] = this.PagerPadding;
            return btn;
        }

        /// <summary>
        /// 處理頁碼
        /// </summary>
        private void RenderPageNumbers()
        {
            int start = Math.Max(0, this.container.PageIndex - this.PagerRange);
            int end = Math.Min(this.container.PageCount - 1, this.container.PageIndex + this.PagerRange);
            for (int i = start; i <= end; i++)
            {
                if (i == this.container.PageIndex)
                {
                    Literal currentPage = new Literal();
                    currentPage.Text = (i + 1).ToString();
                    this.indexer.Controls.Add(currentPage);
                }
                else
                {
                    this.indexer.Controls.Add(CreatePageButton("p" + i, (i + 1).ToString(), i.ToString(), true));
                }
            }
        }

        /// <summary>
        /// 處理下拉選單
        /// </summary>
        private void RenderDrowDownListPager()
        {
            DropDownList ddl = this.indexer.FindControl("ddlPageSelector") as DropDownList;
            if (ddl == null)
            {
                ddl = new DropDownList();
                ddl.ID = "ddlPageSelector";
                ddl.AutoPostBack = true;
                ddl.SelectedIndexChanged += PageList_Select;

                Literal txt = new Literal();
                txt.Text = "第";
                this.indexer.Controls.Add(txt);
                this.indexer.Controls.Add(ddl);
                txt = new Literal();
                txt.Text = "頁";
                this.indexer.Controls.Add(txt);
            }

            if (ddl.Items.Count == 0)
            {
                for (int i = 0; i < this.container.PageCount; i++)
                {
                    ddl.Items.Add(new ListItem((i + 1).ToString(), i.ToString()));
                }
            }
            ddl.SelectedValue = this.container.PageIndex.ToString();
        }

        /// <summary>
        /// 換頁動作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void PageButton_Click(object sender, EventArgs e)
        {
            if (this.CheckContainer())
            {

                LinkButton btn = sender as LinkButton;
                if (btn != null)
                    this.container.PageIndex = int.Parse(btn.CommandArgument);

                ImageButton ibtn = sender as ImageButton;
                if (ibtn != null)
                    this.container.PageIndex = int.Parse(ibtn.CommandArgument);
            }
        }
        /// <summary>
        /// 換頁動作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void PageList_Select(object sender, EventArgs e)
        {
            if (this.CheckContainer())
            {
                DropDownList ddl = sender as DropDownList;
                this.container.PageIndex = int.Parse(ddl.SelectedValue);
            }
        }
    }
}
Eclipse axis sample
package tw.gov.cp.sample;

import java.util.Scanner;

import org.apache.axis.message.MessageElement;
import org.w3c.dom.Element;

import tw.gov.cp.gsp2.CP2ResponseOfRSResult;
import tw.gov.cp.gsp2.GSP2_RS_Service_01Soap;
import tw.gov.cp.gsp2.GSP2_RS_Service_01SoapProxy;
import tw.gov.cp.gsp2.GSP2_RS_Service_01SoapStub;

public class AxisSample {

    /**
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        // Get token1 by user input.
        System.out.print("Enter token1 : ");
        String token1 = scanner.next();
        // Get service id by user input.
        System.out.print("Enter service id : ");
        String serviceId = scanner.next();

        GSP2_RS_Service_01SoapProxy proxy = new GSP2_RS_Service_01SoapProxy();
        // Endpoint is defualt setted as
        // 'http://www.xxx.xxx.tw/GSP2WS/RSMediator01.asmx'.
        // For different endpoint. Use setEndpoint method or constructor to set
        // new WSDL.

        GSP2_RS_Service_01Soap soap = proxy.getGSP2_RS_Service_01Soap();
        GSP2_RS_Service_01SoapStub stub = (GSP2_RS_Service_01SoapStub) soap;
        // Set toke1 and service id to soap header authorization
        stub.setAuthHeader(token1, serviceId);

        // Get result from server.
        CP2ResponseOfRSResult result = proxy.getProfileColumns();
        System.out.printf("returned message : %s%n", result.getMessage());
        System.out.printf("returned code : %d%n", result.getCode());
        System.out.println();

        if (result.getResult() != null) {
            MessageElement[] messages = result.getResult().getProfileCollection().get_any();
            for (MessageElement msg : messages) {
                // key
                Element keyNode = ((MessageElement) msg.getFirstChild()).getAsDOM();
                // value
                Element valueNode = ((MessageElement) msg.getLastChild()).getAsDOM();
                // Print all return value
                System.out.printf("%s = %s%n", keyNode.getTextContent(), valueNode.getTextContent());
            }
        }
    }

}
Eclipse Intellisense
Reference : 開啟Eclipse自動完成功能
String to byte array
string to byte array
Encoding.UTF8.GetBytes(str);
byte array to string
Encoding.UTF8.GetString(bytes);