2015年3月4日 星期三

2015年2月27日 星期五

CASE WHEN IS NULL

引用
SELECT (CASE WHEN PUR_AMT IS NULL THEN 0 ELSE PUR_AMT END) PUR_AMT 
FROM   PDA_PCOTI

2015年2月24日 星期二

MSSQL 輸出千分位

引用
1.ASCII轉換10進位、16進位
有時候我們必須要知道字串對應到ASCII是10進位的哪個數字,最簡單方式如下:
int tenNum = (int)'A'; //字元轉出ASCII 10進位表示
Console.WriteLine(string.Format("10進位數字:{0}", tenNum.ToString()));
string hexNum = Convert.ToString(tenNum,16); //轉成16進位表示
Console.WriteLine(string.Format("16進位數字:{0}", hexNum));


2.字串反轉
由於工作上廠商寫入RFID的資料,不知為啥要反過來,所以逼得我要將讀取出來的資料做個反轉!!
string testString = "ABCDEF";
char[] testCharArr = testString.ToCharArray();
Array.Reverse(testCharArr);
Console.WriteLine(new String(testCharArr));

3.MSSQL 輸出千分位!
最近有個小需求,希望在頁面上呈現【1,000.00】這種數字樣式,當然從資料庫撈出後,再用C#轉換也可以。
但既然TSQL也能做到不如就直接轉換吧!!
select convert(varchar,CONVERT(MONEY,MyColumn),1)  from MyTable

2015年2月9日 星期一

DataGridView取欄位值

抓取GridView裡的欄位值

   LOT.Text = GridView3.Rows(0).Cells(10).Text

Private SubDataGridView1_CellContentClick(ByVal sender As System.Object, ByVale AsSystem.Windows.Forms.DataGridViewCellEventArgs) HandlesDataGridView1.CellContentClick
    '點選單一儲存格
   DataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect
   MsgBox("你點選了:" & DataGridView1.CurrentCell.Value.ToString)
    Me.DataGridView1.SelectionMode =DataGridViewSelectionMode.FullRowSelect
    End Sub

    Private SubButton1_Click(ByVal sender As System.Object, ByVale As System.EventArgs) HandlesButton1.Click
    '選取整列
    '先點一下最左邊儲存格選取整列再按按鍵
    Dim I, C, R As Integer
    Dim Sel_Count As Integer
    Dim S As String
    Me.DataGridView1.SelectionMode =DataGridViewSelectionMode.FullRowSelect
   Sel_Count =DataGridView1.GetCellCount(DataGridViewElementStates.Selected)
    For I = 0 To Sel_Count- 1
   C = DataGridView1.SelectedCells(I).ColumnIndex
   R = DataGridView1.CurrentRow.Index
   DataGridView1.CurrentCell = DataGridView1(C, R)
   S = S + DataGridView1.CurrentCell.Value.ToString & vbCrLf
    Next
   MsgBox("你點選了第" & DataGridView1.CurrentRow.Index & "列" & vbCrLf & S)
    EndSub

2015年2月8日 星期日

在已繪製的文字中設定定位停駐點

如何:在已繪製的文字中設定定位停駐點

.NET Framework 4.5
您可以經由呼叫 StringFormat 物件的 SetTabStops 方法,然後將該 StringFormat 物件傳遞至 Graphics 類別的 DrawString 方法,以設定文字的定位停駐點。
注意事項 注意事項
System.Windows.Forms.TextRenderer 不支援將定位停駐點加入至繪製的文字,但您可以使用 TextFormatFlags.ExpandTabs 旗標擴充現有的定位停駐點。

下列範例會在 150、250 和 350 設定定位停駐點。 然後程式碼會顯示名稱和考試成績的索引標籤式清單。
下圖顯示的是索引標籤式文字。
字型文字
下列程式碼會將兩個引數傳遞至 SetTabStops 方法。 第二個引數是包含定位點位移 (Offset) 的陣列。 傳遞至 SetTabStops 第一個引數是 0,表示陣列中的第一個位移是從週框左邊緣的位置 0 開始測量。
        Dim myText As String = _
           "Name" & ControlChars.Tab & _
           "Test 1" & ControlChars.Tab & _
           "Test 2" & ControlChars.Tab & _
           "Test 3" & ControlChars.Cr

        myText = myText & "Joe" & ControlChars.Tab & _
                          "95" & ControlChars.Tab & _
                          "88" & ControlChars.Tab & _
                          "91" & ControlChars.Cr
        myText = myText & "Mary" & ControlChars.Tab & _
                          "98" & ControlChars.Tab & _
                          "84" & ControlChars.Tab & _
                          "90" & ControlChars.Cr
        myText = myText & "Sam" & ControlChars.Tab & _
                          "42" & ControlChars.Tab & _
                          "76" & ControlChars.Tab & _
                          "98" & ControlChars.Cr
        myText = myText & "Jane" & ControlChars.Tab & _
                          "65" & ControlChars.Tab & _
                          "73" & ControlChars.Tab & _
                          "92" & ControlChars.Cr

        Dim fontFamily As New FontFamily("Courier New")
        Dim font As New Font( _
           fontFamily, _
           12, _
           FontStyle.Regular, _
           GraphicsUnit.Point)
        Dim rect As New Rectangle(10, 10, 450, 100)
        Dim stringFormat As New StringFormat()
        Dim solidBrush As New SolidBrush(Color.FromArgb(255, 0, 0, 255))
        Dim tabs As Single() = {150, 100, 100, 100}

        stringFormat.SetTabStops(0, tabs)

        e.Graphics.DrawString(myText, font, solidBrush, RectangleF.op_implicit(rect), stringFormat)

        Dim pen As Pen = Pens.Black
        e.Graphics.DrawRectangle(pen, rect)