打印模块修改

usertest
cjy 4 months ago
parent 359f97c652
commit 39fc81dc28

@ -12,7 +12,7 @@ public static class StringExtensions
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static bool IsSqlInjection(string input)
public static bool IsSqlInjection(this string input)
{
string[] sqlCheckList = { "TRUNCATE", "INSERT", "UPDATE", "DELETE", "DROP", "--", ";", "'" };
foreach (string item in sqlCheckList)

@ -46,7 +46,7 @@ namespace DS.WMS.Core.Sys.Interface
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public DataResult EditSysPrintTemplate(SysPrintTemplateReq req);
public Task<DataResult> EditSysPrintTemplate(SysPrintTemplateReq req);
/// <summary>
/// 打印模块删除

@ -12,6 +12,7 @@ using DS.Module.SqlSugar;
using DS.WMS.Core.Code.Entity;
using Org.BouncyCastle.Ocsp;
using System.Collections.Generic;
using Masuit.Tools.Strings;
namespace DS.WMS.Core.Sys.Method
{
@ -96,29 +97,71 @@ namespace DS.WMS.Core.Sys.Method
.First();
return DataResult<SysPrintTemplateRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
}
public DataResult EditSysPrintTemplate(SysPrintTemplateReq req)
public async Task<DataResult> EditSysPrintTemplate(SysPrintTemplateReq req)
{
if (req.Id == 0)
{
var isExist = db.Queryable<SysPrintTemplate>().Where(x => x.TemplateCode == req.TemplateCode).WhereIF(req.CarrierId != 0, x => x.CarrierId == req.CarrierId).First();
if (isExist != null)
if (db.Queryable<SysPrintTemplate>().Where(x => x.TemplateCode == req.TemplateCode).WhereIF(req.CarrierId != 0, x => x.CarrierId == req.CarrierId).Any())
{
return DataResult.Failed("打印模板唯一编码已存在!");
return await Task.FromResult(DataResult.Failed("打印模板唯一编码已存在!"));
}
if (req.IsUseDataSource) {
if (string.IsNullOrEmpty(req.SourceSql))
{
return await Task.FromResult(DataResult.Failed("打印数据源不能为空!"));
}
if (!req.SourceSql.Contains(';'))
{
return await Task.FromResult(DataResult.Failed("数据源必须包含分号!"));
}
if (req.SourceSql.Substring(req.SourceSql.Length - 1, 1) != ";")
{
return await Task.FromResult(DataResult.Failed("数据源最后必须包含分号!"));
}
if (req.SourceSql.IsSqlInjection())
{
return await Task.FromResult(DataResult.Failed("sql数据源包含非法字符,请检查!"));
}
}
var data = req.Adapt<SysPrintTemplate>();
var entity = db.Insertable(data).ExecuteReturnEntity();
var entity = await db.Insertable(data).ExecuteReturnEntityAsync();
return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
}
else
{
var info = db.Queryable<SysPrintTemplate>().Where(x => x.Id == req.Id).First();
var info = await db.Queryable<SysPrintTemplate>().Where(x => x.Id == req.Id).FirstAsync();
if (req.IsUseDataSource)
{
if (string.IsNullOrEmpty(req.SourceSql))
{
return await Task.FromResult(DataResult.Failed("打印数据源不能为空!"));
}
if (!req.SourceSql.Contains(';'))
{
return await Task.FromResult(DataResult.Failed("数据源必须包含分号!"));
}
if (req.SourceSql.Substring(req.SourceSql.Length - 1, 1) != ";")
{
return await Task.FromResult(DataResult.Failed("数据源最后必须包含分号!"));
}
if (req.SourceSql.IsSqlInjection())
{
return await Task.FromResult(DataResult.Failed("sql数据源包含非法字符,请检查!"));
}
}
info = req.Adapt(info);
db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
await db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
return await Task.FromResult(DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess));
}
}

@ -94,9 +94,9 @@ public class PrintTemplateController : ApiController
/// <returns></returns>
[HttpPost]
[Route("EditSysPrintTemplate")]
public DataResult EditSysPrintTemplate([FromBody] SysPrintTemplateReq req)
public async Task<DataResult> EditSysPrintTemplate([FromBody] SysPrintTemplateReq req)
{
var res = _invokeService.EditSysPrintTemplate(req);
var res = await _invokeService.EditSysPrintTemplate(req);
return res;
}

@ -312,8 +312,7 @@ namespace DS.WMS.PrintApi.Service
var printFileName = $"{fileName}.frx";
var printFile = Path.Combine(savePath, printFileName);
//写入CRX文件
using (FileStream fs = new FileStream(printFile, FileMode.Create))
{
@ -324,7 +323,6 @@ namespace DS.WMS.PrintApi.Service
//生成报表
FastReport.Report report = new FastReport.Report();
report.Load(printFile);
var str = new FastReport.Data.JsonConnection.JsonDataSourceConnectionStringBuilder();
str.Json = JsonConvert.SerializeObject(data);
if (report.Dictionary.Connections.Count == 0)
@ -336,34 +334,9 @@ namespace DS.WMS.PrintApi.Service
Name = "Connection",
});
}
//else {
// var dataSource = report.Dictionary.Connections[0] as JsonDataSourceConnection;
// dataSource.ConnectionString = str.ConnectionString;
//}
//var dataSource = report.Dictionary.Connections[0] as JsonDataSourceConnection;
//var str = new FastReport.Data.JsonConnection.JsonDataSourceConnectionStringBuilder();
//str.Json = JsonConvert.SerializeObject(data);
//dataSource.ConnectionString = str.ConnectionString;
//JsonSchemaGenerator generator = new JsonSchemaGenerator();
//JsonSchema jsonSchema = generator.Generate()
//report.Dictionary.Connections.Clear();
//var dataSource = report.Dictionary.Connections[0] as JsonDataSourceConnection;
//var str = new FastReport.Data.JsonConnection.JsonDataSourceConnectionStringBuilder();
//str.Json = JsonConvert.SerializeObject(data);
////dataSource.ConnectionString = str.ConnectionString;
////重置数据源
//report.Dictionary.Connections.Add(new JsonDataSourceConnection()
//{
// ConnectionString = str.ConnectionString,
// Alias = "JSON"
//});
//report.Dictionary.Connections[0].ConnectionString = str.ConnectionString;
report.Save(printFile);
report.Prepare();
var printName = string.Empty;
var saveFile = string.Empty;

Loading…
Cancel
Save