Пример #1
0
        public SetMealList(SetMealInfo mealInfo)
        {
            _mealInfo = mealInfo;

            InitializeComponent();
            inti();
        }
Пример #2
0
        private void ShowRecord()
        {
            try
            {
                this.flpMealList.Visible = false;
                this.flpMealList.Controls.Clear();
                this.lblRecordAmount.Text = "";

                _smlList = new List<SetMealList>();

                DateTime startTime = DateTime.Parse(dtpDateFrom.Value.ToString("yyyy/MM/dd"));
                DateTime endTime = DateTime.Parse(dtpDateTo.Value.ToString("yyyy/MM/dd"));

                int lastIndex = 0;

                if (endTime >= startTime)
                {
                    System.TimeSpan ts = endTime.Subtract(startTime);//TimeSpan得到dt1和dt2的时间间隔
                    int countDays = ts.Days;//相隔天数
                    if (countDays > 60)
                    {
                        base.MessageDialog("提示", "最多只能查询前后60天的记录!");
                        startTime = startTime.AddDays(60);
                        this.dtpDateTo.Value = startTime;
                        return;
                    }

                    DateTime nowDate = DateTime.Parse(System.DateTime.Now.ToString("yyyy/MM/dd"));

                    if (startTime < nowDate)//如果開始時間是小于當前時間,則查詢定餐使用記錄
                    {
                        MealBookingHistory_mbh_Info mbhInfo = new MealBookingHistory_mbh_Info();
                        mbhInfo.mbh_cTargetID = _userInfo.ucp_cCUSID;
                        mbhInfo.StartTime = startTime;

                        if (endTime > nowDate)
                        {
                            mbhInfo.EndTime = nowDate;
                        }
                        else
                        {
                            mbhInfo.EndTime = endTime;
                        }

                        List<MealBookingHistory_mbh_Info> mbhList = _imbhBL.SearchRecords(mbhInfo);

                        if (mbhList != null && mbhList.Count > 0)
                        {
                            //補全一個星期
                            int weekIndex = GetWeekIndex(mbhList[0].mbh_dMealDate);

                            for (int index = 0; index < weekIndex - 1; index++)
                            {
                                SetMealList mealList = new SetMealList(null);
                                _smlList.Add(mealList);
                                //this.flpMealList.Controls.Add(mealList);
                            }

                            lastIndex = GetWeekIndex(mbhList[mbhList.Count - 1].mbh_dMealDate);//如果有定餐記錄,記下最后一日

                            for (DateTime dt = startTime; dt < nowDate; dt = dt.AddDays(1))
                            {
                                SetMealInfo mealInfo = new SetMealInfo();
                                mealInfo.times = dt;

                                bool isSet = false;

                                foreach (MealBookingHistory_mbh_Info info in mbhList)
                                {
                                    DateTime subDt = DateTime.Parse(info.mbh_dMealDate.ToString("yyyy/MM/dd"));
                                    if (subDt == dt)
                                    {
                                        if (info.mbh_cMealType == DefineConstantValue.MealType.Breakfast.ToString())
                                        {
                                            mealInfo.Breakfast = info.mbh_lIsSet;
                                            isSet = true;
                                        }
                                        else if (info.mbh_cMealType == DefineConstantValue.MealType.Lunch.ToString())
                                        {
                                            mealInfo.Lunch = info.mbh_lIsSet;
                                            isSet = true;
                                        }
                                        else if (info.mbh_cMealType == DefineConstantValue.MealType.Supper.ToString())
                                        {
                                            mealInfo.Dinner = info.mbh_lIsSet;
                                            isSet = true;
                                        }
                                    }
                                }

                                if (isSet == true)
                                {
                                    SetMealList mealList = new SetMealList(mealInfo);

                                    _smlList.Add(mealList);

                                    //this.flpMealList.Controls.Add(mealList);
                                }

                                isSet = false;
                            }
                        }
                    }

                    if (endTime >= nowDate)//如果結束日期大于當前日期,則查詢定餐設置記錄
                    {
                        PaymentUDMealState_pms_Info pmsInfo = new PaymentUDMealState_pms_Info();
                        pmsInfo.pms_cCardUserID = _userInfo.ucp_cCUSID;
                        pmsInfo.pms_cClassID = _userInfo.CardOwner.cus_cClassID;
                        pmsInfo.pms_cGradeID = _userInfo.CardOwner.ClassInfo.csm_cGDMID;

                        pmsInfo.TimeTo = dtpDateTo.Value;

                        if (startTime > nowDate)
                        {
                            pmsInfo.TimeFrom = startTime;
                        }
                        else
                        {
                            pmsInfo.TimeFrom = nowDate;
                        }

                        List<PaymentUDMealState_pms_Info> pmsList = _ipumsBL.SearchMealRecords(pmsInfo);

                        if (pmsList != null && pmsList.Count > 0)
                        {
                            ////補全一個星期
                            //int weekIndex = GetWeekIndex((DateTime)(pmsList[0].pms_dStartDate));

                            //if (lastIndex == 0)
                            //{
                            //    lastIndex = weekIndex - 1;
                            //}
                            //else
                            //{
                            //    lastIndex = 7 - lastIndex - weekIndex;
                            //}

                            //for (int index = 0; index < lastIndex; index++)
                            //{
                            //    SetMealList mealList = new SetMealList(null);
                            //    _smlList.Add(mealList);
                            //    //this.flpMealList.Controls.Add(mealList);
                            //}

                            this.lblRecordAmount.Text = pmsList.Count.ToString();

                            pmsList = pmsList.OrderBy(p => p.pms_dStartDate).ToList();

                            for (int index = 0; index < pmsList.Count; index++)
                            {
                                SetMealInfo mealInfo = new SetMealInfo();
                                mealInfo.times = (DateTime)pmsList[index].pms_dStartDate;
                                mealInfo.Breakfast = pmsList[index].pms_cBreakfast;
                                mealInfo.Lunch = pmsList[index].pms_cLunch;
                                mealInfo.Dinner = pmsList[index].pms_cDinner;

                                SetMealList mealList = new SetMealList(mealInfo);

                                _smlList.Add(mealList);

                                //this.flpMealList.Controls.Add(mealList);
                            }
                        }
                    }
                }
                else
                {
                    base.MessageDialog("提示", "结束时间不能小于开始时间!");
                }
            }
            catch
            {

            }
            finally
            {
                this.flpMealList.Visible = true;
                //計算最大頁數
                if (_smlList != null)
                {
                    _MaxPage = _smlList.Count / _PageSize;

                    if (_smlList.Count % _PageSize != 0)
                    {
                        _MaxPage++;
                    }

                    if (_MaxPage == 0)
                    {
                        _PageIndex = 0;
                    }
                    else
                    {
                        if (_PageIndex == 0)
                        {
                            _PageIndex = 1;
                        }
                    }

                    ShowList();//顯示內容
                }

                SetUpDownBtnStatus();
            }
        }