using log4net; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UFIDA.U8.Framework.Api.ControlObject.Common; using UFIDA.U8.Framework.Api.ControlObject.Json; using UFIDA.U8.Framework.Api.ControlObject.Models; using UFSoft.U8.Framework.ContextSrv; using UFSoft.U8.U8M.BFDispatcher; using UFSoft.U8.U8M.Common; using UFSoft.U8.U8M.DAC; using UFSoft.U8.U8M.DOSchema.MO; namespace UFIDA.U8.Framework.Api.ControlObject.U8M { public class MOrder { protected readonly ILog logInfo = LogManager.GetLogger("logInfo"); private MOrderDs GetEmptyDs() { var ds = MOMExecutor.BFMOrder_LoadData("LoadFirst", 0, new DefaultContextContainer()); #region 清除数据集里的数据 if (ds.Tables.Contains("mom_orderdetail_ExtraDefine")) { ds.Tables["mom_orderdetail_ExtraDefine"].Clear(); } if (ds.Tables.Contains("mom_order_ExtraDefine")) { ds.Tables["mom_order_ExtraDefine"].Clear(); } ds.MoAllocateSubs.Clear(); ds.MoAllocates.Clear(); ds.MOrderDetails.Clear(); ds.Order.Clear(); #endregion return ds; } private MOrderDs GetVoucherDs(string cCardNum, AutoDocNoGenerateParam docNoParam, Dictionary input) { var ds = GetEmptyDs(); var head = ds.Order.NewOrderRow(); ds.Order.AddOrderRow(head); var docNo = U8MCommonExecutor.BFVoucher_GetVoucherID(cCardNum, docNoParam.Paramaters, false, new DefaultContextContainer()); var be = new UFSoft.U8.MO.BE.MOrder(ds); var beHead = new BEHelper(be); beHead.SetValue(input); if (string.IsNullOrWhiteSpace(be.MoCode)) { be.MoCode = docNo; } var bodys = input["body"] as List> ?? $"{input["body"]}".ToObject>>(); for (var i = 0; i < bodys.Count; i++) { var body = bodys[i]; var detail = be.MOrderDetails[i]; var beBody = new BEHelper(detail); beBody.SetValue(body); beBody.SetPartId(); beBody.SetBomId(); } return (MOrderDs)be.DataObject; } public BaseResult Save(string cCardNum, Dictionary input) { try { var docNoParam = new AutoDocNoGenerateParam(EnumAutoDocNoType.HandAuto, cCardNum) { IsCurrentDocNoByHand = false }; var ds = GetVoucherDs(cCardNum, docNoParam, input); if (ds == null) { throw new Exception("未能构建数据集"); } //var context = new DefaultContextContainer(); //context.context["taskid"] = taskId; var id = MOMExecutor.BFMomProcess_HMOSaveWithDocNoPara(ds, docNoParam, new DefaultContextContainer()); return new BaseResult() { bSuccess = true, message = "新增成功", result = id }; } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult() { bSuccess = false, message = "新增失败", result = ex.Message }; } } public BaseResult Delete(string cCardNum, List inputs) { try { if (inputs == null || inputs.Count <= 0) throw new Exception("没有需要删除的数据"); var dataReader = SimpleDACObject.ExecuteReader($"SELECT MID FROM dbo.fc_MoRoutingBill WHERE cVouchCode IN ('{string.Join("','", inputs)}') AND cVouchType='{cCardNum}'"); var newInput = new List(); while (dataReader.Read()) { newInput.Add(int.Parse($"{dataReader[0]}")); } return Delete(newInput); } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult() { bSuccess = false, message = "删除失败", result = ex.Message }; } } public BaseResult Delete(List inputs) { try { if (inputs == null || inputs.Count <= 0) throw new Exception("没有需要删除的数据"); var ht = new Hashtable(); foreach (var input in inputs) { ht.Add(input, input); } var id = MOMExecutor.BFMomProcess_MODeleteProcess(ht, new DefaultContextContainer()); return new BaseResult() { bSuccess = true, message = "删除成功", result = id }; } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult() { bSuccess = false, message = "删除失败", result = ex.Message }; } } //public BaseResult Verify(string cCardNum, List inputs) //{ // try // { // if (inputs == null || inputs.Count <= 0) // throw new Exception("没有需要审核的数据"); // var dataReader = SimpleDACObject.ExecuteReader($"SELECT MID FROM dbo.fc_MoRoutingBill WHERE cVouchCode IN ('{string.Join("','", inputs)}') AND cVouchType='{cCardNum}'"); // var newInput = new List(); // while (dataReader.Read()) // { // newInput.Add(int.Parse($"{dataReader[0]}")); // } // return Verify(newInput); // } // catch (Exception ex) // { // logInfo.Error(ex.Message, ex); // return new BaseResult() { bSuccess = false, message = "审核失败", result = ex.Message }; // } //} //public BaseResult StatusProcess(List inputs) //{ // try // { // if (inputs == null || inputs.Count <= 0) // throw new Exception("没有需要审核的数据"); // var ht = new Dictionary(); // foreach (var input in inputs) // { // ht.Add(input, $"{input}"); // } // var id = MOMExecutor.BFMomProcess_MOStatusProcess(ht, new DefaultContextContainer()); // return new BaseResult() { bSuccess = true, message = "审核成功", result = id }; // } // catch (Exception ex) // { // logInfo.Error(ex.Message, ex); // return new BaseResult() { bSuccess = false, message = "审核失败", result = ex.Message }; // } //} //public BaseResult UnVerify(string cCardNum, List inputs) //{ // try // { // if (inputs == null || inputs.Count <= 0) // throw new Exception("没有需要弃审的数据"); // var dataReader = SimpleDACObject.ExecuteReader($"SELECT MID FROM dbo.fc_MoRoutingBill WHERE cVouchCode IN ('{string.Join("','", inputs)}') AND cVouchType='{cCardNum}'"); // var newInput = new List(); // while (dataReader.Read()) // { // newInput.Add(int.Parse($"{dataReader[0]}")); // } // return UnVerify(newInput); // } // catch (Exception ex) // { // logInfo.Error(ex.Message, ex); // return new BaseResult() { bSuccess = false, message = "弃审失败", result = ex.Message }; // } //} //public BaseResult UnVerify(List inputs) //{ // try // { // if (inputs == null || inputs.Count <= 0) // throw new Exception("没有需要弃审的数据"); // var ht = new Dictionary(); // foreach (var input in inputs) // { // ht.Add(input, $"{input}"); // } // var id = SFExecutor.BFMoRoutingBill_UnVerify(ht, new DefaultContextContainer()); // return new BaseResult() { bSuccess = true, message = "弃审成功", result = id }; // } // catch (Exception ex) // { // logInfo.Error(ex.Message, ex); // return new BaseResult() { bSuccess = false, message = "弃审失败", result = ex.Message }; // } //} } }