数据库表记录如:检测时间 库房名 监测点名 温度值
2010年8月25日14:51:01 1号库房 1号点 27.35
2010年8月25日14:51:01 13号库房 1号点 27.35
2010年8月25日14:51:01 13号库房 2号点 27.35
2010年8月25日14:51:01 13号库房 3号点 27.35
2010年8月25日14:51:01 21号库房 2号点 27.35要求:按时间分组,每组内按库房名和监测点名中的首数字进行排序,难啊⊙﹏⊙b汗,有知道怎么用linq方式实现的本人不胜感激涕零!
2010年8月25日14:51:01 1号库房 1号点 27.35
2010年8月25日14:51:01 13号库房 1号点 27.35
2010年8月25日14:51:01 13号库房 2号点 27.35
2010年8月25日14:51:01 13号库房 3号点 27.35
2010年8月25日14:51:01 21号库房 2号点 27.35要求:按时间分组,每组内按库房名和监测点名中的首数字进行排序,难啊⊙﹏⊙b汗,有知道怎么用linq方式实现的本人不胜感激涕零!
解决方案 »
- C# textbox 多行模式下 文本换行问题
- 突发奇想,可以通过编写程序去检验图片是否PS过吗?
- 请教 C# 从FTP服务器下载文件 为何报错?
- 怎么把网页中的{Product id="1" ClassId="3"}替换成Product(1,3),请各位大侠出售相助
- 使用 TcpClient 传输多张图片的问题
- 打开一个word文档,插入一个字符串,指定大小,指定是否居中等等信息
- 如何激活按值封送的对象(MBV)
- 在线跪求.net2005序列号 百分送上 可以在加 在线等
- C#如何处理由于死锁被自动Kill掉的事务?
- WinFrm中的窗体怎样不让其外观(Button,GridView的控件)不因为Windous的桌面的主题的改变而改变 (我在Windows经典主题下做的窗体到其他主
- 未将对象引用设置到对象的实例
- 请高人帮忙解释下一下代码
{
public DateTime CheckTime { get; set; }
public string StoreHouse { get; set; }
public string Position { get; set; }
public float Value { get; set; }
}
static void Main(string[] args)
{
List<Record> rList = new List<Record>
{
new Record{CheckTime=new DateTime(2010,8,25,14,51,01),StoreHouse="1号库房",Position="1号点",Value=27.35f},
new Record{CheckTime=new DateTime(2010,8,25,14,51,02),StoreHouse="13号库房",Position="1号点",Value=27.35f},
new Record{CheckTime=new DateTime(2010,8,25,14,51,02),StoreHouse="13号库房",Position="2号点",Value=27.35f},
new Record{CheckTime=new DateTime(2010,8,25,14,51,03),StoreHouse="21",Position="1号点",Value=27.35f},
new Record{CheckTime=new DateTime(2010,8,25,14,51,03),StoreHouse="13号库房",Position="1号点",Value=27.35f} };
var groups = from g in rList group g by g.CheckTime; foreach (var g in groups)
{
var orderVal = from r in g orderby r.StoreHouse[0] ascending orderby r.Position[0] ascending select r; foreach (Record r in orderVal)
{
Console.WriteLine("time={0},storehouse={1},postion={2}", r.CheckTime, r.StoreHouse, r.Position);
}
} }
dots.Add(new Dot { dt=DateTime.Now, Father="1号",Name="1号点",Value=12.121f});
dots.Add(new Dot { dt = new DateTime(2010,2,3,21,21,12), Father = "2号", Name = "2号点", Value = 12.121f });
dots.Add(new Dot { dt = new DateTime(2010, 2, 3, 1, 1, 4), Father = "3号", Name = "3号点", Value = 12.121f });
dots.Add(new Dot { dt = new DateTime(2010, 3, 3, 23, 2, 3), Father = "10号", Name = "10号点", Value = 12.121f });
dots.Add(new Dot { dt = new DateTime(2010, 4, 1, 21, 21, 6), Father = "11号", Name = "11号点", Value = 12.121f });
dots.Add(new Dot { dt = new DateTime(2010, 1, 2, 8, 22, 8), Father = "12号", Name = "12号点", Value = 12.121f });
dots.Add(new Dot { dt = new DateTime(2010, 2, 12, 9, 3, 12), Father = "20号", Name = "20号点", Value = 12.121f});
dots.Add(new Dot { dt = new DateTime(2010, 7, 13, 11, 6, 11), Father = "21号", Name = "21号点", Value = 12.121f });
dots.Add(new Dot { dt = DateTime.Now, Father = "21号", Name = "21号点", Value = 12.121f });
dots.Add(new Dot { dt = DateTime.Now, Father = "2号", Name = "2号点", Value = 12.121f});
dots.Add(new Dot { dt = DateTime.Now, Father = "10号", Name = "10号点", Value = 12.121f });
dots.Add(new Dot { dt = DateTime.Now, Father = "11号", Name = "11号点", Value = 12.121f });
//时间分组
var ds = from d in dots group d by d.dt.ToString();
DataTable table = new DataTable();
table.Columns.Add("1");
table.Columns.Add("2");
table.Columns.Add("3");
table.Columns.Add("4");
foreach (var g in ds)
{
//因为每个Father名称都以数字开始命名,故(ˇˍˇ) 想按数字大小排序,而非按字符串"数字"大小排序。应该怎么实现?
var ds2 = from d2 in g orderby d2.Father.Substring(0,2) orderby d2.Name select d2; foreach (var d in ds2)
{
table.Rows.Add(new object[] {d.dt,d.Father,d.Name,d.Value });
}
}
dataGridView1.DataSource = table.DefaultView;
dots.Add(new Dot { dt=DateTime.Now, Father="1号",Name="1号点",Value=12.121f});
dots.Add(new Dot { dt = new DateTime(2010,2,3,21,21,12), Father = "2号", Name = "2号点", Value = 12.121f });
dots.Add(new Dot { dt = new DateTime(2010, 2, 3, 1, 1, 4), Father = "3号", Name = "3号点", Value = 12.121f });
dots.Add(new Dot { dt = new DateTime(2010, 3, 3, 23, 2, 3), Father = "10号", Name = "10号点", Value = 12.121f });
dots.Add(new Dot { dt = new DateTime(2010, 4, 1, 21, 21, 6), Father = "11号", Name = "11号点", Value = 12.121f });
dots.Add(new Dot { dt = new DateTime(2010, 1, 2, 8, 22, 8), Father = "12号", Name = "12号点", Value = 12.121f });
dots.Add(new Dot { dt = new DateTime(2010, 2, 12, 9, 3, 12), Father = "20号", Name = "20号点", Value = 12.121f});
dots.Add(new Dot { dt = new DateTime(2010, 7, 13, 11, 6, 11), Father = "21号", Name = "21号点", Value = 12.121f });
dots.Add(new Dot { dt = DateTime.Now, Father = "21号", Name = "21号点", Value = 12.121f });
dots.Add(new Dot { dt = DateTime.Now, Father = "2号", Name = "2号点", Value = 12.121f});
dots.Add(new Dot { dt = DateTime.Now, Father = "10号", Name = "10号点", Value = 12.121f });
dots.Add(new Dot { dt = DateTime.Now, Father = "11号", Name = "11号点", Value = 12.121f });
//时间分组
var ds = from d in dots group d by d.dt.ToString();
DataTable table = new DataTable();
table.Columns.Add("1");
table.Columns.Add("2");
table.Columns.Add("3");
table.Columns.Add("4");
foreach (var g in ds)
{
//因为每个Father名称都以数字开始命名,故(ˇˍˇ) 想按数字大小排序,而非按字符串"数字"大小排序。应该怎么实现?
var ds2 = from d2 in g orderby d2.Father.Substring(0,2) orderby d2.Name select d2; foreach (var d in ds2)
{
table.Rows.Add(new object[] {d.dt,d.Father,d.Name,d.Value });
}
}
dataGridView1.DataSource = table.DefaultView;