機率分布統計取得函數
x軸 設定取樣範圍是0~255 間距為1
y軸 機率值 0~1


'-------------------------------------------
Public Function getprob() As Single()

Dim op1 As New OpenFileDialog

'-------選取來源檔視窗-------------------
op1.Filter = ".raw|*.*"
Dim path As String

If op1.ShowDialog() = Windows.Forms.DialogResult.OK Then
path = op1.FileName

End If


Dim pic As New Bitmap(path) '讀圖 (檔案路徑 :Debug 目錄下 )
' Dim pic As New Bitmap("test.bmp") '讀圖 (檔案路徑 :Debug 目錄下 )
' Dim pic As New Bitmap("test.jpg") '讀圖 (檔案路徑 :Debug 目錄下 ) 任何圖片格式都可以讀成Bitmap 物件

Dim x As Integer = pic.Width '取得原圖寬度
Dim y As Integer = pic.Height '取得原圖長度
Dim pic2 As New Bitmap(x, y) '產生新圖 設定大小跟原圖一樣大

Dim colorG As Double
'-------/選取來源檔視窗/-------------------


'-------灰階運算--------------

' Dim pixelcolor As Color '測試用
' pixelcolor = pic.GetPixel(1, 1) ' 可以發現1個 Pixel 點 包含了(R,G,B)

Dim colorG_int_array(x - 1, y - 1) As UInt16
Dim histogram(255) As Long '灰度值分布數量統計
' Dim probility_G(255) As Single '灰度值機率分布

For j = 0 To y - 1
For i = 0 To x - 1
colorG = 0.299 * pic.GetPixel(i, j).R + 0.587 * pic.GetPixel(i, j).G + 0.114 * pic.GetPixel(i, j).B
Dim pointG = colorG - CInt(colorG) '四捨五入運算
If pointG > 0.5 Then
colorG = CInt(colorG) + 1
Else
colorG = CInt(colorG)
End If

colorG_int_array(i, j) = colorG
'--------------在出現的灰值上累計數量------------
For n = 0 To 255
If colorG = n Then
histogram(n) = histogram(n) + 1
End If
Next
'-------------/在出現的灰值上累計數量/--------------
Next
Next



'-------/灰階運算/--------------


'----------灰度機率統計--------------------------------------
Dim CDF_G(255) As Single

'Dim sum_p As Single = 0
Dim probility_G(255) As Single
For i = 0 To 255
probility_G(i) = histogram(i) / (x * y)
' sum_p = sum_p + probility_G(i)


'----------灰度CDF-------------
If i = 0 Then

CDF_G(i) = probility_G(i)
Else
CDF_G(i) = CDF_G(i - 1) + probility_G(i)

End If
'----------/灰度CDF/-----------------

Next

'----------灰度機率統計-----------------------------------------


Return probility_G
End Function

prague12 發表在 痞客邦 留言(0) 人氣()

NORMAL分布

======================================

Public Function Normal(ByVal x As Double) As Double
Dim mean = 0
Dim sd = 1
Dim numberator = Pow((x - mean), 2)
Dim denominator = 2 * sd * sd
Dim power_exp = -1 * numberator / denominator
Dim exp_number = Pow(E, power_exp)
Dim gausian_head = 1 / (Sqrt(2 * PI) * sd)
Dim result = gausian_head * exp_number



Return result

End Function





Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


' Dim aaa = colinear_condition(10, 1, 2, 3, 55, 55, 66, 3, 3, 3)

' Dim q1 = aaa(0, 0)
'Dim q2 = aaa(0, 1)

For i = 0 To 100



Dim randomX As New Random

Dim p = randomX.Next(0, 100)
Dim q = randomX.Next(0, 100) * -1
Dim randomValue = 0
Dim G = Gaussian(randomValue, 0, 1)
Dim N = Normal(randomValue)

' Dim uu = G - N

Next

End Sub

prague12 發表在 痞客邦 留言(0) 人氣()

空間共線條件轉換成像點

'------------------------------------------

    Public Function colinear_condition(ByVal fc As Double, ByVal air_x As Double, ByVal air_y As Double, ByVal air_z As Double, ByVal ground_x As Double, ByVal ground_y As Double, ByVal ground_z As Double, ByVal omega As Double, ByVal fi As Double, ByVal kapa As Double) As Double(,)


        Dim mid_image(1, 1) As Double ' 只是用來一次回傳多個值 x=m(1,0) ,y=m(0,1)
        Dim mid_x, mid_y As Double
        Dim m11, m12, m13, m21, m22, m23, m31, m32, m33 As Double
        Const per_degree_value = Math.PI / 180
        Dim omega_value = omega * per_degree_value
        Dim fi_value = fi * per_degree_value
        Dim kapa_value = kapa * per_degree_value
        '----------------------------------------------------------------
        ' m11 = Math.Cos(omega * per_degree_value) 'omega單位是'度'  >>   但函數要帶的是value,做個轉換
        m11 = Cos(omega_value) * Cos(kapa_value)
        m12 = Sin(omega_value) * Sin(fi_value) * Cos(kapa_value) + Cos(omega_value) * Sin(kapa_value)
        m13 = (-1) * Cos(omega_value) * Sin(fi_value) * Cos(kapa_value) + Sin(omega_value) * Sin(kapa_value)

        m21 = (-1) * Cos(fi_value) * Sin(kapa_value)
        m22 = -1 * Sin(omega_value) * Sin(fi_value) * Sin(kapa_value) + Cos(omega_value) * Cos(kapa_value)
        m23 = Cos(omega_value) * Sin(fi_value) * Sin(kapa_value) + Sin(omega_value) * Cos(kapa_value)

        m31 = Sin(fi_value)
        m32 = -1 * Sin(omega_value) * Cos(fi_value)
        m33 = Cos(omega_value) * Cos(fi_value)
        '------------------------------------------------------------------


        Dim dx = (ground_x - air_x)
        Dim dy = (ground_y - air_y)
        Dim dz = (ground_z - air_z)

        Dim mid_x_numerator = m11 * dx + m12 * dy + m13 * dz
        Dim mid_x_denominator = m31 * dx + m32 * dy + m33 * dz

        mid_x = (-1 * fc) * mid_x_numerator / mid_x_denominator

        Dim mid_y_numerator = m21 * dx + m22 * dy + m23 * dz
        'Dim mid_y_denominator = m31 * dx + m32 * dy + m33 * dz
        Dim mid_y_denominator = mid_x_denominator  '分母都是一樣的 少一點計算量

        mid_y = (-1 * fc) * mid_y_numerator / mid_y_denominator
        '------------------------------------------------------

        mid_image(1, 0) = mid_x
        mid_image(0, 1) = mid_y


        Return mid_image


    End Function

prague12 發表在 痞客邦 留言(0) 人氣()

使用google email的smtp轉信

參考自 :http://www.dotblogs.com.tw/yc421206/archive/2010/01/05/12803.aspx

jkFIXed: 改寫一下成函數 內文是字串 解讀時屬於html的解讀

測試成功可用於ASP網頁
//=====================
Imports System.Data
Imports System.Net

Public Function To_email_message(ByVal receiver_of_Email As String, ByVal contentBODY As String, ByVal time As String) As String
Try


Dim mailTo_address As String = TextBox_mail.Text
Dim mail As New Mail.MailMessage()
Dim pwd As String = "netxxxxxx"
Dim receiver_cred As New NetworkCredential("hcgprague@gmail.com", pwd)
' Dim receiverTest As String
'receiverTest = "hcgprague@hotmail.com," + "prague12.tw@yahoo.com.tw"
'收件者
mail.To.Add(receiver_of_Email)
'mail.Subject = "subject gmail_test "
mail.Subject = "有新訂購" + time

'寄件者
mail.From = New System.Net.Mail.MailAddress("fff@gmail.com")
mail.IsBodyHtml = True
mail.Body = "messageAAAA content 中文也要來一下 " + vbNewLine + contentBODY

'設定SMTP
Dim smtp As New Mail.SmtpClient("smtp.gmail.com")
smtp.UseDefaultCredentials = False
smtp.EnableSsl = True
smtp.Credentials = receiver_cred
smtp.Port = 587

'送出Mail
smtp.Send(mail)

Return ("send EMAIL OK")

Catch ex As Exception
Return ("send EMAIL FAIL")
End Try

End Function

prague12 發表在 痞客邦 留言(0) 人氣()

wm6 CF下 製作CF沒內建的 '' sendkey ''功能
http://msdn.microsoft.com/en-us/library/ms927178.aspx
//------------------------------------------------------

Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Public Class Class1

_
Public Shared Function keybd_event(ByVal bVk As Int32, ByVal bScan As Int32, _
ByVal dwFlags As Int32, ByVal dwExtraInfo As Int32) As Boolean
End Function


_
Public Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function

_
Public Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
End Function

Public Const WM_CLOSE As Integer = &H10
Public Const VK_DOWN = &H28
Public Const VK_select = &H29
Public Const VK_RETURN = &HD 'enter
'//---------------
Public Shared Sub sendkeys(ByVal keycode As Byte)

Const KEYEVENTF_KEYUP As Byte = &H2
'http://msdn.microsoft.com/en-us/library/ms927178.aspx

keybd_event(keycode, 0, 0, 0) ' Generates a KEY_DOWN
keybd_event(keycode, 0, KEYEVENTF_KEYUP, 0) ' Generates a KEY_UP
End Sub

....................
...................

...................

prague12 發表在 痞客邦 留言(0) 人氣()

鍵盤,滑鼠 全域hook ,vb winAPI dll 引用法

參考自:
C#篇 >> http://www.dotblogs.com.tw/huanlin/archive/2008/04/23/3320.aspx
VB篇 >> http://www.inpowers.net/viewthread.php?tid=31514&extra=page%3D1
'//--------------------------------------------------------------------------
jk_fix心得:
vb的部分 會因為 Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly.GetModules()(0) 導致失敗

hKeyboardHook = SetWindowsHookExA(WH_KEYBOARD_LL, KeyboardHookProcedure, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly.GetModules()(0)), 0)

得要使用winAPI GetModuleHandle() 去換掉 Marshal .....(細部參考c#篇)

之後即可成功使用全域hook
//-----------------------------------------------------------------------
'以下是jk 整合vb篇和c#篇後的結果 ~~測試ok可用
'//================================================
Public Class hook

#Region "定義結構"
Private Structure MouseHookStruct
Dim PT As Point
Dim Hwnd As Integer
Dim WHitTestCode As Integer
Dim DwExtraInfo As Integer
End Structure
Private Structure MouseLLHookStruct
Dim PT As Point
Dim MouseData As Integer
Dim Flags As Integer
Dim Time As Integer
Dim DwExtraInfo As Integer
End Structure
Private Structure KeyboardHookStruct
Dim vkCode As Integer
Dim ScanCode As Integer
Dim Flags As Integer
Dim Time As Integer
Dim DwExtraInfo As Integer
End Structure
#End Region


#Region "API聲明導入"
'//-------------------------寫法1---類同c#宣告---------------------------------------
_
Public Shared Function GetModuleHandle(ByVal lpModuleName As String) As IntPtr
End Function
'--------------------寫法2-- 新名--------------------Alias 原名---------------------------
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" _
(ByVal idHook As Integer, _
ByVal lpfn As HookProc, _
ByVal hmod As Integer, _
ByVal dwThreadId As Integer) As Integer
'-----------------------------寫法3-----------新名=原名---省略宣告法----------------------------------------------
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal idHook As Integer) As Integer
'------------------------------------------------------------------------------------
Public Declare Function CallNextHookEx Lib "user32" Alias "CallNextHookEx" (ByVal idHook As Integer, ByVal ncode As Integer, ByVal wParam As Int32, ByVal lParam As IntPtr) As Integer
'--------------------------------------------------------------------------------------

Public Declare Function ToAscii Lib "user32" (ByVal uVirtKey As Integer, ByVal uScancode As Integer, ByVal lpdKeyState As Byte(), ByVal lpwTransKey As Byte(), ByVal fuState As Integer) As Integer
Public Declare Function GetKeyboardState Lib "user32" (ByVal pbKeyState As Byte()) As Integer
Public Declare Function GetKeyState Lib "user32" (ByVal vKey As Integer) As Short
Public Delegate Function HookProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
#End Region

#Region "常量聲明"

Private Const WH_MOUSE_LL = 14
Private Const WH_KEYBOARD_LL = 13
Private Const WH_MOUSE = 7
Private Const WH_KEYBOARD = 2
Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_MBUTTONDOWN = &H207
Private Const WM_LBUTTONUP = &H202
Private Const WM_RBUTTONUP = &H205
Private Const WM_MBUTTONUP = &H208
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_RBUTTONDBLCLK = &H206
Private Const WM_MBUTTONDBLCLK = &H209
Private Const WM_MOUSEWHEEL = &H20A
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const WM_SYSKEYDOWN = &H104
Private Const WM_SYSKEYUP = &H105
Private Const VK_SHIFT As Byte = &H10
Private Const VK_CAPITAL As Byte = &H14
Private Const VK_NUMLOCK As Byte = &H90
#End Region
''' 滑鼠啟動事件
Public Event MouseActivity As MouseEventHandler
''' 鍵盤按下事件
Public Event KeyDown As KeyEventHandler
''' 鍵盤輸入事件
Public Event KeyPress As KeyPressEventHandler
''' 鍵盤鬆開事件
Public Event KeyUp As KeyEventHandler
Private hMouseHook As Integer
Private hKeyboardHook As Integer
Private Shared MouseHookProcedure As HookProc
Private Shared KeyboardHookProcedure As HookProc
''' 創建一個全域滑鼠鍵盤鉤子 (請使用Start方法開始監視)
Sub New()
'留空即可
End Sub
''' 創建一個全域滑鼠鍵盤鉤子,決定是否安裝鉤子
''' 是否立刻掛鉤系統消息
Sub New(ByVal InstallAll As Boolean)
If InstallAll Then StartHook(True, True)
End Sub
''' 創建一個全域滑鼠鍵盤鉤子,並決定安裝鉤子的類型
''' 掛鉤鍵盤消息
''' 掛鉤滑鼠消息
Sub New(ByVal InstallKeyboard As Boolean, ByVal InstallMouse As Boolean)
StartHook(InstallKeyboard, InstallMouse)
End Sub
''' 析構函數
Protected Overrides Sub Finalize()
UnHook() '卸載物件時反註冊系統鉤子
MyBase.Finalize()
End Sub


'鍵盤消息的委託處理代碼
Private Function KeyboardHookProc(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer
Dim handled As Boolean = False
If nCode >= 0 Then
Dim MyKeyboardHookStruct As KeyboardHookStruct = DirectCast(Marshal.PtrToStructure(lParam, GetType(KeyboardHookStruct)), KeyboardHookStruct)
'啟動KeyDown
If wParam = WM_KEYDOWN OrElse wParam = WM_SYSKEYDOWN Then '如果消息為按下普通鍵或系統鍵
Dim e As New KeyEventArgs(MyKeyboardHookStruct.vkCode)
RaiseEvent KeyDown(Me, e) '啟動事件
handled = handled Or e.Handled '是否取消下一個鉤子
End If
'啟動KeyUp
If wParam = WM_KEYUP OrElse wParam = WM_SYSKEYUP Then
Dim e As New KeyEventArgs(MyKeyboardHookStruct.vkCode)
RaiseEvent KeyUp(Me, e)
handled = handled Or e.Handled
End If
'啟動KeyPress
If wParam = WM_KEYDOWN Then
Dim isDownShift As Boolean = (GetKeyState(VK_SHIFT) & &H80 = &H80)
Dim isDownCapslock As Boolean = (GetKeyState(VK_CAPITAL) 0)
Dim keyState(256) As Byte
GetKeyboardState(keyState)
Dim inBuffer(2) As Byte
If ToAscii(MyKeyboardHookStruct.vkCode, MyKeyboardHookStruct.ScanCode, keyState, inBuffer, MyKeyboardHookStruct.Flags) = 1 Then
Dim key As Char = Chr(inBuffer(0))
If isDownCapslock Xor isDownShift And Char.IsLetter(key) Then
key = Char.ToUpper(key)
End If
Dim e As New KeyPressEventArgs(key)
RaiseEvent KeyPress(Me, e)
handled = handled Or e.Handled
End If
End If
'取消或者啟動下一個鉤子
If handled Then Return 1 Else Return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam)
End If
End Function
'滑鼠消息的委託處理代碼
Private Function MouseHookProc(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer
If nCode >= 0 Then
Dim mouseHookStruct As MouseLLHookStruct = DirectCast(Marshal.PtrToStructure(lParam, GetType(MouseLLHookStruct)), MouseLLHookStruct)
Dim moubut As MouseButtons = MouseButtons.None '滑鼠按鍵
Dim mouseDelta As Integer = 0 '滾輪值
Select Case wParam
Case WM_LBUTTONDOWN
moubut = MouseButtons.Left
Form1.ComboBox1.SelectedText = "L"
'MsgBox("LB")
Case WM_RBUTTONDOWN
moubut = MouseButtons.Right
Form1.ComboBox1.SelectedText = "R"
'MsgBox("RB")

Case WM_MBUTTONDOWN
moubut = MouseButtons.Middle
' MsgBox("MidB")
Case WM_MOUSEWHEEL
MsgBox("ROLL ~over")
Application.Exit()


Dim int As Integer = (mouseHookStruct.MouseData >> 16) And &HFFFF
'本段代碼CLE添加,模仿C#的Short從Int棄位轉換
If int > Short.MaxValue Then mouseDelta = int - 65536 Else mouseDelta = int
End Select
Dim clickCount As Integer = 0 '按一下次數
If moubut MouseButtons.None Then
If wParam = WM_LBUTTONDBLCLK OrElse wParam = WM_RBUTTONDBLCLK OrElse wParam = WM_MBUTTONDBLCLK Then
clickCount = 2
Else
clickCount = 1
End If
End If
Dim e As New MouseEventArgs(moubut, clickCount, mouseHookStruct.PT.X, mouseHookStruct.PT.Y, mouseDelta)
RaiseEvent MouseActivity(Me, e)
End If
Return CallNextHookEx(hMouseHook, nCode, wParam, lParam) '啟動下一個鉤子
End Function


''' 開始安裝系統鉤子
''' 掛鉤鍵盤消息
''' 掛鉤滑鼠消息
Public Sub StartHook(Optional ByVal InstallKeyboardHook As Boolean = True, Optional ByVal InstallMouseHook As Boolean = False)



'註冊鍵盤鉤子
If InstallKeyboardHook AndAlso hKeyboardHook = 0 Then

Dim curProcess = Process.GetCurrentProcess
Dim curModule = curProcess.MainModule
'---------------------------------------------
KeyboardHookProcedure = New HookProc(AddressOf KeyboardHookProc)

Dim hook_intptr = GetModuleHandle(curModule.ModuleName)
' Dim hook_int = Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly.GetModules()(0))

hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, hook_intptr, 0)

If hKeyboardHook = 0 Then '檢測是否註冊完成
UnHook(True, False) '在這裡反註冊

MsgBox("error")
'Throw New Win32Exception(Marshal.GetLastWin32Error) '報告錯誤
End If
End If
'註冊滑鼠鉤子
If InstallMouseHook AndAlso hMouseHook = 0 Then

Dim curProcess = Process.GetCurrentProcess
Dim curModule = curProcess.MainModule
'---------------------------------------------
MouseHookProcedure = New HookProc(AddressOf MouseHookProc)
Dim hook_intptr = GetModuleHandle(curModule.ModuleName)
hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProcedure, hook_intptr, 0)
If hMouseHook = 0 Then
UnHook(False, True)
MsgBox("error")
' Throw New Win32Exception(Marshal.GetLastWin32Error)

End If
End If
End Sub
''' 立刻卸載系統鉤子
''' 卸載鍵盤鉤子
''' 卸載滑鼠鉤子
''' 是否報告錯誤
Public Sub UnHook(Optional ByVal UninstallKeyboardHook As Boolean = True, Optional ByVal UninstallMouseHook As Boolean = True, Optional ByVal ThrowExceptions As Boolean = False)
'卸載鍵盤鉤子
If hKeyboardHook 0 AndAlso UninstallKeyboardHook Then
Dim retKeyboard As Integer = UnhookWindowsHookEx(hKeyboardHook)
hKeyboardHook = 0
If ThrowExceptions AndAlso retKeyboard = 0 Then '如果出現錯誤,是否報告錯誤
Throw New Win32Exception(Marshal.GetLastWin32Error) '報告錯誤
End If
End If
'卸載滑鼠鉤子
If hMouseHook 0 AndAlso UninstallMouseHook Then
Dim retMouse As Integer = UnhookWindowsHookEx(hMouseHook)
hMouseHook = 0
If ThrowExceptions AndAlso retMouse = 0 Then
Throw New Win32Exception(Marshal.GetLastWin32Error)
End If
End If
End Sub

''' 鍵盤鉤子是否無效
Public Property KeyHookInvalid() As Boolean
Get
Return hKeyboardHook = 0
End Get
Set(ByVal value As Boolean)
If value Then UnHook(True, False) Else StartHook(True, False)
End Set
End Property
''' 滑鼠鉤子是否無效
Public Property MouseHookInvalid() As Boolean
Get
Return hMouseHook = 0
End Get
Set(ByVal value As Boolean)
If value Then UnHook(False, True) Else StartHook(False, True)
End Set
End Property
End Class

prague12 發表在 痞客邦 留言(0) 人氣()

// 範例解說: 這樣可以去搜索在路徑的資料夾內的檔案 逐一讀取

//-------------------------------------
public void Read_ALLfile()
{
while (true)
{
foreach (string sFile in Directory.GetFiles(@"c:\\eml"))
{// 這樣可以去搜索在路徑的資料夾內的檔案 逐一讀取
try
{

FileStream fs = File.Open(sFile, FileMode.Open, FileAccess.ReadWrite);

// StreamReader sr = new StreamReader(fs); 測試用
// string all = sr.ReadToEnd();
// MessageBox.Show(all);

EMLReader reader = new EMLReader(fs);
fs.Close();

//=======QP解碼===================
string body_content = QPDecode(reader.Body);
//=======/QP解碼/===================

}


catch (System.IO.IOException err)
{
MessageBox .Show ("File " + sFile + " is currently in use.");
}
Thread.Sleep(10);

}

// break;

}
}

prague12 發表在 痞客邦 留言(2) 人氣()

.msg檔案讀取/ 中文編碼轉換
參考自:
http://www.codeproject.com/KB/office/reading_an_outlook_msg.aspx

//------------------------------------
jkFixLib:
使用不同編碼的來源檔作讀取 有中文轉換的問題
基本上分為 8位元讀取(utf8/big5) 跟 16位元讀取(unicode) 的問題
OutlookStorage.Message的 8位元讀取(utf8)會造成讀取中文編碼錯誤 需修改成(default) >> 應該是big5
//-------------------------------

//jk 轉碼測試心得 :
// 讀入stream的時候 要根據來源檔的編碼作讀取設定 才能轉出正確的中文字串 之後可以任意作編碼轉換的動作
// BUT 如果一開始的讀取編碼就錯誤了(中文變亂碼) 那後續的轉碼過程 中文都無法正常

//==========================
]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using iwantedue; //加入 OutlookStorage.Messag LIB class

private void button1_Click(object sender, EventArgs e)
{
// OutlookStorage.Message outlookMsg = new OutlookStorage.Message(@"C:\uni_test.msg");//來源檔是unicode(utf-16)編碼
OutlookStorage.Message outlookMsg = new OutlookStorage.Message(@"C:\07_test.msg");//來源檔是big5編碼

//jk測試心得 :
// 讀入stream的時候 要根據來源檔的編碼作讀取設定 才能轉出正確的中文字串 之後可以任意作編碼轉換的動作
// BUT 如果一開始的讀取編碼就錯誤了(中文變亂碼) 那後續的轉碼過程 中文都無法正常

//-------編碼轉換--------------
byte[] bb = Encoding .UTF8 .GetBytes ( outlookMsg.BodyText );
// MessageBox.Show(Encoding.Default .GetString(bb));//驗證轉碼後的字串,仍正確的顯示
byte[] cc = Encoding.Convert(Encoding.UTF8 , Encoding.Unicode , bb);//進行轉碼,參數1,來源編碼,參數二,目標編碼,參數三,欲編碼變數
string title = Encoding.Unicode .GetString(cc); // 轉換成UTF-8編碼
//-------/編碼轉換/-----------------
textBox_title.Text = outlookMsg.Subject; //可以正常顯示中文(UTF-8編碼)
textBox_content.Text = outlookMsg.BodyText;//可以正常顯示中文(UTF-8編碼)
}

prague12 發表在 痞客邦 留言(0) 人氣()

參考;
http://www.soeye.cn/article/549.aspx
http://blog.xuite.net/bless.andy/csharp/21006011
http://www.iwms.net/n516c13.aspx
http://www.cnblogs.com/freedom831215/archive/2010/07/29/1787941.html


關於POP3郵件 .eml 解碼
=====================
Base64解碼
QP 解碼 quoted-printable解码

prague12 發表在 痞客邦 留言(0) 人氣()

右鍵選單元件 ContextMenuStrip

參考自
http://tw.myblog.yahoo.com/teddybear-13/article?mid=226&next=203&l=f&fid=11



以下為vb2008 簡單示範 可用ok
//===================================================
Public Class Form1



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Me.PictureBox1.ContextMenuStrip = ContextMenuStrip1

Me.ContextMenuStrip = ContextMenuStrip1

End Sub

Private Sub AToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AToolStripMenuItem1.Click
MsgBox("a1")
End Sub

Private Sub A2ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles A2ToolStripMenuItem.Click
MsgBox("a2")
End Sub
End Class

prague12 發表在 痞客邦 留言(0) 人氣()

  Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        ' 強型別的Dataet+ TableAdapter +  Listview (.net3.5 好用組合)
        '----------------------------------------------
        Dim tablejk As   New  vote_DataSetTableAdapters.vote_1TableAdapter 
        Dim content_new = TextBox_putin.Text
        tablejk.Insert("A1", content_new, CInt(1), CInt(2), CInt(3), CInt(4))  'Insert是自動產生的邏輯函數

        'Dim GridViewjk As New GridView                       '(似乎不能搭配gridview)
        '   GridViewjk.DataSource = aaa.GetDataBy_clas("A1")   '會失敗沒反應
        '  GridViewjk.DataBind()

        '邏輯函數在TableAdapter工具可以另外精靈化產生語法函數~
        ListView1.DataSource = tablejk.GetDataBy_clas("A1")  'GetDataBy_clas是自訂邏輯函數
        ListView1.DataBind()
        ListView2.DataSource = tablejk.GetData_IP(TextBox1.Text)
        ListView2.DataBind()

 

    End Sub

prague12 發表在 痞客邦 留言(0) 人氣()

  • Aug 25 Wed 2010 23:12
  • URL

http://www.dotblogs.com.tw/jeff-yeh/archive/2009/11/11/11530.aspx

http://netcomclarkboy.blogspot.com/2009/03/opennetcf-smart-device-frameworksdf.html

prague12 發表在 痞客邦 留言(0) 人氣()

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click


Dim conn_str = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\jk1db.mdf;Integrated Security=True;User Instance=True"
Dim Conn As New SqlConnection(conn_str)
' Conn.Open() '使用adapter 可以不用事先open ,ADAPTER會自己 open 和 close


Dim cmd_str_insert = " INSERT INTO [Table1] ([name], [pwd]) VALUES ('BBB', '777')"
Dim cmd_str_select = "select * from Table1 where name= @var " '可變參數只能放 >>查詢值
'--------------------------------------------------



'----sqlAdapter + sqlcommand -----------------
Dim myAdapter2 As New SqlDataAdapter '定義一組橋接器
Dim sql_cmd As New SqlCommand(cmd_str_select, Conn) '定義 動作電源器(sql命令,連線字串)
myAdapter2.SelectCommand = sql_cmd ' 動作電源器 插上 橋接器
'--------/sqlAdapter + sqlcommand/--------------------



'------sql安全參數給法-------------
sql_cmd.Parameters.AddWithValue("@var", "AAA") '動作電源器加入 安全sql參數 寫法1
'sql_cmd.Parameters.Add("@var", SqlDbType.NChar).Value = "name" '參數寫法2
'--------/sql安全參數給法/-----------



'--------------------------------------
Dim dss As New DataSet
myAdapter2.Fill(dss) '遠端執行select,並且回傳資料給本地 DatSet > ds

GridView_adapter.DataSource = dss '傳送給 資料表格來源 在本機記憶體裡

If dss.Tables.Count > 0 Then '可以測試insert 的確沒有回傳資料給 ds
GridView_adapter.DataBind() '綁到網頁畫面上去

End If
'-------------------------------

End Sub

prague12 發表在 痞客邦 留言(0) 人氣()

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click




Dim conn_str = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\jk1db.mdf;Integrated Security=True;User Instance=True"
Dim Conn As New SqlConnection(conn_str)

' Conn.Open() '使用adapter 可以不用事先open ,ADAPTER會自己 open 和 close


Dim cmd_str_insert = " INSERT INTO [Table1] ([name], [pwd]) VALUES ('BBB', '777')"
Dim cmd_str_select = "select * from Table1"
'--------------------------------------------------
Dim ds As New DataSet
' Dim myAdapter As SqlDataAdapter = New SqlDataAdapter(cmd_str_insert, Conn) 'SqlDataAdapter(SQL命令,連線)
'myAdapter.Fill(ds) '--遠端執行SQL指令insert ,這實際上沒有回傳資料表 所以本地 DataSet ds 還是空的

Dim myAdapter2 As SqlDataAdapter = New SqlDataAdapter(cmd_str_select, Conn) 'SqlDataAdapter(SQL命令,連線)
myAdapter2.Fill(ds) '遠端執行select,並且回傳資料給本地 DatSet > ds
'-------------------------------
GridView_adapter.DataSource = ds '傳送給 資料表格來源 在本機記憶體裡


If ds.Tables.Count > 0 Then '可以測試insert 的確沒有回傳資料給 ds
GridView_adapter.DataBind() '綁到網頁畫面上去

End If




End Sub

prague12 發表在 痞客邦 留言(0) 人氣()

SqlDataSource 是在sqlAdapter之後的新控制項 有個天生的限制,就是只能執行單一批次。 如果你要執行二個以上的 SQL statement,請把它寫成 stored procedure。 不然,就乾脆別用 SqlDataSource 了(只用 SqlDataAdapter, SqlCommand 來保持高度的彈性)
//-------------------
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ds As New DataSet

Dim conn As New SqlConnection

conn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\jk1db.mdf;Integrated Security=True;User Instance=True"
conn.Open()

'----------一些sql 的動作語法-----------查詢 ,寫入--------
'SqlDataSource1.InsertCommand = " INSERT INTO [Table1] ([name], [pwd]) VALUES ('UUU', '999')"

SqlDataSource1.InsertParameters.Add("name_str", TextBox1_.Text) 'sql變數 給法
SqlDataSource1.InsertParameters.Add("pwd_str", "888") 'sql變數 給法
SqlDataSource1.InsertCommand = " INSERT INTO [Table1] ([name], [pwd]) VALUES (@name_str, @pwd_str)"
SqlDataSource1.Insert()



' SqlDataSource1.InsertParameters.Add("name_str", TextBox1_.Text) 'sql變數 給法
' SqlDataSource1.InsertParameters.Add("pwd_str", "888") 'sql變數 給法
' Dim cmd_str_select = "select * from Table1"
'SqlDataSource1.SelectCommand = cmd_str_select
conn.Close()

End Sub

prague12 發表在 痞客邦 留言(0) 人氣()