Code
[code][/code]Code (VB.NET) Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If txtMemId.Text = "" Then
MessageBox.Show("กรุณาระบุรหัสลูกค้าด้วยค่ะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtMemId.Focus()
Exit Sub
End If
If chkNotMember.Checked = True Then
If txtMemName.Text = "" Then
MessageBox.Show("กรุณาระบุชื่อลูกค้าด้วยค่ะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtMemName.Focus()
Exit Sub
End If
End If
If lsvFoodList.Items.Count = 0 Then
MessageBox.Show("กรุณาป้อนรายการสั่งอาหารด้วยค่ะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtFoodId.Focus()
Exit Sub
End If
Dim sqlAdd As String = ""
Dim comAdd As OleDbCommand = New OleDbCommand
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
Try
If MessageBox.Show("คุณต้องการบันทึกรายการอาหารที่สั่ง ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
With comAdd
.CommandType = CommandType.Text
.CommandText = sqlAdd
.Connection = Conn
'MessageBox.Show(comAdd.CommandText.ToString())
comAdd.ExecuteNonQuery()
End With
Dim i As Integer = 0
Dim tmpFoodId As String = ""
Dim sqlFood As String = ""
Dim tmptxtAmount As Integer = 0
Dim tmplbltotal As Integer = 0
Dim tmpAmount As Integer = 0
Dim tmplblSalePrice As Integer = 0
Dim tmpSum As Integer = 0
Dim tmpDiscount As Integer = 0
Dim tmpNet As Integer = 0
If IsInstallPrinter() = True Then
If prDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
'prDoc.Print()
End If
Else
MessageBox.Show("กรุณาติดตั้งเครื่อง Printer ก่อนสั่งพิมพ์เอกสาร", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
Catch ErrProcess As Exception
MessageBox.Show("ไม่สามารถบันทึกรายการสั่งอาหารได้ เนื่องจาก " & ErrProcess.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End Try
End Sub
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Data
Imports System.Data.OleDb
Imports System.Windows.Forms
Namespace WindowsFormsApplication1
Class AccessDatabase
Private AccessConnection As OleDbConnection
Private AccessCommand As OleDbCommand
Private AccessCommandString As String
Public Sub New()
Dim AccessConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\AccessDatabase.mdb"
AccessConnection = New OleDbConnection(AccessConnectionString)
End Sub
Protected Property CommandString() As String
Get
Return AccessCommandString
End Get
Set (ByVal Value As String)
AccessCommandString = value
AccessCommand = New OleDbCommand(AccessCommandString, AccessConnection)
End Set
End Property
Protected Sub AddParameter(ByVal ParameterName As String, ByVal ParameterType As OleDbType, ByVal ParameterValue As Object)
AccessCommand.Parameters.Add(ParameterName, ParameterType)
AccessCommand.Parameters(ParameterName).Value = ParameterValue
End Sub
Protected Function ExecuteQuery() As DataTable
Dim dataTable As DataTable = New DataTable()
Try
Dim AccessDataAdapter As OleDbDataAdapter = New OleDbDataAdapter(AccessCommand)
AccessDataAdapter.Fill(dataTable)
Catch ex As Exception
MessageBox.Show(ex.Message)
Return Nothing
End Try
Return dataTable
End Function
Protected Function ExecuteScalar() As Object
Dim Result As Object = 0
Try
AccessConnection.Open()
Result = AccessCommand.ExecuteScalar()
AccessConnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Return 0
End Try
Return Result
End Function
Protected Function ExecuteNonQuery() As Boolean
Try
AccessConnection.Open()
AccessCommand.ExecuteNonQuery()
AccessConnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Return False
End Try
Return True
End Function
End Class
End Namespace
Dim Dt As DataTable = New DataTable()
Dim SelectExample As AccessDatabase = New AccessDatabase()
SelectExample.CommandString = "Select * From [MyTable]"
Dt = SelectExample.ExecuteQuery()
Select 2
Dim Dt As DataTable = New DataTable()
Dim SelectExample As AccessDatabase = New AccessDatabase()
SelectExample.CommandString = "Select * From [MyTable] Where [ID]=@ID"
SelectExample.AddParameter("@ID", OledbType.Integer, 8)
Dt = SelectExample.ExecuteQuery()
[Or_No] = type อะไร
[Ore_date] = type อะไร
[Mem_Id] = type อะไร
[Total_Price] = type อะไร
[Persent] = type อะไร
[Table_No] = type อะไร
[No_Count] = type อะไร
Date :
2010-02-03 22:08:52
By :
tungman
No. 43
Guest
[Or_No] = type อะไร Text
[Ore_date] = type อะไร Date/Time
[Mem_Id] = type อะไร Text
[Total_Price] = type อะไร Text
[Persent] = type อะไร Text
[Table_No] = type อะไร Text
[No_Count] = type อะไร AutoNumber
ไม่ติดตรงนั้นแล้ว
แต่กด Save แล้ว มันไม่ลงฐาน อ่ะค่ะ
Date :
2010-02-04 13:40:23
By :
ยัยใบบ้า
No. 53
Guest
Code
[code][/code]Code (VB.NET) Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Drawing.Printing
Public Class frmSale
Dim Conn As New OleDbConnection(strConn)
Dim connect As New OleDbConnection
Dim da As New OleDbDataAdapter
Dim ds As DataSet = New DataSet
Dim dt As DataTable
Dim tr As SqlTransaction
Dim bs As BindingSource = New BindingSource()
Dim commandUnit As SqlCommand
Dim UseFont As New Font("MS Sans Serif", 10)
Dim prDoc As New PrintDocument
Private prDlg As PrintDialog = New PrintDialog
Dim tmpSumCommission As Double = 0
Dim tmptxtMemId As String = ""
Dim tmptakeid As String = ""
'Dim dtfInfo As DateTimeFormatInfo
Dim tmpNetMeReceived As Single = 0
Dim LastSaleID As String = ""
Dim IsFind As Boolean = False
Dim IsFindMember As Boolean = False
Dim IsFindFood As Boolean = False
Dim ToClose As Boolean = False
Private Sub frmSale_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
Conn = New OleDbConnection(strConn)
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
With cboTable
.Items.Add("")
'.Items.Add("")
'.Items.Add("")
.SelectedIndex = 0
End With
tmptakeid = CStr(Tmp.Item("Pay_No"))
tmptakeid = (CInt(tmptakeid) + 1).ToString("00000")
End With
Catch
tmptakeid = "00001"
End Try
'Tmp.Close()
End Sub
Private Sub btnShowMemberList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowMemberList.Click
Dim fAllMember As New frmMemberList
fAllMember.ShowDialog(Me)
Private Sub chkNotMember_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkNotMember.CheckedChanged
If chkNotMember.Checked = True Then
lblSumBeforeDiscount.Text = "0"
lblDiscount.Text = "0"
lblNet.Text = "0"
'txtFoodId.Focus()
End Sub
Private Sub AutoGenerateMemberID()
Dim sqlTmp As String = ""
Dim comTmp As OleDbCommand = New OleDbCommand
Dim Tmp As OleDbDataReader
Dim tmpMemberID As Integer = 0
sqlTmp = "SELECT TOP 1 Mem_Id FROM Member ORDER BY Mem_Id DESC"
Conn = New OleDbConnection(strConn)
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
Private Sub btnShowOrderList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowOrderList.Click
If txtMemId.Text = "" Then
MessageBox.Show("กรุณาป้อนข้อมูลลูกค้าก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtMemId.Focus()
Exit Sub
End If
Dim fAllFood As New frmOrderFoodList
fAllFood.ShowDialog(Me)
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lsvFoodList.Items.Clear()
ClearAllFoodData()
Private Sub txtFoodId_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtFoodId.KeyDown
If txtFoodId.Text <> "" Then
If (e.KeyCode = Keys.Enter) Then
If txtFoodId.Text = "" Then
MessageBox.Show("กรุณาป้อนข้อมูลลูกค้าก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtFoodId.Focus()
Exit Sub
End If
Dim sqlFood As String = ""
sqlFood = "SELECT Food.Food_Id,Food.Food_Name,Food.price,Sale.totle"
sqlFood &= " FROM Food, Sale"
sqlFood &= " WHERE (Food.Food_Id = Sale.Food_Id)"
sqlFood &= " AND (Food.Food_Id='" & txtFoodId.Text & "')"
'sqlFood = "SELECT Food_Id,Food_Name,price "
'sqlFood &= " FROM Food"
'sqlFood &= " WHERE (Food_Id='" & txtFoodId.Text & "')"
If IsFindFood = True Then
ds.Tables("Food").Clear()
End If
MessageBox.Show("ไม่พบรหัสอาหารตามที่คุณระบุ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
ClearAllFoodData()
txtFoodId.Focus()
txtFoodId.SelectAll()
End If
End If
End If
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If (txtFoodId.Text = "") Or (lblTitle.Text = "") Or (lblSalePrice.Text = "") Or (txtAmount.Text = "") Or (lbltotal.Text = "") Then
txtFoodId.Focus()
Exit Sub
End If
Dim i As Integer = 0
Dim tmpFoodId As String = ""
For i = 0 To lsvFoodList.Items.Count - 1
tmpFoodId = lsvFoodList.Items(i).SubItems(0).Text
If txtFoodId.Text = tmpFoodId Then
MessageBox.Show("คุณเลือกรหัสอาหารซ้ำกัน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
Private Sub lsvFoodList_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lsvFoodList.DoubleClick
Dim i As Integer = 0
For i = 0 To lsvFoodList.SelectedItems.Count - 1
Dim lvi As ListViewItem
lvi = lsvFoodList.SelectedItems(i)
lsvFoodList.Items.Remove(lvi)
Next
CalculateRent()
End Sub
Sub CalculateRent()
Dim i As Integer = 0
Dim tmplblSalePrice As Integer = 0 'ราคา
Dim tmptxtAmount As Integer = 0 'จำนวนที่ขาย
Dim tmplbltotal As Integer = 0 'รวมเป็นเเงิน
Dim tmpSum As Integer = 0 'ผลรวม
Dim tmpDiscount As Integer = 0 'ส้วนลด กรณีเป็นลูกค้า
Dim tmpNet As Integer = 0 'ยอดที่ต้องจ่าย
If rIsMember = "1" Then
rRentRateDiscount = 0
End If
For i = 0 To lsvFoodList.Items.Count - 1
tmptxtAmount = CInt(lsvFoodList.Items(i).SubItems(2).Text)
tmplblSalePrice = CInt(lsvFoodList.Items(i).SubItems(3).Text)
tmplbltotal = CInt(lsvFoodList.Items(i).SubItems(4).Text)
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If txtMemId.Text = "" Then
MessageBox.Show("กรุณาระบุรหัสลูกค้าด้วยค่ะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtMemId.Focus()
Exit Sub
End If
If chkNotMember.Checked = True Then
If txtMemName.Text = "" Then
MessageBox.Show("กรุณาระบุชื่อลูกค้าด้วยค่ะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtMemName.Focus()
Exit Sub
End If
End If
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
Dim sqlAdd As String = ""
Dim comAdd As OleDbCommand = New OleDbCommand
Try
If MessageBox.Show("คุณต้องการบันทึกรายการอาหารที่สั่ง ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
'INTERT ข้อมูลในตาราง Sale
Dim i As Integer = 0
Dim tmpFoodId As String = ""
'Dim sqlFood As String = ""
Dim tmptxtAmount As Integer = 0
Dim tmplbltotal As Integer = 0
Dim tmpAmount As Integer = 0
Dim tmplblSalePrice As Integer = 0
Dim tmpSum As Integer = 0
Dim tmpDiscount As Integer = 0
Dim tmpNet As Integer = 0
Dim tmpRentDate As Date
Dim tmpReturnDate As Date
tmpRentDate = Date.Now
If rIsMember = "1" Then
rRentRateDiscount = 0
End If
Dim sqlFood As String
sqlFood = "Insert Into [Sale] ([Or_No], [Food_Id], [Unit_Price], [Amount], [Total]" & _
"Values (" & _
"@Or_No, @Food_Id, @Unit_Price, @Amount," & _
")"
If IsInstallPrinter() = True Then
If prDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
prDoc.Print()
End If
Else
MessageBox.Show("กรุณาติดตั้งเครื่อง Printer ก่อนสั่งพิมพ์เอกสาร", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
Catch ErrProcess As Exception
MessageBox.Show("ไม่สามารถบันทึกรายการสั่งอาหารได้ เนื่องจาก " & ErrProcess.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
tr.Commit()
End Try
End Sub
Private Function IsInstallPrinter() As Boolean
IsInstallPrinter = False
If prDoc.PrinterSettings.PrinterName = "<no default printer>" Then
IsInstallPrinter = False
Else
IsInstallPrinter = True
End If
End Function
Private Sub StringToPrint_Print(ByVal sender As Object, ByVal e As PrintPageEventArgs)
End Sub
Private Sub AnyString(ByVal g As Graphics, ByVal printString As String, ByVal xPos As Integer, ByVal yPos As Integer)
Code
[code][/code]Code (VB.NET) Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If txtMemId.Text = "" Then
MessageBox.Show("กรุณาระบุรหัสลูกค้าด้วยค่ะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtMemId.Focus()
Exit Sub
End If
If chkNotMember.Checked = True Then
If txtMemName.Text = "" Then
MessageBox.Show("กรุณาระบุชื่อลูกค้าด้วยค่ะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtMemName.Focus()
Exit Sub
End If
End If
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
Dim sqlAdd As String = ""
Dim comAdd As OleDbCommand = New OleDbCommand
Dim cmdAdd As OleDbCommand = New OleDbCommand
'Dim AccessCommand As OleDbDataReader
Try
If MessageBox.Show("คุณต้องการบันทึกรายการอาหารที่สั่ง ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Conn = New OleDbConnection(strConn)
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
With comAdd
.CommandText = sqlSale
'.ExecuteNonQuery()
End With
'INTERT ข้อมูลในตาราง Sale
Dim i As Integer = 0
Dim tmpFoodId As String = ""
'Dim sqlFood As String = ""
Dim tmptxtAmount As Integer = 0
Dim tmplbltotal As Integer = 0
Dim tmpAmount As Integer = 0
Dim tmplblSalePrice As Integer = 0
Dim tmpSum As Integer = 0
Dim tmpDiscount As Integer = 0
Dim tmpNet As Integer = 0
Dim tmpRentDate As Date
Dim tmpReturnDate As Date
tmpRentDate = Date.Now
If rIsMember = "1" Then
rRentRateDiscount = 0
End If
Dim sqlFood As String
sqlFood = "Insert Into [Sale] ([Or_No], [Food_Id], [Unit_Price], [Amount], [Total]" & _
"Values (" & _
"@Or_No, @Food_Id, @Unit_Price, @Amount," & _
")"
If IsInstallPrinter() = True Then
If prDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
prDoc.Print()
End If
Else
MessageBox.Show("กรุณาติดตั้งเครื่อง Printer ก่อนสั่งพิมพ์เอกสาร", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
Catch ErrProcess As Exception
MessageBox.Show("ไม่สามารถบันทึกรายการสั่งอาหารได้ เนื่องจาก " & ErrProcess.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
Conn.Close()
End Try
End Sub