Ejemplo n.º 1
0
 private void prepareHotkeysTable(SQLiteDataObject oData)
 {
     var d = new WndNote();
     try
     {
         var id = PNData.HK_START;
         var o = oData.GetScalar("SELECT MAX(ID) FROM HOT_KEYS");
         if (o != null && !DBNull.Value.Equals(o))
         {
             id = (int)(long)o + 1;
         }
         startPreparingMenuHotkeys(HotkeyType.Main, oData, ctmPN, ref id);
         startPreparingMenuHotkeys(HotkeyType.Note, oData, d.NoteMenu, ref id);
         startPreparingMenuHotkeys(HotkeyType.Edit, oData, d.EditMenu, ref id);
         startPreparingGroupsHotkeys(HotkeyType.Group, oData, ref id);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
     finally
     {
         d.Close();
     }
 }
Ejemplo n.º 2
0
        private void createMenusOrder(SQLiteDataObject oData, bool firstTime)
        {
            var dn = new WndNote();
            var dcp = new WndCP(false);
            try
            {
                var ctmNote = dn.NoteMenu;
                var ctmEdit = dn.EditMenu;
                var ctmList = dcp.CPMenu;

                if (firstTime)
                {
                    PNStatic.SpTextProvider.SplashText = PNLang.Instance.GetMessageText("load_menus", "Preparing menus order table");
                    foreach (var ti in ctmPN.Items.OfType<Control>())
                    {
                        addMenusOrder(oData, ctmPN.Name, ti, null, ctmPN.Items.IndexOf(ti));
                    }
                    foreach (var ti in ctmNote.Items.OfType<Control>())
                    {
                        addMenusOrder(oData, ctmNote.Name, ti, null, ctmNote.Items.IndexOf(ti));
                    }
                    foreach (var ti in ctmEdit.Items.OfType<Control>())
                    {
                        addMenusOrder(oData, ctmEdit.Name, ti, null, ctmEdit.Items.IndexOf(ti));
                    }
                    foreach (var ti in ctmList.Items.OfType<Control>())
                    {
                        addMenusOrder(oData, ctmList.Name, ti, null, ctmList.Items.IndexOf(ti));
                    }
                }
                else
                {
                    var updateList = new List<string>();
                    const string SQL = "SELECT MENU_NAME FROM MENUS_ORDER WHERE CONTEXT_NAME = '%CONTEXT_NAME%'";
                    using (var t = oData.FillDataTable(SQL.Replace("%CONTEXT_NAME%", ctmPN.Name)))
                    {
                        var names = t.AsEnumerable().Select(r => Convert.ToString(r["MENU_NAME"]));
                        foreach (var ti in ctmPN.Items.OfType<Control>())
                        {
                            newMenusOrder(oData, ctmPN.Name, ti, null, ctmPN.Items.IndexOf(ti), names, updateList);
                        }
                    }
                    using (var t = oData.FillDataTable(SQL.Replace("%CONTEXT_NAME%", ctmNote.Name)))
                    {
                        var names = t.AsEnumerable().Select(r => Convert.ToString(r["MENU_NAME"]));
                        foreach (var ti in ctmNote.Items.OfType<Control>())
                        {
                            newMenusOrder(oData, ctmNote.Name, ti, null, ctmNote.Items.IndexOf(ti), names, updateList);
                        }
                    }
                    using (var t = oData.FillDataTable(SQL.Replace("%CONTEXT_NAME%", ctmEdit.Name)))
                    {
                        var names = t.AsEnumerable().Select(r => Convert.ToString(r["MENU_NAME"]));
                        foreach (var ti in ctmEdit.Items.OfType<Control>())
                        {
                            newMenusOrder(oData, ctmEdit.Name, ti, null, ctmEdit.Items.IndexOf(ti), names, updateList);
                        }
                    }
                    using (var t = oData.FillDataTable(SQL.Replace("%CONTEXT_NAME%", ctmList.Name)))
                    {
                        var names = t.AsEnumerable().Select(r => Convert.ToString(r["MENU_NAME"]));
                        foreach (var ti in ctmList.Items.OfType<Control>())
                        {
                            newMenusOrder(oData, ctmList.Name, ti, null, ctmList.Items.IndexOf(ti), names, updateList);
                        }
                    }

                    updateList.RemoveAll(string.IsNullOrWhiteSpace);
                    if (updateList.Count > 0)
                    {
                        PNStatic.SpTextProvider.SplashText = PNLang.Instance.GetMessageText("update_menus_order",
                            "Updating menus indexes");
                        foreach (var s in updateList)
                        {
                            oData.Execute(s);
                        }
                    }
                }
                PNMenus.PrepareDefaultMenuStrip(ctmPN, MenuType.Main, false);
                PNMenus.PrepareDefaultMenuStrip(ctmNote, MenuType.Note, false);
                PNMenus.PrepareDefaultMenuStrip(ctmEdit, MenuType.Edit, false);
                PNMenus.PrepareDefaultMenuStrip(ctmList, MenuType.ControlPanel, false);
                PNMenus.PrepareDefaultMenuStrip(ctmPN, MenuType.Main, true);
                PNMenus.PrepareDefaultMenuStrip(ctmNote, MenuType.Note, true);
                PNMenus.PrepareDefaultMenuStrip(ctmEdit, MenuType.Edit, true);
                PNMenus.PrepareDefaultMenuStrip(ctmList, MenuType.ControlPanel, true);
                PNMenus.CheckAndApplyNewMenusOrder(ctmPN);
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
            finally
            {
                dn.Close();
                dcp.Close();
            }
        }
Ejemplo n.º 3
0
        private bool preSaveMenus(MenuType type, TreeView tvw)
        {
            try
            {
                foreach(var pti in tvw.Items.OfType<PNTreeItem>())
                {
                    fillNodesList(pti, _OrderLists[type].Item2, _HiddenLists[type].Item2);
                }
                if (_OrderLists[type].Item1.Where((t, i) => t != _OrderLists[type].Item2[i]).Any())
                {
                    foreach (var pti in tvw.Items.OfType<PNTreeItem>())
                    {
                        createOrderSql(pti);
                    }
                    switch (type)
                    {
                        case MenuType.Main:
                            _MenusOrderChanged.Main = true;
                            break;
                        case MenuType.Note:
                            {
                                var d = new WndNote();
                                try
                                {
                                    _MenusOrderChanged.Note = true;
                                    PNMenus.PrepareDefaultMenuStrip(d.NoteMenu, MenuType.Note, true);
                                }
                                finally
                                {
                                    d.Close();
                                }
                            }
                            break;
                        case MenuType.Edit:
                            {
                                var d = new WndNote();
                                try
                                {
                                    _MenusOrderChanged.Edit = true;
                                    PNMenus.PrepareDefaultMenuStrip(d.EditMenu, MenuType.Edit, true);
                                }
                                finally
                                {
                                    d.Close();
                                }
                            }
                            break;
                        case MenuType.ControlPanel:
                            {
                                var d = new WndCP();
                                try
                                {
                                    _MenusOrderChanged.ControlPanel = true;
                                    PNMenus.PrepareDefaultMenuStrip(d.CPMenu, MenuType.ControlPanel, true);
                                }
                                finally
                                {
                                    d.Close();
                                }
                            }
                            break;
                    }
                }

                _TempHiddenMenus.AddRange(
                    _HiddenLists[type].Item2.Select(s => new PNHiddenMenu(s, type)));

                return true;
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
                return false;
            }
        }