267 lines
13 KiB
C#
267 lines
13 KiB
C#
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace YLErp.Core.Helpers
|
|
{
|
|
public class FormatToDictHelper
|
|
{
|
|
/// <summary>
|
|
/// 格式化日期通配符
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="dict"></param>
|
|
public static void FormatToDict(string key, DateTime? value, Dictionary<string, JToken> dict)
|
|
{
|
|
var temp = new Dictionary<string, string>();
|
|
FormatToDict(key, value, temp);
|
|
foreach (var item in temp)
|
|
{
|
|
dict[item.Key] = item.Value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 格式化日期通配符
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="dict"></param>
|
|
public static void FormatToDict(string key, DateTime value, Dictionary<string, JToken> dict)
|
|
{
|
|
var temp = new Dictionary<string, string>();
|
|
FormatToDict(key, value, temp);
|
|
foreach (var item in temp)
|
|
{
|
|
dict[item.Key] = item.Value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 格式化int通配符
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="dict"></param>
|
|
public static void FormatToDict(string key, int? value, Dictionary<string, JToken> dict)
|
|
{
|
|
var temp = new Dictionary<string, string>();
|
|
FormatToDict(key, value, temp);
|
|
foreach (var item in temp)
|
|
{
|
|
dict[item.Key] = item.Value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 格式化日期通配符
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="dict"></param>
|
|
public static void FormatToDict(string key, int value, Dictionary<string, JToken> dict)
|
|
{
|
|
var temp = new Dictionary<string, string>();
|
|
FormatToDict(key, value, temp);
|
|
foreach (var item in temp)
|
|
{
|
|
dict[item.Key] = item.Value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 格式化日期通配符
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="dict"></param>
|
|
public static void FormatToDict(string key, double? value, Dictionary<string, JToken> dict)
|
|
{
|
|
var temp = new Dictionary<string, string>();
|
|
FormatToDict(key, value, temp);
|
|
foreach (var item in temp)
|
|
{
|
|
dict[item.Key] = item.Value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 格式化日期通配符
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="dict"></param>
|
|
public static void FormatToDict(string key, double value, Dictionary<string, JToken> dict)
|
|
{
|
|
var temp = new Dictionary<string, string>();
|
|
FormatToDict(key, value, temp);
|
|
foreach (var item in temp)
|
|
{
|
|
dict[item.Key] = item.Value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 格式化日期通配符
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="dict"></param>
|
|
public static void FormatToDict(string key, DateTime? value, Dictionary<string, string> dict)
|
|
{
|
|
dict[key] = value?.ToString("yyyy年MM月dd日");
|
|
dict[key.Insert(key.Length, "N")] = value?.ToString("yyyyMMdd");
|
|
dict[key.Insert(key.Length, "/")] = value?.ToString("yyyy/MM/dd");
|
|
dict[key.Insert(key.Length, "-")] = value?.ToString("yyyy-MM-dd");
|
|
dict[key.Insert(key.Length, "年")] = value?.ToString("yyyy");
|
|
dict[key.Insert(key.Length, "月")] = value?.Month.ToString();
|
|
dict[key.Insert(key.Length, "日")] = value?.Day.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 格式化日期通配符
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="dict"></param>
|
|
public static void FormatToDict(string key, DateTime value, Dictionary<string, string> dict)
|
|
{
|
|
dict[key] = value.ToString("yyyy年MM月dd日");
|
|
dict[key.Insert(key.Length, "N")] = value.ToString("yyyyMMdd");
|
|
dict[key.Insert(key.Length, "/")] = value.ToString("yyyy/MM/dd");
|
|
dict[key.Insert(key.Length, "-")] = value.ToString("yyyy-MM-dd");
|
|
dict[key.Insert(key.Length, "年")] = value.ToString("yyyy");
|
|
dict[key.Insert(key.Length, "月")] = value.ToString("MM");
|
|
dict[key.Insert(key.Length, "日")] = value.ToString("dd");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 格式化Int通配符
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="dict"></param>
|
|
public static void FormatToDict(string key, int value, Dictionary<string, string> dict)
|
|
{
|
|
dict[key] = value.ToString("0");
|
|
dict[key.Insert(key.Length, "A")] = Math.Abs(value).ToString("0");
|
|
dict[key.Insert(key.Length, "大写")] = CmycurD(value);
|
|
}
|
|
/// <summary>
|
|
/// 格式化Double通配符
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="dict"></param>
|
|
public static void FormatToDict(string key, double? value, Dictionary<string, string> dict)
|
|
{
|
|
dict[key] = value?.ToString("0.00");
|
|
dict[key.Insert(key.Length, "2")] = value?.ToString("0.00");
|
|
dict[key.Insert(key.Length, "3")] = value?.ToString("0.000");
|
|
dict[key.Insert(key.Length, "4")] = value?.ToString("0.0000");
|
|
dict[key.Insert(key.Length, "5")] = value?.ToString("0.00000");
|
|
dict[key.Insert(key.Length, "6")] = value?.ToString("0.000000");
|
|
dict[key.Insert(key.Length, "A")] = value != null ? Math.Abs(value.Value).ToString("0") : "";
|
|
dict[key.Insert(key.Length, "A2")] = value != null ? Math.Abs(value.Value).ToString("0.00") : "";
|
|
dict[key.Insert(key.Length, "A3")] = value != null ? Math.Abs(value.Value).ToString("0.000") : "";
|
|
dict[key.Insert(key.Length, "A4")] = value != null ? Math.Abs(value.Value).ToString("0.0000") : "";
|
|
dict[key.Insert(key.Length, "A5")] = value != null ? Math.Abs(value.Value).ToString("0.00000") : "";
|
|
dict[key.Insert(key.Length, "A6")] = value != null ? Math.Abs(value.Value).ToString("0.000000") : "";
|
|
dict[key.Insert(key.Length, "2?")] = value?.ToString("0.##");
|
|
dict[key.Insert(key.Length, "3?")] = value?.ToString("0.###");
|
|
dict[key.Insert(key.Length, "4?")] = value?.ToString("0.####");
|
|
dict[key.Insert(key.Length, "5?")] = value?.ToString("0.#####");
|
|
dict[key.Insert(key.Length, "6?")] = value?.ToString("0.######");
|
|
dict[key.Insert(key.Length, "A2?")] = value != null ? Math.Abs(value.Value).ToString("0.##") : "";
|
|
dict[key.Insert(key.Length, "A3?")] = value != null ? Math.Abs(value.Value).ToString("0.###") : "";
|
|
dict[key.Insert(key.Length, "A4?")] = value != null ? Math.Abs(value.Value).ToString("0.####") : "";
|
|
dict[key.Insert(key.Length, "A5?")] = value != null ? Math.Abs(value.Value).ToString("0.#####") : "";
|
|
dict[key.Insert(key.Length, "A6?")] = value != null ? Math.Abs(value.Value).ToString("0.######") : "";
|
|
dict[key.Insert(key.Length, "大写")] = value != null ? CmycurD(value.Value) : "";
|
|
}
|
|
/// <summary>
|
|
/// 格式化Double通配符
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="dict"></param>
|
|
public static void FormatToDict(string key, double? value, JObject dict)
|
|
{
|
|
dict[key] = value?.ToString("0.00");
|
|
dict[key.Insert(key.Length, "2")] = value?.ToString("0.00");
|
|
dict[key.Insert(key.Length, "3")] = value?.ToString("0.000");
|
|
dict[key.Insert(key.Length, "4")] = value?.ToString("0.0000");
|
|
dict[key.Insert(key.Length, "5")] = value?.ToString("0.00000");
|
|
dict[key.Insert(key.Length, "6")] = value?.ToString("0.000000");
|
|
dict[key.Insert(key.Length, "A")] = value != null ? Math.Abs(value.Value).ToString("0") : "";
|
|
dict[key.Insert(key.Length, "A2")] = value != null ? Math.Abs(value.Value).ToString("0.00") : "";
|
|
dict[key.Insert(key.Length, "A3")] = value != null ? Math.Abs(value.Value).ToString("0.000") : "";
|
|
dict[key.Insert(key.Length, "A4")] = value != null ? Math.Abs(value.Value).ToString("0.0000") : "";
|
|
dict[key.Insert(key.Length, "A5")] = value != null ? Math.Abs(value.Value).ToString("0.00000") : "";
|
|
dict[key.Insert(key.Length, "A6")] = value != null ? Math.Abs(value.Value).ToString("0.000000") : "";
|
|
dict[key.Insert(key.Length, "2?")] = value?.ToString("0.##");
|
|
dict[key.Insert(key.Length, "3?")] = value?.ToString("0.###");
|
|
dict[key.Insert(key.Length, "4?")] = value?.ToString("0.####");
|
|
dict[key.Insert(key.Length, "5?")] = value?.ToString("0.#####");
|
|
dict[key.Insert(key.Length, "6?")] = value?.ToString("0.######");
|
|
dict[key.Insert(key.Length, "A2?")] = value != null ? Math.Abs(value.Value).ToString("0.##") : "";
|
|
dict[key.Insert(key.Length, "A3?")] = value != null ? Math.Abs(value.Value).ToString("0.###") : "";
|
|
dict[key.Insert(key.Length, "A4?")] = value != null ? Math.Abs(value.Value).ToString("0.####") : "";
|
|
dict[key.Insert(key.Length, "A5?")] = value != null ? Math.Abs(value.Value).ToString("0.#####") : "";
|
|
dict[key.Insert(key.Length, "A6?")] = value != null ? Math.Abs(value.Value).ToString("0.######") : "";
|
|
dict[key.Insert(key.Length, "大写")] = value != null ? CmycurD(value.Value) : "";
|
|
}
|
|
/// <summary>
|
|
/// 格式化Double通配符
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="dict"></param>
|
|
public static void FormatToDict(string key, double value, Dictionary<string, string> dict)
|
|
{
|
|
dict[key] = value.ToString("0.00");
|
|
dict[key.Insert(key.Length, "2")] = value.ToString("0.00");
|
|
dict[key.Insert(key.Length, "3")] = value.ToString("0.000");
|
|
dict[key.Insert(key.Length, "4")] = value.ToString("0.0000");
|
|
dict[key.Insert(key.Length, "5")] = value.ToString("0.00000");
|
|
dict[key.Insert(key.Length, "6")] = value.ToString("0.000000");
|
|
dict[key.Insert(key.Length, "A")] = Math.Abs(value).ToString("0");
|
|
dict[key.Insert(key.Length, "A2")] = Math.Abs(value).ToString("0.00");
|
|
dict[key.Insert(key.Length, "A3")] = Math.Abs(value).ToString("0.000");
|
|
dict[key.Insert(key.Length, "A4")] = Math.Abs(value).ToString("0.0000");
|
|
dict[key.Insert(key.Length, "A5")] = Math.Abs(value).ToString("0.00000");
|
|
dict[key.Insert(key.Length, "A6")] = Math.Abs(value).ToString("0.000000");
|
|
dict[key.Insert(key.Length, "2?")] = value.ToString("0.##");
|
|
dict[key.Insert(key.Length, "3?")] = value.ToString("0.###");
|
|
dict[key.Insert(key.Length, "4?")] = value.ToString("0.####");
|
|
dict[key.Insert(key.Length, "5?")] = value.ToString("0.#####");
|
|
dict[key.Insert(key.Length, "6?")] = value.ToString("0.######");
|
|
dict[key.Insert(key.Length, "A2?")] = Math.Abs(value).ToString("0.##");
|
|
dict[key.Insert(key.Length, "A3?")] = Math.Abs(value).ToString("0.###");
|
|
dict[key.Insert(key.Length, "A4?")] = Math.Abs(value).ToString("0.####");
|
|
dict[key.Insert(key.Length, "A5?")] = Math.Abs(value).ToString("0.#####");
|
|
dict[key.Insert(key.Length, "A6?")] = Math.Abs(value).ToString("0.######");
|
|
dict[key.Insert(key.Length, "大写")] = CmycurD(value);
|
|
}
|
|
/// <summary>
|
|
/// 人民币转大写
|
|
/// <para>该方法直接调用NumberHelper.CmycurD(num)</para>
|
|
/// </summary>
|
|
/// <param name="num"></param>
|
|
/// <returns></returns>
|
|
public static string CmycurD(double num)
|
|
{
|
|
var str = NumberHelper.CmycurD(num);
|
|
if (str.EndsWith("整") && !str.EndsWith("元整"))
|
|
{
|
|
str = str.Remove(str.Length - 1);
|
|
}
|
|
return str;
|
|
}
|
|
}
|
|
}
|