|
|
|
|
using HighWayIot.Plc;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace HighWayIot.Winform.Business
|
|
|
|
|
{
|
|
|
|
|
public class GeneralUtils
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 在字符串数组前面加一个空字符串
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="str"></param>
|
|
|
|
|
public static string[] HeadAddEmptyString(string[] str)
|
|
|
|
|
{
|
|
|
|
|
Array.Resize(ref str, str.Length + 1);
|
|
|
|
|
Array.Copy(str, 0, str, 1, str.Length - 1);
|
|
|
|
|
str[0] = string.Empty;
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 转换string为int
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="text"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static int? StringNullOrToInt(string text)
|
|
|
|
|
{
|
|
|
|
|
return int.TryParse(text, out int result) ? (int?)result : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string IntEmptyOrToString(int? value)
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
{
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return value.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 返回对应的枚举类Type类型
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
|
public static Type GetTypeByEnum(DataTypeEnum type)
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case DataTypeEnum.Bool:
|
|
|
|
|
return typeof(bool);
|
|
|
|
|
case DataTypeEnum.Byte:
|
|
|
|
|
return typeof(byte);
|
|
|
|
|
case DataTypeEnum.Int16:
|
|
|
|
|
return typeof(short);
|
|
|
|
|
case DataTypeEnum.UInt16:
|
|
|
|
|
return typeof(ushort);
|
|
|
|
|
case DataTypeEnum.Int32:
|
|
|
|
|
return typeof(int);
|
|
|
|
|
case DataTypeEnum.UInt32:
|
|
|
|
|
return typeof(uint);
|
|
|
|
|
case DataTypeEnum.Int64:
|
|
|
|
|
return typeof(long);
|
|
|
|
|
case DataTypeEnum.UInt64:
|
|
|
|
|
return typeof(ulong);
|
|
|
|
|
case DataTypeEnum.Float:
|
|
|
|
|
return typeof(float);
|
|
|
|
|
case DataTypeEnum.Double:
|
|
|
|
|
return typeof(double);
|
|
|
|
|
default:
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|