@@ -9,21 +9,86 @@ namespace SQLBakVersion
99 public partial class Main : Form
1010 {
1111 private readonly SQLVersion sqlVersion = new SQLVersion ( ) ;
12+ private bool isDragging = false ;
13+ private Point lastLocation ;
14+
1215 public Main ( )
1316 {
1417 InitializeComponent ( ) ;
18+
19+ pnlDragDrop . Location = new Point ( 10 , 37 ) ;
20+ }
21+
22+ private void pnlTitleBar_MouseDown ( object sender , MouseEventArgs e )
23+ {
24+ if ( e . Button == MouseButtons . Left )
25+ {
26+ isDragging = true ;
27+ lastLocation = e . Location ;
28+ }
29+ }
30+
31+ private void pnlTitleBar_MouseMove ( object sender , MouseEventArgs e )
32+ {
33+ if ( isDragging )
34+ {
35+ this . Location = new Point ( ( this . Location . X - lastLocation . X ) + e . X , ( this . Location . Y - lastLocation . Y ) + e . Y ) ;
36+ this . Update ( ) ;
37+ }
38+ }
39+
40+ private void pnlTitleBar_MouseUp ( object sender , MouseEventArgs e )
41+ {
42+ isDragging = false ;
43+ }
44+
45+ private void btnClose_Click ( object sender , EventArgs e )
46+ {
47+ this . Close ( ) ;
48+ }
49+
50+ private void pnlDragDrop_Click ( object sender , EventArgs e )
51+ {
52+ SelectBakFile ( ) ;
53+ }
54+
55+ private void Main_DragEnter ( object sender , DragEventArgs e )
56+ {
57+ if ( e . Data . GetDataPresent ( DataFormats . FileDrop ) )
58+ {
59+ string [ ] files = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
60+ if ( files . Length > 0 && Path . GetExtension ( files [ 0 ] ) . ToLower ( ) == ".bak" )
61+ {
62+ e . Effect = DragDropEffects . Copy ;
63+ return ;
64+ }
65+ }
66+ e . Effect = DragDropEffects . None ;
1567 }
1668
17- private void btnBrowse_Click ( object sender , EventArgs e )
69+ private void Main_DragDrop ( object sender , DragEventArgs e )
70+ {
71+ string [ ] files = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
72+ if ( files . Length > 0 && Path . GetExtension ( files [ 0 ] ) . ToLower ( ) == ".bak" )
73+ {
74+ ProcessBakFile ( files [ 0 ] ) ;
75+ }
76+ }
77+
78+ private void SelectBakFile ( )
1879 {
1980 OpenFileDialog openFileDialog = new OpenFileDialog ( ) ;
2081 openFileDialog . Filter = "SQL Server backup files (*.bak)|*.bak" ;
2182 if ( openFileDialog . ShowDialog ( ) == DialogResult . OK )
2283 {
23- txtBakFilePath . Text = openFileDialog . FileName ;
84+ ProcessBakFile ( openFileDialog . FileName ) ;
2485 }
86+ }
87+
88+ private void ProcessBakFile ( string filePath )
89+ {
90+ lblDragDrop . Text = Path . GetFileName ( filePath ) ;
2591
26- string filePath = txtBakFilePath . Text ;
2792 string output = string . Empty ;
2893 if ( string . IsNullOrEmpty ( filePath ) || ! File . Exists ( filePath ) )
2994 output = "Please select a valid .bak file." ;
0 commit comments