| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | ///导出xls,动态解析存储过程参数 |
| | | /// </summary> |
| | | /// <param name="mode"></param> |
| | | /// <returns></returns> |
| | | |
| | | [RequestMethod(RequestMethods.POST)] |
| | | public ReturnDto<ExpandoObject> XlsOutView_NEW([FromBody] dynamic mode) |
| | | { |
| | | string rptParameter = mode.outParameter; |
| | | var paramDict = new Dictionary<string, object>(); |
| | | // 动态解析参数 |
| | | if (mode.outParams != null) |
| | | { |
| | | foreach (var prop in mode.outParams) |
| | | { |
| | | string name = prop.Name; |
| | | object value = prop.Value; |
| | | paramDict.Add(name, value); |
| | | } |
| | | } |
| | | var _pdfFloder = AppSettingsHelper.getValueByKey("DownPath"); |
| | | var _pdfName = Guid.NewGuid() + ".xls"; |
| | | var _pdfSaveFolder = Path.Combine(AppContext.BaseDirectory, _pdfFloder); |
| | | if (!Directory.Exists(_pdfSaveFolder)) |
| | | Directory.CreateDirectory(_pdfSaveFolder); |
| | | var pdfSavePath = Path.Combine(_pdfSaveFolder, _pdfName); |
| | | dynamic m = new ExpandoObject(); |
| | | try |
| | | { |
| | | var dset = RunProcedure(rptParameter, paramDict); |
| | | if (dset == null || dset.Tables.Count <= 0) |
| | | return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Exception, "没有查询到任何数据"); |
| | | var ary = new ArrayList(); |
| | | ExcelHelper.ExportAryHead(dset.Tables[0], ary, pdfSavePath); |
| | | m.fileUrl = "down/" + _pdfName; |
| | | return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "读取成功!"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogHelper.Debug(ToString(), ex.Message); |
| | | return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Exception, "读取失败," + ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 通用存储过程执行方法 |
| | | /// </summary> |
| | | private DataSet RunProcedure(string procName, IDictionary<string, object> paramDict) |
| | | { |
| | | var dset = new DataSet(); |
| | | using (var conn = new SqlConnection(DbHelperSQL.strConn)) |
| | | { |
| | | using (var comm = new SqlCommand(procName, conn)) |
| | | { |
| | | comm.CommandType = CommandType.StoredProcedure; |
| | | // 动态添加参数 |
| | | foreach (var kvp in paramDict) |
| | | { |
| | | comm.Parameters.AddWithValue("@" + kvp.Key, kvp.Value == null ? DBNull.Value : kvp.Value.ToString()); |
| | | } |
| | | using (var adapter = new SqlDataAdapter(comm)) |
| | | { |
| | | adapter.Fill(dset, "0"); |
| | | } |
| | | } |
| | | } |
| | | return dset; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据参数读取存储过程名称 |
| | | /// </summary> |