/// <summary> /// 下载事件 /// 解压并下载 /// by xlb 2012-12-17 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLoad_Click(object sender, EventArgs e) { try { DataRow focusRow = gridView1.GetDataRow(gridView1.FocusedRowHandle); if (focusRow == null) { DrectSoft.Common.Ctrs.DLG.MyMessageBox.Show("请选择一条记录"); return; } string QueryStr = "select tempname,tempcontent from CommonnotePrintTemp where tempflow=@tempflow"; SqlParameter[] sps = { new SqlParameter("@tempflow", focusRow["TEMPFLOW"]) }; DbDataReader dbreander = DS_SqlHelper.ExecuteDataReader(QueryStr, sps, CommandType.Text); while (dbreander.Read()) { FileStream fstrem = null; string content = DS_Common.UnzipEmrXml(dbreander["TEMPCONTENT"].ToString()); byte[] bytecontent = Convert.FromBase64String(content); //MemoryStream ms = new MemoryStream(bytecontent); SaveFileDialog saveModel = new SaveFileDialog(); saveModel.Title = "下载到本地文件"; //saveModel.Filter = "模板文件(*.xrp)|*.xrp"; saveModel.FileName = dbreander["TEMPNAME"].ToString(); if (saveModel.ShowDialog() == DialogResult.OK) { FileInfo fileinfo = new FileInfo(saveModel.FileName); fstrem = fileinfo.OpenWrite(); fstrem.Write(bytecontent, 0, bytecontent.Length); fstrem.Close(); DrectSoft.Common.Ctrs.DLG.MyMessageBox.Show("下载成功"); } } } catch (Exception ex) { DrectSoft.Common.Ctrs.DLG.MyMessageBox.Show(1, ex); } }
/// <summary> /// 从数据库中下载用于使用的打印模板 /// xll /// 2012-12-17 /// </summary> private void LoadxrpReport() { FileStream fstrem = null; try { string appPath = Application.StartupPath; if (!Directory.Exists(appPath + @"\Report")) { Directory.CreateDirectory(appPath + @"\Report"); } DrectSoft.DSSqlHelper.DS_SqlHelper.CreateSqlHelper(); string sqlGetTemp = @"select tempflow,tempname,ModifyDateTime from commonnoteprinttemp where valide='1'"; DataTable dtTemPrint = DrectSoft.DSSqlHelper.DS_SqlHelper.ExecuteDataTable(sqlGetTemp, CommandType.Text); if (dtTemPrint == null || dtTemPrint.Rows.Count <= 0) { return; } foreach (DataRow item in dtTemPrint.Rows) { string filePath = ""; //为兼容早期版本做处理 if (item["TEMPNAME"].ToString().Contains(".")) { filePath = appPath + @"\Report\" + item["TEMPNAME"].ToString(); // fileinfo = new FileInfo(appPath + @"\Report\" + item["TEMPNAME"].ToString()); } else { filePath = appPath + @"\Report\" + item["TEMPNAME"].ToString() + ".xrp"; // fileinfo = new FileInfo(appPath + @"\Report\" + item["TEMPNAME"].ToString()+".xrp"); } FileInfo fileinfo = new FileInfo(filePath); if (fileinfo.LastWriteTime < Convert.ToDateTime(item["MODIFYDATETIME"])) { File.Delete(filePath); fileinfo = new FileInfo(filePath); string sqlTempDetail = @"select TEMPCONTENT from commonnoteprinttemp where tempflow=@tempflow"; SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("@tempflow", SqlDbType.Text) }; sqlParams[0].Value = item["TEMPFLOW"].ToString(); DataTable dtTemPrintDetali = DrectSoft.DSSqlHelper.DS_SqlHelper.ExecuteDataTable(sqlTempDetail, sqlParams, CommandType.Text); if (dtTemPrintDetali == null || dtTemPrintDetali.Rows.Count <= 0) { continue; } string gzipStr = dtTemPrintDetali.Rows[0]["TEMPCONTENT"].ToString(); if (string.IsNullOrEmpty(gzipStr)) { continue; } string content = DS_Common.UnzipEmrXml(gzipStr); byte[] bytecontent = Convert.FromBase64String(content); fstrem = fileinfo.OpenWrite(); fstrem.Write(bytecontent, 0, bytecontent.Length); fstrem.Close(); } } } catch (Exception ex) { throw ex; } finally { if (fstrem != null) { fstrem.Close(); } } }