Ejemplo n.º 1
0
        private static string SplitDate <T>(T objValue, out long splitIndex, DbLoadBalanceInfo.TableNameRule tnr)
        {
            splitIndex = 0;
            string   tableName = tnr.Prefix;
            DateTime dateValue = Convert.ToDateTime(objValue);

            if (tnr.Format >= 1 && tnr.Format <= 4)
            {
                string suffix = string.Empty;
                switch (tnr.Format)
                {
                case 1:
                    suffix = dateValue.ToString("yyyy");
                    break;

                case 2:
                    suffix = dateValue.ToString("yyyyMM");
                    break;

                case 3:
                    suffix = dateValue.ToString("yyyyMMdd");
                    break;

                case 4:    //当年第几周
                    int week = new System.Globalization.GregorianCalendar().GetWeekOfYear(dateValue, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday);
                    suffix = dateValue.ToString("yyyy") + week.ToString();
                    break;

                default:
                    break;
                }
                if (suffix != string.Empty)
                {
                    tableName  = string.Format("{0}_{1}", tnr.Prefix, suffix);
                    splitIndex = int.Parse(dateValue.ToString("yyyyMMdd"));
                }
            }
            return(tableName);
        }