1
zrg
2024-08-13 461a7bfc0a2250ec5ff4b7a85cb6ce3c2f0bf06e
WebAPI/Controllers/BaseSet/Gy_MaterialController.cs
@@ -13,6 +13,7 @@
using System.Windows.Forms;
using WebAPI.Models;
using WebAPI.Service;
using System.Text.RegularExpressions;
namespace WebAPI.Controllers
{
@@ -113,6 +114,127 @@
                return objJsonResult;
            }
        }
        #region 物料根据分类获取最大物料编码
        [Route("Gy_Material/getMaxNum")]
        [HttpGet]
        public object getMaxNum(int HMaterTypeID, string user, string Organization)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                //编辑权限
                if (!DBUtility.ClsPub.Security_Log_second("Gy_Material", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查看权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (HMaterTypeID == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有选择具体分类!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    ds = oCN.RunProcReturn(@"select * from h_v_Gy_MaterialList where 组织名称='" + Organization + "'" + "and HMaterTypeID = '"+ HMaterTypeID + "'" + " order by 物料代码 desc", "h_v_Gy_MaterialList");
                    if (ds == null || ds.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "没有找到该分类的物料编码请使用普通新增";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    string HNumber = ds.Tables[0].Rows[0]["物料代码"].ToString();
                    // 使用正则表达式找到数字部分  (?<=\D)是一个零宽断言,表示前面的字符不是数字 (\d+)$表示后面跟着一连串字符串知道末尾
                    Match match = Regex.Match(HNumber, @"(?<=\D)(\d+)$");
                    if (match.Success)
                    {
                        string prefix = HNumber.Substring(0, HNumber.Length - match.Length); // 提取前缀
                        int number = int.Parse(match.Value); // 解析数字
                        // 数字+1
                        number++;
                        // 格式化数字,保持原长度
                        string formattedNumber = number.ToString().PadLeft(match.Length, '0');
                        // 重新组合字符串
                        string result = prefix + formattedNumber;
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "success";
                        objJsonResult.data = result;
                        return objJsonResult;
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "此分类物料编码格式有误";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 获取物料精度通过id
        [Route("Gy_Material/getDecByID")]
        [HttpGet]
        public object getDecByID(int HMaterID)
        {
            try
            {
                if(HMaterID == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有选择物料";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn(@"select HQtyDec,HPriceDec,HMoneyDec from Gy_Material where HitemID=" + HMaterID , "Gy_Material");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "没有找到该物料编码";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Success";
                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
        /// <summary>
        /// 物料设置获取信息
@@ -1951,7 +2073,7 @@
                ,HPERUNITSTANDHOUR,HSTDLABORPREPARETIME,HSTDMACHINEPREPARETIME
                 )
                values
                ({jsonData.HItemID},{jsonData.HERPItemID},'{jsonData.HNumber}','{jsonData.HName}','{jsonData.HModel}',
                ({jsonData.HItemID},{jsonData.HItemID},'{jsonData.HNumber}','{jsonData.HName}','{jsonData.HModel}',
                '{jsonData.HShortNumber}',{jsonData.HParentID},{jsonData.HLevel},{jsonData.HEndFlag},{jsonData.HStopflag},'{jsonData.HRemark}',{jsonData.HMaterClsID},{jsonData.HUnitID},{jsonData.HUnitGroupID},{jsonData.HLength},{jsonData.HWidth},{jsonData.HHeight},{jsonData.HJQty},{jsonData.HMQty},'{jsonData.HOldMaterNumber}',{jsonData.HWHID},{jsonData.HSPID},'{jsonData.HPlanMode}','{jsonData.HUseFlag}','{jsonData.HMakeTime}',{jsonData.HMinPickQty},{jsonData.HCREATEORGID},{jsonData.HUSEORGID},'{jsonData.HBatchManager}',{jsonData.HCHECKINCOMING},{jsonData.HAuxPropFlag},{jsonData.HISKFPERIOD},{jsonData.HAuxUnitID},{jsonData.HSNUnitID},{jsonData.HBASEUNITID},{jsonData.HSALEUNITID},{jsonData.HSALEPRICEUNITID},{jsonData.HPERUNITSTANDHOUR},'{jsonData.HSTDLABORPREPARETIME}','{jsonData.HSTDMACHINEPREPARETIME}')";
                    oCN.RunProc(sql);