a 3
b 5
c 9
d 1
b 7上边中有相同的b,合并后效果
a 3
b 12
c 9
d 1 /*List<DataClass.jx_so> listk = new List<DataClass.jx_so>(); List<string> listL = new List<string>();
List<string> listL2 = new List<string>();
for (int k = 0; k < listk.Count; k++)
{
//if (listL.IndexOf(listk[k]) == -1)
// listL.Add();
}
*/求高人帮忙解决一下!
b 5
c 9
d 1
b 7上边中有相同的b,合并后效果
a 3
b 12
c 9
d 1 /*List<DataClass.jx_so> listk = new List<DataClass.jx_so>(); List<string> listL = new List<string>();
List<string> listL2 = new List<string>();
for (int k = 0; k < listk.Count; k++)
{
//if (listL.IndexOf(listk[k]) == -1)
// listL.Add();
}
*/求高人帮忙解决一下!
{
var qwlist = from wp in listk
group wp by wp.Part_no into g
let sum = g.Sum(s => s.Qty)
select new
{
Part_no = g.Key,
Model=g.Key,
Color=g.Key,
ysum = sum
};
foreach (var pq in qwlist)
{
Response.Write(pq.Model+"-"+pq.Color + " " + pq.ysum.ToString());
//Console.WriteLine(pq.x + " " + pq.ysum.ToString());
}
我response.write出的,model,color这些参数都一样,都是part_no,怎么写可以多加参数进去
group wp by wp.x into g
let sum = g.Sum(s => s.y)
select new
{
x = g.Key,
x1 = g.Key,
x2 = g.Key,
ysum = sum
};
foreach (var pq in qwlist)
{
Console.WriteLine(pq.x + " " + pq.x1 + " " + pq.x2 + " " + pq.ysum.ToString());
}
public jx_so(string x, int y,string A,string B,string C) : this()
{
X = x;
Y = y;
A=a;
B=B;
C=c;
}里边的参数多了好多,但还是以x为分组,以这个为准合并
插入时候不会重复的
/// <summary>
/// 插入数据
/// </summary>
/// <param name="name"></param>
/// <param name="number"></param>
/// <res></res>
private void AddData(string name, int number)
{
if (mydata.ContainsKey(name)) {
mydata[name] += number;
} else {
mydata[name] = number;
}
}
/// <summary>
/// 申明字典
/// </summary>
/// <res></res>
Dictionary<string, int> mydata = new Dictionary<string, int>();
/// <summary>
/// 遍历字典
/// </summary>
/// <res></res>
private void ForData()
{
foreach (KeyValuePair<string, int> subdata in mydata) {
string a = subdata.Key;
//键值 如你的abcde
int b = subdata.Value;
//数值总数
}
}
我用您的方法,结果把各各参数给加起来了。
变成了 00010001 本本本本。
里面的int 你可以改成1个自己写的class类嘛 那个只是1个简单的作品
/// 声明一个产品类,用来存储多个单子合并后的产品记录
/// </summary>
public class Pro
{
private string model, color, change_type, tax, customer_name, part_no;
private double unitprice; public Pro(string Model, string Color, string Part_no, string Change_type, string Tax, string Customer_name, double Unitprice)
{
this.model = Model;
this.color = Color;
this.part_no = Part_no;
this.change_type = Change_type;
this.tax = Tax;
this.customer_name = Customer_name;
this.unitprice = Unitprice;
} public string Model
{
get { return model; }
set { model = value; }
}
public string Color
{
get { return color; }
set { color = value; }
}
public string Change_type
{
get { return change_type; }
set { change_type = value; }
}
public string Tax
{
get { return tax; }
set { tax = value; }
}
public string Customer_name
{
get { return customer_name; }
set { customer_name = value; }
}
public string Part_no
{
get { return part_no; }
set { part_no = value; }
}
}
还是弄的不对。。
所以红色部分会有问题