SVN-Revision: r527
This commit is contained in:
wyf
2025-04-30 07:57:42 +00:00
parent 929215e0f8
commit 8889e7ab62
+93 -13
View File
@@ -1252,14 +1252,20 @@ namespace Lskj.Control.Model
/// <para>版本:1.0</para>
/// </summary>
/// <param name="control">The control.</param>
public static void ToExcel(this GridControl control, string menuName, bool ismerger = false, string CustomColumKey = "")
public static void ToExcel(this GridControl control, string menuName, bool ismerger = false, string CustomColumKey = "", bool withOutDate = false)
{
if (control == null) return;
SaveFileDialog dialog = new SaveFileDialog();
dialog.Title = "导出";
String suffix = SystemInfo.Instance.IsXlsxFirst ? ".xlsx" : ".xls";
dialog.FileName = menuName + DateTime.Now.ToString(SystemInfo.Instance.ExportFileDateFormat) + suffix;
if (control != null && control.Parent != null && control.Parent.Parent != null && control.Parent.Parent is GridControlEx gcEx && gcEx.ExportNameWithoutDate)
{
dialog.FileName = menuName + suffix;
}
else
{
dialog.FileName = menuName + DateTime.Now.ToString(SystemInfo.Instance.ExportFileDateFormat) + suffix;
}
dialog.Filter = SystemInfo.Instance.IsXlsxFirst ? "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls|PDF文件|*.PDF|RTF文件|*.RTF|HTML文件|*.html" :
"Excel文件(*.xls)|*.xls|Excel文件(*.xlsx)|*.xlsx|PDF文件|*.PDF|RTF文件|*.RTF|HTML文件|*.html";
@@ -1849,6 +1855,37 @@ namespace Lskj.Control.Model
return dataView.ToTable();
}
/// <summary>
/// 获取排序和筛选后的数据源
/// </summary>
/// <param name="view"></param>
/// <returns></returns>
public static DataTable GetFilteredAndSortedDataTable(this BandedGridView view)
{
DataTable dataSource = view.GridControl.DataSourceTable();
string filterCondition = CriteriaToWhereClauseHelper.GetDataSetWhere(view.ActiveFilterCriteria);
string pattern = @"len\(\[([^\]]+)\]\)";
// 使用正则表达式替换
filterCondition = Regex.Replace(filterCondition, pattern, match =>
{
string field = match.Groups[1].Value;
return $"len(Convert([{field}], 'System.String'))";
});
string sortCondition = "";
foreach (GridColumnSortInfo sortInfo in view.SortInfo)
{
if (sortCondition != "")
{
sortCondition += ", ";
}
string sortOrder = sortInfo.SortOrder == ColumnSortOrder.Ascending ? "ASC" : "DESC";
sortCondition += $"{sortInfo.Column.FieldName} {sortOrder}";
}
DataView dataView = new DataView(dataSource);
dataView.RowFilter = filterCondition;
dataView.Sort = sortCondition;
return dataView.ToTable();
}
/// <summary>
/// <para>说明:获取GridControl的DataTable</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-12-05 </para>
@@ -2034,7 +2071,7 @@ namespace Lskj.Control.Model
if (cell.CellType == CellType.Formula)
{
//isImportRows = false;
// dataRow[col.FieldName] = cell.StringCellValue;
// dataRow[col.FieldName] = cell.StringCellValue;
continue;
}
if (cell.CellType == CellType.Numeric && (cell.NumericCellValue + "").StartsWith("-"))
@@ -2602,7 +2639,7 @@ namespace Lskj.Control.Model
public static bool QuickImport(this GridView gridView, ModuleModel SysModel, string parmaryKey, string leftField, string leftValue,List<string> ImportReturnName, List<string> ImportReturnValue, GridControlEx ParentGridEx=null )
public static bool QuickImport(this GridView gridView, ModuleModel SysModel, string parmaryKey, string leftField, string leftValue, List<string> ImportReturnName, List<string> ImportReturnValue, GridControlEx ParentGridEx = null)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Title = "选择导入文件";
@@ -2646,7 +2683,7 @@ namespace Lskj.Control.Model
RegressionMsg.OwnerBand = gridBand;
gridControlEx.GridView.Columns.Add(RegressionMsg);
}
else
else
{
gridControlEx.SetEditColumns(tableColumns, GridCustomColumnStruct.BaseMainGridView + SysModel.FormKey);
gridControlEx.GridView.OptionsBehavior.Editable = false;//禁止编辑
@@ -2667,7 +2704,7 @@ namespace Lskj.Control.Model
}
if (!BaseImpl.HasExistsColumn(SysModel.MenuTable,_importFlag))
if (!BaseImpl.HasExistsColumn(SysModel.MenuTable, _importFlag))
{
BaseImpl.ExecSqlValue(string.Format("alter table {0} add {1} varchar(20) default('0')", SysModel.MenuTable, _importFlag));
}
@@ -2677,7 +2714,7 @@ namespace Lskj.Control.Model
ImportTable = gridControlEx.GridView.ToExcelDataTable(fileName, colFields, true);
if (ImportTable==null&&ImportTable.Rows.Count < 1)
if (ImportTable == null && ImportTable.Rows.Count < 1)
{
MessageBox.Show("没有任何数据可以进行导入", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
@@ -2763,7 +2800,7 @@ namespace Lskj.Control.Model
string colName = "";
int success = 0;
int failed = 0;
List<string> _calcFields = new List<string>();
DataTable dtCalcFields = BaseImpl.GetDataTableResult(string.Format("select name from sys.columns where object_id=object_id('{0}') and is_computed=1", SysModel.MenuTable));
if ((dtCalcFields != null) && (dtCalcFields.Rows.Count > 0))
@@ -2795,7 +2832,7 @@ namespace Lskj.Control.Model
failedData.Columns.Add("import_errormsg");
if (!failedData.Columns.Contains(_importFlag))
failedData.Columns.Add(_importFlag);
for (int i = 0; i < ImportTable.Rows.Count; i++)
{
ImportTable.Rows[i][_importFlag] = "1";
@@ -3018,7 +3055,7 @@ namespace Lskj.Control.Model
SqlHelper.ExecuteNonQuery(ReplaceHelper.ReplaceRowParam(dataRow, ReplaceHelper.ReplaceUserInfo(SysModel.afterimportSql2)));
}
datatb.Clear();
LogUtil.WriteDebug(SysModel.ModeCode, "导入数据", SysModel.MenuText, "数据导入,成功" + success.ToString() + "条,失败" + failed.ToString() + "条");
}
@@ -3051,7 +3088,7 @@ namespace Lskj.Control.Model
/// <param name="dtTable"></param>
/// <param name="currentRow"></param>
/// <param name="key"></param>
private static void setDefaultValue(DataTable dtTable, DataRow currentRow,string _qzKey)
private static void setDefaultValue(DataTable dtTable, DataRow currentRow, string _qzKey)
{
if ((dtTable.Columns.Contains(_qzKey + "operatorid")) && ((string.IsNullOrEmpty(currentRow[_qzKey + "operatorid"] + "") || currentRow[_qzKey + "operatorid"] + "" == "0")))
currentRow[_qzKey + "operatorid"] = ERPInfo.Instance.UserId;
@@ -3649,4 +3686,47 @@ namespace Lskj.Control.Model
// 设置填充模式为实心填充
cellStyle.FillPattern = FillPattern.SolidForeground;
}
cell.CellStyle = cellStyle;
}
// 保存更改回原始文件
using (FileStream file = new FileStream(excelFilePath, FileMode.Create, FileAccess.Write))
{
workbook.Write(file);
}
}
catch (Exception ex)
{
}
}
/// <summary>
/// 是否存在未保存的数据
/// </summary>
/// <param name="control"></param>
/// <returns></returns>
public static bool IsDataNotSaved(this GridControlEx control)
{
DataTable table = control.gridControl.DataSource as DataTable;
foreach (DataRow row in table.Rows)
{
if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Added)
{
return true;
}
}
return false;
}
}
}