近來向Open course學習,以下是關鍵字摘要。
權能區分
直的分層,橫的分科
坐井觀天
馬馬虎虎
碰碰運氣
策略:
1.成本領導(成本最低)
2.差異化領導
3.Focus領導
環境變動很快,組織配合環境重新設計組織架構。
組織設計
1.工作專業化 - 把一個工作打破分成細小工作。
2.部門化 [橫分科,直分層 (複雜度)]
3.指揮鏈
4.管轄幅度
5.集權
6.形式化
創新,變革 (Innovation and change)
溝通(聽說讀寫):意義的移轉與了解。
男:重視地位
女:重視連結
第一次溝通很重要,需要回饋。
要素:「天龍八部」
發訊者,訊息,編碼,管道
解碼,愛訊者,回饋,噪音
讀的原則:
Preview
Question
Read
State
Test
寫的原則:
Introduction : what, why
Method & Material : how
Results
Discussion
Appendix
聽的原則:
不要多話。
用自已的話說說看。
說的原則:
自信
使用麥克風
素材的準備
備忘錄
利用視覺效果
回答問題
準備1分鐘的自我介紹,250中文字,100英文字
6/08/2011
12/22/2010
冬至送湯圓
┴┬┴┬/ ̄\_/ ̄\
┬┴┬┴▏ ▏▔▔▔▔\ 冬至到 ..送湯圓..
┴┬┴/\ / ﹨
┬┴∕ / ) ╮╰╮ ╭ ╯╭╰╮
┴┬▏ ● ▏ ╮╰╮ ╭ ╯╭╰╮
┬┴▏ ▔█ ◥█□█□█□█◤
┴◢██◣ \__/ █○●○●○█
┬█████◣ / █○●○●○█
┴████████████◣ ◥█□█□█◤
◢████████████▆▄ ▆███▆
█◤◢██◣◥███████◤\
◥◢████ ██████◤ \
┴█████ █████◤ ﹨
┬│ │█████◤ ▏
┴│ │ ▏
┬∕ ∕
┬┴┬┴▏ ▏▔▔▔▔\ 冬至到 ..送湯圓..
┴┬┴/\ / ﹨
┬┴∕ / ) ╮╰╮ ╭ ╯╭╰╮
┴┬▏ ● ▏ ╮╰╮ ╭ ╯╭╰╮
┬┴▏ ▔█ ◥█□█□█□█◤
┴◢██◣ \__/ █○●○●○█
┬█████◣ / █○●○●○█
┴████████████◣ ◥█□█□█◤
◢████████████▆▄ ▆███▆
█◤◢██◣◥███████◤\
◥◢████ ██████◤ \
┴█████ █████◤ ﹨
┬│ │█████◤ ▏
┴│ │ ▏
┬∕ ∕
10/19/2010
vb.net限制輸入數字並只到小數點後2位
Private Sub txtRatio_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtRatio.KeyPress
'輸入為數字,小數點或backspace
If Char.IsDigit(e.KeyChar) Or e.KeyChar = "." Or e.KeyChar = Chr(8) Then 'Backspace:
'輸入的小數點為唯一
If e.KeyChar = "." And InStr(CType(sender, System.Windows.Forms.TextBox).Text, ".") > 0 Then
e.Handled = True
Else
'小數最多2位
If e.KeyChar <> Chr(8) And InStr(CType(sender, System.Windows.Forms.TextBox).Text, ".") > 0 Then
Dim sAry() As String = CType(sender, System.Windows.Forms.TextBox).Text.Split(".")
If sAry(1).Length >= 2 Then
e.Handled = True
Else
e.Handled = False
End If
Else
e.Handled = False
End If
End If
'輸入的負號是否在第一位
ElseIf e.KeyChar = "-" And CType(sender, System.Windows.Forms.TextBox).Text = "" Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Labels:
.net,
MS Visual Studio 2005,
vb
9/29/2010
SVN backup incremental
It is a simple way to backup svn project incremental.
In the console >
svnadmin dump _svn -r 25:125 --incremental > svnbackup_20100929.rev25_125.dump
In the console >
svnadmin dump _svn -r 25:125 --incremental > svnbackup_20100929.rev25_125.dump
Labels:
SVN backup
7/14/2010
Class for connection DB for .net 2.0
We always write some common code for any project. I share one of connecting MS SQL 2005.
This class help us to connect DB, show message on browser and export EXCEL file. We can insert, update, delete and query.
This class help us to connect DB, show message on browser and export EXCEL file. We can insert, update, delete and query.
' /**********************************************************************/
' /* System : */
' /* Sub System : */
' /* Module Name : */
' /* Description : */
' /* */
' /* Environment : Windows XP + MS Visual Studio 2005 */
' /* Transacion : None */
' /* Modification history */
' /* Date Label Editor Description */
' /* ========== ========== ========== ============================== */
' /* YYYY/MM/DD Author Create */
' /**********************************************************************/
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Data
Imports System.IO
Public Class clsDb
Public Shared _ConnStr As String = "Data Source=your server name; Initial Catalog=your catalog; User Id=account;Password=password; Min Pool Size=2; Max Pool Size=40;Pooling=true; Connect Timeout=60"
Private Shared _logPath As String = "logs.log"
Public Sub New(ByVal xmlPath As String)
'constructor
End Sub
'query data from MSSQL
Public Shared Function QueryRunSQL(ByVal sSQL As String) As DataSet
Return QueryRunSQL(sSQL, clsDb._ConnStr)
End Function
'query data from MSSQL
Public Shared Function QueryRunSQL(ByVal sSQL As String, ByVal sConnStr As String) As DataSet
Dim sqlConn As SqlConnection = New SqlConnection(sConnStr)
Dim sqlDapt As SqlDataAdapter
Dim scmd As String = ""
Dim dsSource As New DataSet
Try
sqlDapt = New SqlDataAdapter(sSQL, sqlConn)
sqlDapt.Fill(dsSource)
Catch ex As Exception
dsSource = ErrorData(ex.Message)
Finally
sqlConn.Close()
sqlConn.Dispose()
SqlConnection.ClearAllPools()
End Try
Return dsSource
End Function
'insert, update or delete data from MSSQL
Public Shared Function ExecuteRunSQL(ByVal sql As String) As Integer
Dim list As ArrayList = New ArrayList()
list.Add(sql)
Return ExecuteRunSQL(list)
End Function
'insert, update or delete data from MSSQL
Public Shared Function ExecuteRunSQL(ByVal list As ArrayList) As Integer
Return ExecuteRunSQL(list, clsDb._ConnStr)
End Function
'insert, update or delete data from MSSQL
Public Shared Function ExecuteRunSQL(ByVal list As ArrayList, ByVal sConnStr As String) As Integer
Dim iProcess As Integer = 0
Try
If list Is Nothing Then
Return False
End If
Dim conn As SqlConnection = New SqlConnection(sConnStr)
conn.Open()
Dim trx = conn.BeginTransaction()
Dim command As New SqlCommand
command.Connection = conn
command.Transaction = trx
Try
For Each sSql As String In list
command.CommandText = sSql 'sSql is "delete * from table where condition"
iProcess = command.ExecuteNonQuery()
Next
trx.Commit()
Catch ex As Exception
trx.Rollback()
conn.Close()
Throw ex
Finally
conn.Close()
End Try
Catch ex As Exception
Throw New Exception(ex.Message + Chr(10) + Chr(13) + ex.StackTrace, ex)
Finally
list = Nothing
End Try
Return iProcess
End Function
'sorting hashtable
Public Function SortHashtable(ByVal oHash As Hashtable) As DataView
Dim oTable As New Data.DataTable
oTable.Columns.Add(New Data.DataColumn("key"))
oTable.Columns.Add(New Data.DataColumn("value"))
For Each oEntry As Collections.DictionaryEntry In oHash
Dim oDataRow As DataRow = oTable.NewRow()
oDataRow("key") = oEntry.Key
oDataRow("value") = oEntry.Value
oTable.Rows.Add(oDataRow)
Next
Dim oDataView As DataView = New DataView(oTable)
oDataView.Sort = "value DESC, key ASC"
Return oDataView
End Function
Public Shared Sub MessageBox(ByVal pgMain As Page, ByVal msg As String)
Dim strScript As String = ""
Try
msg = msg.Replace("'", "\'")
msg = msg.Replace(vbCrLf, "\r\n")
msg = msg.Replace(vbLf, "\n")
msg = msg.Replace(vbCr, "\r")
msg = msg.Replace("\""", "\\""")
strScript += ""
If (Not pgMain.ClientScript.IsStartupScriptRegistered(pgMain.GetType(), "MessageBox")) Then
pgMain.ClientScript.RegisterStartupScript(pgMain.GetType(), "MessageBox", strScript)
End If
Catch ex As Exception
pgMain.Response.Write(ex.ToString())
End Try
End Sub
Public Shared Function ShowError(ByVal dsSource As DataSet) As String
Dim sError As String = ""
Try
Dim msg As String = ""
If dsSource.Tables.Count > 0 Then
Dim dtTempTable As DataTable = dsSource.Tables("ErrorMessage")
Dim iJ As Integer
If dtTempTable.Rows.Count > 0 Then
For iJ = 0 To dtTempTable.Rows.Count - 1
msg = dtTempTable.Rows(iJ).Item(0).ToString.Replace("'", "")
msg = msg.Replace("。", "!")
msg = msg.Replace(vbCrLf, "\r\n")
Next
End If
End If
sError = msg
Catch ex As Exception
WriteLog(ex.ToString, "Exception Handler", _logPath)
End Try
Return sError
End Function
Public Shared Function ErrorData(ByVal errorMessage As String) As DataSet
Dim dsSource As New DataSet
Dim dtNewTable As DataTable = New DataTable("ErrorMessage")
dtNewTable.Columns.Add("Message")
Dim dr As DataRow = dtNewTable.NewRow()
dr("Message") = errorMessage
dtNewTable.Rows.Add(dr)
dsSource.Tables.Add(dtNewTable)
Return dsSource
End Function
Public Shared Sub WriteLog(ByVal sErrorMessage As String, ByVal sWho As String, ByVal sFileName As String)
Dim sFile As String
If sFileName Is Nothing Then
sFile = ".\\commonLogs.log"
Else
sFile = sFileName
End If
Dim sLogWriter As IO.StreamWriter = New IO.StreamWriter(sFile, True, System.Text.Encoding.Default)
Try
sLogWriter.WriteLine("[" & Format(DateTime.Now, "yyyy-MM-dd HH:mm:ss") + " user:" + sWho + "] message: " + sErrorMessage)
sLogWriter.Close()
Catch ex As Exception
sLogWriter.WriteLine("[Exception" & Format(DateTime.Now, "yyyy-MM-dd HH:mm:ss") + " user:" + sWho + "] message: " + ex.ToString)
sLogWriter.Close()
Exit Sub
End Try
End Sub
'export to Excel file
Public Shared Function ExportToXls(ByVal dt As System.Data.DataTable, ByVal xlsPath As String) As Boolean
If xlsPath.Trim = "" Then Exit Function
Dim txtPath As String = Replace(xlsPath, ".xls", ".csv")
If File.Exists(txtPath) = True Then File.Delete(txtPath)
If File.Exists(xlsPath) = True Then File.Delete(xlsPath)
Dim oExcel As Object = CreateObject("Excel.Application")
GC.Collect() : GC.WaitForPendingFinalizers()
Try
'---------------------------------
'create header
'---------------------------------
Dim sb As New StringBuilder
Dim icount As Integer
Dim sColumn As String = ""
For icount = 0 To dt.Columns.Count - 1
sColumn += dt.Columns(icount).ToString + ","
Next
sb.Append(sColumn.TrimEnd(","))
sb.Append(Chr(13) + Chr(10))
'---------------------------------
'create data
'---------------------------------
If dt.Rows.Count > 0 Then
For Each dr As DataRow In dt.Rows
Dim en_data As IEnumerator = dt.Columns.GetEnumerator
While en_data.MoveNext
sb.Append(dr.Item(en_data.Current).ToString).Append(",")
End While
sb.Append(Chr(13) + Chr(10))
Next
End If
'out a text file
Dim sw As StreamWriter = New StreamWriter(txtPath, False, System.Text.Encoding.Unicode)
sw.WriteLine(sb.ToString)
sw.Flush()
sw.Close()
'out a excel file
oExcel.Visible = False : oExcel.DisplayAlerts = False
oExcel.Workbooks.OpenText(Filename:=txtPath, StartRow:=1, DataType:=1, _
TextQualifier:=1, ConsecutiveDelimiter:=False, TAB:=False, _
Semicolon:=False, Comma:=True, _
Space:=False, Other:=False, TrailingMinusNumbers:=True)
'oExcel.ActiveWorkbook.SaveAs(Filename:=xlsPath) 'output Excel file
Catch ex As Exception
ExportToXls = False
Throw New Exception(ex.ToString)
Finally
'If File.Exists(txtPath) = True Then File.Delete(txtPath) 'Del temp csv
oExcel.ActiveWorkbook.Close()
oExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
oExcel = Nothing
GC.Collect()
ExportToXls = True
End Try
Return ExportToXls
End Function
Public Shared Function Now() As String
Return Format(DateTime.Now, "yyyy-MM-dd HH:mm:ss").Replace("-", "_").Replace(" ", "_").Replace(":", "_")
End Function
End Class
Labels:
.net,
code,
MS Visual Studio 2005
3/24/2010
1/15/2010
1/07/2010
MS SQL 列出Table所有欄位
--列出Table所有欄位 SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE (TABLE_NAME = '[TableName]')
12/29/2009
比對並Update的SQL - MS SQL version
系統上線一陣子後因為資料日漸增多,我們會把資料切成online, offline的部分,有時會想將online更新到offline,這時我們把兩個Table的資料做比對,找出相同的資料後,更新offline。
使用下面的SQL可以更新offline資料。使用cursor。
使用下面的SQL可以更新offline資料。使用cursor。
DECLARE c Cursor FOR
select pd.tankid, pd.bodid, pd.sampletstamp
from newbod.dbo.tblQCThickMeasurements bod, ProcessData.dbo.tblQCThickMeasurements pd
where bod.tankid = pd.tankid
and bod.bodid = pd.bodid
and bod.sampletstamp = pd.sampletstamp
and pd.qualcopied = 0;
Open c;
IF (@@CURSOR_ROWS<>0) ---判斷cursor開啟狀況
BEGIN
DECLARE @tankId VARCHAR(50), @BodId VARCHAR(50), @sampleTS Datetime;
Fetch NEXT FROM c INTO @tankId, @BodId, @sampleTS;
While (@@FETCH_STATUS <> -1)--當陳述式失敗,或資料列超出結果集時停止迴圈
BEGIN
update ProcessData.dbo.tblQCThickMeasurements set
qualcopied=1
where tankid = @tankId
and bodid = @BodId
and sampletstamp = @sampleTS;
Fetch NEXT FROM c INTO @tankId, @BodId, @sampleTS;
END;
END;
CLOSE c;
DEALLOCATE c;
GO
比對並Update的SQL - Oracle version
系統上線一陣子後因為資料日漸增多,我們會把資料切成online, offline的部分,有時會想將online更新到offline,這時我們把兩個Table的資料做比對,找出相同的資料後,更新offline。
使用下面的SQL可以更新offline資料。
當條件上出現重覆資料時,Oracle就不允許update了,需要自已將重覆測試的資料過濾,自行update不重覆的資料,會使用到cursor如同下方SQL
使用下面的SQL可以更新offline資料。
update
(select ol.tank_id, ol.bod_id, ol.sampletstamp, ol.qualcopied
from hisadm.qc_cord_summ su, hisadm.qc_cord_summ_ol ol
where su.tank_id = ol.tank_id
and su.bod_id = ol.bod_id
and su.sampletstamp = ol.sampletstamp
and ol.qualcopied = 'F'
and ol.sampletstamp <> to_date('2009/7/26 11:32:00','yyyy/MM/dd HH24:MI:SS')
and ol.sampletstamp <> to_date('2009/12/8 19:17:00','yyyy/MM/dd HH24:MI:SS')) a set
a.qualcopied = 'T';
當條件上出現重覆資料時,Oracle就不允許update了,需要自已將重覆測試的資料過濾,自行update不重覆的資料,會使用到cursor如同下方SQL
declare cursor c is select ol.tank_id, ol.bod_id, ol.sampletstamp, ol.qualcopied
from hisadm.qc_cord_summ su, hisadm.qc_cord_summ_ol ol
where su.tank_id = ol.tank_id
and su.bod_id = ol.bod_id
and su.sampletstamp = ol.sampletstamp
and ol.qualcopied = 'F'
and ol.sampletstamp <> to_date('2009/7/26 11:32:00','yyyy/MM/dd HH24:MI:SS')
and ol.sampletstamp <> to_date('2009/12/8 19:17:00','yyyy/MM/dd HH24:MI:SS');
begin
for r_c in c loop
update hisadm.qc_cord_summ_ol a set
a.qualcopied = 'T'
where a.tank_id = r_c.tank_id
and a.bod_id = r_c.bod_id
and a.sampletstamp = r_c.sampletstamp;
end loop;
end;
12/28/2009
MS SQL 2000以下版本如何做出row_num的效果?
MS SQL 2005含以上的版本有個 row_number() 可以讓使用者容易的做查詢出的資料加上序號,可是MS SQL 2000就不支援了。
由於這樣的需求簡單寫了下方的code,可以做出序號效果,前題是id欄位是唯一。
由於這樣的需求簡單寫了下方的code,可以做出序號效果,前題是id欄位是唯一。
select (select count(1) from table1 c where c.id <= table1.id) as row_number, table1.* from table1
Labels:
code,
MS SQL 2000,
SQL
11/27/2009
Oracle 找出loss的數字序列
今日遇到個問題。
在table: pt_dltgls裡有location 1 ~ 500(符合條件的max location),其中有些location在輸入時漏掉了。所以要找出這裡漏掉的location,讓使用者來補回。
SQL做法:
1.Oracle語法列出1 ~ max location。
2.再minus現有的location,剩下的就是漏掉的location啦!~
Oracle SQL
ps:感謝同仁Aming大力幫忙,沒有Aming還真寫不出來呢~哈~
在table: pt_dltgls裡有location 1 ~ 500(符合條件的max location),其中有些location在輸入時漏掉了。所以要找出這裡漏掉的location,讓使用者來補回。
SQL做法:
1.Oracle語法列出1 ~ max location。
2.再minus現有的location,剩下的就是漏掉的location啦!~
Oracle SQL
Select level location from dual connect by level <= (select nvl(max(location), 0) from pt_dltgls where dp_lot_id='C9J04031' and gls_status='S') minus select distinct location from pt_dltgls t where dp_lot_id='C9J04031' and gls_status='S'
ps:感謝同仁Aming大力幫忙,沒有Aming還真寫不出來呢~哈~
11/25/2009
How to code a class in VB.net 2005
近幾年物件導向愈來愈熱門,每個語言的概念差不多但寫法都不一樣,那要怎麼寫一個VB.net的Class呢?
Imports Microsoft.VisualBasic
Imports System.Data.OleDb
Imports System.Data
Public Class Table
Private _name As String
Private _delSql As ArrayList
Private _dtDel As DataTable
Private _dsQry As DataSet
Public Sub New(ByVal name As String)
'constructor
Me._name = name
Me._delSql = New ArrayList()
End Sub
Public ReadOnly Property Name() As String
Get
Return _name
End Get
End Property
Public Property DataTable() As DataTable
Get
Return _dtDel
End Get
Set(ByVal value As DataTable)
_dtDel = value
End Set
End Property
Public Sub putDelSql(ByVal sSql As String)
If Not sSql Is Nothing Then
_delSql.Add(sSql)
End If
End Sub
Public Function getDelSql() As ArrayList
Return _delSql
End Function
Public Function getDelSql(ByVal i As Integer) As String
If i <= _delSql.Count - 1 Then
Return _delSql(i)
End If
Return Nothing
End Function
Public Property DataSetQry() As DataSet
Get
Return _dsQry
End Get
Set(ByVal value As DataSet)
_dsQry = value
End Set
End Property
End Class
11/17/2009
jQuery玩Ajax 後端服務由jsp提供
jQuery強大的支援Ajax呼叫與使用,可要怎麼做呢?
下面的例子要求使用者輸入姓名,使用者按下「Click Me」後,透過ajax機制傳送姓名給jsp程式,而jsp只是單純顯示出使用者所輸入的姓名而已。
Step by Step
1.import js檔。
2.body裡加上下方的tag
3.head裡加入下方的javascript
4.提供Ajax呼叫查詢後端資料的jsp
下面的例子要求使用者輸入姓名,使用者按下「Click Me」後,透過ajax機制傳送姓名給jsp程式,而jsp只是單純顯示出使用者所輸入的姓名而已。
Step by Step
1.import js檔。
2.body裡加上下方的tag
Loading......
3.head裡加入下方的javascript
4.提供Ajax呼叫查詢後端資料的jsp
<%@ page language="java" contentType="text/html; charset=BIG5"
pageEncoding="BIG5" import="java.util.*;"%>
<%
String gender = request.getParameter("gender");
String name = request.getParameter("name");
out.println((gender.equalsIgnoreCase("male")?"Mr.":"Mrs.") + " " + name);
out.println("Hello world! This message is posted by Server.");
%>
Labels:
Ajax,
code,
java,
javascript,
jQuery
用jQuery操作html Dom object
jQuery怎樣操作html dom呢?下面有個也是學著網上先進做的範例。
效果請參考
Step by Step
1.import js檔。
2.body裡加上下方的tag
3.head裡加入下方的javascript
效果請參考
Step by Step
1.import js檔。
2.body裡加上下方的tag
| jQuery DOM Operation | |
|---|---|
original |
3.head裡加入下方的javascript
Labels:
code,
dom,
javascript,
jQuery
First touch jQuery
jQuery是個javascript Library,讓程式人員寫較少的code完成所需功能。
官網:http://jquery.com/
官網說明:
jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.
下面是個簡單的例子,學著網上其它先進做出來的範例。
上方效果若看不到請參考
Step by Step
1.使用jQuery要先Download jQuery API,它是個javascript檔。有幾個版本。以jQuery 1.3.2為例
2.import js檔到html上。
3.在html的body裡加上下方的tag
4.html的head裡加入下方的javascript
官網:http://jquery.com/
官網說明:
jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.
下面是個簡單的例子,學著網上其它先進做出來的範例。
上方效果若看不到請參考
Step by Step
1.使用jQuery要先Download jQuery API,它是個javascript檔。有幾個版本。以jQuery 1.3.2為例
- jQuery Minified - 是去掉空白,註解的精簡版本,適用在上線的系統。
- jQuery Regular - 是標準版本,適用在開發時較容易觀看它原始的code。
2.import js檔到html上。
3.在html的body裡加上下方的tag
4.html的head裡加入下方的javascript
Labels:
code,
javascript,
jQuery
Object to XML by DOM API in Java
有時侯我們想要把java object轉成XML時會使用到的code,轉出來的xml約像下面的格式。
DOMtoXML.javaA12345 1 B12345 2 Iden123 李昭慶 d1 c1 1 1 1 d2 c2 2 2 2 d3 c3 3 3 3
/**
* Object output XML format by DOM.
*/
package com.iden.Dom;
import java.io.*;
import java.util.ArrayList;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.dom.DOMSource;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class DOMtoXML {
DOMtoXML(){}
public static void main(String[] args) {
DOMtoXML jt = new DOMtoXML();
Lot lot = new Lot("A12345", "1", "B12345", "2", "Iden123", "李昭慶");
lot.putGlass("d1", "c1", "1", "1", "1");
lot.putGlass("d2", "c2", "2", "2", "2");
lot.putGlass("d3", "c3", "3", "3", "3");
String xml = lot.genObjectToXML();
System.out.println(xml); //print the xml string
}
private String encoding(String s){
try {
return new String(s.getBytes(), "UTF-8"); //"ISO-8859-1"
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
}
class Lot {
DocumentBuilderFactory f;
DocumentBuilder b;
Document doc;
private String lotId1;
private String glsQty1;
private String lotId2;
private String glsQty2;
private String userId;
private String userName;
private ArrayList glasses;
Lot(String lotId1, String glsQty1, String lotId2, String glsQty2, String userId, String userName) {
this.glasses = new ArrayList();
this.lotId1 = lotId1;
this.glsQty1 = glsQty1;
this.lotId2 = lotId2;
this.glsQty2 = glsQty2;
this.userId = userId;
this.userName = userName;
f = DocumentBuilderFactory.newInstance();
try {
b = f.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
doc = b.newDocument();
}
public String genObjectToXML(){
try {
/*
* XML output format:
*/
Element root = doc.createElement(this.getClass().getSimpleName());
doc.appendChild(root);
Element e;
e = doc.createElement("lotId1");
root.appendChild(e);
e.appendChild(doc.createTextNode(this.lotId1));
e = doc.createElement("glsQty1");
root.appendChild(e);
e.appendChild(doc.createTextNode(this.glsQty1));
e = doc.createElement("lotId2");
root.appendChild(e);
e.appendChild(doc.createTextNode(this.lotId2));
e = doc.createElement("glsQty2");
root.appendChild(e);
e.appendChild(doc.createTextNode(this.glsQty2));
e = doc.createElement("userId");
root.appendChild(e);
e.appendChild(doc.createTextNode(this.userId));
e = doc.createElement("userName");
root.appendChild(e);
e.appendChild(doc.createTextNode(this.userName));
Element g, dpLot, cutLot, gId, location, orgLocation;
for(int i=0;i<glasses.size();i++){
Glass objG = (Glass)glasses.get(i);
g = doc.createElement("glass");
root.appendChild(g);
dpLot = doc.createElement("dpLotId");
g.appendChild(dpLot);
dpLot.appendChild(doc.createTextNode(objG.getDpLotId()));
cutLot = doc.createElement("cutLotId");
g.appendChild(cutLot);
cutLot.appendChild(doc.createTextNode(objG.getCutLotId()));
gId = doc.createElement("glsId");
g.appendChild(gId);
gId.appendChild(doc.createTextNode(objG.getGlsId()));
location = doc.createElement("location");
g.appendChild(location);
location.appendChild(doc.createTextNode(objG.getLocation()));
orgLocation = doc.createElement("orgLocation");
g.appendChild(orgLocation);
orgLocation.appendChild(doc.createTextNode(objG.getOrgLocation()));
}
TransformerFactory tf = TransformerFactory.newInstance();
Transformer m = tf.newTransformer();
DOMSource source = new DOMSource(doc);
ByteArrayOutputStream byte1 = new ByteArrayOutputStream();
StreamResult result = new StreamResult(byte1);
System.out.println("Encoding: " + m.getOutputProperty(OutputKeys.ENCODING));
m.setOutputProperty(OutputKeys.ENCODING, "BIG5");
m.transform(source, result);
return byte1.toString();
} catch (TransformerConfigurationException e) {
e.printStackTrace();
} catch (TransformerException e) {
e.printStackTrace();
}
return null;
}
public void putGlass(String dpLotId, String cutLotId, String glsId, String location, String orgLocation) {
if (dpLotId != null && cutLotId != null && glsId != null && location != null && orgLocation != null) {
Glass g = new Glass();
g.setDpLotId(dpLotId);
g.setCutLotId(cutLotId);
g.setGlsId(glsId);
g.setLocation(location);
g.setOrgLocation(orgLocation);
glasses.add(g);
}
}
class Glass {
private String dpLotId;
private String cutLotId;
private String glsId;
private String location;
private String orgLocation;
public String getGlsId() {
return glsId;
}
public void setGlsId(String glsId) {
this.glsId = glsId;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getDpLotId() {
return dpLotId;
}
public void setDpLotId(String dpLotId) {
this.dpLotId = dpLotId;
}
public String getCutLotId() {
return cutLotId;
}
public void setCutLotId(String cutLotId) {
this.cutLotId = cutLotId;
}
public String getOrgLocation() {
return orgLocation;
}
public void setOrgLocation(String orgLocation) {
this.orgLocation = orgLocation;
}
}
}
神眼三代與呼叫器無法同步解決法
話說媽媽的VIOS被偷兒光顧後,我們家裡就出現三隻神眼三代傳訊鎖了。有用過這隻的朋友都知道這隻鎖最重要的就是鎖體上鎖後會同步呼叫器,當有人打開車門或進入車內時,鎖體會大叫,呼叫器也會第一時間通知車主。
最近有一隻鎖體沒電了,我就依照著說明手冊步驟更換電池,測試時,鎖體打開到open再扣上C型扣,居然有兩個呼叫器都B一聲,同步開機了,糟了! 我再測試另一隻原來鎖體,打開再扣上C型扣,哇~都沒辦法同步配對的呼叫器了。(變成A鎖同步A呼叫器與B呼叫器,而B鎖沒有呼叫器能與它同步)
為了重新同步,打了通電話給神眼的經銷商,居然要我郵寄給他們重設,電話那頭說:「重設定呼叫器就可以了,跟你說你也不會做,寄回來我們重設就好。」
「哇咧~~我們家有三隻鎖耶! 那每次出問題時都寄回去,鎖體很重,郵寄費不低耶~~,重設呼叫器誰不會呀; 步驟說清楚我不就知道了嗎。」心裡OS。
不死心,再打一通給鎖的製造商-超安精密,電話是位聲音很好聽的小姐接聽,說明過鎖的狀況與問題後,她很熱心的解說重設步驟,是這樣低。
再一次謝謝超安,客服做的不錯哦~有你們的貼心,真好。
最近有一隻鎖體沒電了,我就依照著說明手冊步驟更換電池,測試時,鎖體打開到open再扣上C型扣,居然有兩個呼叫器都B一聲,同步開機了,糟了! 我再測試另一隻原來鎖體,打開再扣上C型扣,哇~都沒辦法同步配對的呼叫器了。(變成A鎖同步A呼叫器與B呼叫器,而B鎖沒有呼叫器能與它同步)
為了重新同步,打了通電話給神眼的經銷商,居然要我郵寄給他們重設,電話那頭說:「重設定呼叫器就可以了,跟你說你也不會做,寄回來我們重設就好。」
「哇咧~~我們家有三隻鎖耶! 那每次出問題時都寄回去,鎖體很重,郵寄費不低耶~~,重設呼叫器誰不會呀; 步驟說清楚我不就知道了嗎。」心裡OS。
不死心,再打一通給鎖的製造商-超安精密,電話是位聲音很好聽的小姐接聽,說明過鎖的狀況與問題後,她很熱心的解說重設步驟,是這樣低。
- 1.將無法同步的鎖體與呼叫器拿遠一點,離另外2隻鎖與呼叫器遠一點。
- 2.鎖體用key打開到open,C型扣扣回,B一聲,閃燈熄滅後,馬上再打開到open。
- 3.馬上按下呼叫器左鍵(解除鍵),按一下放開。
- 4.等一下,若成功,鎖會BBB之後閃爍,呼叫器也會B並且液晶上會有訊號格顯示。
再一次謝謝超安,客服做的不錯哦~有你們的貼心,真好。
11/10/2009
Java 自已動手寫log
不用log4j自已寫個簡單的log程式。
分檔規則是將log分年,月記錄,每天一個log檔,日子一久想查某一天的log也比較方便。
例如:2009年10月11月有log時,log分檔會像這樣。
Log class
分檔規則是將log分年,月記錄,每天一個log檔,日子一久想查某一天的log也比較方便。
例如:2009年10月11月有log時,log分檔會像這樣。
- /2009/10/
- 1.log
- 2.log
- 3.log
- 5.log
- ......
- /2009/11/
- 1.log
- 2.log
- 3.log
- .....
Log class
/*
* Log.java with encode
* for logging
*
* Created on 2009年10月16日
*
* @author Iden
*
****<< Modification Note >>
* Date PTS/PBR/PCR Label Editor Description
* ========== =============== ========== ========== ============================================================
* 2009/10/16 0.0.0.1 Iden create
*/
package com.iden.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.text.SimpleDateFormat;
public class Log {
private String filePath = ""; //directory path of Log
private String filePrefix = ""; //prefix name of log file
private String fileSubName = ""; //subname of log file
String curWorkingDir = System.getProperty("user.dir"); //User working directory
private String breakLine="\n";
private Object encoding;
private String encodingStr;
public Log(String path) {
this(path, "log", "UTF-8");
}
public Log(String path, String subname, Object encoding) {
this(path, "Log", subname, encoding);
}
public Log(String path, String prefix, String subname, Object encoding) {
if(encoding ==null)
new Exception("encoding is empth");
filePath = path;
filePrefix = prefix;
fileSubName = subname;
this.encoding = encoding;
}
/**
* Output the log file
* @param str
*/
public void write(String str) {
OutputStream stream = null;
Writer writer = null;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
try {
String folder = generateDirectory();
File file = new File(folder + filePrefix + "_" + getCurrYYYYMMDD() + "." + fileSubName);
StringBuffer sb = new StringBuffer("");
sb.append("[" + formatter.format(new java.util.Date()) + "] [start]" + breakLine)
.append(str)
.append(breakLine + "[end]" + breakLine);
stream = new FileOutputStream(file, true);
if (encoding instanceof Charset) {
writer = new OutputStreamWriter(stream, (Charset)encoding);
} else if (encoding instanceof CharsetEncoder) {
writer = new OutputStreamWriter(stream, (CharsetEncoder)encoding);
} else {
writer = new OutputStreamWriter(stream, (String)encoding);
}
OutputStreamWriter osw =(OutputStreamWriter)writer;
encodingStr = osw.getEncoding();
osw = null;
writer.write(sb.toString());
writer.flush();
writer.close();
} catch (java.io.FileNotFoundException efnf) {
writeException("FileNotFoundException at open log file: " + efnf.getMessage());
} catch (java.io.IOException exio) {
writeException("IOException at write log file: " + exio.getMessage());
} catch (java.lang.Exception e) {
writeException("Exception at write log file: " + e.getMessage());
} finally {
writer = null;
}
}
/**
* Output the log file with default encoding
* @param str
*/
public void writeDefaultEncode(String str) {
java.io.FileWriter fw = null;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
try {
String folder = generateDirectory();
fw = new java.io.FileWriter(folder + filePrefix + "_"
+ getCurrYYYYMMDD() + "." + fileSubName, true);
fw.write("[" + formatter.format(new java.util.Date()) + "] " + breakLine + "[start]" + breakLine);
fw.write(str);
fw.write(breakLine + "[end]" + breakLine);
fw.flush();
fw.close();
} catch (java.io.FileNotFoundException efnf) {
writeException("FileNotFoundException at open log file: " + efnf.getMessage());
} catch (java.io.IOException exio) {
writeException("IOException at write log file: " + exio.getMessage());
} catch (java.lang.Exception e) {
writeException("Exception at write log file: " + e.getMessage());
} finally {
fw = null;
}
}
/**
* Get the encoding string
*/
public String getEncoding(){
if(encodingStr != null)
return encodingStr;
return null;
}
/**
* Generate directory path
* @return
*/
private String generateDirectory() {
String folder = defineDirectoryName(filePath);
java.io.File file = new java.io.File(folder);
file.mkdirs();
return folder;
}
/**
* Define the directory path of Log. format is path\YYYY\MM
* @param path
* @return current directory path
*/
private String defineDirectoryName(String path) {
java.util.Calendar cal = java.util.Calendar.getInstance(java.util.Locale.TAIWAN);
String folder = path;
folder = folder + "\\" + String.valueOf(cal.get(java.util.Calendar.YEAR));
if (String.valueOf((cal.get(java.util.Calendar.MONTH) + 1)).length() == 1) {
folder = folder + "\\0" + String.valueOf((cal.get(java.util.Calendar.MONTH) + 1));
} else {
folder = folder + "\\" + String.valueOf((cal.get(java.util.Calendar.MONTH) + 1));
}
folder = folder + "\\";
return folder;
}
/**
* Get the current date. format is YYYYMMDD
* @return String of YYYYMMDD
*/
private String getCurrYYYYMMDD() {
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); //yyyy/MM/dd HH:mm:ss
return formatter.format(new java.util.Date());
}
/**
* Output Exception message from this object
* @param msg
*/
private void writeException(String msg){
new Log(this.curWorkingDir).write(msg);
}
}
訂閱:
文章 (Atom)