|
@@ -44,7 +44,7 @@ namespace qdr.app.studiou.orders2printpack
|
|
|
if (dlgSaveXls.ShowDialog(this) == DialogResult.OK)
|
|
if (dlgSaveXls.ShowDialog(this) == DialogResult.OK)
|
|
|
{
|
|
{
|
|
|
_xlsPath = dlgSaveXls.FileName;
|
|
_xlsPath = dlgSaveXls.FileName;
|
|
|
- tbXslxPath.Text = _csvPath;
|
|
|
|
|
|
|
+ tbXslxPath.Text = _xlsPath;
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -71,7 +71,9 @@ namespace qdr.app.studiou.orders2printpack
|
|
|
|
|
|
|
|
private DataTable ProcessData(DataTable data)
|
|
private DataTable ProcessData(DataTable data)
|
|
|
{
|
|
{
|
|
|
- //LabelAggegationDataExpression
|
|
|
|
|
|
|
+ // Aggregate data first
|
|
|
|
|
+ data = AggregateData(data);
|
|
|
|
|
+
|
|
|
var expressionParts = AppSettings.Default.LabelAggegationDataExpression.Split('=');
|
|
var expressionParts = AppSettings.Default.LabelAggegationDataExpression.Split('=');
|
|
|
var expressionColumnName = expressionParts[0];
|
|
var expressionColumnName = expressionParts[0];
|
|
|
var expressionValue = expressionParts[1];
|
|
var expressionValue = expressionParts[1];
|
|
@@ -100,7 +102,57 @@ namespace qdr.app.studiou.orders2printpack
|
|
|
return result;
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Aggregates order data by grouping order numbers, product categories, and product variant types,
|
|
|
|
|
+ /// then summing the quantities for each group.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="data">Input DataTable containing order details</param>
|
|
|
|
|
+ /// <returns>Aggregated DataTable with columns: order_no, prod_cat, prod_var_type, qty (sum)</returns>
|
|
|
|
|
+ private DataTable AggregateData(DataTable data)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (data == null)
|
|
|
|
|
+ throw new ArgumentNullException(nameof(data));
|
|
|
|
|
+
|
|
|
|
|
+ // Create result DataTable with appropriate columns
|
|
|
|
|
+ DataTable result = new DataTable();
|
|
|
|
|
+ result.Columns.Add("order_no", typeof(string));
|
|
|
|
|
+ result.Columns.Add("prod_cat", typeof(string));
|
|
|
|
|
+ result.Columns.Add("prod_var_type", typeof(string));
|
|
|
|
|
+ result.Columns.Add("qty", typeof(string));
|
|
|
|
|
+
|
|
|
|
|
+ // Group and aggregate using LINQ
|
|
|
|
|
+ var aggregatedData = data.AsEnumerable()
|
|
|
|
|
+ .GroupBy(row => new
|
|
|
|
|
+ {
|
|
|
|
|
+ OrderNo = row.Field<string>("order_no"),
|
|
|
|
|
+ ProdCat = row.Field<string>("prod_cat"),
|
|
|
|
|
+ ProdVarType = row.Field<string>("prod_var_type")
|
|
|
|
|
+ })
|
|
|
|
|
+ .Select(group => new
|
|
|
|
|
+ {
|
|
|
|
|
+ group.Key.OrderNo,
|
|
|
|
|
+ group.Key.ProdCat,
|
|
|
|
|
+ group.Key.ProdVarType,
|
|
|
|
|
+ TotalQty = group.Sum(row => int.Parse(row.Field<string>("qty"))).ToString()
|
|
|
|
|
+ })
|
|
|
|
|
+ .OrderBy(x => x.OrderNo)
|
|
|
|
|
+ .ThenBy(x => x.ProdCat)
|
|
|
|
|
+ .ThenBy(x => x.ProdVarType);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // Populate result DataTable
|
|
|
|
|
+ foreach (var item in aggregatedData)
|
|
|
|
|
+ {
|
|
|
|
|
+ result.Rows.Add(
|
|
|
|
|
+ item.OrderNo,
|
|
|
|
|
+ item.ProdCat,
|
|
|
|
|
+ item.ProdVarType,
|
|
|
|
|
+ int.Parse(item.TotalQty)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
private void butConfig_Click(object sender, EventArgs e)
|
|
private void butConfig_Click(object sender, EventArgs e)
|