添加项目文件。
This commit is contained in:
13
Command/Command.csproj
Normal file
13
Command/Command.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Common\Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
268
Command/CommandApplication.cs
Normal file
268
Command/CommandApplication.cs
Normal file
@@ -0,0 +1,268 @@
|
||||
using Common.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Command
|
||||
{
|
||||
|
||||
[ADPCommand]
|
||||
public static class CommandApplication
|
||||
{
|
||||
/// <summary>
|
||||
/// 打开外部应用程序
|
||||
/// </summary>
|
||||
/// <param name="route">程序路径</param>
|
||||
/// <param name="waitShutdown">是否等待关闭</param>
|
||||
/// <param name="AdminRun">是否请求管理员运行</param>
|
||||
public static void OpenApplication(string route, bool waitShutdown, bool AdminRun)
|
||||
{
|
||||
|
||||
// 创建一个新的进程实例
|
||||
Process process = new Process();
|
||||
|
||||
try
|
||||
{
|
||||
// 指定要启动的程序路径
|
||||
process.StartInfo.FileName = route;
|
||||
|
||||
// 指定是否等待程序关闭
|
||||
process.StartInfo.UseShellExecute = !waitShutdown;
|
||||
if (AdminRun) process.StartInfo.Verb = "runas";
|
||||
// 启动程序
|
||||
process.Start();
|
||||
|
||||
// 如果需要等待程序关闭,则等待程序退出
|
||||
if (waitShutdown)
|
||||
{
|
||||
process.WaitForExit();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("错误!: " + ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// 确保进程对象被释放
|
||||
process.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 使用默认方式打开一个文件
|
||||
/// </summary>
|
||||
/// <param name="route">文件路径</param>
|
||||
public static void OpenFile(string route)
|
||||
{
|
||||
// 创建一个新的进程实例
|
||||
Process process = new Process();
|
||||
|
||||
try
|
||||
{
|
||||
// 指定要启动的程序路径
|
||||
process.StartInfo.FileName = route;
|
||||
process.StartInfo.UseShellExecute = true;
|
||||
// 启动程序
|
||||
process.Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("错误!: " + ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// 确保进程对象被释放
|
||||
process.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Python引擎相关字段
|
||||
private static Process _pythonProcess;
|
||||
private static string _pythonPath = string.Empty;
|
||||
private static bool _isPythonEngineInitialized = false;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化python引擎
|
||||
/// </summary>
|
||||
/// <param name="py路径">Python解释器路径</param>
|
||||
public static void Initialization_Python(string py路径)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 验证Python路径是否存在
|
||||
if (string.IsNullOrEmpty(py路径) || !File.Exists(py路径))
|
||||
{
|
||||
throw new FileNotFoundException($"Python解释器路径不存在: {py路径}");
|
||||
}
|
||||
|
||||
// 验证是否为Python可执行文件
|
||||
var fileInfo = new FileInfo(py路径);
|
||||
if (!fileInfo.Name.ToLower().Contains("python"))
|
||||
{
|
||||
Console.WriteLine("警告: 指定的文件可能不是Python解释器");
|
||||
}
|
||||
|
||||
// 测试Python是否能正常运行
|
||||
var testProcess = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = py路径,
|
||||
Arguments = "--version",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true
|
||||
}
|
||||
};
|
||||
|
||||
testProcess.Start();
|
||||
testProcess.WaitForExit(5000); // 5秒超时
|
||||
|
||||
if (testProcess.ExitCode != 0)
|
||||
{
|
||||
throw new InvalidOperationException($"Python解释器验证失败,退出码: {testProcess.ExitCode}");
|
||||
}
|
||||
|
||||
_pythonPath = py路径;
|
||||
_isPythonEngineInitialized = true;
|
||||
|
||||
Console.WriteLine($"Python引擎初始化成功,版本: {testProcess.StandardOutput.ReadToEnd().Trim()}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_isPythonEngineInitialized = false;
|
||||
_pythonPath = string.Empty;
|
||||
Console.WriteLine($"初始化Python引擎失败: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 运行python脚本
|
||||
/// </summary>
|
||||
/// <param name="路径">Python脚本路径</param>
|
||||
/// <returns>脚本执行结果</returns>
|
||||
public static string Run_Python_Script(string 路径)
|
||||
{
|
||||
if (!_isPythonEngineInitialized)
|
||||
{
|
||||
throw new InvalidOperationException("Python引擎未初始化,请先调用初始化python引擎");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(路径) || !File.Exists(路径))
|
||||
{
|
||||
throw new FileNotFoundException($"Python脚本路径不存在: {路径}");
|
||||
}
|
||||
|
||||
Process process = null;
|
||||
try
|
||||
{
|
||||
process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = _pythonPath,
|
||||
Arguments = $"\"{路径}\"",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true
|
||||
}
|
||||
};
|
||||
|
||||
var output = new StringBuilder();
|
||||
var error = new StringBuilder();
|
||||
|
||||
// 设置输出和错误处理
|
||||
process.OutputDataReceived += (sender, e) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(e.Data))
|
||||
output.AppendLine(e.Data);
|
||||
};
|
||||
|
||||
process.ErrorDataReceived += (sender, e) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(e.Data))
|
||||
error.AppendLine(e.Data);
|
||||
};
|
||||
|
||||
process.Start();
|
||||
|
||||
// 异步读取输出
|
||||
process.BeginOutputReadLine();
|
||||
process.BeginErrorReadLine();
|
||||
|
||||
process.WaitForExit();
|
||||
|
||||
var outputResult = output.ToString().Trim();
|
||||
var errorResult = error.ToString().Trim();
|
||||
|
||||
if (process.ExitCode != 0)
|
||||
{
|
||||
throw new InvalidOperationException($"Python脚本执行失败,退出码: {process.ExitCode}, 错误: {errorResult}");
|
||||
}
|
||||
|
||||
return string.IsNullOrEmpty(outputResult) ? "执行成功" : outputResult;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"运行Python脚本失败: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
process?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放python引擎
|
||||
/// </summary>
|
||||
/// <param name="py">Python解释器路径(可选,用于验证)</param>
|
||||
public static void Release_Python(string py = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(py) && py != _pythonPath)
|
||||
{
|
||||
Console.WriteLine($"警告: 释放的Python路径与当前初始化路径不匹配");
|
||||
}
|
||||
|
||||
// 如果有正在运行的Python进程,尝试终止它
|
||||
if (_pythonProcess != null && !_pythonProcess.HasExited)
|
||||
{
|
||||
try
|
||||
{
|
||||
_pythonProcess.Kill();
|
||||
_pythonProcess.WaitForExit(1000);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"终止Python进程时出错: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
_pythonPath = string.Empty;
|
||||
_isPythonEngineInitialized = false;
|
||||
_pythonProcess = null;
|
||||
|
||||
Console.WriteLine("Python引擎已释放");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"释放Python引擎失败: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
261
Command/CommandArray.cs
Normal file
261
Command/CommandArray.cs
Normal file
@@ -0,0 +1,261 @@
|
||||
using Common.Attributes;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Command
|
||||
{
|
||||
|
||||
[ADPCommand]
|
||||
public static class CommandArray
|
||||
{
|
||||
#region 数组操作
|
||||
/// <summary>
|
||||
/// 从数组中获取指定位置的元素。
|
||||
/// </summary>
|
||||
/// <param name="Array">要索引的数组。</param>
|
||||
/// <param name="Index">要获取的元素的位置。</param>
|
||||
/// <returns>指定位置的元素。</returns>
|
||||
public static object IndexArray(object Array, int Index)
|
||||
{
|
||||
return ((dynamic)Array)[Index];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置数组中指定位置的元素为给定值。
|
||||
/// </summary>
|
||||
/// <param name="Array">要设置元素的数组。</param>
|
||||
/// <param name="Location">要设置的元素的位置。</param>
|
||||
/// <param name="Value">要设置的值。</param>
|
||||
/// <returns>修改后的数组。</returns>
|
||||
public static object SetArrayElement(object Array, int Location, object Value)
|
||||
{
|
||||
((dynamic)Array)[Location] = (dynamic)Value;
|
||||
return Array;
|
||||
}
|
||||
/// <summary>
|
||||
/// 将给定数组的长度设置为指定值,并返回一个新的数组。
|
||||
/// 如果指定的长度小于原始数组的长度,则截取原始数组的一部分作为新数组。
|
||||
/// </summary>
|
||||
/// <param name="Arr">要设置长度的数组。</param>
|
||||
/// <param name="Length">新数组的长度。</param>
|
||||
/// <returns>新的数组,或者原始数组(如果输入参数不是数组类型)。</returns>
|
||||
public static object SetArrayLength(object Arr, int Length)
|
||||
{
|
||||
if (Arr is Array)
|
||||
{
|
||||
// 创建一个新的数组实例来存储结果
|
||||
Array temp = Array.CreateInstance(Arr.GetType()!.GetElementType()!, Length);
|
||||
// 确定复制的长度,取原始数组长度和目标长度的最小值
|
||||
int CopyLength = Math.Min(((Array)Arr).Length, Length);
|
||||
// 复制原始数组的元素到新数组中
|
||||
Array.Copy((Array)Arr, temp, CopyLength);
|
||||
return temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果输入参数不是数组类型,则返回原始数组
|
||||
return Arr;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在指定位置插入元素到数组中。
|
||||
/// </summary>
|
||||
/// <param name="Arr">要插入元素的数组。</param>
|
||||
/// <param name="Location">要插入元素的位置。</param>
|
||||
/// <param name="InsertElement">要插入的元素。</param>
|
||||
/// <returns>插入元素后的数组。</returns>
|
||||
public static object SetArrayInsertElement(object Arr, int Location, object InsertElement)
|
||||
{
|
||||
// 将数组转换为可编辑列表
|
||||
var temp = Enumerable.ToList((dynamic)Arr);
|
||||
|
||||
// 在指定位置插入元素
|
||||
temp.Insert(Location, (dynamic)InsertElement);
|
||||
|
||||
// 如果原数组是数组类型,则将可编辑列表转换回数组并返回
|
||||
if (Arr is Array)
|
||||
{
|
||||
return Enumerable.ToArray(temp);
|
||||
}
|
||||
|
||||
// 返回插入元素后的可编辑列表
|
||||
return temp;
|
||||
}
|
||||
/// <summary>
|
||||
/// 从数组中删除指定的元素。
|
||||
/// </summary>
|
||||
/// <param name="Arr">要删除元素的数组。</param>
|
||||
/// <param name="DeleteElement">要从数组中删除的元素。</param>
|
||||
/// <returns>删除元素后的数组。</returns>
|
||||
public static object SetArrayDeleteElement(object Arr, object DeleteElement)
|
||||
{
|
||||
// 将数组转换为可编辑列表
|
||||
var temp = Enumerable.ToList((dynamic)Arr);
|
||||
|
||||
// 从列表中移除指定元素
|
||||
temp.Remove((dynamic)DeleteElement);
|
||||
|
||||
// 如果原数组是数组类型,则将可编辑列表转换回数组并返回
|
||||
if (Arr is Array)
|
||||
{
|
||||
return Enumerable.ToArray(temp);
|
||||
}
|
||||
|
||||
// 返回删除元素后的可编辑列表
|
||||
return temp;
|
||||
}
|
||||
/// <summary>
|
||||
/// 从数组中删除指定位置的元素。
|
||||
/// </summary>
|
||||
/// <param name="Arr">要删除元素的数组。</param>
|
||||
/// <param name="DeleteElementLocation">要从数组中删除的元素的位置。</param>
|
||||
/// <returns>删除元素后的数组。</returns>
|
||||
public static object SetArrayDeleteLocationElement(object Arr, int DeleteElementLocation)
|
||||
{
|
||||
var temp = Enumerable.ToList((dynamic)Arr);
|
||||
temp.RemoveAt(DeleteElementLocation);
|
||||
if (Arr is Array)
|
||||
{
|
||||
return Enumerable.ToArray(temp);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
/// <summary>
|
||||
/// 在数组中寻找第一个匹配的元素,并返回其索引位置。
|
||||
/// </summary>
|
||||
/// <param name="Arr">要搜索的数组。</param>
|
||||
/// <param name="QueryElement">要寻找的元素。</param>
|
||||
/// <returns>要寻找的元素在数组中的第一个匹配项的索引;如果未找到匹配项,则为 -1。</returns>
|
||||
public static int ArrayQueryFirstMatchElement(object Arr, object QueryElement)
|
||||
{
|
||||
if (Arr is Array)
|
||||
{
|
||||
return Array.IndexOf((dynamic)Arr, (dynamic)QueryElement);
|
||||
}
|
||||
return ((dynamic)Arr).IndexOf((dynamic)QueryElement);
|
||||
}
|
||||
/// <summary>
|
||||
/// 替换数组中第一个匹配的元素为指定的新元素。
|
||||
/// </summary>
|
||||
/// <param name="Arr">要进行替换操作的数组。</param>
|
||||
/// <param name="FirstMatchElement">要替换的元素。</param>
|
||||
/// <param name="ReplaceElement">要替换为的新元素。</param>
|
||||
/// <returns>替换后的数组。</returns>
|
||||
public static object ArrayReplaceFirstMatchElement(object Arr, object FirstMatchElement, object ReplaceElement)
|
||||
{
|
||||
var temp = Enumerable.ToList((dynamic)Arr);
|
||||
int Location = ArrayQueryFirstMatchElement(Arr, FirstMatchElement);
|
||||
temp[Location] = (dynamic)ReplaceElement;
|
||||
return temp;
|
||||
}
|
||||
/// <summary>
|
||||
/// 将数组中所有匹配的元素替换为指定的新元素。
|
||||
/// </summary>
|
||||
/// <param name="Arr">要进行替换操作的数组。</param>
|
||||
/// <param name="MatchElement">要替换的元素。</param>
|
||||
/// <param name="ReplaceElement">要替换为的新元素。</param>
|
||||
/// <returns>替换后的数组。</returns>
|
||||
public static object ArrayReplaceAllMatchElement(object Arr, object MatchElement, object ReplaceElement)
|
||||
{
|
||||
var temp = Enumerable.ToList((dynamic)Arr);
|
||||
int 长度 = temp.Count;
|
||||
|
||||
for (int i = 0; i < 长度; i++)
|
||||
{
|
||||
if (((dynamic)Arr)[i] == (dynamic)MatchElement)
|
||||
{
|
||||
((dynamic)Arr)[i] = (dynamic)ReplaceElement;
|
||||
}
|
||||
}
|
||||
return Arr;
|
||||
}
|
||||
/// <summary>
|
||||
/// 反转数组中元素的顺序。
|
||||
/// </summary>
|
||||
/// <param name="Arr">要反转的数组。</param>
|
||||
/// <returns>反转后的数组。</returns>
|
||||
public static object ArrayReverse(object Arr)
|
||||
{
|
||||
var temp = Enumerable.ToList((dynamic)Arr);
|
||||
temp.Reverse();
|
||||
if (Arr is Array)
|
||||
{
|
||||
return Enumerable.ToArray(temp);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
/// <summary>
|
||||
/// 对数组进行排序。
|
||||
/// </summary>
|
||||
/// <param name="Arr">要排序的数组。</param>
|
||||
/// <returns>排序后的数组。</returns>
|
||||
public static object ArraySorting(object Arr)
|
||||
{
|
||||
var temp = Enumerable.ToList((dynamic)Arr);
|
||||
temp = Enumerable.ToList(Enumerable.Order(temp));
|
||||
if (Arr is Array)
|
||||
{
|
||||
return Enumerable.ToArray(temp);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取数组的长度。
|
||||
/// </summary>
|
||||
/// <param name="Arr">要获取长度的数组。</param>
|
||||
/// <returns>数组的长度。</returns>
|
||||
public static int GetArrayLength(object Arr)
|
||||
{
|
||||
if (Arr is Array)
|
||||
{
|
||||
return ((Array)Arr).Length;
|
||||
}
|
||||
return ((ICollection)Arr).Count;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 将对象转换为数组。
|
||||
/// </summary>
|
||||
/// <param name="Arr">要转换的对象。</param>
|
||||
/// <returns>转换后的数组。</returns>
|
||||
public static object objectConvertToArray(object Arr)
|
||||
{
|
||||
return Enumerable.ToArray((dynamic)Arr);
|
||||
}
|
||||
/// <summary>
|
||||
/// 将对象转换为列表。
|
||||
/// </summary>
|
||||
/// <param name="Arr">要转换的对象。</param>
|
||||
/// <returns>转换后的列表。</returns>
|
||||
public static object objectConvertToList(object Arr)
|
||||
{
|
||||
return Enumerable.ToList((dynamic)Arr);
|
||||
}
|
||||
/// <summary>
|
||||
/// 从数组中截取指定长度的子数组。
|
||||
/// </summary>
|
||||
/// <param name="Arr">要截取的数组。</param>
|
||||
/// <param name="StartLocation">截取开始的位置。</param>
|
||||
/// <param name="Length">要截取的长度。</param>
|
||||
/// <returns>截取得到的子数组。</returns>
|
||||
public static object ArrayCapture(object Arr, int StartLocation, int Length)
|
||||
{
|
||||
var temp = Enumerable.ToList((dynamic)Arr);
|
||||
temp = Enumerable.ToList(Enumerable.Take(Enumerable.Skip(temp, StartLocation), Length));
|
||||
if (Arr is Array)
|
||||
{
|
||||
return Enumerable.ToArray(temp);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
473
Command/CommandMath.cs
Normal file
473
Command/CommandMath.cs
Normal file
@@ -0,0 +1,473 @@
|
||||
using Common.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Command
|
||||
{
|
||||
public enum ComparisonFuncEnum
|
||||
{
|
||||
Big,
|
||||
BigOrEqual,
|
||||
Small,
|
||||
SmallOrEqual,
|
||||
Equal,
|
||||
NotEqual
|
||||
}
|
||||
|
||||
[ADPCommand]
|
||||
public static class CommandMath
|
||||
{
|
||||
#region 返回值是Double类型数据
|
||||
/// <summary>
|
||||
/// 两数相加(Param1 + Param2)
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:实数1</param>
|
||||
/// <param name="Param2">传入值:实数2</param>
|
||||
/// <example>Param1:9 Param2:2 返回值:11</example>
|
||||
/// <returns></returns>
|
||||
public static double ParamAdd(double Param1, double Param2)
|
||||
{
|
||||
return Param1 + Param2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 两数相减(Param1 - Param2)
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:实数1</param>
|
||||
/// <param name="Param2">传入值:实数2</param>
|
||||
/// <example>Param1:9 Param2:2 返回值:7</example>
|
||||
/// <returns></returns>
|
||||
public static double ParamReduce(double Param1, double Param2)
|
||||
{
|
||||
return Param1 - Param2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 两数相乘(Param1 * Param2)
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:实数1</param>
|
||||
/// <param name="Param2">传入值:实数2</param>
|
||||
/// <example>Param1:9 Param2:2 返回值:18</example>
|
||||
/// <returns></returns>
|
||||
public static double ParamMult(double Param1, double Param2)
|
||||
{
|
||||
return Param1 * Param2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 两数相除(Param1 / Param2)
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:实数1</param>
|
||||
/// <param name="Param2">传入值:实数2</param>
|
||||
/// <param name="Param3">传入值:保留几位小数</param>
|
||||
/// <example>Param1:10 Param2:3 Param3:3 返回值:3.333</example>
|
||||
/// <example>Param1:11 Param2:3 Param3:2 返回值:3.67</example>
|
||||
/// <returns></returns>
|
||||
public static double ParamDivide(double Param1, double Param2, int Param3)
|
||||
{
|
||||
return Math.Round((Param1 / Param2), Param3);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 两数相除求余(Param1 % Param2)
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:实数1</param>
|
||||
/// <param name="Param2">传入值:实数2</param>
|
||||
/// <example>Param1:9 Param2:2 返回值:1</example>
|
||||
/// <returns></returns>
|
||||
public static double ParamRemainder(double Param1, double Param2)
|
||||
{
|
||||
return Param1 % Param2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实数开根号
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:实数1</param>
|
||||
/// <example>Param1:16 返回值:4</example>
|
||||
/// <returns></returns>
|
||||
public static double ParamSquareRoot(double Param1)
|
||||
{
|
||||
return Math.Sqrt(Param1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实数的幂运算
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:实数1</param>
|
||||
/// <param name="Param2">传入值:实数1需要做几次方</param>
|
||||
/// <example>Param1:3 Param2:2 返回值:9</example>
|
||||
/// <example>Param1:2 Param2:3 返回值:8</example>
|
||||
/// <example>Param1:5 Param2:4 返回值:625</example>
|
||||
/// <returns></returns>
|
||||
public static double ParamPow(double Param1, double Param2)
|
||||
{
|
||||
return Math.Pow(Param1, Param2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实数的绝对值
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:实数1</param>
|
||||
/// <example>Param1:-3.7 返回值:3.7</example>
|
||||
/// <returns></returns>
|
||||
public static double ParamAbs(double Param1)
|
||||
{
|
||||
return Math.Abs(Param1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实数的向下取整
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:实数1</param>
|
||||
/// <example>Param1:3.7 返回值:3</example>
|
||||
/// <returns></returns>
|
||||
public static double ParamFloor(double Param1)
|
||||
{
|
||||
return Math.Floor(Param1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实数的向上取整
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:实数1</param>
|
||||
/// <example>Param1:3.7 返回值:4</example>
|
||||
/// <returns></returns>
|
||||
public static double ParamCeiling(double Param1)
|
||||
{
|
||||
return Math.Ceiling(Param1);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 返回值是String类型的数据
|
||||
/// <summary>
|
||||
/// A与B转换为double后比较,返回A比较B的结果
|
||||
/// </summary>
|
||||
/// <param name="a">比较数1</param>
|
||||
/// <param name="b">比较数2</param>
|
||||
/// <param name="比较方法">比较方法</param>
|
||||
/// <returns>返回A比较B</returns>
|
||||
public static bool Comparison(string a, string b, ComparisonFuncEnum 比较方法)
|
||||
{
|
||||
var aa = Convert.ToDouble(a);
|
||||
var bb = Convert.ToDouble(b);
|
||||
|
||||
switch (比较方法)
|
||||
{
|
||||
case ComparisonFuncEnum.Big:
|
||||
return aa > bb;
|
||||
case ComparisonFuncEnum.BigOrEqual:
|
||||
return aa >= bb;
|
||||
case ComparisonFuncEnum.Small:
|
||||
return aa < bb;
|
||||
case ComparisonFuncEnum.SmallOrEqual:
|
||||
return aa <= bb;
|
||||
case ComparisonFuncEnum.Equal:
|
||||
return aa == bb;
|
||||
case ComparisonFuncEnum.NotEqual:
|
||||
return aa != bb;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加法指令,转换为double后返回o1+o2
|
||||
/// </summary>
|
||||
/// <param name="o1">运算数1</param>
|
||||
/// <param name="o2">运算数2</param>
|
||||
/// <returns>返回o1+o2</returns>
|
||||
public static string TwoNumberAdd(string o1, string o2)
|
||||
{
|
||||
return (Convert.ToDecimal(o1) + Convert.ToDecimal(o2)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 减法指令,转换为double后返回o1-o2
|
||||
/// </summary>
|
||||
/// <param name="o1">运算数1</param>
|
||||
/// <param name="o2">运算数2</param>
|
||||
/// <returns>返回o1-o2</returns>
|
||||
public static string TwoNumberReduce(string o1, string o2)
|
||||
{
|
||||
return (Convert.ToDecimal(o1) - Convert.ToDecimal(o2)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 乘法指令,转换为double后返回o1*o2
|
||||
/// </summary>
|
||||
/// <param name="o1">运算数1</param>
|
||||
/// <param name="o2">运算数2</param>
|
||||
/// <returns>返回o1*o2</returns>
|
||||
public static string TwoNumberMult(string o1, string o2)
|
||||
{
|
||||
return (Convert.ToDecimal(o1) * Convert.ToDecimal(o2)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 除法指令,转换为double后返回o1/o2
|
||||
/// </summary>
|
||||
/// <param name="o1">运算数1</param>
|
||||
/// <param name="o2">运算数2</param>
|
||||
/// <returns>返回o1/o2</returns>
|
||||
public static string TwoNumberDivide1(string o1, string o2)
|
||||
{
|
||||
return (Convert.ToDecimal(o1) / Convert.ToDecimal(o2)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 转换为double后返回o1/o2
|
||||
/// </summary>
|
||||
/// <param name="o1">运算数1</param>
|
||||
/// <param name="o2">运算数2</param>
|
||||
/// <param name="o3">保留几位小数</param>
|
||||
/// <returns>返回o1/o2</returns>
|
||||
public static string TwoNumberDivide2(string o1, string o2, int o3)
|
||||
{
|
||||
return (Math.Round((Convert.ToDecimal(o1) / Convert.ToDecimal(o2)), o3)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回o1%o2
|
||||
/// </summary>
|
||||
/// <param name="o1">运算数1</param>
|
||||
/// <param name="o2">运算数2</param>
|
||||
/// <returns>返回o1%o2</returns>
|
||||
public static string TwoNumberRemainder(string o1, string o2)
|
||||
{
|
||||
return (Convert.ToDecimal(o1) % (Convert.ToDecimal(o2))).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算两个数字的平方。
|
||||
/// </summary>
|
||||
/// <param name="o1">第一个数字的字符串表示。</param>
|
||||
/// <param name="o2">第二个数字的字符串表示。</param>
|
||||
/// <example>Param1:3 Param2:2 返回值:9</example>
|
||||
/// <example>Param1:2 Param2:3 返回值:8</example>
|
||||
/// <example>Param1:5 Param2:4 返回值:625</example>
|
||||
/// <returns>返回两个数字的平方的字符串表示。</returns>
|
||||
public static string NumberPow(string o1, string o2)
|
||||
{
|
||||
// 将输入的字符串转换为双精度浮点数,并计算它们的平方
|
||||
// 最后将结果转换为字符串并返回
|
||||
return Math.Pow(Convert.ToDouble(o1), Convert.ToDouble(o2)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算一个数的平方根。
|
||||
/// </summary>
|
||||
/// <param name="o1">要计算平方根的数字的字符串表示。</param>
|
||||
/// <returns>返回输入数字的平方根的字符串表示。</returns>
|
||||
public static string NumberSqrt(string o1)
|
||||
{
|
||||
// 将输入的字符串转换为双精度浮点数,并计算其平方根。
|
||||
// 最后将结果转换为字符串并返回。
|
||||
return Math.Sqrt(Convert.ToDouble(o1)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算一个数的绝对值。
|
||||
/// </summary>
|
||||
/// <param name="o1">要计算绝对值的数字的字符串表示。</param>
|
||||
/// <returns>返回输入数字的绝对值的字符串表示。</returns>
|
||||
public static string NumberAbs(string o1)
|
||||
{
|
||||
// 将输入的字符串转换为双精度浮点数,并计算其绝对值。
|
||||
// 最后将结果转换为字符串并返回。
|
||||
return Math.Abs(Convert.ToDouble(o1)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算一个角度的正弦值。
|
||||
/// </summary>
|
||||
/// <param name="o1">要计算正弦值的角度的字符串表示(单位为弧度)。</param>
|
||||
/// <returns>返回输入角度的正弦值的字符串表示。</returns>
|
||||
public static string NumberSin(string o1)
|
||||
{
|
||||
// 将输入的字符串转换为双精度浮点数,并计算其正弦值。
|
||||
// 最后将结果转换为字符串并返回。
|
||||
return Math.Sin(Convert.ToDouble(o1)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算一个角度的余弦值。
|
||||
/// </summary>
|
||||
/// <param name="o1">要计算余弦值的角度的字符串表示(单位为弧度)。</param>
|
||||
/// <returns>返回输入角度的余弦值的字符串表示。</returns>
|
||||
public static string NumberCos(string o1)
|
||||
{
|
||||
// 将输入的字符串转换为双精度浮点数,并计算其余弦值。
|
||||
// 最后将结果转换为字符串并返回。
|
||||
return Math.Cos(Convert.ToDouble(o1)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算一个角度的正切值。
|
||||
/// </summary>
|
||||
/// <param name="o1">要计算正切值的角度的字符串表示(单位为弧度)。</param>
|
||||
/// <returns>返回输入角度的正切值的字符串表示。</returns>
|
||||
public static string NumberTan(string o1)
|
||||
{
|
||||
// 将输入的字符串转换为双精度浮点数,并计算其正切值。
|
||||
// 最后将结果转换为字符串并返回。
|
||||
return Math.Tan(Convert.ToDouble(o1)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算一个数的反正弦值。
|
||||
/// </summary>
|
||||
/// <param name="o1">要计算反正弦值的数的字符串表示。</param>
|
||||
/// <returns>返回输入数的反正弦值的字符串表示(单位为弧度)。</returns>
|
||||
public static string NumberASin(string o1)
|
||||
{
|
||||
// 将输入的字符串转换为双精度浮点数,并计算其反正弦值。
|
||||
// 最后将结果转换为字符串并返回。
|
||||
return Math.Asin(Convert.ToDouble(o1)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算一个数的反余弦值。
|
||||
/// </summary>
|
||||
/// <param name="o1">要计算反余弦值的数的字符串表示。</param>
|
||||
/// <returns>返回输入数的反余弦值的字符串表示(单位为弧度)。</returns>
|
||||
public static string NumberACos(string o1)
|
||||
{
|
||||
// 将输入的字符串转换为双精度浮点数,并计算其反余弦值。
|
||||
// 最后将结果转换为字符串并返回。
|
||||
return Math.Acos(Convert.ToDouble(o1)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算一个数的反正切值。
|
||||
/// </summary>
|
||||
/// <param name="o1">要计算反正切值的数的字符串表示。</param>
|
||||
/// <returns>返回输入数的反正切值的字符串表示(单位为弧度)。</returns>
|
||||
public static string NumberATan(string o1)
|
||||
{
|
||||
// 将输入的字符串转换为双精度浮点数,并计算其反正切值。
|
||||
// 最后将结果转换为字符串并返回。
|
||||
return Math.Atan(Convert.ToDouble(o1)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算 e 的给定次幂。
|
||||
/// </summary>
|
||||
/// <param name="o1">e 的指数的字符串表示。</param>
|
||||
/// <returns>返回 e 的给定次幂的字符串表示。</returns>
|
||||
public static string eIndex(string o1)
|
||||
{
|
||||
// 将输入的字符串转换为双精度浮点数,并计算 e 的给定次幂。
|
||||
// 最后将结果转换为字符串并返回。
|
||||
return Math.Exp(Convert.ToDouble(o1)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算一个数的自然对数。
|
||||
/// </summary>
|
||||
/// <param name="o1">要计算自然对数的数的字符串表示。</param>
|
||||
/// <returns>返回输入数的自然对数的字符串表示。</returns>
|
||||
public static string NumberNaturalLogarithm(string o1)
|
||||
{
|
||||
// 将输入的字符串转换为双精度浮点数,并计算其自然对数。
|
||||
// 最后将结果转换为字符串并返回。
|
||||
return Math.Log(Convert.ToDouble(o1)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算一个数在指定基数下的对数。
|
||||
/// </summary>
|
||||
/// <param name="o1">要计算对数的数的字符串表示。</param>
|
||||
/// <param name="Base">对数的基数的字符串表示。</param>
|
||||
/// <returns>返回输入数在指定基数下的对数的字符串表示。</returns>
|
||||
public static string NumberLogarithm(string o1, string Base)
|
||||
{
|
||||
// 将输入的字符串转换为双精度浮点数,并计算其在指定基数下的对数。
|
||||
// 最后将结果转换为字符串并返回。
|
||||
return Math.Log(Convert.ToDouble(o1), Convert.ToDouble(Base)).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 对输入数字进行四舍五入取整。
|
||||
/// </summary>
|
||||
/// <param name="n1">要进行取整操作的数字的字符串表示。</param>
|
||||
/// <returns>返回经过四舍五入取整后的结果的字符串表示。</returns>
|
||||
public static string NumberRoundToNearest(string n1)
|
||||
{
|
||||
// 将输入的字符串转换为双精度浮点数,并进行四舍五入取整。
|
||||
// 最后将结果转换为字符串并返回。
|
||||
return Math.Round(Convert.ToDouble(n1)).ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对输入数字进行向上舍入取整。
|
||||
/// </summary>
|
||||
/// <param name="n1">要进行取整操作的数字的字符串表示。</param>
|
||||
/// <returns>返回经过向上舍入取整后的结果的字符串表示。</returns>
|
||||
public static string NumberRoundUp(string n1)
|
||||
{
|
||||
// 将输入的字符串转换为双精度浮点数,并进行向上舍入取整。
|
||||
// 最后将结果转换为字符串并返回。
|
||||
return Math.Ceiling(Convert.ToDouble(n1)).ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对输入数字进行向下舍入取整。
|
||||
/// </summary>
|
||||
/// <param name="n1">要进行取整操作的数字的字符串表示。</param>
|
||||
/// <returns>返回经过向下舍入取整后的结果的字符串表示。</returns>
|
||||
public static string NumberRoundDown(string n1)
|
||||
{
|
||||
// 将输入的字符串转换为双精度浮点数,并进行向下舍入取整。
|
||||
// 最后将结果转换为字符串并返回。
|
||||
return Math.Floor(Convert.ToDouble(n1)).ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取圆周率π的字符串表示。
|
||||
/// </summary>
|
||||
/// <returns>返回圆周率π的字符串表示。</returns>
|
||||
public static string PI()
|
||||
{
|
||||
// 返回圆周率π的字符串表示。
|
||||
return Math.PI.ToString();
|
||||
}
|
||||
|
||||
//public static Random random1 = new Random();
|
||||
/// <summary>
|
||||
/// 生成一个随机整数。
|
||||
/// </summary>
|
||||
/// <returns>返回生成的随机整数的字符串表示。</returns>
|
||||
public static string RandomNumber_Int()
|
||||
{
|
||||
Random random = new Random();
|
||||
// 使用随机数生成器生成一个随机整数,并将其转换为字符串表示。
|
||||
return random.Next().ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成一个指定范围内的随机整数。
|
||||
/// </summary>
|
||||
/// <param name="最小">随机数生成范围的最小值。</param>
|
||||
/// <param name="最大">随机数生成范围的最大值(不包含)。</param>
|
||||
/// <returns>返回生成的指定范围内的随机整数的字符串表示。</returns>
|
||||
public static string RandomNumber_RangeInt(int 最小, int 最大)
|
||||
{
|
||||
Random random = new Random();
|
||||
// 使用随机数生成器生成一个指定范围内的随机整数,并将其转换为字符串表示。
|
||||
return random.Next(最小, 最大).ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成一个随机小数。
|
||||
/// </summary>
|
||||
/// <returns>返回生成的随机小数的字符串表示。</returns>
|
||||
public static string RandomNumber_Decimal()
|
||||
{
|
||||
Random random = new Random();
|
||||
// 使用随机数生成器生成一个随机小数,并将其转换为字符串表示。
|
||||
return random.NextDouble().ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算给定算式的结果。
|
||||
/// </summary>
|
||||
/// <param name="s">要计算的算式的字符串表示。</param>
|
||||
/// <returns>返回计算结果的字符串表示。</returns>
|
||||
public static string FormulaCalculation(string s)
|
||||
{
|
||||
// 创建一个 DataTable 实例来进行算式的计算。
|
||||
DataTable dataTable = new DataTable();
|
||||
// 使用 DataTable 的 Compute 方法计算给定的算式,并将结果转换为字符串表示。
|
||||
return dataTable.Compute(s, "").ToString();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
153
Command/CommandRadixChange.cs
Normal file
153
Command/CommandRadixChange.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
using Common.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Command
|
||||
{
|
||||
|
||||
[ADPCommand]
|
||||
public static class CommandRadixChange
|
||||
{
|
||||
#region 进制转换
|
||||
/// <summary>
|
||||
/// 二进制 转换成 八进制
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:字符类型</param>
|
||||
/// <example>Param1:"101010" 返回值:"52"</example>
|
||||
/// <returns></returns>
|
||||
public static string TwoRadix_ConvertTo_EightRadix(string Param1)
|
||||
{
|
||||
return Convert.ToString(Convert.ToInt32(Param1, 2),8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 二进制 转换成 十进制
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:字符类型</param>
|
||||
/// <example>Param1:"101010" 返回值:"42"</example>
|
||||
/// <returns></returns>
|
||||
public static string TwoRadix_ConvertTo_TenRadix(string Param1)
|
||||
{
|
||||
return Convert.ToString(Convert.ToInt32(Param1, 2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 二进制 转换成 十六进制
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:字符类型</param>
|
||||
/// <example>Param1:"101010" 返回值:"2A"</example>
|
||||
/// <returns></returns>
|
||||
public static string TwoRadix_ConvertTo_SixteenRadix(string Param1)
|
||||
{
|
||||
return Convert.ToString(Convert.ToInt32(Param1, 2), 16);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 八进制 转换成 二进制
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:字符类型</param>
|
||||
/// <example>Param1:"88" 返回值:"1001000"</example>
|
||||
/// <returns></returns>
|
||||
public static string EightRadix_ConvertTo_TwoRadix(string Param1)
|
||||
{
|
||||
return Convert.ToString(Convert.ToInt32(Param1, 8), 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 八进制 转换成 十进制
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:字符类型</param>
|
||||
/// <example>Param1:"88" 返回值:"72"</example>
|
||||
/// <returns></returns>
|
||||
public static double EightRadix_ConvertTo_TenRadix(string Param1)
|
||||
{
|
||||
double Value = Convert.ToInt32(Param1, 8);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 八进制 转换成 十六进制
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:字符类型</param>
|
||||
/// <example>Param1:"88" 返回值:"48"</example>
|
||||
/// <returns></returns>
|
||||
public static string EightRadix_ConvertTo_SixteenRadix(string Param1)
|
||||
{
|
||||
return Convert.ToString(Convert.ToInt32(Param1, 8), 16);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 十进制 转换成 二进制
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:整型数值</param>
|
||||
/// <example>Param1:60 返回值:"111100"</example>
|
||||
/// <returns></returns>
|
||||
public static string TenRadix_ConvertTo_TwoRadix(int Param1)
|
||||
{
|
||||
return Convert.ToString(Param1, 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 十进制 转换成 八进制
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:整型数值</param>
|
||||
/// <example>Param1:60 返回值:"74"</example>
|
||||
/// <returns></returns>
|
||||
public static string TenRadix_ConvertTo_EightRadix(int Param1)
|
||||
{
|
||||
return Convert.ToString(Param1, 8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 十进制 转换成 十六进制
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:整型数值</param>
|
||||
/// <example>Param1:60 返回值:"3C"</example>
|
||||
/// <returns></returns>
|
||||
public static string TenRadix_ConvertTo_SixteenRadix(int Param1)
|
||||
{
|
||||
return Convert.ToString(Param1, 16);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 十六进制 转换成 二进制
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:字符类型</param>
|
||||
/// <example>Param1:"6F" 返回值:"1101111"</example>
|
||||
/// <returns></returns>
|
||||
public static string SixteenRadix_ConvertTo_Radix2(string Param1)
|
||||
{
|
||||
return Convert.ToString(Convert.ToInt32(Param1, 16), 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 十六进制 转换成 八进制
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:字符类型</param>
|
||||
/// <example>Param1:"6F" 返回值:"157"</example>
|
||||
/// <returns></returns>
|
||||
public static string SixteenRadix_ConvertTo_EightRadix8(string Param1)
|
||||
{
|
||||
return Convert.ToString(Convert.ToInt32(Param1, 16), 8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 十六进制 转换成 十进制
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:字符类型</param>
|
||||
/// <example>Param1:"6F" 返回值:"111"</example>
|
||||
/// <returns></returns>
|
||||
public static string SixteenRadix_ConvertTo_TenRadix(string Param1)
|
||||
{
|
||||
return Convert.ToString(Convert.ToInt32(Param1, 16));
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
196
Command/CommandStringProcessing.cs
Normal file
196
Command/CommandStringProcessing.cs
Normal file
@@ -0,0 +1,196 @@
|
||||
using Common.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Command
|
||||
{
|
||||
|
||||
[ADPCommand]
|
||||
public static class CommandStringProcessing
|
||||
{
|
||||
///<summary>
|
||||
///获取值
|
||||
///</summary>
|
||||
///<param name="obj">要获取的值。</param>
|
||||
///returns>获取值(字符串)。</returns>
|
||||
public static string GetValue(object obj)
|
||||
{
|
||||
return Convert.ToString(obj) ?? string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在原字符串中查找指定字符的位置。
|
||||
/// </summary>
|
||||
/// <param name="str">要查找的字符串。</param>
|
||||
/// <param name="findStr">要查找的字符。</param>
|
||||
/// <returns>字符在字符串中的位置,如果未找到则返回 -1。</returns>
|
||||
public static int FindStr(string str, string findStr)
|
||||
{
|
||||
return str.IndexOf(findStr);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将原字符串中的指定字符替换为新字符。
|
||||
/// </summary>
|
||||
/// <param name="str">要替换的字符串。</param>
|
||||
/// <param name="ReplaceStr">要被替换的字符。</param>
|
||||
/// <param name="ReplacedStr">替换后的新字符。</param>
|
||||
/// <returns>替换后的字符串。</returns>
|
||||
public static string ReplaceStr(string str, string ReplaceStr, string ReplacedStr)
|
||||
{
|
||||
return str.Replace(ReplaceStr, ReplacedStr);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从原字符串中移除指定位置开始的指定个数的字符。
|
||||
/// </summary>
|
||||
/// <param name="str">要操作的字符串。</param>
|
||||
/// <param name="startLocation">开始移除字符的位置。</param>
|
||||
/// <param name="removeQty">要移除的字符个数。</param>
|
||||
/// <returns>移除后的字符串。</returns>
|
||||
public static string RemoveStr(string str, int startLocation, int removeQty)
|
||||
{
|
||||
return str.Remove(startLocation, removeQty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在原字符串的指定位置插入新字符串。
|
||||
/// </summary>
|
||||
/// <param name="str">要操作的字符串。</param>
|
||||
/// <param name="startLocation">要插入字符串的位置。</param>
|
||||
/// <param name="newStr">要插入的字符串。</param>
|
||||
/// <returns>插入后的字符串。</returns>
|
||||
public static string InsertStr(string str, int startLocation, string newStr)
|
||||
{
|
||||
return str.Insert(startLocation, newStr);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从原字符串中截取指定位置开始的指定个数的字符。
|
||||
/// </summary>
|
||||
/// <param name="str">要操作的字符串。</param>
|
||||
/// <param name="startLocation">要截取的起始位置。</param>
|
||||
/// <param name="qty">要截取的字符个数。</param>
|
||||
/// <returns>截取后的字符串。</returns>
|
||||
public static string CaptureStr(string str, int startLocation, int qty)
|
||||
{
|
||||
return str.Substring(startLocation, qty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串转换为小写形式。
|
||||
/// </summary>
|
||||
/// <param name="str">要转换的字符串。</param>
|
||||
/// <returns>转换为小写后的字符串。</returns>
|
||||
public static string StrConvertToLower(string str)
|
||||
{
|
||||
return str.ToLower();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串转换为大写形式。
|
||||
/// </summary>
|
||||
/// <param name="str">要转换的字符串。</param>
|
||||
/// <returns>转换为大写后的字符串。</returns>
|
||||
public static string StrConvertToUpper(string str)
|
||||
{
|
||||
return str.ToUpper();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取字符串的长度。
|
||||
/// </summary>
|
||||
/// <param name="str">要获取长度的字符串。</param>
|
||||
/// <returns>字符串的长度。</returns>
|
||||
public static int GetStrLength(string str)
|
||||
{
|
||||
return str.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 去除字符串两端的空白字符。
|
||||
/// </summary>
|
||||
/// <param name="str">要去除空白字符的字符串。</param>
|
||||
/// <returns>去除空白字符后的字符串。</returns>
|
||||
public static string StrRemoveLeadingAndTrailingWhitespaces(string str)
|
||||
{
|
||||
return str.Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字节数组转换为字符串,使用 UTF-8 编码。
|
||||
/// </summary>
|
||||
/// <param name="arr">要转换的字节数组。</param>
|
||||
/// <returns>转换后的字符串。</returns>
|
||||
public static string ByteArrayToStr_UTF8(byte[] arr)
|
||||
{
|
||||
return Encoding.UTF8.GetString(arr);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字节数组转换为字符串,使用 GB18030 编码。
|
||||
/// </summary>
|
||||
/// <param name="arr">要转换的字节数组。</param>
|
||||
/// <returns>转换后的字符串。</returns>
|
||||
public static string ByteArrayToStr_GB18030(byte[] arr)
|
||||
{
|
||||
return Encoding.GetEncoding("gb18030").GetString(arr);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字节数组转换为字符串,使用自选的编码类型。
|
||||
/// </summary>
|
||||
/// <param name="arr">要转换的字节数组。</param>
|
||||
/// <param name="encodingType">要使用的编码类型。</param>
|
||||
/// <returns>转换后的字符串。</returns>
|
||||
public static string ByteArrayToStr_SelfSelectedEncoding(byte[] arr, string encodingType)
|
||||
{
|
||||
return Encoding.GetEncoding(encodingType).GetString(arr);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字节数组转换为16进制字符串
|
||||
/// </summary>
|
||||
/// <param name="str">要转换的字节数组。</param>
|
||||
/// <returns>转换后的字符串。</returns>
|
||||
public static string ByteArrayTo_HexStr(byte[] str)
|
||||
{
|
||||
return Convert.ToInt32(str.ToString(),2).ToString("X2");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串转换为字节数组,使用 UTF-8 编码。
|
||||
/// </summary>
|
||||
/// <param name="str">要转换的字符串。</param>
|
||||
/// <returns>转换后的字节数组。</returns>
|
||||
public static byte[] StrToByteArray_UTF8(string str)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(str);
|
||||
}
|
||||
/// <summary>
|
||||
/// 将字符串转换为字节数组,使用 GB18030 编码。
|
||||
/// </summary>
|
||||
/// <param name="str">要转换的字符串。</param>
|
||||
/// <returns>转换后的字节数组。</returns>
|
||||
public static byte[] StrToByteArray_GB18030(string str)
|
||||
{
|
||||
return Encoding.GetEncoding("gb18030").GetBytes(str);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串转换为字节数组,使用自选的编码类型。
|
||||
/// </summary>
|
||||
/// <param name="str">要转换的字符串。</param>
|
||||
/// <param name="encodingType">要使用的编码类型。</param>
|
||||
/// <returns>转换后的字节数组。</returns>
|
||||
public static byte[] StrToByteArray_SelfSelectedEncoding(string str, string encodingType)
|
||||
{
|
||||
return Encoding.GetEncoding(encodingType).GetBytes(str);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
463
Command/CommandSystem.cs
Normal file
463
Command/CommandSystem.cs
Normal file
@@ -0,0 +1,463 @@
|
||||
using Common.Attributes;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Command
|
||||
{
|
||||
[ADPCommand]
|
||||
public static class CommandSystem
|
||||
{
|
||||
#region 类型转换
|
||||
/// <summary>
|
||||
/// int转化为double
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:整型数值</param>
|
||||
/// <example>Param1:40 返回值:40</example>
|
||||
/// <returns></returns>
|
||||
public static double Int_ConvertTo_Double(int Param1)
|
||||
{
|
||||
return Convert.ToDouble(Param1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// double转化为Int16
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:实数数值</param>
|
||||
/// <example>Param1:4 返回值:4</example>
|
||||
/// <example>Param1:4.67 返回值:4</example>
|
||||
/// <returns></returns>
|
||||
public static Int16 Double_ConvertTo_Int16(double Param1)
|
||||
{
|
||||
Int16 Value = Convert.ToInt16(Param1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// double转化为int,即Int32
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:实数数值</param>
|
||||
/// <example>Param1:4 返回值:4</example>
|
||||
/// <example>Param1:4.67 返回值:4</example>
|
||||
/// <returns></returns>
|
||||
public static int Double_ConvertTo_Int(double Param1)
|
||||
{
|
||||
int Value = Convert.ToInt32(Param1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// double转化为Int64
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:实数数值</param>
|
||||
/// <example>Param1:4 返回值:4</example>
|
||||
/// <example>Param1:4.67 返回值:4</example>
|
||||
/// <returns></returns>
|
||||
public static Int64 Double_ConvertTo_Int64(double Param1)
|
||||
{
|
||||
Int64 Value = Convert.ToInt64(Param1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// float转化为double
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:浮点数值</param>
|
||||
/// <example>Param1:4.0 返回值:4</example>
|
||||
/// <example>Param1:4.2 返回值:4.2</example>
|
||||
/// <returns></returns>
|
||||
public static double Float_ConvertTo_Double(float Param1)
|
||||
{
|
||||
double Value = Convert.ToDouble(Param1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断string转化为int,转换成功返回 true,失败返回 false
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:字符串</param>
|
||||
/// <example>Param1:"2" 返回值:true</example>
|
||||
/// <example>Param1:"abc" 返回值:false</example>
|
||||
/// <returns></returns>
|
||||
public static bool BoolString_ConvertTo_Int(string Param1)
|
||||
{
|
||||
bool Value = int.TryParse(Param1, out int intValue);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// string转化为int
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:字符串</param>
|
||||
/// <example>Param1:"2" 返回值:2</example>
|
||||
/// <returns></returns>
|
||||
public static int String_ConvertTo_Int(string Param1)
|
||||
{
|
||||
int Value = Convert.ToInt32(Param1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// int转化为string
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:整型数值</param>
|
||||
/// <example>Param1:2 返回值:"2"</example>
|
||||
/// <returns></returns>
|
||||
public static string Int_ConvertTo_String(int Param1)
|
||||
{
|
||||
string Value = Convert.ToString(Param1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断string转化为double,转换成功返回 true,失败返回 false
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:字符串</param>
|
||||
/// <example>Param1:"2" 返回值:true</example>
|
||||
/// <example>Param1:"2.1" 返回值:true</example>
|
||||
/// <example>Param1:"abc" 返回值:false</example>
|
||||
/// <returns></returns>
|
||||
public static bool BoolString_ConvertTo_Double(string Param1)
|
||||
{
|
||||
bool Value = double.TryParse(Param1, out double intValue);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// string转化为double
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:字符串</param>
|
||||
/// <example>Param1:"2" 返回值:2</example>
|
||||
/// <example>Param1:"2.1" 返回值:2.1</example>
|
||||
/// <returns></returns>
|
||||
public static double String_ConvertTo_Double(string Param1)
|
||||
{
|
||||
double Value = Convert.ToDouble(Param1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// double转化为string
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:实数数值</param>
|
||||
/// <example>Param1:2 返回值:"2"</example>
|
||||
/// <example>Param1:2.1 返回值:"2.1"</example>
|
||||
/// <returns></returns>
|
||||
public static string Double_ConvertTo_String(double Param1)
|
||||
{
|
||||
string Value = Convert.ToString(Param1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// float转化为string
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:浮点数值</param>
|
||||
/// <example>Param1:2.0 返回值:"2.0"</example>
|
||||
/// <example>Param1:2.1 返回值:"2.1"</example>
|
||||
/// <returns></returns>
|
||||
public static string Float_ConvertTo_String(float Param1)
|
||||
{
|
||||
string Value = Convert.ToString(Param1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断string转化为datetime,转换成功返回 true,失败返回 false
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:时间字符串</param>
|
||||
/// <example>Param1:"2025-08-14" 返回值:true</example>
|
||||
/// <example>Param1:"2025-08-14 13:14:15" 返回值:true</example>
|
||||
/// <example>Param1:"abc" 返回值:false</example>
|
||||
/// <returns></returns>
|
||||
public static bool BoolString_ConvertTo_Datetime(string Param1)
|
||||
{
|
||||
bool Value = DateTime.TryParse(Param1, out DateTime DateTimeValue);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// string转化为datetime
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:时间字符串</param>
|
||||
/// <example>Param1:"2025-08-14" 返回值:2025/8/14 0:00:00</example>
|
||||
/// <example>Param1:"2025-08-14 13:14:15" 返回值:2025/8/14 13:14:15</example>
|
||||
/// <returns></returns>
|
||||
public static DateTime String_ConvertTo_Datetime(string Param1)
|
||||
{
|
||||
DateTime Value = Convert.ToDateTime(Param1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// datetime转化为string
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:时间</param>
|
||||
/// <example>Param1:2025/8/14 13:14:15 返回值:"2025/08/14 13:14:15"</example>
|
||||
/// <returns></returns>
|
||||
public static string Datetime_ConvertTo_String1(DateTime Param1)
|
||||
{
|
||||
string Value = Convert.ToString(Param1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// datetime转化为string
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:时间</param>
|
||||
/// <param name="DateTimeFormat">传入值:字符串时间格式</param>
|
||||
/// <example>Param1:2025/8/14 13:14:15 DateTimeFormat:"yyyy-MM-dd" 返回值:"2025-08-14"</example>
|
||||
/// <example>Param1:2025/8/14 13:14:15 DateTimeFormat:"yyyy-MM-dd hh:mm:ss" 返回值:"2025-08-14 01:14:15"</example>
|
||||
/// <example>Param1:2025/8/14 13:14:15 DateTimeFormat:"yyyy-MM-dd HH:mm:ss" 返回值:"2025-08-14 13:14:15"</example>
|
||||
/// <example>Param1:2025/8/14 13:14:15 DateTimeFormat:"yyyyMMdd" 返回值:"20250814"</example>
|
||||
/// <returns></returns>
|
||||
public static string Datetime_ConvertTo_String2(DateTime Param1,string DateTimeFormat)
|
||||
{
|
||||
string Value = Param1.ToString(DateTimeFormat);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// bool转化为string
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:布尔值</param>
|
||||
/// <example>Param1:true 返回值:"true"</example>
|
||||
/// <example>Param1:false 返回值:"false"</example>
|
||||
/// <returns></returns>
|
||||
public static string Bool_ConvertTo_String(bool Param1)
|
||||
{
|
||||
string Value = Convert.ToString(Param1);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// string转化为bool
|
||||
/// </summary>
|
||||
/// <param name="Param1">传入值:字符串</param>
|
||||
/// <example>Param1:"true" 返回值:true</example>
|
||||
/// <example>Param1:"false" 返回值:false</example>
|
||||
/// <example>Param1:"abc" 返回值:false</example>
|
||||
/// <returns></returns>
|
||||
public static bool String_ConvertTo_Bool(string Param1)
|
||||
{
|
||||
bool Value = bool.TryParse(Param1, out bool boolValue);
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将无符号整型转换为整型
|
||||
/// </summary>
|
||||
/// <param name="u"></param>
|
||||
/// <returns></returns>
|
||||
public static int Uint_ConvertTo_Int(uint u)
|
||||
{
|
||||
return (int)u;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将对象转换为字符串
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static string Object_ConvertTo_String(object obj)
|
||||
{
|
||||
return Convert.ToString(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串内容转换为byte
|
||||
/// </summary>
|
||||
/// <param name="s">要转换的内容</param>
|
||||
/// <returns></returns>
|
||||
public static byte String_ConvertTo_Byte(string s)
|
||||
{
|
||||
return Convert.ToByte(s);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换为short(int16)
|
||||
/// </summary>
|
||||
/// <param name="s">要转换的内容</param>
|
||||
/// <returns></returns>
|
||||
public static short String_ConvertTo_Short(string s)
|
||||
{
|
||||
return Convert.ToInt16(s);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串转换为无符号整数。
|
||||
/// </summary>
|
||||
/// <param name="s">要转换的字符串。</param>
|
||||
/// <returns>转换后的无符号整数。</returns>
|
||||
public static uint String_ConvertTo_Uint(string s)
|
||||
{
|
||||
return Convert.ToUInt32(s);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将指定进制的字符串转换为整数。
|
||||
/// </summary>
|
||||
/// <param name="s">要转换的字符串。</param>
|
||||
/// <param name="XRadix">源字符串的进制。只能为2,8,10,16</param>
|
||||
/// <returns>转换后的整数。</returns>
|
||||
public static int XRadixString_ConvertTo_Int(string s, int XRadix)
|
||||
{
|
||||
return Convert.ToInt32(s, XRadix);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 逻辑操作
|
||||
/// <summary>
|
||||
/// 执行整数的异或操作。
|
||||
/// </summary>
|
||||
/// <param name="a">第一个整数。</param>
|
||||
/// <param name="b">第二个整数。</param>
|
||||
/// <returns>异或操作结果。</returns>
|
||||
public static int XOR(int a, int b)
|
||||
{
|
||||
return a ^ b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行整数的位或操作。
|
||||
/// </summary>
|
||||
/// <param name="a">第一个整数。</param>
|
||||
/// <param name="b">第二个整数。</param>
|
||||
/// <returns>位或操作结果。</returns>
|
||||
public static int BitwiseOR(int a, int b)
|
||||
{
|
||||
return a | b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行整数的位与操作。
|
||||
/// </summary>
|
||||
/// <param name="a">第一个整数。</param>
|
||||
/// <param name="b">第二个整数。</param>
|
||||
/// <returns>位与操作结果。</returns>
|
||||
public static int BitwiseAND(int a, int b)
|
||||
{
|
||||
return a & b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将整数向左移动指定位数。
|
||||
/// </summary>
|
||||
/// <param name="a">要移动的整数。</param>
|
||||
/// <param name="BitwiseLeftShift">左移的位数。</param>
|
||||
/// <returns>移动后的结果。</returns>
|
||||
public static int LeftShift(int a, int BitwiseLeftShift)
|
||||
{
|
||||
return a << BitwiseLeftShift;
|
||||
}
|
||||
/// <summary>
|
||||
/// 将整数向右移动指定位数。
|
||||
/// </summary>
|
||||
/// <param name="a">要移动的整数。</param>
|
||||
/// <param name="BitwiseRightShift">右移的位数。</param>
|
||||
/// <returns>移动后的结果。</returns>
|
||||
public static int RightShift(int a, int BitwiseRightShift)
|
||||
{
|
||||
return a >> BitwiseRightShift;
|
||||
}
|
||||
/// <summary>
|
||||
/// 执行逻辑或操作。
|
||||
/// </summary>
|
||||
/// <param name="a">第一个逻辑值。</param>
|
||||
/// <param name="b">第二个逻辑值。</param>
|
||||
/// <returns>逻辑或操作结果。</returns>
|
||||
public static bool LogicalOR(bool a, bool b)
|
||||
{
|
||||
return a || b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行逻辑与操作。
|
||||
/// </summary>
|
||||
/// <param name="a">第一个逻辑值。</param>
|
||||
/// <param name="b">第二个逻辑值。</param>
|
||||
/// <returns>逻辑与操作结果。</returns>
|
||||
public static bool LogicalAND(bool a, bool b)
|
||||
{
|
||||
return a && b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字节的高低位对调。
|
||||
/// </summary>
|
||||
/// <param name="b">要对调的字节。</param>
|
||||
/// <returns>对调后的字节。</returns>
|
||||
public static byte ByteHighAndLowBitSwap(byte b)
|
||||
{
|
||||
return (byte)(((b & 0x0F) << 4) | ((b & 0xF0) >> 4));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 翻转字节数组中的元素顺序。
|
||||
/// </summary>
|
||||
/// <param name="b">要翻转的字节数组。</param>
|
||||
/// <returns>翻转后的字节数组。</returns>
|
||||
public static byte[] ByteArrayReverse(byte[] b)
|
||||
{
|
||||
return b.Reverse().ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将当前线程挂起指定的时间。
|
||||
/// </summary>
|
||||
/// <param name="time">要延时的时间,以毫秒为单位。</param>
|
||||
public static void Delay_ms(int time)
|
||||
{
|
||||
Thread.Sleep(time);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将当前线程挂起指定的时间。
|
||||
/// </summary>
|
||||
/// <param name="time">要延时的时间,以秒为单位。</param>
|
||||
public static void Delay_s(int time)
|
||||
{
|
||||
Thread.Sleep(time * 1000);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将当前线程挂起指定的时间。
|
||||
/// </summary>
|
||||
/// <param name="time">要延时的时间,以分钟为单位。</param>
|
||||
public static void Delay_min(int time)
|
||||
{
|
||||
Thread.Sleep(time * 1000 * 60);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将当前线程挂起指定的时间。
|
||||
/// </summary>
|
||||
/// <param name="time">要延时的时间,以小时为单位。</param>
|
||||
public static void Delay_hour(int time)
|
||||
{
|
||||
Thread.Sleep(time * 1000 * 60 * 60);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将当前线程挂起指定的时间。
|
||||
/// </summary>
|
||||
/// <param name="time">要延时的时间,以天为单位。</param>
|
||||
public static void Delay_day(int time)
|
||||
{
|
||||
Thread.Sleep(time * 1000 * 60 * 60 * 24);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
95
Command/CommandTime.cs
Normal file
95
Command/CommandTime.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using Common.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Command
|
||||
{
|
||||
|
||||
[ADPCommand]
|
||||
public static class CommandTime
|
||||
{
|
||||
#region 时间处理
|
||||
/// <summary>
|
||||
/// 获取给定时间段的总毫秒数。
|
||||
/// </summary>
|
||||
/// <param name="TimePeriod">要获取总毫秒数的时间段。</param>
|
||||
/// <returns>返回时间段的总毫秒数。</returns>
|
||||
public static double GetTimePeriodMilliseconds(TimeSpan TimePeriod)
|
||||
{
|
||||
// 返回时间段的总毫秒数。
|
||||
return TimePeriod.TotalMilliseconds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取给定时间段的总秒数。
|
||||
/// </summary>
|
||||
/// <param name="TimePeriod">要获取总秒数的时间段。</param>
|
||||
/// <returns>返回时间段的总秒数。</returns>
|
||||
public static double GetTimePeriodSeconds(TimeSpan TimePeriod)
|
||||
{
|
||||
// 返回时间段的总秒数。
|
||||
return TimePeriod.TotalSeconds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取给定时间段的总分钟数。
|
||||
/// </summary>
|
||||
/// <param name="TimePeriod">要获取总分钟数的时间段。</param>
|
||||
/// <returns>返回时间段的总分钟数。</returns>
|
||||
public static double GetTimePeriodMinutes(TimeSpan TimePeriod)
|
||||
{
|
||||
// 返回时间段的总分钟数。
|
||||
return TimePeriod.TotalMinutes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取给定时间段的总小时数。
|
||||
/// </summary>
|
||||
/// <param name="TimePeriod">要获取总小时数的时间段。</param>
|
||||
/// <returns>返回时间段的总小时数。</returns>
|
||||
public static double GetTimePeriodHours(TimeSpan TimePeriod)
|
||||
{
|
||||
// 返回时间段的总小时数。
|
||||
return TimePeriod.TotalHours;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取给定时间段的总天数。
|
||||
/// </summary>
|
||||
/// <param name="TimePeriod">要获取总天数的时间段。</param>
|
||||
/// <returns>返回时间段的总天数。</returns>
|
||||
public static double GetTimePeriodDays(TimeSpan TimePeriod)
|
||||
{
|
||||
// 返回时间段的总天数。
|
||||
return TimePeriod.TotalDays;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算两个日期时间之间的时间差。
|
||||
/// </summary>
|
||||
/// <param name="date1">第一个日期时间。</param>
|
||||
/// <param name="date2">第二个日期时间。</param>
|
||||
/// <returns>返回两个日期时间之间的时间差。</returns>
|
||||
public static TimeSpan GetDateReduce(DateTime date1, DateTime date2)
|
||||
{
|
||||
// 返回第一个日期时间减去第二个日期时间的时间差。
|
||||
return date1 - date2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前系统时间。
|
||||
/// </summary>
|
||||
/// <returns>返回当前系统时间。</returns>
|
||||
public static DateTime GetNowTime()
|
||||
{
|
||||
// 返回当前系统时间。
|
||||
return DateTime.Now;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
58
Command/Delay.cs
Normal file
58
Command/Delay.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Common.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Command
|
||||
{
|
||||
[ADPCommand]
|
||||
public static class Delay
|
||||
{
|
||||
/// <summary>
|
||||
/// 等待_毫秒
|
||||
/// </summary>
|
||||
/// <param name="millisecond"></param>
|
||||
/// <param name="ct"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task Delay_ms(int millisecond, CancellationToken ct)
|
||||
{
|
||||
await Task.Delay(millisecond, ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待_秒
|
||||
/// </summary>
|
||||
/// <param name="second"></param>
|
||||
/// <param name="ct"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task Delay_s(float second, CancellationToken ct)
|
||||
{
|
||||
await Task.Delay((int)second * 1000, ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待_分钟
|
||||
/// </summary>
|
||||
/// <param name="minnute"></param>
|
||||
/// <param name="ct"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task Delay_m(float minnute, CancellationToken ct)
|
||||
{
|
||||
await Task.Delay((int)minnute * 60 * 1000, ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待_小时
|
||||
/// </summary>
|
||||
/// <param name="minnute"></param>
|
||||
/// <param name="ct"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task Delay_h(float minnute, CancellationToken ct)
|
||||
{
|
||||
await Task.Delay((int)minnute * 60 * 1000, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user