Imports System.Data.SqlClient
Public Class frmAddShare
Dim conn As SqlConnection
Dim com As SqlCommand
Dim ap As SqlDataAdapter
Dim ds As New DataSet()
Dim dt As New DataTable
Dim dr As SqlDataReader
Dim numm As Integer = 0
Dim n As Integer = 0
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
conn.Close()
frmMain.Show()
Me.Close()
End Sub
Private Sub frmAddShare_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn = New SqlConnection()
With conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = Database.strConn.ToString
.Open()
End With
Number()
ShowData()
TextBox9.Text = frmLogin.b.ToString()
End Sub
Private Sub ShowData()
With conn
If .State = ConnectionState.Open Then .Close()
.Open()
End With
ds.Clear()
Dim sql As String = "Select รหัสการเพิ่มหุ้น,รหัสสมาชิก,ชื่อสมาชิก,จำนวนหุ้นที่เพิ่ม,มูลค่าในการเพิ่มหุ้น From เพิ่มหุ้น Where สถานะ =1 Order by รหัสการเพิ่มหุ้น"
com = New SqlCommand(sql, conn)
ap = New SqlDataAdapter(com)
ap.Fill(ds, "เพิ่มหุ้น")
DataGridView1.DataSource = ds.Tables("เพิ่มหุ้น")
DataGridView1.Columns.Item(0).Width = 120
DataGridView1.Columns.Item(1).Width = 110
DataGridView1.Columns.Item(2).Width = 200
DataGridView1.Columns.Item(3).Width = 130
DataGridView1.Columns.Item(4).Width = 138
conn.Close()
End Sub
Private Sub Number()
With conn
If .State = ConnectionState.Open Then .Close()
.Open()
End With
dt.Clear()
Dim sql2 As String = "SELECT รหัสการเพิ่มหุ้น FROM เพิ่มหุ้น"
com = New SqlCommand()
With com
.CommandType = CommandType.Text
.CommandText = sql2
.Connection = conn
.Parameters.Clear()
.Parameters.Add("รหัสการเพิ่มหุ้น", SqlDbType.VarChar).Value = "001"
dr = .ExecuteReader()
If dr.HasRows Then
dt = New DataTable
dt.Load(dr)
numm = (CInt(dt.Rows(dt.Rows.Count - 1).Item("รหัสการเพิ่มหุ้น").ToString)) + 1
dt.Clear()
dr.Close()
conn.Close()
If (numm < 10) Then
TextBox10.Text = "00" & numm
Else
TextBox10.Text = "0" & numm
End If
Else
conn.Close()
TextBox10.Text = "001"
End If
End With
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
With conn
If .State = ConnectionState.Open Then .Close()
.Open()
End With
Try
Dim ac As String = "SELECT * FROM member where m_id ='" & TextBox1.Text.Trim & "'"
com = New SqlCommand
With com
.CommandType = CommandType.Text
.CommandText = ac
.Connection = conn
.Parameters.Clear()
.Parameters.Add("member", SqlDbType.VarChar).Value = TextBox1.Text.Trim
dr = .ExecuteReader()
If dr.HasRows Then
dt = New DataTable
dt.Load(dr)
TextBox2.Text = dt.Rows(0).Item("m_name").ToString
TextBox3.Text = dt.Rows(0).Item("m_nhun").ToString
n = CInt(dt.Rows(0).Item("m_phun").ToString)
TextBox4.Text = dt.Rows(0).Item("m_thun").ToString
dr.Close()
conn.Close()
Else
End If
End With
Catch ex As Exception
End Try
End Sub
Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
Try
Dim i As Integer = CInt(TextBox5.Text.Trim)
TextBox6.Text = i + CInt(TextBox3.Text.Trim)
TextBox7.Text = i * n
TextBox8.Text = CInt(TextBox4.Text.Trim) + CInt(TextBox7.Text.Trim)
Catch ex As Exception
TextBox5.Text = ""
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With conn
If .State = ConnectionState.Open Then .Close()
.Open()
End With
Try
If TextBox1.Text = "" Or TextBox5.Text = "" Then
MessageBox.Show("กรุณากรอกข้อมูลให้ครบทุกช่องด้วยค่ะ", "การตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
Dim SQL1 As String = "INSERT INTO เพิ่มหุ้น(รหัสการเพิ่มหุ้น,รหัสสมาชิก,ชื่อสมาชิก,จำนวนหุ้นที่เพิ่ม,มูลค่าในการเพิ่มหุ้น,วันที่เพิ่มหุ้น,ชื่อพนักงาน) VALUES('" & TextBox10.Text & "','" & TextBox1.Text & "','" & TextBox2.Text & "','" & CInt(TextBox5.Text) & "','" & CInt(TextBox7.Text) & "','" & DateTimePicker1.Text & "','" & TextBox9.Text & "',1)"
com = New SqlCommand(SQL1, conn)
com.ExecuteNonQuery()
conn.Close()
conn.Open()
Dim sql As String = "UPDATE member SET m_nhun ='" & TextBox6.Text.Trim & "',m_phun ='" & TextBox8.Text.Trim & "' Where m_id ='" & TextBox1.Text.Trim & "'"
com = New SqlCommand(sql, conn)
com.ExecuteNonQuery()
conn.Close()
Clear()
ShowData()
End If
Catch ex As Exception
End Try
End Sub
Private Sub Clear()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
TextBox8.Clear()
Number()
TextBox1.Focus()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Clear()
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
End Sub
End Class