private bool DoAdd() { Model.channel_category model = new Model.channel_category(); BLL.channel_category bll = new BLL.channel_category(); model.title = txtTitle.Text.Trim(); model.build_path = txtBuildPath.Text.Trim(); model.domain = txtDomain.Text.Trim(); model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99); if (cbIsDefault.Checked == true) { model.is_default = 1; } else { model.is_default = 0; } if (bll.Add(model) > 0) { //更新一下域名缓存 CacheHelper.Remove(DTKeys.CACHE_SITE_HTTP_DOMAIN); AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加频道分类:" + model.title); //记录日志 return true; } return false; }
private void ShowInfo(int _id) { BLL.channel_category bll = new BLL.channel_category(); Model.channel_category model = bll.GetModel(_id); txtTitle.Text = model.title; txtBuildPath.Text = model.build_path; txtBuildPath.Attributes.Add("ajaxurl", "../../tools/admin_ajax.ashx?action=channel_category_validate&old_build_path=" + Utils.UrlEncode(model.build_path)); txtBuildPath.Focus(); //设置焦点,防止JS无法提交 txtDomain.Text = model.domain; txtSortId.Text = model.sort_id.ToString(); if (model.is_default == 1) { cbIsDefault.Checked = true; } else { cbIsDefault.Checked = false; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.channel_category model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update " + databaseprefix + "channel_category set "); strSql.Append("title=@title,"); strSql.Append("build_path=@build_path,"); strSql.Append("templet_path=@templet_path,"); strSql.Append("domain=@domain,"); strSql.Append("is_default=@is_default,"); strSql.Append("sort_id=@sort_id"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@build_path", SqlDbType.NVarChar, 100), new SqlParameter("@templet_path", SqlDbType.NVarChar, 100), new SqlParameter("@domain", SqlDbType.NVarChar, 255), new SqlParameter("@is_default", SqlDbType.TinyInt, 1), new SqlParameter("@sort_id", SqlDbType.Int, 4) }; parameters[0].Value = model.id; parameters[1].Value = model.title; parameters[2].Value = model.build_path; parameters[3].Value = model.templet_path; parameters[4].Value = model.domain; parameters[5].Value = model.is_default; parameters[6].Value = model.sort_id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void CreateIndexHtml(string lang, string aspx_filename, string catalogue) { if (File.Exists(Utils.GetMapPath(config.webpath + aspx_filename.Substring(0, aspx_filename.IndexOf(".aspx") + 5)))) { string urlPath = config.webpath + aspx_filename.Replace("^", "&"); //文件相对路径 string htmlPath = config.webpath + catalogue; //保存相对路径 if (htmlPath.IndexOf(".") < 0) { htmlPath = htmlPath + "index." + config.staticextension; } //检查目录是否存在 string directorystr = HttpContext.Current.Server.MapPath(htmlPath.Substring(0, htmlPath.LastIndexOf("/"))); if (!Directory.Exists(directorystr)) { Directory.CreateDirectory(directorystr); } string linkwebsite = HttpContext.Current.Request.Url.Authority; Model.channel_category modelchannelcategory = objchannel_category.GetModel(lang); if (modelchannelcategory != null && !string.IsNullOrEmpty(modelchannelcategory.domain)) { linkwebsite = modelchannelcategory.domain; } System.Net.WebRequest request = System.Net.WebRequest.Create("http://" + linkwebsite + urlPath); System.Net.WebResponse response = request.GetResponse(); System.IO.Stream stream = response.GetResponseStream(); System.IO.StreamReader streamreader = new System.IO.StreamReader(stream, System.Text.Encoding.GetEncoding("utf-8")); string content = streamreader.ReadToEnd(); using (StreamWriter sw = new StreamWriter(Utils.GetMapPath(htmlPath), false, Encoding.UTF8)) { sw.WriteLine(content); sw.Flush(); sw.Close(); } } else { HttpContext.Current.Response.Write("1");//找不到生成的模版! } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.channel_category GetModel(string build_path) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,title,build_path,templet_path,domain,is_default,sort_id from " + databaseprefix + "channel_category "); strSql.Append(" where build_path=@build_path"); SqlParameter[] parameters = { new SqlParameter("@build_path", SqlDbType.NVarChar, 50) }; parameters[0].Value = build_path; Model.channel_category model = new Model.channel_category(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } model.title = ds.Tables[0].Rows[0]["title"].ToString(); model.build_path = ds.Tables[0].Rows[0]["build_path"].ToString(); model.templet_path = ds.Tables[0].Rows[0]["templet_path"].ToString(); model.domain = ds.Tables[0].Rows[0]["domain"].ToString(); if (ds.Tables[0].Rows[0]["is_default"].ToString() != "") { model.is_default = int.Parse(ds.Tables[0].Rows[0]["is_default"].ToString()); } if (ds.Tables[0].Rows[0]["sort_id"].ToString() != "") { model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString()); } return(model); } else { return(null); } }
//批量删除 protected void btnDelete_Click(object sender, EventArgs e) { ChkAdminLevel("site_channel_category", AXEnums.ActionEnum.Delete.ToString()); //检查权限 int sucCount = 0; int errorCount = 0; BLL.channel_category bll = new BLL.channel_category(); for (int i = 0; i < rptList.Items.Count; i++) { int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value); CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId"); if (cb.Checked) { //检查该分类下是否还有频道 int channelCount = new BLL.channel().GetCount("category_id=" + id); if (channelCount > 0) { errorCount += 1; continue; } Model.channel_category model = bll.GetModel(id); //删除成功后对应的目录及文件 if (bll.Delete(id)) { sucCount += 1; Utils.DeleteDirectory(siteConfig.webpath + AXKeys.DIRECTORY_REWRITE_ASPX + "/" + model.build_path); Utils.DeleteDirectory(siteConfig.webpath + AXKeys.DIRECTORY_REWRITE_HTML + "/" + model.build_path); } else { errorCount += 1; } } } AddAdminLog(AXEnums.ActionEnum.Delete.ToString(), "删除频道分类成功" + sucCount + "条,失败" + errorCount + "条"); //记录日志 JscriptMsg("删除成功" + sucCount + "条,失败" + errorCount + "条!", Utils.CombUrlTxt("category_list.aspx", "keywords={0}", this.keywords), "Success", "parent.loadMenuTree"); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.channel_category model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + databaseprefix + "channel_category("); strSql.Append("title,build_path,templet_path,domain,is_default,sort_id)"); strSql.Append(" values ("); strSql.Append("@title,@build_path,@templet_path,@domain,@is_default,@sort_id)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@build_path", SqlDbType.NVarChar, 100), new SqlParameter("@templet_path", SqlDbType.NVarChar, 100), new SqlParameter("@domain", SqlDbType.NVarChar, 255), new SqlParameter("@is_default", SqlDbType.TinyInt, 1), new SqlParameter("@sort_id", SqlDbType.Int, 4) }; parameters[0].Value = model.title; parameters[1].Value = model.build_path; parameters[2].Value = model.templet_path; parameters[3].Value = model.domain; parameters[4].Value = model.is_default; parameters[5].Value = model.sort_id; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.channel_category GetModel(string build_path) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,title,build_path,templet_path,domain,is_default,sort_id from " + databaseprefix + "channel_category "); strSql.Append(" where build_path=@build_path"); SqlParameter[] parameters = { new SqlParameter("@build_path", SqlDbType.NVarChar,50)}; parameters[0].Value = build_path; Model.channel_category model = new Model.channel_category(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } model.title = ds.Tables[0].Rows[0]["title"].ToString(); model.build_path = ds.Tables[0].Rows[0]["build_path"].ToString(); model.templet_path = ds.Tables[0].Rows[0]["templet_path"].ToString(); model.domain = ds.Tables[0].Rows[0]["domain"].ToString(); if (ds.Tables[0].Rows[0]["is_default"].ToString() != "") { model.is_default = int.Parse(ds.Tables[0].Rows[0]["is_default"].ToString()); } if (ds.Tables[0].Rows[0]["sort_id"].ToString() != "") { model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString()); } return model; } else { return null; } }