Esempio n. 1
0
        //---------------------------------------------------------------------------
        private void AddNewPositiveHabitForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //saving a file fill be done when user exits Form
            DialogResult dialogResult = MessageBox.Show(
                "Save object?",
                " ",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button1,
                MessageBoxOptions.DefaultDesktopOnly);

            if (dialogResult == DialogResult.Yes)
            {
                NewPositiveHabit.CoreDescription = tbCoreDescription.Text;
                if (tbCoreDescription.Text == string.Empty || tbCoreDescription.Text == "")
                {
                    MessageBox.Show("Core Description is the only property that can't be empty", " ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;
                }

                try {
                    NewPositiveHabit.Frequency         = (PositiveHabitFrequency)cbFrequency.SelectedItem;
                    NewPositiveHabit.Category          = (PositiveHabitCategory)cbCategory.SelectedItem;
                    NewPositiveHabit.CommonDenominator = (PositiveHabitCommonDenominatorCategory)cbCommonDenominator.SelectedItem;
                }
                catch {
                    if (cbFrequency.SelectedIndex == -1)
                    {
                        MessageBox.Show("Frequency needs to be selected", " ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        e.Cancel = true;
                    }
                    if (cbCategory.SelectedIndex == -1)
                    {
                        MessageBox.Show("Category needs to be selected", " ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        e.Cancel = true;
                    }
                    if (cbCommonDenominator.SelectedIndex == -1)
                    {
                        MessageBox.Show("Common denominator needs to be selected", " ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        e.Cancel = true;
                    }
                }
                NewPositiveHabit.FullDescription  = tbFullDescription.Text;
                NewPositiveHabit.ReasonOfNotDoing = tbReasonOfNotDoing.Text;
                NewPositiveHabit.PossibleSolution = tbPossibleSolution.Text;

                this.DialogResult = DialogResult.Yes; //refers to THIS Form (AddNewRowForm)
            }
            else
            {
                NewPositiveHabit  = null;
                this.DialogResult = DialogResult.No; //refers to THIS Form (AddNewRowForm)
            }
        }
        public static void LoadXmltoList(List <PositiveHabit> positiveHabitCollection)
        {
            DataTable tableInsideXml = new DataTable();

            try {
                tableInsideXml.ReadXml("MehrereFunktionenDataBase.xml");
            }
            //wenn ich es könnte besser sein?
            //these 2 exceptions WERE doubled
            catch (FileNotFoundException ex) {
                HandleLoadExceptions(ex, tableInsideXml);
                ////case: no file whatsoever
                //MessageBox.Show(ex.Message);
                //dataTable.TableName = "PositiveHabitRecord";
                //dataTable.WriteXml("MehrereFunktionenDataBase.xml", XmlWriteMode.WriteSchema);

                ////and try again, now it won't fire Exception
                //dataTable.ReadXml("MehrereFunktionenDataBase.xml");
            }
            catch (ArgumentException ex) {
                HandleLoadExceptions(ex, tableInsideXml);
                ////case: sometimes
                //MessageBox.Show(ex.Message);
                //dataTable.TableName = "PositiveHabitRecord";
                //dataTable.WriteXml("MehrereFunktionenDataBase.xml", XmlWriteMode.WriteSchema);

                ////and try again, now it won't fire Exception
                //dataTable.ReadXml("MehrereFunktionenDataBase.xml");
            }

            foreach (DataRow dataRow in tableInsideXml.AsEnumerable())
            {
                PositiveHabit PositiveHabit = new PositiveHabit();

                PositiveHabit.CoreDescription =
                    ((dataRow[0] == DBNull.Value /*null*/) ? string.Empty : (string)dataRow[0]);

                PositiveHabit.Frequency         = (PositiveHabitFrequency)dataRow[1];
                PositiveHabit.Category          = (PositiveHabitCategory)dataRow[2];
                PositiveHabit.CommonDenominator = (PositiveHabitCommonDenominatorCategory)dataRow[3];

                PositiveHabit.FullDescription =
                    ((dataRow[4] == DBNull.Value /*null*/) ? string.Empty : (string)dataRow[4]);
                PositiveHabit.ReasonOfNotDoing =
                    ((dataRow[5] == DBNull.Value /*null*/) ? string.Empty : (string)dataRow[5]);
                PositiveHabit.PossibleSolution =
                    ((dataRow[6] == DBNull.Value /*null*/) ? string.Empty : (string)dataRow[6]);

                PositiveHabit.LastCheckedInComboBox = (DateTime)dataRow[7];

                positiveHabitCollection.Add(PositiveHabit);
            }
        }
Esempio n. 3
0
        //---------------------------------------------------------------------------
        public void SendCurrentInformations(PositiveHabit dataAboutParticularAction)
        {
            //this method is called >>before<< .ShowDialog() so I can send object
            //whose Properties are used below
            lCoreDescription.Text   = "core description....." + dataAboutParticularAction.CoreDescription;
            lFrequency.Text         = "current frequency...." + dataAboutParticularAction.Frequency;
            lCategory.Text          = "category............." + dataAboutParticularAction.Category;
            lCommonDenominator.Text = "common denominator..." + dataAboutParticularAction.CommonDenominator;

            lLastChecked.Text = "last checked at......" + dataAboutParticularAction.LastCheckedInComboBox.ToShortDateString();

            tbFullDescription.Text  = dataAboutParticularAction.FullDescription;
            tbReasonOfNotDoing.Text = dataAboutParticularAction.ReasonOfNotDoing;
            tbPossibleSolution.Text = dataAboutParticularAction.PossibleSolution;


            currentActiveAction = dataAboutParticularAction;
        }
Esempio n. 4
0
        //---------------------------------------------------------------------------
        /// <summary>
        /// EH handling adding new record
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bAddNewRecord_Click(object sender, EventArgs e)
        {
            AddNewPositiveHabitForm addNewRowForm = new AddNewPositiveHabitForm();

            PositiveHabit tempPositiveHabit = new PositiveHabit();

            addNewRowForm.NewPositiveHabit = tempPositiveHabit;
            this.Hide();
            DialogResult dialogResult = addNewRowForm.ShowDialog();

            if (dialogResult == DialogResult.Yes)
            {
                //MessageBox.Show("Successfully created new PositiveHabit !"); //test
                positiveHabitCollection.Add(tempPositiveHabit);
                UpdateDgvRecordsFromCollection();
            }
            else if (dialogResult == DialogResult.No)
            {
                //MessageBox.Show("Creating aborted !"); //test
            }

            this.Show();
        }