Migration file widgets made by WPF

Source: Internet
Author: User

The client needs to upload the PDF file to the server. Then there are a lot of PDF files that need to be picked out by many PDF files. So I made a little tool.

The function is simple, select the source folder, select the Excel file that records the files you want to extract. OK, the interface is as follows.

The XAML code is as follows

<window x:class= "File Migration Tool. MainWindow "xmlns=" http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns:x=" Http://schemas.micros Oft.com/winfx/2006/xaml "xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "xmlns:mc=" Http://schem        as.openxmlformats.org/markup-compatibility/2006 "xmlns:local=" Clr-namespace: File Migration Tool "mc:ignorable=" D " Title= "MainWindow" height= "670.266" width= "911.817" > <grid margin= "0,0,-8,1" > &LT;GRID.ROWDEFINITIONS&G            T        <rowdefinition height= "400*"/> <rowdefinition height= "239*"/> </Grid.RowDefinitions> <label x:name= "Label" content= "Please select folder:" Horizontalalignment= "left" margin= "78,53,0,0" verticalalignment= "Top" Fon Tsize= "21.333"/> <textbox x:name= "TextBox" horizontalalignment= "left" height= "All" margin= "253,63,0,0" Textwra pping= "Wrap" verticalalignment= "Top" width= "491"/> <button x:name= "button" content= "read" HorIzontalalignment= "left" margin= "758,63,0,0" verticalalignment= "Top" width= "All" height= "" click= "Button_Click"/ > <datagrid autogeneratecolumns= "False" name= "DataGrid1" verticalalignment= "Top" Canuserso Rtcolumns= "false" margin= "78,194,75,0" isreadonly= "True" canuserresizecolumns= "false" canuserresizerows = "false" Selectionmode= "single" canuserreordercolumns= "false" alternationcount= "2" height= "371" Rowhead Erwidth= "0" canuseraddrows= "False" grid.rowspan= "2" > <DataGrid.Columns> <datagridte   Xtcolumn header= "serial number" width= "binding=" {Binding id} "/> <datagridtextcolumn header=" folder all Files " Width= "540" binding= "{Binding Name}"/> </DataGrid.Columns> </DataGrid> <label X:name= "label_copy" content= "Please select excle:" horizontalalignment= "left" margin= "78,103,0,0" verticalalignment= "Top" Fontsize= "21.333"/> <textbox x:nAme= "Textbox_copy" horizontalalignment= "left" height= "" margin= "253,116,0,0" textwrapping= "Wrap" Verticalalignment= "Top" width= "491"/> <button x:name= "button_copy" content= "read" horizontalalignment= "left" M Argin= "758,116,0,0" verticalalignment= "Top" width= "" height= "" "click=" button2_click "/> <button x:Name=" bu Tton1 "content=" starts extracting "horizontalalignment=" left "margin=" 253,152,0,0 "verticalalignment=" Top "width=" 490 "height=" 27 "click=" Button1_Click "/> <label x:name=" lblmsg "content=" "horizontalalignment=" left "margin=" 413,191,0,0 "G Rid. row= "1" verticalalignment= "Top"/> <button x:name= "Button2" content= "Show Only failed Files" horizontalalignment= "left" Margi N= "741,191,0,0" grid.row= "1" verticalalignment= "Top" width= "", "height=" click= button2_click_1 "/>" </Grid ></Window>

Background CS is as follows:

usingSystem;usingSystem.Collections.Generic;usingSystem.Data;usingSystem.IO;usingSystem.Linq;usingSystem.Text;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usingSystem.Windows.Input;usingSystem.Windows.Media;usingSystem.Windows.Media.Imaging;usingSystem.Windows.Navigation;usingSystem.Windows.Shapes;namespaceFile Migration Tool {classFileName { Public intID {Get;Set; }  Public stringName {Get;Set; } }    /// <summary>    ///the interactive logic of MainWindow.xaml/// </summary>     Public Partial classMainwindow:window {intID =-1; List<FileName> lost =NewList<filename> ();//Failed Collection         PublicMainWindow () {InitializeComponent (); } List<FileName> list =NewList<filename>(); Private voidButton_Click (Objectsender, RoutedEventArgs e) {System.Windows.Forms.FolderBrowserDialog FD=NewSystem.Windows.Forms.FolderBrowserDialog (); Fd. Shownewfolderbutton=false; System.Windows.Interop.HwndSource Source= Presentationsource.fromvisual ( This) asSystem.Windows.Interop.HwndSource; System.Windows.Forms.IWin32Window win=NewOldwindow (source.            Handle); System.Windows.Forms.DialogResult result=FD.            ShowDialog (Win); if(result.) Equals (System.Windows.Forms.DialogResult.OK)) {TextBox.Text=FD.                 SelectedPath;                          GetAllDirectories (TextBox.Text); }        }           PrivateList<filename> GetAllDirectories (stringRootPath) {                   string[] subpaths = System.IO.Directory.GetDirectories (RootPath);//Get all subdirectories            foreach(stringPathinchsubpaths) {getalldirectories (path);//do the same thing to the root directory for each word directory: The subdirectory is found and the file name of the current directory is stored in the list            }            string[] files =System.IO.Directory.GetFiles (RootPath); foreach(stringFileinchfiles) {ID++; FileName Model=NewFileName (); Model. Name=file.                ToUpper (); Model.id=ID; List. ADD (model);//Save all file names in the current directory to the file list            }            returnlist; }        Private voidButton2_Click (Objectsender, RoutedEventArgs e) {Microsoft.Win32.OpenFileDialog Dialog=NewMicrosoft.Win32.OpenFileDialog (); Dialog. Filter="Excel File (*.xlsx) |*.xls"; if(dialog. ShowDialog () = =true) {Textbox_copy.text=dialog.            FileName; }        }        /// <summary>        ///Start Extraction/// </summary>        /// <param name= "Sender" ></param>        /// <param name= "E" ></param>        Private voidButton1_Click (Objectsender, RoutedEventArgs e) {Exclecore Core=NewExclecore (TextBox_Copy.Text.Trim ()); Lblmsg. Content="start reading data from Excel"; DataTable DT= Core. GetTable (0,false); if(dt! =NULL) {List<FileName> Excel =NewList<filename>(); inti =0; foreach(DataRow Drinchdt. Rows) {FileName model=NewFileName (); Model.id= ++i; Model. Name= dr[0]. ToString ().                    ToUpper (); Excel.                ADD (model); } dataGrid1.ItemsSource=Excel; if(!Window.getwindow (DATAGRID1). IsVisible) {Window.getwindow (DATAGRID1).                Show ();                } datagrid1.updatelayout (); Lblmsg. Content="start reading Excel successfully, start migrating files to resource folder"; stringPath = AppDomain.CurrentDomain.BaseDirectory +"\\RESOURCE\\"; foreach(FileName minchExcel) {                    varquery = fromSinchListwheres.name.contains (m.name)Selects; if(Query. ToList (). Count >0)                    {                        stringOldPath = query. ToList () [0].                        Name; stringNewPath = Path +M.name; File.Copy (OldPath, NewPath,true); DataGridRow Row= (DataGridRow) This. DataGrid1.ItemContainerGenerator.ContainerFromIndex (M.id-1); Row. Background=NewSolidColorBrush (Colors.blue); Lblmsg. Content="file ""+ M.name +""Mobile Success"; }                    Else{datagridrow row= (DataGridRow) This. DataGrid1.ItemContainerGenerator.ContainerFromIndex (M.id-1); Row. Background=NewSolidColorBrush (colors.red); Lost.                    ADD (m); }} lblmsg. Content="task execution completed, the successful background color is blue, the background color of the failure is red. "; }        }        Private voidButton2_click_1 (Objectsender, RoutedEventArgs e) {dataGrid1.ItemsSource=lost; if(!Window.getwindow (DATAGRID1). IsVisible) {Window.getwindow (DATAGRID1).            Show ();            } datagrid1.updatelayout ();  for(inti =0; I < This. DataGrid1.Items.Count; i++) {DataGridRow row= (DataGridRow) This. DataGrid1.ItemContainerGenerator.ContainerFromIndex (i); Row. Background=NewSolidColorBrush (colors.red); }                   }    }}

The bindings for WPF and Winfrom are somewhat different.

But in general Tiger can also be made out.

Migration file widgets made by WPF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.