diff --git a/SYS.Common/App.config b/SYS.Common/App.config index b3cccb0d03169914fc9f5ab89af067139aab2277..44ece1bd0778b3832aaa6cd5fa99a1677c5b7f90 100644 --- a/SYS.Common/App.config +++ b/SYS.Common/App.config @@ -24,12 +24,24 @@ - + + + + + + + + + + + + + diff --git a/SYS.Common/SYS.Common.csproj b/SYS.Common/SYS.Common.csproj index fc3ece3ced6e26873bc3aa275e3e76230373edda..66d4757d4cd8415b33651ebef54a17e1689add66 100644 --- a/SYS.Common/SYS.Common.csproj +++ b/SYS.Common/SYS.Common.csproj @@ -43,50 +43,109 @@ + + ..\packages\BouncyCastle.Cryptography.2.2.1\lib\net461\BouncyCastle.Cryptography.dll + + + ..\packages\Enums.NET.4.0.1\lib\net45\Enums.NET.dll + + + ..\packages\SharpZipLib.1.3.3\lib\net45\ICSharpCode.SharpZipLib.dll + ..\packages\jvncorelib.1.0.1.7\lib\net461\jvncorelib-fr.dll + + ..\packages\MathNet.Numerics.Signed.4.15.0\lib\net461\MathNet.Numerics.dll + + + ..\packages\Microsoft.IO.RecyclableMemoryStream.2.3.2\lib\net462\Microsoft.IO.RecyclableMemoryStream.dll + False ..\SYS.Library\Newtonsoft.Json.dll + + ..\packages\NPOI.2.6.2\lib\netstandard2.0\NPOI.Core.dll + + + ..\packages\NPOI.2.6.2\lib\netstandard2.0\NPOI.OOXML.dll + + + ..\packages\NPOI.2.6.2\lib\netstandard2.0\NPOI.OpenXml4Net.dll + + + ..\packages\NPOI.2.6.2\lib\netstandard2.0\NPOI.OpenXmlFormats.dll + + + ..\packages\SixLabors.Fonts.1.0.0\lib\netstandard2.0\SixLabors.Fonts.dll + + + ..\packages\SixLabors.ImageSharp.2.1.4\lib\netstandard2.0\SixLabors.ImageSharp.dll + - - ..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + ..\packages\System.Configuration.ConfigurationManager.6.0.0\lib\net461\System.Configuration.ConfigurationManager.dll + - - ..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + - - ..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll - - ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + + ..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Security.AccessControl.6.0.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Cryptography.Xml.6.0.1\lib\net461\System.Security.Cryptography.Xml.dll + + + ..\packages\System.Security.Permissions.6.0.0\lib\net461\System.Security.Permissions.dll + + + ..\packages\System.Security.Principal.Windows.5.0.0\lib\net461\System.Security.Principal.Windows.dll + + + + ..\packages\System.Text.Encoding.CodePages.5.0.0\lib\net461\System.Text.Encoding.CodePages.dll + ..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + + + diff --git a/SYS.Common/Util/ExportHelper.cs b/SYS.Common/Util/ExportHelper.cs new file mode 100644 index 0000000000000000000000000000000000000000..a6fe138b4161c3611dba64c808517186ae88f546 --- /dev/null +++ b/SYS.Common/Util/ExportHelper.cs @@ -0,0 +1,134 @@ +using jvncorelib_fr.EntityLib; +using NPOI.SS.UserModel; +using NPOI.XSSF.UserModel; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SYS.Common +{ + /// + /// 导出助手 + /// + public class ExportHelper + { + /// + /// 导出DataGridView数据到Excel(默认当前页) + /// + /// + /// + /// + public void ExportDataGridViewToExcel(DataGridView dataGridView, string filePath,List ignoreColumns = null) + { + var workbook = new XSSFWorkbook(); // 创建XSSFWorkbook实例 + ISheet sheet = workbook.CreateSheet("Customer List"); // 创建工作表 + + IRow headerRow = sheet.CreateRow(0); // 创建表头行 + // 创建表头 + for (int i = 0; i < dataGridView.Columns.Count; i++) + { + if (!ignoreColumns.Contains(dataGridView.Columns[i].Name)) + { + var cell = headerRow.CreateCell(i); + cell.SetCellValue(dataGridView.Columns[i].HeaderText); + } + } + + // 写入数据行 + int rowIndex = 1; + foreach (DataGridViewRow row in dataGridView.Rows) + { + if (!row.IsNewRow) // 排除未提交的新行 + { + IRow sheetRow = sheet.CreateRow(rowIndex++); + for (int i = 0; i < row.Cells.Count; i++) + { + var cell = sheetRow.CreateCell(i); + var cellValue = row.Cells[i].Value; + if (cellValue != null && !ignoreColumns.Contains(dataGridView.Columns[i].Name)) // 检查空值 + { + if (cellValue is DateTime) + { + cell.SetCellValue(Convert.ToDateTime(row.Cells[i].Value).ToString("yyyy-MM-dd")); + } + else + { + cell.SetCellValue(row.Cells[i].Value.ToString()); + } + } + } + } + } + + // 保存到文件 + using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write)) + { + workbook.Write(fileStream); + } + } + + /// + /// 导出DataGridView数据到Excel(默认全部) + /// + /// + /// + /// + /// + public void ExportDataToExcel(List dataSource, string filePath, List ignoreColumns = null) + { + var workbook = new XSSFWorkbook(); // 创建XSSFWorkbook实例 + ISheet sheet = workbook.CreateSheet("Customer List"); // 创建工作表 + + IRow headerRow = sheet.CreateRow(0); // 创建表头行 + + // 使用反射获取数据类型的属性,这些属性将用作列名 + var properties = typeof(T).GetProperties(); + + if (!ignoreColumns.IsNullOrEmpty()) + { + properties = properties.Where(prop => !ignoreColumns.Contains(prop.Name)).ToArray(); + } + + // 创建表头 + for (int i = 0; i < properties.Length; i++) + { + var cell = headerRow.CreateCell(i); + cell.SetCellValue(properties[i].Name); + } + + // 写入数据行 + int rowIndex = 1; + foreach (var item in dataSource) + { + IRow sheetRow = sheet.CreateRow(rowIndex++); + for (int i = 0; i < properties.Length; i++) + { + var cell = sheetRow.CreateCell(i); + var value = properties[i].GetValue(item); + + if (value != null) + { + if (value is DateTime) + { + cell.SetCellValue(((DateTime)value).ToString("yyyy-MM-dd")); + } + else + { + cell.SetCellValue(value.ToString()); + } + } + } + } + + // 保存到文件 + using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write)) + { + workbook.Write(fileStream); + } + } + } +} diff --git a/SYS.Common/packages.config b/SYS.Common/packages.config index 86b3d1080927d9b98161da0498d8801480f5a89d..79fadf1b2fd6d26f0ef16325abe5b5e4e862a32b 100644 --- a/SYS.Common/packages.config +++ b/SYS.Common/packages.config @@ -1,7 +1,24 @@  + + + + - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SYS.FormUI/App.config b/SYS.FormUI/App.config index d1d1b2948befaac397e7eabef6c9dabc999fd289..0491153fc7c88c775902d6ef64f9afac0b3e3af7 100644 --- a/SYS.FormUI/App.config +++ b/SYS.FormUI/App.config @@ -33,12 +33,24 @@ - + + + + + + + + + + + + + diff --git a/SYS.FormUI/AppFunction/FrmCustoManager.Designer.cs b/SYS.FormUI/AppFunction/FrmCustoManager.Designer.cs index 071cb197be67fef7af683193d28be42b35f751e0..6d39610e7befc7aa047117da76a1deb4c82c5d5f 100644 --- a/SYS.FormUI/AppFunction/FrmCustoManager.Designer.cs +++ b/SYS.FormUI/AppFunction/FrmCustoManager.Designer.cs @@ -60,6 +60,7 @@ this.label3 = new System.Windows.Forms.Label(); this.btnPg = new Sunny.UI.UIPagination(); this.uiLine1 = new Sunny.UI.UILine(); + this.cbExportAll = new Sunny.UI.UICheckBox(); ((System.ComponentModel.ISupportInitialize)(this.dgvCustomerList)).BeginInit(); this.cmsCustoManager.SuspendLayout(); this.uiGroupBox1.SuspendLayout(); @@ -387,7 +388,7 @@ this.btnPg.Name = "btnPg"; this.btnPg.PageSize = 15; this.btnPg.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None; - this.btnPg.Size = new System.Drawing.Size(782, 34); + this.btnPg.Size = new System.Drawing.Size(677, 34); this.btnPg.Style = Sunny.UI.UIStyle.Custom; this.btnPg.TabIndex = 121; this.btnPg.Text = null; @@ -405,12 +406,26 @@ this.uiLine1.TabIndex = 123; this.uiLine1.Text = "右键可复制客户编号"; // + // cbExportAll + // + this.cbExportAll.Cursor = System.Windows.Forms.Cursors.Hand; + this.cbExportAll.Font = new System.Drawing.Font("微软雅黑", 12F); + this.cbExportAll.Location = new System.Drawing.Point(687, 533); + this.cbExportAll.MinimumSize = new System.Drawing.Size(1, 1); + this.cbExportAll.Name = "cbExportAll"; + this.cbExportAll.Padding = new System.Windows.Forms.Padding(22, 0, 0, 0); + this.cbExportAll.Size = new System.Drawing.Size(98, 29); + this.cbExportAll.Style = Sunny.UI.UIStyle.Custom; + this.cbExportAll.TabIndex = 124; + this.cbExportAll.Text = "导出全部"; + // // FrmCustoManager // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255))))); this.ClientSize = new System.Drawing.Size(1005, 623); this.ControlBox = false; + this.Controls.Add(this.cbExportAll); this.Controls.Add(this.uiLine1); this.Controls.Add(this.btnPg); this.Controls.Add(this.uiGroupBox1); @@ -462,5 +477,6 @@ private Sunny.UI.UIContextMenuStrip cmsCustoManager; private System.Windows.Forms.ToolStripMenuItem tsmiCustoNo; private Sunny.UI.UILine uiLine1; + private Sunny.UI.UICheckBox cbExportAll; } } \ No newline at end of file diff --git a/SYS.FormUI/AppFunction/FrmCustoManager.cs b/SYS.FormUI/AppFunction/FrmCustoManager.cs index d547e99b39e192775eba788e6e1c472a7bd50f22..f2e7e994cd4539409b73bc316a803e8cde4b7eef 100644 --- a/SYS.FormUI/AppFunction/FrmCustoManager.cs +++ b/SYS.FormUI/AppFunction/FrmCustoManager.cs @@ -188,67 +188,55 @@ namespace SYS.FormUI #region 导出事件方法 private void picLoadOut_Click_1(object sender, EventArgs e) { - //#region 导出信息保存为Excel表 - //bool tf = UIMessageBox.Show("导出信息为敏感操作,确定要继续导出吗?(此步操作将写入操作日志)", "信息提醒",UIStyle.Orange,UIMessageBoxButtons.OKCancel); - //if (!tf) - //{ + // 调用之前定义的导出方法 + ExportHelper exportHelper = new ExportHelper(); + SaveFileDialog saveFileDialog = new SaveFileDialog(); + // 设置保存对话框的属性 + saveFileDialog.Filter = "2003~2007工作表*.xls|*.xls|2010及以上版本工作表*.xlsx|*.xlsx"; + saveFileDialog.Title = cbExportAll.Checked ? "导出Excel文件(导出全部)" : "导出Excel文件(导出当前页)"; + saveFileDialog.FileName = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + "客户列表"; // 默认文件名 + saveFileDialog.CheckPathExists = true; // 检查目录是否存在 - // //Response.ContentEncoding = System.Text.Encoding.UTF8; - // string fileName = ""; - // string saveFileName = ""; - // //fileName.Charset = "GB2312"; - // SaveFileDialog saveDialog = new SaveFileDialog(); - // //saveDialog.DefaultExt = "xls"; - // saveDialog.FileName = fileName; - // saveDialog.Filter = "2003~2007工作表*.xls|*.xls|2010及以上版本工作表*.xlsx|*.xlsx"; - // saveDialog.ShowDialog(); - // saveFileName = saveDialog.FileName; - // if (saveFileName.IndexOf(":") < 0) return; - // Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); - // if (xlApp == null) - // { - // UIMessageBox.Show("无法创建Excel对象,您的电脑可能未安装Excel!", "来自T仔的提醒",UIStyle.Red); - // return; - // } - // Microsoft.Office.Interop.Excel.Workbooks workbooks = xlApp.Workbooks; - // Microsoft.Office.Interop.Excel.Workbook workbook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet); - // Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1]; - // for (int i = 0; i < this.dgvCustomerList.Columns.Count; i++) - // { - // xlApp.Cells[1, i + 1] = dgvCustomerList.Columns[i].HeaderText; - // } - // for (int i = 0; i < dgvCustomerList.Rows.Count; i++)//添加每一项 - // { - // for (int j = 0; j < dgvCustomerList.Columns.Count; j++) - // { - // xlApp.Cells[i + 2, j + 1] = dgvCustomerList.Rows[i].Cells[j].Value.ToString(); - // } - // } - // System.Windows.Forms.Application.DoEvents(); - // worksheet.Columns.EntireColumn.AutoFit();//列宽自适应 - // UIMessageBox.Show(fileName + "信息导出成功", "来自T仔提示",UIStyle.Green, UIMessageBoxButtons.OK); - // #region 获取添加操作日志所需的信息 - // RecordHelper.Record(LoginInfo.WorkerClub + LoginInfo.WorkerName + LoginInfo.WorkerPosition + LoginInfo.WorkerName + "于" + DateTime.Now + "导出了" + "后台用户信息!", 3); - // #endregion - - // System.Diagnostics.Process.Start("Explorer.exe", saveFileName); - // if (saveFileName != "") - // { - // try - // { - // workbook.Saved = true; - // workbook.SaveCopyAs(saveFileName); //fileSaved = true; - // } - // catch (Exception ex) - // {//fileSaved = false; - // UIMessageBox.Show("导出文件时出错,文件可能正被打开!\n" + ex.Message); - // return; - // } - // } - // xlApp.Quit(); - // GC.Collect(); - //} - //#endregion + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + // 用户确认保存,获取选择的文件路径 + string filePath = saveFileDialog.FileName; + + try + { + if (cbExportAll.Checked) + { + dic = new Dictionary() + { + { "pageIndex",null}, + { "pageSize",null} + }; + ResponseMsg response = HttpHelper.Request("Custo/SelectCustoAll", null, dic); + if (response.statusCode != 200) + { + UIMessageBox.ShowError("SelectCustoAll+接口服务异常,请提交Issue或尝试更新版本!"); + return; + } + OSelectCustoAllDto custos = HttpHelper.JsonToModel(response.message); + exportHelper.ExportDataToExcel(custos.listSource, filePath, new List { "CustoSex", "PassportType", "CustoID", "CustoType", "delete_mk", "datains_usr", "datains_date", "datachg_usr", "datachg_date" }); + } + else + { + exportHelper.ExportDataGridViewToExcel(dgvCustomerList, filePath, new List { "Column1", "Column2", "Column3", "Column4" }); + } + UIMessageBox.Show("导出成功!", "信息", UIStyle.Blue, UIMessageBoxButtons.OK); + System.Diagnostics.Process.Start("Explorer.exe", filePath); + #region 获取添加操作日志所需的信息 + RecordHelper.Record(LoginInfo.WorkerClub + LoginInfo.WorkerName + LoginInfo.WorkerPosition + LoginInfo.WorkerName + "于" + DateTime.Now + "导出了" + "后台用户信息!", 3); + #endregion + } + catch (Exception ex) + { + // 处理可能发生的任何错误 + UIMessageBox.Show($"导出失败: {ex.Message}", "错误", UIStyle.Red, UIMessageBoxButtons.OK); + } + } + // 如果用户取消了保存,则不执行任何操作 } #endregion diff --git a/SYS.FormUI/SYS.FormUI.csproj b/SYS.FormUI/SYS.FormUI.csproj index 686cfc7306eea1ab5379d3a51b8160af87d8f4b9..20bb4678387bdcc7cba8eea28eb183212b6a8e4d 100644 --- a/SYS.FormUI/SYS.FormUI.csproj +++ b/SYS.FormUI/SYS.FormUI.csproj @@ -102,23 +102,43 @@ ..\packages\SunnyUI.Common.3.0.6\lib\net462\SunnyUI.Common.dll - - ..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + ..\packages\System.Configuration.ConfigurationManager.6.0.0\lib\net461\System.Configuration.ConfigurationManager.dll + + - - ..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + - - ..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll + + + + + ..\packages\System.Security.AccessControl.6.0.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Permissions.6.0.0\lib\net461\System.Security.Permissions.dll + + + ..\packages\System.Security.Principal.Windows.5.0.0\lib\net461\System.Security.Principal.Windows.dll - - ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Text.Encoding.CodePages.5.0.0\lib\net461\System.Text.Encoding.CodePages.dll ..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll @@ -137,6 +157,7 @@ + diff --git a/SYS.FormUI/packages.config b/SYS.FormUI/packages.config index d596ccdcfc6a304cc2f36d9182a9d46d2cf4deab..fe1e609ff050aa9969cad97e23a32f9365f25caf 100644 --- a/SYS.FormUI/packages.config +++ b/SYS.FormUI/packages.config @@ -6,10 +6,15 @@ - - - - + + + + + + + + + \ No newline at end of file diff --git a/topsky-hotel-manager-system-web-api b/topsky-hotel-manager-system-web-api index edca4ff510e2351cdee1a3e35a5e37c7f9d7f27f..ee21dcd688014213aba436d745136b3ae1449855 160000 --- a/topsky-hotel-manager-system-web-api +++ b/topsky-hotel-manager-system-web-api @@ -1 +1 @@ -Subproject commit edca4ff510e2351cdee1a3e35a5e37c7f9d7f27f +Subproject commit ee21dcd688014213aba436d745136b3ae1449855