2012年12月26日 星期三

[學習] decimal 小數點位數 四捨五入

[SQL]
select round(1.5446,2)
1.5400

select round(round(1.5446,3),2)
1.5500

select CAST(1.5446 AS decimal(9,2))
1.54

select CAST(1.546 AS decimal(9,2))
1.55


*資料型態decimal
  -生產數、工作分鐘 

SELECT 生產數,工作分鐘,
生產數/工作分鐘*60,
Convert(Decimal(18,4),生產數/工作分鐘)*60,
floor(convert(decimal(18,4),生產數/工作分鐘)*60),
floor(生產數/工作分鐘*60),

Round(生產數/工作分鐘*60,1) AS 小數第1位,
Round(生產數/工作分鐘*60,4) AS 小數第4位,

(生產數/工作分鐘*60*10+0.5)/10,
FLOOR(生產數/工作分鐘*60*10+0.5)/10
FROM tblA



[ACCESS]

SELECT 生產數,工作分鐘,
 Round(生產數/工作分鐘*60,1),
 Int(CDBL(生產數/工作分鐘)*60*10+0.5)/10 ,
 Int((生產數/工作分鐘)*60*10+0.5)/10 
 FROM tblA

互相比對結果值(EXCEL)








[VB]
小數點表示法
^[0-9]+(.[0-9]{1,6})?$

通過
0
0.
0.0
0.123456
123456789.123456

-----------------

資料庫 insert 時,decimal型態自動進位(四捨五入)。
假設小位數到3,資料庫 decimal型態就必須設置小數點到3。
當然在程式設計時,也必須 decimal 型態 到小數點3。

-----------------

1. 整數以下四捨五入
     int(46410*0.05+0.5)=2321

2. 例 : 12.346 四捨五入至小數點以下一位
     int(12.346*10+0.5)/10=12.3

3. 例 : 12.346 四捨五入至小數點以下二位
     int(12.346*100+0.5)/100=12.35

參考:
浮點數計算結果更接近正解? 算錢用浮點,遲早被人扁

2012年12月25日 星期二

[SQL] bit欄位型態, 插入Insert 與 讀取Select的值為1與0, 而不是True與False...

insert/update:
資料必須為 1,0 而不是 True,False
Convert.ToInt16(CheckBox1.Checked)  轉換為 1,0

select:
資料會自動轉為 True,False

備註:
欄位 Uses , Char(255)
SELECT CASE Uses WHEN 'T' THEN true ELSE 'false'

參考:
bit和 bool的问题
SQL Server数据库中bit字段类型使用时的注意事项
boolean插入mysql中bit类型,读出来是false和true,但是用false查询用,是空的  <-- 要用 1,0 查詢
how-to-add-custom-checkbox-column-to-datagridview

Convert.ToBoolean

2012年12月24日 星期一

[除錯] 字串未被辨認為有效的 DateTime

說明:
當資料欄位型態為 DateTime ,而資料欄卻沒有資料 DBNull
取出資料存在陣列,其在陣列的值依然為 DBNull 而非 Empty
當DataBindSource某欄位其資料型態為DateTime
並且要將陣列 "日期資料 DBNull / Empty" 配置過去時
便會發生 Error Msg : 字串未被辨認為有效的 DateTime

解決方式:
塞入"無意義的"日期字串, 但未來要使用時必須判別說 "1900/1/1" 便是...
不一定是最好方法,評估一下便可適用專案解法...

                    If i = 58 OrElse i = 63 OrElse i = 66 Then
                        MsgBox(bs.Item(bs.Position)(i).ToString)
                        'MsgBox(bs.Item(bs.Position)(i).GetType.ToString)
                        'bs.Item(bs.Position)(i) = CDate(bsReset(i).ToString).Date
                        If bs.Item(bs.Position)(i).GetType.ToString = "System.DBNull" Then
                            'MsgBox("A")
                            bs.Item(bs.Position)(i) = "1900/01/01" '暫時的解法
                        Else
                            '
                            bs.Item(bs.Position)(i) = bsReset(i).ToString
                        End If
                        MsgBox(bs.Item(bs.Position)(i).ToString)
                    Else
                        bs.Item(bs.Position)(i) = bsReset(i).ToString
                    End If

正解:
控制項.DataBindings.Add 當繫結格式為 DateTime 時,可以輸入空白!

參考:
[SQLite]字串未被辨認為有效的 DateTime?
字串未被辨認為有效的DateTime
DateTime的的問題:字串為辯認為有效的DateTime。
字串轉DateTime的問題

[C#]
((DataRowView)bs_印字[bs_印字.Position])["MARK1"]

其它(日期)參考:
時間格式及方法運用
標準日期和時間格式字串
DateTime.GetDateTimeFormats 方法
DateTimeFormatInfo 類別
用DateTimeFormatInfo格式化日期时间(C#)
AM and PM with "Convert.ToDateTime(string)"
how get a.m. p.m. from DateTime?
自訂日期和時間格式字串
datetime.now first and last minutes of the day
SQL时间类型(DateTime)模糊查询及Between
善用 SQL Server 中的 CONVERT 函數處理日期字串
[SQL]使用BETWEEN要注意的地方
[筆記] SQL - between

2012年12月23日 星期日

[學習] CheckedChanged 與 CheckedStateChanged 的區別

CheckedChanged 
 True / False

CheckedStateChanged  
 CheckState.Indeterminate(會打勾 並且會有灰色網格背景)
      / CheckState.Unchecked / CheckState.Checked

事件觸發:
從控制項改變值 或 從程式改變值
兩者事件都會觸發


'做驗證時,千萬別用 CheckedChanged 與 CheckedStateChanged 會進入無窮迴圈XD
Private Sub CheckBox2_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles CheckBox2.Validating

     '實現VBA Method [Me.Undo()功能] (解釋--還原到先前的值!!)

     If Me.CheckBox2.CheckState = CheckState.Checked Then
          Me.CheckBox2.CheckState = CheckState.Unchecked
     Else
          Me.CheckBox2.CheckState = CheckState.Checked
     End If
End Sub

NOTE:
如同 TextBox2.undo

參考:
CheckBox.CheckedChanged 事件
CheckBox.CheckStateChanged 事件
checkedBox 属性checkedChanged与checkedStateChanged 区别
VB2010之十二: CheckBox控件

2012年12月20日 星期四

[技巧] DataGridView 實現 CurrentRow 上移 下移

After:


BeFore:



解決:
        bs.DataMember = "Head"
        bs.DataSource = Me.MyCallForm.DataGridView3.DataSource '另一個視窗的DGV3
        DataGridView1.DataSource = bs

(運用bindingsource)
With DataGridView1
     If .Rows.Count > 0 Then
          '到底了 沒辦法再往下移 so 跳開副程式
          If .CurrentRow.Index = .Rows.Count - 1 Then Exit Sub
                Dim a As String = Nothing
                '交換上下 Row的資料
                For i As Integer = 0 To .ColumnCount - 1
                    a = bs.Item(bs.Position + 1)(i).ToString
                    bs.Item(bs.Position + 1)(i) = bs.Item(bs.Position)(i).ToString
                    bs.Item(bs.Position)(i) = a
                Next
          'refresh DGV的資料
          .Refresh()
          'CurrentRow 位置 +1
          .CurrentCell = .Rows(bs.Position + 1).Cells(5)
     End If
End With


(運用datatable)
With DataGridView1
     If .Rows.Count > 0 AndAlso .CurrentRow IsNot Nothing Then
         If .CurrentRow.Index = 0 Then Exit Sub '到頂了 沒辦法再往上移 so 跳開副程式
         dr.ItemArray = DSquotation.Tables("Memo").rows(.CurrentRow.Index - 1).ItemArray
         DSquotation.Tables("Memo").rows(.CurrentRow.Index - 1).ItemArray = DSquotation.Tables("Memo").rows(.CurrentRow.Index).ItemArray
         DSquotation.Tables("Memo").rows(.CurrentRow.Index).ItemArray = dr.ItemArray
      End If

      .Refresh()
      .CurrentCell = .Rows(.CurrentRow.Index - 1).Cells("說明")
End With

參考:

DataGridView 控制項 (Windows Form)
C#中,DataGridView 有 Binding DataSource 的 Rows Add/ Remove 作法
C# Winform DataGridView实现行[Row]的上下移动........
BindingSource Methods
如何手動移動Datagridview的列
求 DataGridview Row 资料任意上下移动对调,该怎么解决
DataGridView手動新增、修改資料列
當控制項已繫結資料時 無法以程式設計的方式將資料列加入 DataGridView 的資料列集合
DataGridView加入欄位
[C#]DataGridView的RowChanged event

兩行 / 兩列 / 行與列 交換
有關資料表的排序問題
如何将DataTable中的某两行记录调换顺序?
dataTable交换两行数据
交换DataTable中的行列位置
DataTable实现列位置交换,用于SQL语句无法解决字段页面显示顺序问题

[C#]
((DataRowView)bs_印字[bs_印字.Position])["MARK1"]

(待運用...)
.select
.copyto

2012年12月17日 星期一

[學習] 字串處理, 切割與截取

取得 "(" 起始位置 index
InStr(ComboBox1.Text, "(")

EX: 123(456)
從字串左邊第一個位置開始截取 直到位置 InStr(ComboBox1.Text, "(") - 1
Microsoft.VisualBasic.Left(ComboBox1.Text, InStr(ComboBox1.Text, "(") - 1)
Result : 123

Microsoft.VisualBasic.Right(cbo_發文者.Text, cbo_發文者.Text.Length-InStr(cbo_發文者.Text, "(")).ToString().Trim(")")
Result : 456

參考:
Functions (Visual Basic)
字串處理
常用VB字串處理函數
字串處理函數
Visual Basic 2005 - 善用 StringBuilder 提升字串處理效率
戰鬥吧!打工戰士!身為工程師須具備的字串處理思維!
在一個字串中插入另一個字串
[C#]簡單快速將各種數值字數轉成數字(string to int)
[隨手筆記]C#字串中的Right方法

[SQL] 多欄位查詢


            Dim str As String = "select * from [A010詢價單資料表-表頭] Where 1=1"

            '選擇哪個查詢條件
            Select Case frm詢價單search.TabControl1.SelectedIndex
                Case 0 '一般
                    'SELECT         外調單號, 預訂交期
                    'FROM             E010外調訂單資料表明細
                    'WHERE         (DATEPART(yy, 預訂交期) = 2008) AND (DATEPART(mm, 預訂交期) = 8)
                    'ORDER BY  預訂交期

                    If frm詢價單search.TextBox1.Text <> "0" Then
                        '日期-年度
                        str = str + " and DATEPART(yy,日期) = " & _
                        frm詢價單search.TextBox1.Text.ToString & ""
                    End If

                    If frm詢價單search.ComboBox1.Text <> "0(全部)" Then
                        '日期-月份
                        str = str + " and DATEPART(mm,日期) = " & _
                        Microsoft.VisualBasic.Left(frm詢價單search.ComboBox1.Text, 2) & ""
                    End If

                    If frm詢價單search.ComboBox2.Text <> "0(全部)" Then
                        '業務員-編號
                        str = str + " and 業務員 = '" & _
                        Microsoft.VisualBasic.Left(frm詢價單search.ComboBox2.Text, InStr(frm詢價單search.ComboBox2.Text, "(") - 1) & "'"
                    End If

                Case 1 '依客戶編號
                    If frm詢價單search.ComboBox3.Text <> "0(全部)" Then
                        'Dim 客戶編號() As String = frm詢價單search.ComboBox3.Text.Split(frm詢價單search.ComboBox3.Text.Split, "(")
                        'str = str + " and 客戶編號 = '" & _
                        ' 客戶編號(0).Trim & "'"

                        str = str + " and 客戶編號 = '" & _
                        Microsoft.VisualBasic.Left(frm詢價單search.ComboBox3.Text, InStr(frm詢價單search.ComboBox3.Text, "(") - 1) & "'"
                    End If

                    '在之前有嚴格判別是否為日期格式 並且不是空白~~
                    If frm詢價單search.TextBox2.Text <> "" And frm詢價單search.TextBox3.Text <> "" Then
                        str = str + " and 日期 between '" & Format(CDate(frm詢價單search.TextBox2.Text), "yyyy/MM/dd") & "' and '" & Format(CDate(frm詢價單search.TextBox3.Text), "yyyy/MM/dd") & "'"
                    End If

                Case 2 '依客戶訂號
                    If Not String.IsNullOrEmpty(frm詢價單search.TextBox4.Text) Then
                        If frm詢價單search.CheckBox1.Checked = True Then
                            str = str + " and 客戶訂號 = '" & _
                            frm詢價單search.TextBox4.Text & "'"
                        Else
                            str = str + " and 客戶訂號 like '%" & _
                            frm詢價單search.TextBox4.Text & "%'"
                        End If
                    End If
                Case 3 '依單號
                    If Not String.IsNullOrEmpty(frm詢價單search.TextBox5.Text) Then
                        str = str + " and 詢價單號 = '" & _
                        frm詢價單search.TextBox5.Text & "'"
                    End If
            End Select

            'sqlQuery
            MsgBox(str)




參考:
[習題]給初學者的範例,多重欄位搜尋引擎 for GridView #1
[MySQL Note.] 資料庫查詢抱怨(刪除線)優化筆記
多欄位的搜尋引擎
改善SQL效能的寫法

[SQL] 判斷空白

select top 1 staff_sn from retainJob where staff_sn = e.staff_sn and endDate is null order by startDate DESC

參考:
MS SQL與Oracle判斷欄位是否為NULL的方法比較,COALESCE()、ISNULL()、NVL()
SQL COALESCE() Very Cool, But Slower Than ISNULL()
SQL - 使用 NULLIF
SQLServer 中的 ISNULL 和 NULLIF
SQL SERVER – Explanation and Comparison of NULLIF and ISNULL
ISNULL (Transact-SQL)
NULLIF (Transact-SQL)
SQL::CASE, NULLIF() and ISNULL()
Access中的IsNull()
在Access中,IsNull的作用僅僅是判斷是否為空值
不過Access還是有支援MS-SQL IsNull的相似指令碼,在Access是用 iif 替代..
Select iif(IsNull( express ), value1, value2 ) From TableName
語法說明,判斷express是否為空,若是空的回傳value1,反之則回傳value2

[SQL] 判斷日期


Dim str As String = "select * from [A010詢價單資料表-表頭] Where 1=1"

'選擇哪個查詢條件
Select Case frm詢價單search.TabControl1.SelectedIndex
     Case 0 '一般
            'SELECT         外調單號, 預訂交期
            'FROM             E010外調訂單資料表明細
            'WHERE         (DATEPART(yy, 預訂交期) = 2008) AND (DATEPART(mm, 預訂交期) = 8)
            'ORDER BY  預訂交期

      If frm詢價單search.TextBox1.Text <> "0" Then
          '日期-年度
           str = str + " and DATEPART(yy,日期) = " & _
           frm詢價單search.TextBox1.Text.ToString & ""
      End If

      If frm詢價單search.ComboBox1.Text <> "0(全部)" Then
            '日期-月份
             str = str + " and DATEPART(mm,日期) = " & _
             Microsoft.VisualBasic.Left(frm詢價單search.ComboBox1.Text, 2) & ""
      End If

........

參考:
MS-SQL時間格式一覽
MS SQL日期處理方法
MSSQL 抓取現在日期的函數
善用 SQL Server 中的 CONVERT 函數處理日期字串
SQL Server中使用convert转化长日期为短日期
sql使用convert转化长日期为短日期的总结
MS SQL 的datetime 格式轉換
MS SQL日期處理方法-整理(Date and Time Functions Tips)
SQL Server datetime LIKE select?
sql的between與查詢日期範圍
SQL between 日期范围
找出某個日期區間內的資料
各種日期時間計算
日期相減, 算出天數
計算日期的天數
計算兩個日期差距幾天
日期運算的小技巧整理(以起迄日期結束日期為例)
如何下日期相減後得到的是日期
SQL 日期的應用
在SQL中 得到日期 並格式化

TIPS-.NET DateTime Formating
Linq小技巧:日期處理

其它(日期)參考:
時間格式及方法運用
標準日期和時間格式字串
DateTime.GetDateTimeFormats 方法
DateTimeFormatInfo 類別
用DateTimeFormatInfo格式化日期时间(C#)
AM and PM with "Convert.ToDateTime(string)"
how get a.m. p.m. from DateTime?
自訂日期和時間格式字串
datetime.now first and last minutes of the day
SQL时间类型(DateTime)模糊查询及Between
善用 SQL Server 中的 CONVERT 函數處理日期字串
[SQL]使用BETWEEN要注意的地方
[筆記] SQL - between

[學習] 限制上傳的副檔名

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click

     Dim f As OpenFileDialog = New OpenFileDialog()
     f.Filter = "文件格式(*.pdf;*.doc;*.docx;*.ppt;*.pptx;*.xls;*.xlsx)|*.pdf;*.doc;*.docx;*.ppt;*.pptx;*.xls;*.xlsx"  '支援格式   'WMF   'ICO
     'f.Filter = "All   Image   Formats   (*.bmp;*.jpg;*.jpeg;*.gif;*.png;*.tif)| " & _
     '   "*.bmp;*.jpg;*.jpeg;*.gif;*.png;*.tif|Bitmaps   (*.bmp)|*.bmp| " & _
     '   "GIFs   (*.gif)|*.gif|JPEGs   (*.jpg)|*.jpg;*.jpeg|PNGs   (*.png)|*.png|TIFs   (*.tif)|*.tif|All   Files   (*.*)|*.* "

     f.FilterIndex = 1
     f.ShowDialog(Me)
     Me.txbPath.Text = f.FileName

     If Path.GetExtension(txbPath.Text.Trim) = ".pdf" OrElse Path.GetExtension(txbPath.Text.Trim) = ".doc" OrElse Path.GetExtension(txbPath.Text.Trim) = ".docx" OrElse Path.GetExtension(txbPath.Text.Trim) = ".ppt" OrElse Path.GetExtension(txbPath.Text.Trim) = ".pptx" OrElse Path.GetExtension(txbPath.Text.Trim) = ".xls" OrElse Path.GetExtension(txbPath.Text.Trim) = ".xlsx" Then
     'do nothing
     Else
          If txbPath.Text.Trim <> "" Then
               MsgBox("僅 圖片格式(*.pdf;*.doc;*.docx;*.ppt;*.pptx;*.xls;*.xlsx) 可上傳!!")
          End If
          Exit Sub
     End If

'限制檔案大小

'檔圖片轉檔 並縮圖 - 以減少儲存空間

     'MsgBox(Path.GetFileName(f.FileName)) 取得檔案名稱(含副檔名)
     'Path.GetExtension 取得副檔名
     'Me.PictureBox1.ImageLocation = Me.txbPath.Text '取得完整路徑
End Sub

Note:
除了前端判斷
後端也要判斷
小心偽裝的檔案


參考:
VS 2008
.Net 3.5

~~要如何限制上傳的副檔名~~
如何限制FileUpload的副檔名
怎么限制上传图片的格式和大小? - [Asp.net]
上傳檔案時,限制只能pdf、xls的副檔名
OpenFileDialog 元件常用屬性和方法
Path.GetExtension 方法
Path.GetExtension 获取扩展名
[ASP.NET]將上傳圖檔分成大小圖後存入資料庫
Use With statement with OpenFileDialog

[除錯] DataGridView SelectionChanged 點到表頭會出錯


'點到表頭會出錯
 If DataGridView1.CurrentRow.Index <> -1 Then

 End If

'改成
 If DataGridView1.CurrentRow IsNot Nothing Then

 Endif


'確定是否點選到DataGridView的某行資料列 [C#]
if (this.DataGridView.SelectedRows.Count != 0) {}


參考:
C# datagridview selectionchanged event error
You're likely getting this error because its trigger the event when it's not a valid selection (ie. -1) thus throwing this exception.
DataGridView - EditOnEnter

環境:
VS 2008
.Net 3.5

[SQL] 多欄位查詢結果合併成一個字串

同個Row的兩個欄位(或N個欄位) 使用+ 來連接成一個欄位!

sqlQuery1:
SELECT (e.zhFname+e.zhName) as zhName,(e.enName+'  '+e.enFname) as enName FROM table

顯示結果:
zhName = "志玲"
enName = "LiYin Lin"

sqlQuery2:
SELECT (convert(nvarchar(4),系統ID) + '(' + 系統名稱 + ')') as 系統 FROM [Usys系統別資料表] WHERE 系統ID <> 0

顯示結果:
系統 = 1(內銷業務管理)

Note:
若有某一欄位型態不是字串(EX:integer ,double, etc... 日期沒試過~)
就必須 (convert(nvarchar(10),系統ID) 轉成字串

假設原本資料庫設定為 int(4) 其可表示範圍為
 - 2,147,483,647 ~ 2,147,483,647 
0~4,294,967,295 兩者皆為10位數

故轉字串時 就必須設 nvarchar(10) OR varchar(10)
否則會產生溢位錯誤...

參考:
select firstname+lastname from tb1;
用  +  做連接
+ (字串串連) (Transact-SQL)
CONCAT( ) 的語法
SQL Server 2012 :認識 CONCAT 字串函數

M$ sqlserver 2005
SQL 語法如何將多欄位查詢結果合併成一個字串
如何將多行查詢結果合併成單一字串?
SQL指令— CONCAT(字符串连接函数)
SQL 合并字段、拼字段、把多个数值拼写成一个字段。

===================================================
不同ROW的同一個欄位運用 FOR XML PATH 來連接成一個欄位!

資料結構:

語法 FOR XML PATH 之後的資料:

  select [pro] from yiTest.dbo.person for xml path('');

  select [pro]+',' from yiTest .dbo.person for xml path('');

  SELECT
  (
  (SELECT ','+[pro]
  FROM [yiTest].[dbo].[person] t2
  --WHERE t2.id = t1.id
  FOR XML PATH('')
  )
  )as [pro]
  FROM
  [yiTest].[dbo].[person] t1

    SELECT
  (
  (SELECT ','+[pro]
  FROM [yiTest].[dbo].[person] t2
  WHERE t2.id = t1.id
  FOR XML PATH('')
  )
  )as [pro]
  FROM
  [yiTest].[dbo].[person] t1

  select id,name,
  (select ','+pro from yiTest .dbo.person t1 where t1.id = t2.id for xml path('')) pro
  from yiTest.dbo.person t2
  group by id,name

參考:
SQL SERVER 2005 以後才支援 FOR XML PATH
SQL SERVER 2012 以後微軟提供了 CONCAT函數 來實現此功能
Concatenate the values in a column in SQL Server 2000 and 2005
使用 PATH 模式
一秒看破 T - SQL 多筆欄位合併
SQL 合并多条记录为一条
[SQL]將多筆資料合併為一筆顯示(FOR XML PATH)
[SQL]將多筆資料同一欄位值合併
[SQL] 多筆資料合併為一筆
灵活运用 SQL SERVER FOR XML PATH
SQL Server 2005 “FOR XML PATH” Multiple tags with same name
[MS SQL]將多筆資料合併欄位,減少不必要的連線
將多筆相同鍵值的欄位內容合併
T-SQL多筆輸出資料合併單一欄位輸出
使用 MSSQL 打造仿 MySQL 的group_concat 函数的山寨版
SQL語法如何將直的資料做橫向的字串連結
mssql2005如何实现类似GROUP_CONCAT (my-sql) 的功能
GROUP_CONCAT In MS-SQL
Simulating group_concat MySQL function in Microsoft SQL Server 2005?
Emulating MySQL’s GROUP_CONCAT() Function in SQL Server 2005

FOR XML PATH 多筆資料合併為一筆
FOR XML PATH 多筆資料合併為一筆

其它參考:
動態將多筆資料的特定欄位依分隔符號組成字串
[SQL]利用UNION ALL整合統計合併資料
[Oracle]請問如果查詢條件無資料能否顯示筆數為 0 呢?
SQL不同TABLE相同欄位合併的方法
MS SQL多表查詢合併
SQL合併查詢?(超難)
[Oracle]多筆資料合併在同一列上
SQL2005/2008手工注入之批量爆数据for xml path

使用 PIVOT 和 UNPIVOT 讓資料多列變成一列
SQL - 使用 PIVOT
動態 PIVOT 陳述式:Dynamic PIVOT
SQL資料轉行
續:SQL 資料轉行

SQL SERVER 2000/2005 列转行 行转列

2012年12月14日 星期五

[除錯] 字串或二進位資料會被截斷


資料庫insert時,Error Msg:
1.字串或二進位資料會被截斷
2.數值對 Int32 而言太大或太小


資料庫欄位型態:
int(4)


解決程式:
'不能用CInt 因為超過最大值 會無法判斷 (因為無法轉成INT)
If CDec(C.Text.Trim) > 2147483647 Then
MsgBox("資料欄位不准許大於[2147483647]!!")
End If


參考:
字串或二进位资料会被截断。
如何快速得知"字串或二進位資料會被截斷"是哪個欄位長度不足??
字串或二進位資料會被截斷

2012年12月7日 星期五

[學習] 取得系統環境路徑 Fonts 並且判斷系統字型是否存在

問題:
得知應用程式所安裝的系統OS(Win32)下~
系統字型是否存在著型某種字型~

解決:
Imports System.IO
        '取得環境路徑 fonts 系統字型資料夾
        '.NET Framweork 4 版本之後 才有 fonts
        'Dim strAns As String = Environment.GetFolderPath(Environment.SpecialFolder.fonts)

        ' get parent of System folder to have Windows folder
        Dim dirWinFolder As DirectoryInfo = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.System))
        'DirectoryInfo dirWindowsFolder = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.System));

        ' Concatenate Fonts folder onto Windows folder.
        Dim strFontsFolder As String = Path.Combine(dirWinFolder.FullName, "Fonts")
        'string strFontsFolder = Path.Combine(dirWindowsFolder.FullName, "Fonts");

        'Results in full path e.g. "C:\Windows\Fonts"
        'MsgBox(dirWinFolder.Parent.Name) 'C:\
        'MsgBox(dirWinFolder.Name) 'Windows
        'MsgBox(strFontsFolder) 'C:\Windows\Fonts

        '判斷是否存在字型
        Dim strFullPath As String = strFontsFolder & "\dftt-b5.ttf"
        If File.Exists(strFullPath) Then
            'MsgBox("存在!")
        Else
            File.Copy(Application.StartupPath & "\dftt-b5.ttf", strFullPath)
        End If

備註:
因為系統載入後,當系統無應用程式所使用字型時。
即使將字型COPY到系統字型資料夾,應用程式依然是使用預設字型。
因為應用程式字型設定在於COPY之前。

第二次開始應用程式,程式才會真正LOAD到 dftt-b5.tff 字型檔。

解決辦法:
(1)在程式中解決? 如何在應用程式設置字型之前COPY到系統字型資料夾?
(2)將字型檔直接包在應用程式安裝檔,並指定字型安裝路徑為系統字型資料夾路徑。
    那路徑設定怎麼設定?
(3)解決(1)辦法...(不是很好的辦法)
    在COPY完成後,將所有使用到此字型的控制項 or others...
    其字型指為 dftt-b5.tff,還沒試,應該可行一 一?

參考:
VS 2008
.Net 3.5
Environment.GetFolderPath Method (Environment.SpecialFolder)
How to get the path to the Windows fonts folder?
How to get the path to the Windows fonts folder?
Finding Font Filename from Font Title
Font Installation (copying file into Fonts directory from server to user's machine)
copy a font file in my programm resources to windows fonts
How do I install a font on a user's machine in VB.NET so applications like Word can use it?
VB.NET修改host文件
获取ALL USER 的特殊目录的类
如何获取系统下字体的路径?
如何判断使用者电脑中系统字型大小?
查知目前系統字型大小?
抓系統字型設定問題
取得電腦內部所有安裝字型
程式的啟動與載入
c# 獲取相對路徑
取得目前執行程式的目錄

2012年12月5日 星期三

[技巧] 透過 Win32API 的 kernel32.dll 來讀寫ini文件(設定檔)

程式:DayActivateFormWinApp.exe
Imports System.Runtime.InteropServices
Imports System.Text
'主程式
Public Class Form1
    Public Shared AppIniPath = "C:\DayActivateFormWinApp.ini"

    Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.Click
        Win32API.EnumWindowsDllImport(New Win32API.EnumWindowsCallback(AddressOf FillActiveWindowsList), 0)
        Exit Sub

        Dim hwnd As IntPtr = Win32API.FindWindow("DayCensorWinApp.DayLigoMain", vbNullString)
        If hwnd = IntPtr.Zero Then
            MsgBox("Not found!")
        Else
            MsgBox("Found!")

            Win32API.WritePrivateProfileString("DayLigoMain", "程式ID", My程式ID, AppIniPath)
            Win32API.WritePrivateProfileString("DayLigoMain", "MySqlWhere", MySqlWhere, AppIniPath)

            Exit Sub
        End If
    End Sub
End Class

----分隔線----

Imports System.Runtime.InteropServices
Imports System.Text
' 用來包裝 Windows 32 API 常式和函式的類別。
Public Class Win32API

#Region "修改INI檔中內容"
    ''' <summary>
    ''' 修改INI檔中內容
    ''' </summary>
    ''' <param name="lpApplicationName">欲在其中寫入的節點名稱</param>
    ''' <param name="lpKeyName">欲設置的項名</param>
    ''' <param name="lpString">要寫入的新字串</param>
    ''' <param name="lpFileName">INI檔案名</param>
    ''' <returns>非零表示成功,零表示失敗</returns>
    <DllImport("kernel32")> _
    Public Shared Function WritePrivateProfileString(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
    End Function
#End Region

End Class

文件:DayActivateFormWinApp.ini
[DayLigoMain]
程式ID=19
MySqlWhere=3

參考:
VB.net INI 讀寫
VB.net GetPrivateProfileString WritePrivateProfileString 读写INI
[C#.Net]调用kernel32读写ini文件
[C++]WritePrivateProfileString function (Windows)
c# extern 关键字 和 kernel32.dll中的api:WritePrivateProfileString,GetPrivateProfileString
writeprivateprofilestring (kernel32)
getprivateprofilestring (kernel32)
啟動應用程式並且傳入參數

VB.Net 讀取 INI
VB.NET配置文件存储方案-ini文件及ini文件的读写方法
用 vb.net 读写 ini 文件

Ini 檔案的讀取與寫入類別

应用程序中使用配置档

2012年11月27日 星期二

[學習 ] 列舉表單上所有的控制項 列舉開啟的所有表單

當想一次完成某些控制項的(屬性)設定時。
        For Each Control As Windows.Forms.Control In Me.Controls
            If Control.GetType Is GetType(Button) Then
                Control.Enabled = False
                Control.Width = 200
            End If
        Next

        For Each Control As Windows.Forms.Control In Me.Controls
            If Control.GetType Is GetType(TextBox) Then
                Control.Enabled = False
                Control.Width = 200
            End If
        Next
,etc...

當想取得目前程式中所有被開啟的表單集合時。
        For Each frm As Form In My.Application.OpenForms
            MsgBox(frm.Name & "," & frm.Text)
        Next

之後就可以做你想做的運用了...
存取每個表單上的全域物件(或變數)。
ex:
if frm.Name = "form1" then .....
,etc...

備註:
如果某Control是停駐於另一個Control下
則用此方法會找不到
ex:TextBox1 停駐於 GroupBox1 下...
此時的方法只會顯示(查詢到) GroupBox
可參考 方法 或 更好的方法(待查)
[ASP.NET] 透析FindControl

參考:
[技巧] Controls.Find - 驗證篇

List Of ALL Controls In PROJECT - VB.Net
How to find all child controls from a starting control or form
Foreach Control in form, all the TextBoxes
How to recursively get all controls on a form in C#
How to get ALL child controls of a Windows Forms form
Foreach Every Control on all forms

[技巧] ReportViewer 超連結 Hyperlink 開啟本機檔案

Get Selected Value From ReportViewer via Hyperlink

CrystalReport 可直接在公式呼叫外部程式並傳入參數 或 直接開啟檔案 PDF WORD,etc...
formula = "C:\DAYLIGO\TEST\DayActivateFormWinApp.exe 21 " & LEFT(CSTR({RY010採購合同資料表.批號}),1)  & ""

ReportViewer 無法直接在公式呼叫外部程式 或 開啟檔案 PDF WORD,etc...
僅能超連結URL的網頁,所連結網頁會 GET/POST 接收參數!

或許 ReportViewer 有這樣的功能也說不定... 網路上也找的到相關的需求,但沒有解答!

解決方法:
    Private Sub ReportViewer1_Hyperlink(ByVal sender As System.Object, ByVal e As Microsoft.Reporting.WinForms.HyperlinkEventArgs) Handles ReportViewer1.Hyperlink
        '法一
        Dim aa As String = e.Hyperlink
        aa = aa.Replace("http://", "")
        aa = aa.Replace("/", " ")
        Shell("C:\Dayligo\TEST\DayActivateFormWinApp.exe " & aa, AppWinStyle.NormalFocus)
        'MsgBox(e.Hyperlink)
        e.Cancel = True

        '法二

        Dim bb As String = e.Hyperlink
        bb = bb.Replace("%20", " ")
        bb = bb.Replace("file:///", "")
        'MsgBox(e.Hyperlink)
        'MsgBox(bb)
        Shell(bb, AppWinStyle.NormalFocus)

        e.Cancel = True
    End Sub

'法一
在 report1.rdlc 將表格設定導覽,並指定到URL   ="http://19/" & Fields!sdid.Value
在 reporviewer1 運用 Hyperlink 事件,並取出 link 參數。
並在程式中解析~ 取出所要的參數。
19表示我要呼叫哪支程式(表單Form) 並傳入參數 sdid.Value

注意:
設定 enablehyperlinks = true
http:// <-- 這樣不會觸發連結事件
http://1/ <-- 這樣才會觸發連結事件



'法二
跳至URL:
="C:\Dayligo\TEST\DayActivateFormWinApp.exe 19 " & Fields!sdid.Value

開發工具:
VS2008
Framework3.5

參考:
如何获取ReportViewer呈现的报表中某单元格的值?
'Jump To' action with relative hyperlink
Hyperlink to a local file doesn't work
在ReportViewer中使用超链接(HyperLink)
啟動應用程式並且傳入參數

備註:
A組件下,某個視窗(水晶報表)
透過報表某欄位hyperlink開啟本地檔案DayActivateFormWinApp.exe (並且傳參數給本地檔案)
透過DayActivateFormWinApp.exe及接收的參數,再來呼叫A組件下的某支副程式
透過此支程式來呼叫B組件下,某個視窗(EX:個人資料檔案!!)
B組件依接到的參數顯示資料

2012年11月26日 星期一

[技巧] 判斷是否已開啟視窗

法一 - A、
只能在 父MDI [MAIN_ligoHRsys] 下運作! 當嵌入其它組件時,無法在其下 父MDI 下運算!
        '若表單已存在 則讓他為主要顯示表單
        If l_Frm IsNot Nothing Then

            For i As Integer = 0 To MAIN_ligoHRsys.FindForm().MdiChildren.Length - 1
                If frmText.Equals(MAIN_ligoHRsys.FindForm().MdiChildren(i).Text) Then
                    MAIN_ligoHRsys.FindForm().MdiChildren(i).Tag = 4
                    MAIN_ligoHRsys.FindForm().MdiChildren(i).Activate()
                    DirectCast(MAIN_ligoHRsys.FindForm().MdiChildren(i), Object).MyDataRequery(Nothing)
                End If
            Next
        End If


法一 - B、
當嵌入在任何組件時 在其 父MDI 下運作,必使用 Me.Parent 方可執行!
        '若表單已存在 則讓他為主要顯示表單
        If l_Frm IsNot Nothing Then

            For i As Integer = 0 To Me.Parent.FindForm().MdiChildren.Length - 1
                If frmText.Equals(Me.Parent.FindForm.MdiChildren(i).Text) Then
                    Me.Parent.FindForm.MdiChildren(i).Activate()
                    Me.Parent.FindForm.MdiChildren(i).Tag = 1
                    DirectCast(Me.Parent.FindForm().MdiChildren(i), Object).MyDataRequery(Nothing)
                End If
            Next
        End If


法二、
If My.Application.OpenForms.Item("FormName") IsNot Nothing Then
     'do something here 已經打開
Else
     'do something here 還沒打開
End If


法三、[C#]
            if (Application.OpenForms.OfType<frm力高裝箱明細列印作業>().Count() == 1)
                Application.OpenForms.OfType<frm力高裝箱明細列印作業>().First().Activate();
            else
            {
                frm裝箱明細列印作業 frm = new frm裝箱明細列印作業();
                frm.MdiParent = this.MdiParent;
                frm.Show();
            }   


參考:
[MSDN]Form.ActiveMdiChild 屬性
[MSDN]My.Application.OpenForms 屬性
VB.NET判断一个窗口是否打开的代码
[C#.NET] 如何 使用 WinForm 關閉 視窗 事件
C# WinForm 只允许运行一个实例 ,如果有就激活到前段
WinFrom 判断窗体是否已存在

2012年11月20日 星期二

[學習] 多使用者 處理 同一筆資料 防止 race condition

系統架構
User1(程式)
                            <--------->       SV1(WebService)       <--------->       SV2(DataBase)
User2(程式)
       .
       .
       .
UserN(程式)


 (強碰問題~ 幾乎很少發生!!)
1.(程式-產生序號 Fetch From DB & +1) ex: sn+=1
當多個user同時處理同一筆record時~~
在不違反商業邏輯狀態下,直接覆蓋(update)前者的資料~~
每個record都會有記錄欄位,記錄修改者是誰~~

2.(程式-產生序號 Fetch From DB & +1) ex: sn+=1
在user1處理A-record時 不讓其它user同時處理A-record

user1(程式) 發出個訊息(參數) 給 SV1
其它user處理record時 並先與SV1判斷是否同record
若是 則告知其它user 目前不能用

-但會有網路斷線問題~~
-故需要一個機制~~
-那便是一個處理record的時間~~
-並在n分鐘內不讓其它使用者處理同一筆record~~

時間可存在 DataBase(同一筆record的欄位) 或 SV1

參考:
用 SELECT ... FOR UPDATE 避免 Race condition
数据库插入,多人操作,如何能做到绝对不重复插入?
select 後 insert
競爭危害

2012年11月18日 星期日

[除錯] 轉換 expression 到資料型別 smalldatetime 時發生算術溢位錯誤


---Error Message----
1.INSERT INTO SQL SERVER時引發錯誤,SQL資料類型 smalldatetime
將 varchar 資料類型轉換成 smalldatetime 資料類型時,產生超出範圍的值

2.
轉換 expression 到資料型別 smalldatetime 時發生算術溢位錯誤
轉換 nvarchar 到資料型別 smalldatetime 時發生算術溢位錯誤
,etc...




資料庫欄位型態為 datetime or smalldatetime
程式 insert 時,必須注意日期規則是否溢位

Ex:
一月份最大日期為31日
此時 insert 32 便會 error


解決辦法(1)--  
其實用 ISDate() 最準 
接受輸入格式 
(1)12-24 (自動加入今年)
(2)12-01-01 ,  2013-1-1,
(3)2011/1/1 ,  2012/01/12
(4)12/1-01 


在 insert 前判別規則
ex: 正規化表示法
If Not Regex.IsMatch(C.Text.Trim, "^((19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01]))*$") Then
   'do something
End



解決辦法(2)--
將資料庫 欄位型態 改為 varchar / nvarchar


溢位是因為期中有NULL值或空白值 

解決辦法(3)--
WHERE下條件
where date <> "" and date is not null 或是 where isdate(date)

NOTE:
一、IsDate() 有效日期的範圍是介於西元 100 年 1 月 1 日與西元 9999 年 12 月 31 日之間;其有效範圍會因作業系統而有所差異。

二、
smalldatetime 有效時間範圍 1900/1/1~2079/6/6
datetime 有效時間範圍 1753/1/1~9999/12/31
所以如果不用到太遠的日期範圍,就會使用smalldatetime。
更關鍵的差別,smalldatetime只精準到分,而datetime可精準到3.33毫秒。





參考1
參考2
參考3




[學習] Directory.GetCurrentDirectory 和 Application.StartupPath 區別

Imports System.IO

—————————————————————————————
StartupPath 程式執行後,路徑位置不因外在因素而變。
GetCurrentDirectory 程式執行後,路徑位置會因外在因素而變。
—————————————————————————————

獲取文件路徑定義
Application.StartupPath——獲取啟動了應用程序的可執行文件的路徑,不包括可執行文件的名稱。
Environment.CurrentDirectory——獲取和設置當前目錄(即該進程從中啟動的目錄)的完全限定路徑。
Application.ExecutablePath——獲取啟動了應用程序的可執行文件的路徑,包括可執行文件的名稱。
Directory.GetCurrentDirectory()——獲取應用程序的當前工作目錄。
Directory.GetCurrentDirectory()——程序文件自身的路徑。


GetCurrentDirectory 會受 OpenFileDialog(SaveFileDialog) 的影響,而改變路徑位置。
假如有兩個程式 C:/A/a.exe 和 C:/B/b.exe
當在 a.exe 中啟動 b.exe,System.Diagnostics.Process.Start(@"C:/B/b.exe")
此時 b.exe 中的 Directory.GetCurrentDirectory() 返回值為 “C:/A”
Application.StartupPath 值為“C:/B”

如果直接在 C:/B/ 中啟動 b.exe,那麼兩個值就會一樣,都為“C:/B”
這就是 Directory.GetCurrentDirectory 和 Application.StartupPath 的區別

Application.StartupPath 是程序的啟動目錄,這個在程序運行以後,就不會改變了。
Directory.GetCurrentDirectory() 是"當前目錄",是可以在程序運行時候改變的 ,
用Directory.SetCurrentDirectory() 就可以改變。
Directory.GetCurrentDirectory() 初始值和 Application.StartupPath() 一樣。

參考:
[C#]使用 Path 類別取得檔案或目錄路徑資訊
File.Exists 方法
有关File.Exists(filename)的问题
c# 獲取相對路徑
取得目前執行程式的目錄

2012年11月13日 星期二

[除錯] 建立視窗控制代碼時發生錯誤 (下)

建立視窗控制代碼時發生錯誤 (上)

網路上這樣的發問訊息不多...
在(中文)資訊很少 也無解決方法...
有談論到的中文網站
 點我點我(1)
 點我點我(2) <<---- 有解決方法 但不是我要的!

(英文)資訊較多 卻苦無解決方法(讀者可以試試找英文的文件)...
[KeyWords]
Creating Window Handle
System.outOfMemoryException
System.NullReferenceException
MdiParent
FormWindowState.Maximized

有遇到相同原因的 或許可以試試
若剛好同樣的原因 那恭喜你 可以解決了

解決辦法

(1)

        p_mdi.MdiParent = Me
        p_mdi.WindowState = FormWindowState.Maximized
        p_mdi.Show()

改成
        p_mdi.Owner = Me
        p_mdi.WindowState = FormWindowState.Maximized
        p_mdi.Show()

這樣就不是MDI表單了~
但問題解決了~

(2)

p_mdi.WindowState = FormWindowState.Maximized

註解掉~ 並且不讓子表單在放大狀態運作~
這樣在畫面上會很怪 也很不符合使用邏輯~
但問題也解決了~

實際上可解決辦法

(1)
(Coding狀態) 將 [UI畫面] 拉大至可以將 [TextBox1] 容納~

(2)
將 btn[版面設置] 移至 [TextBox1] 後面~ 此時(Coding狀態) [TextBox1] 便落在 [UI畫面] 上~

(3)
將 [TextBox1] 位置 調置前面 使落在 [UI畫面] 上~

(4)
不管你用什麼辦法~ 
(刪除前面某個btn or others 讓 [TextBox1] 落在 [UI畫面] 上)
(刪除 [TextBox1])
, etc...

只要讓 [TextBox1] 在(Coding狀態) [UI畫面上] 便解決問題!
若是在程式執行時~ 才拉大UI畫面 一樣會出錯!


真正原因在於...............................................(研究中)

一、
我將專案每個表單內的程式全清空~ 僅保留空的程式!

EX: (表單 Class 原始)
Public Class MGMT_Personal
       'do something
End Class

UI設計畫面保留~
程式依然出錯~ 所以確定不是 Code 的問題!

二、
建立新的專案 測試MDI 也將 [TextBox1] (Codeing狀態)移出 [UI畫面] 外~
執行不會出錯 所以是原本專案上 拉UI時 未知的地方出錯~



----不無可能是程式碼某部份寫錯 for loop 之類的東西----

[除錯] 建立視窗控制代碼時發生錯誤 (上)

建立視窗控制代碼時發生錯誤 (下)

(1)開發環境 Development Environment
WinXP (32-bit x86) SP3
VS.NET 2008
.Net Framework 3.5

VB WinForm
MDI Form

(2)程式碼 Code
    '建立新的子表單
    Private Sub ShowMDIForm(ByVal p_mdi As Form)
        p_mdi.MdiParent = Me
        'p_mdi.Owner = Me
        p_mdi.WindowState = FormWindowState.Maximized
        p_mdi.Show()
    End Sub

    '檢查是否子表單已存在
    Function checkFormExist(ByVal FormText As String) As Boolean
        Dim bFound As Boolean = False
        For Each f As Form In Me.MdiChildren
            If f.Text.Equals(FormText) Then
                f.Activate()
                bFound = True
                Exit For
            End If
        Next
        Return bFound
    End Function

    '建立子表單
    Private Sub TreeView1_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
        Dim l_Frm As Form = New Form
        Select Case e.Node.Text
            Case "個資管理"
                l_Frm = New MGMT_Personal
            Case "薪資管理"
                l_Frm = New MGMT_Salary
            Case "任職管理"
                l_Frm = New MGMT_P
            Case "事項管理"
                l_Frm = New MGMT_ImptItem
        End Select

        '判斷存表單是否已存在 - 若否則開啟 New & Show
        If checkFormExist(l_Frm.Text) = False Then
            ShowMDIForm(l_Frm)
        End If

        '判斷存表單是否已存在 - 若是則開啟 Activate
        If l_Frm IsNot Nothing Then
            For i As Integer = 0 To Me.MdiChildren.Length - 1
                If e.Node.Text.Equals(Me.MdiChildren(i).Text) Then
                    Me.MdiChildren(i).Activate()
                    'Return
                End If
            Next
        End If
    End Sub

(3)參考畫面


(4)錯誤產生時間
當點選 "任職管理" 再點選其它 "表單選項" 便會發生 Error!

(5)參考辦法
疑難排解例外狀況:System.OutOfMemoryException


使用過多的 Managed 記憶體,通常是因為:
  • 將大量資料集讀入記憶體中。
  • 建立過多的快取項目。
  • 上傳或下載大型檔案。
  • 剖析檔案時,使用太多規則運算式 (Regular Expression) 或字串。
  • 檢視狀態過多。
  • 工作階段狀態中有過多資料,或工作階段過多。
在 COM 物件上叫用方法,而且這個 COM 物件會傳回包含安全陣列 (非固定大小的陣列) 的使用者定義型別時,便可能會擲回這個例外狀況,其中的訊息為:「存放裝置空間不足,無法完成此操作」。這是因為 .NET Framework 無法封送處理具有安全陣列型別的結構欄位。

(6)錯誤訊息
System.OutOfMemoryException 未處理
  Message="建立視窗控制代碼時發生錯誤。"
  Source="System.Windows.Forms"
  StackTrace:
       於 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)    於 System.Windows.Forms.Control.CreateHandle()    於 System.Windows.Forms.Form.CreateHandle()    於 System.Windows.Forms.Control.get_Handle()    於 System.Windows.Forms.Form.SetVisibleCore(Boolean value)    於 System.Windows.Forms.Control.Show()    於 eHRsys.MAIN_ligoHRsys.ShowMDIForm(Form p_mdi) 於 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\eHRsys\eHRsys\MAIN_ligoHRsys.vb: 行 33    於 eHRsys.MAIN_ligoHRsys.TreeView1_NodeMouseClick(Object sender, TreeNodeMouseClickEventArgs e) 於 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\eHRsys\eHRsys\MAIN_ligoHRsys.vb: 行 74    於 System.Windows.Forms.TreeView.OnNodeMouseClick(TreeNodeMouseClickEventArgs e)    於 System.Windows.Forms.TreeView.WmNotify(Message& m)    於 System.Windows.Forms.TreeView.WndProc(Message& m)    於 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)    於 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)    於 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)    於 System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)    於 System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)    於 System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)    於 System.Windows.Forms.Control.WmNotify(Message& m)    於 System.Windows.Forms.Control.WndProc(Message& m)    於 System.Windows.Forms.ScrollableControl.WndProc(Message& m)    於 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)    於 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)    於 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)    於 System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)    於 System.Windows.Forms.NativeWindow.DefWndProc(Message& m)    於 System.Windows.Forms.Control.DefWndProc(Message& m)    於 System.Windows.Forms.TreeView.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)    於 System.Windows.Forms.TreeView.WndProc(Message& m)    於 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)    於 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)    於 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)    於 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)    於 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)    於 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)    於 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)    於 System.Windows.Forms.Application.Run(ApplicationContext context)    於 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()    於 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()    於 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)    於 eHRsys.My.MyApplication.Main(String[] Args) 於 17d14f5c-a337-4978-8281-53493378c1071.vb: 行 81    於 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)    於 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)    於 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()    於 System.Threading.ThreadHelper.ThreadStart_Context(Object state)    於 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)    於 System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.NullReferenceException
       Message="並未將物件參考設定為物件的執行個體"
       Source="System.Windows.Forms"
       StackTrace:
            於 System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)    於 System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)    於 System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)    於 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
       InnerException:

-------------------------------------------------------------------------

如需叫用 Just-In-Time (JIT) 偵錯的詳細資料,
請參閱本訊息結尾處 (而非這個對話方塊) 的資訊。

************** 例外狀況文字 **************
System.OutOfMemoryException: 建立視窗控制代碼時發生錯誤。 ---> System.NullReferenceException: 並未將物件參考設定為物件的執行個體
   於 System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   於 System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
   於 System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
   於 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   --- 內部例外狀況堆疊追蹤的結尾 ---
   於 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   於 System.Windows.Forms.Control.CreateHandle()
   於 System.Windows.Forms.Form.CreateHandle()
   於 System.Windows.Forms.Control.get_Handle()
   於 System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   於 System.Windows.Forms.Control.Show()
   於 eHRsys.MAIN_ligoHRsys.ShowMDIForm(Form p_mdi) 於 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\eHRsys\eHRsys\MAIN_ligoHRsys.vb: 行 9
   於 eHRsys.MAIN_ligoHRsys.TreeView1_NodeMouseClick(Object sender, TreeNodeMouseClickEventArgs e) 於 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\eHRsys\eHRsys\MAIN_ligoHRsys.vb: 行 55
   於 System.Windows.Forms.TreeView.OnNodeMouseClick(TreeNodeMouseClickEventArgs e)
   於 System.Windows.Forms.TreeView.WmNotify(Message& m)
   於 System.Windows.Forms.TreeView.WndProc(Message& m)
   於 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   於 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   於 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** 已載入的組件 **************
mscorlib
    組件版本: 2.0.0.0
    Win32 版本: 2.0.50727.3634 (GDR.050727-3600)
    程式碼基底: file:///C:/WINNT/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
eHRsys
    組件版本: 1.0.0.0
    Win32 版本: 1.0.0.0
    程式碼基底: file:///C:/Documents%20and%20Settings/Administrator/My%20Documents/Visual%20Studio%202008/Projects/eHRsys/eHRsys/bin/Debug/eHRsys.exe
----------------------------------------
Microsoft.VisualBasic
    組件版本: 8.0.0.0
    Win32 版本: 8.0.50727.3053 (netfxsp.050727-3000)
    程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
    組件版本: 2.0.0.0
    Win32 版本: 2.0.50727.3634 (GDR.050727-3600)
    程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
    組件版本: 2.0.0.0
    Win32 版本: 2.0.50727.3637 (GDR.050727-3600)
    程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    組件版本: 2.0.0.0
    Win32 版本: 2.0.50727.3639 (GDR.050727-3600)
    程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    組件版本: 2.0.0.0
    Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
    程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    組件版本: 2.0.0.0
    Win32 版本: 2.0.50727.3082 (QFE.050727-3000)
    程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
    組件版本: 2.0.0.0
    Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
    程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
System.Windows.Forms.resources
    組件版本: 2.0.0.0
    Win32 版本: 2.0.50727.1433 (REDBITS.050727-1400)
    程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_zh-CHT_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------
mscorlib.resources
    組件版本: 2.0.0.0
    Win32 版本: 2.0.50727.3634 (GDR.050727-3600)
    程式碼基底: file:///C:/WINNT/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------

************** JIT 偵錯 **************
若要啟用 Just-In-Time (JIT) 偵錯功能,則必須在
此應用程式或電腦的 .config 檔案中,設定
system.windows.forms 區段內的 jitDebugging 值。
且該應用程式也必須在啟用偵錯的狀態下進行
編譯。

例如:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

當 JIT 偵錯功能啟用後,會將所有未處理的例外
狀況傳送給電腦上已註冊的 JIT 偵錯工具進行處
理,而不是使用這個對話方塊來處理。