测试
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Web.UI.WebControls;
|
||||
using ADODB;
|
||||
using GetComObj;
|
||||
using MSXML2;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using UFIDA.U8.Framework.Api.Common.Entity;
|
||||
using UFIDA.U8.Framework.Api.ControlObject.Entity;
|
||||
using UFIDA.U8.Framework.Api.ControlObject.Json;
|
||||
|
||||
namespace UFIDA.U8.Framework.Api.ControlObject.Common
|
||||
@@ -314,5 +320,294 @@ namespace UFIDA.U8.Framework.Api.ControlObject.Common
|
||||
|
||||
return rethash + (char)3;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取币种汇率
|
||||
/// </summary>
|
||||
/// <param name="dDate">日期</param>
|
||||
/// <param name="cAccId">账套</param>
|
||||
/// <param name="exchName">币种</param>
|
||||
/// <param name="conn">连接对象</param>
|
||||
/// <returns></returns>
|
||||
public static Exch GetExch(DateTime dDate, string cAccId, string exchName, Connection conn)
|
||||
{
|
||||
var strSql =
|
||||
$@"SELECT a.cexch_name,a.bcal,a.idec,round(convert(decimal(28,20),a.nerror),a.idec) nerror,b.itype,a.iotherused,b.nflat
|
||||
FROM foreigncurrency a
|
||||
left join exch b on b.cexch_name=a.cexch_name
|
||||
left join ufsystem.dbo.UA_Period c on c.iYear=b.iyear and c.iId=b.iperiod and cAcc_Id='{cAccId}' and bIsDelete=0
|
||||
WHERE (a.iotherused=-1 or (b.itype=2 and c.dBegin>='{dDate:yyyy-MM-dd}' and c.dEnd<='{dDate:yyyy-MM-dd}')) and a.cexch_name='{exchName}'
|
||||
order by b.itype ";
|
||||
|
||||
var rs = new Recordset();
|
||||
rs.Open(strSql, conn); //查询档案
|
||||
|
||||
if (rs.BOF || rs.EOF)
|
||||
throw new Exception($"当前币种:{exchName}在当前会计期间未设置汇率");
|
||||
|
||||
rs.MoveFirst();
|
||||
|
||||
var exch = new Exch
|
||||
{
|
||||
cexch_name = $"{rs.Fields["cexch_name"].Value}"
|
||||
};
|
||||
|
||||
if (rs.Fields["bcal"].Value != null)
|
||||
{
|
||||
exch.bcal = Convert.ToBoolean(rs.Fields["bcal"].Value);
|
||||
}
|
||||
|
||||
if (rs.Fields["idec"].Value != null)
|
||||
{
|
||||
exch.idec = Convert.ToInt16(rs.Fields["idec"].Value);
|
||||
}
|
||||
|
||||
if (rs.Fields["nerror"].Value != null)
|
||||
{
|
||||
exch.nerror = Convert.ToDecimal(rs.Fields["nerror"].Value);
|
||||
}
|
||||
|
||||
if (rs.Fields["iotherused"].Value != null)
|
||||
{
|
||||
exch.iotherused = Convert.ToInt32(rs.Fields["iotherused"].Value);
|
||||
}
|
||||
|
||||
if (rs.Fields["nflat"].Value != null && !string.IsNullOrWhiteSpace($"{rs.Fields["nflat"].Value}"))
|
||||
{
|
||||
exch.nflat = Convert.ToDecimal(rs.Fields["nflat"].Value);
|
||||
}
|
||||
|
||||
return exch;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置字典对象数据
|
||||
/// </summary>
|
||||
/// <param name="dict">字典对象</param>
|
||||
/// <param name="defs">实体字段配置信息</param>
|
||||
/// <param name="conn">数据库连接对象</param>
|
||||
/// <param name="newCode">新单号</param>
|
||||
/// <param name="rowNo">行号</param>
|
||||
/// <param name="bUpdate">是否更新</param>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<string, object> SetDictionaryData(this Dictionary<string, object> dict, List<SysU8FieldDefine> defs, Connection conn = null, string newCode = "", int rowNo = 1, Exch exch = null, bool bUpdate = false)
|
||||
{
|
||||
var adef = defs.Where(s => s.bDefault ?? false).ToList();
|
||||
//var codeField = "";
|
||||
if (adef.Count > 0 && !bUpdate)
|
||||
{
|
||||
foreach (var def in adef)
|
||||
{
|
||||
switch (def.DefaultValue)
|
||||
{
|
||||
case "当前日期":
|
||||
dict[def.FieldName] = $"{DateTime.Today:yyyy-MM-dd}";
|
||||
break;
|
||||
case "当前日期时间":
|
||||
dict[def.FieldName] = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}";
|
||||
break;
|
||||
case "单号":
|
||||
dict[def.FieldName] = newCode; //一直取不到,怀疑是带字段的关系,需要后续研究后确定
|
||||
//codeField = def.FieldName;
|
||||
break;
|
||||
case "行号":
|
||||
dict[def.FieldName] = rowNo;
|
||||
break;
|
||||
case "汇率":
|
||||
if (exch?.nflat != null && string.IsNullOrWhiteSpace($"{dict[def.FieldName]}"))
|
||||
{
|
||||
dict[def.FieldName] = exch.nflat;
|
||||
}
|
||||
|
||||
if (exch?.iotherused == -1)
|
||||
{
|
||||
dict[def.FieldName] = 1;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
if (!dict.ContainsKey(def.FieldName) || string.IsNullOrWhiteSpace($"{dict[def.FieldName]}"))
|
||||
dict[def.FieldName] = def.DefaultValue ?? "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//查找档案关联的字段并赋值
|
||||
var keys = dict.Keys.ToList();
|
||||
|
||||
foreach (var key in keys)
|
||||
{
|
||||
var bdef = defs.Where(s => s.ModelName == key && (s.bArchives ?? false)).ToList(); //获取当前字段的关联信息
|
||||
|
||||
if (bdef.Count <= 0) continue;
|
||||
|
||||
var archivesTablesList = bdef.Select(s => s.ArchivesTable).Distinct().ToList(); //合并关联的档案表
|
||||
|
||||
if (archivesTablesList.Count <= 0) continue;
|
||||
|
||||
foreach (var archives in archivesTablesList) //根据档案表查询
|
||||
{
|
||||
var fieldList = bdef.Where(s => s.ArchivesTable == archives)
|
||||
.Select(s => new { s.FieldName, s.ArchivesField }).ToList(); //获取需要查询的字段
|
||||
var field = bdef.Where(s => s.ArchivesTable == archives).Select(s => s.ArchivesSource).First(); //获取档案与实体的关联字段
|
||||
var strField = string.Join(",", fieldList.Select(s => s.ArchivesField)); //组装需要查询的字段
|
||||
|
||||
var strSql = $"SELECT {strField} FROM {archives} WHERE {field}='{dict[key]}'"; //构建查询语句
|
||||
|
||||
var rs = new Recordset();
|
||||
rs.Open(strSql, conn); //查询档案
|
||||
|
||||
if (rs.BOF || rs.EOF) continue; //无数据不赋值
|
||||
|
||||
rs.MoveFirst();
|
||||
foreach (var f in fieldList)
|
||||
{
|
||||
dict[f.FieldName] = $"{rs.Fields[f.ArchivesField].Value}"; //根据字段值赋值
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var cdef = defs.Where(s => s.bCalc ?? false).OrderBy(s => s.iSort).ToList(); //获取计算列的配置
|
||||
|
||||
if (cdef.Count > 0)
|
||||
{
|
||||
foreach (var def in cdef)
|
||||
{
|
||||
var calcFormula = def.CalcFormula;
|
||||
var cPrecision = def.cPrecision;
|
||||
foreach (var key in dict.Keys.Where(key => calcFormula.Contains($"{{{key}}}"))) //遍历字段来替换公式中的参数
|
||||
{
|
||||
calcFormula = calcFormula.Replace($"{{{key}}}", $"{dict[key]}");
|
||||
}
|
||||
|
||||
//汇率单独处理
|
||||
if (calcFormula.Contains("{汇率:B}") || calcFormula.Contains("{汇率:Y}"))
|
||||
{
|
||||
var YB = "B";
|
||||
var pp = "*";
|
||||
if (calcFormula.Contains("{汇率:Y}"))
|
||||
{
|
||||
YB = "Y";
|
||||
}
|
||||
|
||||
var nflat = 1m;
|
||||
if (exch != null)
|
||||
{
|
||||
if (exch.iotherused != -1)
|
||||
{
|
||||
if (exch.idec != null)
|
||||
cPrecision = Convert.ToInt32(exch.idec);
|
||||
|
||||
nflat = exch.nflat ?? 1;
|
||||
|
||||
if (YB == "Y" && !(exch.bcal ?? false))
|
||||
{
|
||||
pp = "/";
|
||||
}
|
||||
|
||||
if (YB == "B" && (exch.bcal ?? false))
|
||||
{
|
||||
pp = "/";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cPrecision = null;
|
||||
}
|
||||
}
|
||||
|
||||
calcFormula = calcFormula.Replace("{汇率:B}", $"{pp}{nflat}");
|
||||
calcFormula = calcFormula.Replace("{汇率:Y}", $"{pp}{nflat}");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var dt = new DataTable();
|
||||
|
||||
var val = cPrecision == null
|
||||
? dt.Compute(calcFormula, "")
|
||||
: Math.Round(Convert.ToDecimal(dt.Compute(calcFormula, "")), cPrecision ?? 6); //计算公式结果
|
||||
|
||||
dict[def.FieldName] = val;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logInfo.Debug($"字段:{def.FieldName}公式解析失败,公式结果:{calcFormula}");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 把对象转换为Boolean类型
|
||||
/// </summary>
|
||||
/// <param name="obj">需要转换的对象</param>
|
||||
/// <returns></returns>
|
||||
public static bool ToBoolean(this object obj)
|
||||
{
|
||||
return bool.TryParse($"{obj}", out var re) && re;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把对象转换为Int类型
|
||||
/// </summary>
|
||||
/// <param name="obj">需要转换的对象</param>
|
||||
/// <returns></returns>
|
||||
public static int ToShort(this object obj)
|
||||
{
|
||||
if (!short.TryParse($"{obj}", out var re))
|
||||
throw new InvalidCastException($"值:{obj}无法转换为短数字格式!");
|
||||
|
||||
return re;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把对象转换为Int类型
|
||||
/// </summary>
|
||||
/// <param name="obj">需要转换的对象</param>
|
||||
/// <returns></returns>
|
||||
public static int ToInt(this object obj)
|
||||
{
|
||||
if (!int.TryParse($"{obj}", out var re))
|
||||
throw new InvalidCastException($"值:{obj}无法转换为数字格式!");
|
||||
|
||||
return re;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="length"></param>
|
||||
/// <param name="useNum"></param>
|
||||
/// <param name="useLow"></param>
|
||||
/// <param name="useUpp"></param>
|
||||
/// <param name="useSpe"></param>
|
||||
/// <param name="customerStr"></param>
|
||||
/// <returns></returns>
|
||||
public static string GenRandomString(int length, bool useNum, bool useLow, bool useUpp, bool useSpe,
|
||||
string customerStr)
|
||||
{
|
||||
var b = new byte[4];
|
||||
new RNGCryptoServiceProvider().GetBytes(b);
|
||||
var r = new Random(BitConverter.ToInt32(b, 0));
|
||||
string s = null, str = customerStr;
|
||||
if (useNum) str += "0123456789";
|
||||
if (useLow) str += @"abcdefghijklmnopqrstuvwxyz";
|
||||
if (useUpp) str += @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
if (useSpe) str += "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
|
||||
for (var i = 0; i < length; i++)
|
||||
{
|
||||
s += str.Substring(r.Next(0, str.Length - 1), 1);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user