示例#1
0
        //Query databe on a region index, return it's name in string
        public static string RegionIndexToName(int index)
        {
            string region = "Haku ei onnistunut";

            try
            {
                ConnectionUtils.OpenConnection();
                MySqlDataReader reader = null;
                string          query  = "SELECT * FROM toimintaalue " +
                                         "WHERE toimintaalue_id = " + index + ";";
                MySqlCommand command = new MySqlCommand(query, ConnectionUtils.connection);
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    region = (string)reader["nimi"];
                }
                reader.Close();
                ConnectionUtils.CloseConnection();
                return(region);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(region);
            }
        }
        private void btnRegionAddAdd_Click(object sender, EventArgs e)
        {
            try
            {
                //Add a region to the database, gets data from form components
                string query = "START TRANSACTION; " +
                               "INSERT INTO toimintaalue(toimintaalue_id,nimi) " +
                               "VALUES(default,'" +
                               TextBoxUtils.ModifyInput(tbRegionAddRegionName.Text, 40) + "');" +
                               "COMMIT;";

                try
                {
                    ConnectionUtils.OpenConnection();
                    MySqlCommand command = new MySqlCommand(query, ConnectionUtils.connection);
                    command.ExecuteNonQuery();
                    ConnectionUtils.CloseConnection();
                    this.Close();
                }
                catch (Exception ex)
                {
                    //Incase of database-connection problems
                    ConnectionUtils.CloseConnection();
                    MessageBox.Show("Virhe tietojen syöttämisessä tietokantaan. Tarkista kenttien tiedot. Lisätietoja: " + ex.Message.ToString());
                }
            }
            catch (Exception ex)
            {
                //Incase of variable conversion problems
                ConnectionUtils.CloseConnection();
                MessageBox.Show("Virhe tietojen muuntamisessa. Tarkista kenttien tiedot. Lisätietoja: " + ex.Message.ToString());
            }
        }
示例#3
0
        //Query database on a region name, and return it's index
        public static int RegionNameToIndex(string region)
        {
            int index = 0;

            try
            {
                ConnectionUtils.OpenConnection();
                MySqlDataReader reader = null;
                string          query  = "SELECT * FROM toimintaalue " +
                                         "WHERE nimi = '" + region + "';";
                MySqlCommand command = new MySqlCommand(query, ConnectionUtils.connection);
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    index = reader.GetInt32(0);
                }
                reader.Close();
                ConnectionUtils.CloseConnection();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return(index);
        }
示例#4
0
        private void btnModifyCottageModify_Click(object sender, EventArgs e)
        {
            //Make sure the data should be modified
            DialogResult result = MessageBox.Show("Haluatko varmasti muuttaa valitun mökin tietoja?", "Muuta mökin tietoja",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (result == DialogResult.Yes)
            {
                try
                {
                    //Updates cottages information in the database. Gets data from form components, cottage is uniquely identified by cottageID, which can't be modified
                    string query = "START TRANSACTION; " +
                                   "UPDATE mokki " +
                                   "SET toimintaalue_id=" + RegionUtils.RegionNameToIndex(cbModifyCottageRegion.Text) +
                                   ",postinro='" + TextBoxUtils.ModifyInput(tbModifyCottagePostNum.Text, 5) +
                                   "',mokkinimi='" + TextBoxUtils.ModifyInput(tbModifyCottageName.Text, 45) +
                                   "',katuosoite='" + TextBoxUtils.ModifyInput(tbModifyCottageStreet.Text, 45) + "'," +
                                   "kuvaus='" + TextBoxUtils.ModifyInput(tbModifyCottageDescription.Text, 500) +
                                   "',henkilomaara=" + nudModifyCottageCapacity.Value +
                                   " ,varustelu='" + TextBoxUtils.ModifyInput(cbModifyCottageEquipment.Text, 100) +
                                   "', hinta=" + Convert.ToDouble(nudModifyCottagePrice.Value) + " " +
                                   "WHERE mokki_id=" + Convert.ToInt32(lblModifyCottageID.Text) + "; " +
                                   "COMMIT;";
                    try
                    {
                        ConnectionUtils.OpenConnection();
                        MySqlCommand command = new MySqlCommand(query, ConnectionUtils.connection);
                        command.ExecuteNonQuery();
                        ConnectionUtils.CloseConnection();
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        //Incase of database-connection problems
                        ConnectionUtils.CloseConnection();
                        MessageBox.Show("Virhe tietojen syöttämisessä tietokantaan. Tarkista kenttien tiedot, ja yritä uudelleen myöhemmin. Lisätietoja virheestä: "
                                        + ex.Message.ToString());
                    }
                }
                catch (Exception ex)
                {
                    //Incase of variable conversion problems
                    ConnectionUtils.CloseConnection();
                    MessageBox.Show("Virhe tietojen muuntamisessa. Onhan kaikkien kenttien syötteet oikein? Lisätietoja virheestä: " + ex.Message.ToString());
                }
            }
        }
        private void btnModifyServiceModify_Click(object sender, EventArgs e)
        {
            //Make sure the data should be modified
            DialogResult result = MessageBox.Show("Haluatko varmasti muuttaa valitun palvelun tietoja?", "Muuta palvelun tietoja",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (result == DialogResult.Yes)
            {
                try
                {
                    //Updates services information in the database. Gets data from form components, service is uniquely identified by serviceID, which can't be modified
                    string query = "START TRANSACTION; " +
                                   "UPDATE palvelu " +
                                   "SET toimintaalue_id=" + RegionUtils.RegionNameToIndex(cbModifyServiceRegion.Text) +
                                   ",nimi='" + TextBoxUtils.ModifyInput(tbModifyServiceName.Text, 40) +
                                   "',tyyppi=" + Convert.ToInt32(tbModifyServiceType.Text) +
                                   ",kuvaus='" + TextBoxUtils.ModifyInput(tbModifyServiceDescription.Text, 40) + "'," +
                                   "hinta=" + Convert.ToDouble(nudModifyServicePrice.Value) +
                                   ",alv=" + Convert.ToDouble(nudModifyServiceVAT.Value) + " " +
                                   "WHERE palvelu_id=" + Convert.ToInt32(lblModifyServiceID.Text) + "; " +
                                   "COMMIT;";
                    try
                    {
                        ConnectionUtils.OpenConnection();
                        MySqlCommand command = new MySqlCommand(query, ConnectionUtils.connection);
                        command.ExecuteNonQuery();
                        ConnectionUtils.CloseConnection();
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        //Incase of database-connection problems
                        ConnectionUtils.CloseConnection();
                        MessageBox.Show("Virhe tietojen syöttämisessä tietokantaan. Tarkista kenttien tiedot, ja yritä uudelleen myöhemmin. Lisätietoja virheestä: "
                                        + ex.Message.ToString());
                    }
                }
                catch (Exception ex)
                {
                    //Incase of variable conversion problems
                    ConnectionUtils.CloseConnection();
                    MessageBox.Show("Virhe tietojen muuntamisessa. Onhan kaikkien kenttien syötteet oikein? Lisätietoja virheestä: " + ex.Message.ToString());
                }
            }
        }
示例#6
0
        public static bool CheckCottageID(int mokki_id) //Check is database contains selected cottage
        {
            ConnectionUtils.OpenConnection();
            MySqlCommand    msc    = new MySqlCommand("SELECT mokki_id FROM mokki WHERE MOKKI_ID = '" + mokki_id + "'", ConnectionUtils.connection);
            MySqlDataReader reader = msc.ExecuteReader();

            if (!reader.HasRows)
            {
                ConnectionUtils.CloseConnection();
                MessageBox.Show("Antamaasi mökkiID:tä ei löytynyt.", "Virhe", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            else
            {
                ConnectionUtils.CloseConnection();
                return(true);
            }
        }
示例#7
0
        public static bool CheckOrderCottageBookDate(int mokki_id, int varaus_id, string dateFrom, string DateTo)
        {
            ConnectionUtils.OpenConnection(); // Check is the same cottage in other orders free at the indicated time
            MySqlCommand msc = new MySqlCommand("SELECT mokki_id FROM mokki " +
                                                "WHERE mokki_id = " + mokki_id + " " +
                                                "AND mokki_id IN " +
                                                "(SELECT mokki_mokki_id FROM varaus v WHERE '" + dateFrom + " 16:00:00' < v.varattu_loppupvm AND '" + DateTo + " 12:00:00' > v.varattu_alkupvm AND '" + varaus_id + "' != VARAUS_ID);", ConnectionUtils.connection);
            MySqlDataReader reader = msc.ExecuteReader();

            if (reader.HasRows)
            {
                ConnectionUtils.CloseConnection();
                MessageBox.Show("Valitsemasi mökki on varattu annetuna ajalla", "Mökki varattu annetuna ajalla", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            else
            {
                ConnectionUtils.CloseConnection();
                return(true);
            }
        }
 private void btnAddCottageAdd_Click(object sender, EventArgs e)
 {
     //Add a cottage to the database, gets data from form components
     try
     {
         PostUtils.CheckPostal(tbAddCottagePostNum.Text, tbAddCottagePostRegion.Text);
         string query = "START TRANSACTION; " +
                        "INSERT INTO mokki(mokki_id,toimintaalue_id,postinro,mokkinimi,katuosoite,kuvaus,henkilomaara,varustelu,hinta) " +
                        "VALUES(default," +
                        RegionUtils.RegionNameToIndex(cbAddCottageRegion.Text) + ",'" +
                        TextBoxUtils.ModifyInput(tbAddCottagePostNum.Text, 5) + "','" +
                        TextBoxUtils.ModifyInput(tbAddCottageName.Text, 45) + "','" +
                        TextBoxUtils.ModifyInput(tbAddCottageStreet.Text, 45) + "','" +
                        TextBoxUtils.ModifyInput(tbAddCottageDescription.Text, 500) + "'," +
                        (int)nudAddCottageCapacity.Value + ",'" +
                        TextBoxUtils.ModifyInput(cbAddCottageEquipment.Text, 100) + "'," +
                        (double)nudAddCottagePrice.Value + "); " +
                        "COMMIT;";
         try
         {
             ConnectionUtils.OpenConnection();
             MySqlCommand command = new MySqlCommand(query, ConnectionUtils.connection);
             command.ExecuteNonQuery();
             ConnectionUtils.CloseConnection();
             this.Close();
         }
         catch (Exception ex)
         {
             //Incase of connction problems
             ConnectionUtils.CloseConnection();
             MessageBox.Show("Virhe tietojen syöttämisessä tietokantaan. Tarkista kenttien tiedot. Lisätietoja: " + ex.Message.ToString());
         }
     }
     catch (Exception ex)
     {
         //Incase of exceptions in variable conversion
         ConnectionUtils.CloseConnection();
         MessageBox.Show("Virhe tietojen muuntamisessa. Tarkista kenttien tiedot. Lisätietoja: " + ex.Message.ToString());
     }
 }
        private void btnRegionModifyModify_Click(object sender, EventArgs e)
        {
            //Make sure the data should be modified
            DialogResult result = MessageBox.Show("Haluatko varmasti muuttaa valitun toiminta-alueen nimeä?", "Muuta toiminta-alueen nimeä",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (result == DialogResult.Yes)
            {
                try
                {
                    //Updates regions information in the database. Gets data from form components, region is uniquely identified by regionID, which can't be modified
                    string query = "START TRANSACTION; " +
                                   "UPDATE toimintaalue " +
                                   "SET nimi='" + TextBoxUtils.ModifyInput(tbRegionModifyRegionName.Text, 40) + "' " +
                                   "WHERE toimintaalue_id=" + Convert.ToInt32(TextBoxUtils.ModifyInput(lblRegionModifyRegionID.Text, 11)) + "; " +
                                   "COMMIT;";
                    try
                    {
                        ConnectionUtils.OpenConnection();
                        MySqlCommand command = new MySqlCommand(query, ConnectionUtils.connection);
                        command.ExecuteNonQuery();
                        ConnectionUtils.CloseConnection();
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        //Incase of database-connection problems
                        ConnectionUtils.CloseConnection();
                        MessageBox.Show("Virhe tietojen syöttämisessä tietokantaan. Yritä uudelleen myöhemmin. Lisätietoja virheestä: "
                                        + ex.Message.ToString());
                    }
                }
                catch (Exception ex)
                {
                    //Incase of variable conversion problems
                    ConnectionUtils.CloseConnection();
                    MessageBox.Show("Virhe tietojen muuntamisessa. Onhan kaikkien kenttien syötteet oikein? Lisätietoja virheestä: " + ex.Message.ToString());
                }
            }
        }
示例#10
0
        private void btnAddServiceAdd_Click(object sender, EventArgs e)
        {
            try
            {
                //Add a service to the database, gets data from form components
                string query = "START TRANSACTION; " +
                               "INSERT INTO palvelu(palvelu_id,toimintaalue_id,nimi,tyyppi,kuvaus,hinta,alv) " +
                               "VALUES(default," +
                               RegionUtils.RegionNameToIndex(cbAddServiceRegion.Text) + ",'" +
                               TextBoxUtils.ModifyInput(tbAddServiceName.Text, 40) + "'," +
                               Convert.ToInt32(tbAddServiceType.Text) + ",'" +
                               TextBoxUtils.ModifyInput(tbAddServiceDescription.Text, 500) + "'," +
                               (double)nudAddServicePrice.Value + "," +
                               (double)nudAddServiceVAT.Value + "); " +
                               "COMMIT;";

                try
                {
                    ConnectionUtils.OpenConnection();
                    MySqlCommand command = new MySqlCommand(query, ConnectionUtils.connection);
                    command.ExecuteNonQuery();
                    ConnectionUtils.CloseConnection();
                    this.Close();
                }
                catch (Exception ex)
                {
                    //Incase of database-connection problems
                    ConnectionUtils.CloseConnection();
                    MessageBox.Show("Virhe tietojen syöttämisessä tietokantaan. Tarkista kenttien tiedot. Lisätietoja: " + ex.Message.ToString());
                }
            }
            catch (Exception ex)
            {
                //Incase of variable conversion problems
                ConnectionUtils.CloseConnection();
                MessageBox.Show("Virhe tietojen muuntamisessa. Tarkista kenttien tiedot. Lisätietoja: " + ex.Message.ToString());
            }
        }