โปรแกรมขายสินค้า POS of Sales ระบบยิงบาร์โค้ด
โปรแกรมระบบการขายสินค้า POS of Sales (C++/CLI) เหมือน Seven-Eleven
ในห้อง 'คอมพิวเตอร์ & อินเตอร์เน็ต' ตั้งกระทู้โดย ledphong, 9 กันยายน 2014.
-
ไฟล์ที่แนบมา:
-
-
แผนภาพ Diagram Database Access 2003 ต้องเข้าใจซ่ะก่อนค่อยไปเขียนโปรแกรม
ไฟล์ที่แนบมา:
-
-
ที่ผ่านมาพาแต่พวกท่านเขียนแบบ Record เดียวในตารางเดียวแต่ยังไม่ได้ทันเชื่อมตารางและมีความซับซ้อนสูงๆ หรือ แบบวิศวกรที่กำลังจะก่อสร้างตึกสูงลัดฟ้าเลยทีเดียวครับ
-
ฐานข้อมูล dbPOSSimple จะประกอบด้วย 3 Tables
============================
1.ตาราง tblProduct ตารางสินค้า -
กำหนดตัวแปรใน ตาราง tblProduct
ไฟล์ที่แนบมา:
-
-
ตัวแปร tblProduct
ไฟล์ที่แนบมา:
-
-
เวลาคีย์ข้อมูลในช่องค้นหาแล้วให้ปรากฎในตารางข้อมูลเป็นเช่นนี้
================================
เวลายิงข้อมูลควรยิงที่บาร์โค้ดจะง่ายกว่าใช่ไหมครับ
อาศัยหลักการค้นหาข้อมูลแล้วโชว์ข้อมูลครับ (ถ้าเข้าใจ)ไฟล์ที่แนบมา:
-
-
เขียนคำสั่งติดต่อฐานข้อมูลและดึงข้อมูลมาโชว์ listView (ยิงบาร์โค้ด)
===================================
private: System::Void frmInvoiceDetail_Load(System::Object^ sender, System::EventArgs^ e) {
lblTotalAmount->Text = "0.00";
LoadData();
}
private :
void LoadData(){
//=============Load Data=====================
OleDbConnection^ oleDbConnection;
OleDbCommand ^ oleDbCommand;
OleDbDataReader^ oleDbDataReader;
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\dbPOSSimple.mdb";
try{
String^ strQuery = "SELECT ProductCode,Barcode,ProductName,Price,Unit,Total FROM tblProduct " +
"Where " + //เพิ่มมาใหม่
"(Barcode Like '%" + txtSearchBarcode->Text + "%') ORDER BY ProductCode ";//เพิ่มมาใหม่
oleDbConnection = gcnew OleDbConnection(strConnection);
oleDbConnection->Open();
oleDbCommand = gcnew OleDbCommand(strQuery, oleDbConnection);
oleDbDataReader = oleDbCommand->ExecuteReader();
while(oleDbDataReader->Read()){
ListViewItem^ item = gcnew ListViewItem(oleDbDataReader["ProductCode"]->ToString());
item->SubItems->Add(oleDbDataReader["Barcode"]->ToString());
item->SubItems->Add(oleDbDataReader["ProductName"]->ToString());
item->SubItems->Add(oleDbDataReader["Price"]->ToString());
item->SubItems->Add(oleDbDataReader["Unit"]->ToString());
item->SubItems->Add(oleDbDataReader["Total"]->ToString());
listView1->Items->Add(item);
}
//======CalCulate==========
CalculateProduct();
//=========================
oleDbDataReader->Close();
}
catch(Exception^ e){
MessageBox::Show(e->Message, "Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
return;
}
finally{
oleDbConnection->Close();
if(oleDbDataReader != nullptr){
oleDbDataReader->Close();
oleDbDataReader = nullptr;
}
if(oleDbCommand != nullptr){
oleDbCommand = nullptr;
}
}
}
void CalculateProduct(){
// =============การแสดงผล listView===========================
double TotalAmount = 0.00;
for each( ListViewItem ^ lvi in listView1->Items){
ListViewItem::ListViewSubItem ^ SubItem = lvi->SubItems[5];//ผลรวมจำนวนเงินทั้งหมด
TotalAmount += double::parse(SubItem->Text);
}
lblTotalAmount->Text = TotalAmount.ToString(L"C");
}
private: System::Void btnSearchBarcode_Click(System::Object^ sender, System::EventArgs^ e) {
listView1->Items->Clear();
LoadData();
txtSearchBarcode->Text = "";
}ไฟล์ที่แนบมา:
-
-
ควรใช้ if HasRows เหมือน C#.NET
-
ตัวอย่าง C#.NET
==============================
private void OK_Click(System.Object sender, System.EventArgs e)
{
string sqlQRY = "SELECT * FROM Products WHERE ProductCode = '" + txtCode.Text + "'";
SqlCommand cmd = new SqlCommand(sqlQRY, conn);
SqlDataReader rdr = cmd.ExecuteReader;
if (string.IsNullOrEmpty(txtCode.Text)) {
MessageBox.Show("Input a product code!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
txtCode.Text = "";
txtCode.Focus();
} else if (rdr.HasRows) {
rdr.Read();
int intProductID = rdr("ProductID").ToString;
SalesDataSet.SalesDetailsRow newRow = SalesDataSet.SalesDetails.NewSalesDetailsRow;
newRow.SalesID = SalesIDTextBox.Text;
newRow.ProductName = intProductID;
newRow.Qty = 1;
decimal Price = rdr("Price");
newRow.Price = Price;
newRow.Amount = Price;
SalesDataSet.SalesDetails.Rows.Add(newRow);
txtCode.Text = "";
txtCode.Focus();
} else {
MessageBox.Show("Product not found!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
txtCode.Text = "";
txtCode.Focus();
}
txtTotal.Text = Totals();
decimal vat = default(decimal);
vat = Conversion.Val(txtTotal.Text) * 0.12;
txtVAT.Text = vat;
Button1.Enabled = true;
} -
โหลดเลขที่ใบขายสินค้า
===============================
private: System::Void frmInvoiceDetail_Load(System::Object^ sender, System::EventArgs^ e) {
lblTotalAmount->Text = "0.00";
//==========LoadData GenID=================================
OleDbConnection^ oleDbConnection;
OleDbCommand ^ oleDbCommand;
System::DateTime now = System::DateTime::Now;
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\dbPOSSimple.mdb";
oleDbConnection = gcnew OleDbConnection(strConnection);
oleDbConnection->Open();
oleDbCommand = gcnew OleDbCommand("SELECT Count(ProductPK)+1 FROM tblProduct", oleDbConnection);
Object ^MaxID = oleDbCommand->ExecuteScalar();
textBox1->Text = now.ToString("yy") + MaxID->ToString()->PadLeft(7, '0');
//เช่น 570000001 ความกว้าง = 9 ตัวอักษร, 57 คือ พ.ศ.
//=========================================================
}ไฟล์ที่แนบมา:
-
-
ยิงบาร์โค้ดแล้ว Show ข้อมูล
ไฟล์ที่แนบมา:
-
-
ตัวอย่างมาจาก C#.NET เขบ็ดไปเป็น C++/CLI
==========================ไฟล์ที่แนบมา:
-
-
ฐานข้อมูล Northwind.mdb (Access 2003)
========================
Copy ฐานข้อมูลไว้ใน C:
ไปหาโหลดใน Internet เอาครับ -
Form_Load (ลอกตามนี้ทำได้เลยเหมือนโปรแกรมขายตาม Seven - eleven )
==================================
using namespace System;
using namespace System::Collections::Generic;
using namespace System::ComponentModel;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Linq;
using namespace System::Text;
using namespace System::Windows::Forms;
using namespace System::Data::Common;
namespace DataEntry
{
Form1::Form1()
{
InitializeInstanceFields();
InitializeComponent();
}
void Form1::Form1_Load(Object ^sender, EventArgs ^e)
{
CheckProvider();
lsvProductList->Columns->Add("รหัสสินค้า", 60, HorizontalAlignment::Left);
lsvProductList->Columns->Add("ชื่อสินค้า", 150, HorizontalAlignment::Left);
lsvProductList->Columns->Add("ราคาขาย", 65, HorizontalAlignment::Right);
lsvProductList->Columns->Add("จำนวน", 50, HorizontalAlignment::Right);
lsvProductList->Columns->Add("รวมเป็นเงิน", 70, HorizontalAlignment::Right);
lsvProductList->View = View::Details;
lsvProductList->GridLines = true;
lsvProductList->FullRowSelect = true;
txtAmount->ContextMenu = gcnew ContextMenu();
txtProductID->ContextMenu = gcnew ContextMenu();
ClearProductData();
lblNet->Text = "0";
} -
void Form1::CheckProvider()
{
if (optAccess->Checked == true)
{
strConn = "Provider=Microsoft.JET.OLEDB.4.0;data source=C:\\Northwind.mdb";
strProvider = "System.Data.OleDb";
}
else if (optSQLServer->Checked == true)
{
strConn = "Data Source=.\\SQLExpress;Integrated security=SSPI;Initial Catalog=Northwind;";
strProvider = "System.Data.SqlClient";
}
DbProviderFactory ^dbFactory = DbProviderFactories::GetFactory(strProvider);
Conn = dbFactory->CreateConnection();
if (Conn->State == ConnectionState::Open)
{
Conn->Close();
}
Conn->ConnectionString = strConn;
Conn->Open();
}
void Form1::ClearProductData()
{
txtProductID->Text = "";
lblProductName->Text = "";
lblSalePrice->Text = "0";
txtAmount->Text = "1";
lblTotal->Text = "0";
}
void Form1::txtCustomerID_KeyDown(Object ^sender, KeyEventArgs ^e)
{
if (txtCustomerID->Text->Trim() == "")
{
return;
}
if (e->KeyCode == Keys::Enter)
{
sb->Remove(0, sb->Length);
sb->Append("SELECT CustomerID,ContactName,Address");
sb->Append(" FROM Customers");
sb->Append(" WHERE (CustomerID LIKE '%" + txtCustomerID->Text + "%')");
String ^sqlCustomer = sb->ToString();
DataTable ^dtCustomer;
DbCommand ^com = Conn->CreateCommand();
com->CommandType = CommandType::Text;
com->CommandText = sqlCustomer;
com->Connection = Conn;
dr = com->ExecuteReader();
if (dr->HasRows)
{
dtCustomer = gcnew DataTable();
dtCustomer->Load(dr);
txtCustomerID->Text = dtCustomer->Rows[0]["CustomerID"]->ToString();
lblContactName->Text = dtCustomer->Rows[0]["ContactName"]->ToString();
lblAddress->Text = dtCustomer->Rows[0]["Address"]->ToString();
txtProductID->Focus();
}
else
{
MessageBox::Show("รหัสลูกค้าที่คุณป้อน ไม่มี !!!", "ผลการตรวจสอบ", MessageBoxButtons::OK, MessageBoxIcon::Information);
ClearCustomerData();
txtCustomerID->Focus();
}
dr->Close();
}
}
void Form1::ClearCustomerData()
{
txtCustomerID->Text = "";
lblContactName->Text = "";
lblAddress->Text = "";
}
void Form1::txtProductID_KeyDown(Object ^sender, KeyEventArgs ^e)
{
if (txtProductID->Text->Trim() == "")
{
return;
}
if (e->KeyCode == Keys::Enter)
{
sb->Remove(0, sb->Length);
sb->Append("SELECT ProductID,ProductName,UnitPrice");
sb->Append(" FROM Products");
sb->Append(" WHERE (ProductID =" + txtProductID->Text->Trim() + ")");
String ^sqlProduct = sb->ToString();
DataTable ^dtProduct;
auto com = Conn->CreateCommand();
com->CommandType = CommandType::Text;
com->CommandText = sqlProduct;
com->Connection = Conn;
dr = com->ExecuteReader();
if (dr->HasRows)
{
dtProduct = gcnew DataTable();
dtProduct->Load(dr);
txtProductID->Text = dtProduct->Rows[0]["ProductID"]->ToString();
lblProductName->Text = dtProduct->Rows[0]["ProductName"]->ToString();
lblSalePrice->Text = dtProduct->Rows[0]["UnitPrice"]->ToString();
CalculateTotal();
txtAmount->Focus();
}
else
{
MessageBox::Show("รหัสสินค้าที่คุณป้อน ไม่ถูกต้อง !!!", "ผลการตรวจสอบ", MessageBoxButtons::OK, MessageBoxIcon::Information);
ClearProductData();
txtProductID->Focus();
}
dr->Close();
}
}
void Form1::txtAmount_TextChanged(Object ^sender, EventArgs ^e)
{
if (txtAmount->Text->Trim() == "")
{
txtAmount->Text = "1";
}
if (int::parse(txtAmount->Text) == 0)
{
txtAmount->Text = "1";
}
CalculateTotal();
}
void Form1::CalculateTotal()
{
double Total;
Total = (double::parse(lblSalePrice->Text)) * int::parse(txtAmount->Text);
lblTotal->Text = Total.ToString("#,##0.00");
}
void Form1::cmdAdd_Click(Object ^sender, EventArgs ^e)
{
if ((txtProductID->Text->Trim() == "") || (lblProductName->Text->Trim() == ""))
{
txtProductID->Focus();
return;
}
if (int::parse(txtAmount->Text) == 0)
{
txtAmount->Focus();
return;
}
int i = 0;
ListViewItem ^lvi;
int tmpProductID = 0;
for (i = 0; i <= lsvProductList->Items->Count - 1; i++)
{
tmpProductID = int::parse(lsvProductList->Items->SubItems[0]->Text);
if (int::parse(txtProductID->Text->Trim()) == tmpProductID)
{
MessageBox::Show("คุณเลือกสินค้าซ้ำกัน กรุณาเลือกใหม่ !!!", "ผลการตรวจสอบ", MessageBoxButtons::OK, MessageBoxIcon::Information);
ClearProductData();
txtProductID->Focus();
txtProductID->SelectAll();
return;
}
}
array<String^> ^anyData;
anyData = gcnew array<String^> {txtProductID->Text, lblProductName->Text, lblSalePrice->Text, txtAmount->Text, lblTotal->Text};
lvi = gcnew ListViewItem(anyData);
lsvProductList->Items->Add(lvi);
CalculateNet();
ClearProductData();
cmdSave->Enabled = true;
txtProductID->Focus();
}
void Form1::lsvProductList_DoubleClick(Object ^sender, EventArgs ^e)
{
int i = 0;
for (i = 0; i <= lsvProductList->SelectedItems->Count - 1; i++)
{
ListViewItem ^lvi;
lvi = lsvProductList->SelectedItems;
lsvProductList->Items->Remove(lvi);
}
CalculateNet();
txtProductID->Focus();
}
void Form1::CalculateNet()
{
int i = 0;
double tmpNetTotal = 0;
for (i = 0; i <= lsvProductList->Items->Count - 1; i++)
{
tmpNetTotal += double::parse(lsvProductList->Items->SubItems[4]->Text);
}
lblNet->Text = tmpNetTotal.ToString("#,##0.00");
}
void Form1::cmdClear_Click(Object ^sender, EventArgs ^e)
{
lsvProductList->Items->Clear();
lblNet->Text = "0";
txtProductID->Focus();
}
void Form1::cmdSave_Click(Object ^sender, EventArgs ^e)
{
if (txtCustomerID->Text->Trim() == "")
{
MessageBox::Show("กรุณาป้อนรหัสลูกค้า !!!", "ข้อผิดพลาด", MessageBoxButtons::OK, MessageBoxIcon::Information);
txtCustomerID->Focus();
return;
}
if (lsvProductList->Items->Count > 0)
{
if (MessageBox::Show("คุณต้องการบันทึกรายการสั่งซื้อสินค้า ใช่หรือไม่ ?", "คำยืนยัน", MessageBoxButtons::YesNo, MessageBoxIcon::Information) == System::Windows::Forms::DialogResult::Yes)
{
tr = Conn->BeginTransaction();
sb->Remove(0, sb->Length);
sb->Append("INSERT INTO Orders (CustomerID,OrderDate)");
sb->Append(" VALUES ('" + txtCustomerID->Text->Trim()->Replace("'", "") + "',");
sb->Append("'" + DateTime::Today + "')");
String ^sqlSave = sb->ToString();
auto com = Conn->CreateCommand();
com->CommandType = CommandType::Text;
com->CommandText = sqlSave;
com->Connection = Conn;
com->Transaction = tr;
com->ExecuteNonQuery();
sb->Remove(0, sb->Length);
sb->Append("SELECT TOP 1 OrderID FROM Orders");
sb->Append(" ORDER BY OrderID DESC");
sqlSave = sb->ToString();
int LastOrderID;
com->CommandType = CommandType::Text;
com->CommandText = sqlSave;
com->Connection = Conn;
dr = com->ExecuteReader();
if (dr->HasRows)
{
dr->Read();
LastOrderID = dr->GetInt32(dr->GetOrdinal("OrderID"));
}
else
{
LastOrderID = 10000;
}
dr->Close();
int i;
for (i = 0; i <= lsvProductList->Items->Count - 1; i++)
{
sb->Remove(0, sb->Length);
sb->Append("INSERT INTO [Order Details] (OrderID,ProductID,");
sb->Append(" UnitPrice,Quantity,Discount)");
sb->Append(" VALUES (" + LastOrderID + ",");
sb->Append("'" + lsvProductList->Items->SubItems[0]->Text + "',");
sb->Append(lsvProductList->Items->SubItems[2]->Text + ",");
sb->Append(lsvProductList->Items->SubItems[3]->Text + ",0)");
sqlSave = sb->ToString();
com->CommandText = sqlSave;
com->ExecuteNonQuery();
}
tr->Commit();
MessageBox::Show("บันทึกรายการสั่งซื้อสินค้า เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons::OK, MessageBoxIcon::Information);
lsvProductList->Clear();
ClearCustomerData();
ClearProductData();
lblNet->Text = "0";
txtCustomerID->Focus();
}
}
}
void Form1::eek:ptAccess_CheckedChanged(Object ^sender, EventArgs ^e)
{
CheckProvider();
}
void Form1::eek:ptSQLServer_CheckedChanged(Object ^sender, EventArgs ^e)
{
CheckProvider();
}
void Form1::txtProductID_KeyPress(Object ^sender, KeyPressEventArgs ^e)
{
if (e->KeyChar < '0' || e->KeyChar > '9')
{
e->Handled = true;
}
}
void Form1::txtAmount_KeyPress(Object ^sender, KeyPressEventArgs ^e)
{
if (e->KeyChar < '0' || e->KeyChar > '9')
{
e->Handled = true;
}
}
void Form1::DisposeObject(bool disposing)
{
if (disposing && (components != nullptr))
{
delete components;
}
//C# TO C++ CONVERTER NOTE: There is no explicit call to the base class destructor in C++:
// base.Dispose(disposing);
}
void Form1::InitializeComponent()
{
this->GroupBox3 = gcnew System::Windows::Forms::GroupBox();
this->optSQLServer = gcnew System::Windows::Forms::RadioButton();
this->optAccess = gcnew System::Windows::Forms::RadioButton();
this->cmdSave = gcnew System::Windows::Forms::Button();
this->cmdClear = gcnew System::Windows::Forms::Button();
this->cmdAdd = gcnew System::Windows::Forms::Button();
this->GroupBox2 = gcnew System::Windows::Forms::GroupBox();
this->lsvProductList = gcnew System::Windows::Forms::ListView();
this->txtAmount = gcnew System::Windows::Forms::TextBox();
this->lblTotal = gcnew System::Windows::Forms::Label();
this->lblSalePrice = gcnew System::Windows::Forms::Label();
this->lblProductName = gcnew System::Windows::Forms::Label();
this->txtProductID = gcnew System::Windows::Forms::TextBox();
this->Label9 = gcnew System::Windows::Forms::Label();
this->Label8 = gcnew System::Windows::Forms::Label();
this->Label7 = gcnew System::Windows::Forms::Label();
this->Label6 = gcnew System::Windows::Forms::Label();
this->Label5 = gcnew System::Windows::Forms::Label();
this->lblNet = gcnew System::Windows::Forms::Label();
this->Label4 = gcnew System::Windows::Forms::Label();
this->GroupBox1 = gcnew System::Windows::Forms::GroupBox();
this->lblAddress = gcnew System::Windows::Forms::Label();
this->lblContactName = gcnew System::Windows::Forms::Label();
this->txtCustomerID = gcnew System::Windows::Forms::TextBox();
this->Label3 = gcnew System::Windows::Forms::Label();
this->Label2 = gcnew System::Windows::Forms::Label();
this->Label1 = gcnew System::Windows::Forms::Label();
this->GroupBox3->SuspendLayout();
this->GroupBox2->SuspendLayout();
this->GroupBox1->SuspendLayout();
this->SuspendLayout();
//
// GroupBox3
//
this->GroupBox3->Controls->Add(this->optSQLServer);
this->GroupBox3->Controls->Add(this->optAccess);
this->GroupBox3->Location = System::Drawing::point(11, 349);
this->GroupBox3->Name = "GroupBox3";
this->GroupBox3->Size = System::Drawing::Size(439, 54);
this->GroupBox3->TabIndex = 5;
this->GroupBox3->TabStop = false;
this->GroupBox3->Text = "เลือก Provider";
//
// optSQLServer
//
this->optSQLServer->AutoSize = true;
this->optSQLServer->Cursor = System::Windows::Forms::Cursors::Hand;
this->optSQLServer->Location = System::Drawing::point(181, 19);
this->optSQLServer->Name = "optSQLServer";
this->optSQLServer->Size = System::Drawing::Size(129, 17);
this->optSQLServer->TabIndex = 1;
this->optSQLServer->Text = "System.Data.SqlClient";
this->optSQLServer->UseVisualStyleBackColor = true;
this->optSQLServer->CheckedChanged += gcnew System::EventHandler(this, &Form1::eek:ptSQLServer_CheckedChanged);
//
// optAccess
//
this->optAccess->AutoSize = true;
this->optAccess->Checked = true;
this->optAccess->Cursor = System::Windows::Forms::Cursors::Hand;
this->optAccess->Location = System::Drawing::point(20, 19);
this->optAccess->Name = "optAccess";
this->optAccess->Size = System::Drawing::Size(118, 17);
this->optAccess->TabIndex = 0;
this->optAccess->TabStop = true;
this->optAccess->Text = "System.Data.OleDb";
this->optAccess->UseVisualStyleBackColor = true;
this->optAccess->CheckedChanged += gcnew System::EventHandler(this, &Form1::eek:ptAccess_CheckedChanged);
//
// cmdSave
//
this->cmdSave->Cursor = System::Windows::Forms::Cursors::Hand;
this->cmdSave->Location = System::Drawing::point(469, 320);
this->cmdSave->Name = "cmdSave";
this->cmdSave->Size = System::Drawing::Size(75, 23);
this->cmdSave->TabIndex = 4;
this->cmdSave->Text = "บันทึก";
this->cmdSave->UseVisualStyleBackColor = true;
this->cmdSave->Click += gcnew System::EventHandler(this, &Form1::cmdSave_Click);
//
// cmdClear
//
this->cmdClear->Cursor = System::Windows::Forms::Cursors::Hand;
this->cmdClear->Location = System::Drawing::point(469, 203);
this->cmdClear->Name = "cmdClear";
this->cmdClear->Size = System::Drawing::Size(75, 23);
this->cmdClear->TabIndex = 3;
this->cmdClear->Text = "Clear";
this->cmdClear->UseVisualStyleBackColor = true;
this->cmdClear->Click += gcnew System::EventHandler(this, &Form1::cmdClear_Click);
//
// cmdAdd
//
this->cmdAdd->Cursor = System::Windows::Forms::Cursors::Hand;
this->cmdAdd->Location = System::Drawing::point(469, 181);
this->cmdAdd->Name = "cmdAdd";
this->cmdAdd->Size = System::Drawing::Size(75, 23);
this->cmdAdd->TabIndex = 2;
this->cmdAdd->Text = "เพิ่มรายการ";
this->cmdAdd->UseVisualStyleBackColor = true;
this->cmdAdd->Click += gcnew System::EventHandler(this, &Form1::cmdAdd_Click);
//
// GroupBox2
//
this->GroupBox2->Controls->Add(this->lsvProductList);
this->GroupBox2->Controls->Add(this->txtAmount);
this->GroupBox2->Controls->Add(this->lblTotal);
this->GroupBox2->Controls->Add(this->lblSalePrice);
this->GroupBox2->Controls->Add(this->lblProductName);
this->GroupBox2->Controls->Add(this->txtProductID);
this->GroupBox2->Controls->Add(this->Label9);
this->GroupBox2->Controls->Add(this->Label8);
this->GroupBox2->Controls->Add(this->Label7);
this->GroupBox2->Controls->Add(this->Label6);
this->GroupBox2->Controls->Add(this->Label5);
this->GroupBox2->Location = System::Drawing::point(11, 153);
this->GroupBox2->Name = "GroupBox2";
this->GroupBox2->Size = System::Drawing::Size(439, 190);
this->GroupBox2->TabIndex = 1;
this->GroupBox2->TabStop = false;
this->GroupBox2->Text = "รายการสั้่งซื้อ";
//
// lsvProductList
//
this->lsvProductList->Location = System::Drawing::point(11, 58);
this->lsvProductList->Name = "lsvProductList";
this->lsvProductList->Size = System::Drawing::Size(412, 126);
this->lsvProductList->TabIndex = 10;
this->lsvProductList->TabStop = false;
this->lsvProductList->UseCompatibleStateImageBehavior = false;
this->lsvProductList->DoubleClick += gcnew System::EventHandler(this, &Form1::lsvProductList_DoubleClick);
//
// txtAmount
//
this->txtAmount->Location = System::Drawing::point(311, 32);
this->txtAmount->Name = "txtAmount";
this->txtAmount->Size = System::Drawing::Size(44, 20);
this->txtAmount->TabIndex = 1;
this->txtAmount->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
this->txtAmount->TextChanged += gcnew System::EventHandler(this, &Form1::txtAmount_TextChanged);
this->txtAmount->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &Form1::txtAmount_KeyPress);
//
// lblTotal
//
this->lblTotal->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
this->lblTotal->Location = System::Drawing::point(355, 32);
this->lblTotal->Name = "lblTotal";
this->lblTotal->Size = System::Drawing::Size(68, 20);
this->lblTotal->TabIndex = 9;
this->lblTotal->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
//
// lblSalePrice
//
this->lblSalePrice->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
this->lblSalePrice->Location = System::Drawing::point(245, 32);
this->lblSalePrice->Name = "lblSalePrice";
this->lblSalePrice->Size = System::Drawing::Size(65, 20);
this->lblSalePrice->TabIndex = 8;
this->lblSalePrice->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
//
// lblProductName
//
this->lblProductName->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
this->lblProductName->Location = System::Drawing::point(61, 32);
this->lblProductName->Name = "lblProductName";
this->lblProductName->Size = System::Drawing::Size(184, 20);
this->lblProductName->TabIndex = 7;
//
// txtProductID
//
this->txtProductID->Location = System::Drawing::point(11, 32);
this->txtProductID->Name = "txtProductID";
this->txtProductID->Size = System::Drawing::Size(50, 20);
this->txtProductID->TabIndex = 0;
this->txtProductID->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::txtProductID_KeyDown);
this->txtProductID->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &Form1::txtProductID_KeyPress);
//
// Label9
//
this->Label9->AutoSize = true;
this->Label9->Location = System::Drawing::point(353, 16);
this->Label9->Name = "Label9";
this->Label9->Size = System::Drawing::Size(70, 13);
this->Label9->TabIndex = 4;
this->Label9->Text = "รวมเป็นเงิน :";
//
// Label8
//
this->Label8->AutoSize = true;
this->Label8->Location = System::Drawing::point(311, 16);
this->Label8->Name = "Label8";
this->Label8->Size = System::Drawing::Size(46, 13);
this->Label8->TabIndex = 3;
this->Label8->Text = "จำนวน :";
//
// Label7
//
this->Label7->AutoSize = true;
this->Label7->Location = System::Drawing::point(242, 16);
this->Label7->Name = "Label7";
this->Label7->Size = System::Drawing::Size(54, 13);
this->Label7->TabIndex = 2;
this->Label7->Text = "ราคาขาย :";
//
// Label6
//
this->Label6->AutoSize = true;
this->Label6->Location = System::Drawing::point(64, 16);
this->Label6->Name = "Label6";
this->Label6->Size = System::Drawing::Size(52, 13);
this->Label6->TabIndex = 1;
this->Label6->Text = "ชื่อสินค้า :";
//
// Label5
//
this->Label5->AutoSize = true;
this->Label5->Location = System::Drawing::point(8, 16);
this->Label5->Name = "Label5";
this->Label5->Size = System::Drawing::Size(58, 13);
this->Label5->TabIndex = 0;
this->Label5->Text = "รหัสสินค้า :";
//
// lblNet
//
this->lblNet->BackColor = System::Drawing::Color::Black;
this->lblNet->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
this->lblNet->Font = gcnew System::Drawing::Font("Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::point, (safe_cast<System::Byte>(222)));
this->lblNet->ForeColor = System::Drawing::Color::FromArgb((safe_cast<int>((safe_cast<System::Byte>(192)))), (safe_cast<int>((safe_cast<System::Byte>(255)))), (safe_cast<int>((safe_cast<System::Byte>(192)))));
this->lblNet->Location = System::Drawing::point(420, 38);
this->lblNet->Name = "lblNet";
this->lblNet->Size = System::Drawing::Size(124, 53);
this->lblNet->TabIndex = 9;
this->lblNet->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
//
// Label4
//
this->Label4->AutoSize = true;
this->Label4->Location = System::Drawing::point(417, 25);
this->Label4->Name = "Label4";
this->Label4->Size = System::Drawing::Size(70, 13);
this->Label4->TabIndex = 8;
this->Label4->Text = "รวมเป็นเงิน :";
//
// GroupBox1
//
this->GroupBox1->Controls->Add(this->lblAddress);
this->GroupBox1->Controls->Add(this->lblContactName);
this->GroupBox1->Controls->Add(this->txtCustomerID);
this->GroupBox1->Controls->Add(this->Label3);
this->GroupBox1->Controls->Add(this->Label2);
this->GroupBox1->Controls->Add(this->Label1);
this->GroupBox1->Location = System::Drawing::point(11, 14);
this->GroupBox1->Name = "GroupBox1";
this->GroupBox1->Size = System::Drawing::Size(306, 133);
this->GroupBox1->TabIndex = 0;
this->GroupBox1->TabStop = false;
this->GroupBox1->Text = "ข้อมูลลูกค้า";
//
// lblAddress
//
this->lblAddress->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
this->lblAddress->Location = System::Drawing::point(47, 64);
this->lblAddress->Name = "lblAddress";
this->lblAddress->Size = System::Drawing::Size(230, 59);
this->lblAddress->TabIndex = 5;
//
// lblContactName
//
this->lblContactName->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
this->lblContactName->Location = System::Drawing::point(67, 40);
this->lblContactName->Name = "lblContactName";
this->lblContactName->Size = System::Drawing::Size(210, 20);
this->lblContactName->TabIndex = 4;
//
// txtCustomerID
//
this->txtCustomerID->Location = System::Drawing::point(11, 40);
this->txtCustomerID->Name = "txtCustomerID";
this->txtCustomerID->Size = System::Drawing::Size(55, 20);
this->txtCustomerID->TabIndex = 0;
this->txtCustomerID->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::txtCustomerID_KeyDown);
//
// Label3
//
this->Label3->AutoSize = true;
this->Label3->Location = System::Drawing::point(8, 64);
this->Label3->Name = "Label3";
this->Label3->Size = System::Drawing::Size(33, 13);
this->Label3->TabIndex = 2;
this->Label3->Text = "ที่อยู่ :";
//
// Label2
//
this->Label2->AutoSize = true;
this->Label2->Location = System::Drawing::point(64, 24);
this->Label2->Name = "Label2";
this->Label2->Size = System::Drawing::Size(48, 13);
this->Label2->TabIndex = 1;
this->Label2->Text = "ชื่อ-สกุล :";
//
// Label1
//
this->Label1->AutoSize = true;
this->Label1->Location = System::Drawing::point(8, 24);
this->Label1->Name = "Label1";
this->Label1->Size = System::Drawing::Size(57, 13);
this->Label1->TabIndex = 0;
this->Label1->Text = "รหัสลูกค้า :";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6.0F, 13.0F);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(555, 416);
this->Controls->Add(this->GroupBox3);
this->Controls->Add(this->cmdSave);
this->Controls->Add(this->cmdClear);
this->Controls->Add(this->cmdAdd);
this->Controls->Add(this->GroupBox2);
this->Controls->Add(this->lblNet);
this->Controls->Add(this->Label4);
this->Controls->Add(this->GroupBox1);
this->Name = "Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = "การสร้างฟอร์มป้อนข้อมูล (Data Entry - Common Version) (VC# 2010)";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->GroupBox3->ResumeLayout(false);
this->GroupBox3->PerformLayout();
this->GroupBox2->ResumeLayout(false);
this->GroupBox2->PerformLayout();
this->GroupBox1->ResumeLayout(false);
this->GroupBox1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
void Form1::InitializeInstanceFields()
{
strConn = "";
strProvider = "";
sb = gcnew StringBuilder();
}
} -
อาศัยหลักการ
==========================
1.คีย์ค้นหาแล้วพบชื่อผลิตภัณฑ์ที่ต้องการได้
2.เพิ่มค่าการซื้อในหน้าจอได้
3.ลบข้อมูลในหน้าจอได้หากไม่เลือกสินค้าแล้ว
4.บันทึกลงไฟล์ได้ใน lsvProductList