예제 #1
0
        /// <summary>
        ///  Map a DataRow to a MsgTemplate Entity.
        /// </summary>
        /// <returns></returns>
        public static MsgTemplate Row2Entity(System.Data.DataRow row)
        {
            if (row == null)
            {
                return(null);
            }

            MsgTemplate entity = new MsgTemplate();

            entity._tmplCode      = Cast.String(row["MSG_TMPL_CODE"]);
            entity._name          = Cast.String(row["MSG_TMPL_NAME"]);
            entity._msgTypeId     = Cast.Int(row["MSG_TYPE_ID"]);
            entity._accessibility = Cast.Enum <MessageAccessibility>(row["MSG_TMPL_ACCESS"]);
            entity._expires       = Cast.Int(row["EXPIRE_TIME"]);
            entity._source        = Cast.String(row["MSG_TMPL_SRC"]);
            entity._viewEntry     = Cast.String(row["ENTRY_URL"]);
            entity._titleFormat   = Cast.String(row["TITLE_FORMAT"]);
            entity._contentFormat = Cast.String(row["CONTENT_FORMAT"]);
            entity._navId         = Cast.Int(row["MSG_OPT"]);
            entity._responseEntry = Cast.String(row["REPLY_URL"]);
            entity._createTime    = Cast.DateTime(row["CREATE_TIME"]);
            entity._modifyTime    = Cast.DateTime(row["MODIFY_TIME"]);
            entity._createBy      = Cast.Int(row["CREATE_BY"]);
            entity._modifyBy      = Cast.Int(row["MODIFY_BY"]);

            return(entity);
        }
예제 #2
0
        /// <summary>
        ///  Map a DataTable's Rows to a List of MsgTemplate Entity.
        /// </summary>
        /// <returns></returns>
        public static IList <MsgTemplate> Row2Entity(System.Data.DataTable dt)
        {
            IList <MsgTemplate> list = null;

            if (dt != null && dt.Rows.Count > 0)
            {
                list = new List <MsgTemplate>(dt.Rows.Count);
                foreach (System.Data.DataRow row in dt.Rows)
                {
                    MsgTemplate entity = Row2Entity(row);
                    if (entity != null)
                    {
                        list.Add(entity);
                    }
                }
            }
            return(list);
        }
예제 #3
0
        /// <summary>
        /// 创建新消息
        /// </summary>
        /// <param name="session"></param>
        /// <param name="tmplCode"></param>
        /// <param name="title"></param>
        /// <param name="content"></param>
        /// <param name="createBy"></param>
        /// <param name="sentAtOnce"></param>
        /// <param name="sentTime"></param>
        public static void NewMessage(ISession session, string tmplCode, string title, string content, string createBy, bool sentAtOnce, DateTime sentTime)
        {
            MsgTemplate tmpl = MsgTemplate.Retrieve(session, tmplCode);

            if (tmpl != null)
            {
                Message msg = new Message();
                msg._accessibility = tmpl.Accessibility;
                msg._source        = tmpl.Source;
                msg._destination   = "";
                if (tmpl.Expires > 0)
                {
                    msg._expireTime = DateTime.Now.AddSeconds(tmpl.Expires);
                }
                msg._createBy      = createBy;
                msg._createTime    = DateTime.Now;
                msg._msgTypeId     = tmpl.MsgTypeId;
                msg._responseEntry = tmpl.ResponseEntry;
                if (!sentAtOnce)
                {
                    if (sentTime < DateTime.Now)
                    {
                        throw new Exception("发送时间不能小于当前时间");
                    }
                    msg._sendTime = sentTime;
                }
                msg._status   = MessageStatus.New;
                msg._title    = title;
                msg._content  = content;
                msg._tmplCode = tmplCode;
                if (!msg.Create(session))
                {
                    logger.Info(string.Format("创建消息失败.模板代码:{0},标题:{1},内容:{2},创建人:{3}", tmplCode, title, content, createBy));
                }
            }
            else
            {
                throw new Exception(string.Format("指定的消息模板代码不存在;模板代码:{0}", tmplCode));
            }
        }
예제 #4
0
        /// <summary>
        ///  Map a DataRow to a MsgTemplate Entity.
        /// </summary>
        /// <returns></returns>
        public static MsgTemplate Row2Entity(System.Data.DataRow row)
        {
            if(row == null) return null;

            MsgTemplate entity = new MsgTemplate();

            entity._tmplCode= Cast.String(row["MSG_TMPL_CODE"]);
            entity._name= Cast.String(row["MSG_TMPL_NAME"]);
            entity._msgTypeId= Cast.Int(row["MSG_TYPE_ID"]);
            entity._accessibility= Cast.Enum<MessageAccessibility>(row["MSG_TMPL_ACCESS"]);
            entity._expires= Cast.Int(row["EXPIRE_TIME"]);
            entity._source= Cast.String(row["MSG_TMPL_SRC"]);
            entity._viewEntry= Cast.String(row["ENTRY_URL"]);
            entity._titleFormat= Cast.String(row["TITLE_FORMAT"]);
            entity._contentFormat= Cast.String(row["CONTENT_FORMAT"]);
            entity._navId= Cast.Int(row["MSG_OPT"]);
            entity._responseEntry= Cast.String(row["REPLY_URL"]);
            entity._createTime= Cast.DateTime(row["CREATE_TIME"]);
            entity._modifyTime= Cast.DateTime(row["MODIFY_TIME"]);
            entity._createBy= Cast.Int(row["CREATE_BY"]);
            entity._modifyBy= Cast.Int(row["MODIFY_BY"]);

               return entity;
        }
    //Save Data
    private void SaveData()
    {
        MsgTemplate msgTemplate = new  MsgTemplate();
        bool flag = true;
        try
        {
                msgTemplate.Name = Cast.String(txtName.Text.Trim());
                msgTemplate.MsgTypeId = Cast.Int(ddlMsgType.SelectedValue.Trim());
                msgTemplate.Accessibility = Cast.Enum<MessageAccessibility>(rdlAccessibility.SelectedValue);
                msgTemplate.Expires = Cast.Int(txtExpires.Text.Trim());
                msgTemplate.Source = Cast.String(txtSource.Text.Trim());
                msgTemplate.ViewEntry = Cast.String(txtViewEntry.Text.Trim());
                msgTemplate.TitleFormat = Cast.String(txtTitleFormat.Value.Trim());
                msgTemplate.ContentFormat = Cast.String(txtContentFormat.Value.Trim());
                msgTemplate.NavId = Cast.Int(txtNavId.Value.Trim());
                msgTemplate.ResponseEntry = Cast.String(txtResponseEntry.Text.Trim());
                msgTemplate.ModifyBy = SecuritySession.CurrentUser.UserId;
                msgTemplate.ModifyTime = DateTime.Now;
                msgTemplate.TmplCode = this.txtTmplCode.Text.Trim();
            using (_session = new Session())
            {
                if (IsAddNew())
                {
                    msgTemplate.CreateBy = msgTemplate.ModifyBy;
                    msgTemplate.CreateTime = msgTemplate.ModifyTime;
                    flag = msgTemplate.Create(_session);
                }
                else
                {

                   flag = msgTemplate.Update(_session,  "Name",  "MsgType",  "Accessibility",  "Expires",  "Source",  "ViewEntry",  "TitleFormat",  "ContentFormat",  "NavId",  "ResponseEntry");
                }
            }
            this.hidTmplCode.Value = msgTemplate.TmplCode.Trim();
            this.txtTmplCode.Text = msgTemplate.TmplCode.Trim();
            this.txtTmplCode.ReadOnly = true;
           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("保存消息模板", ex);
            WebUtil.ShowMsg(this, "发生未处理的异常,请刷新页面重新操作,或者联系系统管理员");
        }
    }