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); } } }
/// <summary> /// 增加优惠信息 /// </summary> /// <param name="info"></param> /// <returns></returns> public CommandResult Insert(PREPreferentialInfo info) { return(provider.Insert(info)); }