Ejemplo n.º 1
0
        public void SetDayModel(int year, int month)
        {
            DateTime dtFirstDay = Convert.ToDateTime(string.Format("{0}-{1}-1", year, month));
            int days = DateTime.DaysInMonth(year, month);//此月有几天
            ////不足31天的部分日期置空
            //if (Days < 31)
            //{
            //    for (int i = 31; i > Days; i--)
            //    {
            //        dayModelList[i - 1].Day = "";
            //    }
            //}

            int dayInWeekIndex = Convert.ToInt32(dtFirstDay.DayOfWeek);//星期几
            int dayInListIndex = 0;//日期索引(42格)
            int dayIndex = 1;//不超过days的值,1号开始

            for (int i = 0; i < 6; i++)//1~6周
            {
                for (int j = 0; j < 7; j++, dayInListIndex++)//星期日~星期六
                {
                    DayStruct dayPoint = new DayStruct(0, 0);
                    if (i == 0)//第一周,判断第一行的数据
                    {
                        if (j < dayInWeekIndex)//上个月的
                        {
                            dayModelList[dayInListIndex].Day = "";//置空
                            continue;
                        }
                        else
                        {
                            dayPoint.X = j;
                            dayPoint.Y = 0;
                            dayModelList[dayInListIndex].Day = (dayIndex).ToString();
                        }
                    }
                    else
                    {
                        dayPoint.X = j;
                        dayPoint.Y = i;
                        if (dayIndex <= days)
                        {
                            dayModelList[dayInListIndex].Day = (dayIndex).ToString();
                        }
                        else//超过的部分都是空
                        {
                            dayModelList[dayInListIndex].Day = "";
                        }
                    }

                    dayModelList[dayInListIndex].DayPoint = dayPoint;
                    dayIndex++;
                }
            }
        }
Ejemplo n.º 2
0
 public DayModel()
 {
     DayPoint = new DayStruct(0, 0);
 }