 |
|
VB.NET ต้องการเรียกข้อมูลช่างมาอัตโนมัติเมื่อมีงานที่ตรงกับหน้าที่ วนเรื่อยๆ แล้วก็ขอคำอธิบายกับตัวอย่างโค้ด report และ print รบกวนด้วยนะคะ |
|
 |
|
|
 |
 |
|
เอาโค้ดมาดูด้วยคับท่าน จะได้ช่วยดู..
|
 |
 |
 |
 |
Date :
2011-09-09 17:55:18 |
By :
lee_latee |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค้ดปุ่ม save ค่ะ
Dim CusID As String = txtCusID.Text.Trim
Dim CusName As String = txtCusName.Text.Trim
Dim CusLname As String = txtCusLname.Text.Trim
Dim CusAdd As String = txtCusAdd.Text.Trim
Dim CusMobile As String = txtCusMobile.Text.Trim
Dim CusType As String = cbbCusType.Text
Dim EmpID As String = txtEmpID.Text.Trim
Dim EmpName As String = txtEmpName.Text.Trim
Dim EmpSurname As String = txtEmpSurname.Text.Trim
Dim EmpClass As String = cbbClass.Text
Dim EmpMobile As String = txtEmpMobile.Text.Trim
Dim WDetail As String = txtWDetail.Text.Trim
Dim Wstatus As String = "ปกติ"
Dim WArea As String = cbbArea.Text
Dim WOrder As String = cbbOrder.Text
If cbbOrder.SelectedItem = "ติดตั้ง,เดินสายภายใน" Then
WOrder = "E1"
ElseIf cbbOrder.SelectedItem = "ตรวจสอบ,ซ่อมแซมบริการอินเตอร์เน็ต" Then
WOrder = "E2"
ElseIf cbbOrder.SelectedItem = "ตรวจสอบ,ซ่อมแซมบริการโทรศัพท์" Then
WOrder = "E3"
End If
If cbbArea.SelectedItem = "เขตดินแดง" Then
WArea = "W001"
ElseIf cbbArea.SelectedItem = "เขตพญาไท" Then
WArea = "W002"
ElseIf cbbArea.SelectedItem = "เขตราชเทวี" Then
WArea = "W003"
ElseIf cbbArea.SelectedItem = "เขตสามเสน" Then
WArea = "W004"
End If
Select Case actionFlag
Case "ADD"
AutoGenearteMember_id()
Dim WorkID As String = txtWorkID.Text.Trim
sqlcmd = "INSERT INTO tbDetailWork(WorkID,CusID,CusType,CusName,CusSurname,Address,CusMoblie,EmpID,EmpName,EmpSurname,EmpMoblie,WAreaID,DID,WorkODDetail,WorkODTime,WorkWTime,Status) VALUES ('" & WorkID & "','" & CusID & "','" & CusType & "','" & CusName & "','" & CusLname & "','" & CusAdd & "','" & CusMobile & "','" & EmpID & "','" & EmpName & "','" & EmpSurname & "','" & EmpMobile & "','" & WArea & "','" & WOrder & "','" & WDetail & "','" & cnvDateToSql(txtOD.Text) & "','" & cnvDateToSql(txtWD.Text) & "','" & Wstatus & "')"
Case "EDIT"
Dim WorkID As String = txtWorkID.Text.Trim
sqlcmd = "Update tbDetailWork set WAreaID='" + WArea + "',DID='" + WOrder + "',WorkODDetail='" + WDetail + "',WorkODTime='" + cnvDateToSql(txtOD.Text) + "',WorkWTime='" + cnvDateToSql(txtWD.Text) + "',Status='" + Wstatus + "' Where WorkID =" & WorkID
End Select
Cnnstring = "Data Source=CHOKO-PC;Initial Catalog=DBPMs;Persist Security Info=True;User Id=pms;Password=project"
'MessageBox.Show(Sqlcmd)
Dim cn As New System.Data.SqlClient.SqlConnection(Cnnstring)
Dim cm As New SqlCommand(sqlcmd, cn)
Dim dr As SqlDataReader
cn.Open()
dr = cm.ExecuteReader
cn.Close()
MsgBox("บันทึกข้อมูลเรียบร้อยแล้ว")
ShowData()
ClearForm(GroupBox1)
cbbClass.Text = ""
cbbArea.Text = ""
cbbOrder.Text = ""
cbbCusType.Text = ""
dgvDetail.Enabled = True
btnAdd.Enabled = True
btnClear.Enabled = False
btnSave.Enabled = False
txtCusID.Enabled = False
txtCusName.Enabled = False
txtCusLname.Enabled = False
txtCusAdd.Enabled = False
txtCusMobile.Enabled = False
cbbCusType.Enabled = False
txtEmpID.Enabled = False
txtEmpName.Enabled = False
txtEmpSurname.Enabled = False
cbbClass.Enabled = False
txtEmpMobile.Enabled = False
txtWorkID.Enabled = False
cbbArea.Enabled = False
cbbOrder.Enabled = False
txtWDetail.Enabled = False
txtOD.Enabled = False
txtWD.Enabled = False
End Sub
โค้ดดึงข้อมูลที่ตอนนี้ใช้พิมพ์เอาน่ะค่ะ
Private Sub txtCusID_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtCusID.KeyDown
If txtCusID.Text <> "" Then
If (e.KeyCode = Keys.Enter) Then
Dim sqlCus As String = ""
sqlCus = "SELECT * FROM tbCus WHERE CusID = '" & txtCusID.Text & " ' order by CusID"
Cnnstring = "Data Source=CHOKO-PC;Initial Catalog=DBPMs;Persist Security Info=True;User Id=pms;Password=project"
With Cnn 'เริ่มต้นเชื่อมฐานข้อมูล
If .State = ConnectionState.Open Then .Close()
.ConnectionString = Cnnstring
.Open() 'เชื่อมต่อฐานข้อมูล
End With
If IsFind = True Then
ds.Tables("tbCus").Clear()
End If
da.SelectCommand.CommandText = sqlCus
da.Fill(ds, "tbCus")
If ds.Tables("tbCus").Rows.Count <> 0 Then
IsFind = True
ClearAllBinding()
txtCusID.DataBindings.Add("Text", ds, "tbCus.CusID")
txtCusName.DataBindings.Add("Text", ds, "tbCus.CusName")
txtCusLname.DataBindings.Add("Text", ds, "tbCus.CusSurname")
txtCusAdd.DataBindings.Add("Text", ds, "tbCus.Address")
txtCusMobile.DataBindings.Add("Text", ds, "tbCus.CusMoblie")
cbbCusType.DataBindings.Add("Text", ds, "tbCus.CusType")
cbbArea.DataBindings.Add("Text", ds, "tbCus.WAreaID")
Dim dt As DataTable
dt = ds.Tables("tbCus")
txtWDetail.Focus()
Else
IsFind = False
MsgBox("ไม่มีลูกค้าที่คุณระบุ")
ClearForm(GroupBox2)
txtCusID.Focus()
txtCusID.SelectAll()
End If
End If
End If
End Sub
Private Sub txtEmpID_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtEmpID.KeyDown
If txtEmpID.Text <> "" Then
If (e.KeyCode = Keys.Enter) Then
Dim sqlEmp As String = ""
sqlEmp = "SELECT * FROM tbEMP WHERE EmpID = '" & txtEmpID.Text & " ' order by EmpID"
Cnnstring = "Data Source=CHOKO-PC;Initial Catalog=DBPMs;Persist Security Info=True;User Id=pms;Password=project"
With Cnn 'เริ่มต้นเชื่อมฐานข้อมูล
If .State = ConnectionState.Open Then .Close()
.ConnectionString = Cnnstring
.Open() 'เชื่อมต่อฐานข้อมูล
End With
If IsFind2 = True Then
ds.Tables("tbEMP").Clear()
End If
da.SelectCommand.CommandText = sqlEmp
da.Fill(ds, "tbEMP")
If ds.Tables("tbEMP").Rows.Count <> 0 Then
IsFind2 = True
ClearAllBinding()
txtEmpID.DataBindings.Add("Text", ds, "tbEmp.EmpID")
txtEmpName.DataBindings.Add("Text", ds, "tbEmp.EmpName")
txtEmpSurname.DataBindings.Add("Text", ds, "tbEmp.EmpSurname")
cbbClass.DataBindings.Add("Text", ds, "tbEmp.DID")
txtEmpMobile.DataBindings.Add("Text", ds, "tbEmp.EmpMoblie")
Dim dt As DataTable
dt = ds.Tables("tbEMP")
Else
IsFind2 = False
MsgBox("ไม่มีพนักงานที่คุณระบุ")
ClearForm(GroupBox3)
txtEmpID.Focus()
txtEmpID.SelectAll()
End If
End If
End If
End Sub
คือถ้าพิมพ์รหัสลูกค้าแล้ว จะได้รหัสพื้นที่ขึ้นมาอัตโนมัติ ที่ cbbArea ก็อยากให้พวกข้อมูลใน groupbox ข้อมูลพนักงานมันขึ้นมาเองโดยดูจาก รหัสพื้นที่ และงานที่สั่งน่ะค่ะ

แต่นึก loop ไม่ออก ด้วยความโง่งม TT
แล้วก็ขอข้อมูลเกี่ยวกะ preview & print หน่อยนะคะ ที่หาๆมา ไม่เข้าใจ หรือไม่ก็ไม่ตรงเป้าหมายเลยค่ะ จะ cystal report ก็ทำไม่เป็น TT ตอนนี้ที่จอเป็น Mdi ค่ะ ต้องการว่าถ้าทำปุ่มพิมพ์ขึ้นมาในแต่ฟอร์ม ให้ปริ้นท์ฟอร์มลูก โดยมีหน้าจอก่อน print ให้ดูก่อนน่ะค่ะ
ขอบคุณมากค่ะ
|
 |
 |
 |
 |
Date :
2011-09-09 18:44:04 |
By :
Juladit |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|