Exemple #1
0
        private void EventButtonSearchFolder(object sender, EventArgs e)
        {
            string NameFolder = TxFolderSearch.Text;

            if (SearchResult?.Length > 0)
            {
                ClearArraySearchResult();
            }

            Point offset = new Point(PvFolders.Width, -1 * PvFolders.Height);

            if (NameFolder.Length < 1)
            {
                Ms.ShortMessage(MsgType.Fail, "No characters to search", 250, PvFolders).Offset(offset).NoTable().Create(); return;
            }

            if (Program.ApplicationSettings.FolderNameSearchMode == TextSearchMode.StartWith)
            {
                SearchResult = TvFolders.FindNodes(x => x.Name.StartsWith(NameFolder));
            }

            if (Program.ApplicationSettings.FolderNameSearchMode == TextSearchMode.Contains)
            {
                SearchResult = TvFolders.FindNodes(x => x.Name.Contains(NameFolder));
            }

            if (Program.ApplicationSettings.FolderNameSearchMode == TextSearchMode.WholeWord)
            {
                SearchResult = TvFolders.FindNodes(x => x.Name == NameFolder);
            }

            SearchIterator = 0;
            if (SearchResult.Length > 0)
            {
                SelectOneNode(SearchResult[0]);
            }

            BxFolderSearchGotoNext.Visibility = ElementVisibility.Collapsed;

            if (SearchResult.Length < 1)
            {
                Ms.ShortMessage(MsgType.Fail, "The search has not given any results", 300, PvFolders).Offset(offset).NoTable().Create();
            }

            if (SearchResult.Length == 1)
            {
                Ms.ShortMessage(MsgType.Debug, "One folder has been found", 220, PvFolders).Offset(offset).NoTable().Create();
            }

            if (SearchResult.Length > 1)
            {
                Ms.ShortMessage(MsgType.Info, $"Number of folders found: {SearchResult.Length}", 220, PvFolders).Offset(offset).NoTable().Create();
                SearchIterator = 1;
                BxFolderSearchGotoNext.Visibility = ElementVisibility.Visible;
            }
        }
Exemple #2
0
        private void EventButtonAddFolder(object sender, EventArgs e)
        {
            const string ErrorHeader = "Error trying to add a new folder";
            RadTreeNode  parent      = TvFolders.SelectedNode;
            ReturnCode   code        = ReturnCodeFactory.Error(ErrorHeader);

            if (parent == null)
            {
                Ms.ShortMessage(MsgType.Fail, "The folder where the new one is added is not specified", 400, TxFolderAdd).Create();
                return;
            }

            int    IdFolder       = DbSettings.GetIdFolder(parent);
            string ParentFullPath = parent.FullPath;
            bool   Error          = false;

            if (IdFolder < 0)
            {
                Ms.ShortMessage(MsgType.Fail, "The folder where the new one is added is not specified", 400, TxFolderAdd).Create();
                return;
            }

            if (parent.Level > 14)
            {
                Ms.ShortMessage(MsgType.Fail, "Hierarchical nesting too deep", 280, TxFolderAdd).Create();
                return;
            }

            string NameFolderDraft = TxFolderAdd.Text.Trim();
            string NameFolder      = NameFolderDraft.RemoveSpecialCharacters();

            TxFolderAdd.Text = NameFolder;

            if (NameFolder.Length < 1)
            {
                if (NameFolderDraft.Length < 1)
                {
                    Ms.ShortMessage(MsgType.Fail, "New folder name not specified", 230, TxFolderAdd).Offset(-100 + TxFolderAdd.Size.Width, -70).Create();
                    return;
                }
                else
                {
                    Ms.ShortMessage(MsgType.Fail, "You have specified characters that cannot be used in the folder name", 470, TxFolderAdd).Create();
                    return;
                }
            }

            int IdNewFolder = -1;

            try
            {
                code = DbSettings.FolderInsert(IdFolder, NameFolder);
            }
            catch (Exception ex)
            {
                Error = true;
                Ms.Error(ErrorHeader, ex).Control(TxFolderAdd).Create();
                IdNewFolder = -1;
            }

            IdNewFolder = code.IdObject;

            if (code.Error)
            {
                if (Error == false)
                {
                    Ms.Message(ErrorHeader, code.StringValue, TxFolderAdd).Fail();
                }
            }

            if (IdNewFolder <= 0)
            {
                if ((Error == false) && (code.Success))
                {
                    Ms.Message(ErrorHeader, code.StringValue, TxFolderAdd).Fail();
                }
            }
            else // Give out SUCCESS MESSAGE //
            {
                if (NameFolderDraft.Length == NameFolder.Length)
                {
                    Ms.ShortMessage(MsgType.Debug, code.StringValue, GetMessageBoxWidth(code.StringValue), TxFolderAdd)
                    .Offset(TxFolderAdd.Width, -5 * TxFolderAdd.Height).Create();
                }
                else
                {
                    Ms.Message("Some characters you specify\nhave been excluded from the name", code.StringValue)
                    .Control(TxFolderAdd).Offset(200, 0).Delay(7).Info();
                    Ms.Message("The folder name contained forbidden characters:", NameFolderDraft).NoAlert().Warning();
                    Ms.Message("The name has been corrected:", NameFolder).NoAlert().Warning();
                }

                EventRefreshDataFromDatabaseFile();

                parent = TvFolders.GetNodeByPath(ParentFullPath);
                if (parent == null)
                {
                    Ms.Message(MsgType.Error, "Error!", $"Method TvFolders.GetNodeByPath(ParentFullPath) has returned [null]. ParentFullPath={ParentFullPath}", null, MsgPos.Unknown, 0).NoAlert().Create();
                    Ms.ShortMessage(MsgType.Warning, $"Error! Details in the message log", 300, TxFolderAdd).NoTable().Create();
                }
                else
                {
                    TvManager.TryToSelectFolderAfterCreating(parent, NameFolder);
                }
            }
            TxFolderAdd.Clear();
        }