2017年6月22日 星期四

note (片段)

----------------------------------------------------------------------------------------------------------------------------------------
GridView 數字欄位加千分號

<asp:Label ID="lb_text" runat="server" Text='<%# Eval("CONSOLIDATED_REVENUE","{0:N0}") %>'></asp:Label>
or
<asp:BoundField DataField="CONSOLIDATED_REVENUE" HeaderText="合併營收" DataFormatString="{0:N0}"
    SortExpression="CONSOLIDATED_REVENUE" ItemStyle-HorizontalAlign="Center"  >
</asp:BoundField>

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

GridView & DataList --DataBind取值方法

##############
http://scenic0327-tek.blogspot.tw/2012/03/blog-post_29.html
##############
http://www.blueshop.com.tw/board/FUM20041006161839LRJ/BRD20110730191358HNV.html

If e.Row.RowType = DataControlRowType.DataRow Then
            Dim lnkView As New LinkButton()
            lnkView.ID = "patent_id"
            lnkView.Text = TryCast(e.Row.DataItem, DataRowView).Row("patent_id").ToString()
            AddHandler lnkView.Click, AddressOf ViewDetails
            lnkView.CommandArgument = TryCast(e.Row.DataItem, DataRowView).Row("patent_id").ToString()
            e.Row.Cells(1).Controls.Add(lnkView)

            'For i As Integer = 0 To e.Row.Cells.Count - 1 'row的值

            '    xxx.Text += e.Row.Cells(i).Text & "<br/>"
            '    'If e.Row.Cells(i).ClientID = "img" Then
            '    '    xxx.Text = "Y"
            '    'End If
            'Next

            For i As Integer = 0 To GridView1.HeaderRow.Cells.Count - 1 '標題的值
                If GridView1.HeaderRow.Cells(i).Text = "簡圖" Then
                    If TryCast(e.Row.DataItem, DataRowView).Row("img").ToString() <> "" Then
                        Dim img As New Image()
                        img.ID = "img"
                        img.Width = 100

                        img.ImageUrl = "FileStagingPath/" & TryCast(e.Row.DataItem, DataRowView).Row("img").ToString()
                        e.Row.Cells(i).Controls.Add(img)
                    End If
                End If
            Next

            'Dim txtCountry As New TextBox()
            'txtCountry.ID = "name"
            'txtCountry.Text = TryCast(e.Row.DataItem, DataRowView).Row("name").ToString()
            'e.Row.Cells(2).Controls.Add(txtCountry)
        End If
##############


Imports System.IO

'判斷FileUpload檔案是否存在
If (FileUpload_Img.HasFile) Then
End If

'取得上傳檔案的集合
Dim hfc As HttpFileCollection = Request.Files

For j As Integer = 0 To hfc.Count - 1
   Dim fileName As String = Mid(hfc(j).FileName, InStrRev(hfc(j).FileName, "\") + 1, Len(hfc(j).FileName)) '檔案名稱(含副檔名)
   Dim fileNameEx As String = Mid(hfc(j).FileName, InStrRev(hfc(j).FileName, "."), Len(hfc(j).FileName)) '副檔名
   Dim fileSize As String = hfc(j).ContentLength '檔案大小
Next


'判斷上船的目錄路徑是否存在
If My.Computer.FileSystem.DirectoryExists(saveDir1) Then
End If

'建立目錄路徑
My.Computer.FileSystem.CreateDirectory(saveDir1)

'判斷目錄是否有相同檔案名稱
If File.Exists(filePath) Then
End if

'變更檔案名稱
File.Move("ttt.txt", "ttt-1.txt")


https://msdn.microsoft.com/zh-tw/library/cc148994.aspx

#####################
資料繫結

<%# DataBinder.Eval(Container, "DataItem.description")%>

######################
DataList

DataList刪除
<asp:ImageButton ID="imgBut_delete" runat="server" ImageUrl="images/CNSREJ16.GIF" CommandName="delete" />

要加入DataKeyField
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" DataKeyField="detailed_id" >

Protected Sub DataList1_DeleteCommand(source As Object, e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.DeleteCommand
    Dim keyID As Integer = Convert.ToInt32(DataList1.DataKeys(e.Item.ItemIndex))
End Sub


DataList 資料內容處理
 Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            '處理子層DataList2的資料
            Dim dl2 As DataList = CType(e.Item.FindControl("DataList2"), DataList)
            'Dim hidden2 As HiddenField = DirectCast(e.Item.FindControl("lb_needDate"), HiddenField)
            'Dim QID As String = hidden2.Value

            'If QID = 33 Then
            For Each li As DataListItem In dl2.Items
                Dim lbl As Label = DirectCast(e.Item.FindControl("lb_needDate"), Label)
                If lbl IsNot Nothing Then
                    If lbl.Text = "Self Directed" Or lbl.Text = "Systems" Then
                        lbl.Visible = False
                    End If
                End If
            Next
            'End If
        End If
    End Sub


#####
檔案上傳
多個檔案上傳




2017年6月14日 星期三

CSS 語法,文字換行,強迫不換行。

CSS 文字換行的 style 為 word-wrap ,透過這個屬性可以指定換行的方式,並可以強制文字不換行。
而 CSS 還有個空白長度的設定,透過 white-space 可以移除連續空白。
  • 文字強迫換行 word-break: break-all;
  • 依單字換行 word-wrap:break-word;
  • 死都不換行 white-space:nowrap;

換行設定, word-wrap & word-break

文字強迫換行,太長的英文字,會自動切成兩半。

  • word-break: break-all; 若一個單字過長,超過畫面的寬度,則將單字切斷,並換行。

word-break: break-all;
Before Moammar Long language string Long language string Long language string Long language string, there were the Phoenicians.
從上面的 DEMO 中可以看到 language 這個單字被切成兩斷。

文字自動換行,長英文字不切斷

  • word-wrap:break-word; 若一個單字過長,超過畫面的寬度,則將單字換行(不切斷單字)。

word-wrap:break-word;
Before Moammar Long language string Long language string Long language string Long language string, there were the Phoenicians.
不切斷英字單字對於一般的讀者是比較好懂的,唯一的缺點是右邊會出現很大的一塊空白。

空白設定 : white-space

保留原始空白與換行

  • white-space:pre; 保留原始資料的空白與換行,功能與 HTML tag 中的 <pre> 相同。
white-space:pre;
Before Moammar Gadhafi, there were the Phoenicians. And the Greeks.

強迫文字不換行

  • white-space:nowrap; 移除連續空白,移除換行符號(n r), 強迫文字不換行。
white-space:nowrap;
Before Moammar Gadhafi, there were the Phoenicians. And the Greeks. 

保留原始空白,但文字自動換行

  • white-space:pre-wrap; 保留所有空白,自動換行。
white-space:pre-wrap;
Before Moammar Gadhafi, there were the Phoenicians. And the Greeks. The Romans.

連續空白,取代成一個空白。

  • white-space: pre-line ,這個語法可以會自動將多個空白轉換成一個空白
white-space: pre-line;
Before Moammar Gadhafi, there were the Phoenicians. And the Greeks. The Romans. 

2017年6月3日 星期六

OracleConnection.BeginTransaction 方法 ()

Public Sub RunOracleTransaction(ByVal connectionString As String)
    Using connection As New OracleConnection(connectionString)
        connection.Open()

        Dim command As OracleCommand = connection.CreateCommand()
        Dim transaction As OracleTransaction

        ' Start a local transaction
        transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted)
        ' Assign transaction object for a pending local transaction
        command.Transaction = transaction

        Try
            command.CommandText = _
                "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')"
            command.ExecuteNonQuery()
            command.CommandText = _
                "INSERT INTO Dept (DeptNo, Dname, Loc) values (60, 'ENGINEERING', 'KANSAS CITY')"
            command.ExecuteNonQuery()
            transaction.Commit()
            Console.WriteLine("Both records are written to database.")
        Catch e As Exception
            transaction.Rollback()
            Console.WriteLine(e.ToString())
            Console.WriteLine("Neither record was written to database.")
        End Try
    End Using
End Sub