using DBUtility; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using SQLHelper; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Net; using System.Net.Http; using System.Web; using System.Web.Http; using WebAPI.Code; using WebAPI.Models; namespace WebAPI.Controllers { public class SupMaterPackController : ApiController { private JsonResult objJsonResult = new JsonResult(); private json objjson = new json(); SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); DataSet ds; //获取系统参数 Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter(); #region 物料标准包装 [Route("SupMaterPackBill/List")] [HttpGet] public object List(string HSupIDs, string sqlWhere) { try { List columnNameList = new List(); string sql1 = "select * from h_v_SRM_SupMaterPackList where 1 = 1 and hsupid in ( " + HSupIDs.Trim() + ")"; string sql = sql1 + sqlWhere + " order by hmainid desc"; ds = oCn.RunProcReturn(sql, "h_v_SRM_SupMaterPackList"); //添加列名 foreach (DataColumn col in ds.Tables[0].Columns) { Type dataType = col.DataType; string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.list = columnNameList; objJsonResult.data = ds.Tables[0]; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 保存最小包装 [Route("SupMaterPackBill/Save")] [HttpPost] public object Save([FromBody] JObject msg) { var _value = msg["msg"].ToString(); string msg1 = _value.ToString(); string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string msg2 = sArray[0].ToString(); string msg3 = sArray[1].ToString(); string msg4 = sArray[2].ToString(); string UserName = ""; ListModels oListModels = new ListModels(); try { DAL.ClsSupMaterPackBill oBill = new DAL.ClsSupMaterPackBill(); List lsmain = new List(); msg2 = msg2.Replace("\\", ""); msg2 = msg2.Replace("\n", ""); //\n lsmain = oListModels.getObjectByJson_ClsSupMaterPackBillMain(msg2); foreach (Model.ClsSupMaterPackBillMain oItem in lsmain) { //oItem.HMaker = ""; UserName = oItem.HMaker; //制单人 oItem.HBillType = "10001"; oItem.HBillSubType = "10001"; oItem.HBillStatus = 1; DBUtility.ClsPub.CurUserName = UserName; oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year); if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!没有单据日期,无法保存!"; objJsonResult.data = 1; return objJsonResult; } oBill.omodel = oItem; } //表体数据 //按 },{来拆分数组 //去掉【和】 msg3 = msg3.Substring(1, msg3.Length - 2); msg3 = msg3.Replace("\\", ""); msg3 = msg3.Replace("\n", ""); //\n //msg2 = msg2.Replace("'", "’"); List ls = new List(); ls = oListModels.getObjectByJson_ClsSupMaterPackBillSub(msg3); int i = 0; foreach (Model.ClsSupMaterPackBillSub oItemSub in ls) { i++; oItemSub.HEntryID = i; oBill.DetailColl.Add(oItemSub); } //保存 //保存完毕后处理 bool bResult; if (Convert.ToInt32(msg4) == 1) { // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); } else { bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo); } if (bResult) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "保存成功!"; objJsonResult.data = 1; return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo; objJsonResult.data = 1; return objJsonResult; } } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!" + e.ToString(); objJsonResult.data = 1; return objJsonResult; } } #endregion #region 标准包装编辑获取数据 [Route("SupMaterPackBill/edit")] [HttpGet] public object SupMaterPackBill_Edit(long HInterID) { try { //查询主表 DataSet ds; SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); ds = oCn.RunProcReturn("select * from h_v_SRM_SupMaterPack_Edit where hmainid =" + HInterID, "h_v_SRM_SupMaterPack_Edit"); if (ds == null || ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "false!没有返回包装包装信息"; objJsonResult.data = null; return objJsonResult; } else { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0]; return objJsonResult; } } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "获取标准包装信息异常" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion [Route("SupMaterPackBill/delete")] [HttpGet] public object DeleteSupMaterPackBill(string HInterID, string HUserName) { SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); try { SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); if (objjson.code == "0") return objjson; oCN.BeginTran(); oCN.RunProc($"Delete From SRM_SupMaterPackSub where cast(HMaterID as varchar(200))+cast(HInterID as varchar(200))+cast(HEntryID as varchar(200)) in ({HInterID})"); oCN.Commit(); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "删除成功!"; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { oCN.RollBack(); objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } } }