1、前台代码 sys_channel_edit.aspx

<tbody id="item_box">
<asp:Repeater ID="rptList" runat="server">
<ItemTemplate>
<tr class="td_c">
<td>
<input type="hidden" name="item_type" value="<%#Eval("type")%>" />
<input type="hidden" name="item_page" value="<%#Eval("page")%>" />
<span class="item_type"><%#GetPageTypeName(Eval("type").ToString())%></span>
</td>
<td><input type="hidden" name="old_item_name" value="<%#Eval("name")%>" /><input name="item_name" type="text" value="<%#Eval("name")%>" class="txtInput small" style="width:98%;" readonly="readonly" /></td>
<td><input name="item_path" type="text" value="<%#Eval("path")%>" class="txtInput small3" style="width:98%;" readonly="readonly" /></td>
<td><input name="item_pattern" type="text" value="<%#Eval("pattern")%>" class="txtInput small3" style="width:98%;" readonly="readonly" /></td>
<td><input name="item_querystring" type="text" value="<%#Eval("querystring")%>" class="txtInput small3" style="width:98%;" readonly="readonly" /></td>
<td><input name="item_templet" type="text" value="<%#Eval("templet")%>" class="txtInput small" style="width:98%;" readonly="readonly" /></td>
<td><img alt="编辑" src="../images/icon_edit.gif" class="operator" /><img alt="删除" src="../images/icon_del.gif" class="operator" /></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>

2、后台获取rptList数据

        #region 赋值操作=================================
private void ShowInfo(int _id)
{
BLL.sys_channel bll = new BLL.sys_channel();
Model.sys_channel model = bll.GetModel(_id);
txtName.Text = model.name;
hidName.Value = model.name;
txtTitle.Text = model.title;
ddlModelId.SelectedValue = model.model_id.ToString();
txtSortId.Text = model.sort_id.ToString();
//绑定URL配置列表
rptList.DataSource = new BLL.url_rewrite().GetList(model.id.ToString());
rptList.DataBind();
}
#endregion #region 增加操作=================================
private bool DoAdd()
{
Model.sys_channel model = new Model.sys_channel();
BLL.sys_channel bll = new BLL.sys_channel();
model.name = txtName.Text.Trim();
model.title = txtTitle.Text.Trim();
model.model_id = int.Parse(ddlModelId.SelectedValue);
model.sort_id = int.Parse(txtSortId.Text.Trim());
int new_id = bll.Add(model); //保存
if (new_id < )
{
return false;
}
#region 保存URL配置.开始===================================
BLL.url_rewrite bll2 = new BLL.url_rewrite();
bll2.Remove("channel", new_id.ToString()); //先删除
string[] itemTypeArr = Request.Form.GetValues("item_type");
string[] itemNameArr = Request.Form.GetValues("item_name");
string[] itemPathArr = Request.Form.GetValues("item_path");
string[] itemPatternArr = Request.Form.GetValues("item_pattern");
string[] itemQuerystringArr = Request.Form.GetValues("item_querystring");
string[] itemTempletArr = Request.Form.GetValues("item_templet");
string[] itemPageArr = Request.Form.GetValues("item_page");
if (itemTypeArr != null && itemNameArr != null && itemPathArr != null
&& itemPatternArr != null && itemQuerystringArr != null && itemTempletArr != null && itemPageArr != null)
{
if ((itemTypeArr.Length == itemNameArr.Length) && (itemNameArr.Length == itemPathArr.Length) && (itemPathArr.Length == itemPatternArr.Length)
&& (itemPatternArr.Length == itemQuerystringArr.Length) && (itemQuerystringArr.Length == itemTempletArr.Length))
{
for (int i = ; i < itemTypeArr.Length; i++)
{
bll2.Add(new Model.url_rewrite
{
name = itemNameArr[i].Trim(),
path = itemPathArr[i].Trim(),
pattern = itemPatternArr[i].Trim(),
//page = GetPageName(model.name, itemTypeArr[i].Trim()), //源页面地址
page = itemPageArr[i].Trim(),
querystring = itemQuerystringArr[i].Trim(),
templet = itemTempletArr[i].Trim(),
channel = new_id.ToString(),
type = itemTypeArr[i].Trim(),
inherit = GetInherit(model.model_id, itemTypeArr[i].Trim()) //继承的类名
});
}
}
}
#endregion 保存URL配置.结束 return true;
}
#endregion #region 修改操作=================================
private bool DoEdit(int _id)
{
DTcms.BLL.sys_channel bll = new DTcms.BLL.sys_channel();
DTcms.Model.sys_channel model = bll.GetModel(_id);
model.name = txtName.Text.Trim();
model.title = txtTitle.Text.Trim();
model.model_id = int.Parse(ddlModelId.SelectedValue);
model.sort_id = int.Parse(txtSortId.Text.Trim());
if (!bll.Update(model))
{
return false;
} #region 保存URL配置.开始===================================
BLL.url_rewrite bll2 = new BLL.url_rewrite();
bll2.Remove("channel", model.id.ToString()); //先删除
string[] itemTypeArr = Request.Form.GetValues("item_type");
string[] itemNameArr = Request.Form.GetValues("item_name");
string[] itemPathArr = Request.Form.GetValues("item_path");
string[] itemPatternArr = Request.Form.GetValues("item_pattern");
string[] itemQuerystringArr = Request.Form.GetValues("item_querystring");
string[] itemTempletArr = Request.Form.GetValues("item_templet");
string[] itemPageArr = Request.Form.GetValues("item_page");
if (itemTypeArr != null && itemNameArr != null && itemPathArr != null
&& itemPatternArr != null && itemQuerystringArr != null && itemTempletArr != null)
{
if ((itemTypeArr.Length == itemNameArr.Length) && (itemNameArr.Length == itemPathArr.Length) && (itemPathArr.Length == itemPatternArr.Length)
&& (itemPatternArr.Length == itemQuerystringArr.Length) && (itemQuerystringArr.Length == itemTempletArr.Length))
{
for (int i = ; i < itemTypeArr.Length; i++)
{
bll2.Add(new Model.url_rewrite
{
name = itemNameArr[i].Trim(),
path = itemPathArr[i].Trim(),
pattern = itemPatternArr[i].Trim(),
//page = GetPageName(model.name, itemTypeArr[i].Trim()), //源页面地址
page = itemPageArr[i].Trim(),
querystring = itemQuerystringArr[i].Trim(),
templet = itemTempletArr[i].Trim(),
channel = model.id.ToString(),
type = itemTypeArr[i].Trim(),
inherit = GetInherit(model.model_id, itemTypeArr[i].Trim()) //继承的类名
});
}
}
}
#endregion 保存URL配置.结束 return true;
}
#endregion //保存
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (action == DTEnums.ActionEnum.Edit.ToString()) //修改
{
ChkAdminLevel("sys_channel", DTEnums.ActionEnum.Edit.ToString()); //检查权限
if (!DoEdit(this.id))
{
JscriptMsg("保存过程中发生错误啦!", "", "Error");
return;
}
JscriptMsg("修改信息成功啦!", "sys_channel_list.aspx", "Success", "parent.loadChannelTree");
}
else //添加
{
ChkAdminLevel("sys_channel", DTEnums.ActionEnum.Add.ToString()); //检查权限
if (!DoAdd())
{
JscriptMsg("保存过程中发生错误啦!", "", "Error");
return;
}
JscriptMsg("添加信息成功啦!", "sys_channel_list.aspx", "Success", "parent.loadChannelTree");
}
} }

3、取得URL配置列表,对其的一些操作

/// <summary>
/// 取得URL配制列表
/// </summary>
public List<Model.url_rewrite> GetList(string channel)
{
List<Model.url_rewrite> ls = new List<Model.url_rewrite>();
string filePath = Utils.GetXmlMapPath(DTKeys.FILE_URL_XML_CONFING);
XmlDocument doc = new XmlDocument();
doc.Load(filePath);
XmlNode xn = doc.SelectSingleNode("urls");
foreach (XmlElement xe in xn.ChildNodes)
{
if (xe.NodeType != XmlNodeType.Comment && xe.Name.ToLower() == "rewrite")
{
if (xe.Attributes["name"] != null)
{
if (!string.IsNullOrEmpty(channel))
{
if (channel.ToLower() == xe.Attributes["channel"].Value.ToLower())
{
Model.url_rewrite model = new Model.url_rewrite();
if (xe.Attributes["name"] != null)
model.name = xe.Attributes["name"].Value;
if (xe.Attributes["path"] != null)
model.path = xe.Attributes["path"].Value;
if (xe.Attributes["pattern"] != null)
model.pattern = xe.Attributes["pattern"].Value;
if (xe.Attributes["page"] != null)
model.page = xe.Attributes["page"].Value;
if (xe.Attributes["querystring"] != null)
model.querystring = xe.Attributes["querystring"].Value;
if (xe.Attributes["templet"] != null)
model.templet = xe.Attributes["templet"].Value;
if (xe.Attributes["channel"] != null)
model.channel = xe.Attributes["channel"].Value;
if (xe.Attributes["type"] != null)
model.type = xe.Attributes["type"].Value;
if (xe.Attributes["inherit"] != null)
model.inherit = xe.Attributes["inherit"].Value;
ls.Add(model);
}
}
else
{
Model.url_rewrite model = new Model.url_rewrite();
if (xe.Attributes["name"] != null)
model.name = xe.Attributes["name"].Value;
if (xe.Attributes["path"] != null)
model.path = xe.Attributes["path"].Value;
if (xe.Attributes["pattern"] != null)
model.pattern = xe.Attributes["pattern"].Value;
if (xe.Attributes["page"] != null)
model.page = xe.Attributes["page"].Value;
if (xe.Attributes["querystring"] != null)
model.querystring = xe.Attributes["querystring"].Value;
if (xe.Attributes["templet"] != null)
model.templet = xe.Attributes["templet"].Value;
if (xe.Attributes["channel"] != null)
model.channel = xe.Attributes["channel"].Value;
if (xe.Attributes["type"] != null)
model.type = xe.Attributes["type"].Value;
if (xe.Attributes["inherit"] != null)
model.inherit = xe.Attributes["inherit"].Value;
ls.Add(model);
} }
}
}
return ls;
}
#endregion /// <summary>
/// 删除节点
/// </summary>
public bool Remove(string attrName, string attrValue)
{
string filePath = Utils.GetXmlMapPath(DTKeys.FILE_URL_XML_CONFING);
XmlDocument doc = new XmlDocument();
doc.Load(filePath);
XmlNode xn = doc.SelectSingleNode("urls");
XmlNodeList xnList = xn.ChildNodes;
if (xnList.Count > )
{
for (int i = xnList.Count - ; i >= ; i--)
{
XmlElement xe = (XmlElement)xnList.Item(i);
if (xe.Attributes[attrName].Value.ToLower() == attrValue.ToLower())
{
xn.RemoveChild(xe);
}
}
doc.Save(filePath);
return true;
}
return false;
} /// <summary>
/// 修改节点
/// </summary>
public bool Edit(Model.url_rewrite model)
{
string filePath = Utils.GetXmlMapPath(DTKeys.FILE_URL_XML_CONFING);
XmlDocument doc = new XmlDocument();
doc.Load(filePath);
XmlNode xn = doc.SelectSingleNode("urls");
XmlNodeList xnList = xn.ChildNodes;
if (xnList.Count > )
{
foreach (XmlElement xe in xnList)
{
if (xe.Attributes["name"].Value.ToLower() == model.name.ToLower())
{
if (!string.IsNullOrEmpty(model.path))
xe.SetAttribute("path", model.path);
else if (xe.Attributes["path"] != null)
xe.Attributes["path"].RemoveAll();
if (!string.IsNullOrEmpty(model.pattern))
xe.SetAttribute("pattern", model.pattern);
else if (xe.Attributes["pattern"] != null)
xe.Attributes["pattern"].RemoveAll();
if (!string.IsNullOrEmpty(model.page))
xe.SetAttribute("page", model.page);
else if (xe.Attributes["page"] != null)
xe.Attributes["page"].RemoveAll();
if (!string.IsNullOrEmpty(model.querystring))
xe.SetAttribute("querystring", model.querystring);
else if (xe.Attributes["querystring"] != null)
xe.Attributes["querystring"].RemoveAll();
if (!string.IsNullOrEmpty(model.templet))
xe.SetAttribute("templet", model.templet);
else if (xe.Attributes["templet"] != null)
xe.Attributes["templet"].RemoveAll();
if (!string.IsNullOrEmpty(model.channel))
xe.SetAttribute("channel", model.channel);
else if (xe.Attributes["channel"] != null)
xe.Attributes["channel"].RemoveAll();
if (!string.IsNullOrEmpty(model.type))
xe.SetAttribute("type", model.type);
else if (xe.Attributes["type"] != null)
xe.Attributes["type"].RemoveAll();
if (!string.IsNullOrEmpty(model.inherit))
xe.SetAttribute("inherit", model.inherit);
else if (xe.Attributes["inherit"] != null)
xe.Attributes["inherit"].RemoveAll();
doc.Save(filePath);
return true;
}
}
}
return false;
} /// <summary>
/// 增加节点
/// </summary>
public bool Add(Model.url_rewrite model)
{
try
{
string filePath = Utils.GetXmlMapPath(DTKeys.FILE_URL_XML_CONFING);
XmlDocument doc = new XmlDocument();
doc.Load(filePath);
XmlNode xn = doc.SelectSingleNode("urls");
XmlElement xe = doc.CreateElement("rewrite");
if (!string.IsNullOrEmpty(model.name))
xe.SetAttribute("name", model.name);
if (!string.IsNullOrEmpty(model.path))
xe.SetAttribute("path", model.path);
if (!string.IsNullOrEmpty(model.pattern))
xe.SetAttribute("pattern", model.pattern);
if (!string.IsNullOrEmpty(model.page))
xe.SetAttribute("page", model.page);
if (!string.IsNullOrEmpty(model.querystring))
xe.SetAttribute("querystring", model.querystring);
if (!string.IsNullOrEmpty(model.templet))
xe.SetAttribute("templet", model.templet);
if (!string.IsNullOrEmpty(model.channel))
xe.SetAttribute("channel", model.channel.ToString());
if (!string.IsNullOrEmpty(model.type))
xe.SetAttribute("type", model.type);
if (!string.IsNullOrEmpty(model.inherit))
xe.SetAttribute("inherit", model.inherit);
xn.AppendChild(xe);
doc.Save(filePath);
return true;
}
catch
{
return false;
}
}

.NET开发笔记--对config文件的操作(2)的更多相关文章

  1. .NET开发笔记--对config文件的操作(1)

    1先写一些常用的公共类: 在Web.config文件中的配置: <!-- appSettings网站信息配置--> <appSettings> <add key=&quo ...

  2. .NET开发笔记--对config文件的操作(3)

    1.添加新节点前进行判断看是否已存在相同的属性值,若存在进行更新,不存在则进行添加操作. protected bool AddPizza() { //初始化id int newId; string f ...

  3. Python入门笔记(16):对文件的操作(2)

    一.文件系统 从系统角度来看,文件系统是对文件存储器空间进行组织和分配,负责文件存储并对存入的文件进行保护和检索的系统.具体地说,它负责为用户建立文件,存入.读出.修改.转储文件,控制文件的存取,当用 ...

  4. loadrunner 脚本开发-调用java jar文件远程操作Oracle数据库测试

    调用java jar文件远程操作Oracle数据库测试 by:授客 QQ:1033553122 测试环境 数据库:linux 下Oracle_11g_R2 Loadrunner:11 备注:想学ora ...

  5. Beego 学习笔记12:文件的操作

    文件的操作 1>     此事例操作的是text文件 2>     文件的操作有读取text内容,将内容写入到文件中,删除文件,创建文件 3>     新建一个控制器,名为rwfil ...

  6. 《UNIX-Shell编程24学时教程》读书笔记Chap3,4 文件,目录操作

    Chap3 文件操作   P28 在这章中,要着重记住一些常用的选项,要有使用正则表达式的思维,能更快达到目的.----@im天行 3.1 列文件名 .profile  sh的初始化脚本: .kshr ...

  7. Python入门笔记(15):对文件的操作(1)

    一.文件对象 我理解的文件对象就是一个接口,通过这个接口对文件进行相关操作. <Python 核心编程>上说的很晦涩,这里没有深刻理解到,希望有人能解释给我听. >>> ...

  8. Appcan开发笔记:导出Excel文件

    Appcan IDE为4.0+; appcan提供了导出文件的方法 appcan.file.write 文件会自动创建,要解决的事情是Excel用字符串输出,可以考虑 csv(逗号间隔).HTML.X ...

  9. [开发笔记]-C#判断文件类型

    判断文件真实的类型,不是通过扩展名来判断: /// <summary> /// 判断文件格式 /// http://www.cnblogs.com/babycool /// </su ...

随机推荐

  1. [转]mysql 常用命令集锦[绝对精华]

    测试环境:mysql 5.0.45 [注:可以在mysql中通过mysql> SELECT VERSION();来查看数据库版本] 一.连接MYSQL. 格式: mysql -h主机地址 -u用 ...

  2. java中的super限定

    super的用法: (1)如果需要在子类中调用父类中被覆盖的实例方法,可以用super限定来调用父类中被覆盖的方法.当然,也可以调用从父类继承的实例变量. public void callOverri ...

  3. LoadRunner参数化时的各个选项说明

    LoadRunner参数化时的各个选项说明 分类: LoadRunner 2009-03-27 09:32 6294人阅读 评论(1) 收藏 举报 loadrunnerrandomgeneratore ...

  4. 数字图像和视频处理的基础-第4周运动预计matlab练习题

    In this problem you will perform block matching motion estimation between two consecutive video fram ...

  5. 【微信小程序】微信小程序wx.previewImage预览图片

    一.小知识 二.例子,配合轮播图使用效果更佳!(如图1) 1.wxml <scroll-view scroll-y="true"> <swiper catchta ...

  6. VSCode集成Git代码管理

    一.安装和配置VSCode与Git 1.下载Git并安装: https://git-scm.com/download/ 2.下载VSCode并进行安装: https://code.visualstud ...

  7. Android studio使用心得(二)— 打包签名apk发布

    1.—–Android Studio菜单   Build->Generate Signed APK 2.——Create new.. 3.——-跟eclipse里面一样,添加keystore 信 ...

  8. HDFS原理解析(整体架构,读写操作流程及源代码查看等)

    前言 HDFS 是一个能够面向大规模数据使用的.可进行扩展的文件存储与传递系统.是一种同意文件通过网络在多台主机上分享的文件系统,可让多机器上的多用户分享文件和存储空间.让实际上是通过网络来訪问文件的 ...

  9. Spring MVC 框架搭建及具体解释

    如今主流的Web MVC框架除了Struts这个主力 外.其次就是Spring MVC了,因此这也是作为一名程序猿需要掌握的主流框架.框架选择多了.应对多变的需求和业务时,可实行的方案自然就多了. 只 ...

  10. python-简单函数小例子 单位转换

    第一种方法def fahrenheit_converter(g): fahrenheit = g /1000 return str(fahrenheit) + 'kg' #调用函数g2kg = fah ...