📄 wrorder.vb
字号:
Imports System
Imports System.Data
Imports System.Drawing
Imports System.Data.SqlClient
Public Class Form7
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写处置以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.TextBox3 = New System.Windows.Forms.TextBox()
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.Label5 = New System.Windows.Forms.Label()
Me.Label4 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.ListBox1 = New System.Windows.Forms.ListBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Button3 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button1 = New System.Windows.Forms.Button()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox3, Me.DateTimePicker1, Me.TextBox2, Me.TextBox1, Me.Label5, Me.Label4, Me.Label3, Me.Label2, Me.ListBox1, Me.Label1})
Me.GroupBox1.Location = New System.Drawing.Point(8, 8)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(360, 256)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "外卖订单信息"
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(176, 192)
Me.TextBox3.Multiline = True
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(160, 48)
Me.TextBox3.TabIndex = 9
Me.TextBox3.Text = "TextBox3"
'
'DateTimePicker1
'
Me.DateTimePicker1.Location = New System.Drawing.Point(176, 144)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.Size = New System.Drawing.Size(160, 21)
Me.DateTimePicker1.TabIndex = 8
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(176, 88)
Me.TextBox2.Multiline = True
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(160, 32)
Me.TextBox2.TabIndex = 7
Me.TextBox2.Text = "TextBox2"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(176, 48)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(160, 21)
Me.TextBox1.TabIndex = 6
Me.TextBox1.Text = "TextBox1"
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(176, 176)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(80, 16)
Me.Label5.TabIndex = 5
Me.Label5.Text = "送货货物请单"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(176, 128)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(56, 16)
Me.Label4.TabIndex = 4
Me.Label4.Text = "送货日期"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(176, 72)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(56, 16)
Me.Label3.TabIndex = 3
Me.Label3.Text = "送货地点"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(176, 24)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(64, 24)
Me.Label2.TabIndex = 2
Me.Label2.Text = "订单编码"
'
'ListBox1
'
Me.ListBox1.ItemHeight = 12
Me.ListBox1.Location = New System.Drawing.Point(8, 48)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(144, 196)
Me.ListBox1.TabIndex = 1
'
'Label1
'
Me.Label1.ForeColor = System.Drawing.Color.Navy
Me.Label1.Location = New System.Drawing.Point(8, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(128, 24)
Me.Label1.TabIndex = 0
Me.Label1.Text = "当前所有外卖订单:"
'
'Button3
'
Me.Button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button3.ForeColor = System.Drawing.Color.Navy
Me.Button3.Location = New System.Drawing.Point(320, 272)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(48, 24)
Me.Button3.TabIndex = 6
Me.Button3.Text = "更新"
'
'Button2
'
Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button2.ForeColor = System.Drawing.Color.Navy
Me.Button2.Location = New System.Drawing.Point(264, 272)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(48, 24)
Me.Button2.TabIndex = 5
Me.Button2.Text = "删除"
'
'Button1
'
Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button1.ForeColor = System.Drawing.Color.Navy
Me.Button1.Location = New System.Drawing.Point(208, 272)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(48, 24)
Me.Button1.TabIndex = 4
Me.Button1.Text = "添加"
'
'Form7
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(376, 303)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button3, Me.Button2, Me.Button1, Me.GroupBox1})
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Name = "Form7"
Me.Text = "登记外卖订单"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Public Sub GetAllData()
Dim sqlstr As String
Dim ds As New DataSet()
ds.Clear()
Me.ListBox1.Items.Clear()
sqlstr = "SELECT orderid FROM OrderInfo WHERE orderstyle='外卖'"
ds = GetDataFromDB(sqlstr)
Dim i As Integer
Dim temp As String
If Not ds Is Nothing Then
For i = 0 To ds.Tables(0).Rows.Count - 1
temp = Trim(ds.Tables(0).Rows(i)("orderid").ToString)
Me.ListBox1.Items.Add(temp)
Next
End If
End Sub
Public Function GetFormData() As ExOrder
Dim order As New ExOrder()
order.id = Trim(Me.TextBox1.Text)
order.rdate = CDate(Me.DateTimePicker1.Value.ToShortDateString)
order.address = Trim(Me.TextBox2.Text)
order.item = Trim(Me.TextBox3.Text)
Return order
End Function
Private Sub WrOrder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GetAllData()
If Me.ListBox1.Items.Count > 0 Then
Me.ListBox1.SetSelected(0, True)
ShowData(0)
End If
End Sub
Public Sub ShowData(ByVal index As Integer)
If index >= 0 Then
Dim order As New ExOrder()
order = GetOrderInfo(Trim(Me.ListBox1.SelectedItem.ToString))
Me.TextBox1.Text = order.id
Me.DateTimePicker1.Value = order.rdate
Me.TextBox2.Text = order.address
Me.TextBox3.Text = order.item
End If
End Sub
Public Function GetOrderInfo(ByVal orderid As String) As ExOrder
Dim sqlstr As String
Dim order As New ExOrder()
sqlstr = "SELECT * FROM OrderInfo WHERE orderid='" & orderid & "'"
Dim ds As New DataSet()
ds.Clear()
ds = GetDataFromDB(sqlstr)
If Not ds Is Nothing Then
order.id = ds.Tables(0).Rows(0)("orderid")
order.rdate = ds.Tables(0).Rows(0)("requiredate")
order.address = ds.Tables(0).Rows(0)("shipadress")
order.item = ds.Tables(0).Rows(0)("cargos")
End If
Return order
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sqlstr As String
Dim order As New ExOrder()
order = GetFormData()
If order.id = "" Then
Exit Sub
End If
If order.item = "" Then
Exit Sub
End If
sqlstr = "INSERT INTO OrderInfo (orderid,orderstyle,orderdate,requiredate,shipadress,cargos) VALUES ('" & order.id & "','外卖','" & CDate(Now.ToShortDateString) & "','" & order.rdate & "','" & order.address & "','" & order.item & "')"
UpdateData(sqlstr)
GetAllData()
ShowData(0)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sqlstr As String
sqlstr = "DELETE FROM OrderInfo WHERE orderid='" & Me.TextBox1.Text.Trim & "'"
UpdateData(sqlstr)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim order As New ExOrder()
order = GetFormData()
If order.id = "" Then
Exit Sub
End If
Dim sqlstr As String
With order
sqlstr = "UPDATE OrderInfo SET requiredate ='" & .rdate & "',shipadress ='" & .address & ",cargos='" & .item & "' WHERE orderid='" & .id & "'"
End With
UpdateData(sqlstr)
End Sub
End Class
Public Class ExOrder
Public id As String
Public rdate As Date
Public item As String
Public address As String
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -