| | |
| | | using System.Text; |
| | | using Newtonsoft.Json; |
| | | using SqlSugar; |
| | | using System.Data; |
| | | using System.Dynamic; |
| | | using SystemDataDbType = System.Data.DbType; |
| | | |
| | | namespace PadApplication.Services; |
| | | |
| | |
| | | /// </summary> |
| | | public class MesCutterLedgerManager : Repository<MesCutterLedger> |
| | | { |
| | | private readonly MesQaItemsDetect02Manager |
| | | mesQaItemsDetect02Manager = new(); |
| | | //private readonly MesQaItemsDetect02Manager |
| | | //mesQaItemsDetect02Manager = new(); |
| | | |
| | | /// <summary> |
| | | /// 刀具查询(支持编号或名称模糊查询) |
| | |
| | | total = total |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 上下刀操作(上刀type=0,下刀type=1) |
| | | /// 仅负责参数转发,所有数据写入由存储过程完成。 |
| | | /// </summary> |
| | | /// <param name="machineNo">机台编号</param> |
| | | /// <param name="toolNo">刀具编号</param> |
| | | /// <param name="type">操作类型(上刀、下刀)</param> |
| | | /// <param name="useLimit">使用上限</param> |
| | | /// <returns>存储过程执行结果</returns> |
| | | public object SubmitToolAction(string workOrderNo, string machineNo, string toolNo, string type, int? useLimit, decimal? sdjs = null, decimal? xdjs = null) |
| | | { |
| | | 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("V_SDJS", sdjs ?? (object)DBNull.Value), |
| | | new SugarParameter("V_XDJS", xdjs ?? (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[7].Value?.ToString(); |
| | | var outSum = parameters[8].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", string.IsNullOrEmpty(workOrderNo) ? (object)DBNull.Value : workOrderNo, System.Data.DbType.String), |
| | | new SugarParameter("V_MACHINE_NO", string.IsNullOrEmpty(machineNo) ? (object)DBNull.Value : machineNo, System.Data.DbType.String), |
| | | new SugarParameter("PO_CURSOR", null) { Direction = ParameterDirection.Output, DbType = System.Data.DbType.Object } |
| | | }; |
| | | |
| | | try |
| | | { |
| | | // 使用 SqlSugar 的存储过程调用方式 |
| | | 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] == DBNull.Value ? null : row[col]; |
| | | } |
| | | list.Add(expando); |
| | | } |
| | | return list; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception($"调用存储过程 PROC_GET_FORM_DATA 失败: {ex.Message}"); |
| | | } |
| | | } |
| | | } |