protected void btnUnRelease_Click(object sender, EventArgs e)
 {
     LAnnounceData model = new LAnnounceData();
     LAnnounceBB announceBB = new LAnnounceBB();
     try
     {
         if (this.IdValue != null && this.IdValue != 0)
         {
             model = announceBB.GetModel(this.IdValue);
             model.isIndexShow = false;
             model.updtEmpId = this.currentUser.empId;
             model.updtDt = DateTime.Now.ToString();
             announceBB.ModifyRecord(model);
         }
         else
         {
             this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "alert('取消发布失败!');", true);
         }
     }
     catch (Exception ex)
     {
         this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
         return;
     }
     finally
     {
         announceBB.Dispose();
     }
     Response.Redirect("LAnnounceList.aspx?itemNo=" + this.itemNo + "&pTypeNo=main", false);
 }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">model</param>
        public int AddRecord(LAnnounceData model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("set nocount on; ");
            strSql.Append("insert into LAnnounce(");
            strSql.Append(@"title,content,fileIds,isIndexShow,author,updtDt,updtEmpId)");
            strSql.Append(" values (");
            strSql.Append(@"@title,@content,@fileIds,@isIndexShow,@author,@updtDt,@updtEmpId)");
            strSql.Append("; select @@identity; set nocount off; ");
            SqlParameter[] parameters = {
                    new SqlParameter("@title", SqlDbType.NVarChar,100),
                    new SqlParameter("@content", SqlDbType.NText),
                    new SqlParameter("@fileIds", SqlDbType.VarChar,100),
                    new SqlParameter("@isIndexShow", SqlDbType.Bit),
                    new SqlParameter("@author", SqlDbType.NVarChar,10),
                    new SqlParameter("@updtDt", SqlDbType.DateTime),
                    new SqlParameter("@updtEmpId", SqlDbType.Int)
                };
            parameters[0].Value = model.title;
            parameters[1].Value = model.content;
            parameters[2].Value = model.fileIds;
            parameters[3].Value = model.isIndexShow;
            parameters[4].Value = model.author;
            parameters[5].Value = model.updtDt == string.Empty ? null : model.updtDt;
            parameters[6].Value = model.updtEmpId;

            int id = 0;
            try
            {
                object ret = SqlHelper.ExecuteScalar(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);

                if (ret != null && ret != DBNull.Value)
                {
                    id = Convert.ToInt32(ret);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return id;
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">model</param>
        public bool ModifyRecord(LAnnounceData model)
        {
            bool ret = false;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update LAnnounce set ");
            strSql.Append("title=@title,");
            strSql.Append("content=@content,");
            strSql.Append("fileIds=@fileIds,");
            strSql.Append("isIndexShow=@isIndexShow,");
            strSql.Append("author=@author,");
            strSql.Append("updtDt=@updtDt,");
            strSql.Append("updtEmpId=@updtEmpId");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int),
                    new SqlParameter("@title", SqlDbType.NVarChar,100),
                    new SqlParameter("@content", SqlDbType.NText),
                    new SqlParameter("@fileIds", SqlDbType.VarChar,100),
                    new SqlParameter("@isIndexShow", SqlDbType.Bit),
                    new SqlParameter("@author", SqlDbType.NVarChar,10),
                    new SqlParameter("@updtDt", SqlDbType.DateTime),
                    new SqlParameter("@updtEmpId", SqlDbType.Int)
                };
            parameters[0].Value = model.id;
            parameters[1].Value = model.title;
            parameters[2].Value = model.content;
            parameters[3].Value = model.fileIds;
            parameters[4].Value = model.isIndexShow;
            parameters[5].Value = model.author;
            parameters[6].Value = model.updtDt == string.Empty ? null : model.updtDt;
            parameters[7].Value = model.updtEmpId;

            try
            {
                SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);
                ret = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ret;
        }
        /// <summary>
        /// 得到一个model
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns>model</returns>
        public LAnnounceData GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select id,title,content,fileIds,isIndexShow,author,updtDt,updtEmpId from LAnnounce");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int)
                };
            parameters[0].Value = id;

            LAnnounceData model = new LAnnounceData();
            DataSet ds = SqlHelper.ExecuteDataset(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow row = ds.Tables[0].Rows[0];
                if (row["id"] != DBNull.Value)
                {
                    model.id = Convert.ToInt32(row["id"]);
                }
                if (row["title"] != DBNull.Value)
                {
                    model.title = Convert.ToString(row["title"]);
                }
                if (row["content"] != DBNull.Value)
                {
                    model.content = Convert.ToString(row["content"]);
                }
                if (row["fileIds"] != DBNull.Value)
                {
                    model.fileIds = Convert.ToString(row["fileIds"]);
                }
                if (row["isIndexShow"] != DBNull.Value)
                {
                    model.isIndexShow = Convert.ToBoolean(row["isIndexShow"]);
                }
                if (row["author"] != DBNull.Value)
                {
                    model.author = Convert.ToString(row["author"]);
                }
                if (row["updtDt"] != DBNull.Value)
                {
                    model.updtDt = Convert.ToString(row["updtDt"]);
                }
                if (row["updtEmpId"] != DBNull.Value)
                {
                    model.updtEmpId = Convert.ToInt32(row["updtEmpId"]);
                }
                return model;
            }
            else
            {
                return null;
            }
        }
 protected void btnRelease_Click(object sender, EventArgs e)
 {
     //获取选中的数据Id
     foreach (GridViewRow gvrow in this.grid.Rows)
     {
         CheckBox chkId = (CheckBox)gvrow.FindControl("chkId");
         string id = "";
         if (chkId.Checked == true)
         {
             id = chkId.ValidationGroup;
             LAnnounceBB announceBB = new LAnnounceBB();
             try
             {
                 LAnnounceData model = new LAnnounceData();
                 model = announceBB.GetModel(int.Parse(id));
                 if (model.isIndexShow)
                 {
                     this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"此通知已经发布!\");", true);
                 }
                 else
                 {
                     model.isIndexShow = true;
                     announceBB.ModifyRecord(model);
                     this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"发布成功!\");", true);
                 }
             }
             finally
             {
                 announceBB.Dispose();
             }
             this.BindGrid();
             return;
         }
     }
     this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"请选择一条记录!\");", true);
     return;
 }
 /// <summary>
 /// 更新一条数据
 /// </summary>
 /// <param name="model">model</param>
 public bool ModifyRecord(LAnnounceData model)
 {
     return this.announceDB.ModifyRecord(model);
 }
 /// <summary>
 /// 增加一条数据
 /// </summary>
 /// <param name="model">model</param>
 public int AddRecord(LAnnounceData model)
 {
     return this.announceDB.AddRecord(model);
 }
 /// <summary>
 /// 实体类赋值
 /// </summary>
 /// <param name="model">实体类实例</param>
 private void SetModel(ref LAnnounceData model)
 {
     model.title = this.title.Text;
     model.content = this.content.Text;
     model.fileIds = this.fileIds.Value;
     model.author = this.author.Text;
     model.updtEmpId = this.currentUser.empId;
     model.updtDt = DateTime.Now.ToString();
 }
 protected bool Save()
 {
     if (!this.Validata()) return false;
     LAnnounceData model = new LAnnounceData();
     LAnnounceBB announceBB = new LAnnounceBB();
     try
     {
         if (this.State == "1")
         {
             this.SetModel(ref model);
             this.IdValue = announceBB.AddRecord(model);
         }
         else if (this.State == "2")
         {
             model = announceBB.GetModel(this.IdValue);
             this.SetModel(ref model);
             announceBB.ModifyRecord(model);
         }
         return true;
     }
     catch (Exception ex)
     {
         this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
         return false;
     }
     finally
     {
         announceBB.Dispose();
     }
 }