-- 获取当前系统时间 '2024-03-06 09:20:04'
CONVERT ( VARCHAR ( 19 ), GETDATE( ), 120 )
写在Partial部分类里面
具体文档链接点击链接:
新版:后台基础代码扩展实现链接
旧版:后台基础代码扩展实现链接
public override WebResponseContent Update(SaveModel saveModel)
{
//编辑方法保存数据库前处理
UpdateOnExecuting = (Demo_Catalog catalog, object addList, object updateList, List<object> delKeys) =>
{
//如果数据库的分类编号与前端请求的分类编号相同
//并且该记录的主键id和请求的不同说明已存在
//这边也可以用写原生sql解决
repository.DapperContext.ExecuteScalar
("select * from .....")
if (repository.Exists(x => x.CatalogCode == catalog.CatalogCode && x.CatalogId != catalog.CatalogId))
{
return webResponse.Error(CatalogCode + "分类编号已存在");
}
return webResponse.OK();
};
return base.Update(saveModel);
}
public override WebResponseContent Add(SaveModel saveDataModel)
{
// 在保存数据库前的操作,所有数据都验证通过了,这一步执行完就执行数据库保存
AddOnExecuting = (Demo_Catalog catalog, object list) =>
{
if (repository.Exists(x => x.CatalogCode == catalog.CatalogCode))
{
return webResponse.Error("分类编号已存在");
}
return webResponse.OK();
};
return base.Add(saveDataModel);
}
public override PageGridData<Demo_Catalog> GetPageData(PageDataOptions options)
{
//此处是从前台提交的原生的查询条件,这里可以自己过滤
QueryRelativeList = (List<SearchParameters> parameters) =>
{
};
//前端代码
// searchBefore(param) {
// //界面查询前,可以给param.wheres添加查询参数
// //返回false,则不会执行查询
// 前端查询前添加的值(对象也可以 后端用getObject就行) param.value = 1;
// return true;
// },
//后端代码
//获取前端查询前添加的值
if (options.Value.GetInt()==1)
{
Console.WriteLine("1");
}
//2020.08.15
//设置原生查询的sql语句,这里必须返回select * 表所有字段
//(先内部过滤数据,内部调用EF方法FromSqlRaw,自己写的sql注意sql注入的问题),不会影响界面上提交的查询
//查询当前时间的数据
string date = DateTime.Now.AddHours(-10).ToString("yyyy-MM-dd");
QuerySql = $@"select * from Demo_Catalog where createdate>'{date}'";
repository.DapperContext.ex
PageGridData<Demo_Catalog> gridData = new PageGridData<Demo_Catalog>()
{
rows=new List<Demo_Catalog>() { },
total=100
};
//查询当前用户对应的数据
QueryRelativeExpression = (IQueryable<Demo_Catalog> queryable) =>
{
queryable = queryable.Where(x => x.CreateID == UserContext.Current.UserId);
return queryable;
};
return base.GetPageData(options);
}
public override WebResponseContent Export(PageDataOptions pageData)
{
//设置最大导出的数量
Limit = 100000;
//指定导出的字段(2020.05.07)
ExportColumns = x => new { x.CatalogCode, x.CatalogName };
//查询要导出的数据后,在生成excel文件前处理
//list导出的实体,ignore过滤不导出的字段
ExportOnExecuting = (List<Demo_Catalog> list, List<string> ignore) =>
{
list.ForEach(item =>
{
item.CatalogCode = "11";//所有分类编号全是11
});
ignore.Add("Remark");//忽略Remark字段
return webResponse.OK();
};
return base.Export(pageData);
}
///
/// 导入
///
///
///
public override WebResponseContent Import(List<IFormFile> files)
{
//(2020.05.07)
//设置导入的字段(如果指定了上面导出模板的字段,这里配置应该与上面DownLoadTemplate方法里配置一样)
//如果不设置导入的字段DownLoadTemplateColumns,默认显示所有界面上所有可以看到的字段
DownLoadTemplateColumns = x => new { x.SellNo, x.TranNo, x.Remark, x.CreateDate };
///
/// 2022.06.20增加原生excel读取方法(导入时可以自定义读取excel内容)
/// string=当前读取的excel单元格的值
/// ExcelWorksheet=excel对象
/// ExcelRange当前excel单元格对象
/// int=当前读取的第几行
/// int=当前读取的第几列
/// string=返回的值
///
ImportOnReadCellValue = (string value, ExcelWorksheet worksheet, ExcelRange excelRange, int rowIndex, int columnIndex) =>
{
string 表头列名 = worksheet.Cells[1, columnIndex].Value?.ToString();
//这里可以返回处理后的值,值最终写入到model字段上
return value;
};
//导入保存前处理(可以对list设置新的值)
ImportOnExecuting = (List<SellOrder> list) =>
{
//设置webResponse.Code = "-1"会中止后面代码执行,与返回 webResponse.Error()一样,区别在于前端提示的是成功或失败
//webResponse.Code = "-1";
//webResponse.Message = "测试强制返回";
//return webResponse.OK("ok");
return webResponse.OK();
};
//导入后处理(已经写入到数据库了)
ImportOnExecuted = (List<SellOrder> list) =>
{
return webResponse.OK();
};
return base.Import(files);
}
//批量选择获取明商品数据
[Route("getGoods"), HttpPost]
public IActionResult GetGoods([FromBody] PageDataOptions loadData)
{
//调用商品信息的查询方法
var gridData = _goodsService.GetPageData(loadData);
return JsonNormal(gridData);//返回数据-保持大小写一致
//return Json(gridData);不保持大小写一致
}