Example #1
0
        /// <summary>
        ///  Map a DataTable's Rows to a List of MsgSubscriber Entity.
        /// </summary>
        /// <returns></returns>
        public static IList <MsgSubscriber> Row2Entity(System.Data.DataTable dt)
        {
            IList <MsgSubscriber> list = null;

            if (dt != null && dt.Rows.Count > 0)
            {
                list = new List <MsgSubscriber>(dt.Rows.Count);
                foreach (System.Data.DataRow row in dt.Rows)
                {
                    MsgSubscriber entity = Row2Entity(row);
                    if (entity != null)
                    {
                        list.Add(entity);
                    }
                }
            }
            return(list);
        }
Example #2
0
        /// <summary>
        ///  Map a DataRow to a MsgSubscriber Entity.
        /// </summary>
        /// <returns></returns>
        public static MsgSubscriber Row2Entity(System.Data.DataRow row)
        {
            if (row == null)
            {
                return(null);
            }

            MsgSubscriber entity = new MsgSubscriber();

            entity._subscriberId  = Cast.Int(row["MSG_SUB_ID"]);
            entity._tmplCode      = Cast.String(row["MSG_TMPL_CODE"]);
            entity._userId        = Cast.Int(row["USR_ID"]);
            entity._groupId       = Cast.Int(row["UGP_ID"]);
            entity._isGroup       = Cast.Bool(row["IS_GROUP"]);
            entity._subscribeTime = Cast.DateTime(row["MSG_SUB_TIME"]);

            return(entity);
        }
    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, "该用户已经订阅");

            }
        }
    }
Example #4
0
        /// <summary>
        /// 发送新消息
        /// </summary>
        /// <param name="session"></param>
        public static void SendNewMessage(ISession session)
        {
            IList <Message> newMsgs = session.CreateEntityQuery <Message>().And(Exp.Eq("Status", MessageStatus.New)).List <Message>();

            if (newMsgs != null && newMsgs.Count > 0)
            {
                ((Session)session).BeginTransaction();
                try
                {
                    foreach (Message msg in newMsgs)
                    {
                        IList <User> sendingUsers = MsgSubscriber.GetSendingUser4Subscriber(session, msg.TmplCode);
                        foreach (User user in sendingUsers)
                        {
                            MsgReceiver msgrev = new MsgReceiver();
                            msgrev.MessageId      = msg.MessageId;
                            msgrev.ReadStatus     = MessageReadStatus.Unread;
                            msgrev.SendTime       = msg.SendTime;
                            msgrev.SubscriberType = true;
                            msgrev.UserId         = user.UserId;
                            msgrev.ReceiveTime    = DateTime.Now;
                            msgrev.ExpireTime     = msg.ExpireTime;
                            msgrev.Create(session);
                        }
                        msg.Status = MessageStatus.Sent;
                        msg.Update(session, "Status");
                    }

                    ((Session)session).Commit();
                }
                catch
                {
                    ((Session)session).Rollback();
                    throw;
                }
            }
        }
Example #5
0
        /// <summary>
        ///  Map a DataRow to a MsgSubscriber Entity.
        /// </summary>
        /// <returns></returns>
        public static MsgSubscriber Row2Entity(System.Data.DataRow row)
        {
            if(row == null) return null;

            MsgSubscriber entity = new MsgSubscriber();

            entity._subscriberId= Cast.Int(row["MSG_SUB_ID"]);
            entity._tmplCode= Cast.String(row["MSG_TMPL_CODE"]);
            entity._userId= Cast.Int(row["USR_ID"]);
            entity._groupId= Cast.Int(row["UGP_ID"]);
            entity._isGroup= Cast.Bool(row["IS_GROUP"]);
            entity._subscribeTime= Cast.DateTime(row["MSG_SUB_TIME"]);

               return entity;
        }
 //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, "发生未处理的异常,请刷新页面重新操作,或者联系系统管理员");
     }
 }