Jump to content

Point of sales HELP!

- - - - -

  • Please log in to reply
2 replies to this topic

#1
teddiorsenado

teddiorsenado

    Newbie

  • Members
  • Pip
  • 1 posts
Hi. I'm currently developing a POS system(windows application) in C# with SQL Server as the database. In my database, I have a product table that contains the following fields: barcode(primary key) , productID,productName ,productQty ,productSize, and productUnitPrice.

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.

		


       }    



#2
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
Personally, I would use a gridview instead of a list view. I feel that gives you better control and access to the data. I'm not a huge fan of list views when i'm pulling sql data. Pull the sql data using your select statement and then simply bind the gridview. Or you could also use a dataview. It would be something like this:

GridView.DataBind Method (System.Web.UI.WebControls)

the important part is setting up your columns correctly if you don't let it auto-generate.
-CDG10620
Software Developer

#3
Davide

Davide

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 506 posts

cdg10620 said:

Personally, I would use a gridview instead of a list view. I feel that gives you better control and access to the data. I'm not a huge fan of list views when i'm pulling sql data. Pull the sql data using your select statement and then simply bind the gridview. Or you could also use a dataview. It would be something like this:

GridView.DataBind Method (System.Web.UI.WebControls)

the important part is setting up your columns correctly if you don't let it auto-generate.

I couldn't agree more, ListViews suck when used with a database, but I have a feeling than he wants the user to see the product in the list view. If it's not that teddi, then use a datagrid view.
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users