Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (Colazioni.Value == 0)
            {
                MessageBox.Show("Devi inserire almeno una persona per il calcolo delle colazioni!!!", "Attenzione", MessageBoxButtons.OK);
                return;
            }
            foreach (CheckIn c in CheckIns)
            {
                if (connection != null)
                {
                    if (connection.State != ConnectionState.Closed)
                    {
                        connection.Close();
                    }
                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }

                    MySqlCommand cmd = new MySqlCommand("UPDATE  prenotazioni SET checkin = '1',arrivo='" + dateTimePicker1.Value.ToShortDateString() + " " + dateTimePicker1.Value.ToShortTimeString() + "' where prenotazioni.id=" + c.pren + ";", connection);
                    IPHostEntry  host;
                    string       localIP = "";
                    host = Dns.GetHostEntry(Dns.GetHostName());
                    foreach (IPAddress ip in host.AddressList)
                    {
                        if (ip.AddressFamily == AddressFamily.InterNetwork)
                        {
                            localIP = ip.ToString();
                            break;
                        }
                    }
                    cmd.CommandText += "UPDATE  Beacon SET isdbmodified = True , IP='" + localIP + "' ;";
                    cmd.ExecuteNonQuery();
                    connection.Close();
                    //   refreshprenotazioni();
                    if (connection.State != ConnectionState.Closed)
                    {
                        connection.Close();
                    }
                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }

                    MySqlCommand cmd1 = connection.CreateCommand();
                    cmd1.CommandText = "INSERT INTO Colazioni (NumeroPrenotazione,NumeroPersone,CheckIn,CheckOut) VALUES(" + c.pren + "," + Colazioni.Value + "," + 1 + "," + 0 + ")";
                    cmd1.ExecuteNonQuery();
                    // cmd.CommandText = "select last_insert_id();";
                    //int idclient = Convert.ToInt32(cmd.ExecuteScalar());
                    cmd1.Dispose();
                    connection.Close();

                    connection.Close();

                    /*   string ncam="";
                     * string ntype="";
                     *  if (connection.State != ConnectionState.Closed)
                     *         connection.Close();
                     *
                     *     if (connection.State != ConnectionState.Open)
                     *         connection.Open();
                     *     MySqlCommand cmd2 = new MySqlCommand("SELECT camera,tipostanza FROM prenotazioni  WHERE prenotazioni.id=" + c.pren+";", connection);
                     *      MySqlDataReader reader= cmd2.ExecuteReader();
                     *
                     *      while (reader.Read())
                     *      {
                     *        ncam=  reader.GetValue(0).ToString();
                     *        ntype = reader.GetValue(1).ToString();
                     *      }
                     *
                     *      if (connection.State != ConnectionState.Closed)
                     *          connection.Close();*/



                    /*  if (connection.State != ConnectionState.Open)
                     *  connection.Open();
                     *
                     * MySqlCommand cmd3 = new MySqlCommand("UPDATE  camere SET tipo = '"+ntype+"' where camere.Name=" + ncam + ";", connection);*/
                    /*IPHostEntry host;
                     * string localIP = "";
                     * host = Dns.GetHostEntry(Dns.GetHostName());
                     * foreach (IPAddress ip in host.AddressList)
                     * {
                     *  if (ip.AddressFamily == AddressFamily.InterNetwork)
                     *  {
                     *      localIP = ip.ToString();
                     *      break;
                     *  }
                     * }*/
                    /* cmd3.ExecuteNonQuery();
                     * connection.Close();*/
                }
            }



            b3.RefreshOverview();
            b3.RefreshBook();
            b3.calctableau();
            this.Close();
        }