| | |
| | | using System.Data.SqlClient; |
| | | using System.Web.Http; |
| | | using WebAPI.Models; |
| | | using System.Text.RegularExpressions; |
| | | using SyntacticSugar.constant; |
| | | namespace WebAPI.Controllers |
| | | { |
| | | public class Gy_SupplierController : ApiController |
| | |
| | | } |
| | | } |
| | | |
| | | #region 供应商分页列表 |
| | | [Route("Gy_Supplier/page")] |
| | | [HttpGet] |
| | | public json Gy_SupplierPage(string sWhere, string user, int page, int size, string Organization) |
| | | { |
| | | DataSet ds; |
| | | json res = new json(); |
| | | try |
| | | { |
| | | List<object> columnNameList = new List<object>(); |
| | | //判断权限 |
| | | if (!DBUtility.ClsPub.Security_Log_second("Gy_Supplier", 1, false, user)) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "无查看权限!"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | sWhere += ("and 组织名称 = '" + Organization + "'"); |
| | | sWhere = sWhere.Replace("'", "''"); |
| | | if (sWhere == null || sWhere.Equals("")) |
| | | { |
| | | ds = oCN.RunProcReturn("exec h_p_Gy_SupplierList " + page + "," + size + ",''", "h_p_Gy_SupplierList"); |
| | | } |
| | | else |
| | | { |
| | | ds = oCN.RunProcReturn("exec h_p_Gy_SupplierList " + page + "," + size + ",'" + sWhere + "'", "h_p_Gy_SupplierList"); |
| | | } |
| | | |
| | | //添加列名 |
| | | 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列对象的列名 |
| | | } |
| | | |
| | | res.code = CodeConstant.SUCCEED; |
| | | res.count = int.Parse(ds.Tables[1].Rows[0]["count"].ToString()); |
| | | res.Message = "Sucess!"; |
| | | res.list = columnNameList; |
| | | res.data = ds.Tables[0]; |
| | | return res; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | res.code = CodeConstant.FAIL; |
| | | res.count = CountConstant.FAIL; |
| | | res.Message = "Exception!" + e.ToString(); |
| | | res.data = null; |
| | | return res; |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | /// <summary> |
| | |
| | | return objJsonResult; |
| | | } |
| | | } |
| | | |
| | | #region 客户根据分类获取最大客户编码 |
| | | [Route("Gy_Supplier/getMaxNum")] |
| | | [HttpGet] |
| | | public object getMaxNum(int HSupTypeID, string user, string Organization) |
| | | { |
| | | try |
| | | { |
| | | List<object> columnNameList = new List<object>(); |
| | | //编辑权限 |
| | | if (!DBUtility.ClsPub.Security_Log_second("Gy_Supplier", 1, false, user)) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "无查看权限!"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | if (HSupTypeID == 0) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "没有选择具体分类!"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | else |
| | | { |
| | | ds = oCN.RunProcReturn(@"select * from h_v_Gy_SupplierList where 组织名称='" + Organization + "'" + "and HSupTypeID = '" + HSupTypeID + "'" + " order by 供应商代码 desc", "h_v_Gy_SupplierList"); |
| | | 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> |
| | | /// 供应商列表修改按钮方法 |
| | |
| | | ///参数:string sql。 |
| | | ///返回值:object。 |
| | | /// </summary> |
| | | |
| | | [Route("Gy_Supplier/AddBill1")] |
| | | [HttpPost] |
| | | public object AddBill1([FromBody] JObject oMain) |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region 根据父id和等级获得树状图递归 |
| | | |
| | | [Route("Gy_BadReason/Gy_SupTypeTreeListByLevel")] |
| | | [HttpGet] |
| | | public object Gy_MaterTypeTreeListByLevel() |
| | | { |
| | | try |
| | | { |
| | | string sql1 = string.Format("select hitemid,hnumber,hname,hparentid,hlevel from Gy_SupType order by hnumber"); |
| | | |
| | | ds = oCN.RunProcReturn(sql1, "Gy_SupType"); |
| | | |
| | | List<TreeModel> treeModels = new List<TreeModel>(); |
| | | TreeModel first = new TreeModel(); |
| | | first.id = "0"; |
| | | first.title = "供应商分类设置"; |
| | | treeModels.Add(first); |
| | | |
| | | foreach (DataRow row in ds.Tables[0].Rows) |
| | | { |
| | | var HLevel = (int)row["hlevel"]; |
| | | if (HLevel == 1) |
| | | { |
| | | TreeModel tree = new TreeModel(); |
| | | tree.id = row["hitemid"].ToString(); |
| | | tree.title = row["hname"].ToString(); |
| | | treeModels[0].children.Add(tree); |
| | | } |
| | | } |
| | | getTreeByLevel(ds.Tables[0], treeModels[0].children, 2); |
| | | |
| | | objJsonResult.code = "1"; |
| | | objJsonResult.count = 1; |
| | | objJsonResult.Message = "Sucess!"; |
| | | objJsonResult.data = Newtonsoft.Json.JsonConvert.SerializeObject(treeModels); |
| | | return objJsonResult; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "Exception!" + e.ToString(); |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | } |
| | | |
| | | public void getTreeByLevel(DataTable dt, List<TreeModel> tree, int num) |
| | | { |
| | | for (int m = 0; m < tree.Count; m++) |
| | | { |
| | | tree[m].children = new List<TreeModel>(); |
| | | for (int i = 0; i < dt.Rows.Count; i++)//第一次循环,得到所有根节点的子集 |
| | | { |
| | | var HLevel = (int)dt.Rows[i]["hlevel"]; |
| | | var HParentID = dt.Rows[i]["hparentid"].ToString(); |
| | | if (HLevel == num && HParentID == tree[m].id) |
| | | { |
| | | TreeModel tbjson = new TreeModel(); |
| | | tbjson.id = dt.Rows[i]["hitemid"].ToString(); |
| | | tbjson.title = dt.Rows[i]["hname"].ToString(); |
| | | tree[m].children.Add(tbjson); |
| | | } |
| | | } |
| | | for (int i = 0; i < tree[m].children.Count; i++) |
| | | { |
| | | getTreeByLevel(dt, tree[m].children, num + 1);//再次用子集去循环,拿出子集的子集 |
| | | } |
| | | } |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | #region 物料分类 树形图(根据代码展开树状图) |
| | | public class TreeModel |
| | | { |
| | | public string id { get; set; } |
| | | public string title { get; set; } |
| | | public List<TreeModel> children = new List<TreeModel>(); |
| | | } |
| | | /// <summary> |
| | | /// 递归函数 |
| | | /// </summary> |
| | | public void digui(DataTable dt, List<TreeModel> tree, int num) |
| | | { |
| | | for (int m = 0; m < tree.Count; m++) |
| | | { |
| | | tree[m].children = new List<TreeModel>(); |
| | | for (int i = 0; i < dt.Rows.Count; i++)//第一次循环,得到所有根节点的子集 |
| | | { |
| | | var strLen = dt.Rows[i]["hnumber"].ToString().Split('.'); |
| | | if (strLen.Length == num && dt.Rows[i]["hnumber"].ToString().Contains(tree[m].id + ".")) |
| | | { |
| | | TreeModel tbjson = new TreeModel(); |
| | | tbjson.id = dt.Rows[i]["hitemid"].ToString(); |
| | | tbjson.title = dt.Rows[i]["hname"].ToString(); |
| | | tree[m].children.Add(tbjson); |
| | | } |
| | | } |
| | | var strLens = tree[m].id.Split('.'); |
| | | for (int i = 0; i < tree[m].children.Count; i++) |
| | | { |
| | | digui(dt, tree[m].children, strLens.Length + 2);//再次用子集去循环,拿出子集的子集 |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |