private void sys_channel_load(HttpContext context) { StringBuilder strTxt = new StringBuilder(); BLL.sys_channel bll = new BLL.sys_channel(); DataTable dt = bll.GetList("").Tables[0]; strTxt.Append("["); int i = 1; foreach (DataRow dr in dt.Rows) { Model.manager admin_info = new ManagePage().GetAdminInfo(); if (!new BLL.manager_role().Exists(admin_info.role_id, Convert.ToInt32(dr["id"]), DTEnums.ActionEnum.View.ToString())) { continue; } BLL.sys_model bll2 = new BLL.sys_model(); Model.sys_model model2 = bll2.GetModel(Convert.ToInt32(dr["model_id"])); strTxt.Append("{"); strTxt.Append("\"text\":\"" + dr["title"] + "\","); strTxt.Append("\"isexpand\":\"false\","); strTxt.Append("\"children\":["); if (model2.sys_model_navs != null) { int j = 1; foreach (Model.sys_model_nav nav in model2.sys_model_navs) { strTxt.Append("{"); strTxt.Append("\"text\":\"" + nav.title + "\","); strTxt.Append("\"url\":\"" + nav.nav_url + "?channel_id=" + dr["id"] + "\""); //此处要优化,加上nav.nav_url网站目录标签替换 strTxt.Append("}"); if (j < model2.sys_model_navs.Count) { strTxt.Append(","); } j++; } } strTxt.Append("]"); strTxt.Append("}"); strTxt.Append(","); i++; } string newTxt = Utils.DelLastChar(strTxt.ToString(), ",") + "]"; context.Response.Write(newTxt); return; }
private void AdminUploadHandler(HttpContext context, string name) { //检查用户是否登录 DTcms.Model.manager modelAdmin = new DTcms.Web.UI.ManagePage().GetAdminInfo(); if (modelAdmin == null) { JsonHelper.WriteJson(context, new { state = DTEnums.ResultState.NetworkError, error = "对不起,用户尚未登录或已超时!" }); return; } string fieldName = "upfile"; string[] allowExtensions = null; int sizeLimit = 0; switch (name) { case "image": sizeLimit = siteConfig.imgsize; allowExtensions = siteConfig.fileextension.Split(','); //siteConfig.imgextension.Split(','); break; case "scrawl": sizeLimit = 2048000; allowExtensions = new string[] { ".png" }; break; case "video": sizeLimit = siteConfig.videosize; allowExtensions = siteConfig.videoextension.Split(','); break; case "file": sizeLimit = siteConfig.attachsize; allowExtensions = siteConfig.fileextension.Split(','); break; default: JsonHelper.WriteJson(context, new { status = "参数传输错误!" }); return; } if (sizeLimit <= 0 || allowExtensions.Length == 0) { JsonHelper.WriteJson(context, new { status = "参数传输错误!" }); return; } if (name == "scrawl") { string uploadFileName = Utils.GetRamCode() + ".png"; byte[] uploadFileBytes = Convert.FromBase64String(context.Request[fieldName]); string Url = new UpLoad().GetUpLoadPath() + uploadFileName; string localPath = Utils.GetMapPath(Url); string ErrorMessage = string.Empty; DTEnums.ResultState State = DTEnums.ResultState.Success; try { if (!Directory.Exists(Path.GetDirectoryName(localPath))) { Directory.CreateDirectory(Path.GetDirectoryName(localPath)); } File.WriteAllBytes(localPath, uploadFileBytes); State = DTEnums.ResultState.Success; } catch (Exception e) { State = DTEnums.ResultState.FileAccessError; ErrorMessage = e.Message; } JsonHelper.WriteJson(context, new { state = Utils.GetStateString(State), url = Url, title = uploadFileName, original = uploadFileName, error = ErrorMessage }); } else { context.Response.ContentType = "text/plain"; HttpPostedFile _upfile = context.Request.Files[fieldName]; Model.upLoad model = new UpLoad().fileSaveAs(_upfile, allowExtensions, sizeLimit, false, false, 0, 0); if (model.status > 0) { //{"state":"SUCCESS","url":"/upload/201612/22/201612221435403316.jpg","title":"未命名-1.jpg","original":"未命名-1.jpg","error":""} JsonHelper.WriteJson(context, new { state = Utils.GetStateString(DTEnums.ResultState.Success), url = model.path, title = model.name, original = model.name, error = "" }); } else if (model.status == -1) { JsonHelper.WriteJson(context, new { state = DTEnums.ResultState.SizeLimitExceed, error = Utils.GetStateString(DTEnums.ResultState.SizeLimitExceed) }); } else if (model.status == -2) { JsonHelper.WriteJson(context, new { state = DTEnums.ResultState.TypeNotAllow, error = Utils.GetStateString(DTEnums.ResultState.TypeNotAllow) }); } else if (model.status == -3) { JsonHelper.WriteJson(context, new { state = DTEnums.ResultState.NetworkError, error = Utils.GetStateString(DTEnums.ResultState.NetworkError) }); } } }
private void get_navigation_list(HttpContext context) { Model.manager adminModel = new ManagePage().GetAdminInfo(); //获得当前登录管理员信息 if (adminModel == null) { return; } Model.manager_role roleModel = new BLL.manager_role().GetModel(adminModel.role_id); //获得管理角色信息 if (roleModel == null) { return; } DataTable dt = new BLL.navigation().GetDataList(0, DTEnums.NavigationEnum.System.ToString()); this.get_navigation_childs(context, dt, 0, "", roleModel.role_type, roleModel.manager_role_values); }