/// <summary> /// 删除一条数据 /// </summary> public bool Delete(int id) { //取得要删除频道记录 Model.channel_category model = GetModel(id); if (model == null) { return(false); } //取得导航的ID int nav_id = new navigation(databaseprefix).GetNavId("channel_" + model.build_path); using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { //删除导航主表 if (nav_id > 0) { DbHelperSQL.ExecuteSql(conn, trans, "delete from " + databaseprefix + "navigation where class_list like '%," + nav_id + ",%'"); } //删除频道分类表 StringBuilder strSql = new StringBuilder(); strSql.Append("delete from " + databaseprefix + "channel_category "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters); trans.Commit(); } catch { trans.Rollback(); return(false); } } } return(true); }
/// <summary> /// 添加后台管理导航 /// </summary> public bool AppendMenuNodes(string navPath, string dirPath, string xPath, int parentId) { XmlNodeList xnList = XmlHelper.ReadNodes(dirPath + MXKeys.FILE_PLUGIN_XML_CONFING, xPath); if (xnList.Count > 0) { foreach (XmlElement xe in xnList) { if (xe.NodeType != XmlNodeType.Comment && xe.Name.ToLower() == "nav") { //插入导航记录 string nav_name = string.Empty; string nav_title = string.Empty; string link_url = string.Empty; string action_type = string.Empty; if (xe.Attributes["name"] != null) { nav_name = xe.Attributes["name"].Value; } if (xe.Attributes["title"] != null) { nav_title = xe.Attributes["title"].Value; } if (xe.Attributes["url"] != null) { link_url = navPath + xe.Attributes["url"].Value; } if (xe.Attributes["action"] != null) { action_type = xe.Attributes["action"].Value; } int nav_id = new navigation(databaseprefix).Add(parentId, nav_name, nav_title, link_url, 0, 0, action_type); //写入数据库 if (nav_id < 1) { return(false); } //调用自身迭代 AppendMenuNodes(navPath, dirPath, xPath + "/nav", nav_id); } } } return(true); }
/// <summary> /// ɾ��һ������ /// </summary> public bool Delete(int id) { //ȡ��Ҫɾ��Ƶ����¼ Model.channel_category model = GetModel(id); if (model == null) { return false; } //ȡ�õ�����ID int nav_id = new navigation(databaseprefix).GetNavId("channel_" + model.build_path); using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { //ɾ���������� if (nav_id > 0) { DbHelperSQL.ExecuteSql(conn, trans, "delete from " + databaseprefix + "navigation where class_list like '%," + nav_id + ",%'"); } //ɾ��Ƶ������� StringBuilder strSql = new StringBuilder(); strSql.Append("delete from " + databaseprefix + "channel_category "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4)}; parameters[0].Value = id; DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters); trans.Commit(); } catch { trans.Rollback(); return false; } } } return true; }
/// <summary> /// 添加后台管理导航 /// </summary> public bool AppendMenuNodes(string navPath, string dirPath, string xPath, int parentId) { XmlNodeList xnList = XmlHelper.ReadNodes(dirPath + MXKeys.FILE_PLUGIN_XML_CONFING, xPath); if (xnList.Count > 0) { foreach (XmlElement xe in xnList) { if (xe.NodeType != XmlNodeType.Comment && xe.Name.ToLower() == "nav") { //插入导航记录 string nav_name = string.Empty; string nav_title = string.Empty; string link_url = string.Empty; string action_type = string.Empty; if (xe.Attributes["name"] != null) { nav_name = xe.Attributes["name"].Value; } if (xe.Attributes["title"] != null) { nav_title = xe.Attributes["title"].Value; } if (xe.Attributes["url"] != null) { link_url = navPath + xe.Attributes["url"].Value; } if (xe.Attributes["action"] != null) { action_type = xe.Attributes["action"].Value; } int nav_id = new navigation(databaseprefix).Add(parentId, nav_name, nav_title, link_url, 0, 0, action_type); //写入数据库 if (nav_id < 1) { return false; } //调用自身迭代 AppendMenuNodes(navPath, dirPath, xPath + "/nav", nav_id); } } } return true; }
/// <summary> /// 删除后台管理导航 /// </summary> public void RemoveMenuNodes(string dirPath, string xPath) { XmlNodeList xnList = XmlHelper.ReadNodes(dirPath + MXKeys.FILE_PLUGIN_XML_CONFING, xPath); if (xnList.Count > 0) { DAL.navigation dal = new navigation(databaseprefix); foreach (XmlElement xe in xnList) { if (xe.NodeType != XmlNodeType.Comment && xe.Name.ToLower() == "nav") { //删除导航记录 if (xe.Attributes["name"] != null) { int nav_id = dal.GetNavId(xe.Attributes["name"].Value); if (nav_id > 0) { dal.Delete(nav_id); } } } } } }
/// <summary> /// 删除一条数据 /// </summary> public bool Delete(int id) { //取得将要删除的记录 Model.channel model = GetModel(id); if (model == null) { return(false); } //取得导航的ID int nav_id = new navigation(databaseprefix).GetNavId("channel_" + model.name); using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { //删除导航主表 if (nav_id > 0) { DbHelperSQL.ExecuteSql(conn, trans, "delete from " + databaseprefix + "navigation where class_list like '%," + nav_id + ",%'"); } //删除视图 StringBuilder strSql1 = new StringBuilder(); strSql1.Append("if exists (select 1 from sysobjects where id = object_id('view_channel_" + model.name + "') and type = 'V')"); strSql1.Append("drop view view_channel_" + model.name); DbHelperSQL.ExecuteSql(conn, trans, strSql1.ToString()); //删除频道扩展字段表 StringBuilder strSql2 = new StringBuilder(); strSql2.Append("delete from " + databaseprefix + "channel_field "); strSql2.Append(" where channel_id=@channel_id "); SqlParameter[] parameters2 = { new SqlParameter("@channel_id", SqlDbType.Int, 4) }; parameters2[0].Value = id; DbHelperSQL.ExecuteSql(conn, trans, strSql2.ToString(), parameters2); //删除频道表 StringBuilder strSql3 = new StringBuilder(); strSql3.Append("delete from " + databaseprefix + "channel "); strSql3.Append(" where id=@id "); SqlParameter[] parameters3 = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters3[0].Value = id; DbHelperSQL.ExecuteSql(conn, trans, strSql3.ToString(), parameters3); trans.Commit(); } catch { trans.Rollback(); return(false); } } } return(true); }
/// <summary> /// ɾ��һ������ /// </summary> public bool Delete(int id) { //ȡ�ý�Ҫɾ���ļ�¼ Model.channel model = GetModel(id); if (model == null) { return false; } //ȡ�õ�����ID int nav_id = new navigation(databaseprefix).GetNavId("channel_" + model.name); using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { //ɾ���������� if (nav_id > 0) { DbHelperSQL.ExecuteSql(conn, trans, "delete from " + databaseprefix + "navigation where class_list like '%," + nav_id + ",%'"); } //ɾ����ͼ StringBuilder strSql1 = new StringBuilder(); strSql1.Append("if exists (select 1 from sysobjects where id = object_id('view_channel_" + model.name + "') and type = 'V')"); strSql1.Append("drop view view_channel_" + model.name); DbHelperSQL.ExecuteSql(conn, trans, strSql1.ToString()); //ɾ��Ƶ����չ�ֶα� StringBuilder strSql2 = new StringBuilder(); strSql2.Append("delete from " + databaseprefix + "channel_field "); strSql2.Append(" where channel_id=@channel_id "); SqlParameter[] parameters2 = { new SqlParameter("@channel_id", SqlDbType.Int,4)}; parameters2[0].Value = id; DbHelperSQL.ExecuteSql(conn, trans, strSql2.ToString(), parameters2); //ɾ��Ƶ���� StringBuilder strSql3 = new StringBuilder(); strSql3.Append("delete from " + databaseprefix + "channel "); strSql3.Append(" where id=@id "); SqlParameter[] parameters3 = { new SqlParameter("@id", SqlDbType.Int,4)}; parameters3[0].Value = id; DbHelperSQL.ExecuteSql(conn, trans, strSql3.ToString(), parameters3); trans.Commit(); } catch { trans.Rollback(); return false; } } } return true; }