'' ประกาศ C1 , C2 เป็น Global
Private Sub DataGridView1_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
If e.RowIndex = -1 Then Exit Sub
If DataGridView1.CurrentRow.Index < pro.Rows.Count Then '' เทียบข้อมูลใน datagridview กับ datatable
With DataGridView1
C1 = .Rows.Item(e.RowIndex).Cells(0).Value '' กรณี textbox, datetimepicker อยู่ในฟอร์มเดียวกัน
C2 = .Rows.Item(e.RowIndex).Cells(1).Value
End With
End If
Dim i As Integer = 0
If C1 = "" Then Exit Sub ''check ข้อมูลใน C1
For i = 0 To DataGridView2.Rows.Count - 1
With DataGridView2
.Rows.Item(i).Cells(0).Value = C1
.Rows.Item(i).Cells(1).Value = C2
End With
Next
End Sub
Imports System.Data.SqlClient
Imports System.Data
Public Class FormCheckReceived
Dim conn As SqlConnection
Dim ds As DataSet
Dim c1, c2, c3, c4, c5, c6, c7 As Global.System.String
Dim IsFind As Boolean = False
Dim dt As DataTable
Private Sub FormCheckReceived_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New SqlClient.SqlConnection()
Dim cmd As New SqlClient.SqlCommand()
Dim sql2 As String = "SELECT id,date,order_id,pharmacist_id,supplier_id,quantity,total FROM received"
Dim cmd1 As New SqlClient.SqlCommand(sql2, conn)
Dim Result As New SqlCommand
Dim adapter As New SqlDataAdapter(cmd1)
Dim data As New DataSet()
conn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Documents and Settings\User\My Documents\Visual Studio 2008\Projects\PROJECT MORYA.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True"
conn.Open()
cmd.Connection = conn
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim com As New SqlCommand
Dim conn As New SqlClient.SqlConnection()
Dim cmd As New SqlClient.SqlCommand()
conn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Documents and Settings\User\My Documents\Visual Studio 2008\Projects\PROJECT MORYA.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True"
conn.Open()
com.CommandText = "Select * from received"
com.CommandType = CommandType.StoredProcedure
com.Connection = conn
cmd.Connection = conn
cmd.CommandText = ""
'cmd.ExecuteNonQuery()
Dim da As New SqlDataAdapter(com)
Dim ds As New DataSet
da.SelectCommand.Parameters.Add("BeginDate", SqlDbType.Date).Value = dtpstart.Value.ToString("s")
da.SelectCommand.Parameters.Add("EndingDate", SqlDbType.Date).Value = dtpend.Value.ToString("s")
If (IsFind = True) Then
ds.Tables("recevied").Clear()
End If
da.Fill(ds, "received")
If ds.Tables("recevied").Rows.Count <> 0 Then
IsFind = True
DataGridView1.ReadOnly = True
DataGridView1.DataSource = ds.Tables("received")
Else
IsFind = False
MessageBox.Show("ช่วงเวลาที่คุณระบุ ไม่มีรายการขาย", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Dim MyString As String = "12345"
Dim MyInt As Integer = Integer.Parse(MyString)
MyInt += 1
Console.WriteLine(MyInt)
' The result is "12346".
conn.Close()
End Sub
Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
process.Visible = True
End Sub
Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
process.Visible = False
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
If MessageBox.Show("ต้องการออกจากการตรวจสอบการรับสินค้าใช่หรือไม่", "ออกจากระบบ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = vbYes Then
Me.Close()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
If Me.DataGridView1.Rows.Count - 1 > 0 Then
If Not DataGridView1.CurrentRow.IsNewRow Then
MessageBox.Show("คุณต้องการลบข้อมูลใช่หรือไม่", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Question)
DataGridView1.Rows.Remove(DataGridView1.CurrentRow)
Else
MsgBox("Is Noting DATA", MsgBoxStyle.Information)
End If
Else
MsgBox("Is Not DATA", MsgBoxStyle.Information)
End If
Me.Cursor = Cursors.Default
End Sub
Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
Dim j As Integer = 0 '' วิธีแรกครับ
Dim SumPrice As Double = 0
For j = 0 To DataGridView1.Rows.Count - 1
SumPrice += CDbl(DataGridView1.Rows(j).Cells(6).Value)
Next
sales_total.Text = SumPrice.ToString("#,##0.00")
Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
If e.RowIndex = -1 Then Exit Sub
If DataGridView1.CurrentRow.Index < DataGridView1.Rows.Count Then '' เทียบข้อมูลใน datagridview กับ datatable
With (DataGridView1)
c1 = .Rows.Item(e.RowIndex).Cells(0).Value '' กรณี textbox, datetimepicker อยู่ในฟอร์มเดียวกัน
c2 = .Rows.Item(e.RowIndex).Cells(1).Value
c3 = .Rows.Item(e.RowIndex).Cells(2).Value
c4 = .Rows.Item(e.RowIndex).Cells(3).Value
c5 = .Rows.Item(e.RowIndex).Cells(4).Value
c6 = .Rows.Item(e.RowIndex).Cells(5).Value
c7 = .Rows.Item(e.RowIndex).Cells(6).Value
End With
End If
Dim i As Integer = 0
If c1 = "" Then Exit Sub ''check ข้อมูลใน C1
For i = 0 To DataGridView2.Rows.Count - 1
With (DataGridView2)
.Rows.Item(i).Cells(0).Value = c1
.Rows.Item(i).Cells(1).Value = c2
.Rows.Item(i).Cells(0).Value = c3
.Rows.Item(i).Cells(1).Value = c4
.Rows.Item(i).Cells(0).Value = c5
.Rows.Item(i).Cells(1).Value = c6
.Rows.Item(i).Cells(1).Value = c7
End With
Next
End Sub
Private Sub DataGridView1_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
If e.RowIndex = -1 Then Exit Sub
If DataGridView1.CurrentRow.Index < DataGridView2.Rows.Count Then '' เทียบข้อมูลใน datagridview กับ datatable
With (DataGridView1)
c1 = .Rows.Item(e.RowIndex).Cells(0).Value '' กรณี textbox, datetimepicker อยู่ในฟอร์มเดียวกัน
c2 = .Rows.Item(e.RowIndex).Cells(1).Value
c3 = .Rows.Item(e.RowIndex).Cells(2).Value
c4 = .Rows.Item(e.RowIndex).Cells(3).Value
c5 = .Rows.Item(e.RowIndex).Cells(4).Value
End With
End If
Dim i As Integer = 0
If c1 = "" Then Exit Sub ''check ข้อมูลใน C1
For i = 0 To DataGridView2.Rows.Count - 1
With (DataGridView2)
.Rows.Item(i).Cells(0).Value = c1
.Rows.Item(i).Cells(1).Value = c2
.Rows.Item(i).Cells(2).Value = c3
.Rows.Item(i).Cells(3).Value = c4
.Rows.Item(i).Cells(4).Value = c5
End With
Next
End Sub
Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
'................แสดงหมายเลขลำดับที่...............
Using b As SolidBrush = New SolidBrush(Me.DataGridView1.RowHeadersDefaultCellStyle.ForeColor)
e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), _
Me.DataGridView1.DefaultCellStyle.Font, _
b, e.RowBounds.Location.X + 5, _
e.RowBounds.Location.Y + 5)
End Using
End Sub
Private Sub DataGridView2_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView2.RowPostPaint
'................แสดงหมายเลขลำดับที่...............
Using b As SolidBrush = New SolidBrush(Me.DataGridView2.RowHeadersDefaultCellStyle.ForeColor)
e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), _
Me.DataGridView2.DefaultCellStyle.Font, _
b, e.RowBounds.Location.X + 5, _
e.RowBounds.Location.Y + 5)
End Using
End Sub
End Class