protected void ButtonViewLog_Click(object sender, EventArgs e) { string from = this.CADateTimeFrom.IsDateEmpty ? string.Empty : this.CADateTimeFrom.SelectedDate.ToString("yyyy-MM-dd"); string to = this.CADateTimeTo.IsDateEmpty ? string.Empty : this.CADateTimeTo.SelectedDate.ToString("yyyy-MM-dd"); DataTable dtLinq = GetQueryListData(from, to); if (null == dtLinq || dtLinq.Rows.Count <= 0) { return; } StringBuilder sb = new StringBuilder(); var ItemCalculate = from dr in dtLinq.AsEnumerable() orderby dr["CostCenter"] ascending group dr by new { CostCenter = dr["CostCenter"], CostCenterName = dr["CostCenterName"], ItemCode = dr["ItemCode"], PackagedRegulation = dr["PackagedRegulation"], Title = dr["Title"], PONumber = dr["PONumber"] } into g select new { CostCenter = g.Key.CostCenter, CostCenterName = g.Key.CostCenterName, ItemCode = g.Key.ItemCode, TotalQuantity = g.Sum(row => Convert.ToDouble(row["TotalQuantity"])), PackagedRegulation = g.Key.PackagedRegulation, TotalPrice = g.Sum(row => Convert.ToDouble(row["TotalPrice"])), PRNO = g.Key.Title, PONO = g.Key.PONumber }; foreach (var item in ItemCalculate) { string sItemCode = item.ItemCode.ToString(); if (sItemCode.StartsWith("X", StringComparison.InvariantCultureIgnoreCase)) { continue; } PurchaseRequest.PaperBagForVendor pbv = new PaperBagForVendor(); string sTotalQuantity = pbv.GetCount(item.PackagedRegulation.ToString(), item.TotalQuantity.ToString()).ToString(); sb.AppendFormat("PRNO: {0} ", item.PRNO); sb.AppendFormat("PONO: {0} ", item.PONO); sb.AppendFormat("TotalPrice: {0} ", item.TotalPrice); sb.AppendFormat("ItemCode: {0} ", item.ItemCode); sb.AppendFormat("TotalQuantity: {0} ", item.TotalQuantity); sb.AppendFormat("CostCenter: {0} ", item.CostCenter); sb.Append("<br /><br />"); } LiteralLog.Text = sb.ToString(); }
/// <summary> /// 得到纸袋所有记录 /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> DataTable GetPaperBagData(string from, string to) { DataTable dtLinq = GetQueryListData(from, to); if (null == dtLinq||dtLinq.Rows.Count<=0) { return null; } DataTable dt = new DataTable(); dt.Columns.Add("CostCenter"); dt.Columns.Add("CostCenterName"); dt.Columns.Add("ItemCode"); dt.Columns.Add("TotalQuantity"); dt.Columns.Add("TotalPrice"); var ItemCalculate = from dr in dtLinq.AsEnumerable() orderby dr["CostCenter"] ascending group dr by new { CostCenter = dr["CostCenter"], CostCenterName = dr["CostCenterName"], ItemCode = dr["ItemCode"], PackagedRegulation = dr["PackagedRegulation"]} into g select new { CostCenter = g.Key.CostCenter, CostCenterName = g.Key.CostCenterName, ItemCode = g.Key.ItemCode, TotalQuantity = g.Sum(row => Convert.ToDouble(row["TotalQuantity"])), PackagedRegulation = g.Key.PackagedRegulation, TotalPrice = g.Sum(row => Convert.ToDouble(row["TotalPrice"])) }; foreach (var item in ItemCalculate) { string sItemCode = item.ItemCode.ToString(); if (sItemCode.StartsWith("X", StringComparison.InvariantCultureIgnoreCase)) { continue; } PurchaseRequest.PaperBagForVendor pbv = new PaperBagForVendor(); string sTotalQuantity= pbv.GetCount(item.PackagedRegulation.ToString(), item.TotalQuantity.ToString()).ToString(); DataRow dr = dt.NewRow(); dr["CostCenter"] = item.CostCenter; dr["CostCenterName"] = item.CostCenterName; dr["ItemCode"] = sItemCode; dr["TotalQuantity"] = sTotalQuantity.ToString(); dr["TotalPrice"] = item.TotalPrice; dt.Rows.Add(dr); } return dt; }