/// <summary> /// 得到一个对象实体 /// </summary> public Hownet.Model.Mesg GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,FillManID,FillMan,FillDate,LastDate,Title,TextContent,IsEnd,Remark from Mesg "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; Hownet.Model.Mesg model = new Hownet.Model.Mesg(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "") { model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } if (ds.Tables[0].Rows[0]["FillManID"] != null && ds.Tables[0].Rows[0]["FillManID"].ToString() != "") { model.FillManID = int.Parse(ds.Tables[0].Rows[0]["FillManID"].ToString()); } model.FillMan = ds.Tables[0].Rows[0]["FillMan"].ToString(); if (ds.Tables[0].Rows[0]["FillDate"] != null && ds.Tables[0].Rows[0]["FillDate"].ToString() != "") { model.FillDate = DateTime.Parse(ds.Tables[0].Rows[0]["FillDate"].ToString()); } if (ds.Tables[0].Rows[0]["LastDate"] != null && ds.Tables[0].Rows[0]["LastDate"].ToString() != "") { model.LastDate = DateTime.Parse(ds.Tables[0].Rows[0]["LastDate"].ToString()); } model.Title = ds.Tables[0].Rows[0]["Title"].ToString(); model.TextContent = ds.Tables[0].Rows[0]["TextContent"].ToString(); if (ds.Tables[0].Rows[0]["IsEnd"] != null && ds.Tables[0].Rows[0]["IsEnd"].ToString() != "") { model.IsEnd = int.Parse(ds.Tables[0].Rows[0]["IsEnd"].ToString()); } model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString(); model.A = 1; return(model); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Hownet.Model.Mesg model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Mesg("); strSql.Append("FillManID,FillMan,FillDate,LastDate,Title,TextContent,IsEnd,Remark)"); strSql.Append(" values ("); strSql.Append("@FillManID,@FillMan,@FillDate,@LastDate,@Title,@TextContent,@IsEnd,@Remark)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@FillManID", SqlDbType.Int, 4), new SqlParameter("@FillMan", SqlDbType.NVarChar, 50), new SqlParameter("@FillDate", SqlDbType.DateTime), new SqlParameter("@LastDate", SqlDbType.DateTime), new SqlParameter("@Title", SqlDbType.NVarChar, 4000), new SqlParameter("@TextContent", SqlDbType.Text), new SqlParameter("@IsEnd", SqlDbType.Int, 4), new SqlParameter("@Remark", SqlDbType.NVarChar, 4000) }; parameters[0].Value = model.FillManID; parameters[1].Value = model.FillMan; parameters[2].Value = model.FillDate; parameters[3].Value = model.LastDate; parameters[4].Value = model.Title; parameters[5].Value = model.TextContent; parameters[6].Value = model.IsEnd; parameters[7].Value = model.Remark; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }