Exemplo n.º 1
0
        public override void AddParentEntry()         // Add a Termin
        {
            TimeBox timeBox = new TimeBox(true);

            timeBox.posEntry.Text = "0";             // Default pos
            Entry    textEntry = new Entry();
            ComboBox cbType    = new ComboBox(API_Contract.ProgrammTerminTypVal);

            cbType.Active = 1;             // Default is 'Programm'
            GetUserArgs[] args = new GetUserArgs[] {
                new GetUserArgs(new Label("Text"), textEntry),
                new GetUserArgs(new Label("Sichtbarkeit"), cbType),
            };
            var diag = new GetUserDataDialog(args, timeBox, "Speichern", 0, "Abbruch", 1);

            if (diag.Run() == 0)
            {
                bool validated;
                while (!(validated = timeBox.ValidateTime()))
                {
                    if (diag.Run() == 1)
                    {
                        validated = false;
                        break;
                    }
                }
                if (validated)                   // There is valid user data
                {
                    var    treeContent = CurrTreeStore;
                    string finalTime;
                    string tmpTime   = timeBox.Time;
                    string text      = textEntry.Text;
                    string typString = GtkHelper.ComboBoxActiveString(cbType);
                    int    typ       = cbType.Active;
                    // Save on UI
                    TreeIter insertIter;
                    insertIter = treeContent.AppendValues(tmpTime, text, typString);
                    GtkHelper.SortInByColumn(treeContent, (int)ProgrammColumnID.Uhrzeit, insertIter);
                    finalTime = API_Contract.ClearTimeConflicts(treeContent, insertIter);
                    // Save on Database
                    var insert = new Table_Termin(CurrTabIndex, finalTime, text, typ);
                    dbAdapter.InsertEntry(insert);
                }
            }
            // Free Memory
            diag.Destroy();
            foreach (var arg in args)             // Free args
            {
                arg.Dispose();
            }
        }
Exemplo n.º 2
0
        protected override bool HookOnSave()
        {
            // Assert data integrity
            if (!timeBox.ValidateTime())
            {
                return(false);
            }

            // Mutable values
            string validTime;
            string textString = CurrText;
            string origTime   = timeBox.OrigTime;
            string typString  = GtkHelper.ComboBoxActiveString(cbTyp);
            int    typ        = cbTyp.Active;

            // Save on Database
            DatabaseTable orig, newElem;

            if (IsCurrParent)
            {
                validTime = timeBox.Time;
                orig      = new Table_Termin(day, origTime, OrigText, origTyp);
                newElem   = new Table_Termin(day, validTime, textString, typ);
            }
            else
            {
                validTime  = origTime;                // Parent time, we got on EditTreeRow()
                textString = API_Contract.ConvertEditViewToDatabase(textString);
                orig       = new Table_Beschreibung(day, origTime, OrigText, origTyp);
                newElem    = new Table_Beschreibung(day, validTime, textString, typ);
            }
            orig.Update(newElem);

            // Save on UI
            if (IsCurrParent)             // Only Parent time can change
            {
                currTreeStore.SetValue(currTreeIter, (int)ProgrammColumnID.Uhrzeit, validTime);
            }
            currTreeStore.SetValue(currTreeIter, (int)ProgrammColumnID.Typ, typString);

            // Set UI text value and sort in
            if (IsCurrParent)
            {
                // Sort by time, and clear conflicts
                currTreeStore.SetValue(currTreeIter, (int)ProgrammColumnID.Text, textString);
                var iter = GtkHelper.SortInByColumn(currTreeStore,
                                                    (int)ProgrammColumnID.Uhrzeit, currTreeIter);
                validTime = API_Contract.ClearTimeConflicts(currTreeStore, iter);
            }
            else
            {
                // Sort by text
                currTreeStore.SetValue(currTreeIter, (int)ProgrammColumnID.Text,
                                       API_Contract.ConvertDatabaseToTreeChild(textString));
                GtkHelper.SortInByColumn(currTreeStore,
                                         (int)ProgrammColumnID.Text, currTreeIter);
            }

            // Save on this
            timeBox.Time = validTime;
            origTyp      = cbTyp.Active;
            return(true);
        }