1 | using System; |
---|
2 | using System.Windows.Forms; |
---|
3 | |
---|
4 | using Com.Piwigo.Lib.DTO; |
---|
5 | using System.Collections.Generic; |
---|
6 | using Com.Piwigo.Uploader.DTO; |
---|
7 | using Com.Piwigo.Uploader.Service; |
---|
8 | using Com.Piwigo.Uploader.Helper; |
---|
9 | |
---|
10 | using System.IO; |
---|
11 | |
---|
12 | namespace Com.Piwigo.Uploader |
---|
13 | { |
---|
14 | public partial class MainForm : Form |
---|
15 | { |
---|
16 | public MainForm() |
---|
17 | { |
---|
18 | InitializeComponent(); |
---|
19 | modelManagerBaseBindingSource.DataSource = ModelManager.Instance; |
---|
20 | |
---|
21 | txtOptionAuthor.DataBindings.Add("Text", ModelManager.Instance.UploadOption, "Author", false, DataSourceUpdateMode.OnPropertyChanged); |
---|
22 | cbOptionLevel.DataBindings.Add("SelectedValue", ModelManager.Instance.UploadOption, "ConfidentialLevel", false, DataSourceUpdateMode.OnPropertyChanged); |
---|
23 | |
---|
24 | txtAlbName.DataBindings.Add("Text", ModelManager.Instance.AlbumEdited, "Name", false, DataSourceUpdateMode.OnPropertyChanged); |
---|
25 | txtAlbComment.DataBindings.Add("Text", ModelManager.Instance.AlbumEdited, "MessageInfo", false, DataSourceUpdateMode.OnPropertyChanged); |
---|
26 | |
---|
27 | picshowImg.DataBindings.Add("ImageLocation", ModelManager.Instance.ImageEdited, "LocalFile", false, DataSourceUpdateMode.Never); |
---|
28 | txtImgName.DataBindings.Add("Text", ModelManager.Instance.ImageEdited, "Name", false, DataSourceUpdateMode.OnPropertyChanged); |
---|
29 | txtImgComment.DataBindings.Add("Text", ModelManager.Instance.ImageEdited, "AuthorComment", false, DataSourceUpdateMode.OnPropertyChanged); |
---|
30 | txtImgAuthor.DataBindings.Add("Text", ModelManager.Instance.ImageEdited, "Author", false, DataSourceUpdateMode.OnPropertyChanged); |
---|
31 | cbImgLevelEnum.DataBindings.Add("SelectedValue", ModelManager.Instance.ImageEdited, "ConfidentialLevel", false, DataSourceUpdateMode.OnPropertyChanged); |
---|
32 | } |
---|
33 | |
---|
34 | private void MainForm_Load(object sender, EventArgs e) |
---|
35 | { |
---|
36 | string[] args = Environment.GetCommandLineArgs(); |
---|
37 | |
---|
38 | foreach (string arg in args) |
---|
39 | { |
---|
40 | if (Directory.Exists(arg)) |
---|
41 | { |
---|
42 | try |
---|
43 | { |
---|
44 | ModelManager.Instance.directoryName = arg; |
---|
45 | ServiceFactory.GetByType<LoadFromDirectory>().runService(); |
---|
46 | } |
---|
47 | catch (ApplicationException aex) |
---|
48 | { |
---|
49 | MainAppHelper.showdErrorMessageBox(aex); |
---|
50 | } |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | MainAppHelper.BuildAlbumTree(AlbumsTV, ModelManager.Instance.lstAlbumLocaux); |
---|
55 | |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | private void Connect_Click(object sender, EventArgs e) |
---|
60 | { |
---|
61 | try |
---|
62 | { |
---|
63 | String strUri= tbServer.Text.Replace("\\","/"); |
---|
64 | if (!strUri.StartsWith("http")) |
---|
65 | { |
---|
66 | strUri = "http://" + strUri; |
---|
67 | } |
---|
68 | if (!strUri.EndsWith("/ws.php")) |
---|
69 | { |
---|
70 | if (!strUri.EndsWith("/")) |
---|
71 | { |
---|
72 | strUri += "/"; |
---|
73 | } |
---|
74 | strUri += "ws.php"; |
---|
75 | } |
---|
76 | |
---|
77 | Uri uriServeur; |
---|
78 | if (Uri.TryCreate(strUri, UriKind.Absolute,out uriServeur)) |
---|
79 | { |
---|
80 | ModelManager.Instance.serveurName = uriServeur; |
---|
81 | ModelManager.Instance.userName = tbUser.Text; |
---|
82 | ModelManager.Instance.password = tbPassword.Text; |
---|
83 | |
---|
84 | ServiceFactory.GetByType<Connect>().runService(); |
---|
85 | } |
---|
86 | |
---|
87 | } |
---|
88 | catch (ApplicationException aex) |
---|
89 | { |
---|
90 | MainAppHelper.showdErrorMessageBox(aex); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | private void Telecharger_Click(object sender, EventArgs e) |
---|
95 | { |
---|
96 | try |
---|
97 | { |
---|
98 | ServiceFactory.GetByType<UploadToPiwigo>().runService(); |
---|
99 | } |
---|
100 | catch (ApplicationException aex) |
---|
101 | { |
---|
102 | MainAppHelper.showdErrorMessageBox(aex); |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | private void MainForm_FormClosing(object sender, FormClosingEventArgs e) |
---|
107 | { |
---|
108 | try |
---|
109 | { |
---|
110 | if (ModelManager.Instance.isConnected) |
---|
111 | { |
---|
112 | ServiceFactory.GetByType<Disconnect>().runService(); |
---|
113 | } |
---|
114 | } |
---|
115 | catch (ApplicationException aex) |
---|
116 | { |
---|
117 | MainAppHelper.showdErrorMessageBox(aex); |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | |
---|
122 | private void AlbumsTV_AfterSelect(object sender, TreeViewEventArgs e) |
---|
123 | { |
---|
124 | |
---|
125 | ModelManager.Instance.SelectedNode = AlbumsTV.SelectedNode; |
---|
126 | if (e.Node.Tag is LocalAlbum) |
---|
127 | { |
---|
128 | LocalAlbum alb = (LocalAlbum)e.Node.Tag; |
---|
129 | ModelManager.Instance.AlbumEdited.Name = alb.Name; |
---|
130 | ModelManager.Instance.AlbumEdited.Id = alb.Id; |
---|
131 | ModelManager.Instance.AlbumEdited.LocalDir = alb.LocalDir; |
---|
132 | ModelManager.Instance.AlbumEdited.MessageInfo = alb.MessageInfo; |
---|
133 | |
---|
134 | ModelManager.Instance.ImageEdited.Name = String.Empty; |
---|
135 | ModelManager.Instance.ImageEdited.Id = null; |
---|
136 | ModelManager.Instance.ImageEdited.Author = String.Empty; |
---|
137 | ModelManager.Instance.ImageEdited.AuthorComment = String.Empty; |
---|
138 | ModelManager.Instance.ImageEdited.ConfidentialLevel = 0; |
---|
139 | ModelManager.Instance.ImageEdited.LocalFile = String.Empty; ; |
---|
140 | ModelManager.Instance.ImageEdited.LstTags = null; |
---|
141 | ModelManager.Instance.ImageEdited.UpperCatId = 0; |
---|
142 | |
---|
143 | tabControl1.SelectedTab = tabPageAlbum; |
---|
144 | tabControl1.Enabled = true; |
---|
145 | } |
---|
146 | else if (e.Node.Tag is LocalImage) |
---|
147 | { |
---|
148 | LocalImage img = (LocalImage)e.Node.Tag; |
---|
149 | ModelManager.Instance.ImageEdited.Name = img.Name; |
---|
150 | ModelManager.Instance.ImageEdited.Id = img.Id; |
---|
151 | ModelManager.Instance.ImageEdited.Author = img.Author; |
---|
152 | ModelManager.Instance.ImageEdited.AuthorComment = img.AuthorComment; |
---|
153 | ModelManager.Instance.ImageEdited.ConfidentialLevel = img.ConfidentialLevel; |
---|
154 | ModelManager.Instance.ImageEdited.LocalFile = img.LocalFile; |
---|
155 | ModelManager.Instance.ImageEdited.LstTags = img.LstTags; |
---|
156 | ModelManager.Instance.ImageEdited.UpperCatId = img.UpperCatId; |
---|
157 | |
---|
158 | if ((e.Node.Parent != null) |
---|
159 | && (e.Node.Parent.Tag is LocalAlbum)) |
---|
160 | { |
---|
161 | LocalAlbum alb = (LocalAlbum)e.Node.Parent.Tag; |
---|
162 | if (ModelManager.Instance.AlbumEdited.LocalDir != alb.LocalDir) |
---|
163 | { |
---|
164 | ModelManager.Instance.AlbumEdited.Name = alb.Name; |
---|
165 | ModelManager.Instance.AlbumEdited.Id = alb.Id; |
---|
166 | ModelManager.Instance.AlbumEdited.LocalDir = alb.LocalDir; |
---|
167 | ModelManager.Instance.AlbumEdited.MessageInfo = alb.MessageInfo; |
---|
168 | } |
---|
169 | } |
---|
170 | |
---|
171 | tabControl1.SelectedTab = tabPageImg; |
---|
172 | tabControl1.Enabled = true; |
---|
173 | } |
---|
174 | else |
---|
175 | { |
---|
176 | tabControl1.Enabled = false; |
---|
177 | } |
---|
178 | |
---|
179 | System.Diagnostics.Debug.Print(label5.Visible.ToString()); |
---|
180 | } |
---|
181 | |
---|
182 | private void btnAlbumEditCancel_Click(object sender, EventArgs e) |
---|
183 | { |
---|
184 | if (AlbumsTV.SelectedNode.Tag is LocalImage) |
---|
185 | { |
---|
186 | LocalImage img = (LocalImage)AlbumsTV.SelectedNode.Tag; |
---|
187 | if (ModelManager.Instance.ImageEdited.LocalFile == img.LocalFile) |
---|
188 | { |
---|
189 | ModelManager.Instance.ImageEdited.Name = img.Name; |
---|
190 | ModelManager.Instance.ImageEdited.Id = img.Id; |
---|
191 | ModelManager.Instance.ImageEdited.Author = img.Author; |
---|
192 | ModelManager.Instance.ImageEdited.AuthorComment = img.AuthorComment; |
---|
193 | ModelManager.Instance.ImageEdited.ConfidentialLevel = img.ConfidentialLevel; |
---|
194 | ModelManager.Instance.ImageEdited.LocalFile = img.LocalFile; |
---|
195 | ModelManager.Instance.ImageEdited.LstTags = img.LstTags; |
---|
196 | ModelManager.Instance.ImageEdited.UpperCatId = img.UpperCatId; |
---|
197 | } |
---|
198 | } |
---|
199 | else |
---|
200 | { |
---|
201 | tabControl1.Enabled = false; |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | private void btnImgEditCancel_Click(object sender, EventArgs e) |
---|
206 | { |
---|
207 | if (AlbumsTV.SelectedNode.Tag is LocalImage) |
---|
208 | { |
---|
209 | LocalImage img = (LocalImage)AlbumsTV.SelectedNode.Tag; |
---|
210 | if (ModelManager.Instance.ImageEdited.LocalFile == img.LocalFile) |
---|
211 | { |
---|
212 | img.Name = ModelManager.Instance.ImageEdited.Name ; |
---|
213 | img.Id = ModelManager.Instance.ImageEdited.Id ; |
---|
214 | img.Author = ModelManager.Instance.ImageEdited.Author ; |
---|
215 | img.AuthorComment = ModelManager.Instance.ImageEdited.AuthorComment ; |
---|
216 | img.ConfidentialLevel = ModelManager.Instance.ImageEdited.ConfidentialLevel ; |
---|
217 | img.LocalFile = ModelManager.Instance.ImageEdited.LocalFile ; |
---|
218 | img.LstTags = ModelManager.Instance.ImageEdited.LstTags ; |
---|
219 | img.UpperCatId = ModelManager.Instance.ImageEdited.UpperCatId ; |
---|
220 | } |
---|
221 | } |
---|
222 | else |
---|
223 | { |
---|
224 | tabControl1.Enabled = false; |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | private void btnImgEditOk_Click(object sender, EventArgs e) |
---|
229 | { |
---|
230 | if (AlbumsTV.SelectedNode.Tag is LocalAlbum) |
---|
231 | { |
---|
232 | LocalAlbum alb = (LocalAlbum)AlbumsTV.SelectedNode.Tag; |
---|
233 | if (ModelManager.Instance.AlbumEdited.LocalDir == alb.LocalDir) |
---|
234 | { |
---|
235 | alb.Name = ModelManager.Instance.AlbumEdited.Name; |
---|
236 | alb.MessageInfo = ModelManager.Instance.AlbumEdited.MessageInfo; |
---|
237 | |
---|
238 | AlbumsTV.SelectedNode.Text = alb.Name; |
---|
239 | } |
---|
240 | } |
---|
241 | else |
---|
242 | { |
---|
243 | tabControl1.Enabled = false; |
---|
244 | } |
---|
245 | |
---|
246 | } |
---|
247 | |
---|
248 | private void AlbumsTV_DragEnter(object sender, DragEventArgs e) |
---|
249 | { |
---|
250 | if (e.Data.GetDataPresent(DataFormats.FileDrop)) |
---|
251 | { |
---|
252 | e.Effect = DragDropEffects.Copy; |
---|
253 | } |
---|
254 | else |
---|
255 | { |
---|
256 | e.Effect = DragDropEffects.None; |
---|
257 | } |
---|
258 | |
---|
259 | } |
---|
260 | |
---|
261 | private void AlbumsTV_DragDrop(object sender, DragEventArgs e) |
---|
262 | { |
---|
263 | if (e.Data.GetDataPresent(DataFormats.FileDrop)) |
---|
264 | { |
---|
265 | string[] filePaths = (string[])(e.Data.GetData(DataFormats.FileDrop)); |
---|
266 | foreach (string fileLoc in filePaths) |
---|
267 | { |
---|
268 | if (File.Exists(fileLoc) |
---|
269 | || Directory.Exists(fileLoc) ) |
---|
270 | { |
---|
271 | ModelManager.Instance.directoryName = fileLoc; |
---|
272 | ServiceFactory.GetByType<LoadFromDirectory>().runService(); |
---|
273 | } |
---|
274 | } |
---|
275 | MainAppHelper.BuildAlbumTree(AlbumsTV, ModelManager.Instance.lstAlbumLocaux); |
---|
276 | } |
---|
277 | } |
---|
278 | |
---|
279 | private void btnAlbumAjout_Click(object sender, EventArgs e) |
---|
280 | { |
---|
281 | String rootPath = String.Empty; |
---|
282 | if (AlbumsTV.SelectedNode.Tag is LocalImage) |
---|
283 | { |
---|
284 | LocalImage img = (LocalImage)AlbumsTV.SelectedNode.Tag; |
---|
285 | } |
---|
286 | else if (AlbumsTV.SelectedNode.Tag is LocalAlbum) |
---|
287 | { |
---|
288 | LocalAlbum alb = (LocalAlbum)AlbumsTV.SelectedNode.Tag; |
---|
289 | } |
---|
290 | |
---|
291 | folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer; |
---|
292 | folderBrowserDialog1.SelectedPath = rootPath; |
---|
293 | |
---|
294 | folderBrowserDialog1.ShowNewFolderButton = false; |
---|
295 | |
---|
296 | if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) |
---|
297 | { |
---|
298 | ModelManager.Instance.directoryName = folderBrowserDialog1.SelectedPath; |
---|
299 | ServiceFactory.GetByType<LoadFromDirectory>().runService(); |
---|
300 | |
---|
301 | MainAppHelper.BuildAlbumTree(AlbumsTV, ModelManager.Instance.lstAlbumLocaux); |
---|
302 | } |
---|
303 | |
---|
304 | } |
---|
305 | |
---|
306 | private void btnAlbumEditOk_Click(object sender, EventArgs e) |
---|
307 | { |
---|
308 | if (AlbumsTV.SelectedNode.Tag is LocalAlbum) |
---|
309 | { |
---|
310 | LocalAlbum alb = (LocalAlbum)AlbumsTV.SelectedNode.Tag; |
---|
311 | if (ModelManager.Instance.AlbumEdited.LocalDir == alb.LocalDir) |
---|
312 | { |
---|
313 | alb.Name = ModelManager.Instance.AlbumEdited.Name; |
---|
314 | alb.MessageInfo = ModelManager.Instance.AlbumEdited.MessageInfo; |
---|
315 | |
---|
316 | AlbumsTV.SelectedNode.Text = alb.Name; |
---|
317 | } |
---|
318 | } |
---|
319 | else |
---|
320 | { |
---|
321 | tabControl1.Enabled = false; |
---|
322 | } |
---|
323 | } |
---|
324 | |
---|
325 | private void btnAlbDelete_Click(object sender, EventArgs e) |
---|
326 | { |
---|
327 | if (AlbumsTV.SelectedNode.Tag is LocalAlbum) |
---|
328 | { |
---|
329 | LocalAlbum alb = (LocalAlbum)AlbumsTV.SelectedNode.Tag; |
---|
330 | if (ModelManager.Instance.AlbumEdited.LocalDir == alb.LocalDir) |
---|
331 | { |
---|
332 | LocalDataHelper.DeleteInTree(alb); |
---|
333 | TreeNode node = AlbumsTV.SelectedNode; |
---|
334 | AlbumsTV.SelectedNode = AlbumsTV.SelectedNode.NextVisibleNode; |
---|
335 | node.Tag = null; |
---|
336 | node.Remove(); |
---|
337 | } |
---|
338 | } |
---|
339 | else |
---|
340 | { |
---|
341 | tabControl1.Enabled = false; |
---|
342 | } |
---|
343 | |
---|
344 | } |
---|
345 | |
---|
346 | private void AlbumsTV_MouseDown(object sender, MouseEventArgs e) |
---|
347 | { |
---|
348 | if (e.Button == System.Windows.Forms.MouseButtons.Right) |
---|
349 | { |
---|
350 | TreeViewCMenu.Show(AlbumsTV.PointToScreen(e.Location)); |
---|
351 | } |
---|
352 | } |
---|
353 | |
---|
354 | private void TreeViewCMenu_Click(object sender, EventArgs e) |
---|
355 | { |
---|
356 | //ContextMenuStrip cms = (ContextMenuStrip)sender; |
---|
357 | //cms. |
---|
358 | MainAppHelper.BuildAlbumTree(AlbumsTV, ModelManager.Instance.lstAlbumLocaux); |
---|
359 | } |
---|
360 | |
---|
361 | private void btnImgDelete_Click(object sender, EventArgs e) |
---|
362 | { |
---|
363 | |
---|
364 | } |
---|
365 | |
---|
366 | private void btnImgAdd_Click(object sender, EventArgs e) |
---|
367 | { |
---|
368 | |
---|
369 | } |
---|
370 | |
---|
371 | } |
---|
372 | } |
---|