1
chenhaozhe
2025-06-20 55e832ca189624916a7a2e3e6cf24e513de9b1b4
WebAPI/Controllers/BaseSet/Gy_WarehouseController.cs
@@ -85,6 +85,91 @@
        }
        public class TreeModel
        {
            public string Id { get; set; }
            public string Number { get; set; }
            public string Title { get; set; }
            public List<TreeModel> children = new List<TreeModel>();
        }
        /// <summary>
        /// 返回仓库列表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("Gy_Warehouse/listTree")]
        [HttpGet]
        public object listTree(string sWhere, string user, string Organization)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                //编辑权限
                if (!DBUtility.ClsPub.Security_Log_second("Gy_Warehouse", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查看权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                string sql1 = string.Format(@"select * from h_v_IF_WareHouseList_ExtendWHType where 组织名称='" + Organization + "'");
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn(sql1 + sWhere + " order by 仓库代码 ", "h_v_IF_WareHouseList_ExtendWHType");
                }
                else
                {
                    string sql = sql1 + sWhere + " order by 仓库代码 ";
                    ds = oCN.RunProcReturn(sql, "h_v_IF_WareHouseList_ExtendWHType");
                }
                List<TreeModel> treeModels = new List<TreeModel>();
                TreeModel first = new TreeModel();
                first.Id = "0";
                first.Title = "模具仓库";
                first.Number = "0";
                treeModels.Add(first);
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    var strLen = row["hitemid"].ToString().Split('.');
                    if (strLen.Length == 1)
                    {
                        TreeModel tree = new TreeModel();
                        tree.Id = row["hitemid"].ToString();
                        tree.Title = row["hname"].ToString();
                        tree.Number = row["HNumber"].ToString();
                        treeModels[0].children.Add(tree);
                    }
                }
                digui(ds.Tables[0], treeModels[0].children, 2);
                //添加列名
                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.data = Newtonsoft.Json.JsonConvert.SerializeObject(treeModels);
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        /// <summary>
        /// 根据基础资料ID 查找记录
@@ -386,6 +471,17 @@
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                //查询数据中是否存在重复代码
                ds = oCN.RunProcReturn("Select HItemID from Gy_Warehouse  Where HItemID<>" + HItemID + " and HNumber='" + HNumber + "' and HUSEORGID=" + HUSEORGID, "Gy_Warehouse");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!代码重复!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                //保存
                //保存完毕后处理
                if (HItemID == 0)
@@ -412,6 +508,19 @@
                else { 
                    //若MAINDI重复则重新获取
                    oCN.BeginTran();
                    //已审核不允许修改
                    DataSet dss;
                    dss = oCN.RunProcReturn("select * from Gy_Warehouse where HItemID=" + HItemID, "Gy_Warehouse");
                    //判断是否可编辑
                    if (dss.Tables[0].Rows[0]["HCheckEmp"].ToString() != "")
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "此单据状态已经审核,不允许修改!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //主表
                    oCN.RunProc("Update Gy_Warehouse set " +
                        " HNumber='" + HNumber + "'" +
@@ -1215,5 +1324,35 @@
        }
        #endregion
        #region 递归生成树状结构
        /// <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();
                        tbjson.Number = dt.Rows[i]["HNumber"].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
    }
}