Ejemplo n.º 1
0
 public AddEntriesUI(int userID)
 {
     // avataan ikkuna keskellä ruutua ja luodaan olio
     WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
     InitializeComponent();
     headacheObj        = new Headache();
     headacheObj.UserID = userID;
 }
Ejemplo n.º 2
0
 public MainWindow(int userID)
 {
     InitializeComponent();
     // luodaan headache-olio ja asetetaan sen userID:ksi parametri userID
     headacheObj        = new Headache();
     headacheObj.UserID = userID;
     // avataan ikkuna keskellä ruutua
     WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
 }
Ejemplo n.º 3
0
        public static bool AddToSQLite(Headache headache) // Lisäysmetodi
        {
            if (System.IO.File.Exists(filePath))          // Tarkistetaan, onko tiedosto olemassa
            {
                // Luodaan yhteys
                SQLiteConnection connection = new SQLiteConnection($"Data Source = {filePath}; Version=3; Password={password}"); // Yhteys + connection string


                // Luodaan komento ja lisätään sille yhteys
                SQLiteCommand cmd = new SQLiteCommand("INSERT INTO Headache (Date, UserID, AcheType, PainLevel, Medications, Symptoms, Triggers, Reliefs, Notes) Values (@Date, @UserID, @AcheType, @PainLevel, @Medications, @Symptoms, @Triggers, @Reliefs, @Notes)", connection);
                cmd.CommandType = CommandType.Text;
                cmd.Connection  = connection;


                // Lisätään tieto komentoon muuttujina
                cmd.Parameters.AddWithValue("@Date", headache.Date);
                cmd.Parameters.AddWithValue("@UserID", headache.UserID);
                cmd.Parameters.AddWithValue("@AcheType", headache.AcheType);
                cmd.Parameters.AddWithValue("@PainLevel", headache.PainLevel);
                cmd.Parameters.AddWithValue("@Medications", headache.Medications);
                cmd.Parameters.AddWithValue("@Symptoms", headache.Symptoms);
                cmd.Parameters.AddWithValue("@Triggers", headache.Triggers);
                cmd.Parameters.AddWithValue("@Reliefs", headache.Reliefs);
                cmd.Parameters.AddWithValue("@Notes", headache.Notes);

                // Avataan yhteys
                connection.Open();

                // Suoritetaan komento
                cmd.ExecuteNonQuery();

                // Suljetaan yhteys
                connection.Close();

                return(true);
            }
            else // Jos tiedostoa ei löydy, heitetään poikkeus
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        private Headache headacheObj;             // yksityinen olio käsittelyä varten
        public EditEntry(int userID, int entryID) // tässä konstruktorissa on paljon asiaa, mutta siksi, jotta voidaan siirtää tietoa
                                                  // tälle ikkunalle toisesta ikkunasta käsin + asetettua ne kun ikkuna avataan
        {
            InitializeComponent();

            // luodaan uusi olio
            headacheObj = new Headache();

            headacheObj.UserID = userID;
            headacheObj.AcheID = entryID;
            DatabaseAccess.GetHeadacheObjPFromSQLite(headacheObj, entryID); // Haetaan tietoa tietokannasta


            // laitetaan tietokannan tiedot olion kautta tekstilaatikkoihin
            txbAcheType.Text    = headacheObj.AcheType;
            txbPainLevel.Text   = headacheObj.PainLevel.ToString();
            txbMedications.Text = headacheObj.Medications;
            txbSymptoms.Text    = headacheObj.Symptoms;
            txbTriggers.Text    = headacheObj.Triggers;
            txbReliefs.Text     = headacheObj.Reliefs;
            txbNotes.Text       = headacheObj.Notes;
        }
Ejemplo n.º 5
0
        public static bool SaveEditedEntryToSQLite(Headache headache) // Tallennetaan tietoja tietokantaan
        {
            if (System.IO.File.Exists(filePath))
            {
                // Luodaan yhteys
                SQLiteConnection connection = new SQLiteConnection($"Data Source = {filePath}; Version=3; Password={password}"); // Yhteys + connection string

                // Luodaan komento ja lisätään sille yhteys
                SQLiteCommand cmd = new SQLiteCommand("UPDATE Headache SET AcheType = @AcheType, PainLevel = @PainLevel, Medications = @Medications, Symptoms = @Symptoms, Triggers = @Triggers, Reliefs = @Reliefs, Notes = @Notes WHERE AcheID = @AcheID;", connection);
                cmd.CommandType = CommandType.Text;
                cmd.Connection  = connection;

                // Lisätään tieto komentoon muuttujina
                cmd.Parameters.AddWithValue("@AcheType", headache.AcheType);
                cmd.Parameters.AddWithValue("@PainLevel", headache.PainLevel);
                cmd.Parameters.AddWithValue("@Medications", headache.Medications);
                cmd.Parameters.AddWithValue("@Symptoms", headache.Symptoms);
                cmd.Parameters.AddWithValue("@Triggers", headache.Triggers);
                cmd.Parameters.AddWithValue("@Reliefs", headache.Reliefs);
                cmd.Parameters.AddWithValue("@Notes", headache.Notes);
                cmd.Parameters.AddWithValue("@AcheID", headache.AcheID);

                // Avataan yhteys
                connection.Open();

                // Suoritetaan komento
                cmd.ExecuteNonQuery();

                // Suljetaan yhteys
                connection.Close();

                return(true);
            }
            else // Jos tiedostoa ei löydy, heitetään poikkeus
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
        public static void GetHeadacheObjPFromSQLite(Headache headache, int id)
        {
            if (System.IO.File.Exists(filePath))
            {
                headache.UserID = id;
                SQLiteConnection connection = new SQLiteConnection($"Data Source = {filePath}; Version=3; Password={password}"); // Yhteys + connection string
                connection.Open();                                                                                               // Avataan yhteys

                // asetetaan olion AcheType
                SQLiteCommand cmdAcheType = new SQLiteCommand($"SELECT AcheType FROM Headache WHERE AcheID LIKE {id}", connection);
                var           holder1     = cmdAcheType.ExecuteScalar();
                if (holder1 != null)
                {
                    headache.AcheType = holder1.ToString();
                }
                else
                {
                    headache.AcheType = null;
                }

                // aseteaan olion PainLevel
                SQLiteCommand cmdPainLevel = new SQLiteCommand($"SELECT PainLevel FROM Headache WHERE AcheID LIKE {id}", connection);
                var           holder2      = cmdPainLevel.ExecuteScalar();
                if (holder2 != null)
                {
                    string painLevelstring = holder2.ToString();
                    Int32.TryParse(painLevelstring, out int painLevelInt);
                    headache.PainLevel = painLevelInt;
                }
                else
                {
                    headache.PainLevel = 0;
                }

                // asetetaan olion Medications
                SQLiteCommand cmdMedications = new SQLiteCommand($"SELECT Medications FROM Headache WHERE AcheID LIKE {id}", connection);
                var           holder3        = cmdMedications.ExecuteScalar();
                if (holder3 != null)
                {
                    headache.Medications = holder3.ToString();
                }
                else
                {
                    headache.Medications = null;
                }

                // asetetaan olion Symptoms
                SQLiteCommand cmdSymptoms = new SQLiteCommand($"SELECT Symptoms FROM Headache WHERE AcheID LIKE {id}", connection);
                var           holder4     = cmdSymptoms.ExecuteScalar();
                if (holder4 != null)
                {
                    headache.Symptoms = holder4.ToString();
                }
                else
                {
                    headache.Symptoms = null;
                }

                // asetetaan olion Triggers
                SQLiteCommand cmdTriggers = new SQLiteCommand($"SELECT Triggers FROM Headache WHERE AcheID LIKE {id}", connection);
                var           holder5     = cmdTriggers.ExecuteScalar();
                if (holder5 != null)
                {
                    headache.Triggers = holder5.ToString();
                }
                else
                {
                    headache.Triggers = null;
                }

                // asetetaan olion Reliefs
                SQLiteCommand cmdReliefs = new SQLiteCommand($"SELECT Reliefs FROM Headache WHERE AcheID LIKE {id}", connection);
                var           holder6    = cmdReliefs.ExecuteScalar();
                if (holder6 != null)
                {
                    headache.Reliefs = holder6.ToString();
                }
                else
                {
                    headache.Reliefs = null;
                }

                // asetetaan olion Notes
                SQLiteCommand cmdNotes = new SQLiteCommand($"SELECT Notes FROM Headache WHERE AcheID LIKE {id}", connection);
                var           holder7  = cmdNotes.ExecuteScalar();
                if (holder7 != null)
                {
                    headache.Notes = holder7.ToString();
                }
                else
                {
                    headache.Notes = null;
                }

                // Suljetaan yhteys
                connection.Close();
            }
            else // Jos tiedostoa ei löydy, heitetään poikkeus
            {
                throw new System.IO.FileNotFoundException("File not found");
            }
        }