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... 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... 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
Fill zero in front of number
SQL Server:
  1. select replicate('0', (10-len('123')))+'123'
Oracle:
  1. SELECT LPad('123',10,'0') FROM dual
DB2:
  1. values char(repeat('0',10-length('123'))||'123',10)
DataList paging
  1. //利用PageDataSource來做分頁功能
  2. PagedDataSource pds = new PagedDataSource();
  3. //將PageDataSource綁定SqlDataSource
  4. pds.DataSource = SqlDataSource1.Select(DataSourceSelectArguments.Empty);
  5. pds.AllowPaging = true;
  6. // 分頁大小
  7. pds.PageSize = 6;
  8.  
  9. int PageIndex;
  10. //分頁參數
  11. if (!string.IsNullOrEmpty(Request.QueryString["Page"]) && int.TryParse(Request.QueryString["Page"], out PageIndex))
  12. {
  13.     PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
  14. }
  15. else
  16. {
  17.     PageIndex = 1;
  18. }
  19.  
  20. pds.CurrentPageIndex = PageIndex - 1;
  21.  
  22. // 最後一頁
  23. if (!pds.IsLastPage)
  24. {
  25.     hlNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(PageIndex + 1);
  26.     if (Request.QueryString["type"] != null) hlNext.NavigateUrl += "&type=" + Request.QueryString["type"];
  27. }
  28. else
  29. {
  30.     hlNext.Visible = false;
  31. }
  32.  
  33.  
  34. //將DataList綁定PageDataSource
  35. this.DataList1.DataSource = pds;
  36. this.DataList1.DataBind();
JTable : multi line cell
  1. table.getColumnModel().getColumn(i).setCellRenderer(new DefaultTableCellRenderer() {
  2.     @Override
  3.     public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
  4.         String v = (String) value;
  5.         String[] vs = v.split("\n");
  6.  
  7.         JPanel p = new JPanel(new GridLayout(vs.length, 1)) {
  8.             @Override
  9.             public void setForeground(Color fg) {
  10.                 for (int i = 0; i < getComponentCount(); i++) {
  11.                     getComponent(i).setForeground(fg);
  12.                 }
  13.                 super.setForeground(fg);
  14.             }
  15.  
  16.             @Override
  17.             public void setBackground(Color bg) {
  18.                 for (int i = 0; i < getComponentCount(); i++) {
  19.                     getComponent(i).setBackground(bg);
  20.                 }
  21.                 super.setBackground(bg);
  22.             }
  23.         };
  24.  
  25.         // 內容
  26.         for (String s : vs) {
  27.             JLabel l = new JLabel(s, JLabel.LEFT);
  28.             l.setOpaque(true);
  29.             p.add(l);
  30.         }
  31.         // 列高
  32.         table.setRowHeight(row, table.getRowHeight() * vs.length);
  33.  
  34.         // 顏色設定
  35.         p.setOpaque(true);
  36.         p.setBackground(Color.white);
  37.  
  38.         // 變更背景及字體 顏色同, 同時變更內部元件的顏色
  39.         if (isSelected) {
  40.             p.setBackground(UIManager.getColor("Table.selectionBackground"));
  41.             p.setForeground(UIManager.getColor("Table.selectionForeground"));
  42.         }
  43.  
  44.         if (hasFocus) {
  45.             p.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
  46.  
  47.             if (table.isCellEditable(row, column)) {
  48.                 p.setForeground(UIManager.getColor("Table.focusCellForeground"));
  49.                 p.setBackground(UIManager.getColor("Table.focusCellBackground"));
  50.             }
  51.         } else {
  52.             p.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
  53.         }
  54.  
  55.         return p;
  56.     }
  57. });
focus on validating
  1. function focusOnInvalidControl() {
  2.     for (var i = 0; i < Page_Validators.length; i++) {
  3.         if (!Page_Validators[i].isvalid) {
  4.             document.getElementById(Page_Validators[i].controltovalidate).focus();
  5.             return;
  6.         }
  7.     }
  8. }