2012年12月24日 星期一
主子資料表的新增
'新增資料到訂貨主檔
'儲存資料後,超連結到顯示訂單的網頁
Dim connstr As String = "Data Source=120.xxx.xx.xxx;UID=xx;PWD=xx;Database=北風貿易"
Dim sqlconn As SqlConnection = New SqlConnection(connstr)
Dim sqlcmdstr As String = "insert into 訂貨主檔(客戶編號, 員工編號, 訂單日期, 要貨日期, 送貨方式) values(@客戶編號, @員工編號, @訂單日期, @要貨日期, @送貨方式);select @@IDENTITY"
Dim sqlcmd As New SqlCommand(sqlcmdstr, sqlconn)
sqlcmd.Parameters.AddWithValue("@客戶編號", Me.TextBox1.Text)
sqlcmd.Parameters.AddWithValue("@員工編號", Me.TextBox6.Text)
sqlcmd.Parameters.AddWithValue("@訂單日期", Me.TextBox2.Text)
sqlcmd.Parameters.AddWithValue("@要貨日期", Me.TextBox4.Text)
sqlcmd.Parameters.AddWithValue("@送貨方式", Me.TextBox5.Text)
'sqlcmd.Parameters.AddWithValue("@newid", Me.TextBox7.Text)
'sqlcmd.Parameters.AddWithValue("@訂單日期", Me.TextBox2.Text)
sqlconn.Open()
Dim result As SqlDataReader
result = sqlcmd.ExecuteReader
If result.HasRows Then
Do While result.Read()
'Response.Write(result(0).ToString)
Me.Label1.Text = result(0).ToString
Me.TextBox3.Text = result(0).ToString
Loop
Else
Response.Write("No rows returned.")
End If
result.Close()
'result.Read()
sqlconn.Close()
'Response.Write(result.ToString)
'Response.Redirect("gridview.aspx")
Me.GridView1.DataBind()
Protected Sub FormView1_ItemInserted(sender As Object, e As System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles FormView1.ItemInserted
'當子資料表有新項目新增時, 更新下方的訂單明細gridview1
Me.GridView1.DataBind()
End Sub
Protected Sub FormView1_PreRender(sender As Object, e As EventArgs) Handles FormView1.PreRender
'當formview重新整理時,將訂單號碼填進去
Dim orderid As TextBox = CType(Me.FormView1.FindControl("訂單號碼TextBox"), TextBox)
orderid.Text = Me.TextBox3.Text
End Sub
Private Sub Calendar2_DayRender(sender As Object, e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar2.DayRender
'限制只能在7天以後開放選取交期
e.Day.IsSelectable = e.Day.Date > Now.AddDays(7).ToShortDateString
End Sub
Protected Sub Calendar2_SelectionChanged(sender As Object, e As EventArgs) Handles Calendar2.SelectionChanged
'輸入交期
Me.TextBox4.Text = Me.Calendar2.SelectedDate
End Sub
'更新產品編號
Protected Sub DropDownList4_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim productid As TextBox = CType(Me.FormView1.FindControl("產品編號TextBox"), TextBox)
Dim drop_product As DropDownList = CType(Me.FormView1.FindControl("DropDownList4"), DropDownList)
productid.Text = drop_product.SelectedValue.ToString
'Dim ds As DataSet = SqlDataSource1.Select
Dim connstr As String = "Data Source=xxx.xx.xx.xx;UID=xx;PWD=xx;Database=北風貿易"
Dim sqlconn As SqlConnection = New SqlConnection(connstr)
Dim cmd As New SqlCommand("select 單價 from 產品資料 where 產品編號 = @prodid", sqlconn)
cmd.Parameters.AddWithValue("@prodid", Int(drop_product.SelectedValue))
Dim reader As SqlDataReader
sqlconn.Open()
reader = cmd.ExecuteReader
If reader.Read Then
Dim price_text As TextBox = CType(Me.FormView1.FindControl("單價TextBox"), TextBox)
price_text.Text = reader(0).ToString
End If
sqlconn.Close()
End Sub
If Me.TextBox3.Text <> "" Then
Dim connstr As String = "Data Source=xxx.xxx.xx.xx;UID=xx;PWD=xx;Database=北風貿易"
Dim sqlconn As SqlConnection = New SqlConnection(connstr)
Dim cmd As SqlCommand
cmd = New SqlCommand("delete 訂貨主檔 where 訂單號碼='" & Me.TextBox3.Text & "'", sqlconn)
Dim result As Integer
sqlconn.Open()
result = cmd.ExecuteNonQuery
Response.Write(result)
sqlconn.Close()
'If result = -1 Then
Me.TextBox3.Text = ""
Dim orderid As TextBox = CType(Me.FormView1.FindControl("訂單號碼TextBox"), TextBox)
orderid.Text = ""
Me.TextBox4.Text = ""
'End If
End If
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言