using Dapper; using dccdc.Models; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace dccdc.DAL { public class ERPBuMenDal { public List GetAllList(string key) { string sql = "select * from ERPBuMen where 1=1"; if (key != "") { sql += " and bumenname=@key"; } using (IDbConnection conn = CommHelper.GetSqlConnection("OADB")) { return conn.Query(sql, new { key = key }).ToList(); } } public List GetListdir() { string sql = "select * from ERPBuMen where 1=1 and dirid=0"; using (IDbConnection conn = CommHelper.GetSqlConnection("OADB")) { return conn.Query(sql).ToList(); } } public List GetAllChildren(string ksid) { string sql = "select * from ERPBuMen where 1=1"; using (IDbConnection conn = CommHelper.GetSqlConnection("OADB")) { List models = conn.Query(sql).ToList(); List result = new List(); result.Add(ksid); getChildren(ksid, models, ref result); return result; } } private void getChildren(string ksid, List models,ref List result) { List models2 = models.Where(t => t.DirID == ksid).ToList(); foreach (ERPBuMenModel model in models2) { result.Add(model.ID.ToString()); getChildren(model.ID.ToString(), models, ref result); } } public List GetAllChildren2(string ksid) { int ksid2 = Convert.ToInt32(ksid); string sql = "select * from ERPBuMen where 1=1"; using (IDbConnection conn = CommHelper.GetSqlConnection("OADB")) { List models = conn.Query(sql).ToList(); List result = new List(); result.Add(models.Where(t => t.ID == ksid2).FirstOrDefault()); getChildren2(ksid, models, ref result); return result; } } private void getChildren2(string ksid, List models, ref List result) { List models2 = models.Where(t => t.DirID == ksid).ToList(); foreach (ERPBuMenModel model in models2) { result.Add(model); getChildren2(model.ID.ToString(), models, ref result); } } } }