Пример #1
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (IsBtnConfirmEnabled())
            {
                try
                {
                    object comboBoxItem = comboBoxFitnessLvl.SelectedItem;

                    FitnessLevel fitnessLevel = (FitnessLevel)comboBoxItem
                                                .GetType().GetProperty("Value")
                                                .GetValue(comboBoxItem, null);

                    mainController.EditExerciseWithName(currentExercise.Name,
                                                        new Exercise(textBoxExerciseName.Text,
                                                                     fitnessLevel, textBoxExerciseDescription.Text));

                    DialogResult = DialogResult.OK;
                }
                catch (IncompleteDataException)
                {
                    MessageBox.Show("Nepotpuni ili neispravni podaci", "Greška!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (NameAlreadyTakenException)
                {
                    MessageBox.Show("Vježba s unesenim nazivom već postoji", "Greška!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #2
0
        public Target AddTarget(string location, string name, FitnessLevel fitnessLevel, int userId)
        {
            using (var db = new SqlConnection(ConnectionString))
            {
                var insertQuery = @"
                    INSERT INTO[dbo].[Targets]
                           ([Location]
                           ,[Name]
                           ,[FitnessLevel]
                           ,[UserId])
                    output inserted.*
                    VALUES
                           (@location
                           ,@name
                           ,@fitnessLevel
                           ,@userId)";

                var parameters = new
                {
                    Location     = location,
                    Name         = name,
                    FitnessLevel = fitnessLevel,
                    UserId       = userId
                };

                var newTarget = db.QueryFirstOrDefault <Target>(insertQuery, parameters);

                if (newTarget != null)
                {
                    return(newTarget);
                }
                throw new Exception("Could not create new target");
            }
        }
Пример #3
0
        private void UpdateList(List <Client> newClients)
        {
            listClients.Items.Clear();

            foreach (Client client in newClients)
            {
                string   oib           = client.Oib;
                string   firstName     = client.FirstName;
                string   lastName      = client.LastName;
                DateTime dateOfBirth   = client.DateOfBirth;
                string   phoneNumber   = client.PhoneNumber;
                DateTime dateOfJoining = client.DateOfJoining;

                FitnessLevel           fitnessLevel = client.FitnessLevel;
                FieldInfo              fi           = fitnessLevel.GetType().GetField(fitnessLevel.ToString());
                DescriptionAttribute[] attributes   =
                    (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
                string fitnessLevelString = attributes[0].Description;

                string notes = client.Notes;
                List <TrainingGroup> inTrainingGroups = client.InTrainingGroups;

                ListViewItem listItem = new ListViewItem(oib);
                listItem.SubItems.Add(firstName);
                listItem.SubItems.Add(lastName);
                listItem.SubItems.Add(dateOfBirth.ToString("d", CultureInfo.CreateSpecificCulture("hr-HR")));
                listItem.SubItems.Add(phoneNumber);
                listItem.SubItems.Add(dateOfJoining.ToString("d", CultureInfo.CreateSpecificCulture("hr-HR")));
                listItem.SubItems.Add(fitnessLevelString);
                listItem.SubItems.Add(notes);
                listItem.SubItems.Add(string.Join(", ", inTrainingGroups.Select(group => group.Name)));

                listClients.Items.Add(listItem);
            }
        }
Пример #4
0
        public Target AddTarget(string name, string location, FitnessLevel fitnessLevel, int userId)
        {
            var target = new Target()
            {
                Name = name
            };

            Targets.Add(target);
            return(target);
        }
Пример #5
0
 public Exercise(string name, FitnessLevel requiredFitnessLevel, string description)
 {
     if (!string.IsNullOrEmpty(name))
     {
         Name = name;
         RequiredFitnessLevel = requiredFitnessLevel;
         Description          = description;
     }
     else
     {
         throw new IncompleteDataException();
     }
 }
Пример #6
0
 public Training(string name, FitnessLevel requiredFitnessLevel, List <Exercise> exercises)
 {
     if (!string.IsNullOrEmpty(name) && exercises.Count > 0)
     {
         Name = name;
         RequiredFitnessLevel = requiredFitnessLevel;
         Exercises            = exercises;
     }
     else
     {
         throw new IncompleteDataException();
     }
 }
Пример #7
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (IsBtnConfirmEnabled())
            {
                try
                {
                    List <TrainingGroup> selectedGroups = new List <TrainingGroup>();

                    foreach (object item in listBoxGroups.SelectedItems)
                    {
                        TrainingGroup group = (TrainingGroup)item.GetType()
                                              .GetProperty("Value")
                                              .GetValue(item, null);
                        selectedGroups.Add(group);
                    }

                    object comboBoxItem = comboBoxFitnessLvl.SelectedItem;

                    FitnessLevel fitnessLevel = (FitnessLevel)comboBoxItem
                                                .GetType().GetProperty("Value")
                                                .GetValue(comboBoxItem, null);

                    mainController.AddClient(
                        new Client(textBoxOib.Text, textBoxFirstName.Text, textBoxLastName.Text,
                                   dtpDateOfBirth.Value, textBoxPhoneNum.Text,
                                   dtpDateOfJoining.Value, fitnessLevel,
                                   textBoxNotes.Text, selectedGroups));

                    DialogResult = DialogResult.OK;
                }
                catch (IncompleteDataException)
                {
                    MessageBox.Show("Nepotpuni ili neispravni podaci", "Greška!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (OibAlreadyTakenException)
                {
                    MessageBox.Show("Klijent s unesenim OIB-om već postoji", "Greška!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #8
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (IsBtnConfirmEnabled())
            {
                try
                {
                    object comboBoxItem = comboBoxFitnessLvl.SelectedItem;

                    FitnessLevel fitnessLevel = (FitnessLevel)comboBoxItem
                                                .GetType().GetProperty("Value")
                                                .GetValue(comboBoxItem, null);

                    List <Exercise> selectedExercises = new List <Exercise>();

                    foreach (object item in listBoxExercises.SelectedItems)
                    {
                        Exercise exercise = (Exercise)item.GetType()
                                            .GetProperty("Value")
                                            .GetValue(item, null);
                        selectedExercises.Add(exercise);
                    }

                    mainController.AddTraining(
                        new Training(textBoxTrainingName.Text, fitnessLevel,
                                     selectedExercises));

                    DialogResult = DialogResult.OK;
                }
                catch (IncompleteDataException)
                {
                    MessageBox.Show("Nepotpuni ili neispravni podaci", "Greška!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (NameAlreadyTakenException)
                {
                    MessageBox.Show("Trening s unesenim nazivom već postoji", "Greška!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #9
0
 public Client(string oib, string firstName, string lastName, DateTime dateOfBirth, string phoneNumber, DateTime dateOfJoining,
               FitnessLevel fitnessLevel, string notes, List <TrainingGroup> inTrainingGroups)
 {
     if (!string.IsNullOrEmpty(oib) && !string.IsNullOrEmpty(firstName) &&
         !string.IsNullOrEmpty(lastName) && !string.IsNullOrEmpty(phoneNumber) &&
         dateOfBirth != null && dateOfJoining != null &&
         inTrainingGroups.Count > 0)
     {
         Oib              = oib;
         FirstName        = firstName;
         LastName         = lastName;
         DateOfBirth      = dateOfBirth;
         PhoneNumber      = phoneNumber;
         DateOfJoining    = dateOfJoining;
         FitnessLevel     = fitnessLevel;
         Notes            = notes;
         InTrainingGroups = inTrainingGroups;
     }
     else
     {
         throw new IncompleteDataException();
     }
 }
Пример #10
0
        private void UpdateList(List <Training> newTraining)
        {
            listTrainings.Items.Clear();

            foreach (Training training in newTraining)
            {
                string name = training.Name;

                FitnessLevel           requiredFitnessLevel = training.RequiredFitnessLevel;
                FieldInfo              fi         = requiredFitnessLevel.GetType().GetField(requiredFitnessLevel.ToString());
                DescriptionAttribute[] attributes =
                    (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
                string requiredFitnessLevelString = attributes[0].Description;

                List <Exercise> exercises = training.Exercises;

                ListViewItem listItem = new ListViewItem(name);
                listItem.SubItems.Add(requiredFitnessLevelString);
                listItem.SubItems.Add(String.Join(", ", exercises.Select(exercise => exercise.Name)));

                listTrainings.Items.Add(listItem);
            }
        }
Пример #11
0
        private void UpdateList(List <Exercise> newExercises)
        {
            listExercises.Items.Clear();

            foreach (Exercise exercise in newExercises)
            {
                string name = exercise.Name;

                FitnessLevel           requiredFitnessLevel = exercise.RequiredFitnessLevel;
                FieldInfo              fi         = requiredFitnessLevel.GetType().GetField(requiredFitnessLevel.ToString());
                DescriptionAttribute[] attributes =
                    (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
                string requiredFitnessLevelString = attributes[0].Description;

                string description = exercise.Description;

                ListViewItem listItem = new ListViewItem(name);
                listItem.SubItems.Add(requiredFitnessLevelString);
                listItem.SubItems.Add(description);

                listExercises.Items.Add(listItem);
            }
        }