public List <NhomDropDownModel> LayDSNhom() { try { using (ISession session = LOANSessionManager.OpenSession()) { IDbCommand command = new SqlCommand(); command.Connection = session.Connection; command.CommandType = CommandType.StoredProcedure; command.CommandText = "sp_NHOM_LayDSNhom"; DataTable dt = new DataTable(); dt.Load(command.ExecuteReader()); if (dt != null) { if (dt.Rows.Count > 0) { List <NhomDropDownModel> result = new List <NhomDropDownModel>(); foreach (DataRow item in dt.Rows) { NhomDropDownModel nhom = new NhomDropDownModel(); nhom.ID = Convert.ToInt32(item["ID"].ToString()); nhom.Ten = item["Ten"].ToString(); result.Add(nhom); } return(result); } } return(null); } } catch (BusinessException ex) { throw ex; } }
private List <NhomDropDownModel> TaoCayDSNhom(List <NhomDropDownModel> lstData, string maCha, int maNguoiQL) { try { if (lstData == null) { return(null); } List <NhomDropDownModel> lstResult = new List <NhomDropDownModel>(); Stack <NhomDropDownModel> stack = new Stack <NhomDropDownModel>(); List <NhomDropDownModel> lstFind = new List <NhomDropDownModel>(); string maChaTemp = maCha; do { if (stack.Count > 0) { NhomDropDownModel nhom = stack.Pop(); if (nhom != null) { string[] tempArray = nhom.ChuoiMaCha.Split('.'); if (tempArray.Length > 1) { for (int i = 0; i < tempArray.Length - 1; i++) { nhom.Ten = "-" + nhom.Ten; } } lstResult.Add(nhom); maChaTemp = nhom.ChuoiMaCha + "." + nhom.ID; } } lstFind = lstData.FindAll(x => x.ChuoiMaCha.Equals(maChaTemp)); if (lstFind != null) { for (int i = lstFind.Count - 1; i >= 0; i--) { if (lstFind[i].ChuoiMaCha == maCha && lstFind[i].MaNguoiQL != maNguoiQL) { continue; } stack.Push(lstFind[i]); lstData.Remove(lstFind[i]); } } } while (stack.Count > 0); return(lstResult); } catch (BusinessException ex) { throw ex; } }
// Danh sách nhóm duyệt(lấy từ bảng cấu hình) public List <NhomDropDownModel> LayDSDuyetCuaNhanVien(int userId) { try { using (ISession session = LOANSessionManager.OpenSession()) { IDbCommand command = new SqlCommand(); command.Connection = session.Connection; command.CommandType = CommandType.StoredProcedure; command.CommandText = "sp_NHOM_LayDSNhomDuyetChonTheoNhanVien_v2"; command.Parameters.Add(new SqlParameter("@UserID", userId)); DataTable dt = new DataTable(); dt.Load(command.ExecuteReader()); if (dt != null) { if (dt.Rows.Count > 0) { List <NhomDropDownModel> result = new List <NhomDropDownModel>(); List <NhomDropDownModel> resultTemp = new List <NhomDropDownModel>(); foreach (DataRow item in dt.Rows) { NhomDropDownModel nhom = new NhomDropDownModel(); nhom.ID = Convert.ToInt32(item["ID"].ToString()); nhom.Ten = item["Ten"].ToString(); nhom.ChuoiMaCha = item["ChuoiMaCha"].ToString(); nhom.TenQL = item["TenQL"].ToString(); // Nếu nhóm con if (resultTemp.Find(x => nhom.ChuoiMaCha.Contains("." + x.ID.ToString() + ".") || nhom.ChuoiMaCha.EndsWith("." + x.ID.ToString())) != null) { continue; } else { // Nhóm cha resultTemp.RemoveAll(x => x.ChuoiMaCha.Contains("." + nhom.ID.ToString() + ".") || x.ChuoiMaCha.EndsWith("." + nhom.ID.ToString())); resultTemp.Add(nhom); } if (resultTemp.Count > 0) { IDbCommand commandLayDSCon = new SqlCommand(); commandLayDSCon.Connection = session.Connection; commandLayDSCon.CommandType = CommandType.StoredProcedure; commandLayDSCon.CommandText = "sp_NHOM_LayCayNhomCon_v2"; for (int i = 0; i < resultTemp.Count; i++) { commandLayDSCon.Parameters.Clear(); commandLayDSCon.Parameters.Add(new SqlParameter("@parentGroupId", resultTemp[i].ID)); DataTable dt2 = new DataTable(); dt2.Load(commandLayDSCon.ExecuteReader()); if (dt2 != null && dt2.Rows.Count > 0) { List <NhomDropDownModel> lstTemp = new List <NhomDropDownModel>(); foreach (DataRow item2 in dt2.Rows) { NhomDropDownModel nhom2 = new NhomDropDownModel(); nhom2.ID = Convert.ToInt32(item2["ID"].ToString()); nhom2.MaNguoiQL = Convert.ToInt32(item2["MaNguoiQL"].ToString()); nhom2.Ten = item2["Ten"].ToString(); nhom2.ChuoiMaCha = item2["ChuoiMaCha"].ToString(); nhom2.TenQL = item2["TenQL"].ToString(); lstTemp.Add(nhom2); } result.AddRange(TaoCayDSNhom(lstTemp, resultTemp[i].ChuoiMaCha + "." + resultTemp[i].ID.ToString())); } } } } return(result); } } return(null); } } catch (BusinessException ex) { throw ex; } }