Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > อยากรู้เรื่องการส่งค่าข้าม form ของ vb 2005 ผมมีอยู่ 2 form form แรกเป็นหน้าการเสนอราคา



 

อยากรู้เรื่องการส่งค่าข้าม form ของ vb 2005 ผมมีอยู่ 2 form form แรกเป็นหน้าการเสนอราคา

 



Topic : 039422



โพสกระทู้ ( 47 )
บทความ ( 0 )



สถานะออฟไลน์




ผมมีอยู่ 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()

cbmatname.Text = "กรุณาเลือก"
txtmatid.Clear()
txtmatprice.Clear()

cbcomname.Text = "กรุณาเลือก"
txtcomid.Clear()
txtcomprice.Clear()

cbinsname.Text = "กรุณาเลือก"
txtinsid.Clear()
txtinsprice.Clear()

cbzone.Text = "กรุณาเลือก"
txtdevid.Clear()
txtdevprice.Clear()

txtwidth.Clear()
txtlong.Clear()
txtnumber.Clear()

txttotal.Clear()
txttoltalprice.Clear()
txtvat.Clear()
txtsum.Clear()
txtdepositprice.Clear()
txtoutprice.Clear()
End Sub

Private Sub enable_screen()
txtplsid.Enabled = True
txtpricedate.Enabled = True

cbcusid.Enabled = True
txtcusname.Enabled = False
txtcuslname.Enabled = False

cbzone.Enabled = True
txtdevid.Enabled = False
txtdevprice.Enabled = False

cbmatname.Enabled = True
txtmatid.Enabled = False
txtmatprice.Enabled = False

cbcomname.Enabled = True
txtcomid.Enabled = False
txtcomprice.Enabled = False

cbinsname.Enabled = True
txtinsid.Enabled = False
txtinsprice.Enabled = False

txtwidth.Enabled = True
txtlong.Enabled = True
txtnumber.Enabled = True

txttotal.Enabled = False
txttoltalprice.Enabled = False
txtvat.Enabled = False
txtsum.Enabled = False
txtdepositprice.Enabled = False
txtoutprice.Enabled = False

btngetin.Enabled = True
btngetout.Enabled = True

dtp_pls_date.Enabled = True
End Sub

Private Sub disable_screen()
txtplsid.Enabled = False
txtpricedate.Enabled = False

cbcusid.Enabled = False
txtcusname.Enabled = False
txtcuslname.Enabled = False

cbzone.Enabled = False
txtdevid.Enabled = False
txtdevprice.Enabled = False

cbmatname.Enabled = False
txtmatid.Enabled = False
txtmatprice.Enabled = False

cbcomname.Enabled = False
txtcomid.Enabled = False
txtcomprice.Enabled = False

cbinsname.Enabled = False
txtinsid.Enabled = False
txtinsprice.Enabled = False

txtwidth.Enabled = False
txtlong.Enabled = False
txtnumber.Enabled = False

txttotal.Enabled = False
txttoltalprice.Enabled = False
txtvat.Enabled = False
txtsum.Enabled = False
txtdepositprice.Enabled = False
txtoutprice.Enabled = False

btngetin.Enabled = False
btngetout.Enabled = False
btnprint.Enabled = False
dtp_pls_date.Enabled = False
End Sub

Private Sub enableButton()
btnadd.Enabled = False
btndelete.Enabled = False
btnsave.Enabled = True
btncancel.Enabled = True
btnback.Enabled = False
btnprint.Enabled = False
btngetin.Enabled = True
btngetout.Enabled = True
dgvPricelist.Enabled = True
dgvMatdetail.Enabled = True
End Sub

Private Sub disableButton()
btnadd.Enabled = True
btndelete.Enabled = True
btnsave.Enabled = False
btncancel.Enabled = False
btnback.Enabled = False
btnprint.Enabled = False
btngetin.Enabled = False
btngetout.Enabled = False
dgvPricelist.Enabled = True
dgvMatdetail.Enabled = True
End Sub

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

sqlcommand = "insert into PriceList(PriceList_id,Total_price,Deposit_price,OutstandingBalance_price,PriceList_date,Customer_id,Delivery_id,Status)"
sqlcommand &= "values('" & txtplsid.Text & "','"
sqlcommand &= CInt(txtsum.Text) & "','"
sqlcommand &= CInt(txtdepositprice.Text) & "','"
sqlcommand &= CInt(txtoutprice.Text) & "','"
sqlcommand &= dtp_pls_date.Value.Month & "/" & dtp_pls_date.Value.Day & "/" & dtp_pls_date.Value.Year & "','"
sqlcommand &= cbcusid.Text & "','"
sqlcommand &= txtdevid.Text & "','1')"
Dim i As Integer
For i = 0 To dgvMatdetail.Rows.Count - 2
sqlcommand &= "insert into MaterialDetail(PriceList_id,Material_id,Material_price,Component_id,Component_price,Installation_id,Installation_price,Width_material,Long_material,Material_Amount,Sum_price,Status)"
sqlcommand &= "values('" & txtplsid.Text & "','"
sqlcommand &= dgvMatdetail.Rows(i).Cells(1).Value & "','" 'mat
sqlcommand &= CInt(dgvMatdetail.Rows(i).Cells(3).Value) & "','"
sqlcommand &= dgvMatdetail.Rows(i).Cells(4).Value & "','" 'com
sqlcommand &= CInt(dgvMatdetail.Rows(i).Cells(6).Value) & "','"
sqlcommand &= dgvMatdetail.Rows(i).Cells(7).Value & "','" 'ins
sqlcommand &= CInt(dgvMatdetail.Rows(i).Cells(9).Value) & "','"

sqlcommand &= CInt(dgvMatdetail.Rows(i).Cells(10).Value) & "','"
sqlcommand &= CInt(dgvMatdetail.Rows(i).Cells(11).Value) & "','"

sqlcommand &= CInt(dgvMatdetail.Rows(i).Cells(12).Value) & "','"
sqlcommand &= CInt(dgvMatdetail.Rows(i).Cells(13).Value) & "','1')"
Next

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



closeConn()
End Sub
End Class

โค๊ดในส่วนหน้าปริ้นใบเสนอราคา มันจะดึงค่า max id ในเบสมาแสดงเท่านั้น
ผมอยากทราบว่า เราจะเลือกรหัสได้เองตามที่เราต้องการไหม
ถ้าเลือกได้ เราจะส่งค่าไอดีจากหน้าแรก มาให้หน้าที่ 2 รู้ได้อย่างไรว่าต้องปริ้นรหัสตามหน้าแรกอ่าครับ
ขอรบกวนท่านผู้รู้ทุกท่าน ช่วยบอกด้วยนะครับ
ผมมือใหม่มาก ๆ เลยในการเขียนโปรแกรม ไม่ค่อยรู้เรื่องเท่าไหร่
ขอขอบคุณมาก ๆ เลยครับ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-02-22 16:44:20 By : fakestar View : 2088 Reply : 2
 

 

No. 1



โพสกระทู้ ( 373 )
บทความ ( 0 )



สถานะออฟไลน์


อ่านแล้วมึนตึบ เอาวิธีนี้ไปใช้แล้วกัน
ถ้า form1 เรียก form2 ผมเข้าใจถูกไหม?
ให้ pass argument เข้า form2 แล้วกันน่ะ

code ด้านล่างเป็น Sub Main Form2 นะ ลองเอาไปดัดแปลงดู

Shared Sub Main(ByVal args As String())
For Each arg As String In args
Console.WriteLine(arg)
Next arg
Console.ReadLine()
End Sub

ความจริงถ้าคุณรู้เรื่อง global variable ก็ไม่เห็นต้องทำอะไรยุ่งยากครับ ลองไปศึกษาดูครับ






Date : 2010-02-22 17:09:51 By : numenoy
 


 

No. 2



โพสกระทู้ ( 4 )
บทความ ( 0 )



สถานะออฟไลน์


ถ้า 2008 ผมพอรู้คับ คุณต้องกำหนดตัวแปรมา แชร์ ข้อมูล
แต่ 2005 มะเคยเรียน
Date : 2010-02-25 14:58:34 By : t1u2m3
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : อยากรู้เรื่องการส่งค่าข้าม form ของ vb 2005 ผมมีอยู่ 2 form form แรกเป็นหน้าการเสนอราคา
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่