/// <summary> /// 公共发布界面 /// </summary> /// <returns></returns> public ActionResult notice() { int n_id = string.IsNullOrEmpty(Request["n_id"]) ? 0 : Int32.Parse(Request["n_id"]); JMP.BLL.jmp_notice noticebll = new JMP.BLL.jmp_notice(); JMP.MDL.jmp_notice mo = new JMP.MDL.jmp_notice(); if (n_id > 0) { mo = noticebll.GetModel(n_id); } ViewBag.mo = mo; return(View()); }
/// <summary> /// 得到一个对象实体 /// </summary> public JMP.MDL.jmp_notice GetModel(int n_id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select n_id, n_title, n_content, n_time, n_top, n_state, n_locuserid "); strSql.Append(" from jmp_notice "); strSql.Append(" where n_id=@n_id"); SqlParameter[] parameters = { new SqlParameter("@n_id", SqlDbType.Int, 4) }; parameters[0].Value = n_id; JMP.MDL.jmp_notice model = new JMP.MDL.jmp_notice(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["n_id"].ToString() != "") { model.n_id = int.Parse(ds.Tables[0].Rows[0]["n_id"].ToString()); } model.n_title = ds.Tables[0].Rows[0]["n_title"].ToString(); model.n_content = ds.Tables[0].Rows[0]["n_content"].ToString(); if (ds.Tables[0].Rows[0]["n_time"].ToString() != "") { model.n_time = DateTime.Parse(ds.Tables[0].Rows[0]["n_time"].ToString()); } if (ds.Tables[0].Rows[0]["n_top"].ToString() != "") { model.n_top = int.Parse(ds.Tables[0].Rows[0]["n_top"].ToString()); } if (ds.Tables[0].Rows[0]["n_state"].ToString() != "") { model.n_state = int.Parse(ds.Tables[0].Rows[0]["n_state"].ToString()); } if (ds.Tables[0].Rows[0]["n_locuserid"].ToString() != "") { model.n_locuserid = int.Parse(ds.Tables[0].Rows[0]["n_locuserid"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(JMP.MDL.jmp_notice model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update jmp_notice set "); strSql.Append(" n_title = @n_title , "); strSql.Append(" n_content = @n_content , "); strSql.Append(" n_time = @n_time , "); strSql.Append(" n_top = @n_top , "); strSql.Append(" n_state = @n_state , "); strSql.Append(" n_locuserid = @n_locuserid "); strSql.Append(" where n_id=@n_id "); SqlParameter[] parameters = { new SqlParameter("@n_id", SqlDbType.Int, 4), new SqlParameter("@n_title", SqlDbType.NVarChar, -1), new SqlParameter("@n_content", SqlDbType.NVarChar, -1), new SqlParameter("@n_time", SqlDbType.DateTime), new SqlParameter("@n_top", SqlDbType.Int, 4), new SqlParameter("@n_state", SqlDbType.Int, 4), new SqlParameter("@n_locuserid", SqlDbType.Int, 4) }; parameters[0].Value = model.n_id; parameters[1].Value = model.n_title; parameters[2].Value = model.n_content; parameters[3].Value = model.n_time; parameters[4].Value = model.n_top; parameters[5].Value = model.n_state; parameters[6].Value = model.n_locuserid; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 获得数据列表 /// </summary> public List <JMP.MDL.jmp_notice> DataTableToList(DataTable dt) { List <JMP.MDL.jmp_notice> modelList = new List <JMP.MDL.jmp_notice>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { JMP.MDL.jmp_notice model; for (int n = 0; n < rowsCount; n++) { model = new JMP.MDL.jmp_notice(); if (dt.Rows[n]["n_id"].ToString() != "") { model.n_id = int.Parse(dt.Rows[n]["n_id"].ToString()); } model.n_title = dt.Rows[n]["n_title"].ToString(); model.n_content = dt.Rows[n]["n_content"].ToString(); if (dt.Rows[n]["n_time"].ToString() != "") { model.n_time = DateTime.Parse(dt.Rows[n]["n_time"].ToString()); } if (dt.Rows[n]["n_top"].ToString() != "") { model.n_top = int.Parse(dt.Rows[n]["n_top"].ToString()); } if (dt.Rows[n]["n_state"].ToString() != "") { model.n_state = int.Parse(dt.Rows[n]["n_state"].ToString()); } if (dt.Rows[n]["n_locuserid"].ToString() != "") { model.n_locuserid = int.Parse(dt.Rows[n]["n_locuserid"].ToString()); } modelList.Add(model); } } return(modelList); }
/// <summary> /// 添加或修改公告 /// </summary> /// <returns></returns> public JsonResult insertOrUpdatenotice(JMP.MDL.jmp_notice mo) { object retJson = new { success = 0, msg = "操作失败" }; JMP.BLL.jmp_notice noticebll = new JMP.BLL.jmp_notice(); mo.n_time = DateTime.Now; mo.n_state = 0; mo.n_locuserid = UserInfo.UserId; if (mo.n_id > 0) { JMP.MDL.jmp_notice mod = noticebll.GetModel(mo.n_id); var modClone = mod.Clone(); mod.n_title = mo.n_title; mod.n_content = mo.n_content; mod.n_top = mo.n_top; if (noticebll.Update(mod)) { Logger.ModifyLog("修改公告", modClone, mo); retJson = new { success = 1, msg = "修改成功!" }; } else { retJson = new { success = 1, msg = "修改失败!" }; } } else { int cg = noticebll.Add(mo); if (cg > 0) { Logger.CreateLog("新增公告", mo); retJson = new { success = 1, msg = "发布成功!" }; } else { retJson = new { success = 0, msg = "发布失败!" }; } } return(Json(retJson)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(JMP.MDL.jmp_notice model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into jmp_notice("); strSql.Append("n_title,n_content,n_time,n_top,n_state,n_locuserid"); strSql.Append(") values ("); strSql.Append("@n_title,@n_content,@n_time,@n_top,@n_state,@n_locuserid"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@n_title", SqlDbType.NVarChar, -1), new SqlParameter("@n_content", SqlDbType.NVarChar, -1), new SqlParameter("@n_time", SqlDbType.DateTime), new SqlParameter("@n_top", SqlDbType.Int, 4), new SqlParameter("@n_state", SqlDbType.Int, 4), new SqlParameter("@n_locuserid", SqlDbType.Int, 4) }; parameters[0].Value = model.n_title; parameters[1].Value = model.n_content; parameters[2].Value = model.n_time; parameters[3].Value = model.n_top; parameters[4].Value = model.n_state; parameters[5].Value = model.n_locuserid; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(JMP.MDL.jmp_notice model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(JMP.MDL.jmp_notice model) { return(dal.Add(model)); }