/// <summary>
        /// 获取当前用户计划定餐设置
        /// </summary>
        /// <param name="targetUser">用户信息</param>
        /// <returns></returns>
        public List<MealBookingHistory_mbh_Info> getlistMealBookingPlanning(CardUserMaster_cus_Info targetUser)
        {
            try
            {
                List<MealBookingHistory_mbh_Info> listMealPlan = new List<MealBookingHistory_mbh_Info>();

                //获取默认定餐设置
                List<PaymentUDGeneralSetting_pus_Info> listGeneralSettings = this._IPaymentUDGeneralSettingBL.SearchRecords(new PaymentUDGeneralSetting_pus_Info() { pus_iWeek = (int)DateTime.Now.DayOfWeek });

                //获取自定义定餐设置
                List<PaymentUDMealState_pms_Info> listCustomSettings = this._IPaymentUDMealStateBL.SearchRecords(new PaymentUDMealState_pms_Info()
                {
                    //pms_dStartDate = DateTime.Now.Date,
                    //pms_dEndDate = DateTime.Now.Date
                    TimeFrom = DateTime.Now.Date,
                    TimeTo = DateTime.Now.Date
                });

                foreach (Common.DefineConstantValue.MealType mealType in Enum.GetValues(typeof(Common.DefineConstantValue.MealType)))
                {
                    if (mealType == Common.DefineConstantValue.MealType.UnKnown)
                    {
                        continue;
                    }
                    MealBookingHistory_mbh_Info history = new MealBookingHistory_mbh_Info();
                    history.mbh_cMealType = mealType.ToString();

                    #region 个人--》班级--》年级

                    //学生自定义
                    PaymentUDMealState_pms_Info stuCustom = listCustomSettings.Find(x => x.pms_cCardUserID == targetUser.cus_cRecordID);
                    if (stuCustom == null)
                    {
                        //学生默认
                        PaymentUDGeneralSetting_pus_Info stuDefault = listGeneralSettings.Find(x => x.pus_cCardUserID == targetUser.cus_cRecordID);
                        if (stuDefault == null)
                        {
                            #region 班级--》年级

                            //班级自定义
                            stuCustom = listCustomSettings.Find(x => x.pms_cClassID == targetUser.cus_cClassID);
                            if (stuCustom == null)
                            {
                                //班级默认
                                stuDefault = listGeneralSettings.Find(x => x.pus_cClassID == targetUser.cus_cClassID);
                                if (stuDefault == null)
                                {
                                    if (targetUser.ClassInfo != null && targetUser.ClassInfo.GradeInfo != null)
                                    {
                                        #region 年级

                                        //年级自定义
                                        stuCustom = listCustomSettings.Find(x => x.pms_cGradeID == targetUser.ClassInfo.GradeInfo.gdm_cRecordID);
                                        if (stuCustom == null)
                                        {
                                            //年级默认
                                            stuDefault = listGeneralSettings.Find(x => x.pus_cGradeID == targetUser.ClassInfo.GradeInfo.gdm_cRecordID);
                                            if (stuDefault != null)
                                            {
                                                history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.GradeDefault.ToString();
                                                history.mbh_lIsSet = GetGeneralSettings(mealType.ToString(), stuDefault);
                                                listMealPlan.Add(history);
                                                continue;
                                            }
                                            else
                                            {
                                                //缺失年级默认设置时,默认不定餐
                                                history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.Unknown.ToString();
                                                history.mbh_lIsSet = false;
                                                listMealPlan.Add(history);
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.GradeCustom.ToString();
                                            history.mbh_lIsSet = GetCustomMealSettings(mealType.ToString(), stuCustom);
                                            listMealPlan.Add(history);
                                            continue;
                                        }

                                        #endregion
                                    }
                                    else
                                    {
                                        //缺失年级信息时,默认不定餐
                                        history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.Unknown.ToString();
                                        history.mbh_lIsSet = false;
                                        listMealPlan.Add(history);
                                        continue;
                                    }
                                }
                                else
                                {
                                    history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.ClassDefault.ToString();
                                    history.mbh_lIsSet = GetGeneralSettings(mealType.ToString(), stuDefault);
                                    if (history.mbh_lIsSet)
                                    {
                                        CheckClassGradeIsSet(targetUser, history, listGeneralSettings, listCustomSettings, mealType.ToString());
                                    }
                                    listMealPlan.Add(history);
                                    continue;
                                }
                            }
                            else
                            {
                                history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.ClassCustom.ToString();
                                history.mbh_lIsSet = GetCustomMealSettings(mealType.ToString(), stuCustom);
                                if (history.mbh_lIsSet)
                                {
                                    CheckClassGradeIsSet(targetUser, history, listGeneralSettings, listCustomSettings, mealType.ToString());
                                }
                                listMealPlan.Add(history);
                                continue;
                            }

                            #endregion
                        }
                        else
                        {
                            history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.StudentDefault.ToString();
                            history.mbh_lIsSet = GetGeneralSettings(mealType.ToString(), stuDefault);
                            if (history.mbh_lIsSet)
                            {
                                CheckClassGradeIsSet(targetUser, history, listGeneralSettings, listCustomSettings, mealType.ToString());
                            }
                            listMealPlan.Add(history);
                            continue;
                        }
                    }
                    else
                    {
                        history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.StudentCustom.ToString();
                        history.mbh_lIsSet = GetCustomMealSettings(mealType.ToString(), stuCustom);
                        if (history.mbh_lIsSet)
                        {
                            CheckClassGradeIsSet(targetUser, history, listGeneralSettings, listCustomSettings, mealType.ToString());
                        }
                        listMealPlan.Add(history);
                        continue;
                    }

                    #endregion
                }

                return listMealPlan;
            }
            catch (Exception ex)
            { throw ex; }
        }
示例#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();
            }
        }
        /// <summary>
        /// 更新定餐计划
        /// </summary>
        /// <param name="strMealType"></param>
        /// <param name="userInfo"></param>
        void UpdateMealPlanning(string strMealType, CardUserMaster_cus_Info userInfo, MealBookingHistory_mbh_Info oldMealInfo)
        {
            try
            {
                //ShowInformationMessage("检测到该用户此前被欠费自动停餐,现更新定餐信息并提交到各个消费机处。");

                IMealBookingHistoryBL mealBL = MasterBLLFactory.GetBLL<IMealBookingHistoryBL>(MasterBLLFactory.MealBookingHistory);
                MealBookingHistory_mbh_Info mealInfo = new MealBookingHistory_mbh_Info();
                mealInfo.mbh_cMealType = strMealType;
                mealInfo.mbh_cTargetID = userInfo.cus_cRecordID;
                mealInfo.mbh_dMealDate = DateTime.Now;
                List<MealBookingHistory_mbh_Info> listMealInfo = mealBL.SearchRecords(mealInfo);
                if (listMealInfo != null && listMealInfo.Count > 0)
                {
                    MealBookingHistory_mbh_Info currentMealInfo = listMealInfo.FirstOrDefault();
                    if (currentMealInfo != null)
                    {
                        currentMealInfo.mbh_lIsSet = oldMealInfo.mbh_lIsSet;
                        currentMealInfo.mbh_cTargetType = oldMealInfo.mbh_cTargetType;
                        currentMealInfo.mbh_dAddDate = DateTime.Now;
                        currentMealInfo.mbh_cAdd = base.UserInformation.usm_cUserLoginID;
                        ReturnValueInfo rvInfo = mealBL.UpdateRecordWithPreCost(currentMealInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex);
            }
        }
        /// <summary>
        /// 扩展检查
        /// </summary>
        /// <param name="userInfo"></param>
        /// <param name="targetInfo"></param>
        /// <param name="listGeneralSettings"></param>
        /// <param name="listCustomSettings"></param>
        void CheckClassGradeIsSet(CardUserMaster_cus_Info userInfo, MealBookingHistory_mbh_Info targetInfo, List<PaymentUDGeneralSetting_pus_Info> listGeneralSettings, List<PaymentUDMealState_pms_Info> listCustomSettings, string strMealType)
        {
            MealBookingHistory_mbh_Info rvHistoryInfo = new MealBookingHistory_mbh_Info();
            if (targetInfo.mbh_lIsSet)
            {
                if (userInfo.ClassInfo != null)
                {
                    //先检查年级是否停餐,默认+自定义
                    //年级自定义
                    PaymentUDMealState_pms_Info stuCustom = listCustomSettings.Find(x => x.pms_cGradeID == userInfo.ClassInfo.GradeInfo.gdm_cRecordID);
                    if (stuCustom != null)
                    {
                        //有年级自定义
                        bool setInfo = GetCustomMealSettings(strMealType, stuCustom);
                        if (!setInfo)
                        {
                            targetInfo.mbh_lIsSet = setInfo;
                            targetInfo.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.GradeCustom.ToString();
                            return;
                        }
                    }
                    else
                    {
                        PaymentUDGeneralSetting_pus_Info stuDefault = listGeneralSettings.Find(x => x.pus_cGradeID == userInfo.ClassInfo.GradeInfo.gdm_cRecordID);
                        if (stuDefault != null)
                        {
                            //无年级自定义,有年级默认
                            bool setInfo = GetGeneralSettings(strMealType, stuDefault);
                            if (!setInfo)
                            {
                                targetInfo.mbh_lIsSet = setInfo;
                                targetInfo.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.GradeDefault.ToString();
                                return;
                            }
                        }
                    }

                    stuCustom = listCustomSettings.Find(x => x.pms_cClassID == userInfo.ClassInfo.csm_cRecordID);
                    if (stuCustom != null)
                    {
                        //无年级自定义、默认,有班级自定义
                        bool setInfo = GetCustomMealSettings(strMealType, stuCustom);
                        if (!setInfo)
                        {
                            targetInfo.mbh_lIsSet = setInfo;
                            targetInfo.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.ClassCustom.ToString();
                            return;
                        }
                    }
                    else
                    {
                        PaymentUDGeneralSetting_pus_Info stuDefault = listGeneralSettings.Find(x => x.pus_cClassID == userInfo.ClassInfo.csm_cRecordID);
                        if (stuDefault != null)
                        {
                            //无年级自定义、默认,无班级自定义,有班级默认
                            bool setInfo = GetGeneralSettings(strMealType, stuDefault);
                            if (!setInfo)
                            {
                                targetInfo.mbh_lIsSet = setInfo;
                                targetInfo.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.ClassDefault.ToString();
                                return;
                            }
                        }
                    }
                }
            }
        }
        public ReturnValueInfo UpdateRecordWithPreCost(MealBookingHistory_mbh_Info infoObject)
        {
            try
            {
                return this._IMealBookingHistoryDA.UpdateRecordWithPreCost(infoObject);
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        /// <summary>
        /// 获取当餐停餐信息
        /// </summary>
        /// <param name="strMealType">定餐类型</param>
        /// <returns></returns>
        List<MealBookingHistory_mbh_Info> GetMealBookingRecord(string strMealType)
        {
            List<MealBookingHistory_mbh_Info> listMeal = new List<MealBookingHistory_mbh_Info>();
            try
            {
                //获取学生信息
                List<CardUserMaster_cus_Info> listStudent = this._ICardUserMasterBL.SearchRecords(new CardUserMaster_cus_Info()
                {
                    cus_cIdentityNum = Common.DefineConstantValue.CodeMasterDefine.KEY2_SIOT_CardUserIdentity_Student
                });
                listStudent = listStudent.Where(x => x.cus_lValid && x.PairInfo != null).ToList();//需为有效用户及已发卡用户
                this._ListUserInfos = listStudent;

                //获取默认定餐设置
                List<PaymentUDGeneralSetting_pus_Info> listGeneralSettings = this._IPaymentUDGeneralSettingBL.SearchRecords(new PaymentUDGeneralSetting_pus_Info()
                {
                    pus_iWeek = (int)DateTime.Now.DayOfWeek//符合当天星期日子
                });

                //获取自定义定餐设置
                List<PaymentUDMealState_pms_Info> listCustomSettings = this._IPaymentUDMealStateBL.SearchRecords(new PaymentUDMealState_pms_Info()
                {
                    TimeFrom = DateTime.Now.Date,
                    TimeTo = DateTime.Now.Date
                });

                foreach (CardUserMaster_cus_Info stuItem in listStudent)
                {
                    //以一个学生为单位储存定餐数据
                    MealBookingHistory_mbh_Info history = new MealBookingHistory_mbh_Info();
                    history.mbh_cTargetID = stuItem.cus_cRecordID;
                    history.mbh_cMealType = this._CurrentMealType;
                    history.mbh_cRecordID = Guid.NewGuid();
                    history.mbh_dMealDate = DateTime.Now.Date;
                    history.mbh_cAdd = this._ServiceName;
                    history.mbh_dAddDate = DateTime.Now;
                    history.mbh_fMealCost = this._CurrentMealCost;

                    #region 个人-->>班级-->>年级

                    //学生自定义
                    List<PaymentUDMealState_pms_Info> listUD = listCustomSettings.Where(x => x.pms_cCardUserID == stuItem.cus_cRecordID).ToList();
                    PaymentUDMealState_pms_Info stuCustom = null;
                    if (listUD != null)
                    {
                        if (listUD.Count > 1)
                        {
                            //stuCustom = listUD.OrderByDescending(x => x.pms_dEndDate).FirstOrDefault();
                            stuCustom = listUD.OrderByDescending(x => x.pms_dLastDate).FirstOrDefault();
                        }
                        else if (listUD.Count == 1)
                            stuCustom = listUD.FirstOrDefault();
                        else
                            stuCustom = null;
                    }
                    else
                    {
                        stuCustom = null;
                    }
                    if (stuCustom == null)//学生自定义无值
                    {
                        //学生默认
                        PaymentUDGeneralSetting_pus_Info stuDefault = listGeneralSettings.Find(x => x.pus_cCardUserID == stuItem.cus_cRecordID);
                        if (stuDefault == null)//学生默认无值
                        {
                            #region 班级-->>年级

                            //班级自定义
                            listUD = listCustomSettings.Where(x => x.pms_cClassID == stuItem.cus_cClassID).ToList();
                            stuCustom = null;
                            if (listUD != null)
                            {
                                if (listUD.Count > 1)
                                {
                                    //stuCustom = listUD.OrderByDescending(x => x.pms_dEndDate).FirstOrDefault();
                                    stuCustom = listUD.OrderByDescending(x => x.pms_dLastDate).FirstOrDefault();
                                }
                                else if (listUD.Count == 1)
                                    stuCustom = listUD.FirstOrDefault();
                                else
                                    stuCustom = null;
                            }
                            else
                            {
                                stuCustom = null;
                            }
                            if (stuCustom == null)//班级自定义无值
                            {
                                //班级默认
                                stuDefault = listGeneralSettings.Find(x => x.pus_cClassID == stuItem.cus_cClassID);
                                if (stuDefault == null)//班级默认无值
                                {
                                    if (stuItem.ClassInfo != null && stuItem.ClassInfo.GradeInfo != null)
                                    {
                                        #region 年级

                                        //年级自定义
                                        listUD = listCustomSettings.Where(x => x.pms_cGradeID == stuItem.ClassInfo.GradeInfo.gdm_cRecordID).ToList();
                                        stuCustom = null;
                                        if (listUD != null)
                                        {
                                            if (listUD.Count > 1)
                                            {
                                                //stuCustom = listUD.OrderByDescending(x => x.pms_dEndDate).FirstOrDefault();
                                                stuCustom = listUD.OrderByDescending(x => x.pms_dLastDate).FirstOrDefault();
                                            }
                                            else if (listUD.Count == 1)
                                                stuCustom = listUD.FirstOrDefault();
                                            else
                                                stuCustom = null;
                                        }
                                        else
                                        {
                                            stuCustom = null;
                                        }
                                        if (stuCustom == null)//年级自定义无值
                                        {
                                            //年级默认
                                            stuDefault = listGeneralSettings.Find(x => x.pus_cGradeID == stuItem.ClassInfo.GradeInfo.gdm_cRecordID);
                                            if (stuDefault != null)//年级默认有值
                                            {
                                                history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.GradeDefault.ToString();
                                                history.mbh_lIsSet = GetGeneralSettings(this._CurrentMealType, stuDefault);
                                                listMeal.Add(history);
                                                continue;
                                            }
                                            else//年级默认无值
                                            {
                                                //缺失年级默认设置时,默认不定餐
                                                history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.Unknown.ToString();
                                                history.mbh_lIsSet = false;
                                                listMeal.Add(history);
                                                continue;
                                            }
                                        }
                                        else//年级自定义有值
                                        {
                                            history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.GradeCustom.ToString();
                                            history.mbh_lIsSet = GetCustomMealSettings(this._CurrentMealType, stuCustom);
                                            listMeal.Add(history);
                                            continue;
                                        }

                                        #endregion
                                    }
                                    else
                                    {
                                        //缺失年级信息时,默认不定餐
                                        history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.Unknown.ToString();
                                        history.mbh_lIsSet = false;
                                        listMeal.Add(history);
                                        continue;
                                    }
                                }
                                else//班级默认有值
                                {
                                    history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.ClassDefault.ToString();
                                    history.mbh_lIsSet = GetGeneralSettings(this._CurrentMealType, stuDefault);
                                    if (history.mbh_lIsSet)
                                    {
                                        CheckClassGradeIsSet(stuItem, history, listGeneralSettings, listCustomSettings);
                                    }
                                    listMeal.Add(history);
                                    continue;
                                }
                            }
                            else//班级自定义有值
                            {
                                history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.ClassCustom.ToString();
                                history.mbh_lIsSet = GetCustomMealSettings(this._CurrentMealType, stuCustom);
                                if (history.mbh_lIsSet)
                                {
                                    CheckClassGradeIsSet(stuItem, history, listGeneralSettings, listCustomSettings);
                                }
                                listMeal.Add(history);
                                continue;
                            }

                            #endregion
                        }
                        else//学生默认有值
                        {
                            history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.StudentDefault.ToString();
                            history.mbh_lIsSet = GetGeneralSettings(this._CurrentMealType, stuDefault);
                            if (history.mbh_lIsSet)
                            {
                                CheckClassGradeIsSet(stuItem, history, listGeneralSettings, listCustomSettings);
                            }
                            listMeal.Add(history);
                            continue;
                        }
                    }
                    else//学生自定义有记录
                    {
                        history.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.StudentCustom.ToString();
                        history.mbh_lIsSet = GetCustomMealSettings(this._CurrentMealType, stuCustom);
                        if (history.mbh_lIsSet)
                        {
                            CheckClassGradeIsSet(stuItem, history, listGeneralSettings, listCustomSettings);
                        }
                        listMeal.Add(history);
                        continue;
                    }

                    #endregion
                }

                return listMeal;
            }
            catch (Exception ex)
            {
                this._LocalLogger.WriteLog(ex.Message, string.Empty, SystemLog.SystemLog.LogType.Error);
                this._DBLogger.WriteLog(ex.Message, string.Empty, SystemLog.SystemLog.LogType.Error);
            }
            return listMeal;
        }
示例#7
0
        private void btnRecharge_Click(object sender, EventArgs e)
        {
            dlgConfirmInfo dlg = new dlgConfirmInfo();
            dlg.CardInfo = this._CardInfo;
            dlg.UserInfo = this._UserInfo;
            dlg.RechargeMoney = decimal.Parse(labTotalRecharge.Text);
            dlg.PreCostMoney = decimal.Parse(labPreCost.Text);

            GlobalVar.OpenFormList.Add(dlg);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.Cursor = Cursors.WaitCursor;
                this._Reader = PaymentReaderFactory.CreateWriter(PaymentReaderFactory.EastRiverReader906);
                this._Reader.Conn();

                //卡信息再次验证
                ConsumeCardInfo cardInfo = this._Reader.ReadCardInfo(base._CardInfoSection, base._SectionPwd);
                if (cardInfo == null)
                {
                    base.MessageDialog("提示", "转账失败。" + Environment.NewLine + "无法确认卡信息,请重新读卡再试。");
                    this.Cursor = Cursors.Default;
                    return;
                }
                if (cardInfo.CardSourceID != dlg.CardInfo.CardSourceID)
                {
                    base.MessageDialog("提示", "转账失败。" + Environment.NewLine + "卡信息已变更,请重新读卡再试。");
                    this.Cursor = Cursors.Default;
                    return;
                }

                decimal fTotalRecharge = decimal.Parse(labTotalRecharge.Text);
                decimal fPreCost = dlg.PreCostMoney;

                try
                {
                    string strOldCardName = cardInfo.Name.Trim();
                    string strCurrentCardName = (this._UserInfo.ClassInfo.GradeInfo.gdm_cAbbreviation + this._UserInfo.cus_cChaName).Trim();
                    if (strOldCardName != strCurrentCardName)
                    {
                        ConsumeCardInfo changeCardInfo = new ConsumeCardInfo();
                        changeCardInfo.CardBalance = this._CardInfo.CardBalance;
                        changeCardInfo.CardNo = this._CardInfo.CardNo;
                        changeCardInfo.CardPwd = this._CardInfo.CardPwd;
                        changeCardInfo.CardSourceID = this._CardInfo.CardSourceID;
                        changeCardInfo.CardBalance = this._CardInfo.CardBalance;
                        changeCardInfo.Name = strCurrentCardName;

                        //年级信息发生变更,修改对应信息
                        ReturnValueInfo rvChangeCardInfo = this._Reader.WriteCardInfo(base._CardInfoSection, base._SectionPwd, changeCardInfo);
                    }
                }
                catch (Exception)
                { }

                //先进行物理卡充值
                ReturnValueInfo rvInfo = this._Reader.Recharge(base._CardInfoSection, base._SectionPwd, dlg.RechargeMoney);
                if (rvInfo.boolValue && !rvInfo.isError)
                {
                    //卡充值成功后,将原充值记录的状态更新为已完成
                    if (this._ListRechargeRecord != null)
                    {
                        for (int i = 0; i < this._ListRechargeRecord.Count; i++)
                        {
                            if (this._ListRechargeRecord[i] != null)
                            {
                                this._ListRechargeRecord[i].rcr_cStatus = Common.DefineConstantValue.ConsumeMoneyFlowStatus.Finished.ToString();

                                fPreCost += this._ListRechargeRecord[i].rcr_fRechargeMoney;
                                if (fPreCost < 0)
                                {
                                    //未将未结算预付款扣除完毕,余额不变
                                    if (i != this._ListRechargeRecord.Count - 1)
                                    {
                                        this._ListRechargeRecord[i].rcr_fBalance = this._CardInfo.CardBalance;
                                    }
                                    else
                                    {
                                        this._ListRechargeRecord[i].rcr_fBalance = this._CardInfo.CardBalance + fPreCost;
                                    }
                                }
                                else
                                {
                                    this._ListRechargeRecord[i].rcr_fBalance = this._CardInfo.CardBalance + Math.Abs(fPreCost);
                                }

                                this._ListRechargeRecord[i].rcr_dRechargeTime = DateTime.Now.AddSeconds(i);
                            }
                        }

                        decimal fPreCostRecharge = dlg.PreCostMoney;
                        if (fPreCostRecharge != 0)
                        {
                            fPreCostRecharge = Math.Abs(fPreCostRecharge);
                        }
                        rvInfo = this._IRechargeRecordBL.UpdateRechargeRecord(this._ListPreRechargeRecord, this._ListRechargeRecord, fPreCostRecharge);
                    }
                    else
                    {
                        rvInfo.messageText = "转账缓存信息异常,请重新打开本窗口。";
                        rvInfo.isError = true;
                    }

                    if (rvInfo.boolValue && !rvInfo.isError)
                    {
                        try
                        {
                            IMealBookingHistoryBL mealBl = MasterBLLFactory.GetBLL<IMealBookingHistoryBL>(MasterBLLFactory.MealBookingHistory);
                            MealBookingHistory_mbh_Info history = new MealBookingHistory_mbh_Info();
                            history.mbh_cTargetType = Common.DefineConstantValue.MealType.DebtAuto.ToString();
                            history.mbh_cTargetID = this._UserInfo.cus_cRecordID;
                            history.mbh_dMealDate = DateTime.Now.Date;
                            List<MealBookingHistory_mbh_Info> listHistory = mealBl.SearchRecords(history);
                            if (listHistory != null && listHistory.Count > 0)
                            {
                                DateTime? dtSysNow = DateTime.Now;
                                if (rvInfo.ValueObject != null)
                                {
                                    dtSysNow = Convert.ToDateTime(rvInfo.ValueObject);
                                }
                                if (dtSysNow == null)
                                {
                                    dtSysNow = DateTime.Now;
                                }
                                localLog.WriteLog(this._UserInfo.cus_cChaName + "转账完毕。时间:" + dtSysNow.ToString(), string.Empty, SystemLog.SystemLog.LogType.Trace);

                                ResetMealPlanning(this._UserInfo, dtSysNow.Value, listHistory);

                            }
                        }
                        catch (Exception exSub)
                        {
                            localLog.WriteLog(exSub.Message, string.Empty, SystemLog.SystemLog.LogType.Error);
                        }

                        //成功录入充值记录后提示成功
                        this.Cursor = Cursors.Default;
                        base.MessageDialog("提示", "充值成功。");

                        InitReadCard();
                    }
                    else
                    {
                        //录入充值记录失败,则需要将原先充入的卡金额扣除,如果卡已被取走,则需等待后台自动同步金额
                        rvInfo = this._Reader.Recharge(base._CardInfoSection, base._SectionPwd, dlg.RechargeMoney * -1);

                        this.Cursor = Cursors.Default;
                        base.MessageDialog("提示", "充值失败。" + Environment.NewLine + rvInfo.messageText);
                        return;
                    }
                }
                else
                {
                    this.Cursor = Cursors.Default;
                    base.MessageDialog("提示", "充值失败。" + Environment.NewLine + rvInfo.messageText);

                    return;
                }
            }
        }
示例#8
0
 /// <summary>
 /// 更新定餐计划
 /// </summary>
 /// <param name="strMealType"></param>
 /// <param name="userInfo"></param>
 void UpdateMealPlanning(string strMealType, CardUserMaster_cus_Info userInfo, MealBookingHistory_mbh_Info oldMealInfo)
 {
     try
     {
         IMealBookingHistoryBL mealBL = MasterBLLFactory.GetBLL<IMealBookingHistoryBL>(MasterBLLFactory.MealBookingHistory);
         MealBookingHistory_mbh_Info mealInfo = new MealBookingHistory_mbh_Info();
         mealInfo.mbh_cMealType = strMealType;
         mealInfo.mbh_cTargetID = userInfo.cus_cRecordID;
         mealInfo.mbh_dMealDate = DateTime.Now;
         List<MealBookingHistory_mbh_Info> listMealInfo = mealBL.SearchRecords(mealInfo);
         if (listMealInfo != null && listMealInfo.Count > 0)
         {
             MealBookingHistory_mbh_Info currentMealInfo = listMealInfo.FirstOrDefault();
             if (currentMealInfo != null)
             {
                 currentMealInfo.mbh_lIsSet = true;
                 //currentMealInfo.mbh_cTargetType = oldMealInfo.mbh_cTargetType;
                 currentMealInfo.mbh_dAddDate = DateTime.Now;
                 currentMealInfo.mbh_cAdd = "TQS";
                 ReturnValueInfo rvInfo = mealBL.UpdateRecordWithPreCost(currentMealInfo);
                 localLog.WriteLog(userInfo.cus_cChaName + ",更新计划成功。" + DateTime.Now.ToString(), string.Empty, SystemLog.SystemLog.LogType.Trace);
             }
         }
         else
         {
             localLog.WriteLog(userInfo.cus_cChaName + ",找不到可用的历史定餐计划。" + DateTime.Now.ToString(), string.Empty, SystemLog.SystemLog.LogType.Trace);
         }
     }
     catch (Exception ex)
     {
         localLog.WriteLog(userInfo.cus_cChaName + ",异常:" + ex.Message, string.Empty, SystemLog.SystemLog.LogType.Error);
     }
 }
        /// <summary>
        /// 获取卡用户的定餐计划信息列表
        /// </summary>
        /// <param name="UserID">用户ID(输入空值时为查询所有卡用户)</param>
        /// <param name="dtPlan">定餐计划日期</param>
        /// <param name="strMealType">用餐类型</param>
        /// <returns></returns>
        private List<MealBookingHistory_mbh_Info> GetMealPlan(Guid UserID, DateTime dtPlan, string strMealType, decimal fCost, string strAdd)
        {
            List<MealBookingHistory_mbh_Info> listMealPlanInfos = new List<MealBookingHistory_mbh_Info>();

            string strMealTypeAb = string.Empty;
            if (strMealType == Common.DefineConstantValue.MealType.Breakfast.ToString())
            {
                strMealTypeAb = "B";
            }
            else if (strMealType == Common.DefineConstantValue.MealType.Lunch.ToString())
            {
                strMealTypeAb = "L";
            }
            else if (strMealType == Common.DefineConstantValue.MealType.Supper.ToString())
            {
                strMealTypeAb = "D";
            }

            if (string.IsNullOrEmpty(strMealType))
            {
                return listMealPlanInfos;
            }

            StringBuilder strSql = new StringBuilder();
            strSql.AppendFormat("EXEC usp_GetUserSetMealPlanLists ");
            strSql.AppendFormat("'" + UserID.ToString() + "',");
            strSql.AppendFormat("'" + dtPlan.ToString("yyyy-MM-dd 00:00") + "',");
            strSql.AppendFormat(((int)dtPlan.DayOfWeek).ToString() + ",");
            strSql.AppendFormat("'" + strMealTypeAb + "'");

            using (SqlDataReader reader = DbHelperSQL.ExecuteReader(strSql.ToString()))
            {
                while (reader.Read())
                {
                    MealBookingHistory_mbh_Info mealInfo = new MealBookingHistory_mbh_Info();
                    mealInfo.mbh_cRecordID = Guid.NewGuid();
                    mealInfo.mbh_cTargetID = new Guid(reader["UserID"].ToString());
                    mealInfo.mbh_cMealType = strMealType;
                    mealInfo.mbh_fMealCost = fCost;
                    mealInfo.mbh_dMealDate = dtPlan.Date;
                    mealInfo.mbh_cTargetType = reader["SetFrom"].ToString();
                    mealInfo.mbh_lIsSet = int.Parse(reader["FinalMealSet"].ToString()) == 1 ? true : false;
                    mealInfo.mbh_cAdd = strAdd;
                    mealInfo.mbh_dAddDate = DateTime.Now;
                    listMealPlanInfos.Add(mealInfo);
                }
            }

            return listMealPlanInfos;
        }
示例#10
0
        /// <summary>
        /// 获取默认的用餐计划信息
        /// </summary>
        /// <param name="UserID">用户ID(</param>
        /// <param name="dtPlan">定餐计划日期</param>
        /// <param name="strMealType">用餐类型</param>
        /// <returns></returns>
        private MealBookingHistory_mbh_Info GetDefalutMealPlan(Guid UserID, DateTime dtPlan, string strMealType, bool lIsSetMeal, decimal fCost, string strAdd)
        {
            MealBookingHistory_mbh_Info mealInfo = new MealBookingHistory_mbh_Info();

            mealInfo.mbh_cRecordID = Guid.NewGuid();
            mealInfo.mbh_cTargetID = UserID;
            mealInfo.mbh_cTargetType = Common.DefineConstantValue.StuMealBookingType.Unknown.ToString();
            mealInfo.mbh_cMealType = strMealType;
            mealInfo.mbh_dMealDate = dtPlan.Date;
            mealInfo.mbh_lIsSet = lIsSetMeal;
            mealInfo.mbh_fMealCost = fCost;
            mealInfo.mbh_cAdd = strAdd;
            mealInfo.mbh_dAddDate = DateTime.Now;

            return mealInfo;
        }
示例#11
0
        public ReturnValueInfo UpdateRecordWithPreCost(MealBookingHistory_mbh_Info infoObject)
        {
            ReturnValueInfo rvInfo = new ReturnValueInfo();
            try
            {
                if (infoObject != null)
                {
                    using (SIOTSDB_HHZXDataContext db = new SIOTSDB_HHZXDataContext())
                    {
                        db.Connection.Open();
                        db.Transaction = db.Connection.BeginTransaction();
                        try
                        {
                            MealBookingHistory_mbh history = db.MealBookingHistory_mbh.Where(x => x.mbh_cRecordID == infoObject.mbh_cRecordID).FirstOrDefault();

                            if (history != null)
                            {
                                history.mbh_cAdd = infoObject.mbh_cAdd;
                                history.mbh_cMealType = infoObject.mbh_cMealType;
                                history.mbh_cTargetID = infoObject.mbh_cTargetID;
                                history.mbh_cTargetType = infoObject.mbh_cTargetType;
                                history.mbh_dAddDate = infoObject.mbh_dAddDate;
                                history.mbh_dMealDate = infoObject.mbh_dMealDate;
                                history.mbh_lIsSet = infoObject.mbh_lIsSet;
                                history.mbh_fMealCost = infoObject.mbh_fMealCost;

                                CardUserAccount_cua accountInfo = db.CardUserAccount_cua.Where(x => x.cua_cCUSID == infoObject.mbh_cTargetID).FirstOrDefault();

                                PreConsumeRecord_pcs preCostInfo = new PreConsumeRecord_pcs();
                                preCostInfo.pcs_cAccountID = accountInfo.cua_cRecordID;
                                preCostInfo.pcs_cAdd = infoObject.mbh_cAdd;
                                preCostInfo.pcs_cConsumeType = Common.DefineConstantValue.ConsumeMoneyFlowType.AdvanceMealCost.ToString();
                                preCostInfo.pcs_cRecordID = Guid.NewGuid();
                                preCostInfo.pcs_cSourceID = history.mbh_cRecordID;
                                preCostInfo.pcs_cUserID = history.mbh_cTargetID;
                                preCostInfo.pcs_dAddDate = DateTime.Now;
                                preCostInfo.pcs_dConsumeDate = DateTime.Now;
                                preCostInfo.pcs_fCost = history.mbh_fMealCost;
                                preCostInfo.pcs_lIsSettled = false;
                                db.PreConsumeRecord_pcs.InsertOnSubmit(preCostInfo);

                                db.SubmitChanges();
                                db.Transaction.Commit();
                                rvInfo.boolValue = true;
                                return rvInfo;
                            }
                            else
                            {
                                rvInfo.messageText = "GetEntity is null";
                            }
                            db.Transaction.Rollback();
                            db.Connection.Close();
                        }
                        catch (Exception exx)
                        {
                            db.Transaction.Rollback();
                            db.Connection.Close();
                            throw exx;
                        }
                    }
                }
                else
                {
                    rvInfo.messageText = Common.DefineConstantValue.SystemMessageText.strMessageText_E_ObjectNull;
                }
            }
            catch (Exception ex)
            {
                rvInfo.isError = true;
                rvInfo.messageText = ex.Message;
            }
            return rvInfo;
        }
示例#12
0
        public ReturnValueInfo UpdateRecord(MealBookingHistory_mbh_Info infoObject)
        {
            ReturnValueInfo rvInfo = new ReturnValueInfo();
            try
            {
                if (infoObject != null)
                {
                    using (SIOTSDB_HHZXDataContext db = new SIOTSDB_HHZXDataContext())
                    {
                        MealBookingHistory_mbh history = db.MealBookingHistory_mbh.Where(x => x.mbh_cRecordID == infoObject.mbh_cRecordID).FirstOrDefault();

                        if (history != null)
                        {
                            history.mbh_cAdd = infoObject.mbh_cAdd;
                            history.mbh_cMealType = infoObject.mbh_cMealType;
                            history.mbh_cTargetID = infoObject.mbh_cTargetID;
                            history.mbh_cTargetType = infoObject.mbh_cTargetType;
                            history.mbh_dAddDate = infoObject.mbh_dAddDate;
                            history.mbh_dMealDate = infoObject.mbh_dMealDate;
                            history.mbh_lIsSet = infoObject.mbh_lIsSet;
                            history.mbh_fMealCost = infoObject.mbh_fMealCost;

                            db.SubmitChanges();
                            rvInfo.boolValue = true;
                        }
                        else
                        {
                            rvInfo.messageText = "GetEntity is null";
                        }
                    }
                }
                else
                {
                    rvInfo.messageText = Common.DefineConstantValue.SystemMessageText.strMessageText_E_ObjectNull;
                }
            }
            catch (Exception ex)
            {
                rvInfo.isError = true;
                rvInfo.messageText = ex.Message;
            }
            return rvInfo;
        }
示例#13
0
 public ReturnValueInfo InsertRecord(MealBookingHistory_mbh_Info infoObject)
 {
     ReturnValueInfo rvInfo = new ReturnValueInfo();
     try
     {
         if (infoObject != null)
         {
             using (SIOTSDB_HHZXDataContext db = new SIOTSDB_HHZXDataContext())
             {
                 MealBookingHistory_mbh history = Common.General.CopyObjectValue<MealBookingHistory_mbh_Info, MealBookingHistory_mbh>(infoObject);
                 if (history != null)
                 {
                     db.MealBookingHistory_mbh.InsertOnSubmit(history);
                     db.SubmitChanges();
                     rvInfo.boolValue = true;
                     rvInfo.ValueObject = infoObject;
                 }
                 else
                 {
                     rvInfo.messageText = "TransEntity is null";
                 }
             }
         }
         else
         {
             rvInfo.messageText = Common.DefineConstantValue.SystemMessageText.strMessageText_E_ObjectNull;
         }
     }
     catch (Exception ex)
     {
         rvInfo.isError = true;
         rvInfo.messageText = ex.Message;
     }
     return rvInfo;
 }