Удалите предыдущие значения перед записью новых значений в том же текстовом поле в C# - PullRequest
0 голосов
/ 07 февраля 2020

Последний круг, внес много изменений в сам код, улучшен процесс, однако для расчетов, хотя они и правильные, в форме старые значения не стираются при добавлении новых элементов в список, отображаемый в текстовом поле. старые ценности с новыми ценностями рядом с ним. Сама функция работает, так как новый налог на цены и итоговая сумма верны. Используя MVS 2010. what happens when I enter more than one item

Вот сам код:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;

namespace test
{
    public partial class Form1 : Form
    {
        List<Items> STOCK = new List<Items>();
        List<Items> selecteditems = new List<Items>();
        decimal subt;
        decimal GCT = 16.50m;
        decimal GCTamt;
        decimal total;
        public Form1()
        {
            InitializeComponent();

        }

        public void Form1_Load(object sender, EventArgs e)
        {


            this.STOCK = new List<Items>
           {
            new Items{ id = 1, Name = "Bun", Price = 100},
            new Items{ id = 2, Name = "Soda", Price = 80},
            new Items{ id = 3, Name = "Cheese", Price =70},
            new Items{ id = 4, Name = "Tissue", Price = 50},
            new Items{ id = 5, Name = "Fabuloso", Price = 140},
            new Items{ id = 6, Name = "Grace Mackerel", Price = 90},
            new Items{ id = 7, Name = "Rice", Price = 50},
            new Items{ id = 8, Name = "Flour", Price = 40},
            new Items{ id = 9, Name = "Sugar", Price = 30},
           };


        }



        public class Items
        {
            public int id { get; set; }
            public string Name { get; set; }
            public decimal Price { get; set; }
        }

        private void textBox1_Enter(object sender, EventArgs e)
        {
            StringBuilder strBuilder = new StringBuilder();
            STOCK.ForEach(x => strBuilder.Append(string.Format("ID {0} - Name: {1} Price: {2:C2}", x.id, x.Name, x.Price)));
            menu.Text = menu.Text + strBuilder.ToString();
        }

        private void button_Click(object sender, EventArgs e)
        {
            Button B = (Button)sender;
            Disp.Text = Disp.Text + B.Text;
        }


        private void Enter_Click(object sender, EventArgs e)
        {
            var STOCKDict = STOCK.ToDictionary(x => x.id);

            int id;

            SoundPlayer splayer = new SoundPlayer(@"D:\dre2k\Documents\Visual Studio 2010\Projects\test\ching.wav");
            splayer.Play();

            if (!int.TryParse(Disp.Text, out id))
            {
                Disp2.Text = ("Enter number or '0' ");                
            }
            else
            {
                if (STOCKDict.ContainsKey(id))
                {
                    var item = STOCKDict[id];
                    selecteditems.Add(item);
                    Disp2.Text = Disp2.Text + (item.Name);
                }
                else
                {
                    Disp2.Text = (id + " is not available");
                }

                Disp.Text = " ";
            }

            subt = selecteditems.Sum(i => i.Price);
            GCT = 16.50m;
            GCTamt = (subt * GCT / 100);
            total = subt + GCTamt;

            subtot.Text = subtot.Text +"$" + subt;
            TaxDisp.Text = TaxDisp.Text + "$" + GCTamt;
            TotDisp.Text = TotDisp.Text + "$" + total;
        }





        }

        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...