| | |
| | | |
| | | [Route("Gy_Department/LoadTree")] |
| | | [HttpGet] |
| | | public object LoadTree_Json() |
| | | public object LoadTree_Json(string sWhere) |
| | | { |
| | | SQLHelper.ClsCN SubCn = new SQLHelper.ClsCN(); |
| | | string sSql = ""; |
| | | // sSql = "select Name title,code id from province where code=330000 "; |
| | | sSql = "Select HItemID id,HName title,HParentID HParentID,1 HLevel,'true' lazy from Gy_Department"; |
| | | List<Tree_Model> GetRegionList = GetRegion(sSql); |
| | | if (GetRegionList == null) |
| | | //ds = oCN.RunProcReturn("select * from h_v_IF_GroupList " + sWhere, "h_v_IF_GroupList"); |
| | | ds = oCN.RunProcReturn("select * from h_v_DepartmentLoadTree", "h_v_DepartmentLoadTree"); |
| | | if (ds == null || ds.Tables[0].Rows.Count == 0) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "显示失败!原因:" + DBUtility.ClsPub.sExeReturnInfo; |
| | | objJsonResult.Message = "false!"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | else |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.code = "1"; |
| | | objJsonResult.count = 1; |
| | | objJsonResult.Message = "获取成功!"; |
| | | objJsonResult.data = GetRegionList; |
| | | objJsonResult.Message = "Sucess!"; |
| | | objJsonResult.data = ds.Tables[0]; |
| | | return objJsonResult; |
| | | } |
| | | } |
| | | |
| | | public List<Tree_Model> GetRegion(string sSql) |
| | | { |
| | | try |
| | | { |
| | | SqlDataReader reader = GetReader(sSql); |
| | | List<Tree_Model> ModuleList = new List<Tree_Model>(); |
| | | while (reader.Read()) |
| | | { |
| | | ModuleList.Add(new Tree_Model() |
| | | { |
| | | id = Convert.ToInt32(reader["id"]), |
| | | HParentID = Convert.ToInt32(reader["HParentID"]), |
| | | HLevel = Convert.ToInt32(reader["HLevel"]), |
| | | lazy = Convert.ToBoolean(reader["lazy"]), |
| | | title = reader["title"].ToString() |
| | | }); |
| | | } |
| | | reader.Close(); |
| | | return ModuleList; |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | public class Tree_Model |
| | | { |
| | | public long id; |
| | | public string title; |
| | | public string code; |
| | | public long HParentID; |
| | | public string HParentName; |
| | | public long HLevel; |
| | | public bool lazy; |
| | | } |
| | | public static SqlDataReader GetReader(string sql) |
| | | { |
| | | SqlConnection conn = new SqlConnection("Data Source=192.168.0.175;Initial Catalog=HX_LimsSys;User Id=HX_USER,Password=lc@841022;Integrated Security=True"); |
| | | SqlCommand cmd = new SqlCommand(sql, conn); |
| | | try |
| | | { |
| | | conn.Open(); |
| | | SqlDataReader objReader = |
| | | cmd.ExecuteReader(CommandBehavior.CloseConnection); |
| | | return objReader; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | conn.Close(); |
| | | throw ex; |
| | | } |
| | | //finally |
| | | //{ |
| | | // conn.Close(); |
| | | // conn.Dispose(); |
| | | //} |
| | | } |
| | | |
| | | // |
| | | } |