コード例 #1
0
        private void UniqueNameButton_Click(object sender, RoutedEventArgs e)
        {
            _isUniqueNameButtonClicked = true;
            var tabSelected = ((TabItem)this.TabControl.SelectedItem).Header.ToString();

            if (tabSelected == "Rename Files")
            {
                this.getEveryThingReady(true);

                for (int i = 0; i < this.fileData.Count; i++)
                {
                    var temp = filePreview[i];
                    FileOrFolderBus.Unique(ref temp);
                    filePreview[i] = temp;
                }
            }
            else
            {
                this.getEveryThingReady(false);

                for (int i = 0; i < this.folderData.Count; i++)
                {
                    var temp = folderPreview[i];
                    FileOrFolderBus.Unique(ref temp);
                    folderPreview[i] = temp;
                }
            }
        }
コード例 #2
0
        private void ReplaceButton_Click(object sender, RoutedEventArgs e)
        {
            _isReplaceButtonClicked = true;
            oldString = this.OldStringTextBox.Text;
            newString = this.NewStringTextBox.Text;
            var tabSelected = ((TabItem)this.TabControl.SelectedItem).Header.ToString();

            if (tabSelected == "Rename Files")
            {
                this.getEveryThingReady(true);

                for (int i = 0; i < this.fileData.Count; i++)
                {
                    var temp = filePreview[i];
                    FileOrFolderBus.Replace(ref temp, oldString, newString);
                    filePreview[i] = temp;
                }
            }
            else
            {
                this.getEveryThingReady(false);

                for (int i = 0; i < this.folderData.Count; i++)
                {
                    var temp = folderPreview[i];
                    FileOrFolderBus.Replace(ref temp, oldString, newString);
                    folderPreview[i] = temp;
                }
            }
        }
コード例 #3
0
        private void UpperFirstLetterCheckBox_Checked(object sender, RoutedEventArgs e)
        {
            var tabSelected = ((TabItem)(this.TabControl.SelectedItem)).Header.ToString();

            if (tabSelected == "Rename Files")
            {
                this.getEveryThingReady(true);

                for (int i = 0; i < this.fileData.Count; i++)
                {
                    var temp = filePreview[i];
                    FileOrFolderBus.UpperFirstLetter(ref temp);
                    filePreview[i] = temp;
                }
            }
            else
            {
                this.getEveryThingReady(false);
                for (int i = 0; i < this.folderData.Count; i++)
                {
                    var temp = folderPreview[i];
                    FileOrFolderBus.UpperFirstLetter(ref temp);
                    folderPreview[i] = temp;
                }
            }
        }
コード例 #4
0
        private void StartBatchButton_Click(object sender, RoutedEventArgs e)
        {
            //Nếu filePreview không có giá trị thì hiện thông báo bạn chưa đổi tên file hoặc folder
            if (filePreview == null && folderPreview == null)
            {
                MessageBox.Show("Not change name yet");
                return;
            }

            var tabSelected = ((TabItem)(this.TabControl.SelectedItem)).Header.ToString();

            bool mode = (tabSelected == "Rename Files") ? true : false;

            //Kiểm tra trùng tên
            bool check = false;

            if (mode == true)
            {
                for (int i = 0; i < filePreview.Count - 1; i++)
                {
                    for (int j = i + 1; j < filePreview.Count; j++)
                    {
                        if (FileOrFolderBus.checkAlikeFileOrFolder(filePreview[i], filePreview[j]) == 0)
                        {
                            check = true;
                            break;
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < folderPreview.Count - 1; i++)
                {
                    for (int j = i + 1; j < folderPreview.Count; j++)
                    {
                        if (FileOrFolderBus.checkAlikeFileOrFolder(folderPreview[i], folderPreview[j]) == 0)
                        {
                            check = true;
                            break;
                        }
                    }
                }
            }

            if (check == true)
            {
                MessageBoxResult result = MessageBox.Show("Having 2 Files Aliked.\nChoose: Yes (Add Suffix); No (Get Old Name)", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Question);
                switch (result)
                {
                case MessageBoxResult.Yes:
                    if (mode == true)
                    {
                        int suffix = 1;
                        for (int i = filePreview.Count - 1; i >= 1; i--)
                        {
                            for (int j = i - 1; j >= 0; j--)
                            {
                                if (FileOrFolderBus.checkAlikeFileOrFolder(filePreview[i], filePreview[j]) == 0)
                                {
                                    var temp = filePreview[j];
                                    FileOrFolderBus.addSuffix(ref temp, suffix);
                                    filePreview[j] = temp;
                                    suffix++;
                                }
                            }
                        }
                    }
                    else
                    {
                        int suffix = 1;
                        for (int i = folderPreview.Count - 1; i >= 1; i--)
                        {
                            for (int j = i - 1; j >= 0; j--)
                            {
                                if (FileOrFolderBus.checkAlikeFileOrFolder(folderPreview[i], folderPreview[j]) == 0)
                                {
                                    var temp = folderPreview[j];
                                    FileOrFolderBus.addSuffix(ref temp, suffix);
                                    folderPreview[j] = temp;
                                    suffix++;
                                }
                            }
                        }
                    }
                    break;

                case MessageBoxResult.No:
                    if (mode == true)
                    {
                        bool check1 = false;
                        for (int i = 0; i < filePreview.Count - 1; i++)
                        {
                            for (int j = i + 1; j < filePreview.Count; j++)
                            {
                                if (FileOrFolderBus.checkAlikeFileOrFolder(filePreview[i], filePreview[j]) == 0)
                                {
                                    check1         = true;
                                    filePreview[j] = fileData[j].Name;
                                }
                            }
                            if (check1 == true)
                            {
                                filePreview[i] = fileData[i].Name;
                                check1         = false;
                            }
                        }
                    }
                    else
                    {
                        bool check1 = false;
                        for (int i = 0; i < folderPreview.Count - 1; i++)
                        {
                            for (int j = i + 1; j < folderPreview.Count; j++)
                            {
                                if (FileOrFolderBus.checkAlikeFileOrFolder(folderPreview[i], folderPreview[j]) == 0)
                                {
                                    check1           = true;
                                    folderPreview[j] = folderData[j].Name;
                                }
                            }
                            if (check1 == true)
                            {
                                folderPreview[i] = folderData[i].Name;
                                check1           = false;
                            }
                        }
                    }
                    break;
                }
            }

            int numbersOfData = this.fileData != null ? this.fileData.Count : this.folderData.Count;

            for (int i = 0; i < numbersOfData; i++)
            {
                if (mode == true)
                {
                    var temp = fileData[i];
                    FileOrFolderBus.applyChange(ref temp, filePreview[i], mode);
                    fileData[i] = temp;
                }
                else
                {
                    var temp = folderData[i];
                    FileOrFolderBus.applyChange(ref temp, folderPreview[i], mode);
                    folderData[i] = temp;
                }
            }
            MessageBox.Show("Saved");
        }