Example #1
0
        //Parallel list to store prices along with their names

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            slipNumber++;
            products  prod        = new products();
            DataTable tbl         = new DataTable();
            double    totalAmount = 0.0;

            if (BarCode.Text.Equals("") || BarCode.Text == null)
            {
                MessageBox.Show("Enter the barcode you want to Scan");
            }
            else
            {
                tbl = data.getThatProduct(long.Parse(BarCode.Text));
                if (tbl.Rows.Count > 0)
                {
                    DataColumn c_column = new DataColumn("Quantity");
                    if (count < 1)
                    {
                        table = data.getDt();
                        count++;
                    }

                    DataRow row = data.getProduct(long.Parse(BarCode.Text));
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        if (long.Parse(BarCode.Text) == long.Parse(table.Rows[i]["Barcode"].ToString()))
                        {
                            table.Rows[i]["Quantity"] = Int32.Parse(table.Rows[i]["Quantity"].ToString()) + 1;
                            //dcr += int.Parse(table.Rows[i]["Quantity"].ToString());
                            incr = Double.Parse(table.Rows[i]["Price"].ToString());
                            table.Rows[i]["Price"] = Double.Parse(table.Rows[i]["Price"].ToString()) + Double.Parse(row["Price"].ToString());

                            for (int a = 0; a < prodName.Count; a++)
                            {
                                if (prodName[a].ToString().Equals(row["ProductName"].ToString()))
                                {
                                    amt[a] = Double.Parse(table.Rows[i]["Price"].ToString());
                                }
                            }

                            amt.Add(Double.Parse(table.Rows[i]["Price"].ToString()));
                            prodName.Add(String.Format(row["ProductName"].ToString()));
                            time.Add(DateTime.Now);
                            slip.Add(
                                "----------------------------------- \n" +
                                "Product Name : " + String.Format(row["ProductName"].ToString()) + " \n " +
                                "Day : " + tiime + " \n" +
                                "Price : " + Double.Parse(table.Rows[i]["Price"].ToString())
                                );

                            sameProduct = true;
                        }
                    }
                    if (!sameProduct)
                    {
                        table.Rows.Add(row);
                        amt.Add(Double.Parse(row["Price"].ToString()));
                        prodName.Add(String.Format(row["ProductName"].ToString()));
                        time.Add(DateTime.Now);

                        slip.Add(
                            "----------------------------------- \n" +
                            "Product Name : " + String.Format(row["ProductName"].ToString()) + " \n " +
                            "Day : " + tiime + " \n" +
                            "Price : " + Double.Parse(row["Price"].ToString())
                            );
                    }

                    //totalLabel.Content = "R "+totalAmount;
                    invoiceGrid.ItemsSource = table.DefaultView;
                    sameProduct             = false;
                }
                else if (tbl.Rows.Count < 0)
                {
                    MessageBox.Show("Entered Bar Code does not exist");
                }
            }
        }