private void btnDownload_Click(object sender, EventArgs e) { string path = Application.StartupPath + "\\" + Config.GetConfig().APP_DOWNLOAD + "\\" + Func.FormatDate(DateTime.Now, false) + Func.FormatTime(DateTime.Now, true, false); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } foreach (DataGridViewRow row in dgv.Rows) { //下载选中行的文件 if ((bool)row.Cells["colSelect"].Value) { //获取文件数据 EapFile file = Bll.GetBll().DownloadFile(row.Cells["colFileId"].Value.ToString()); if (file == null) { Func.ShowMessage(MessageType.Error, "下载文件[" + row.Cells["colFileId"].Value.ToString() + "]失败"); return; } //写入文件 FileStream fs = new FileStream(path + "\\" + file.FILE_ID, FileMode.Create, FileAccess.Write); fs.Write(file.FILE_DATA, 0, file.FILE_DATA.Length); fs.Close(); } } Func.ShowMessage(MessageType.Information, "文件下载成功,下载的文件已保存到目录[" + path + "]"); }
/// <summary> /// 上传文件数据到数据库 /// </summary> /// <param name="file">文件实体</param> /// <returns>错误消息,为空表示成功</returns> internal string UploadFile(EapFile file) { if (Config.GetConfig().DB_TYPE == "1") { return(DalOracle.GetDalOracle().UploadFile(file)); } return(string.Empty); }
/// <summary> /// 从数据库获取应用文件清单 /// </summary> /// <param name="query">查询条件实体</param> /// <param name="pageno">要查询的页</param> /// <param name="pagesize">页大小</param> /// <param name="icnt">结果记录条数</param> /// <returns>应用文件清单</returns> internal List <EapFile> GetAppFiles(EapFile query, int pageno, int pagesize, out int icnt) { if (Config.GetConfig().DB_TYPE == "1") { return(DalOracle.GetDalOracle().GetAppFiles(query, pageno, pagesize, out icnt)); } icnt = 0; return(null); }
private void btnUpload_Click(object sender, EventArgs e) { OpenFileDialog pfd = new OpenFileDialog(); pfd.Multiselect = true; pfd.Filter = "所有支持的文件(*.dll,*.exe,*.config,*.bat)|*.dll;*.exe;*.config;*.bat"; if (pfd.ShowDialog() == DialogResult.OK) { foreach (string path in pfd.FileNames) { FileInfo fi = new FileInfo(path); //获取文件信息 EapFile eapfile = new EapFile(); eapfile.FILE_ID = fi.Name; eapfile.FILE_VERSION = FileVersionInfo.GetVersionInfo(path).FileVersion; if (eapfile.FILE_VERSION == null) { eapfile.FILE_VERSION = string.Empty; } eapfile.FILE_EDIT_TIME = fi.LastWriteTime; //读取文件 FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); if (fs.Length == 0) { Func.ShowMessage(MessageType.Error, "不能上传空文件"); break; } eapfile.FILE_DATA = new byte[fs.Length]; fs.Read(eapfile.FILE_DATA, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); //上传文件 string ret = Bll.GetBll().UploadFile(eapfile); Log.Write(MessageType.Information, "上传文件[" + eapfile.FILE_ID + "]", Config.GetConfig().user.USER_ID); if (ret != string.Empty) { Func.ShowMessage(MessageType.Error, ret); break; } } page.PageNo = 1; BindData(); } }
private void BindData() { EapFile query = getQuery(); if (query == null) { return; } chkAllSelect.Checked = false; int icnt; dgv.DataSource = Bll.GetBll().GetAppFiles(query, page.PageNo, page.PageSize, out icnt); page.RecordCount = icnt; }
/// <summary> /// 从数据库获取应用文件清单 /// </summary> /// <param name="query">查询条件实体</param> /// <param name="pageno">要查询的页</param> /// <param name="pagesize">页大小</param> /// <param name="icnt">结果记录条数</param> /// <returns>应用文件清单</returns> internal List<EapFile> GetAppFiles(EapFile query, int pageno, int pagesize, out int icnt) { int paracnt = 0; StringBuilder sql = new StringBuilder(600); sql.Append("select t.FILE_ID,t.FILE_VERSION,t.FILE_EDIT_TIME,t.FILE_UPLOAD_TIME from T_EAP_FILE t"); sql.Append(" where 1=1"); if (query.FILE_ID != string.Empty) { sql.Append("and t.FILE_ID like '%'||:FILE_ID||'%'"); paracnt++; } if (query.FILE_VERSION != string.Empty) { sql.Append("and t.FILE_VERSION like '%'||:FILE_VERSION||'%'"); paracnt++; } sql.Append(" order by t.FILE_ID"); OracleParameter[] para = new OracleParameter[paracnt]; for (int i = 0; i < paracnt; i++) { if (query.FILE_ID != string.Empty) { para[i] = new OracleParameter(":FILE_ID", OracleType.VarChar); para[i].Value = query.FILE_ID; query.FILE_ID = string.Empty; continue; } if (query.FILE_VERSION != string.Empty) { para[i] = new OracleParameter(":FILE_VERSION", OracleType.VarChar); para[i].Value = query.FILE_VERSION; query.FILE_VERSION = string.Empty; continue; } } return Oracle.GetOracle().QueryToPage<EapFile>(sql, para, pageno, pagesize, out icnt); }
/// <summary> /// 上传文件数据到数据库 /// </summary> /// <param name="file">文件实体</param> /// <returns>错误消息,为空表示成功</returns> internal string UploadFile(EapFile file) { StringBuilder sql = new StringBuilder(200); sql.Append("insert into T_EAP_FILE(FILE_ID,FILE_VERSION,FILE_EDIT_TIME,FILE_UPLOAD_TIME,FILE_DATA)"); sql.Append(" values(:FILE_ID,:FILE_VERSION,:FILE_EDIT_TIME,sysdate,:FILE_DATA)"); OracleParameter[] para = { new OracleParameter(":FILE_ID", OracleType.VarChar), new OracleParameter(":FILE_VERSION", OracleType.VarChar), new OracleParameter(":FILE_EDIT_TIME", OracleType.DateTime), new OracleParameter(":FILE_DATA", OracleType.Blob) }; para[0].Value = file.FILE_ID; para[1].Value = file.FILE_VERSION; para[2].Value = file.FILE_EDIT_TIME; para[3].Value = file.FILE_DATA; return Oracle.GetOracle().ExecSql(sql, para); }
private EapFile getQuery() { EapFile query = new EapFile(); query.FILE_ID = txtFileId.Text.Trim(); if (Func.StringLength(query.FILE_ID) > 20) { Func.ShowMessage(MessageType.Error, "文件名称最大长度为20个字符(10个汉字)"); return(null); } query.FILE_VERSION = txtFileVersion.Text.Trim(); if (Func.StringLength(query.FILE_VERSION) > 20) { Func.ShowMessage(MessageType.Error, "文件版本最大长度为20个字符(10个汉字)"); return(null); } return(query); }