/// <summary> /// 得到一个对象实体 /// </summary> public XHD.Model.ssn_art DataRowToModel(DataRow row) { XHD.Model.ssn_art model = new XHD.Model.ssn_art(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["factory_Id"] != null) { model.factory_Id = row["factory_Id"].ToString(); } if (row["Art_title"] != null) { model.Art_title = row["Art_title"].ToString(); } if (row["Art_title_en"] != null) { model.Art_title_en = row["Art_title_en"].ToString(); } if (row["Art_Menu_Id"] != null && row["Art_Menu_Id"].ToString() != "") { model.Art_Menu_Id = int.Parse(row["Art_Menu_Id"].ToString()); } if (row["Art_Content"] != null) { model.Art_Content = row["Art_Content"].ToString(); } if (row["image_lst"] != null) { model.image_lst = row["image_lst"].ToString(); } if (row["Art_order"] != null && row["Art_order"].ToString() != "") { model.Art_order = int.Parse(row["Art_order"].ToString()); } if (row["is_del"] != null && row["is_del"].ToString() != "") { model.is_del = int.Parse(row["is_del"].ToString()); } if (row["Creater_Uid"] != null && row["Creater_Uid"].ToString() != "") { model.Creater_Uid = row["Creater_Uid"].ToString(); } if (row["Creater_Name"] != null) { model.Creater_Name = row["Creater_Name"].ToString(); } if (row["Create_Date"] != null && row["Create_Date"].ToString() != "") { model.Create_Date = DateTime.Parse(row["Create_Date"].ToString()); } if (row["Creater_Id"] != null && row["Creater_Id"].ToString() != "") { model.Creater_Id = int.Parse(row["Creater_Id"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(XHD.Model.ssn_art model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ssn_art("); strSql.Append("factory_Id,Art_title,Art_title_en,Art_Menu_Id,Art_Content,image_lst,Art_order,is_del,Creater_Uid,Creater_Name,Create_Date,Creater_Id)"); strSql.Append(" values ("); strSql.Append("@factory_Id,@Art_title,@Art_title_en,@Art_Menu_Id,@Art_Content,@image_lst,@Art_order,@is_del,@Creater_Uid,@Creater_Name,@Create_Date,@Creater_Id)"); strSql.Append(";select @@IDENTITY"); MySqlParameter[] parameters = { new MySqlParameter("@factory_Id", MySqlDbType.VarChar, 60), new MySqlParameter("@Art_title", MySqlDbType.VarChar, 200), new MySqlParameter("@Art_title_en", MySqlDbType.VarChar, 200), new MySqlParameter("@Art_Menu_Id", MySqlDbType.Int32, 11), new MySqlParameter("@Art_Content", MySqlDbType.Text), new MySqlParameter("@image_lst", MySqlDbType.VarChar, 400), new MySqlParameter("@Art_order", MySqlDbType.Int32, 11), new MySqlParameter("@is_del", MySqlDbType.Int16, 4), new MySqlParameter("@Creater_Uid", MySqlDbType.VarChar, 50), new MySqlParameter("@Creater_Name", MySqlDbType.VarChar, 20), new MySqlParameter("@Create_Date", MySqlDbType.DateTime), new MySqlParameter("@Creater_Id", MySqlDbType.Int32, 11) }; parameters[0].Value = model.factory_Id; parameters[1].Value = model.Art_title; parameters[2].Value = model.Art_title_en; parameters[3].Value = model.Art_Menu_Id; parameters[4].Value = model.Art_Content; parameters[5].Value = model.image_lst; parameters[6].Value = model.Art_order; parameters[7].Value = model.is_del; parameters[8].Value = model.Creater_Uid; parameters[9].Value = model.Creater_Name; parameters[10].Value = model.Create_Date; parameters[11].Value = model.Creater_Id; object obj = DbHelperMySQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public XHD.Model.ssn_art GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select Id,factory_Id,Art_title,Art_title_en,Art_Menu_Id,Art_Content,image_lst,Art_order,is_del,Creater_Uid,Creater_Name,Create_Date,Creater_Id from ssn_art "); strSql.Append(" where Id=@Id"); MySqlParameter[] parameters = { new MySqlParameter("@Id", MySqlDbType.Int32) }; parameters[0].Value = Id; XHD.Model.ssn_art model = new XHD.Model.ssn_art(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(XHD.Model.ssn_art model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update ssn_art set "); // strSql.Append("factory_Id=@factory_Id,"); strSql.Append("Art_title=@Art_title,"); strSql.Append("Art_title_en=@Art_title_en,"); //strSql.Append("Art_Menu_Id=@Art_Menu_Id,"); strSql.Append("Art_Content=@Art_Content,"); strSql.Append("image_lst=@image_lst,"); strSql.Append("Art_order=@Art_order"); //strSql.Append("is_del=@is_del,"); //strSql.Append("Creater_Uid=@Creater_Uid,"); //strSql.Append("Creater_Name=@Creater_Name,"); //strSql.Append("Create_Date=@Create_Date,"); //strSql.Append("Creater_Id=@Creater_Id"); strSql.Append(" where Id=@Id and factory_Id=@factory_Id"); MySqlParameter[] parameters = { //new MySqlParameter("@factory_Id", MySqlDbType.VarChar,60), new MySqlParameter("@Art_title", MySqlDbType.VarChar, 200), new MySqlParameter("@Art_title_en", MySqlDbType.VarChar, 200), //new MySqlParameter("@Art_Menu_Id", MySqlDbType.Int32,11), new MySqlParameter("@Art_Content", MySqlDbType.Text), new MySqlParameter("@image_lst", MySqlDbType.VarChar, 400), new MySqlParameter("@Art_order", MySqlDbType.Int32, 11), //new MySqlParameter("@is_del", MySqlDbType.Int16,4), //new MySqlParameter("@Creater_Uid", MySqlDbType.Int32,11), //new MySqlParameter("@Creater_Name", MySqlDbType.VarChar,20), //new MySqlParameter("@Create_Date", MySqlDbType.DateTime), //new MySqlParameter("@Creater_Id", MySqlDbType.Int32,11), new MySqlParameter("@Id", MySqlDbType.Int32, 11), new MySqlParameter("@factory_Id", MySqlDbType.VarChar, 60) }; //parameters[0].Value = model.factory_Id; parameters[0].Value = model.Art_title; parameters[1].Value = model.Art_title_en; //parameters[3].Value = model.Art_Menu_Id; parameters[2].Value = model.Art_Content; parameters[3].Value = model.image_lst; parameters[4].Value = model.Art_order; // parameters[7].Value = model.is_del; //parameters[8].Value = model.Creater_Uid; //parameters[9].Value = model.Creater_Name; // parameters[10].Value = model.Create_Date; // parameters[11].Value = model.Creater_Id; parameters[5].Value = model.Id; parameters[6].Value = model.factory_Id; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; HttpRequest request = context.Request; XHD.BLL.ssn_art _art = new XHD.BLL.ssn_art(); XHD.BLL.ssn_authority _authority = new XHD.BLL.ssn_authority(); XHD.BLL.ssn_art_menu _menu = new XHD.BLL.ssn_art_menu(); XHD.BLL.ssn_role _role = new XHD.BLL.ssn_role(); XHD.BLL.ssn_visit _visit = new XHD.BLL.ssn_visit(); C_Sys_log log = new C_Sys_log(); XHD.Model.ssn_art model = new XHD.Model.ssn_art(); var cookie = context.Request.Cookies[FormsAuthentication.FormsCookieName]; var ticket = FormsAuthentication.Decrypt(cookie.Value); string CoockiesID = ticket.UserData; XHD.BLL.hr_employee emp = new XHD.BLL.hr_employee(); int emp_id = int.Parse(CoockiesID); DataSet dsemp = emp.GetList("id=" + emp_id); string empname = string.Empty; string uid = string.Empty; string factory_Id = string.Empty; if (dsemp != null && dsemp.Tables[0].Rows.Count > 0) { empname = dsemp.Tables[0].Rows[0]["name"].ToString(); uid = dsemp.Tables[0].Rows[0]["uid"].ToString(); factory_Id = dsemp.Tables[0].Rows[0]["Factory_Id"].ToString(); } #region 加载数据grid if (request["Action"] == "grid") { int PageIndex = int.Parse(request["page"] == null ? "1" : request["page"]); int PageSize = int.Parse(request["pagesize"] == null ? "30" : request["pagesize"]); string Total = string.Empty; string filedOrder = " Art_order desc,Id desc "; string strWhere = " "; strWhere += " factory_id ='" + factory_Id + "' and is_del=0 "; if (!string.IsNullOrEmpty(request["Art_Menu_Id"])) { strWhere += " and Art_Menu_Id = '" + request["Art_Menu_Id"] + "'"; } DataSet ds = _art.GetList(PageSize, PageIndex, strWhere, filedOrder, out Total); string dt = XHD.Common.GetGridJSON.DataTableToJSON1(ds.Tables[0], Total); context.Response.Write(dt); } #endregion #region 加载员工的所能操作的页面 tree else if (request["Action"] == "tree") { DataSet dk = null; if (uid != "admin") { string serchtxt = " a.factory_Id = '" + factory_Id + "' and a.App_ids='1' "; serchtxt += "and r.empID='" + emp_id + "'"; DataSet ds = _authority.GetListAuth(serchtxt); if (ds != null && ds.Tables[0].Rows.Count > 0) { string menu_ids = ""; foreach (DataRow item in ds.Tables[0].Rows) { menu_ids += item["Menu_ids"].ToString(); } menu_ids = PageValidate.InputText(menu_ids, int.MaxValue).Replace("m", ""); menu_ids = menu_ids.Substring(0, menu_ids.Length - 1); dk = _menu.GetList(0, " factory_Id='" + factory_Id + "' and Id in (" + menu_ids + ")", "Menu_order"); } } else { dk = _menu.GetList(0, " factory_Id='" + factory_Id + "' and app_id=1", "Menu_order"); } StringBuilder str = new StringBuilder(); str.Append("["); str.Append(GetTreeString(0, dk.Tables[0])); str.Replace(",", "", str.Length - 1, 1); str.Append("]"); context.Response.Write(str); } #endregion #region 保存save else if (request["Action"] == "save") { model.Art_title = XHD.Common.PageValidate.InputText(request["T_title"], 250); model.Art_Content = PageValidate.InputText(request["T_content"], int.MaxValue); model.Art_Content = HttpUtility.HtmlDecode(model.Art_Content); model.Art_title_en = GetSpellCode(model.Art_title);; model.image_lst = PageValidate.InputText(request["images"], int.MaxValue); model.Art_order = int.Parse(request["T_Order"]); model.factory_Id = factory_Id; model.Art_Menu_Id = Convert.ToInt32(PageValidate.InputText(request["art_Menu_Id"], 50)); string id = PageValidate.InputText(request["nid"], 50); if (!string.IsNullOrEmpty(id) && id != "null") { DataSet ds = _art.GetList("Id=" + int.Parse(id)); DataRow dr = ds.Tables[0].Rows[0]; model.Id = int.Parse(id); if (_art.Update(model)) { #region 修改访问权限 //查询该文章原来属于哪些角色下 DataSet dm = _visit.GetList(" Factory_Id='" + factory_Id + "' and find_in_set('a" + model.Id + "', Art_id)"); if (dm != null && dm.Tables[0].Rows.Count > 0) { //此次修改的文章以前已分配过角色 string oldRoleId = string.Empty; //原来所属的角色 string newRoleId = string.Empty; for (int i = 0; i < dm.Tables[0].Rows.Count; i++) { if (i == dm.Tables[0].Rows.Count - 1) { oldRoleId += dm.Tables[0].Rows[i]["Role_id"].ToString(); } else { oldRoleId += dm.Tables[0].Rows[i]["Role_id"].ToString() + ','; } } string artId = "a" + model.Id + ","; if (!string.IsNullOrEmpty(request["role_Id"].ToString())) { newRoleId = request["role_Id"].ToString(); newRoleId = newRoleId.Substring(0, newRoleId.Length - 1); _visit.UpdateN(oldRoleId, newRoleId, artId, factory_Id, model.Art_Menu_Id.Value, emp_id); } else { _visit.UpdateN(oldRoleId, "", artId, factory_Id, model.Art_Menu_Id.Value, emp_id); } log.Add_log(emp_id, empname, request.UserHostAddress, "访问权限修改", "访问权限修改", model.Id, "访问权限修改", oldRoleId, newRoleId, factory_Id); } else { //若所修改的文章原来没有分配角色,若传进来的role_Id不为空,则进行添加 if (!string.IsNullOrEmpty(request["role_Id"].ToString())) { string roleId = request["role_Id"].ToString(); roleId = roleId.Substring(0, roleId.Length - 1); string[] listRole = roleId.Split(','); foreach (var item in listRole) { DataSet df = _visit.GetList("Role_id='" + item + "'and Menu_ids='" + model.Art_Menu_Id + "' and Factory_Id='" + factory_Id + "'"); if (df != null && df.Tables[0].Rows.Count > 0) { //修改 int rId = Convert.ToInt32(df.Tables[0].Rows[0]["id"].ToString()); string art_id = df.Tables[0].Rows[0]["Art_id"].ToString(); art_id += "a" + model.Id + ","; _visit.Updates(rId, art_id); } else { //保存 XHD.Model.ssn_visit modelVisit = new XHD.Model.ssn_visit(); modelVisit.Factory_Id = factory_Id; modelVisit.Role_id = Convert.ToInt32(item); modelVisit.App_ids = "1"; modelVisit.Menu_ids = model.Art_Menu_Id.ToString(); modelVisit.Art_id = "a" + model.Id + ","; modelVisit.Create_id = emp_id; modelVisit.Create_date = DateTime.Now; _visit.Add(modelVisit); } } } } #endregion #region 日志 int UserID = emp_id; string UserName = empname; string IPStreet = request.UserHostAddress; string EventTitle = "ssn资料修改"; string EventType = "ssn资料修改"; int EventID = model.Id; if (dr["Art_title"].ToString() != request["T_title"]) { log.Add_log(UserID, UserName, IPStreet, EventTitle, EventType, EventID, "资料名", dr["Art_title"].ToString(), request["T_title"].ToString(), factory_Id); } if (dr["Art_Content"].ToString() != request["T_content"]) { log.Add_log(UserID, UserName, IPStreet, EventTitle, EventType, EventID, "内容", dr["Art_Content"].ToString(), model.Art_Content, factory_Id); } if (dr["image_lst"].ToString() != request["images"]) { log.Add_log(UserID, UserName, IPStreet, EventTitle, EventType, EventID, "图片", dr["image_lst"].ToString(), request["images"].ToString(), factory_Id); } if (dr["Art_Menu_Id"].ToString() != request["art_Menu_Id"]) { log.Add_log(UserID, UserName, IPStreet, EventTitle, EventType, EventID, "页面Id", dr["Art_Menu_Id"].ToString(), request["art_Menu_Id"].ToString(), factory_Id); } #endregion context.Response.Write("2"); //修改成功 } else { context.Response.Write("3"); //修改失败 } } else { model.is_del = 0; model.Creater_Uid = uid; model.Creater_Name = empname; model.Create_Date = DateTime.Now; model.Creater_Id = emp_id; int artId = _art.Add(model); if (artId > 0) { #region 保存访问权限 if (!string.IsNullOrEmpty(request["role_Id"].ToString())) { string roleId = request["role_Id"].ToString(); roleId = roleId.Substring(0, roleId.Length - 1); string[] listRole = roleId.Split(','); foreach (var item in listRole) { //查询该角色是否已有分配的文章记录 DataSet df = _visit.GetList("Role_id='" + item + "'and Menu_ids='" + model.Art_Menu_Id + "' and Factory_Id='" + factory_Id + "'"); if (df != null && df.Tables[0].Rows.Count > 0) { //若已经记录,则修改 int rId = Convert.ToInt32(df.Tables[0].Rows[0]["id"].ToString()); string art_id = df.Tables[0].Rows[0]["Art_id"].ToString(); art_id += "a" + artId + ","; if (_visit.Updates(rId, art_id)) { context.Response.Write("1"); //保存成功 } else { _art.Delete(artId); context.Response.Write("0"); //保存失败 } } else { //若没有记录,则保存 XHD.Model.ssn_visit modelVisit = new XHD.Model.ssn_visit(); modelVisit.Factory_Id = factory_Id; modelVisit.Role_id = Convert.ToInt32(item); modelVisit.App_ids = "1"; modelVisit.Menu_ids = model.Art_Menu_Id.ToString(); modelVisit.Art_id = "a" + artId + ","; modelVisit.Create_id = emp_id; modelVisit.Create_date = DateTime.Now; if (_visit.Add(modelVisit)) { context.Response.Write("1"); //保存成功 } else { _art.Delete(artId); context.Response.Write("0"); //保存失败 } } } } else { context.Response.Write("1"); //保存成功 } #endregion } else { context.Response.Write("0"); //保存失败 } } } #endregion #region form else if (request["Action"] == "form") { string artId = PageValidate.InputText(request["nid"], 50); string dt; if (PageValidate.IsNumber(artId)) { DataSet ds = _art.GetList("Id=" + artId); dt = XHD.Common.DataToJson.DataToJSON(ds); } else { dt = "{}"; } context.Response.Write(dt); } #endregion #region 除del else if (request["Action"] == "del") { string artId = PageValidate.InputText(request["id"], 50); bool num = _art.Delete(Convert.ToInt32(artId)); if (num) { context.Response.Write("true"); } } #endregion #region 文章修改时获得查看权限 getRoleLiit else if (request["Action"] == "getRoleLiit") { string dt = string.Empty; string artId = PageValidate.InputText(request["nid"], 50); artId = "a" + artId; DataSet ds = _visit.GetList(" Factory_Id='" + factory_Id + "' and find_in_set('" + artId + "', Art_id)"); if (ds != null && ds.Tables[0].Rows.Count > 0) { dt = XHD.Common.GetGridJSON.DataTableToJSON1(ds.Tables[0], "Total"); } else { dt = "{'Rows':[{'id':-9999}],'Total':'Total'}"; } context.Response.Write(dt); } #endregion #region GetRole 获得所有角色 else if (request["Action"] == "GetRole") { string dt = string.Empty; DataSet ds = _role.GetList(" Factory_Id='" + factory_Id + "'"); if (ds != null && ds.Tables[0].Rows.Count > 0) { dt = XHD.Common.GetGridJSON.DataTableToJSON1(ds.Tables[0], "Total"); } else { dt = "{'Rows':[{'id':-9999}],'Total':'Total'}"; } context.Response.Write(dt); } #endregion #region 产文章图片 else if (request["Action"] == "album") { string photo = request["photo"]; //文件路径goods_gallery 商品相册表 string nowfileName1 = string.Empty; if (!string.IsNullOrEmpty(photo)) { photo = photo.Substring(photo.LastIndexOf('\\') + 1); string sExt1 = photo.Substring(photo.LastIndexOf(".")).ToLower(); DateTime now1 = DateTime.Now; nowfileName1 = XHD.Common.TimeParser.GenerateTimeStamp(DateTime.Now) + sExt1; } if (request.Files.Count > 0 && (!string.IsNullOrEmpty(photo))) { HttpPostedFile uploadFile = request.Files[0]; ////生成缩略图 //SmallImg(uploadFile.InputStream, uploadFile.FileName, context, nowfileName1); ////生成主图 //MainImg(uploadFile.InputStream, uploadFile.FileName, context, nowfileName1); uploadFile.SaveAs(context.Server.MapPath(@"~/file/ssn_artImg/" + nowfileName1)); } context.Response.Write("file/ssn_artImg/" + nowfileName1); } #endregion #region 移除图片 else if (request["Action"] == "remove") { string src = request["srcvalue"]; string file = System.Web.HttpContext.Current.Server.MapPath("../" + src); if (System.IO.File.Exists(file)) { File.Delete(file); } } #endregion #region 判断标题是否重复 else if (request["Action"] == "validate") { string title = request["T_title"]; string id = request["T_cid"]; string artMenu_Id = request["art_Menu_Id"]; if (string.IsNullOrEmpty(id) || id == "null") { id = "0"; } DataSet ds = _art.GetList("Art_title = '" + PageValidate.InputText(title, 255) + "' and Art_Menu_Id='" + artMenu_Id + "' and factory_Id='" + factory_Id + "' and Id!=" + int.Parse(id) + " and is_del=0"); if (ds.Tables[0].Rows.Count > 0) { context.Response.Write("false"); } else { context.Response.Write("true"); } } #endregion //#region 获取文章图片 //else if (request["Action"] == "formGallery") //{ // string goods_id = request["goods_id"]; // if (!string.IsNullOrEmpty(goods_id)) // { // DataSet ds = null; // if (request["type"] == "1") // ds = gallery.GetList(" goods_id='" + goods_id + "'"); // else if (request["type"] == "2") // ds = gallery.GetListCopy(" goods_id='" + goods_id + "'"); // string dt = Common.GetGridJSON.DataTableToJSON(ds.Tables[0]); // context.Response.Write(dt); // } //} //#endregion }