public static string DataTable2Json(DataTable dt, int page, convertType type, string formatDateTime = "yyyy-MM-dd")
        {
            var jsonString = string.Empty;

            switch (type)
            {
            case convertType.Default:
                jsonString = DataTable2Default(dt, formatDateTime);
                break;

            case convertType.Table:
                jsonString = DataTable2Table(dt, page, -1, formatDateTime);
                break;
            }
            return(jsonString);
        }
Exemple #2
0
 public static string byteArrayToHexStr(byte[] bytes, convertType type)
 {
     StringBuilder sb = new StringBuilder();
     switch (type)
     {
         case convertType.littleEndian:
             for (int i = 0; i < bytes.Length; i = i + 2)
             {
                 sb.Append(bytes[i + 1].ToString("X2"));
                 sb.Append(" ");
                 sb.Append(bytes[i].ToString("X2"));
                 sb.Append(" ");
             }
             break;
         case convertType.EachByte:
             foreach (byte bt in bytes)
             {
                 sb.Append(bt.ToString("X2"));
                 sb.Append(" ");
             }
             break;
     }
     return sb.ToString();
 }
Exemple #3
0
 public static string fileToHexStr(string filePath, convertType type)
 {
     byte[] tmpBytes = File.ReadAllBytes(filePath);
     return byteArrayToHexStr(tmpBytes, type);
 }
Exemple #4
0
 public static string hexToStr(string strHex, convertType type)
 {
     strHex = strHex.Replace(" ", "");
     if (strHex == string.Empty)
     {
         return string.Empty;
     }
     byte[] byteArray = new byte[strHex.Length / 2];      //两个字节转回一个字符,长度减半
     switch (type)
     {
         case convertType.littleEndian:
             for (int i = 0; i < strHex.Length; i = i + 2)
             {
                 //尝试将数字的字符串表示形式转换为它的等效 Byte,并返回一个指示转换是否成功的值
                 //每次从mhex取两个byte转换存储到vbyte中
                 //if (!byte.TryParse(mHex.Substring(i, 2), System.Globalization.NumberStyles.HexNumber, null, out vBytes[i / 2]))
                 //{
                 //    vBytes[i / 2] = 0;
                 //}
                 byteArray[i / 2] = byte.Parse(strHex.Substring(i, 2), System.Globalization.NumberStyles.HexNumber);
             }
             break;
         case convertType.EachByte:
             for (int i = 0; i < strHex.Length / 2; i = i + 2)
             {
                 byteArray[i / 2] = Convert.ToByte("0x" + strHex.Substring(i, 2), 16);
             }
             break;
     }
     return System.Text.Encoding.Unicode.GetString(byteArray);
 }