110,571
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<string> s = @"001 李四 000 张三
002 王五 001 李四
003 赵六 002 王五
004 孙七 003 赵六
101 小二 100 小一
102 小三 101 小二
201 红太郎 200 灰太狼".Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList();
List<List<string>> list = new List<List<string>>();
while (s.Count > 0)
{
List<string> sublist = new List<string>();
sublist.Add(s[0]);
s.Remove(s[0]);
string s1 = null, s2 = null;
do
{
s1 = s.FirstOrDefault(x => x.Split(' ')[0] == sublist.First().Split(' ')[2]);
if (s1 != null) { sublist = new string[] { s1 }.Concat(sublist).ToList(); s.Remove(s1); }
s2 = s.FirstOrDefault(x => x.Split(' ')[2] == sublist.Last().Split(' ')[0]);
if (s2 != null) { sublist.Add(s2); s.Remove(s2); }
}
while (s1 != null || s2 != null);
list.Add(sublist);
}
foreach (var item in list)
{
Console.WriteLine(item.Last().Split(' ')[0] + " " + item.Last().Split(' ')[1] + " " + item.First().Split(' ')[2] + " " + item.First().Split(' ')[3]);
}
}
}
}
var data = from epf in db.EntProofInfoList
join esr in db.EntSellRelation on epf.Relation equals esr.Relation
where epf.MainID == MainID && esr.IsDel == false && epf.IsDel == false
select esr;
var dataList = data.Where(o => o.BuyerEntMainID == MainID);
if (dataList .Count() != 0)
{
foreach (var item in dataList)
{
var dataValue = data.Where(o => o.BuyerID == item.SellerID);
if (dataValue.Count() != 0)
{
item.SellerEntName = dataValue.FirstOrDefault().SellerEntName;
item.SellerID = dataValue.FirstOrDefault().BuyerID;
item.RelationType = dataValue.FirstOrDefault().RelationType;
}
}
}
var dataList = data.Where(o => o.BuyerEntMainID == MainID);
if (dataList .Count() != 0)
{
foreach (var item in dataList)
{
var dataValue = data.Where(o => o.BuyerID == item.SellerID);
if (dataValue.Count() != 0)
{
item.SellerEntName = dataValue.FirstOrDefault().SellerEntName;
item.SellerID = dataValue.FirstOrDefault().BuyerID;
item.RelationType = dataValue.FirstOrDefault().RelationType;
}
}
}
部分代码是这样的,只能挖到第二层,不能进一步向下挖...