Пример #1
0
        //数据库连接 ZAM 2015-5-22
        public bool Connect()
        {
            bool ret = false;

            try
            {
                DataConnection.count++;
                CacheConnectionObject.Open();

                /*#region<"CachePool Monitor">
                 * // CachePool Monitor ZAM 2015-5-22
                 * int activeCount = CachePoolManager.ActiveConnectionCount;
                 * int idleCount = CachePoolManager.IdleCount(CacheConnectionObject);
                 * int inUseCount = CachePoolManager.InUseCount(CacheConnectionObject);
                 *
                 * HygeiaComUtility.WriteClientLog(HygeiaEnum.LogType.ErrorLog, "Service: " + this.serviceID + " DCount: " + DataConnection.count + " CID: " + ConnectID + " State: " + CacheConnectionObject.State.ToString() + " ID: " + CacheConnectionObject.CacheJobID, "");
                 * HygeiaComUtility.WriteClientLog(HygeiaEnum.LogType.ErrorLog, "Active " + activeCount + " idle: " + idleCount + " inUse:" + inUseCount + " ", "");
                 *
                 #endregion*/

                ret = true;
            }
            catch (Exception ex)
            {
                HygeiaComUtility.WriteClientLog(HygeiaEnum.LogType.ErrorLog, "", "数据库连接失败! error information : " + ex.Message + Environment.NewLine + ex.StackTrace);
                throw ex;
            }
            return(ret);
        }
Пример #2
0
        /// <summary>
        /// Changes the time format.
        /// </summary>
        /// <returns></returns>
        public static string ChgTimeFormat(string TimeString)
        {
            string strTime          = TimeString;
            string strTimeDelimiter = ":";

            try
            {
                if (TimeString.Split(Convert.ToChar(strTimeDelimiter)).Length > 1)
                {
                    //hh:mm → hhmm
                    strTime = TimeString.Replace(strTimeDelimiter, string.Empty);
                }
                else
                {
                    //hhmm → hh:mm
                    // 20141202 ZAM
                    string tempstr = ("0000" + TimeString);
                    strTime = tempstr.Substring(tempstr.Length - 4, 4);
                    strTime = strTime.Substring(0, 2) + strTimeDelimiter + strTime.Substring(2, 2);
                }
            }
            catch (Exception ex)
            {
                HygeiaComUtility.WriteClientLog(HygeiaEnum.LogType.ErrorLog, "", "ChgTimeFormat! error information : " + ex.Message + Environment.NewLine + ex.StackTrace);
                throw ex;
            }
            return(strTime);
        }
Пример #3
0
        /// <summary>
        /// Changes the date format.
        /// </summary>
        /// <returns></returns>
        public static string ChgDateFormat(string DateString)
        {
            string strDate          = DateString;
            string strDateDelimiter = "/";

            try
            {
                switch (DateString.Length)
                {
                case 8:
                    //YYYYMMDD → e.g)YYYY/MM/DD
                    strDate = DateString.Substring(0, 4) + strDateDelimiter + DateString.Substring(4, 2) + strDateDelimiter + DateString.Substring(6, 2);

                    break;

                case 10:
                    //e.g)YYYY/MM/DD → YYYYMMDD
                    strDate = DateString.Replace(strDateDelimiter, string.Empty);

                    break;

                default:

                    break;
                }
            }
            catch (Exception ex)
            {
                HygeiaComUtility.WriteClientLog(HygeiaEnum.LogType.ErrorLog, "", "ChgDateFormat! error information : " + ex.Message + Environment.NewLine + ex.StackTrace);
                throw ex;
            }
            return(strDate);
        }
Пример #4
0
        //CaculateWeekDay 判断日期是星期几 syf 2015-10-10
        public string CaculateWeekDay(string date)
        {
            string week = "星期一";  //待标记颜色

            try
            {
                string weekDayEn = Convert.ToDateTime(date).DayOfWeek.ToString();
                switch (weekDayEn)
                {
                case "Monday":
                    week = "星期一";
                    break;

                case "Tuesday":
                    week = "星期二";
                    break;

                case "Wednesday":
                    week = "星期三";
                    break;

                case "Thursday":
                    week = "星期四";
                    break;

                case "Friday":
                    week = "星期五";
                    break;

                case "Saturday":
                    week = "星期六";
                    break;

                case "Sunday":
                    week = "星期日";
                    break;

                default: break;
                }

                return(week);
            }
            catch (Exception ex)
            {
                HygeiaComUtility.WriteClientLog(HygeiaEnum.LogType.ErrorLog, "PsCompliance.CaculateWeekDay", "数据库操作异常! error information : " + ex.Message + Environment.NewLine + ex.StackTrace);
                return(null);
            }
        }
Пример #5
0
        //数据库断开连接 ZAM 2015-5-22
        public bool DisConnect()
        {
            bool ret = false;

            try
            {
                DataConnection.count--;
                CacheConnectionObject.Close();
                ret = true;
            }
            catch (Exception ex)
            {
                HygeiaComUtility.WriteClientLog(HygeiaEnum.LogType.ErrorLog, "", "数据库断开连接失败! error information : " + ex.Message + Environment.NewLine + ex.StackTrace);
                throw ex;
            }
            return(ret);
        }
Пример #6
0
        //获取服务器日期(解决频繁连接导致的连接未及时关闭) GL 2015-10-13
        public int GetServerDate()
        {
            string serverDate = string.Empty;
            int    date       = 99999999;

            try
            {
                //ZAM 2015-5-7 频繁连接导致的连接未及时关闭
                {
                    if (!pclsCache.Connect())
                    {
                        return(date);
                    }
                }
                serverDate = Cm.CommonLibrary.GetServerDateTime(pclsCache.CacheConnectionObject);    //2014/08/22 15:33:35
                string[] str = serverDate.Split(' ');
                if (str.Length >= 1)
                {
                    serverDate = str[0];
                    serverDate = serverDate.Replace("/", string.Empty);
                    date       = Convert.ToInt32(serverDate);
                }

                return(date);
            }
            catch (Exception ex)
            {
                HygeiaComUtility.WriteClientLog(HygeiaEnum.LogType.ErrorLog, "GetServerDate", "CommonFunction error information : " + ex.Message + Environment.NewLine + ex.StackTrace);
                return(date);

                throw (ex);
            }
            finally
            {
                pclsCache.DisConnect();
            }
        }
Пример #7
0
        /// <summary>
        /// 时间格式转换 GL 2015-10-10
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public string TransTime(string time)
        {
            int    length = time.Length;
            string result = "";

            try
            {
                switch (length)
                {
                case 1:
                    result = "00:0" + time;
                    break;

                case 2:
                    result = "00:" + time;
                    break;

                case 3:
                    result = "0" + time.Substring(0, 1) + ":" + time.Substring(1, 2);
                    break;

                case 4:
                    result = time.Substring(0, 2) + ":" + time.Substring(2, 2);      //Substring(起始, 截取长度)
                    break;

                default: break;
                }

                return(result);
            }
            catch (Exception ex)
            {
                HygeiaComUtility.WriteClientLog(HygeiaEnum.LogType.ErrorLog, "CommonMethod.TransTime", "数据库操作异常! error information : " + ex.Message + Environment.NewLine + ex.StackTrace);
                return(null);
            }
        }