Sub loadgridview()
SQL(0) = " select Name_RefType , Rate_Refund , case when status = '1' then 'Use' else 'Not Use' end as statusStr from " _
& " ( select ID_RefType , Name_RefType , status from Refund_Type ) as t1 " _
& " left outer join ( select ID_RefType , Rate_Refund from Refund_Rate) as t2 " _
& " on t1.ID_RefType = t2.ID_RefType where status = '1'"
DT = M1.GetDatatable(SQL(0))
Try
ViewState("data") = DT
GridView1.DataSource = DT
GridView1.DataBind()
Catch ex As Exception
GridView1 = Nothing
End Try
End Sub
Sub modEditCommand(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
GridView1.EditIndex = e.NewEditIndex
GridView1.ShowFooter = False
loadgridview()
End Sub
Sub modUpdateCommand(ByVal s As Object, ByVal e As GridViewUpdateEventArgs)
'*** nametype ***'
Dim txtType As TextBox = GridView1.Rows(e.RowIndex).FindControl("name_rate")
'*** rate ***'
Dim txtRate As TextBox = GridView1.Rows(e.RowIndex).FindControl("rate")
'*** status ***'
Dim RadStatus As RadioButtonList = GridView1.Rows(e.RowIndex).FindControl("rdlStatusEdit")
Dim rateDouble As Double = 0
Double.TryParse(txtRate.Text, rateDouble)
'alert(e.RowIndex)
SQL(0) = " UPDATE Refund_Type SET Name_RefType = '" & txtType.Text & "' " _
& " , Updated_Date = getDate() , Updated_By = 'who' , status = '" & RadStatus.SelectedValue & "' " _
& " WHERE ID_RefType = " & (e.RowIndex + 1)
M1.Execute(SQL(0))
SQL(1) = "select * from Refund_Rate where ID_RefType = " & (e.RowIndex + 1)
DT1 = M1.GetDatatable(SQL(2))
SQL(2) = " UPDATE Refund_Rate SET Rate_Refund = '" & Round(rateDouble, 2) & "' , Created_Date = getDate() , " _
& "Created_By = 'who' , Status = '" & RadStatus.SelectedValue & "' Where ID_RefType = " & (e.RowIndex + 1)
M1.Execute(SQL(2))
'objCmd = New OleDbCommand(strSQL, objConn)
'objCmd.ExecuteNonQuery()
alert("ดำเนินการเรียบร้อยแล้วค่ะ")
GridView1.EditIndex = -1
GridView1.ShowFooter = True
loadgridview()
End Sub
Sub myGridView_RowCommand(ByVal source As Object, ByVal e As GridViewCommandEventArgs)
'*** nametype ***'
Dim txtType As TextBox = CType(GridView1.FooterRow.FindControl("txtAddType"), TextBox)
'*** rate ***'
Dim txtRate As TextBox = CType(GridView1.FooterRow.FindControl("txtAddrate"), TextBox)
'*** status ***'
Dim RadStatus As RadioButtonList = CType(GridView1.FooterRow.FindControl("rdlStatus"), RadioButtonList)
Dim rateDouble As Double = 0
Double.TryParse(txtRate.Text, rateDouble)
'alert(Round(rateDouble, 2))
If e.CommandName = "Add" Then
If chkexistaddbt() = False Then
Exit Sub
ElseIf chkinputaddbt() = False Then
Exit Sub
ElseIf chkIsNumberaddbt() = False Then
Exit Sub
End If
SQL(0) = " insert into Refund_Type " _
& " ( Name_RefType , Updated_Date , Updated_By , Status ) " _
& " values ( '" & txtType.Text & "' , getdate() , 'kam' , '" & RadStatus.SelectedValue & "') "
M1.Execute(SQL(0))
SQL(1) = "select * from Refund_Type order by ID_RefType DESC"
DT = M1.GetDatatable(SQL(1))
Dim id_type As String = DT.Rows(0)("ID_RefType")
Dim statusVar As String = DT.Rows(0)("Status")
SQL(2) = " insert into Refund_Rate " _
& " ( ID_RefType , Rate_Refund , Created_Date , Created_By , Status ) " _
& " values ( '" & id_type & "' , '" & Round(rateDouble, 2) & "' , getdate() , 'kam' , '" & statusVar & "') "
M1.Execute(SQL(2))
alert("ดำเนินการเรียบร้อยแล้วค่ะ")
loadgridview()
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack() Then
loadgridview()
End If
End Sub