Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

C# saving value of timeTicker for later usage

$
0
0

I am working on project Parking. I have free places for parking for exemple six of them. I made my own clock. When person rents a parking place for two hours for exemple, time ticks backward and when it comes to 0, when that two hours pass, parking place is free again.

problem is. every time I rent new parking place for different time fiwe or six hours, first parking place which is rented for two hours gets value of last rented parking place (six hours).

I need something what will be able to hold value of every rented place sepparately, so that every place can have it own time.

 public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
                int novoVrijeme = 2;
                decimal total = 0;
                int cijenaVremena = 0;
                int prekovremeno = 2;
                //int novaVrijednost;
                int sat = 0;
                int vrijemeSata;

        private void button1_Click(object sender, EventArgs e)
        {
            
            
            try
            {
                timer1.Start();

                int vremenskaRata = Convert.ToInt32(numericUpDown1.Text);
                decimal placanje = Convert.ToDecimal(textBox1.Text);
                int vrijeme = Convert.ToInt32(textBox2.Text);
                int parkiraliste = Convert.ToInt32(numericUpDown2.Text);

                vrijemeSata = vrijeme;
                //int prekovremenaCijena = 1;
                if(vremenskaRata>1 && vremenskaRata<7 && checkBox1.Checked)
                {
                    for (int vrijeme1 = 0; vrijeme1 <= vrijeme; vrijeme1++)
                        cijenaVremena = novoVrijeme * vrijeme1;

                    total = placanje - (cijenaVremena+prekovremeno);

                }
                else
                {

                for (int vrijeme1 = 0; vrijeme1 <= vrijeme; vrijeme1++)
                    cijenaVremena = novoVrijeme * vrijeme1;
                    total = placanje - cijenaVremena;

                }
                textBox3.Text = Convert.ToString(total);

                if (parkiraliste == 0)
                {
                    parkPlace1.Text = "Bussy";
                    parkPlace1.ReadOnly = true;
                }
                if (parkiraliste == 1)
                {
                    parkPlace2.Text = "Bussy";
                    parkPlace2.ReadOnly = true;
                }
                if (parkiraliste == 2)
                {
                    parkPlace3.Text = "Bussy";
                    parkPlace3.ReadOnly = true;
                }

/*
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
                */
            }
            catch
            {   if(textBox1.Text=="")
                MessageBox.Show("not enough money");
            }
        }

        private void EventHandler(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void parkingPlacesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /// empty using file.
        }
        int tick = 0;
        //int nesto = 5;
        private void timer1_Tick(object sender, EventArgs e)
        {
            tick++;
            string timing = Convert.ToString(timeBox.Text);
            timing += tick.ToString();

            if (tick == 10)
            {
                
                tick-=10;
            }
            if (tick == 0)
            {   
                sat ++;
                tick++;
            }
            if (sat == 6)
            {
                sat = 0;
            }

            timeBox.Text += tick.ToString();
            textBox14.Text = sat.ToString();


            if (vrijemeSata == sat)
            {
                parkPlace1.Text = "";
                parkPlace1.ReadOnly = false;
            }
            if (vrijemeSata == sat)
            {
                parkPlace2.Text = "";
                parkPlace2.ReadOnly = false;
            }
            if (textBox2.Text == textBox14.Text)
            {
                parkPlace3.Text = "";
                parkPlace3.ReadOnly = false;
            }
        }

I hope you will understand the question and help me.

thank you.

  

vildan tursic


Viewing all articles
Browse latest Browse all 12583

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>