In my GUI, I have a TEXTBOX for the barcode, a numericUpDown for the quantity,and a LISTVIEW(7 columns : barcode, ID, Description, Quantity, Size, Regular Price, Sale Price) for the cart.
My problem is, how do I add the product information(barcode, productID, productName, productQty, productSize, productUnitPrice) inside the LISTVIEW based on the barcode that was entered on the barcode TEXTBOX?
//Inventory Base Class
public abstract class inventoryBaseClass
{
public inventoryBaseClass()
{
}
public inventoryBaseClass(uint _id)
{
Id = _id;
}
public void OpenSqlConn()
{
try
{
sqlConnection = @"Data Source=PC10\SQLEXPRESS;Initial Catalog=POSDB;Integrated Security=True";
sqlConn = new SqlConnection(sqlConnection);
sqlConn.Open();
}
catch (Exception ex)
{
DialogResult r = MessageBox.Show(ex.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (r == DialogResult.OK)
Application.Exit();
}
}
}
//Point of Sales Class
public class pointOfSalesClass : inventoryBaseClass
{
public pointOfSalesClass()
{
}
public pointOfSalesClass(uint _id)
:base(_id)
{
OpenSqlConn();
string sql = @"Select Barcode, ProductID, ProductName, TotalStocks,Size, Price, SaleAmount FROM PRODUCT WHERE Barcode = +" + _id;
SqlCmd = new SqlCommand();
SqlCmd.CommandText = sql;
SqlCmd.Connection = SqlConn;
}
}
//Point of sales Form
public partial class Point_of_Sales : Form
{
//these variables will hold the values that will be retreived in the SELECT statement in the Point of Sales Class
uint barcode = 0;
string id = "";
string productName = "";
uint qty = 0;
string size = "";
double regularPrice = 0.0;
double salePrice = 0.0;
//ADD to cart(Listview) Button
private void AddItem_Click(object sender, EventArgs e)
{
//the user enters the barcode on the txtBarcode textbox and the quantity to be purchased on the numericUpDown control
//When this button is pressed, the select statement will be executed
pointOfSalesClass addToCart = new pointOfSalesClass(uint.Parse(txtBarcode.Text.ToString()));
addToCart.SqlDataRdr = addToCart.SqlCmd.ExecuteReader();
uint quantity = Convert.ToUInt16(numericQty.Value);
while (addToCart.SqlDataRdr.Read())
{
//These are the values to be retreived
barcode = Convert.ToUInt32(addToCart.SqlDataRdr["Barcode"].ToString());
id = addToCart.SqlDataRdr["ProductID"].ToString();
productName = addToCart.SqlDataRdr["ProductName"].ToString();
qty = Convert.ToUInt32(addToCart.SqlDataRdr["TotalStocks"].ToString());
size = addToCart.SqlDataRdr["Size"].ToString();
regularPrice = Convert.ToDouble(addToCart.SqlDataRdr["Price"].ToString());
salePrice = Convert.ToDouble(addToCart.SqlDataRdr["SaleAmount"].ToString());
}
//After retreiving all values in the select statement
//How do I insert the values(barcode, id, productname, quantity(from the numericUpDown control), size, regularPrice,salePrice) inside the LISTVIEW.
}


Sign In
Create Account

Back to top









