private void btnCancel_Click(object sender, EventArgs e)
 {//取消优惠的代码逻辑
     if (CheckInput())
     {
         IUnitWork unitWork = ProviderFactory.Create <IUnitWork>(AppSettings.CurrentSetting.ParkConnect);
         //1.删除优惠信息表的此项数据
         IPREPreferentialProvider preProvider = ProviderFactory.Create <IPREPreferentialProvider>(AppSettings.CurrentSetting.ParkConnect);
         preProvider.Delete(_CurrentPreInfo, unitWork);
         //2.将Card表的优惠时数减去
         ICardProvider cardProvider = ProviderFactory.Create <ICardProvider>(AppSettings.CurrentSetting.ParkConnect);
         CardInfo      card         = cardProvider.GetByID(_CurrentPreInfo.CardID).QueryObject;
         CardInfo      newVal       = card.Clone();
         newVal.DiscountHour -= _CurrentPreInfo.PreferentialHour;
         if (newVal.DiscountHour < 0)
         {
             newVal.DiscountHour = 0;
         }
         cardProvider.Update(newVal, card, unitWork);
         //3.保存优惠操作记录
         IPREPreferentialLogProvider preLogProvider = ProviderFactory.Create <IPREPreferentialLogProvider>(AppSettings.CurrentSetting.ParkConnect);
         PREPreferentialLog          log            = _CurrentPreInfo.CreateLog();
         log.OperatorTime    = DateTime.Now;
         log.IsCancel        = 1;
         log.CancelReason    = this.txtCancelReason.Text.Trim();
         log.WorkstationID   = PRESysOptionSetting.Current.PRESysOption.CurrentWorkstationID;
         log.WorkstationName = PRESysOptionSetting.Current.PRESysOption.CurrentWorkstation;
         log.OperatorID      = PREOperatorInfo.CurrentOperator.OperatorID;
         preLogProvider.Insert(log, unitWork);
         CommandResult result = unitWork.Commit();
         if (result.Result == ResultCode.Successful)
         {
             MessageBox.Show("取消成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             ClearCardInfo();
             ClearInput();
             btnCancel.Enabled = false;
         }
         else
         {
             MessageBox.Show(result.Message);
         }
     }
 }
Esempio n. 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (CheckInput())
            {
                PREPreferentialInfo info = GetItemFromInput();
                //1.插入优惠信息
                IUnitWork unitWork = ProviderFactory.Create <IUnitWork>(AppSettings.CurrentSetting.ParkConnect);
                IPREPreferentialProvider preProvider = ProviderFactory.Create <IPREPreferentialProvider>(AppSettings.CurrentSetting.ParkConnect);
                preProvider.Insert(info, unitWork);
                //2.更新卡片的优惠信息

                ICardProvider cardProvider = ProviderFactory.Create <ICardProvider>(AppSettings.CurrentSetting.ParkConnect);
                CardInfo      card         = cardProvider.GetByID(info.CardID).QueryObject;
                if (card == null)
                {
                    MessageBox.Show("没有此卡片!");
                    return;
                }
                CardInfo newCard = card.Clone();
                newCard.DiscountHour    += info.PreferentialHour;
                newCard.PreferentialTime = info.PreferentialTime;
                cardProvider.Update(newCard, card, unitWork);
                //3.保存优惠操作记录
                IPREPreferentialLogProvider logProvider = ProviderFactory.Create <IPREPreferentialLogProvider>(AppSettings.CurrentSetting.ParkConnect);
                PREPreferentialLog          log         = info.CreateLog();
                log.OperatorTime = DateTime.Now;
                logProvider.Insert(log, unitWork);
                CommandResult result = unitWork.Commit();
                if (result.Result == ResultCode.Successful)
                {
                    MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ClearInput();
                }
                else
                {
                    MessageBox.Show(result.Message);
                }
            }
        }