コード例 #1
0
        /// <summary>
        /// 每次可以创建一个名字不同的窗口
        /// </summary>
        /// <returns></returns>
        public FTPWindow CreateNewMainWindow()
        {
            string    temp       = "mianWindow" + MainWindow_Count.ToString();
            FTPWindow mainWindow = new FTPWindow();

            //MainWindow mainWindow = new MainWindow();
            mainWindow.Name = temp;
            MainWindow_Count++;
            return(mainWindow);
        }
コード例 #2
0
        /// <summary>
        /// listview使用鼠标左键双击事件,用来双击文件夹进入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FTPListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            //MessageBox.Show("haha");
            var items = this.FTPListView.SelectedItems;

            //MessageBox.Show(items.Count.ToString());
            //MessageBox.Show(items.GetType().ToString());
            FileInfo fileInfo_items = (FileInfo)items[0];
            string   b = System.IO.Path.GetExtension(fileInfo_items.FileName);


            if (System.IO.Path.GetExtension(fileInfo_items.FileName) == "")// 是文件夹的话
            {
                string[] newFileListArray;
                string   temp_1 = FTPLogin.ftp.showCurrentDir();
                //fileListArray = ftp.Dir();
                if (temp_1 == "/")
                {
                    FTPLogin.ftp.chDir(temp_1 + fileInfo_items.FileName);
                    newFileListArray = FTPLogin.ftp.Dir(temp_1 + fileInfo_items.FileName);
                }
                else
                {
                    FTPLogin.ftp.chDir(temp_1 + @"/" + fileInfo_items.FileName);
                    newFileListArray = FTPLogin.ftp.Dir(temp_1 + @"/" + fileInfo_items.FileName);
                }
                //string[] newFileListArray = FTPLogin.ftp.Dir(temp_1  + fileInfo_items.FileName);
                FTPWindow mainWindow = CreateNewMainWindow();
                //MainWindow mainWindow_3 = new MainWindow();
                //mainWindow_3.Name = "mainWindow_3";
                mainWindow.InitialFtpListViewData_2(newFileListArray);
                mainWindow.Show();


                int n = System.Windows.Application.Current.Windows.Count;
                for (int a = 0; a < n; a++)
                {
                    for (int i = 0; i < System.Windows.Application.Current.Windows.Count; i++)
                    {
                        string y = "mianWindow" + (MainWindow_Count - 1).ToString();
                        string x = System.Windows.Application.Current.Windows[i].Name;
                        //2018-9-19
                        string z = "MyWindow";
                        if ((x != y) && (x != z))
                        {
                            System.Windows.Application.Current.Windows[i].Hide();
                        }
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// 2018-9-12:主界面点击 刷新 按钮发生的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Refresh_Click(object sender, RoutedEventArgs e)
        {
            string[] FormerListArray;
            string   current_Path;

            //这里是为了解决用户在没有登录的情况下点击 返回上层目录 按钮出现的异常
            try
            {
                current_Path = FTPLogin.ftp.showCurrentDir();
            }
            catch (Exception)
            {
                System.Windows.MessageBox.Show("请先登录FTP服务器!");
                current_Path = null;
            }
            if (current_Path == null)
            {
                return;
            }


            FTPLogin.ftp.chDir(current_Path);
            FormerListArray = FTPLogin.ftp.Dir(current_Path);
            FTPWindow mainWindow = CreateNewMainWindow();

            //MainWindow mainWindow_3 = new MainWindow();
            //mainWindow_3.Name = "mainWindow_3";
            mainWindow.InitialFtpListViewData_2(FormerListArray);
            mainWindow.Show();


            int n = System.Windows.Application.Current.Windows.Count;

            for (int a = 0; a < n; a++)
            {
                for (int i = 0; i < System.Windows.Application.Current.Windows.Count; i++)
                {
                    string y = "mianWindow" + (MainWindow_Count - 1).ToString();
                    string x = System.Windows.Application.Current.Windows[i].Name;
                    //2018-9-19
                    string z = "MyWindow";
                    if ((x != y) && (x != z))
                    {
                        System.Windows.Application.Current.Windows[i].Hide();
                    }
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// 主界面点击 返回上层目录 按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormerDir_Click(object sender, RoutedEventArgs e)
        {
            string[] FormerListArray;
            string   current_Path;

            //这里是为了解决用户在没有登录的情况下点击 返回上层目录 按钮出现的异常
            try
            {
                current_Path = FTPLogin.ftp.showCurrentDir();
            }
            catch (Exception)
            {
                System.Windows.MessageBox.Show("请先登录FTP服务器!");
                current_Path = null;
            }
            if (current_Path == null)
            {
                return;
            }


            if (current_Path == @"/")
            {
                System.Windows.MessageBox.Show("已经到达FTP服务器的根目录!");
            }
            else
            {
                int index1 = current_Path.LastIndexOf(@"/");

                // 如果查找最后出现 / 的位置是0,说明是在根目录下一层级,那么直接返回根目录即可    如: /xxxx
                if (index1 == 0)
                {
                    FTPLogin.ftp.chDir(@"/");
                    FormerListArray = FTPLogin.ftp.Dir(@"/");
                    FTPWindow mainWindow = CreateNewMainWindow();
                    //MainWindow mainWindow_3 = new MainWindow();
                    //mainWindow_3.Name = "mainWindow_3";
                    mainWindow.InitialFtpListViewData_2(FormerListArray);
                    mainWindow.Show();


                    int n = System.Windows.Application.Current.Windows.Count;
                    for (int a = 0; a < n; a++)
                    {
                        for (int i = 0; i < System.Windows.Application.Current.Windows.Count; i++)
                        {
                            string y = "mianWindow" + (MainWindow_Count - 1).ToString();
                            string x = System.Windows.Application.Current.Windows[i].Name;
                            //2018-9-19
                            string z = "MyWindow";
                            if ((x != y) && (x != z))
                            {
                                System.Windows.Application.Current.Windows[i].Hide();
                            }
                        }
                    }
                }
                // 这里就是至少从根目录进去两个层级或以上的情况   如: /xxxx/XXXXX
                else
                {
                    string formerPath = current_Path.Substring(0, index1); // 取出上一层级的目录
                    FTPLogin.ftp.chDir(formerPath);
                    FormerListArray = FTPLogin.ftp.Dir(formerPath);
                    FTPWindow mainWindow = CreateNewMainWindow();
                    //MainWindow mainWindow_3 = new MainWindow();
                    //mainWindow_3.Name = "mainWindow_3";
                    mainWindow.InitialFtpListViewData_2(FormerListArray);
                    mainWindow.Show();


                    int n = System.Windows.Application.Current.Windows.Count;
                    for (int a = 0; a < n; a++)
                    {
                        for (int i = 0; i < System.Windows.Application.Current.Windows.Count; i++)
                        {
                            string y = "mianWindow" + (MainWindow_Count - 1).ToString();
                            string x = System.Windows.Application.Current.Windows[i].Name;
                            //2018-9-19
                            string z = "MyWindow";
                            if ((x != y) && (x != z))
                            {
                                System.Windows.Application.Current.Windows[i].Hide();
                            }
                        }
                    }
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// 在listview右键中出现的 删除 选项点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteItem_Click(object sender, RoutedEventArgs e)
        {
            var      items          = this.FTPListView.SelectedItems;
            FileInfo fileInfo_items = (FileInfo)items[0];
            string   b = System.IO.Path.GetExtension(fileInfo_items.FileName);

            if (b == "")
            {
                //MessageBox.Show("不允许删除文件夹!");
                try
                {
                    FTPLogin.ftp.RmDir(fileInfo_items.FileName);
                }
                catch (Exception)
                {
                    System.Windows.MessageBox.Show("文件夹里面还有文件哦~");
                }

                string temp_1 = FTPLogin.ftp.showCurrentDir();
                FTPLogin.ftp.chDir(temp_1);
                string[]  newCurrentListArray = FTPLogin.ftp.Dir(temp_1);
                FTPWindow mainWindow          = CreateNewMainWindow();
                mainWindow.InitialFtpListViewData_2(newCurrentListArray);
                mainWindow.Show();
                int n = System.Windows.Application.Current.Windows.Count;
                for (int a = 0; a < n; a++)
                {
                    for (int i = 0; i < System.Windows.Application.Current.Windows.Count; i++)
                    {
                        string y = "mianWindow" + (MainWindow_Count - 1).ToString();
                        string x = System.Windows.Application.Current.Windows[i].Name;
                        //2018-9-19
                        string z = "MyWindow";
                        if ((x != y) && (x != z))
                        {
                            System.Windows.Application.Current.Windows[i].Hide();
                        }
                    }
                }
            }
            else
            {
                FTPLogin.ftp.Delete(fileInfo_items.FileName);
                System.Windows.MessageBox.Show(fileInfo_items.FileName + " 删除成功!");
                // 删除完后刷新整个FTP listview列表
                string temp_1 = FTPLogin.ftp.showCurrentDir();
                FTPLogin.ftp.chDir(temp_1);
                string[]  newCurrentListArray = FTPLogin.ftp.Dir(temp_1);
                FTPWindow mainWindow          = CreateNewMainWindow();
                mainWindow.InitialFtpListViewData_2(newCurrentListArray);
                mainWindow.Show();
                int n = System.Windows.Application.Current.Windows.Count;
                for (int a = 0; a < n; a++)
                {
                    for (int i = 0; i < System.Windows.Application.Current.Windows.Count; i++)
                    {
                        string y = "mianWindow" + (MainWindow_Count - 1).ToString();
                        string x = System.Windows.Application.Current.Windows[i].Name;
                        //2018-9-19
                        string z = "MyWindow";
                        if ((x != y) && (x != z))
                        {
                            System.Windows.Application.Current.Windows[i].Hide();
                        }
                    }
                }
            }
        }