示例#1
0
        private void AddBtn_Click(object sender, EventArgs e)
        {
            if (QuantityUpDown.Value != 0)
            {
                bool sameItem = false;

                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    string item = row.Cells[0].Value.ToString();
                    if (item == ItemTxtLb.Text)
                    {
                        sameItem = true;
                    }
                }


                if (sameItem == false)
                {
                    var index = dataGridView1.Rows.Add();

                    dataGridView1.Rows[index].Cells[0].Value = ItemTxtLb.Text;
                    dataGridView1.Rows[index].Cells[1].Value = UnitPriceTxtLb.Text;
                    dataGridView1.Rows[index].Cells[2].Value = QuantityUpDown.Value;
                    dataGridView1.Rows[index].Cells[3].Value = TotalPriceTxtLb.Text;
                    dataGridView1.Rows[index].Cells[4].Value = orderID;

                    dataGridView1.ClearSelection();

                    string TPtxt = TotalPriceTxtLb.Text.Replace("€", "");
                    totalprice  += Convert.ToInt32(TPtxt);
                    ValueLb.Text = totalprice.ToString() + "€";

                    QuantityUpDown.Value = 0;
                    UnitPriceTxtLb.ResetText();
                    TotalPriceTxtLb.ResetText();
                    ItemTxtLb.ResetText();
                    QuantityUpDown.Hide();
                    listBox.ClearSelected();
                }
                else
                {
                    MessageBox.Show("You cant add the same item", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("You cant add 0 items", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
示例#2
0
        private void listBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            QuantityUpDown.Value = 0;
            TotalPriceTxtLb.ResetText();



            ItemTxtLb.Show();
            UnitPriceTxtLb.Show();
            String text = listBox.GetItemText(listBox.SelectedItem);

            ItemTxtLb.Text = text;
            query          = "select price from items where name = '" + text + "'";

            DataSet ds = db.getData(query);

            try
            {
                UnitPriceTxtLb.Text = ds.Tables[0].Rows[0][0].ToString() + "€";
                QuantityUpDown.Show();
            }
            catch { UnitPriceTxtLb.Hide(); }
        }