| | |
| | | } |
| | | |
| | | /// <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; |
| | | } |
| | | |
| | | [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> |
| | | /// <param name="mode"></param> |
| | |
| | | dt.Fill(dset, "0"); |
| | | } |
| | | } |
| | | |
| | | conn.Close(); |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | #region 各种导出 |
| | | /// <summary> |
| | | /// 导出daa备料单身 |
| | | /// </summary> |
| | | /// <param name="mode"></param> |
| | | /// <returns></returns> |
| | | [RequestMethod(RequestMethods.POST)] |
| | | public ReturnDto<ExpandoObject> XlsOutDaa([FromBody] dynamic mode) |
| | | { |
| | | string guid = mode.guid; |
| | | 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(); |
| | | //读数据 |
| | | var dset = new DataSet(); |
| | | SqlParameter[] parameters ={ |
| | | new("@inMainGuid", guid), |
| | | new("@inP1", ""), |
| | | new("@inP2", ""), |
| | | new("@inP3", ""), |
| | | new("@inP4", "")}; |
| | | try |
| | | { |
| | | dset = DbHelperSQL.RunProcedure("[xlsOutDaa]", parameters, "0"); |
| | | if (dset == null || dset.Tables.Count <= 0) |
| | | return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Exception, |
| | | "没有查询到任何数据"); |
| | | var ary = new ArrayList(); |
| | | ExcelHelper.ExportIqc(dset, 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> |
| | | /// 导出首检 |
| | |
| | | [RequestMethod(RequestMethods.POST)] |
| | | public ReturnDto<ExpandoObject> XlsOutXunJian([FromBody] dynamic mode) |
| | | { |
| | | string begDate = mode.begDate; |
| | | string guid = mode.guid; |
| | | var _pdfFloder = AppSettingsHelper.getValueByKey("DownPath"); |
| | | var _pdfName = Guid.NewGuid() + ".xls"; |
| | | var _pdfSaveFolder = Path.Combine(AppContext.BaseDirectory, _pdfFloder); |
| | |
| | | //读数据 |
| | | var dset = new DataSet(); |
| | | SqlParameter[] parameters ={ |
| | | new("@begDate", begDate), |
| | | new("@inMainGuid", guid), |
| | | new("@inP1", ""), |
| | | new("@inP2", ""), |
| | | new("@inP3", ""), |
| | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 导出成品检验报告 |
| | | /// </summary> |
| | | /// <param name="mode"></param> |
| | | /// <returns></returns> |
| | | [RequestMethod(RequestMethods.POST)] |
| | | public ReturnDto<ExpandoObject> XlsOutChengPin([FromBody] dynamic mode) |
| | | { |
| | | string guid = mode.guid; |
| | | 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(); |
| | | //读数据 |
| | | var dset = new DataSet(); |
| | | SqlParameter[] parameters ={ |
| | | new("@inMainGuid", guid), |
| | | new("@inP1", ""), |
| | | new("@inP2", ""), |
| | | new("@inP3", ""), |
| | | new("@inP4", "")}; |
| | | try |
| | | { |
| | | dset = DbHelperSQL.RunProcedure("[xlsOutChengPin]", parameters, "0"); |
| | | if (dset == null || dset.Tables.Count <= 0) |
| | | return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Exception, |
| | | "没有查询到任何数据"); |
| | | var ary = new ArrayList(); |
| | | ExcelHelper.ExportChengPin(dset, 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); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | |
| | |
| | | { |
| | | Dictionary<string, string> dic = new Dictionary<string, string> |
| | | { |
| | | { "工单编号", "t1" }, |
| | | { "条码", "t2" }, |
| | | //{ "工单编号", "t1" }, |
| | | { "条码", "t2" }, |
| | | }; |
| | | string tmpGuid = mode.tmpGuid; |
| | | string strType = mode.strType;//工单编号,过滤多sheet中的工单据 |
| | | int? rtnInt = (int)ReturnCode.Default; |
| | | int? _it = 0;//返回的行数 |
| | | string _msg = "";//返回的信息 |
| | | (_it, _msg) = getTable(tmpGuid, dic); |
| | | (_it, _msg) = getTable(tmpGuid, dic, strType); |
| | | if (_it <= 0) |
| | | return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Exception, _msg); |
| | | System.Text.StringBuilder sbMsg = new System.Text.StringBuilder(); |
| | |
| | | new SqlParameter("@outMsg",SqlDbType.NVarChar,300), |
| | | new SqlParameter("@inEdtUserGuid",_userGuid), |
| | | new SqlParameter("@tmpGuid",tmpGuid), |
| | | new SqlParameter("@strType",strType), |
| | | }; |
| | | parameters[0].Direction = ParameterDirection.Output; |
| | | parameters[1].Direction = ParameterDirection.Output; |
| | |
| | | { |
| | | rtnInt = -1; |
| | | sbMsg.Append("操作失败:" + ex.Message); |
| | | LogHelper.Debug("", "XlsInDaaHgm:" + ex.Message); |
| | | } |
| | | finally |
| | | { |
| | |
| | | cmd.CommandType = CommandType.StoredProcedure; |
| | | SqlParameter[] parameters = new SqlParameter[] { |
| | | new SqlParameter("@outGuid",SqlDbType.NVarChar,100), |
| | | new SqlParameter("@outMsg",SqlDbType.NVarChar,300), |
| | | new SqlParameter("@outMsg",SqlDbType.NVarChar,1200), |
| | | new SqlParameter("@inEdtUserGuid",_userGuid), |
| | | new SqlParameter("@tmpGuid",tmpGuid), |
| | | new SqlParameter("@strType",strType), |
| | |
| | | catch (Exception ex) |
| | | { |
| | | rtnInt = -1; |
| | | sbMsg.Append("操作失败:" + ex.Message); |
| | | sbMsg.Append("操作失败1:" + ex.Message); |
| | | } |
| | | finally |
| | | { |
| | |
| | | /// 返回dset |
| | | /// </summary> |
| | | /// <param name="tmpGuid"></param> |
| | | /// <param name="dic"></param> |
| | | /// <param name="strType">工单编号,过滤多表格</param> |
| | | /// <returns></returns> |
| | | private static (int?, string?) getTable(string tmpGuid, Dictionary<string, string> dic) |
| | | private static (int?, string?) getTable(string tmpGuid, Dictionary<string, string> dic,string strType="") |
| | | { |
| | | var _it = 0; |
| | | var _msg = ""; |
| | |
| | | System.Data.DataTable dt = new DataTable(); |
| | | try |
| | | { |
| | | dt = ExcelHelper.ExcelToTable(savePath); |
| | | dt = ExcelHelper.ExcelToTable(savePath,strType); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _it = 0; |
| | | _msg = "操作失败,ExcelToTable读取上传文件发生错误:" + ex.Message; |
| | | LogHelper.Debug("", "getTable:" + ex.Message); |
| | | } |
| | | dt.Columns.Add("tmpGuid", Type.GetType("System.Guid")); |
| | | dt.Columns.Add("tmpIdx", Type.GetType("System.String")); |
| | | |
| | | //如果是后盖码,加上工单号 |
| | | if (!string.IsNullOrEmpty(strType)) { |
| | | dt.Columns.Add("工单编号", Type.GetType("System.String")); |
| | | } |
| | | for (int r = 0; r < dt.Rows.Count; r++) |
| | | { |
| | | dt.Rows[r]["tmpGuid"] = Guid.Parse(tmpGuid); |
| | | dt.Rows[r]["tmpIdx"] = r + 3; |
| | | |
| | | //如果是后盖码,加上工单号 |
| | | if (!string.IsNullOrEmpty(strType)) |
| | | { |
| | | dt.Rows[r]["工单编号"] = strType; |
| | | } |
| | | } |
| | | bool flag = false; |
| | | using (SqlConnection destinationConnection = new SqlConnection(DbHelperSQL.strConn)) |
| | |
| | | bulkCopy.BatchSize = dt.Rows.Count; |
| | | bulkCopy.ColumnMappings.Add("tmpGuid", "tmpGuid");//映射字段名 DataTable列名 ,数据库对应的列名 |
| | | bulkCopy.ColumnMappings.Add("tmpIdx", "tmpIdx"); |
| | | //如果是后盖码,加上工单号 |
| | | if (!string.IsNullOrEmpty(strType)) |
| | | { |
| | | bulkCopy.ColumnMappings.Add("工单编号", "t1"); |
| | | } |
| | | |
| | | foreach (KeyValuePair<string, string> kvp in dic) |
| | | { |
| | | // bulkCopy.ColumnMappings.Add("名称", "t1"); |
| | | //bulkCopy.ColumnMappings.Add("名称", "t1"); |
| | | bulkCopy.ColumnMappings.Add(kvp.Key, kvp.Value); |
| | | } |
| | | bulkCopy.WriteToServer(dt); |
| | |
| | | catch (Exception ex) |
| | | { |
| | | _it = 0; |
| | | LogHelper.Debug("", "getTable:" + ex.Message); |
| | | _msg = "操作失败,bulkCopy读取上传文件发生错误:" + ex.Message; |
| | | } |
| | | } |