|
|
@@ -42,6 +42,7 @@ namespace HKCardManager.UserPages |
|
|
|
|
|
|
|
private void ExportDataToExcel(DataGridView TableName, string FileName) |
|
|
|
{ |
|
|
|
var d = TableName.DataSource as List<ReportCountDto>; |
|
|
|
SaveFileDialog saveFileDialog = new SaveFileDialog(); |
|
|
|
saveFileDialog.Title = "导出Excel文件"; //设置文件标题 |
|
|
|
saveFileDialog.Filter = "Microsoft Office Excel 工作簿(*.xls)|*.xls"; //设置文件类型 |
|
|
@@ -77,7 +78,7 @@ namespace HKCardManager.UserPages |
|
|
|
} |
|
|
|
} |
|
|
|
sw.WriteLine(strHeader); |
|
|
|
for (int i = 0; i < TableName.Rows.Count; i++) |
|
|
|
for (int i = 0; i < TableName.Rows.Count+1; i++) |
|
|
|
{ |
|
|
|
RowRead++; |
|
|
|
Percent = (int)(100 * RowRead / TotalCount); |
|
|
@@ -85,13 +86,46 @@ namespace HKCardManager.UserPages |
|
|
|
string strData = string.Empty; |
|
|
|
for (int j = 0; j < TableName.Columns.Count; j++) |
|
|
|
{ |
|
|
|
string? res = TableName.Rows[i].Cells[j].Value?.ToString(); |
|
|
|
if (TableName.Columns[j].Visible) |
|
|
|
if (i == TableName.Rows.Count - 1) |
|
|
|
{ |
|
|
|
if (j > 0 && !string.IsNullOrEmpty(strData)) strData += "\t"; |
|
|
|
strData += string.IsNullOrEmpty(res) ? "" : res; |
|
|
|
if (TableName.Columns[j].Visible && TableName.Columns[j].Name == "早上消费金额") |
|
|
|
{ |
|
|
|
if (j > 0 && !string.IsNullOrEmpty(strData)) strData += "\t"; |
|
|
|
strData += d.Sum(t => t.AM); |
|
|
|
} |
|
|
|
else if (TableName.Columns[j].Visible && TableName.Columns[j].Name == "中午消费金额") |
|
|
|
{ |
|
|
|
if (j > 0 && !string.IsNullOrEmpty(strData)) strData += "\t"; |
|
|
|
strData += d.Sum(t => t.PM); |
|
|
|
} |
|
|
|
else if (TableName.Columns[j].Visible && TableName.Columns[j].Name == "晚上消费金额") |
|
|
|
{ |
|
|
|
if (j > 0 && !string.IsNullOrEmpty(strData)) strData += "\t"; |
|
|
|
strData += d.Sum(t => t.AT); |
|
|
|
} |
|
|
|
else if (TableName.Columns[j].Visible && TableName.Columns[j].Name == "金额总计") |
|
|
|
{ |
|
|
|
if (j > 0 && !string.IsNullOrEmpty(strData)) strData += "\t"; |
|
|
|
strData += d.Sum(t => t.Total); |
|
|
|
} |
|
|
|
else if(TableName.Columns[j].Visible) |
|
|
|
{ |
|
|
|
if (j > 0 && !string.IsNullOrEmpty(strData)) strData += "\t"; |
|
|
|
strData += "-"; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (i <= TableName.Rows.Count+1 - 2) |
|
|
|
{ |
|
|
|
string? res = TableName.Rows[i].Cells[j].Value?.ToString(); |
|
|
|
if (TableName.Columns[j].Visible) |
|
|
|
{ |
|
|
|
if (j > 0 && !string.IsNullOrEmpty(strData)) strData += "\t"; |
|
|
|
strData += string.IsNullOrEmpty(res) ? "" : res; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
sw.WriteLine(strData); |
|
|
|
} |
|
|
@@ -193,7 +227,10 @@ namespace HKCardManager.UserPages |
|
|
|
try |
|
|
|
{ |
|
|
|
this.Invoke(() => { button2.Enabled = false; }); |
|
|
|
dataGridView1.DataSource = reportCountDtos; |
|
|
|
ExportDataToExcel(dataGridView1, this.Tag.ToString()); |
|
|
|
var data = reportCountDtos.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList(); |
|
|
|
dataGridView1.DataSource = data; |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|