ผมมีอยู่ 2 form form แรกเป็นหน้าการเสนอราคา form 2 เป็นหน้าที่เราจะปริ้นใบเสนอราคาออกมา
นี่โค๊ดหน้าแรกครับ
Option Explicit On
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Public Class PriceListform
Dim reIndex As Integer
Private Sub open_conn()
If SqlConnection1.State = ConnectionState.Closed Then
SqlConnection1.Open()
End If
End Sub
Private Sub closeConn()
If SqlConnection1.State = ConnectionState.Open Then
SqlConnection1.Close()
End If
End Sub
Private Sub cleardata()
txtplsid.Clear()
cbcusid.Text = "กรุณาเลือก"
txtcusname.Clear()
txtcuslname.Clear()
Private Sub refresh_grid_p()
Dim da As SqlDataAdapter
Dim ds As DataSet
ds = New DataSet
Dim tempsql As String
Dim i As Integer = 0
tempsql = "select PriceList_id,Total_price,Deposit_price,OutstandingBalance_price,PriceList_date,Customer_id,Delivery_id from PriceList where Status =1"
da = New SqlDataAdapter(tempsql, SqlConnection1)
da.Fill(ds, "Pls")
With dgvPricelist
.ReadOnly = True
.DataSource = ds.Tables("Pls")
.Columns(0).HeaderText = "รหัสใบเสนอราคา"
.Columns(0).Width = 100
.Columns(1).HeaderText = "ราคารวม"
.Columns(1).Width = 100
.Columns(2).HeaderText = "ราคามัดจำ"
.Columns(2).Width = 100
.Columns(3).HeaderText = "ราคาค้างชำระ"
.Columns(3).Width = 100
.Columns(4).HeaderText = "วันที่เสนอราคา"
.Columns(4).Width = 100
.Columns(5).HeaderText = "รหัสลูกค้า"
.Columns(5).Width = 100
.Columns(6).HeaderText = "รหัสเขต"
.Columns(6).Width = 100
End With
End Sub
Private Sub PriceListform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
disable_screen()
refresh_grid_p()
btnsave.Enabled = False
End Sub
Private Sub autoPriceList_id()
Dim sqlcmd As SqlCommand = New SqlCommand
Dim dr As SqlDataReader
Dim tempSql As String = "select Max(PriceList_id) as PriceList_id from PriceList"
Dim tempId As String
open_conn()
Try
sqlcmd.CommandType = CommandType.Text
sqlcmd.CommandText = tempSql
sqlcmd.Connection = SqlConnection1
dr = sqlcmd.ExecuteReader
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Sub
End Try
dr.Read()
If IsDBNull(dr.Item("PriceList_id")) = True Then
txtplsid.Text = "PLS" & "0001"
Else
tempId = dr.Item("PriceList_id")
txtplsid.Text = "PLS" & (tempId.Substring(3) + 1).ToString("0000")
End If
closeConn()
End Sub
Private Sub dgvPricelist_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgvPricelist.CellMouseClick
txtplsid.Text = CStr(dgvPricelist.Rows.Item(e.RowIndex).Cells(0).Value)
txtsum.Text = CStr(dgvPricelist.Rows.Item(e.RowIndex).Cells(1).Value)
txtdepositprice.Text = CStr(dgvPricelist.Rows.Item(e.RowIndex).Cells(2).Value)
txtoutprice.Text = CStr(dgvPricelist.Rows.Item(e.RowIndex).Cells(3).Value)
dtp_pls_date.Text = CStr(dgvPricelist.Rows.Item(e.RowIndex).Cells(4).Value)
cbcusid.Text = CStr(dgvPricelist.Rows.Item(e.RowIndex).Cells(5).Value)
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim tempSql As String = "select Customer_id, Customer_name, Customer_lname from Customer where Customer_id='" & cbcusid.Text & "'"
da = New SqlDataAdapter(tempSql, SqlConnection1)
da.Fill(ds, "Cus")
If ds.Tables("Cus").Rows.Count <> 0 Then
Me.txtcusname.Text = ds.Tables("Cus").Rows(0).Item("Customer_name")
Me.txtcuslname.Text = ds.Tables("Cus").Rows(0).Item("Customer_lname")
End If
cbcusid.Enabled = True
txtdevid.Text = CStr(dgvPricelist.Rows.Item(e.RowIndex).Cells(6).Value)
Dim da1 As SqlDataAdapter
Dim ds1 As New DataSet
Dim tempSql1 As String = "select Delivery_id,Zone, Delivery_price from Delivery where Delivery_id='" & txtdevid.Text & "'"
da1 = New SqlDataAdapter(tempSql1, SqlConnection1)
da1.Fill(ds1, "Dev")
If ds1.Tables("Dev").Rows.Count <> 0 Then
Me.cbzone.Text = ds1.Tables("Dev").Rows(0).Item("Zone")
Me.txtdevprice.Text = ds1.Tables("Dev").Rows(0).Item("Delivery_price")
End If
cbzone.Enabled = True
btngetin.Enabled = False
btngetout.Enabled = False
End Sub
Private Sub getCustomername()
Dim com As SqlCommand = New SqlCommand
Dim tempSql As String = "select Customer_id from Customer"
Dim dr As SqlDataReader
Dim supTable As DataTable = New DataTable
open_conn()
Try
com.CommandText = tempSql
com.CommandType = CommandType.Text
com.Connection = Me.SqlConnection1
dr = com.ExecuteReader
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Sub
End Try
supTable.Load(dr)
cbcusid.DataSource = supTable
cbcusid.DisplayMember = "Customer_id"
closeConn()
End Sub
Private Sub cbcusid_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cbcusid.MouseDown
getCustomername()
End Sub
Private Sub cbcusid_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbcusid.SelectedIndexChanged
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim tempSql As String = "select Customer_id, Customer_name, Customer_lname from Customer where Customer_id='" & cbcusid.Text & "'"
da = New SqlDataAdapter(tempSql, SqlConnection1)
da.Fill(ds, "Cus")
If ds.Tables("Cus").Rows.Count <> 0 Then
Me.txtcusname.Text = ds.Tables("Cus").Rows(0).Item("Customer_name")
Me.txtcuslname.Text = ds.Tables("Cus").Rows(0).Item("Customer_lname")
End If
End Sub
Private Sub getZonename()
Dim com As SqlCommand = New SqlCommand
Dim tempSql As String = "select Zone from Delivery"
Dim dr As SqlDataReader
Dim supTable As DataTable = New DataTable
open_conn()
Try
com.CommandText = tempSql
com.CommandType = CommandType.Text
com.Connection = Me.SqlConnection1
dr = com.ExecuteReader
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Sub
End Try
supTable.Load(dr)
cbzone.DataSource = supTable
cbzone.DisplayMember = "Zone"
closeConn()
End Sub
Private Sub cbzone_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cbzone.MouseDown
getZonename()
End Sub
Private Sub cbzone_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbzone.SelectedIndexChanged
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim tempSql As String = "select Delivery_id, Delivery_price from Delivery where Zone='" & cbzone.Text & "'"
da = New SqlDataAdapter(tempSql, SqlConnection1)
da.Fill(ds, "Dev")
If ds.Tables("Dev").Rows.Count <> 0 Then
Me.txtdevid.Text = ds.Tables("Dev").Rows(0).Item("Delivery_id")
Me.txtdevprice.Text = ds.Tables("Dev").Rows(0).Item("Delivery_price")
End If
End Sub
Private Sub getMaterialname()
Dim com As SqlCommand = New SqlCommand
Dim tempSql As String = "select Material_name from Material"
Dim dr As SqlDataReader
Dim supTable As DataTable = New DataTable
open_conn()
Try
com.CommandText = tempSql
com.CommandType = CommandType.Text
com.Connection = Me.SqlConnection1
dr = com.ExecuteReader
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Sub
End Try
supTable.Load(dr)
cbmatname.DataSource = supTable
cbmatname.DisplayMember = "Material_name"
closeConn()
End Sub
Private Sub cbmatname_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cbmatname.MouseDown
getMaterialname()
End Sub
Private Sub cbmatname_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbmatname.SelectedIndexChanged
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim tempSql As String = "select Material_id, Material_price from Material where Material_name='" & cbmatname.Text & "'"
da = New SqlDataAdapter(tempSql, SqlConnection1)
da.Fill(ds, "Mat")
If ds.Tables("Mat").Rows.Count <> 0 Then
Me.txtmatid.Text = ds.Tables("Mat").Rows(0).Item("Material_id")
Me.txtmatprice.Text = ds.Tables("Mat").Rows(0).Item("Material_price")
End If
End Sub
Private Sub getComponentname()
Dim com As SqlCommand = New SqlCommand
Dim tempSql As String = "select Component_name from Component"
Dim dr As SqlDataReader
Dim supTable As DataTable = New DataTable
open_conn()
Try
com.CommandText = tempSql
com.CommandType = CommandType.Text
com.Connection = Me.SqlConnection1
dr = com.ExecuteReader
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Sub
End Try
supTable.Load(dr)
cbcomname.DataSource = supTable
cbcomname.DisplayMember = "Component_name"
closeConn()
End Sub
Private Sub cbcomname_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cbmatname.MouseDown
getComponentname()
End Sub
Private Sub cbcomname_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbcomname.SelectedIndexChanged
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim tempSql As String = "select Component_id, Component_price from Component where Component_name='" & cbcomname.Text & "'"
da = New SqlDataAdapter(tempSql, SqlConnection1)
da.Fill(ds, "Com")
If ds.Tables("Com").Rows.Count <> 0 Then
Me.txtcomid.Text = ds.Tables("Com").Rows(0).Item("Component_id")
Me.txtcomprice.Text = ds.Tables("Com").Rows(0).Item("Component_price")
End If
End Sub
Private Sub getInstallationname()
Dim com As SqlCommand = New SqlCommand
Dim tempSql As String = "select Installation_name from Installation"
Dim dr As SqlDataReader
Dim supTable As DataTable = New DataTable
open_conn()
Try
com.CommandText = tempSql
com.CommandType = CommandType.Text
com.Connection = Me.SqlConnection1
dr = com.ExecuteReader
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Sub
End Try
supTable.Load(dr)
cbinsname.DataSource = supTable
cbinsname.DisplayMember = "Installation_name"
closeConn()
End Sub
Private Sub cbinsname_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cbinsname.MouseDown
getInstallationname()
End Sub
Private Sub cbinsname_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbinsname.SelectedIndexChanged
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim tempSql As String = "select Installation_id, Installation_price from Installation where Installation_name='" & cbinsname.Text & "'"
da = New SqlDataAdapter(tempSql, SqlConnection1)
da.Fill(ds, "Ins")
If ds.Tables("Ins").Rows.Count <> 0 Then
Me.txtinsid.Text = ds.Tables("Ins").Rows(0).Item("Installation_id")
Me.txtinsprice.Text = ds.Tables("Ins").Rows(0).Item("Installation_price")
End If
End Sub
Private Sub calculator_Pro()
Dim temp1 As Double = 0
Dim temp2 As Double = 0
Dim temp3 As Double = 0
Dim temp4 As Double = 0
Dim temp5 As Double = 0
Dim temp6 As Double = 0
temp1 = txtmatprice.Text
temp2 = txtcomprice.Text
temp3 = txtinsprice.Text
temp4 = (temp1 + temp2 + temp3)
temp5 = (txtwidth.Text * txtlong.Text).ToString("#,##0.00")
temp6 = (temp4 * temp5)
txttotal.Text = (temp6 * txtnumber.Text)
End Sub
Private Sub txtnumber_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtnumber.TextChanged
If txtnumber.Text <> "" And txtwidth.Text = "" And txtlong.Text = "" Then
MessageBox.Show("คุณไม่ได้กรอกข้อมูลขนาดวัสดุ", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
txtnumber.Clear()
txtwidth.Focus()
End If
If txtnumber.Text <> "" And txtlong.Text = "" Then
MessageBox.Show("คุณไม่ได้กรอกข้อมูลขนาดวัสดุ", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
txtnumber.Clear()
txtlong.Focus()
End If
If IsNumeric(txtnumber.Text) = False Then
txtnumber.Text = ""
Exit Sub
End If
calculator_Pro()
End Sub
Private Sub calculator_total()
Dim tempA As Double = 0
Dim tempB As Integer = 0
Dim tempC As Integer = 0
Dim temp As Double = 0
Dim sum As Integer = 0
Dim i As Integer
For i = 0 To dgvMatdetail.Rows.Count - 2
temp = CInt(dgvMatdetail.Rows(i).Cells(13).Value) + temp
Next
txttoltalprice.Text = temp
tempA = temp * 0.07
txtvat.Text = tempA.ToString("#,##0.00")
sum = (tempA + temp + txtdevprice.Text).ToString("#,##0.00")
txtsum.Text = sum
tempB = txtsum.Text * 0.4
txtdepositprice.Text = tempB
txtoutprice.Text = (txtsum.Text - tempB)
End Sub
Private Sub clear()
cbmatname.Text = "กรุณาเลือก"
cbcomname.Text = "กรุณาเลือก"
cbinsname.Text = "กรุณาเลือก"
Me.txtmatprice.Clear()
Me.txtcomprice.Clear()
Me.txtinsprice.Clear()
txttotal.Text = "0.00"
End Sub
Private Sub btngetin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngetin.Click
If cbcusid.Text = "กรุณาเลือก" Or cbzone.Text = "กรุณาเลือก" Then
MessageBox.Show("คุณกรอกข้อมูลไม่ครบ กรุณากรอกใหม่ด้วย", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
If cbcusid.Text = "กรุณาเลือก" Then
cbcusid.Focus()
Exit Sub
ElseIf cbzone.Text = "กรุณาเลือก" Then
cbzone.Focus()
Exit Sub
End If
Exit Sub
End If
If cbmatname.Text = "กรุณาเลือก" Or cbcomname.Text = "กรุณาเลือก" Or cbinsname.Text = "กรุณาเลือก" Then
MessageBox.Show("คุณกรอกข้อมูลไม่ครบ กรุณากรอกใหม่ด้วย", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
If cbmatname.Text = "กรุณาเลือก" Then
cbmatname.Focus()
Exit Sub
End If
If cbcomname.Text = "กรุณาเลือก" Then
cbcomname.Focus()
Exit Sub
End If
If cbinsname.Text = "กรุณาเลือก" Then
cbinsname.Focus()
Exit Sub
End If
Exit Sub
End If
If txtwidth.Text = "" Or txtlong.Text = "" Or txtnumber.Text = "" Then
MessageBox.Show("คุณกรอกข้อมูลไม่ครบ กรุณากรอกใหม่ด้วย", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
If txtwidth.Text = "" Then
txtwidth.Focus()
Exit Sub
End If
If txtlong.Text = "" Then
txtlong.Focus()
Exit Sub
End If
If txtnumber.Text = "" Then
txtnumber.Focus()
Exit Sub
End If
Exit Sub
End If
If MessageBox.Show("คุณต้องการเพิ่ม ใช่หรือไม่", "คำเตือน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
dgvMatdetail.Rows.Insert(0, txtplsid.Text, txtmatid.Text, cbmatname.Text, txtmatprice.Text, txtcomid.Text, cbcomname.Text, txtcomprice.Text, txtinsid.Text, cbinsname.Text, txtinsprice.Text, txtwidth.Text, txtlong.Text, txtnumber.Text, txttotal.Text)
clear()
txtmatid.Clear()
txtcomid.Clear()
txtinsid.Clear()
txtwidth.Clear()
txtlong.Clear()
txtnumber.Clear()
End If
calculator_total()
btnsave.Enabled = True
End Sub
Private Sub dgvmatdetail_CellMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgvMatdetail.CellMouseDown
reIndex = CStr(dgvMatdetail.Rows.Item(e.RowIndex).Index.ToString)
End Sub
Private Sub btngetout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngetout.Click
If MessageBox.Show("คุณต้องการจะแก้ไขข้อมูล ใช่หรือไม่", "คำเตือน", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) = Windows.Forms.DialogResult.Yes Then
If dgvMatdetail.Rows.Count - 1 <> 0 Then
txtplsid.Text = CStr(dgvMatdetail.Rows(reIndex).Cells(0).Value)
txtmatid.Text = CStr(dgvMatdetail.Rows(reIndex).Cells(1).Value)
cbmatname.Text = CStr(dgvMatdetail.Rows(reIndex).Cells(2).Value)
txtmatprice.Text = CStr(dgvMatdetail.Rows(reIndex).Cells(3).Value)
txtcomid.Text = CStr(dgvMatdetail.Rows(reIndex).Cells(4).Value)
cbcomname.Text = CStr(dgvMatdetail.Rows(reIndex).Cells(5).Value)
txtcomprice.Text = CInt(dgvMatdetail.Rows(reIndex).Cells(6).Value)
txtinsid.Text = CStr(dgvMatdetail.Rows(reIndex).Cells(7).Value)
cbinsname.Text = CStr(dgvMatdetail.Rows(reIndex).Cells(8).Value)
txtinsprice.Text = CInt(dgvMatdetail.Rows(reIndex).Cells(9).Value)
txtwidth.Text = CStr(dgvMatdetail.Rows(reIndex).Cells(10).Value)
txtlong.Text = CStr(dgvMatdetail.Rows(reIndex).Cells(11).Value)
txtnumber.Text = CInt(dgvMatdetail.Rows(reIndex).Cells(12).Value)
txtsum.Text = CStr(dgvMatdetail.Rows(reIndex).Cells(13).Value)
dgvMatdetail.Rows.RemoveAt(reIndex)
calculator_total()
End If
End If
End Sub
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
enable_screen()
enableButton()
cleardata()
autoPriceList_id()
txtplsid.Enabled = False
btnsave.Enabled = False
End Sub
Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
Dim sqlcmd As SqlCommand
Dim sqlcommand As String
sqlcmd = New SqlCommand
sqlcommand = "update PriceList set Status = '0' where PriceList_id = '" & txtplsid.Text & "'"
sqlcommand &= "update MaterialDetail set Status = '0' where PriceList_id = '" & txtplsid.Text & "'"
If txtplsid.Text = "" Then
MessageBox.Show("กรุณาเลือกรหัสการเสนอราคาที่ต้องการลบก่อน", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Exit Sub
End If
If MessageBox.Show("คุณต้องการจะลบข้อมูล ใช่หรือไม่", "คำเตือน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
open_conn()
Try
sqlcmd.CommandType = CommandType.Text
sqlcmd.CommandText = sqlcommand
sqlcmd.Connection = SqlConnection1
sqlcmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
txtinsid.Focus()
Exit Sub
End Try
MessageBox.Show("ลบข้อมูลการติดตั้งเรียบร้อยแล้ว", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
cleardata()
disable_screen()
refresh_grid_p()
End Sub
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
Dim sqlcmd As SqlCommand
Dim sqlcommand As String
Dim ds As DataSet = New DataSet
If MessageBox.Show("ต้องการบันทึกข้อมูลใช่หรือไม่", "คำเตือน", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
Else
Exit Sub
End If
sqlcmd = New SqlCommand
open_conn()
Try
sqlcmd.CommandType = CommandType.Text
sqlcmd.CommandText = sqlcommand
sqlcmd.Connection = SqlConnection1
sqlcmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Sub
End Try
disable_screen()
disableButton()
refresh_grid_p()
cleardata()
MessageBox.Show("ระบบได้ทำการบันทึกเรียบร้อยแล้ว", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information)
btnback.Enabled = False
dgvMatdetail.Rows.Clear()
btnprint.Enabled = True
btnadd.Enabled = False
btndelete.Enabled = False
End Sub
Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click
If MessageBox.Show("คุณต้องการ ยกเลิก ใช่หรือไม่", "คำเตือน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
disable_screen()
disableButton()
cleardata()
refresh_grid_p()
txtmatprice.Clear()
txtcomprice.Clear()
txtinsprice.Clear()
txttotal.Clear()
txtdevprice.Clear()
btnback.Enabled = True
End If
End Sub
Private Sub btnback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnback.Click
If MessageBox.Show("คุณต้องการ กลับหน้าจอหลัก ใช่หรือไม่", "คำเตือน", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = Windows.Forms.DialogResult.Yes Then
Me.Hide()
Mainmenuform.Show()
End If
End Sub
Private Sub btnprint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprint.Click
rptpls.Show()
btnback.Enabled = True
btnprint.Enabled = False
btnadd.Enabled = True
btndelete.Enabled = True
End Sub
Private Sub txtwidth_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtwidth.KeyPress
If e.KeyChar >= "ก" And e.KeyChar <= "ๆ" Then
e.Handled = True
End If
If e.KeyChar >= "a" And e.KeyChar <= "z" Then
e.Handled = True
End If
End Sub
Private Sub txtlong_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtlong.KeyPress
If e.KeyChar >= "ก" And e.KeyChar <= "ๆ" Then
e.Handled = True
End If
If e.KeyChar >= "a" And e.KeyChar <= "z" Then
e.Handled = True
End If
End Sub
Private Sub txtlong_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtlong.TextChanged
If txtwidth.Text = "" And txtlong.Text <> "" Then
MessageBox.Show("คุณไม่ได้กรอกข้อมูลความกว้างของวัสดุ", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
txtlong.Clear()
txtwidth.Focus()
Exit Sub
End If
If txtwidth.Text > txtlong.Text Then
MessageBox.Show("คุณกรอกข้อมูลขนาดวัสดุไม่ถูกต้อง", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
txtwidth.Clear()
txtlong.Clear()
txtwidth.Focus()
Exit Sub
End If
End Sub
Private Sub txtnumber_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtnumber.KeyPress
If e.KeyChar >= "ก" And e.KeyChar <= "ๆ" Then
e.Handled = True
End If
If e.KeyChar >= "a" And e.KeyChar <= "z" Then
e.Handled = True
End If
End Sub
End Class
นี่เป็นโค๊ดหน้าที่จะปริ้นใบเสนอราคา
Option Explicit On
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Public Class rptpls
Dim da, da1, da2 As SqlDataAdapter
Dim ds, ds1, ds2 As New DataSet
Dim Str, Str1, Str2 As String
Dim rpt As New crppls
Dim maxPriceList_id As String
Dim checkFeedstuff As Integer
Private Sub openConn()
If SqlConnection1.State = ConnectionState.Closed Then
SqlConnection1.Open()
End If
End Sub
Private Sub closeConn()
If SqlConnection1.State = ConnectionState.Open Then
SqlConnection1.Close()
End If
End Sub
Private Sub rptpls_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ds.Tables.Clear()
Str = "Select MAX(PriceList_id) as PriceList_id from PriceList"
openConn()
da = New SqlDataAdapter(Str, SqlConnection1)
da.Fill(ds, "Max")
maxPriceList_id = ds.Tables("Max").Rows(0).Item("PriceList_id").ToString
closeConn()
ds.Tables.Clear()
ds1.Tables.Clear()
Str1 = "Select * from PriceListview Where PriceList_id ='" & maxPriceList_id & "'"
openConn()
da1 = New SqlDataAdapter(Str1, SqlConnection1)
da1.Fill(ds1, "Pls")
rpt.Database.Tables("PriceListview").SetDataSource(ds1.Tables("Pls"))
'rpt.SetParameterValue("Fname", LoginSession.Employee_FirstName)
'rpt.SetParameterValue("Lname", LoginSession.Employee_LastName)
With CrystalReportViewer1
.ReportSource = rpt
.DisplayStatusBar = True
.DisplayToolbar = True
.DisplayGroupTree = False
End With