| | |
| | | using System.Windows.Forms; |
| | | using WebAPI.Models; |
| | | using WebAPI.Service; |
| | | using System.Text.RegularExpressions; |
| | | |
| | | namespace WebAPI.Controllers |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | #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 |
| | | |
| | | |
| | | /// <summary> |
| | | /// 物料设置获取信息 |
| | | /// </summary> |