Example #1
0
        public static bool Carica(stanza[] el, ref int n, string p)
        {
            if (!File.Exists(p))
            {
                return(false);
            }
            StreamReader miofile = default(StreamReader);

            miofile = new StreamReader(p);
            stanza k = default(stanza);

            n = 0;
            while (miofile.EndOfStream == false)
            {
                k.stato  = bool.Parse(miofile.ReadLine());
                k.numero = int.Parse(miofile.ReadLine());
                k.posti  = int.Parse(miofile.ReadLine());
                k.costo  = decimal.Parse(miofile.ReadLine());


                el[n] = k;
                n++;
            }
            miofile.Close();
            return(true);
        }
Example #2
0
        private void butadd_creazione_Click(object sender, EventArgs e)
        {
            stanza nuovastanza = default;


            int f = Class1.Cerca1(elestanze, num, textnum_creazione.Text);

            if (f != -1)
            {
                MessageBox.Show("Numero stanza già usato");
                textnum_creazione.Clear();
                textposti_creazione.Clear();
                textcosto_creazione.Clear();
                return;
            }


            try
            {
                nuovastanza.numero = int.Parse(textnum_creazione.Text);
                nuovastanza.posti  = int.Parse(textposti_creazione.Text);
                nuovastanza.costo  = decimal.Parse(textcosto_creazione.Text);
                if (comboBox1.Text == "Occupata")
                {
                    nuovastanza.stato = false;
                }
                if (comboBox1.Text == "Libera")
                {
                    nuovastanza.stato = true;
                }

                elestanze[num] = nuovastanza;
                num++;

                textnum_creazione.Clear();
                textposti_creazione.Clear();
                textcosto_creazione.Clear();

                MessageBox.Show("Stanza inserita");
            }
            catch
            {
                MessageBox.Show("Dati inseriti non validi");
                textnum_creazione.Clear();
                textposti_creazione.Clear();
                textcosto_creazione.Clear();
                comboBox1.Text = "";
            }
        }
Example #3
0
        public static void ordinacc(stanza[] elep, int n)
        {
            int    x = 0;
            int    y = 0;
            stanza k = default(stanza);

            while (n > x)
            {
                y = x + 1;
                while (n > y)
                {
                    if (elep[x].costo > elep[y].costo)
                    {
                        k       = elep[x];
                        elep[x] = elep[y];
                        elep[y] = k;
                    }
                    y++;
                }
                x++;
            }
        }
Example #4
0
        public static void ordinacs(stanza[] elep, int n)
        {
            int    x = 0;
            int    y = 0;
            stanza k = default(stanza);

            while (n > x)
            {
                y = x + 1;
                while (n > y)
                {
                    if (string.Compare(elep[x].stato.ToString(), elep[y].stato.ToString()) < 0)
                    {
                        k       = elep[x];
                        elep[x] = elep[y];
                        elep[y] = k;
                    }
                    y++;
                }
                x++;
            }
        }
Example #5
0
        private void butrel_modifica_Click(object sender, EventArgs e)
        {
            stanza nuovastanza = default;
            int    f           = Class1.Cerca1(elestanze, num, textnum_creazione.Text);

            if (f != -1)
            {
                MessageBox.Show("Numero stanza già usato");
                textnum_modifica.Clear();
                textposti_modifica.Clear();
                textcosto_modifica.Clear();
                return;
            }
            try
            {
                int z = default;
                int k = listView2.SelectedIndices.Count;
                if (k != 0)
                {
                    z = Class1.Cerca1(elestanze, num, listView2.SelectedItems[0].SubItems[0].Text);
                }
                nuovastanza.numero = int.Parse(textnum_modifica.Text);
                nuovastanza.posti  = int.Parse(textposti_modifica.Text);
                nuovastanza.costo  = decimal.Parse(textcosto_modifica.Text);


                if (textBox2.Text == "Occupata" || textBox2.Text == "Libera")
                {
                    if (textBox2.Text == "Occupata")
                    {
                        nuovastanza.stato = false;
                    }

                    if (textBox2.Text == "Libera")
                    {
                        nuovastanza.stato = true;
                    }
                }
                else
                {
                    MessageBox.Show("Inserire Libera o Occupata in < Stato >");
                    return;
                }



                elestanze[z] = nuovastanza;


                textnum_modifica.Clear();
                textposti_modifica.Clear();
                textcosto_modifica.Clear();

                MessageBox.Show("Stanza modificata");
                string appoggio = default;
                int    x        = default(int);
                listView2.Items.Clear();

                while (x < num)
                {
                    if (elestanze[x].stato == true)
                    {
                        appoggio = "Libera";
                    }
                    if (elestanze[x].stato == false)
                    {
                        appoggio = "Occupata";
                    }
                    var row     = new string[] { elestanze[x].numero.ToString(), elestanze[x].posti.ToString(), elestanze[x].costo.ToString(), appoggio };
                    var listrow = new ListViewItem(row);
                    listView2.Items.Add(listrow);
                    x = x + 1;
                }
            }
            catch
            {
                textnum_modifica.Clear();
                textposti_modifica.Clear();
                textcosto_modifica.Clear();

                MessageBox.Show("Stanza non modificata, controllare i valori immessi");
                string appoggio = default;
                int    x        = default(int);
                listView2.Items.Clear();

                while (x < num)
                {
                    if (elestanze[x].stato == true)
                    {
                        appoggio = "Libera";
                    }
                    if (elestanze[x].stato == false)
                    {
                        appoggio = "Occupata";
                    }
                    var row     = new string[] { elestanze[x].numero.ToString(), elestanze[x].posti.ToString(), elestanze[x].costo.ToString(), appoggio };
                    var listrow = new ListViewItem(row);
                    listView2.Items.Add(listrow);
                    x = x + 1;
                }
            }
        }