Esempio n. 1
0
        /// <summary>
        /// 取得下一個流水號。
        /// </summary>
        /// <param name="value">目前編號。</param>
        /// <param name="baseValues">編碼基底字串。</param>
        public static string GetNextID(string value, string baseValues)
        {
            string sValue;

            char[] oBaseValues;
            int    iCount;
            int    iIndex;

            oBaseValues = baseValues.ToCharArray();
            iCount      = oBaseValues.Length;
            sValue      = StrFunc.StrTrim(value);

            for (int N1 = sValue.Length - 1; N1 >= 0; N1--)
            {
                iIndex = Array.IndexOf(oBaseValues, sValue[N1]);
                if (iIndex != -1 && iIndex < iCount - 1)
                {
                    return(StrFunc.StrFormat("{0}{1}{2}", StrFunc.StrLeft(sValue, N1), oBaseValues[iIndex + 1], StrFunc.StrSubstring(sValue, N1 + 1)));
                }
                else
                {
                    // 需要進位,將目前位數歸零
                    if (iIndex != -1 && iIndex < iCount)
                    {
                        sValue = StrFunc.StrFormat("{0}{1}{2}", StrFunc.StrLeft(sValue, N1), oBaseValues[0], StrFunc.StrSubstring(sValue, N1 + 1));
                        if (N1 == 0)
                        {
                            return(oBaseValues[0] + sValue);
                        }
                    }
                }
            }
            return(string.Empty);
        }
Esempio n. 2
0
        /// <summary>
        /// 取得下一個流水號。
        /// </summary>
        /// <param name="value">目前編號。</param>
        /// <param name="numberBase">流水號進位基底,2至36進位。</param>
        public static string GetNextID(string value, int numberBase)
        {
            string sValue;

            char[] oBaseValues;
            int    iBaseValue;

            oBaseValues = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
            sValue      = StrFunc.StrTrim(value);

            for (int N1 = sValue.Length - 1; N1 >= 0; N1--)
            {
                iBaseValue = Array.IndexOf(oBaseValues, sValue[N1]);
                if (iBaseValue != -1 && iBaseValue < numberBase - 1)
                {
                    return(StrFunc.StrFormat("{0}{1}{2}", StrFunc.StrLeft(sValue, N1), oBaseValues[iBaseValue + 1], StrFunc.StrSubstring(sValue, N1 + 1)));
                }
                else
                {
                    // 需要進位,將目前位數歸零
                    if (iBaseValue != -1 && iBaseValue < numberBase)
                    {
                        sValue = StrFunc.StrFormat("{0}{1}{2}", StrFunc.StrLeft(sValue, N1), "0", StrFunc.StrSubstring(sValue, N1 + 1));
                    }
                }
            }
            return(string.Empty);
        }
Esempio n. 3
0
        /// <summary>
        /// 轉換為 DateTime 型別。
        /// </summary>
        /// <param name="date">日期字串。</param>
        /// <param name="time">時間字串。</param>
        public static DateTime ToDateTime(string date, string time)
        {
            string sValue;
            string sTime;

            sTime = time;
            // 若時間是四碼或六碼數值,則加上時間冒號
            if (BaseFunc.IsNumeric(sTime))
            {
                if (StrFunc.StrLen(sTime) == 4)
                {
                    sTime = StrFunc.StrFormat("{0}:{1}", StrFunc.StrLeft(sTime, 2), StrFunc.StrSubstring(sTime, 2, 2));
                }
                else if (StrFunc.StrLen(sTime) == 6)
                {
                    sTime = StrFunc.StrFormat("{0}:{1}:{2}", StrFunc.StrLeft(sTime, 2), StrFunc.StrSubstring(sTime, 2, 2), StrFunc.StrSubstring(sTime, 4, 2));
                }
            }

            sValue = StrFunc.StrFormat("{0} {1}", date, sTime);
            if (IsDate(sValue))
            {
                return(BaseFunc.CDateTime(sValue));
            }
            else
            {
                return(DateTime.MinValue);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// 字串格式化。
 /// </summary>
 /// <param name="s">字串</param>
 /// <param name="args">參數陣列</param>
 /// <returns></returns>
 public static string StrFormat(this string s, params object[] args)
 {
     return(StrFunc.StrFormat(s, args));
 }
Esempio n. 5
0
 /// <summary>
 /// 建構函式。
 /// </summary>
 /// <param name="message">錯誤訊息。</param>
 /// <param name="args">參數陣列。</param>
 public GException(string message, params object[] args)
     : base(StrFunc.StrFormat(message, args))
 {
 }