'ปุ่มเพิ่มรายการวัสดุ
Private Sub btnAddMaterial_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddMaterial.Click
Dim i As Integer = 0
Dim lvi As ListViewItem
Dim tmpMaterialID As Integer = 0
For i = 0 To lsvImportDetail.Items.Count - 1
tmpMaterialID = CInt(lsvImportDetail.Items(i).SubItems(0).Text)
If CInt(txtSearchMaterial.Text.Trim()) = tmpMaterialID Then
MessageBox.Show("คุณเลือกวัสดุซ้ำกัน กรุณาเลือกใหม่", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtSearchMaterial.Focus()
txtSearchMaterial.SelectAll()
CalculateTotal()
Exit Sub
End If
Next
Dim anyData() As String
anyData = New String() { _
txtSearchMaterial.Text, _
lblMaterialName.Text, _
txtPrice.Text, _
txtAmount.Text, _
lbltotal.Text _
}
lvi = New ListViewItem(anyData)
lsvImportDetail.Items.Add(lvi)
ClearAllData()
End Sub
'ปุ่มบันทึก
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
' If txtSearchMaterial.Text.Trim = "" Then
'MessageBox.Show("กรุณาป้อนข้อมูลให้ครบ!!!", "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information)
'txtSearchMaterial.Focus()
'Exit Sub
'End If
If lsvImportDetail.Items.Count > 0 Then
If MessageBox.Show("คุณต้องการบ้นทึกข้อมูลการนำเข้าวัสดุ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = DialogResult.Yes Then
Dim im As New Import()
im.Im_Date = Date.Today
im.Lot_No = txtLot_No.Text.Trim()
Dim i As Integer
Dim imd As New ImportDetail()
' Dim m As New Material()
' Dim OldOnhand = m.Onhand
'Dim NewOnhand = OldOnhand + imd.Lot_Amount
'm.Onhand = NewOnhand
Try
For i = 0 To lsvImportDetail.Items.Count - 1
imd = New ImportDetail
imd.Material_Id = (lsvImportDetail.Items(i).SubItems(0).Text)
imd.Price = CInt(lsvImportDetail.Items(i).SubItems(2).Text)
imd.Lot_Amount = CInt(lsvImportDetail.Items(i).SubItems(3).Text)
imd.Onhand_Lot = CInt(lsvImportDetail.Items(i).SubItems(3).Text)
im.ImportDetails.Add(imd)
Next
Using ts As New TransactionScope()
db.Imports.InsertOnSubmit(im)
db.SubmitChanges()
ts.Complete()
End Using
MessageBox.Show("บันทึกรายการนำเข้าวัสดุเรียบร้อยเเล้ว!!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
lsvImportDetail.Clear()
Catch ex As Exception
MessageBox.Show(ex.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End If
End If
End Sub
Tag : .NET, Ms SQL Server 2008, Win (Windows App), LINQ, VS 2010 (.NET 4.x)