Exemplo n.º 1
0
        public override void AddChildEntry()
        {
            var parIter = editFrameAdapter.ActiveParentTreeIter;

            if (parIter.Equals(TreeIter.Zero))
            {
                return;
            }

            // Get User data
            EventTimeBox timeBox = new EventTimeBox(false);

            GetUserArgs[] args = { };
            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 time        = timeBox.Time;
                    int    vId         = int.Parse((string)treeContent.GetValue(parIter, (int)EventColumnId.ID));
                    int    iId         = treeContent.IterNChildren(parIter) + 1;
                    if (iId != 1)                     // XXX: Start counting with 1 here (beta)
                    {
                        iId++;
                    }
                    // Save on UI
                    treeContent.AppendValues(parIter, iId, "", "", "", time);
                    // Save on Database
                    var elem = new Table_Instanz(vId, iId, time);
                    dbAdapter.InsertEntry(elem);
                }
            }

            diag.Destroy();
            foreach (var arg in args)
            {
                arg.Dispose();
            }
        }
Exemplo n.º 2
0
        protected override bool HookOnSave()
        {
            // Assert data integrity
            if (!timeBox.ValidateTime())
            {
                return(false);
            }

            // Mutable values
            string validTime = timeBox.Time;
            string currText  = CurrText;
            int    vId       = int.Parse((string)currTreeStore.GetValue(currParentIter, (int)EventColumnId.ID));

            // Save on Database
            DatabaseTable orig, elem;

            if (IsCurrParent)
            {
                orig = new Table_Veranstaltung(vId, availKrzl[origKrzlIndex], OrigText,
                                               availLang[origLangIndex], int.Parse(timeBox.OrigTime));
                elem = new Table_Veranstaltung(vId, availKrzl[cbKrzl.Active],
                                               currText, availLang[cbLang.Active], int.Parse(validTime));
            }
            else
            {
                int iId = int.Parse((string)currTreeStore.GetValue(currTreeIter, (int)EventColumnId.ID));
                orig = new Table_Instanz(vId, iId, timeBox.OrigTime);
                elem = new Table_Instanz(vId, iId, validTime);
            }
            orig.Update(elem);

            // Save on UI
            if (IsCurrParent)
            {
                currTreeStore.SetValue(currTreeIter, (int)EventColumnId.Name, currText);
            }
            currTreeStore.SetValue(currTreeIter, (int)EventColumnId.Zeit, validTime);

            // Save on this
            timeBox.Time  = validTime;
            origKrzlIndex = cbKrzl.Active;
            origLangIndex = cbLang.Active;
            return(true);
        }
Exemplo n.º 3
0
        public override void AddParentEntry()
        {
            var parIter     = editFrameAdapter.ActiveParentTreeIter;
            var treeContent = CurrTreeStore;

            EventTimeBox timeBox   = new EventTimeBox(true);
            ComboBox     cbKrz     = new ComboBox(API_Contract.SupportedKrzl);
            Entry        krzlEntry = new Entry();

            krzlEntry.Changed += delegate
            {
                krzlEntry.Text = krzlEntry.Text.Trim();
                if (krzlEntry.Text.Length != 0)                   // New Krzl
                {
                    cbKrz.Active    = -1;
                    cbKrz.Sensitive = false;
                }
                else                     // Existing KRZL
                {
                    cbKrz.Sensitive = true;
                }
            };
            ComboBox cbLang    = new ComboBox(API_Contract.SupportedLanguages);
            Entry    textEntry = new Entry();

            GetUserArgs[] args =
            {
                new GetUserArgs(new Label("Sprache"),      cbLang),
                new GetUserArgs(new Label("Kürzel"),       cbKrz),
                new GetUserArgs(new Label("Neues Kürzel"), krzlEntry),
                new GetUserArgs(new Label("Name"),         textEntry),
            };

            var diag = new GetUserDataDialog(args, timeBox, "Speichern", 0, "Abbruch", 1);

            if (diag.Run() == 0)
            {
                bool validated;                 // While the Input is invalid
                while (!(validated = timeBox.ValidateTime() && ValidateKrzl(args[3])))
                {
                    if (diag.Run() == 1)                       // User cancels
                    {
                        validated = false;
                        break;
                    }
                }

                if (validated)                   // There is valid user data
                {
                    string text = textEntry.Text;
                    string time = timeBox.Time;
                    string lang = API_Contract.SupportedLanguages[cbLang.Active];
                    string krzl;
                    int    id = treeContent.IterNChildren(parIter) + 1;
                    if (id != 1)                     // XXX: Start counting with 1 here (beta)
                    {
                        id++;
                    }
                    if (cbKrz.Active > 0)                       // No new Krzl
                    {
                        krzl = API_Contract.SupportedLanguages[cbKrz.Active];
                    }
                    else
                    {
                        krzl = krzlEntry.Text;
                    }
                    // Save on UI
                    treeContent.AppendValues(parIter, id, text, krzl, lang, time);
                    // Save on Database
                    var elem = new Table_Veranstaltung(id, text, krzl, lang, int.Parse(time));
                    dbAdapter.InsertEntry(elem);
                }
            }
            // Free memory
            diag.Destroy();
            foreach (var arg in args)
            {
                arg.Dispose();
            }
        }