//数据绑定 void Bind() { int gid = Str2Int(q("id"), 0); Daiv_OA.Entity.ParentMessageEntity model = new Daiv_OA.Entity.ParentMessageEntity(); model = new Daiv_OA.BLL.ParentMessageBLL().GetEntity(gid); this.Mtitle.Text = model.Mtitle; this.Content.Text = model.Content; }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Daiv_OA.Entity.ParentMessageEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update [OA_ParentMessage] set "); strSql.Append("ToUid=" + model.ToUid + ","); strSql.Append("FromUid=" + model.FromUid + ","); strSql.Append("Mtitle='" + model.Mtitle + "',"); strSql.Append("Content='" + model.Content + "',"); strSql.Append("IsRead=" + model.IsRead + ","); strSql.Append("Addtime='" + model.Addtime + "',"); strSql.Append("Touser='******',"); strSql.Append("IsDeleted=" + model.IsDeleted + "");//注意:最后拼接内容 strSql.Append(" where Mid=" + model.Mid + " "); DbHelperSQL.ExecuteSql(strSql.ToString()); }
/// <summary> /// 得到一个对象实体 /// </summary> public Daiv_OA.Entity.ParentMessageEntity GetEntity(int Mid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 "); strSql.Append(" Mid ,ToUid ,FromUid ,Mtitle ,Content ,IsRead ,Addtime ,Touser ,IsDeleted "); strSql.Append(" FROM [OA_ParentMessage] "); strSql.Append(" where Mid=" + Mid + " "); Daiv_OA.Entity.ParentMessageEntity model = new Daiv_OA.Entity.ParentMessageEntity(); DataSet ds = DbHelperSQL.Query(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { return(ConvertModel(ds.Tables[0], 0)); } else { return(null); } }
/// <summary> /// 构造实体对象 /// </summary> /// <param name="dt"></param> /// <param name="rowindex"></param> /// <returns></returns> public Daiv_OA.Entity.ParentMessageEntity ConvertModel(DataTable dt, int rowindex) { Daiv_OA.Entity.ParentMessageEntity model = new Daiv_OA.Entity.ParentMessageEntity(); try { if (dt.Rows[rowindex]["Mid"].ToString() != "") { model.Mid = int.Parse(dt.Rows[rowindex]["Mid"].ToString()); } if (dt.Rows[rowindex]["ToUid"].ToString() != "") { model.ToUid = int.Parse(dt.Rows[rowindex]["ToUid"].ToString()); } if (dt.Rows[rowindex]["FromUid"].ToString() != "") { model.FromUid = int.Parse(dt.Rows[rowindex]["FromUid"].ToString()); } model.Mtitle = dt.Rows[rowindex]["Mtitle"].ToString(); model.Content = dt.Rows[rowindex]["Content"].ToString(); if (dt.Rows[rowindex]["IsRead"].ToString() != "") { model.IsRead = int.Parse(dt.Rows[rowindex]["IsRead"].ToString()); } if (dt.Rows[rowindex]["Addtime"] != null) { model.Addtime = DateTime.Parse(dt.Rows[rowindex]["Addtime"].ToString()); } model.Touser = dt.Rows[rowindex]["Touser"].ToString(); if (dt.Rows[rowindex]["IsDeleted"].ToString() != "") { model.IsDeleted = int.Parse(dt.Rows[rowindex]["IsDeleted"].ToString()); } } catch (Exception ex) { log.Info("转换成用户对象失败!原因:" + ex.Message); return(new Entity.ParentMessageEntity()); } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Daiv_OA.Entity.ParentMessageEntity model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.ToUid > 0) { strSql1.Append("ToUid,"); strSql2.Append("" + model.ToUid + ","); } if (model.FromUid >= 0) { strSql1.Append("FromUid,"); strSql2.Append("" + model.FromUid + ","); } if (model.Mtitle != null) { strSql1.Append("Mtitle,"); strSql2.Append("'" + model.Mtitle + "',"); } if (model.Content != null) { strSql1.Append("Content,"); strSql2.Append("'" + model.Content + "',"); } if (model.IsRead >= 0) { strSql1.Append("IsRead,"); strSql2.Append("" + model.IsRead + ","); } if (model.Addtime != null) { strSql1.Append("Addtime,"); strSql2.Append("'" + model.Addtime + "',"); } if (model.Touser != null) { strSql1.Append("Touser,"); strSql2.Append("'" + model.Touser + "',"); } if (model.IsDeleted >= 0) { strSql1.Append("IsDeleted,"); strSql2.Append("" + model.IsDeleted + ","); } strSql.Append("insert into [OA_ParentMessage]("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); strSql.Append(";select @@IDENTITY"); object obj = DbHelperSQL.GetSingle(strSql.ToString()); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }