/// <summary> /// 文件添加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnFileAdd_Click(object sender, EventArgs e) { try { openFileDialog2.Filter = "所有文件(*)|*"; openFileDialog2.ShowDialog(); if (openFileDialog2.FileName != string.Empty) { string filenamerount = openFileDialog2.FileName; string fileName = System.IO.Path.GetFileNameWithoutExtension(filenamerount); string fileExec = System.IO.Path.GetExtension(filenamerount); decimal fileSize = WinListAttachFileRule.FileSize(filenamerount); fileSize = SysConvert.ToDecimal(fileSize / 1024, 2); int SysFileSize = 10 * 1024;//10M限制 if (fileSize > SysFileSize) { ShowMessage("文件上传大小不能超过" + SysFileSize + "KB"); return; } byte[] p_File = WinListAttachFileRule.ConvertToBinaryByPath(filenamerount); WinListAttachFileRule rule = new WinListAttachFileRule(); rule.RAdd(p_File, UCWinListID, UCHeadType, UCSubType, UCHTDateID, UCHTDateSeq, fileName, "", fileExec, "", UCFileProt1, UCFileProt2, fileSize, UCUploadOPID, UCUploadOPName, UCLoginLogID); BindGrid(); } } catch (Exception E) { this.ShowMessage(E.Message); } }
/// <summary> /// 文件删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDeleteFlie_Click(object sender, EventArgs e) { try { if (saveFileID == 0) { this.ShowMessage("没有文件"); return; } if (!CheckCorrectDelete()) { return; } if (DialogResult.Yes != ShowConfirmMessage("删除为不可恢复操作,确认删除")) { return; } WinListAttachFileRule.DeleteFile(saveFileID); BindGrid(); } catch (Exception E) { this.ShowMessage(E.Message); } }
/// <summary> /// 绑定数据明细 /// </summary> public void BindGrid() { string conditonstr = string.Empty; conditonstr += " AND WinListID=" + UCWinListID; conditonstr += " AND HeadType=" + UCHeadType; conditonstr += " AND SubType=" + UCSubType; conditonstr += " AND HTDataID=" + UCHTDateID; string filedNameStr = string.Empty; filedNameStr = "ID,FileTitle,FileName,FileSize,UploadTime,UploadOPName,UploadOPID,FileExe,Remark"; WinListAttachFileRule rule = new WinListAttachFileRule(); DataTable dt = rule.RShow(conditonstr + " ORDER BY ID", filedNameStr); gridView1.GridControl.DataSource = dt; gridView1.GridControl.Show(); }
/// <summary> /// 下载文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLoadFile_Click(object sender, EventArgs e) { try { if (saveFileID == 0) { this.ShowMessage("没有文件"); return; } this.saveFileDialog2.Filter = "保存文件(*" + saveFileExe + ")|*" + saveFileExe; this.saveFileDialog2.FileName = saveFileName; if (this.saveFileDialog2.ShowDialog() == DialogResult.Cancel) { return; } System.IO.File.WriteAllBytes(saveFileDialog2.FileName, WinListAttachFileRule.ReadFileContext(saveFileID)); } catch (Exception E) { this.ShowMessage(E.Message); } }