Imports System.Data.SqlClient
Public Class frmCusShare
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 frmCusShare_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 Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
conn.Open()
Dim sql As String = "UPDATE ถอนหุ้น SET สถานะ=2 Where สถานะ=1"
com = New SqlCommand(sql, conn)
com.ExecuteNonQuery()
conn.Close()
frmMain.Show()
Me.Close()
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)
If (i > CInt(TextBox3.Text.Trim)) Then
MessageBox.Show("ถอนหุ้นเกินจำนวน", "การตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Stop)
TextBox5.Text = ""
Else
TextBox6.Text = CInt(TextBox3.Text.Trim) - i
TextBox7.Text = i * n
TextBox8.Text = CInt(TextBox4.Text.Trim) - CInt(TextBox7.Text.Trim)
End If
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) & "','" & DateValue(DateTimePicker1.Value) & "','" & 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_thun='" & 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 TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
End Class