protected void btnAddUser_Click(object sender, EventArgs e) { int userId = -1; if (int.TryParse(this.txtUserId.Value, out userId)) { using (_session = new Session()) { MsgSubscriber subscriber = new MsgSubscriber(); subscriber.UserId = userId; subscriber.IsGroup = false; subscriber.SubscribeTime = DateTime.Now; subscriber.TmplCode = this.txtTmplCode.Text.Trim(); if (!MsgSubscriber.Exists(_session, new string[] { "TmplCode", "UserId" }, new object[] { subscriber.TmplCode, subscriber.UserId })) { subscriber.Create(_session); QueryAndBindData(this.rptSubscribeUser, this.magicPagerUser, true, 1, magicPagerUser.PageSize, true); } else WebUtil.ShowMsg(this, "该用户已经订阅"); } } }
//Save Data private void SaveData() { MsgSubscriber msgSubscriber = new MsgSubscriber(); bool flag = true; try { msgSubscriber.TmplCode = Cast.String(txtTmplCode.Text.Trim()); msgSubscriber.UserId = Cast.Int(txtUserId.Text.Trim()); msgSubscriber.GroupId = Cast.Int(txtGroupId.Text.Trim()); msgSubscriber.IsGroup = Cast.Bool(txtIsGroup.Text.Trim()); msgSubscriber.SubscribeTime = Cast.DateTime(txtSubscribeTime.Text.Trim()); using (_session = new Session()) { if (IsAddNew()) { flag = msgSubscriber.Create(_session); } else { msgSubscriber.SubscriberId = int.Parse(this.txtSubscriberId.Value); flag = msgSubscriber.Update(_session, "TmplCode", "UserId", "GroupId", "IsGroup", "SubscribeTime"); } } this.txtSubscriberId.Value = msgSubscriber.SubscriberId.ToString(); if(flag) WebUtil.ShowMsg(this,"操作成功","提示"); else WebUtil.ShowMsg(this,"操作失败","提示"); } catch(UnauthorizedException ex) { WebUtil.ShowMsg(this,ex.Message,"警告"); } catch(ApplicationException ex) { WebUtil.ShowMsg(this,ex.Message,"提示"); } catch(Exception ex) { logger.Info("保存MsgSubscriber", ex); WebUtil.ShowMsg(this, "发生未处理的异常,请刷新页面重新操作,或者联系系统管理员"); } }