/// <summary> /// 构造函数。 /// </summary> /// <param name="service"></param> /// <param name="items"></param> public WorkUploadWindow(ICoreService service, FileUploadItems items) : base(service) { this.StartPosition = FormStartPosition.CenterScreen; InitializeComponent(); this.fileUploadItems = items; }
/// <summary> /// /// </summary> /// <param name="items"></param> protected void AddUploadWindow(FileUploadItems items) { StudentMainWindow mainForm = this.ParentForm as StudentMainWindow; if (mainForm != null && items != null && items.Count > 0) { mainForm.AddScreenFileObserver(items[0]); mainForm.ShowUploadWindowDialog(items); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpload_Click(object sender, EventArgs e) { try { FileUploadItems items = new FileUploadItems(); this.listView.BeginUpdate(); foreach (ListViewItem lvi in this.listView.Items) { if (lvi.Checked && (lvi.Tag is FileUploadItem)) { items.Add((FileUploadItem)lvi.Tag); } } this.listView.EndUpdate(); if (items.Count == 0) { this.OnMessageEvent(MessageType.Normal | MessageType.PopupInfo, "请勾选需要上传的作品附件!"); return; } this.ShowUploadWindowDialog(items); } catch (Exception x) { this.OnMessageEvent(MessageType.Normal | MessageType.PopupWarn, "发生异常:" + x.Message); } }
/// <summary> /// /// </summary> /// <param name="items"></param> protected void DragFileObserver(FileUploadItems items) { if (items != null && items.Count > 0) { this.listView.BeginUpdate(); foreach (FileUploadItem fi in items) { ListViewItem lvi = new ListViewItem(fi.FileName); lvi.ToolTipText = string.Format("文件名:{0}\r\n后缀名:{1}\r\n文件地址:{2}", fi.FileName, fi.Ext, fi.Path); lvi.Tag = fi; lvi.Checked = true; this.listView.Items.Add(lvi); } this.listView.EndUpdate(); if (!this.btnUpload.Enabled) { this.btnUpload.Enabled = true; } } }
/// <summary> /// 显示上传模态界面。 /// </summary> /// <param name="items"></param> public void ShowUploadWindowDialog(FileUploadItems items) { try { if (new WorkUploadWindow(this.CoreService, items).ShowDialog(this) == DialogResult.Yes) { this.listView.BeginUpdate(); foreach (ListViewItem lvi in this.listView.Items) { if (lvi.Checked) { lvi.Checked = false; lvi.ForeColor = Color.Red; lvi.ToolTipText = "已经上传成功!"; } } this.listView.EndUpdate(); } } catch (Exception x) { this.OnMessageEvent(MessageType.Normal | MessageType.PopupWarn, "发生异常:" + x.Message); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UCCaptureScreenSet_DoubleClick(object sender, EventArgs e) { try { this.Enabled = !(this.bShowWin = true); this.csw = new CaptureScreenWindow(); FileUploadItems items = null; this.csw.CopyScreenCutEvent += new CaptureScreenHandler(delegate(Image data) { if (data != null) { string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); Catalog c = this.CoreService["catalog"] as Catalog; if (c != null) { path += string.Format("\\{0}_截屏_{1:HHmmss}.jpg", c.CatalogName, DateTime.Now); } else { path += string.Format("\\截屏_{0:HHmmss}.jpg", DateTime.Now); } data.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg); if (System.IO.File.Exists(path)) { items = new FileUploadItems(); string strFileName = System.IO.Path.GetFileName(path); string strExt = System.IO.Path.GetExtension(path); items.Add(new FileUploadItem(strFileName, strExt, path)); } } }); this.csw.CopyScreenWindowClosed += new EventHandler(delegate(object o, EventArgs x) { ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object obj) { Thread.Sleep(100); this.ThreadSafeMethod(new MethodInvoker(delegate() { this.AddUploadWindow(items); })); })); }); this.csw.ShowDialog(this); } catch (Exception x) { Program.GlobalExceptionHandler(x); this.OnMessageEvent(MessageType.PopupWarn, "截图异常:" + x.Message); } finally { this.Enabled = !(this.bShowWin = false); } }