| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Core.StlMes.Client.Sale.Util
- {
- public class ConverObject
- {
- private static string _defaultDataTimeFormt = "yyyyMMddHHmmss";
- public static string ConvertDataTimeToString(DateTime value)
- {
- if(value == null || value.ToString().Length == 0)
- return "";
- return value.ToString(_defaultDataTimeFormt);
-
- }
- /// <summary>
- /// 将System.DateTime日期改为sql 认可的to_date
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static string GetTimeStringValueToDateFunction(System.DateTime value)
- {
- return string.Format("to_date('{0}','yyyymmddhh24miss')", Util.ConverObject.ConvertDataTimeToString(value));
- }
- /// <summary>
- /// 将DateTime 类型转为sql 可以比较的类型
- /// </summary>
- /// <param name="dt"></param>
- /// <returns></returns>
- public static string ConvertDateTimeValueToDbLanguage(DateTime dt)
- {
- return string.Format(" trunc( to_date('{0}','yyyymmdd'))", dt.ToString("yyyyMMdd"));
- }
- /// <summary>
- /// 将DateTime 类型转为sql 可以比较的类型
- /// </summary>
- /// <param name="columnName"></param>
- /// <param name="beginDate"></param>
- /// <param name="endDate"></param>
- /// <returns></returns>
- public static string ConvertDateTimeValueToDbLanguage(string columnName, DateTime beginDate, DateTime endDate)
- {
- return string.Format(" and {0} >= trunc( to_date('{1}','yyyymmdd')) and {0} < trunc( to_date('{2}','yyyymmdd')) + 1 ",
- columnName, beginDate.ToString("yyyyMMdd"), endDate.ToString("yyyyMMdd"));
- }
- public static string ConverDateTimeToyyyyMMdd(DateTime time)
- {
- return time.ToString("yyyyMMdd");
- }
- public static string ConvertListStringValueToSqlCondition(string columnName,List<string> list)
- {
- if (list == null || list.Count == 0)
- return " and 1 = 2 ";
- System.Text.StringBuilder sb = new StringBuilder();
- foreach (String s in list)
- {
- sb.Append(string.Format(" {0} = '{1}' ",columnName,s)).Append(" or ");
-
- }
- string sqlCondition = " and (" + sb.ToString() + " 1 = 2 )";
- return sqlCondition;
- }
- public static string ConvertNumberToChinese(string strNum)
- {
- string[] Nums = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
- string[] Digits = { "", "拾", "佰", "仟" };
- string[] Units = { "元", "万", "亿", "万亿" };
- string x, y, z = "";
- if (strNum.Length > 2)
- {
- x = strNum.Substring(0, strNum.Length - 2);
- y = strNum.Substring(strNum.Length - 2, 2);
- }
- else
- {
- x = "";
- y = strNum;
- }
- if (y.Length == 2)
- {
- int n = Convert.ToInt32(y.Substring(0, 1));
- z = Nums[n] + "角";
- }
- if (y.Length > 0)
- {
- int n = Convert.ToInt32(y.Substring(y.Length - 1, 1));
- z += Nums[n] + "分";
- }
- if (y.Length == 0)
- {
- if (x.Length == 0)
- z = "零元整";
- else
- z = "整";
- }
- string S = ""; //返回值
- int p = 0; //字符位置指针
- int m = x.Length % 4; //取模
- // 四位一组得到组数
- int k = (m > 0 ? x.Length / 4 + 1 : x.Length / 4);
- // 外层循环在所有组中循环
- // 从左到右 高位到低位 四位一组 逐组处理
- // 每组最后加上一个单位: "[万亿]","[亿]","[万]"
- for (int i = k; i > 0; i--)
- {
- int L = 4;
- if (i == k && m != 0)
- {
- L = m;
- }
- // 得到一组四位数 最高位组有可能不足四位
- string s = x.Substring(p, L);
- int l = s.Length;
- // 内层循环在该组中的每一位数上循环 从左到右 高位到低位
- for (int j = 0; j < l; j++)
- {
- //处理改组中的每一位数加上所在位: "仟","佰","拾",""(个)
- int n = Convert.ToInt32(s.Substring(j, 1));
- if (n == 0)
- {
- if (j < l - 1
- && Convert.ToInt32(s.Substring(j + 1, 1)) > 0 //后一位(右低)
- && !S.EndsWith(Nums[n]))
- {
- S += Nums[n];
- }
- }
- else
- {
- //处理 1013 一千零"十三", 1113 一千一百"一十三"
- if (!(n == 1 && (S.EndsWith(Nums[0]) | S.Length == 0) && j == l - 2))
- {
- S += Nums[n];
- }
- S += Digits[l - j - 1];
- }
- }
- p += L;
- // 每组最后加上一个单位: [万],[亿] 等
- if (i < k) //不是最高位的一组
- {
- if (Convert.ToInt32(s) != 0)
- {
- //如果所有 4 位不全是 0 则加上单位 [万],[亿] 等
- S += Units[i - 1];
- }
- }
- else
- {
- //处理最高位的一组,最后必须加上单位
- S += Units[i - 1];
- }
- }
- return S + z;
- }
-
- public static double ConvertToDouble(object value)
- {
- try
- {
- return Convert.ToDouble(value);
- }
- catch
- {
- return 0;
- }
- }
- }
- }
|