2014年7月29日 星期二

javascript:window.showModalDialog 需配合 gvCheckRec_RowCommand 才可以實現子視窗關閉後重新綁訂GridView

Protected Sub gvCheckRec_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvCheckRec.RowCommand
        Try
            bindGv()
        Catch ex As Exception
            MyBase.showAlertMsg(Utility.handlePageException(ex, MyBase.tracker))
        End Try
    End Sub


====================================================================
  Protected Sub gvCheckRec_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvCheckRec.RowDataBound

        Dim js As String = ""
        Dim js_Register As String = ""
        Dim ProcessName As String = ""
        Dim RespArea As String = ""
        Dim dllclass As String = ""
        Dim UniqueContent As String = ""
        Dim button As New Button
        Dim rank As Integer = 1

        Try
            If e.Row.RowType = DataControlRowType.Pager Then
                e.Row.Style.Add("text-align", "center")
                e.Row.Style.Add("height", "40px")
                e.Row.Style.Add("background-image", "")
            End If
            'GV項次
            If (e.Row.RowIndex >= 0 And e.Row.RowType = DataControlRowType.DataRow) Then

                js = "javascript:window.open('RptDcsAlm_AnaTool_Detail.aspx?"
                js &= "&rptid=RptDcsAlm_BasMgt_SumQuery.aspx"
                js &= "&start=" & Me.txtDate_OccStart.Text
                js &= "&end=" & Me.txtDate_OccEnd.Text
                js &= "&class=" & dllclass
                js &= "&TagNo=" & e.Row.Cells(1).Text
                js &= "&process=" & ProcessName
                js &= "&RespArea=" & RespArea
                'js &= "&UniqueContent=" & e.Row.Cells(3).Text

                If e.Row.Cells(3).Text <> "" Then
                    Dim source As String = e.Row.Cells(3).Text
                    Dim str As String() = New String() {","}
                    Dim UniqueContentSplit As String() = source.Split(str, StringSplitOptions.RemoveEmptyEntries)
                    Dim Uniq As String
                    Uniq = UniqueContentSplit(0)

                    If Uniq = "上下限管制異常:H " Then
                        js &= "&UniqueContent=上下限管制異常: H"
                    ElseIf Uniq = "上下限管制異常:HH " Then
                        js &= "&UniqueContent=上下限管制異常: HH"
                    ElseIf Uniq = "上下限管制異常:L " Then
                        js &= "&UniqueContent=上下限管制異常: L"
                    ElseIf Uniq = "上下限管制異常:LL " Then
                        js &= "&UniqueContent=上下限管制異常: LL"
                    End If
                End If

                If Me.ddlLevelType.SelectedIndex = 1 Then
                    js &= "&ddlLevel=Level1"
                ElseIf Me.ddlLevelType.SelectedIndex = 2 Then
                    js &= "&ddlLevel=Level2"
                ElseIf Me.ddlLevelType.SelectedIndex = 3 Then
                    js &= "&ddlLevel=Level3"
                Else
                    js &= "&ddlLevel="
                End If

                js &= "','_blank', 'status=yes,left=350,top=200,width=1100,height=500');"

                CType(e.Row.Cells(5).Controls(0), ImageButton).OnClientClick = js


                js_Register = "javascript:window.showModalDialog('MntDcsAlm_BasMgt_AlmSumRegister.aspx?"
                'js_Register = "javascript:window.open('MntDcsAlm_BasMgt_AlmSumRegister.aspx?"
                js_Register &= "&rptid=RptDcsAlm_BasMgt_SumQuery.aspx"
                js_Register &= "&start=" & Me.txtDate_OccStart.Text
                js_Register &= "&end=" & Me.txtDate_OccEnd.Text
                js_Register &= "&class=" & dllclass
                js_Register &= "&TagNo=" & e.Row.Cells(1).Text
                js_Register &= "&process=" & ProcessName
                js_Register &= "&RespArea=" & Me.ddlRespArea.SelectedValue.ToString
                js_Register &= "&RankNo=" & e.Row.Cells(0).Text
                js_Register &= "&AlarmRank=" & Me.txt_AlarmRank.Text
                js_Register &= "&UniqueContent=" & e.Row.Cells(3).Text
                js_Register &= "&AlmCnt=" & e.Row.Cells(4).Text
                If e.Row.Cells(3).Text <> "" Then
                    Dim source As String = e.Row.Cells(3).Text
                    Dim str As String() = New String() {","}
                    Dim UniqueContentSplit As String() = source.Split(str, StringSplitOptions.RemoveEmptyEntries)
                    Dim Uniq As String

                    Uniq = UniqueContentSplit(0)

                    If Uniq = "上下限管制異常:H " Then
                        js_Register &= "&UniqueContent=上下限管制異常: H"
                    ElseIf Uniq = "上下限管制異常:HH " Then
                        js_Register &= "&UniqueContent=上下限管制異常: HH"
                    ElseIf Uniq = "上下限管制異常:L " Then
                        js_Register &= "&UniqueContent=上下限管制異常: L"
                    ElseIf Uniq = "上下限管制異常:LL " Then
                        js_Register &= "&UniqueContent=上下限管制異常: LL"
                    End If
                End If



                If e.Row.Cells(2).Text = "輕故障" Then
                    js_Register &= "&ddlLevel=Level3"
                ElseIf e.Row.Cells(2).Text = "中故障" Then
                    js_Register &= "&ddlLevel=Level2"
                ElseIf e.Row.Cells(2).Text = "重故障" Then
                    js_Register &= "&ddlLevel=Level1"
                Else
                    js_Register &= "&ddlLevel="
                End If

                js_Register &= "','','dialogWidth=850px,dialogHeight=300px');window.close();"


                Dim YorN As Boolean
                If myenumber = e.Row.RowIndex Then

                    YorN = Comparison(dtCheckRecRank, myenumber)
                    myenumber += 1

                    If YorN = True Then
                        CType(e.Row.Cells(6).Controls(0), ImageButton).Visible = False
                    Else
                        CType(e.Row.Cells(6).Controls(0), ImageButton).OnClientClick = js_Register
                    End If

                End If
                Dim u As Integer = myenumber - 10
                If u = e.Row.RowIndex Then

                    YorN = Comparison(dtCheckRecRank, u)
                    myenumber += 1

                    If YorN = True Then
                        CType(e.Row.Cells(6).Controls(0), ImageButton).Visible = False
                    Else
                        CType(e.Row.Cells(6).Controls(0), ImageButton).OnClientClick = js_Register
                    End If

                End If


                'Dim YorN As Boolean
                'If myenumber <= dtCheckRecRank.Rows.Count - 1 Then
                '    'If myenumber = dtCheckRec.Rows.Count - 1 Then
                '    '    myenumber = myenumber
                '    '    YorN = Comparison(dtCheckRec, myenumber)
                '    'Else
                '    YorN = Comparison(dtCheckRecRank, myenumber)
                '    myenumber += 1
                '    'End If


                '    If YorN = True Then
                '        CType(e.Row.Cells(6).Controls(0), ImageButton).Visible = False
                '    Else
                '        CType(e.Row.Cells(6).Controls(0), ImageButton).OnClientClick = js_Register
                '    End If
                'Else
                '    myenumber = 0
                '    'If myenumber = dtCheckRec.Rows.Count - 1 Then
                '    '    myenumber = myenumber
                '    '    YorN = Comparison(dtCheckRec, myenumber)
                '    'Else
                '    YorN = Comparison(dtCheckRecRank, myenumber)
                '    myenumber += 1
                '    'End If

                '    If YorN = True Then
                '        CType(e.Row.Cells(6).Controls(0), ImageButton).Visible = False
                '    Else
                '        CType(e.Row.Cells(6).Controls(0), ImageButton).OnClientClick = js_Register
                '    End If
                'End If


            End If

        Catch ex As Exception
            MyBase.showAlertMsg(Utility.handlePageException(ex, MyBase.tracker))
        End Try

    End Sub

2014年7月23日 星期三

取出SQL 的Table名稱

                    Dim tablename As String = ""
                    Dim a As Char = " "
                    Dim split1 As String = DtDirectAccess.Rows(i)("SqlStatement")
                    split1 = split1.ToUpper
                    Dim split2 As String() = split1.Split(a)
                    For j As Integer = 0 To split2.Length - 1 Step 1
                        Dim Str1 As String = split2(j)
                        If Str1 = "FROM" Then
                            tablename = split2(j + 1)
                        End If
                    Next

2014年7月20日 星期日

[VB.NET] 時間轉換(上下午時間轉為24小時制)

   Public Function ConvertTo24hr(ByVal time As String) As String

        Dim IntAM, IntPM As Integer
        Dim IntMStr, IntMStrDay, IntMStrMins, IntMStrYear, IntMStrMonth, IntMStrHours, IntMStrSec As String
        IntAM = InStr(time, "上午") '不等於0為有上午字串
        IntPM = InStr(time, "下午")
        If time <> "" Then
            If IntAM <> 0 Then
                time = time.Replace("上午", "")
                Dim time2 As String = time
                Dim timSplit As String() = time.Split("/")
                Dim timSplit2 As String() = time2.Split(" ")
                IntMStrYear = timSplit(0)
                IntMStrMonth = timSplit(1)
                IntMStrMonth = IntMStrMonth.PadLeft(2, "0")

                time = IntMStrYear + "-" + IntMStrMonth + "-" + timSplit(2)
                IntMStrDay = time.Substring(7, 3)
                IntMStrDay = IntMStrDay.Replace("-", "")
                IntMStrDay = IntMStrDay.Replace(" ", "")
                IntMStrDay = IntMStrDay.PadLeft(2, "0")
                time = IntMStrYear + "-" + IntMStrMonth + "-" + IntMStrDay + " " + timSplit2(2)
                Dim time3 As String() = time.Split(" ")
                Dim HrMiSe As String = time3(1)
                Dim HrMiSe2 As String() = HrMiSe.Split(":")
                IntMStrHours = HrMiSe2(0)
                IntMStrMins = HrMiSe2(1)
                IntMStrSec = HrMiSe2(2)
                IntMStr = Mid(time, 12, 2)
                IntAM = Convert.ToInt32(IntMStr)
                If IntAM = 12 Then
                    IntAM = IntAM - 12
                    IntMStr = IntAM.ToString
                    IntMStr = IntMStr.PadLeft(2, "0")
                Else
                    IntAM = 0 + IntAM
                    IntMStr = IntAM.ToString
                    IntMStr = IntMStr.PadLeft(2, "0")
                End If
                time = IntMStrYear + "-" + IntMStrMonth + "-" + IntMStrDay + " " + IntMStr + ":" + IntMStrMins + ":" + IntMStrSec
            ElseIf IntPM <> 0 Then
                time = time.Replace("下午", "")
                Dim time2 As String = time
                Dim timSplit As String() = time.Split("/")
                Dim timSplit2 As String() = time2.Split(" ")
                IntMStrYear = timSplit(0)
                IntMStrMonth = timSplit(1)
                IntMStrMonth = IntMStrMonth.PadLeft(2, "0")
                time = IntMStrYear + "-" + IntMStrMonth + "-" + timSplit(2)
                IntMStrDay = time.Substring(7, 3)
                IntMStrDay = IntMStrDay.Replace("-", "")
                IntMStrDay = IntMStrDay.Replace(" ", "")
                IntMStrDay = IntMStrDay.PadLeft(2, "0")
                time = IntMStrYear + "-" + IntMStrMonth + "-" + IntMStrDay + " " + timSplit2(2)
                Dim time3 As String() = time.Split(" ")
                Dim HrMiSe As String = time3(1)
                Dim HrMiSe2 As String() = HrMiSe.Split(":")
                IntMStrHours = HrMiSe2(0)
                IntMStrMins = HrMiSe2(1)
                IntMStrSec = HrMiSe2(2)
                IntMStr = Mid(time, 12, 2)
                IntAM = Convert.ToInt32(IntMStr)
                If IntAM = 12 Then
                    IntAM = IntAM
                    IntMStr = IntAM.ToString
                    IntMStr = IntMStr.PadLeft(2, "0")
                Else
                    IntAM = 12 + IntAM
                    IntMStr = IntAM.ToString
                    IntMStr = IntMStr.PadLeft(2, "0")
                End If
                time = IntMStrYear + "-" + IntMStrMonth + "-" + IntMStrDay + " " + IntMStr + ":" + IntMStrMins + ":" + IntMStrSec
            End If
        End If
       
        Return time
    End Function