实现这个功能有没有其他办法
public void qudiaoduoyu() { public DataTable dt = new DataTable(); int aa = 0; string row1 = myDataSet.Tables[0].Rows[0]["订单号码"].ToString();//取表的第一行 string row2 = myDataSet.Tables[0].Rows[0]["邮件号"].ToString();//取表的第一行 DataRow[] drr = myDataSet.Tables[0].Select(" 订单号码='"+row1 + "'"); DataRow[] drr1 = myDataSet.Tables[0].Select(" 订单号码='"+row2 + "'"); BLL.kuaidifeiyong mykuaidifeiyong = new BLL.kuaidifeiyong(); DataRow dr = myDataSet.Tables[0].NewRow();//临时新的行 dr["收寄日期"] = drr1[0]["收寄日期"].ToString(); dr["订单号码"] = drr1[0]["订单号码"].ToString(); if (drr1[0]["订单金额"] != null && drr1[0]["订单金额"].ToString() != "") dr["订单金额"] = decimal.Parse(drr1[0]["订单金额"].ToString()); if (drr1[0]["单位"] != null) dr["单位"] = drr1[0]["单位"].ToString(); if (drr1[0]["寄达地"] != null) dr["寄达地"] = drr1[0]["寄达地"].ToString(); if (drr1[0]["省"] != null) dr["省"] = drr1[0]["省"].ToString(); dr["快递公司"] = drr1[0]["快递公司"].ToString(); dr["邮件号"] = drr1[0]["邮件号"].ToString(); dr["重量"] = decimal.Parse(drr1[0]["重量"].ToString()); dr["件数"] = int.Parse(drr1[0]["件数"].ToString()); dr["邮费"] = decimal.Parse(drr1[0]["邮费"].ToString()); dr["备注"] = drr1[0]["备注"].ToString(); if (drr1[0]["省"] != null) dr["我算运费"] = feiyongjisuan(drr1[0]["邮件号"].ToString(), drr1[0]["省"].ToString(), decimal.Parse(drr1[0]["重量"].ToString())); if (drr.Length > 1 && drr[0]["邮件号"].ToString() != "") { aa += 1; drr1 = myDataSet.Tables[0].Select(" 邮件号='-1'"); dr["订单号码"] = drr[0]["订单号码"].ToString(); dr["订单金额"] = decimal.Parse(drr[0]["订单金额"].ToString()); decimal zl = 0; int js = 0; decimal yf = 0; decimal wsyf = 0; foreach (DataRow dr11 in drr) { if (dr["邮件号"].ToString().IndexOf(dr11["邮件号"].ToString()) == -1) dr["邮件号"] = dr["邮件号"] + "," + dr11["邮件号"].ToString(); zl += decimal.Parse(dr11["重量"].ToString()); js += int.Parse(dr11["件数"].ToString()); yf += decimal.Parse(dr11["邮费"].ToString()); wsyf += feiyongjisuan(dr11["邮件号"].ToString(), dr11["省"].ToString(), decimal.Parse(dr11["重量"].ToString())); myDataSet.Tables[0].Rows.Remove(dr11);//清除此类的行 } dr["重量"] = zl; dr["件数"] = js; dr["邮费"] = yf; dr["我算运费"] = wsyf; dr["比例"] = wsyf / decimal.Parse(dr["订单金额"].ToString()); } decimal ddje = 0; if (drr1.Length > 1 && drr1[0]["邮件号"].ToString() != "") { aa += 1; dr["邮件号"] = drr1[0]["邮件号"].ToString(); dr["重量"] = decimal.Parse(drr1[0]["重量"].ToString()); dr["件数"] = int.Parse(drr1[0]["件数"].ToString()); dr["邮费"] = decimal.Parse(drr1[0]["邮费"].ToString()); dr["我算运费"] = feiyongjisuan(drr1[0]["邮件号"].ToString(), drr1[0]["省"].ToString(), decimal.Parse(drr1[0]["重量"].ToString())); foreach (DataRow dr22 in drr1) { if (dr["订单号码"].ToString().IndexOf(dr22["订单号码"].ToString()) == -1) dr["订单号码"] = dr["订单号码"] + "," + dr22["订单号码"].ToString(); ddje += decimal.Parse(dr22["订单金额"].ToString()); myDataSet.Tables[0].Rows.Remove(dr22);//清除此类的行 } dr["订单金额"] = ddje; dr["比例"] = decimal.Parse(dr["我算运费"].ToString()) / decimal.Parse(dr["订单金额"].ToString()); dr["备注"] = "合并"; } if (aa == 0) { myDataSet.Tables[0].Rows.Remove(drr1[0]);//清除此类的行 } myDataSet.Tables[0].Rows.Add(dr);//添加临时新的行数据 qudiaoduoyu(); }
如需要阅读该回复,请登录或注册CSDN!
如需要阅读该回复,请登录或注册CSDN!