chenhaozhe
2025-10-19 fcc99f2648369ea6aa20e59f59653ac872bba091
WebAPI/Controllers/»ù´¡×ÊÁÏ/»ù´¡×ÊÁÏ/Gy_MateNumRelationController.cs
@@ -457,5 +457,71 @@
            }
        }
        #endregion
        #region å®¢æˆ·ç‰©æ–™å¯¹åº”表保存
        [Route("Gy_MateNumRelation/SaveGy_MateNumRelationAPI")]
        [HttpPost]
        public object SaveGy_MateNumRelationAPI([FromBody] JObject oMain)
        {
            try
            {
                var model = oMain["model"].ToString();
                LogService.Write("1" + model);
                //反序列化
                model = "[" + model + "]";
                List<Gy_MateNumRelation_Sec> lsmain = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Gy_MateNumRelation_Sec>>(model);
                string sql = string.Empty;
                oCN.BeginTran();
                foreach (var item in lsmain)
                {
                    // ä½¿ç”¨å½“前item的HItemID删除
                    sql = $"delete from  Gy_MateNumRelation_Sec where HItemID = {item.HItemID}";
                    oCN.RunProc(sql);
                    // å¼€å¯identity_insert
                    sql = "set identity_insert Gy_MateNumRelation_Sec on";
                    oCN.RunProc(sql);
                    LogService.Write("客户物料对应表" + @"Insert Into Gy_MateNumRelation_Sec " +
                          "(HItemID,HCusID,HCusRelationNumber,HCusRelationName,HMaterID" +
                          ",HUsed,HCREATEORGID,HUSEORGID,HRemark,HMakeDate,HMaker" +
                          ") " +
                          " values('" + item.HItemID + "','" + item.HCusID + "','" + item.HCusRelationNumber + "','" + item.HCusRelationName + "','" + item.HMaterID + "'," +
                          "'" + item.HUsed + "','" + item.HUSEORGID + "','" + item.HUSEORGID + "','" + item.HRemark + "',getdate(),'" + item.HMaker +
                          "') ");
                    // æ’入当前item的记录
                    sql = "Insert Into Gy_MateNumRelation_Sec " +
                          "(HItemID,HCusID,HCusRelationNumber,HCusRelationName,HMaterID" +
                          ",HUsed,HCREATEORGID,HUSEORGID,HRemark,HMakeDate,HMaker" +
                          ") " +
                          " values('" + item.HItemID + "','" + item.HCusID + "','" + item.HCusRelationNumber + "','" + item.HCusRelationName + "','" + item.HMaterID + "'," +
                          "'" + item.HUsed + "','" + item.HUSEORGID + "','" + item.HUSEORGID + "','" + item.HRemark + "',getdate(),'" + item.HMaker +
                         "') ";
                    oCN.RunProc(sql);
                    // å…³é—­identity_insert
                    sql = "set identity_insert Gy_MateNumRelation_Sec off";
                    oCN.RunProc(sql);
                    // æäº¤å½“前事务
                    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.Message;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}