| | |
| | | using Newtonsoft.Json; |
| | | using SqlSugar; |
| | | using System.Data; |
| | | using System.Dynamic; |
| | | using SystemDataDbType = System.Data.DbType; |
| | | |
| | | namespace PadApplication.Services; |
| | | |
| | |
| | | { |
| | | var parameters = new[] |
| | | { |
| | | new SugarParameter("V_WORK_ORDER_NO", workOrderNo), |
| | | new SugarParameter("V_MACHINE_NO", machineNo), |
| | | new SugarParameter("V_TOOL_NO", toolNo), |
| | | new SugarParameter("V_TYPE", type), |
| | | new SugarParameter("V_USE_LIMIT", useLimit ?? (object)DBNull.Value), |
| | | new SugarParameter("PO_OUTMSG", null) { Direction = ParameterDirection.Output, DbType = System.Data.DbType.String, Size = 200 }, |
| | | new SugarParameter("PO_OUTSUM", null) { Direction = ParameterDirection.Output, DbType = System.Data.DbType.Int32 } |
| | | }; |
| | | new SugarParameter("V_WORK_ORDER_NO", workOrderNo), |
| | | new SugarParameter("V_MACHINE_NO", machineNo), |
| | | new SugarParameter("V_TOOL_NO", toolNo), |
| | | new SugarParameter("V_TYPE", type), |
| | | new SugarParameter("V_USE_LIMIT", useLimit ?? (object)DBNull.Value), |
| | | new SugarParameter("PO_OUTMSG", null) { Direction = ParameterDirection.Output, DbType = System.Data.DbType.String, Size = 200 }, |
| | | new SugarParameter("PO_OUTSUM", null) { Direction = ParameterDirection.Output, DbType = System.Data.DbType.Int32 } |
| | | }; |
| | | try |
| | | { |
| | | Db.Ado.UseStoredProcedure().SqlQuery<object>( |
| | | "PROC_TOOL_ACTION", parameters); |
| | | var outMsg = parameters[5].Value?.ToString(); |
| | | var outSum = parameters[6].Value; |
| | | // 这里 outMsg 已经包含了存储过程每步DML的详细错误信息 |
| | | return new { outMsg, outSum }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 只有存储过程本身执行异常才会进入这里 |
| | | throw new Exception($"{ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取工单表单数据(通过工单编号和机台编号查询)。 |
| | | /// 仅负责参数转发,所有数据读取由存储过程完成。 |
| | | /// </summary> |
| | | /// <param name="workOrderNo">工单编号</param> |
| | | /// <param name="machineNo">机台编号</param> |
| | | /// <returns>表单数据的动态列表</returns> |
| | | public List<dynamic> GetFormData(string workOrderNo, string machineNo) |
| | | { |
| | | var parameters = new[] |
| | | { |
| | | new SugarParameter("V_WORK_ORDER_NO", workOrderNo), |
| | | new SugarParameter("V_MACHINE_NO", machineNo), |
| | | new SugarParameter("PO_CURSOR", null) { Direction = ParameterDirection.Output, DbType = SystemDataDbType.Object } |
| | | }; |
| | | // 假设存储过程名为 PROC_GET_FORM_DATA,返回游标 |
| | | var result = Db.Ado.UseStoredProcedure().GetDataTable("PROC_GET_FORM_DATA", parameters); |
| | | // DataTable 转 List<dynamic> |
| | | var list = new List<dynamic>(); |
| | | foreach (DataRow row in result.Rows) |
| | | { |
| | | IDictionary<string, object> expando = new ExpandoObject(); |
| | | foreach (DataColumn col in result.Columns) |
| | | { |
| | | expando[col.ColumnName] = row[col]; |
| | | } |
| | | list.Add(expando); |
| | | } |
| | | return list; |
| | | } |
| | | } |