Beispiel #1
0
        private void btnFinish_Click(object sender, EventArgs e)
        {
            Boolean       isCountable = true;
            string        info, label;
            int           setsAmount = 0;
            trainingDone  newDone    = new trainingDone();
            List <string> setDetails = new List <string>();

            foreach (FlowLayoutPanel flp in panelBig.Controls)
            {
                info  = "";
                label = "";
                setDetails.Clear();
                foreach (Control ctrl in flp.Controls)
                {
                    if (ctrl is TextBox)
                    {
                        if (ctrl.Text != "")
                        {
                            //info += ctrl.Text + "|";
                            setDetails.Add(ctrl.Text);
                            setsAmount++;
                        }
                    }
                    if (ctrl is Label)
                    {
                        label = ctrl.Text;
                    }
                }
                IQueryable <Exercise> exName =
                    from ex in FPdatabase.Exercise
                    where ex.name == label
                    select ex;

                IQueryable <TE> exercise =
                    from te in FPdatabase.TE
                    where te.trainingID == training.trainingID && te.exerciseID == exName.FirstOrDefault().exerciseID
                    select te;


                if (setDetails.Count() != 0)
                {
                    for (int i = 0; i < setDetails.Count(); i++)
                    {
                        info += setDetails[i] + "|";
                    }
                    var exerciseToUpdate = exName.SingleOrDefault();
                    exerciseToUpdate.lastInfo = info;
                    FPdatabase.SubmitChanges();

                    ExerciseInfo exInfo = new ExerciseInfo
                    {
                        setsAmount = setsAmount
                    };
                    exInfo.trainingDone = newDone;
                    exInfo.TE           = exercise.AsEnumerable().LastOrDefault();

                    FPdatabase.ExerciseInfo.InsertOnSubmit(exInfo);
                    FPdatabase.SubmitChanges();
                    for (int i = 0; i < setDetails.Count(); i++)
                    {
                        ExerciseDetail exDetail = new ExerciseDetail
                        {
                            setNumber    = i + 1,
                            ExerciseInfo = exInfo,
                            setInfo      = setDetails[i]
                        };
                        FPdatabase.ExerciseDetail.InsertOnSubmit(exDetail);
                        FPdatabase.SubmitChanges();
                    }
                    isCountable = true;
                }
            }
            if (isCountable)
            {
                string comment = textBox1.Text;
                newDone.date       = DateTime.Today;
                newDone.trainingID = training.trainingID;
                //newDone.Training = training;


                if (comment == "" || comment == "Type here...")
                {
                    newDone.comment = "none";
                }
                else
                {
                    newDone.comment = comment;
                }
                FPdatabase.SubmitChanges();
                MessageBox.Show("Congratulations! You have succesfully finished training!", "Congrats!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            else
            {
                MessageBox.Show("You didn't do anything!", "??", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #2
0
        private void btnFinish_Click(object sender, EventArgs e)
        {
            Boolean isCountable = true;
            string  info, label;

            //int counter;

            foreach (FlowLayoutPanel flp in panelBig.Controls)
            {
                info  = "";
                label = "";
                //counter = 0;
                foreach (Control ctrl in flp.Controls)
                {
                    if (ctrl is TextBox)
                    {
                        //counter++;
                        if (ctrl.Text != "")
                        {
                            info += ctrl.Text + "|";
                        }
                    }
                    if (ctrl is Label)
                    {
                        label = ctrl.Text;
                    }
                }
                IQueryable <Exercise> exName =
                    from ex in FPdatabase.Exercise
                    where ex.name == label
                    select ex;

                IQueryable <TE> exercise =
                    from te in FPdatabase.TE
                    where te.trainingID == training.trainingID && te.exerciseID == exName.FirstOrDefault().exerciseID
                    select te;


                if (info != "")
                {
                    var exerciseToUpdate = exName.SingleOrDefault();
                    exerciseToUpdate.lastInfo = info;
                    FPdatabase.SubmitChanges();

                    ExerciseInfo exInfo = new ExerciseInfo
                    {
                        info     = info,
                        randomPK = exercise.AsEnumerable().LastOrDefault().randomPK,
                    };
                    var lastDone = (from ld in FPdatabase.trainingDone select ld).AsEnumerable().LastOrDefault();
                    if (lastDone == null)
                    {
                        exInfo.doneID = 1;
                    }
                    else
                    {
                        exInfo.doneID = lastDone.doneID + 1;
                    }
                    FPdatabase.ExerciseInfo.InsertOnSubmit(exInfo);
                    FPdatabase.SubmitChanges();
                    isCountable = true;
                }
            }
            if (isCountable)
            {
                string       comment = Microsoft.VisualBasic.Interaction.InputBox("Please add a comment to your training!", "comment", "");
                trainingDone newDone = new trainingDone();
                FPdatabase.trainingDone.InsertOnSubmit(newDone);
                newDone.date       = DateTime.Now.Date;
                newDone.trainingID = training.trainingID;
                if (comment == "")
                {
                    newDone.comment = "none";
                }
                else
                {
                    newDone.comment = comment;
                }
                FPdatabase.SubmitChanges();
                MessageBox.Show("Congratulations! You have succesfully finished training!", "Congrats!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            else
            {
                MessageBox.Show("You didn't do anything!", "??", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }