protected void Page_Load(object sender, EventArgs e) { iframeid = IRequest.GetQueryString("iframeid"); int CateId = IRequest.GetQueryInt("cateid", 0); int Id = IRequest.GetQueryInt("id", -1); string cateName = IRequest.GetQueryString("catename"); if (CateId > 0) { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Cate cate = new SqlDb.Dcms_Cate(); cate.Cate_Id = CateId; IQuery query = session.GetQuery(cate).Where(SqlDb.Dcms_Cate._CATE_ID_.EqulesExp()); List<SqlDb.Dcms_Cate> cateList = query.GetList<SqlDb.Dcms_Cate>(); if (cateList.Count > 0) { cateName = cateList[0].Cate_Title; News_CateName.Value = cateName; News_CateId.Value = CateId.ToString(); News_CateName.Value = cateName; } } } if (Id == 0) { this.Page.Title = "新建" + cateName; this.lit_Title.Text = "新建" + cateName; News_Id.Value = "0"; } else if (Id > 0) { this.Page.Title = "编辑" + cateName; this.lit_Title.Text = "编辑" + cateName; lit_id.Text = Id.ToString(); News_Id.Value = Id.ToString(); } else { int thisId = 0; using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_News news = new SqlDb.Dcms_News(); news.News_CateId = CateId; IQuery query = session.GetQuery(news).Where(SqlDb.Dcms_News._NEWS_CATEID_.EqulesExp()); IList<SqlDb.Dcms_News> newslist = query.GetList<SqlDb.Dcms_News>(); if (newslist.Count > 0) { thisId = newslist[0].News_Id; } } this.Page.Title = "编辑" + cateName; this.lit_Title.Text = "编辑" + cateName; lit_id.Text = thisId.ToString(); News_Id.Value = thisId.ToString(); } }
protected void Page_Load(object sender, EventArgs e) { iframeid = IRequest.GetQueryString("iframeid"); int CateId = IRequest.GetQueryInt("cateid", 0); int Id = IRequest.GetQueryInt("id", -1); string cateName = IRequest.GetQueryString("catename"); if (CateId > 0) { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Cate cate = new SqlDb.Dcms_Cate(); cate.Cate_Id = CateId; IQuery query = session.GetQuery(cate).Where(SqlDb.Dcms_Cate._CATE_ID_.EqulesExp()); List <SqlDb.Dcms_Cate> cateList = query.GetList <SqlDb.Dcms_Cate>(); if (cateList.Count > 0) { cateName = cateList[0].Cate_Title; GuestBook_CateName.Value = cateName; GuestBook_CateId.Value = CateId.ToString(); GuestBook_CateName.Value = cateName; } } } if (Id == 0) { this.Page.Title = "新建" + cateName; this.lit_Title.Text = "新建" + cateName; GuestBook_Id.Value = "0"; } else if (Id > 0) { this.Page.Title = "编辑" + cateName; this.lit_Title.Text = "编辑" + cateName; lit_id.Text = Id.ToString(); GuestBook_Id.Value = Id.ToString(); } else { int thisId = 0; using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_GuestBook modle = new SqlDb.Dcms_GuestBook(); modle.GuestBook_CateId = CateId; IQuery query = session.GetQuery(modle).Where(SqlDb.Dcms_GuestBook._GUESTBOOK_CATEID_.EqulesExp()); IList <SqlDb.Dcms_GuestBook> datalist = query.GetList <SqlDb.Dcms_GuestBook>(); if (datalist.Count > 0) { thisId = datalist[0].GuestBook_Id; } } this.Page.Title = "编辑" + cateName; this.lit_Title.Text = "编辑" + cateName; lit_id.Text = thisId.ToString(); GuestBook_Id.Value = thisId.ToString(); } }
/// <summary> /// 插入一条数据 /// </summary> /// <returns>"true"/"false"</returns> private string doInsert() { try { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Cate cate = new SqlDb.Dcms_Cate(); cate.Cate_AddTime = DateTime.Now; UpdateModelByForm(cate, Request.Form); int parentId = IRequest.GetFormInt("Cate_ParentID", 0); if (parentId > 0) { SqlDb.Dcms_Cate pCate = new SqlDb.Dcms_Cate(); IQuery query = session.GetQuery(pCate).Where(SqlDb.Dcms_Cate._CATE_ID_.EqulesExp(parentId)); List <SqlDb.Dcms_Cate> cateList = query.GetList <SqlDb.Dcms_Cate>(); if (cateList.Count > 0) { cate.Cate_IdPath = cateList[0].Cate_IdPath + parentId.ToString() + ","; //更新是否含有子类 if (cateList[0].Cate_HasChild == 0) { session.simple("update [Dcms_Cate] set [Cate_HasChild]=1 where [Cate_Id]=" + parentId.ToString()); } } } else { cate.Cate_IdPath = ",0,"; } cate.Cate_Lang = Convert.ToString(Utils.GetCookie("LangFlag")); if (cate.Cate_Lang.Length < 1) { return("false"); } else { cate.Cate_Guid = Guid.NewGuid().ToString("N"); //提交插入 session.Create(cate); } } return("true"); } catch { return("false"); } }
/// <summary> /// 批量删除操作 /// </summary> /// <returns></returns> private string doDelete() { try { int id = IRequest.GetQueryInt("id", 0); if (id > 0) { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Cate Cate = new SqlDb.Dcms_Cate(); IQuery query = session.GetQuery(Cate).Where(SqlDb.Dcms_Cate._CATE_ID_.EqulesExp(id)); List <SqlDb.Dcms_Cate> cateList = query.GetList <SqlDb.Dcms_Cate>(); if (cateList.Count > 0) { if (cateList[0].Cate_ParentID == 0 && adminInfo.Admin_Id != 1) { return("no"); } string Sql = "DELETE FROM [Dcms_Cate] WHERE [Cate_Id] =" + id.ToString() + ""; session.simple(Sql); //同时删除子一级 if (cateList[0].Cate_HasChild > 0) { //string Sql2 = "DELETE FROM [Dcms_Cate] WHERE [Cate_ParentID] =" + id.ToString() + ""; string Sql2 = "Delete From [Dcms_Cate] where Cate_IdPath like '%," + id.ToString() + ",%'"; session.simple(Sql2); } //更新父级的部分数据 int pId = cateList[0].Cate_ParentID; string pSql = "select [Cate_Id] from [Dcms_Cate] where [Cate_ParentID]=" + pId.ToString(); DataTable dt = session.GetTable(pSql); if (dt.Rows.Count <= 0) { session.simple("update [Dcms_Cate] set [Cate_HasChild]=0 where [Cate_Id]=" + pId.ToString()); } } } } return("true"); } catch { return("false"); } }
protected void Page_Load(object sender, EventArgs e) { int CateId = IRequest.GetQueryInt("CateId", 0); if (CateId > 0) { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Cate cate = new SqlDb.Dcms_Cate(); cate.Cate_Id = CateId; IQuery query = session.GetQuery(cate).Where(SqlDb.Dcms_Cate._CATE_ID_.EqulesExp()); List<SqlDb.Dcms_Cate> cateList = query.GetList<SqlDb.Dcms_Cate>(); if (cateList.Count > 0) { string cateName = cateList[0].Cate_Title; this.Page.Title = cateName; this.lit_Title.Text = cateName; Cate_Id.Value = CateId.ToString(); Cate_Name.Value = cateName; } } } }
protected void Page_Load(object sender, EventArgs e) { int CateId = IRequest.GetQueryInt("CateId", 0); if (CateId > 0) { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Cate cate = new SqlDb.Dcms_Cate(); cate.Cate_Id = CateId; IQuery query = session.GetQuery(cate).Where(SqlDb.Dcms_Cate._CATE_ID_.EqulesExp()); List <SqlDb.Dcms_Cate> cateList = query.GetList <SqlDb.Dcms_Cate>(); if (cateList.Count > 0) { string cateName = cateList[0].Cate_Title; this.Page.Title = cateName; this.lit_Title.Text = cateName; Cate_Id.Value = CateId.ToString(); Cate_Name.Value = cateName; } } } }
/// 转移数据 /// </summary> /// <returns></returns> private string shift() { string shiftway=IRequest.GetFormString("ShiftWay"); string catelangfrom = IRequest.GetFormString("CateLangFrom"); string catelangto = IRequest.GetFormString("CateLangTo"); int catefrom =IRequest.GetFormInt("CateFrom", 0); int cateto = IRequest.GetFormInt("CateTo",0); string shifttype = IRequest.GetFormString("ShiftType"); string isdelete = IRequest.GetFormString("IsDelete"); string catelang = IRequest.GetFormString("catelang"); string catetoname=IRequest.GetFormString("CateToName"); using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { try { if (shiftway == "0")//版本转移 { session.BeginTrans(); string Sql = "select * from [Dcms_Cate] where Cate_Lang='" + catelangfrom + "' order by [Cate_Id] asc"; DataTable cateFromDt = session.GetTable(Sql); if (cateFromDt.Rows.Count > 0) { SqlDb.Dcms_Cate cate = new SqlDb.Dcms_Cate(); Dictionary<int, int> dic = new Dictionary<int, int>(); session.Create(cate);//先插入一条获取max cateid int maxcateid = session.ExecuteCount("select Max(Cate_Id) from [Dcms_Cate]", cate); session.simple("delete from [Dcms_Cate] where Cate_Id='" + maxcateid.ToString() + "'"); foreach (DataRow dr in cateFromDt.Rows) { if (shifttype.Equals("All"))//如果是转移栏目和内容 { UpdateModelByDt(cate, dr); if (session.ExecuteCount("select Max(Cate_Id) from [Dcms_Cate]", cate) < maxcateid) { dic.Add(Convert.ToInt32(dr["Cate_Id"].ToString()), maxcateid + 1); } else { dic.Add(Convert.ToInt32(dr["Cate_Id"].ToString()), session.ExecuteCount("select Max(Cate_Id) from [Dcms_Cate]", cate) + 1); } cate.Cate_Lang = catelangto; cate.Cate_IdPath = ",0,"; foreach (KeyValuePair<int, int> kv in dic) { foreach (string key in dr["Cate_IdPath"].ToString().Split(new char[] { ',' })) { if (kv.Key.ToString().Equals(key)) { cate.Cate_IdPath = cate.Cate_IdPath + kv.Value.ToString() + ","; } } if (int.Parse(dr["Cate_ParentID"].ToString()) == kv.Key) { cate.Cate_ParentID = kv.Value; } } session.Create(cate);//插入栏目 string csql = "select * from [dcms_" + dr["Cate_Module"].ToString() + "] where " + dr["Cate_Module"].ToString() + "_cateid=" + dr["Cate_Id"].ToString() + " order by [" + dr["Cate_Module"].ToString() + "_id] asc"; DataTable contentFromDt = session.GetTable(csql); if (contentFromDt.Rows.Count > 0) { Dictionary<int, int> cdic = new Dictionary<int, int>(); session.simple("insert into [dcms_" + dr["Cate_Module"].ToString() + "] (" + dr["Cate_Module"].ToString() + "_cateid) values(0)"); int maxcid = Convert.ToInt32(session.ExecuteScalar("select Max(" + dr["Cate_Module"].ToString() + "_id) from [dcms_" + dr["Cate_Module"].ToString() + "]")); session.simple("delete from [Dcms_" + dr["Cate_Module"].ToString() + "] where " + dr["Cate_Module"].ToString() + "_Id='" + maxcid.ToString() + "'"); foreach (DataRow cdr in contentFromDt.Rows) { if (Convert.ToInt32(session.ExecuteScalar("select Max(" + dr["Cate_Module"].ToString() + "_id) from [dcms_" + dr["Cate_Module"].ToString() + "]")) < maxcid) { cdic.Add(Convert.ToInt32(cdr[dr["Cate_Module"].ToString() + "_id"].ToString()), maxcid + 1); } else { cdic.Add(Convert.ToInt32(cdr[dr["Cate_Module"].ToString() + "_id"].ToString()), Convert.ToInt32(session.ExecuteScalar("select Max(" + dr["Cate_Module"].ToString() + "_id) from [dcms_" + dr["Cate_Module"].ToString() + "]")) + 1); } string columns = ""; for (int i = 1; i < contentFromDt.Columns.Count; i++) { columns += contentFromDt.Columns[i].ColumnName + ","; } columns = columns.Substring(0, columns.LastIndexOf(',')); session.simple("insert into [dcms_" + dr["Cate_Module"].ToString() + "] (" + columns + ") select " + columns + " from [dcms_" + dr["Cate_Module"].ToString() + "] where " + dr["Cate_Module"].ToString() + "_id=" + cdr[dr["Cate_Module"].ToString() + "_id"].ToString()); session.simple("update [dcms_" + dr["Cate_Module"].ToString() + "] set " + dr["Cate_Module"].ToString() + "_cateid=" + dic[Convert.ToInt32(dr["Cate_Id"].ToString())].ToString() + " where " + dr["Cate_Module"].ToString() + "_id=" + cdic[Convert.ToInt32(cdr[dr["Cate_Module"].ToString() + "_id"].ToString())].ToString()); } } } if (shifttype.Equals("Channel"))//如果是只转移栏目 { UpdateModelByDt(cate, dr); if (session.ExecuteCount("select Max(Cate_Id) from [Dcms_Cate]", cate) < maxcateid) { dic.Add(Convert.ToInt32(dr["Cate_Id"].ToString()), maxcateid + 1); } else { dic.Add(Convert.ToInt32(dr["Cate_Id"].ToString()), session.ExecuteCount("select Max(Cate_Id) from [Dcms_Cate]", cate) + 1); } cate.Cate_Lang = catelangto; cate.Cate_IdPath = ",0,"; foreach (KeyValuePair<int, int> kv in dic) { foreach (string key in dr["Cate_IdPath"].ToString().Split(new char[] { ',' })) { if (kv.Key.ToString().Equals(key)) { cate.Cate_IdPath = cate.Cate_IdPath + kv.Value.ToString() + ","; } } if (int.Parse(dr["Cate_ParentID"].ToString()) == kv.Key) { cate.Cate_ParentID = kv.Value; } } session.Create(cate);//插入栏目 } } } } if (shiftway == "1")//栏目转移下只转移内容 { session.BeginTrans(); string Sql = "select * from [Dcms_Cate] where Cate_Id='" + catefrom + "' order by [Cate_Id] asc"; DataTable cateFromDt = session.GetTable(Sql); string moduleStr = cateFromDt.Rows[0]["Cate_Module"].ToString(); string csql = "select * from [dcms_" + moduleStr + "] where " + moduleStr + "_cateid=" + cateFromDt.Rows[0]["Cate_Id"].ToString() + " order by [" + moduleStr + "_id] asc"; DataTable contentFromDt = session.GetTable(csql); if (contentFromDt.Rows.Count > 0) { Dictionary<int, int> cdic = new Dictionary<int, int>(); session.simple("insert into [dcms_" + moduleStr + "] (" + moduleStr + "_cateid) values(0)"); int maxcid = Convert.ToInt32(session.ExecuteScalar("select Max(" + moduleStr + "_id) from [dcms_" + moduleStr + "]")); session.simple("delete from [Dcms_" + moduleStr + "] where " + moduleStr + "_Id='" + maxcid.ToString() + "'"); foreach (DataRow cdr in contentFromDt.Rows) { if (Convert.ToInt32(session.ExecuteScalar("select Max(" + moduleStr + "_id) from [dcms_" + moduleStr + "]")) < maxcid) { cdic.Add(Convert.ToInt32(cdr[moduleStr + "_id"].ToString()), maxcid + 1); } else { cdic.Add(Convert.ToInt32(cdr[moduleStr + "_id"].ToString()), Convert.ToInt32(session.ExecuteScalar("select Max(" + moduleStr + "_id) from [dcms_" + moduleStr + "]")) + 1); } string columns = ""; for (int i = 1; i < contentFromDt.Columns.Count; i++) { columns += contentFromDt.Columns[i].ColumnName + ","; } columns = columns.Substring(0, columns.LastIndexOf(',')); session.simple("insert into [dcms_" + moduleStr + "] (" + columns + ") select " + columns + " from [dcms_" + moduleStr + "] where " + moduleStr + "_id=" + cdr[moduleStr + "_id"].ToString()); string upstr = "update [dcms_" + moduleStr + "] set " + moduleStr + "_CateName=" + "'" + catetoname + "'" + "," + moduleStr + "_cateid=" + cateto + " where " + moduleStr + "_id=" + cdic[Convert.ToInt32(cdr[moduleStr + "_id"].ToString())].ToString(); session.simple(upstr); // session.simple("update [dcms_" + moduleStr + "] set " +moduleStr+"_CateName=" + catetoname + "," + moduleStr + "_cateid=" + cateto + " where " + moduleStr + "_id=" + cdic[Convert.ToInt32(cdr[moduleStr + "_id"].ToString())].ToString()); if (isdelete == "1")//转移内容后删除原来内容 { session.simple("delete from [dcms_" + moduleStr + "] where " + moduleStr + "_id=" + cdr[moduleStr + "_id"].ToString()); } } } } session.CommitTrans(); return "转移成功!"; } catch { session.RollbackTrans(); return "转移失败!"; } } }
private SqlDb.Dcms_Cate getmodel(string where) { DataTable newtab = session.GetTable(where); if (newtab.Rows.Count < 1) { return null; } SqlDb.Dcms_Cate recate = new SqlDb.Dcms_Cate(); if (newtab.Rows[0]["Cate_AddTime"].ToString()!="") recate.Cate_AddTime = DateTime.Parse(newtab.Rows[0]["Cate_AddTime"].ToString()); recate.Cate_ExField1 = newtab.Rows[0]["Cate_ExField1"].ToString(); recate.Cate_ExField10 = newtab.Rows[0]["Cate_ExField10"].ToString(); recate.Cate_ExField2 = newtab.Rows[0]["Cate_ExField2"].ToString(); recate.Cate_ExField3 = newtab.Rows[0]["Cate_ExField3"].ToString(); recate.Cate_ExField4 = newtab.Rows[0]["Cate_ExField4"].ToString(); recate.Cate_ExField5 = newtab.Rows[0]["Cate_ExField5"].ToString(); recate.Cate_ExField6 = newtab.Rows[0]["Cate_ExField6"].ToString(); recate.Cate_ExField7 = newtab.Rows[0]["Cate_ExField7"].ToString(); recate.Cate_ExField8 = newtab.Rows[0]["Cate_ExField8"].ToString(); recate.Cate_ExField9 = newtab.Rows[0]["Cate_ExField9"].ToString(); recate.Cate_Guid = newtab.Rows[0]["Cate_Guid"].ToString(); if (newtab.Rows[0]["Cate_HasChild"].ToString()!="") recate.Cate_HasChild = int.Parse(newtab.Rows[0]["Cate_HasChild"].ToString()); if(newtab.Rows[0]["Cate_Id"].ToString()!="") recate.Cate_Id = int.Parse(newtab.Rows[0]["Cate_Id"].ToString()); recate.Cate_IdPath = newtab.Rows[0]["Cate_IdPath"].ToString(); recate.Cate_Image = newtab.Rows[0]["Cate_Image"].ToString(); recate.Cate_Intro = newtab.Rows[0]["Cate_Intro"].ToString(); recate.Cate_Key = newtab.Rows[0]["Cate_Key"].ToString(); recate.Cate_Lang = newtab.Rows[0]["Cate_Lang"].ToString(); recate.Cate_ManageName = newtab.Rows[0]["Cate_ManageName"].ToString(); recate.Cate_ManageUrl = newtab.Rows[0]["Cate_ManageUrl"].ToString(); if (newtab.Rows[0]["Cate_ModelKeyId"].ToString()!="") recate.Cate_ModelKeyId = newtab.Rows[0]["Cate_ModelKeyId"].ToString(); recate.Cate_Module = newtab.Rows[0]["Cate_Module"].ToString(); if(newtab.Rows[0]["Cate_Order"].ToString()!="") recate.Cate_Order = int.Parse(newtab.Rows[0]["Cate_Order"].ToString()); if (newtab.Rows[0]["Cate_ParentID"].ToString()!="") recate.Cate_ParentID = int.Parse(newtab.Rows[0]["Cate_ParentID"].ToString()); recate.Cate_SEODescription = newtab.Rows[0]["Cate_SEODescription"].ToString(); recate.Cate_SEOKeyWord = newtab.Rows[0]["Cate_SEOKeyWord"].ToString(); recate.Cate_SEOTitle = newtab.Rows[0]["Cate_SEOTitle"].ToString(); recate.Cate_State = newtab.Rows[0]["Cate_State"].ToString(); recate.Cate_Title = newtab.Rows[0]["Cate_Title"].ToString(); recate.Cate_Url = newtab.Rows[0]["Cate_Url"].ToString(); return recate; }
//递归遍历 private void forXML(XmlNode xn, int ParentID) { foreach (XmlNode node in xn.ChildNodes) { SqlDb.Dcms_Cate newcate= new SqlDb.Dcms_Cate(); SqlDb.Dcms_Cate parent = new SqlDb.Dcms_Cate(); ///循环 NewCate list判断guid是否存在,不存在的话就添加,存在的话,修改 int forint = 0; foreach (DataRow dr in CateDs.Rows) { if (dr["Cate_Guid"].ToString() == node.Attributes["Guid"].Value) { forint = 1; } } if (forint == 1) { newcate = getmodel("select * from Dcms_Cate where Cate_Guid='" + node.Attributes["Guid"].Value + "'"); } parent = getmodel("select * from Dcms_Cate where Cate_Id=" + ParentID); newcate.Cate_Key = node.Attributes["ModelKey"].Value; newcate.Cate_Title = node.Attributes["name"].Value; string type = node.Attributes["type"].Value; //是否为新建分类 if (type.Split('|')[1].Split('#').Length < 2) { switch (type.Split('|')[1]) { case "Down": newcate.Cate_Module = "down"; break; case "GuestBook": newcate.Cate_Module = "guestbook"; break; case "Introduction": newcate.Cate_Module = "baseinfo"; break; case "Link": newcate.Cate_Module = "link"; break; case "News": newcate.Cate_Module = "news"; break; case "Position": newcate.Cate_Module = "position"; break; case "Product": newcate.Cate_Module = "products"; break; } // newcate.Cate_ModelKeyId = 0; } else { switch (type.Split('|')[1].Split('#')[0]) { case "Down": newcate.Cate_Module = "down"; break; case "GuestBook": newcate.Cate_Module = "guestbook"; break; case "Introduction": newcate.Cate_Module = "baseinfo"; break; case "Link": newcate.Cate_Module = "link"; break; case "News": newcate.Cate_Module = "news"; break; case "Position": newcate.Cate_Module = "position"; break; case "Product": newcate.Cate_Module = "products"; break; } } newcate.Cate_ModelKeyId = selectmodule(type).ToString(); if (node.Attributes["showtype"].Value == "1") { newcate.Cate_ManageUrl = newcate.Cate_Module + "_list.aspx"; } else { newcate.Cate_ManageUrl = newcate.Cate_Module + "_update.aspx"; } newcate.Cate_Lang = language; newcate.Cate_Guid = node.Attributes["Guid"].Value; newcate.Cate_HasChild = 0; ///如果guid存在修改,如果不存在就添加; if (forint == 1) { session.Update(newcate); } else { if (parent != null) { newcate.Cate_IdPath = parent.Cate_IdPath+ParentID+","; parent.Cate_HasChild=1; session.Update(parent); } else { newcate.Cate_IdPath = ",0,"; } newcate.Cate_AddTime=DateTime.Now; newcate.Cate_State = "1"; newcate.Cate_ParentID = ParentID; session.Create(newcate); } //把XML中的GUID保存到arraylis中 CateAl.Add(node.Attributes["Guid"].Value); int MaxId = int.Parse(session.ExecuteScalar("select max(Cate_Id) from Dcms_Cate").ToString()); forXML(node, MaxId); } }
/// <summary> /// 编辑一条数据 /// </summary> /// <returns>"true"/"false"</returns> private string doUpdate() { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { try { string newcatetitle = IRequest.GetFormString("Cate_Title"); string oldercatetitle = string.Empty; string cateid = IRequest.GetFormString("Cate_Id"); string catemodule = IRequest.GetFormString("Cate_Module"); int id = IRequest.GetFormInt("Cate_Id", 0); if (id > 0) { session.BeginTrans(); int cateParentId = IRequest.GetFormInt("Cate_ParentID", 0); int olderParentId = 0; SqlDb.Dcms_Cate cate = new SqlDb.Dcms_Cate(); IQuery query = session.GetQuery(cate).Where(SqlDb.Dcms_Cate._CATE_ID_.EqulesExp(id)); List<SqlDb.Dcms_Cate> cateList = query.GetList<SqlDb.Dcms_Cate>(); if (cateList.Count > 0) { cate = cateList[0]; olderParentId = cate.Cate_ParentID; oldercatetitle = cate.Cate_Title; string Cate_str_idpath = cate.Cate_IdPath; string catenewidpath = cate.Cate_IdPath; if (cate.Cate_ParentID != cateParentId)//父栏目改变,修改当前新的父栏目 { if (cateParentId == 0)//如果新的父结点是根目录 { cate.Cate_IdPath = ",0,"; catenewidpath = cate.Cate_IdPath; SqlDb.Dcms_Cate subCate = new SqlDb.Dcms_Cate(); if (Cate_str_idpath == ",0,")//如果是根目录,修改该目录下所有的子栏目 { IQuery subCateQuery = session.GetQuery(subCate).Where(SqlDb.Dcms_Cate._CATE_IDPATH_.Like('%', "," + cate.Cate_Id.ToString() + ",", '%')); List<SqlDb.Dcms_Cate> subCateList = subCateQuery.GetList<SqlDb.Dcms_Cate>(); for (int i = 0; i < subCateList.Count; i++) { string sql3 = "update [Dcms_Cate] set Cate_IdPath='" + subCateList[i].Cate_IdPath.Replace(Cate_str_idpath, cate.Cate_IdPath) + "' where cate_id=" + subCateList[i].Cate_Id.ToString(); session.simple(sql3); } } else//如果不是根目录 { IQuery subCateQuery = session.GetQuery(subCate).Where(SqlDb.Dcms_Cate._CATE_IDPATH_.Like('%', Cate_str_idpath, '%')); List<SqlDb.Dcms_Cate> subCateList = subCateQuery.GetList<SqlDb.Dcms_Cate>(); for (int i = 0; i < subCateList.Count; i++) { if (subCateList[i].Cate_Id == cate.Cate_Id || subCateList[i].Cate_IdPath == Cate_str_idpath || (!subCateList[i].Cate_IdPath.Contains(cate.Cate_Id.ToString())))//排除自身和兄弟结点及兄弟结点下的子结点 { continue; } string sql3 = "update [Dcms_Cate] set Cate_IdPath='" + subCateList[i].Cate_IdPath.Replace(Cate_str_idpath, cate.Cate_IdPath) + "' where cate_id=" + subCateList[i].Cate_Id.ToString(); session.simple(sql3); } } } else//如果新的父结点不是根目录 { SqlDb.Dcms_Cate newParentCate = new SqlDb.Dcms_Cate(); IQuery newParentQuery = session.GetQuery(newParentCate).Where(SqlDb.Dcms_Cate._CATE_ID_.EqulesExp(cateParentId)); List<SqlDb.Dcms_Cate> newParentCateList = newParentQuery.GetList<SqlDb.Dcms_Cate>(); if (newParentCateList[0].Cate_IdPath.Contains(cate.Cate_IdPath) && newParentCateList[0].Cate_IdPath != cate.Cate_IdPath && cate.Cate_IdPath != ",0,") { return "父级栏目不能为该栏目下的子栏目!"; } cate.Cate_IdPath = newParentCateList[0].Cate_IdPath + cateParentId.ToString() + ","; catenewidpath = cate.Cate_IdPath; if (newParentCateList[0].Cate_HasChild == 0) { SqlDb.Dcms_Cate subCate = new SqlDb.Dcms_Cate(); if (Cate_str_idpath == ",0,")//如果是根目录,修改该目录下所有的子栏目 { IQuery subCateQuery = session.GetQuery(subCate).Where(SqlDb.Dcms_Cate._CATE_IDPATH_.Like('%', "," + cate.Cate_Id.ToString() + ",", '%')); List<SqlDb.Dcms_Cate> subCateList = subCateQuery.GetList<SqlDb.Dcms_Cate>(); for (int i = 0; i < subCateList.Count; i++) { string sql3 = "update [Dcms_Cate] set Cate_IdPath='" + subCateList[i].Cate_IdPath.Replace(Cate_str_idpath, cate.Cate_IdPath) + "' where cate_id=" + subCateList[i].Cate_Id.ToString(); session.simple(sql3); } } else//如果不是根目录 { IQuery subCateQuery = session.GetQuery(subCate).Where(SqlDb.Dcms_Cate._CATE_IDPATH_.Like('%', Cate_str_idpath, '%')); List<SqlDb.Dcms_Cate> subCateList = subCateQuery.GetList<SqlDb.Dcms_Cate>(); for (int i = 0; i < subCateList.Count; i++) { if (subCateList[i].Cate_Id == cate.Cate_Id || subCateList[i].Cate_IdPath == Cate_str_idpath || (!subCateList[i].Cate_IdPath.Contains(cate.Cate_Id.ToString())))//排除自身和兄弟结点及兄弟结点下的子结点 { continue; } string sql3 = "update [Dcms_Cate] set Cate_IdPath='" + subCateList[i].Cate_IdPath.Replace(Cate_str_idpath, cate.Cate_IdPath) + "' where cate_id=" + subCateList[i].Cate_Id.ToString(); session.simple(sql3); } } newParentCate = newParentCateList[0]; newParentCate.Cate_HasChild = 1; session.Update(newParentCate); } } } UpdateModelByForm(cate, Request.Form); //提交编辑 cate.Cate_IdPath = catenewidpath; session.Update(cate); DataTable subcatedt = session.GetTable("select * from dcms_cate where cate_idpath like '%," + id + ",%'");//取该类别下的所有子类别 if (subcatedt.Rows.Count > 0) { string oldcateidpath_1=""; oldcateidpath_1 = cate.Cate_IdPath.Substring(0, cate.Cate_IdPath.IndexOf("," + cateParentId.ToString() + ",") + 1); for (int c = 0; c < subcatedt.Rows.Count; c++) { oldcateidpath_1 = cate.Cate_IdPath + id + "," + subcatedt.Rows[c]["cate_idpath"].ToString().Substring(subcatedt.Rows[c]["cate_idpath"].ToString().IndexOf("," + id + ",")+id.ToString().Length+2); session.simple("update dcms_cate set cate_idpath='" + oldcateidpath_1 + "' where cate_id=" + subcatedt.Rows[c]["cate_id"].ToString()); } } subcatedt.Dispose(); if (olderParentId != cateParentId)//父栏目改变,修改旧的父栏目 { SqlDb.Dcms_Cate olderParentCate = new SqlDb.Dcms_Cate(); IQuery olderParentQuery = session.GetQuery(olderParentCate).Where(SqlDb.Dcms_Cate._CATE_PARENTID_.EqulesExp(olderParentId)); List<SqlDb.Dcms_Cate> olderParentCateList = olderParentQuery.GetList<SqlDb.Dcms_Cate>(); if (olderParentCateList.Count == 0)//原有的父栏目已没有子栏目更新haschild值 { IQuery tempParentQuery = session.GetQuery(olderParentCate).Where(SqlDb.Dcms_Cate._CATE_ID_.EqulesExp(olderParentId)); List<SqlDb.Dcms_Cate> tempParentCateList = tempParentQuery.GetList<SqlDb.Dcms_Cate>(); olderParentCate = tempParentCateList[0]; olderParentCate.Cate_HasChild = 0; session.Update(olderParentCate); } } } } if(!newcatetitle.Equals(oldercatetitle))//是否更改了栏目名称 { string updatectsql = "update dcms_" + catemodule + " set " + catemodule + "_CateName='" + newcatetitle + "' where " + catemodule + "_CateId=" + cateid; session.simple(updatectsql); } session.CommitTrans(); return "true"; } catch { session.RollbackTrans(); return "false"; } } }
///<summary> ///导入测试数据 ///</summary> ///<returns>"true"/"false"</returns> private string testData() { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { try { string xmlpath = HttpContext.Current.Server.MapPath(@"~/sysconfig/TestData.xml"); XmlDocument objXmlDoc = new XmlDocument(); objXmlDoc.Load(xmlpath); XmlNode rootNode = objXmlDoc.SelectSingleNode("root"); //记录测试数据 string xmlPathTestData = HttpContext.Current.Server.MapPath(@"~/sysconfig/TestRecord.xml"); XmlDocument objXmlDocTestData = new XmlDocument(); objXmlDocTestData.Load(xmlPathTestData); XmlNode rootTestData = objXmlDocTestData.DocumentElement; SqlDb.Dcms_Cate cate = new SqlDb.Dcms_Cate(); IQuery query = session.GetQuery(cate).Where(SqlDb.Dcms_Cate._CATE_MODULE_.NotEquls("guestbook").AND(SqlDb.Dcms_Cate._CATE_MANAGEURL_.NotNull())); List<SqlDb.Dcms_Cate> catelist = query.GetList<SqlDb.Dcms_Cate>(); if (catelist.Count > 0) { session.BeginTrans(); for (int i = 0; i < catelist.Count; i++) { if (catelist[i].Cate_ManageUrl.Equals("baseinfo_update.aspx")) { XmlNode objNode = rootNode.ChildNodes[0]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_BaseInfo baseinfo = new SqlDb.Dcms_BaseInfo(); session.simple("DELETE FROM [Dcms_BaseInfo] WHERE [BaseInfo_CateId] IN(" + catelist[i].Cate_Id + ")"); baseinfo.BaseInfo_CateId = catelist[i].Cate_Id; baseinfo.BaseInfo_CateName = catelist[i].Cate_Title; baseinfo.BaseInfo_Title = catelist[i].Cate_Title; baseinfo.BaseInfo_Content = "<p>" + xn.Attributes["title"].Value + "测试内容</p>" + xn.Attributes["content"].Value.Replace("[BR]", "<br /><br />"); baseinfo.BaseInfo_AddTime = DateTime.Now; baseinfo.BaseInfo_State = "1"; session.Create(baseinfo); } if (catelist[i].Cate_ManageUrl.Equals("baseinfo_list.aspx")) { XmlNode objNode = rootNode.ChildNodes[0]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_BaseInfo baseinfo = new SqlDb.Dcms_BaseInfo(); baseinfo.BaseInfo_CateId = catelist[i].Cate_Id; for (int j = 1; j < 6; j++) { baseinfo.BaseInfo_CateName = catelist[i].Cate_Title; baseinfo.BaseInfo_Title = xn.Attributes["title"].Value + "(" + j.ToString() + ")"; baseinfo.BaseInfo_Content = "<p>" + xn.Attributes["title"].Value + "测试内容" + j.ToString() + "</p>" + xn.Attributes["content"].Value.Replace("[BR]", "<br /><br />"); baseinfo.BaseInfo_AddTime = DateTime.Now; baseinfo.BaseInfo_State = "1"; session.Create(baseinfo); //记录测试数据 string addID = session.ExecuteScalar("select max(BaseInfo_Id) from Dcms_BaseInfo"); if (!string.IsNullOrEmpty(addID)) { XmlElement element = objXmlDocTestData.CreateElement("data"); element.SetAttribute("table", "Dcms_BaseInfo"); element.SetAttribute("keyColumn", "BaseInfo_Id"); element.SetAttribute("id", addID); rootTestData.AppendChild(element); } } } if (catelist[i].Cate_ManageUrl.Equals("news_update.aspx")) { XmlNode objNode = rootNode.ChildNodes[1]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_News news = new SqlDb.Dcms_News(); session.simple("DELETE FROM [Dcms_News] WHERE [News_CateId] IN(" + catelist[i].Cate_Id + ")"); news.News_CateId = catelist[i].Cate_Id; news.News_CateName = catelist[i].Cate_Title; news.News_Title = catelist[i].Cate_Title; news.News_Content = "<p>" + catelist[i].Cate_Title + "测试内容</p>" + xn.Attributes["content"].Value.Replace("[BR]", "<br /><br />"); news.News_AddTime = DateTime.Now; news.News_State = "1"; session.Create(news); } if (catelist[i].Cate_ManageUrl.Equals("news_list.aspx")) { XmlNode objNode = rootNode.ChildNodes[1]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_News news = new SqlDb.Dcms_News(); news.News_CateId = catelist[i].Cate_Id; for (int j = 1; j < 6; j++) { news.News_CateName = catelist[i].Cate_Title; news.News_Title = xn.Attributes["title"].Value + "(" + j.ToString() + ")"; news.News_Content = "<p>" + catelist[i].Cate_Title + "测试内容" + j.ToString() + "</p>" + xn.Attributes["content"].Value.Replace("[BR]", "<br /><br />"); news.News_AddTime = DateTime.Now; news.News_State = "1"; session.Create(news); //记录测试数据 string addID = session.ExecuteScalar("select max(News_Id) from Dcms_News"); if (!string.IsNullOrEmpty(addID)) { XmlElement element = objXmlDocTestData.CreateElement("data"); element.SetAttribute("table", "Dcms_News"); element.SetAttribute("keyColumn", "News_Id"); element.SetAttribute("id", addID); rootTestData.AppendChild(element); } } } if (catelist[i].Cate_ManageUrl.Equals("products_update.aspx")) { XmlNode objNode = rootNode.ChildNodes[2]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Products products = new SqlDb.Dcms_Products(); session.simple("DELETE FROM [Dcms_Products] WHERE [Products_CateID] IN(" + catelist[i].Cate_Id + ")"); products.Products_CateID = catelist[i].Cate_Id; products.Products_CateName = catelist[i].Cate_Title; products.Products_Title = catelist[i].Cate_Title; products.Products_MinImage = xn.Attributes["minimage"].Value; products.Products_BigImage = xn.Attributes["bigimage"].Value; products.Products_Introduction = xn.Attributes["content"].Value.Replace("[BR]", "<br /><br />"); products.Products_AddTime = DateTime.Now; products.Products_State = "1"; products.Products_CodeName = "00001"; products.Products_IsHot = "1"; products.Products_IsNew = "1"; session.Create(products); } if (catelist[i].Cate_ManageUrl.Equals("products_list.aspx")) { XmlNode objNode = rootNode.ChildNodes[2]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Products products = new SqlDb.Dcms_Products(); products.Products_CateID = catelist[i].Cate_Id; for (int j = 1; j < 6; j++) { products.Products_CateName = catelist[i].Cate_Title; products.Products_Title = xn.Attributes["title"].Value + "(" + j.ToString() + ")"; products.Products_MinImage = xn.Attributes["minimage"].Value; products.Products_BigImage = xn.Attributes["bigimage"].Value; products.Products_Introduction = "<p>测试内容" + j.ToString() + "</p>" + xn.Attributes["content"].Value.Replace("[BR]", "<br /><br />"); products.Products_AddTime = DateTime.Now; products.Products_State = "1"; products.Products_CodeName = "0000" + j.ToString(); products.Products_IsHot = "1"; products.Products_IsNew = "1"; session.Create(products); //记录测试数据 string addID = session.ExecuteScalar("select max(Products_Id) from Dcms_Products"); if (!string.IsNullOrEmpty(addID)) { XmlElement element = objXmlDocTestData.CreateElement("data"); element.SetAttribute("table", "Dcms_Products"); element.SetAttribute("keyColumn", "Products_Id"); element.SetAttribute("id", addID); rootTestData.AppendChild(element); } } } if (catelist[i].Cate_ManageUrl.Equals("link_update.aspx")) { XmlNode objNode = rootNode.ChildNodes[3]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Link link = new SqlDb.Dcms_Link(); session.simple("DELETE FROM [Dcms_Link] WHERE [Link_CateId] IN(" + catelist[i].Cate_Id + ")"); link.Link_CateId = catelist[i].Cate_Id; link.Link_CateName = catelist[i].Cate_Title; link.Link_Title = catelist[i].Cate_Title; link.Link_Url = xn.Attributes["linkurl"].Value; link.Link_AddTime = DateTime.Now; link.Link_State = "1"; session.Create(link); } if (catelist[i].Cate_ManageUrl.Equals("link_list.aspx")) { XmlNode objNode = rootNode.ChildNodes[3]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Link link = new SqlDb.Dcms_Link(); link.Link_CateId = catelist[i].Cate_Id; for (int j = 1; j < 6; j++) { link.Link_CateName = catelist[i].Cate_Title; link.Link_Title = xn.Attributes["title"].Value + "(" + j.ToString() + ")"; link.Link_Url = xn.Attributes["linkurl"].Value; link.Link_AddTime = DateTime.Now; link.Link_State = "1"; session.Create(link); //记录测试数据 string addID = session.ExecuteScalar("select max(link_Id) from Dcms_Link"); if (!string.IsNullOrEmpty(addID)) { XmlElement element = objXmlDocTestData.CreateElement("data"); element.SetAttribute("table", "Dcms_Link"); element.SetAttribute("id", addID); rootTestData.AppendChild(element); } } } if (catelist[i].Cate_ManageUrl.Equals("down_update.aspx")) { XmlNode objNode = rootNode.ChildNodes[4]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Down down = new SqlDb.Dcms_Down(); session.simple("DELETE FROM [Dcms_Down] WHERE [Down_CateID] IN(" + catelist[i].Cate_Id + ")"); down.Down_CateID = catelist[i].Cate_Id; down.Down_CateName = catelist[i].Cate_Title; down.Down_Title = catelist[i].Cate_Title; down.Down_FileType = xn.Attributes["filetype"].Value; down.Down_LocalPath = xn.Attributes["localpath"].Value; down.Down_AddTime = DateTime.Now; down.Down_State = "1"; session.Create(down); } if (catelist[i].Cate_ManageUrl.Equals("down_list.aspx")) { XmlNode objNode = rootNode.ChildNodes[4]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Down down = new SqlDb.Dcms_Down(); down.Down_CateID = catelist[i].Cate_Id; for (int j = 1; j < 6; j++) { down.Down_CateName = catelist[i].Cate_Title; down.Down_Title = xn.Attributes["title"].Value + "(" + j.ToString() + ")"; down.Down_FileType = xn.Attributes["filetype"].Value; down.Down_LocalPath = xn.Attributes["localpath"].Value; down.Down_AddTime = DateTime.Now; down.Down_State = "1"; session.Create(down); //记录测试数据 string addID = session.ExecuteScalar("select max(Down_Id) from Dcms_Down"); if (!string.IsNullOrEmpty(addID)) { XmlElement element = objXmlDocTestData.CreateElement("data"); element.SetAttribute("table", "Dcms_Down"); element.SetAttribute("keyColumn", "Down_Id"); element.SetAttribute("id", addID); rootTestData.AppendChild(element); } } } if (catelist[i].Cate_ManageUrl.Equals("position_update.aspx")) { XmlNode objNode = rootNode.ChildNodes[5]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Position position = new SqlDb.Dcms_Position(); session.simple("DELETE FROM [Dcms_Position] WHERE [Position_CateId] IN(" + catelist[i].Cate_Id + ")"); position.Position_CateId = catelist[i].Cate_Id; position.Position_CateName = catelist[i].Cate_Title; position.Position_Title = xn.Attributes["title"].Value; position.Position_Num = xn.Attributes["num"].Value; position.Position_Departments = xn.Attributes["departments"].Value; position.Position_Area = xn.Attributes["area"].Value; position.Position_AddTime = DateTime.Now; position.Position_ValidTime = Convert.ToDateTime(xn.Attributes["validtime"].Value); position.Position_Conditions = xn.Attributes["conditions"].Value.Replace("[BR]", "<br /><br />"); position.Position_Description = xn.Attributes["description"].Value.Replace("[BR]", "<br /><br />"); position.Position_Contact = xn.Attributes["contact"].Value.Replace("[BR]", "<br /><br />"); position.Position_State = "1"; session.Create(position); } if (catelist[i].Cate_ManageUrl.Equals("position_list.aspx")) { XmlNode objNode = rootNode.ChildNodes[5]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Position position = new SqlDb.Dcms_Position(); position.Position_CateId = catelist[i].Cate_Id; for (int j = 1; j < 6; j++) { position.Position_CateName = catelist[i].Cate_Title; position.Position_Title = xn.Attributes["title"].Value + "(" + j.ToString() + ")"; position.Position_Num =xn.Attributes["num"].Value; position.Position_Departments = xn.Attributes["departments"].Value + "(" + j.ToString() + ")"; position.Position_Area = xn.Attributes["area"].Value + "(" + j.ToString() + ")"; position.Position_AddTime = DateTime.Now; position.Position_ValidTime = Convert.ToDateTime(xn.Attributes["validtime"].Value); position.Position_Conditions = "<p>测试内容" + j.ToString() + "</p>" + xn.Attributes["conditions"].Value.Replace("[BR]", "<br /><br />"); position.Position_Description = "<p>测试内容" + j.ToString() + "</p>" + xn.Attributes["description"].Value.Replace("[BR]", "<br /><br />"); position.Position_Contact = "<p>测试内容" + j.ToString() + "</p>" + xn.Attributes["contact"].Value.Replace("[BR]", "<br /><br />"); position.Position_State = "1"; session.Create(position); //记录测试数据 string addID = session.ExecuteScalar("select max(Position_Id) from Dcms_Position"); if (!string.IsNullOrEmpty(addID)) { XmlElement element = objXmlDocTestData.CreateElement("data"); element.SetAttribute("table", "Dcms_Position"); element.SetAttribute("keyColumn", "Position_Id"); element.SetAttribute("id", addID); rootTestData.AppendChild(element); } } } } session.CommitTrans(); //记录测试数据 objXmlDocTestData.Save(xmlPathTestData); return "生成成功!"; } return "false"; } catch(Exception ex) { session.RollbackTrans(); return "生成失败!"+ex.Message; } } }
/// <summary> /// 批量删除操作 /// </summary> /// <returns></returns> private string doDelete() { try { int id = IRequest.GetQueryInt("id", 0); if (id > 0) { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Cate Cate = new SqlDb.Dcms_Cate(); IQuery query = session.GetQuery(Cate).Where(SqlDb.Dcms_Cate._CATE_ID_.EqulesExp(id)); List<SqlDb.Dcms_Cate> cateList = query.GetList<SqlDb.Dcms_Cate>(); if (cateList.Count > 0) { if (cateList[0].Cate_ParentID == 0 && adminInfo.Admin_Id != 1) { return "no"; } string Sql = "DELETE FROM [Dcms_Cate] WHERE [Cate_Id] =" + id.ToString() + ""; session.simple(Sql); //同时删除子一级 if (cateList[0].Cate_HasChild > 0) { //string Sql2 = "DELETE FROM [Dcms_Cate] WHERE [Cate_ParentID] =" + id.ToString() + ""; string Sql2 = "Delete From [Dcms_Cate] where Cate_IdPath like '%," + id.ToString() + ",%'"; session.simple(Sql2); } //更新父级的部分数据 int pId = cateList[0].Cate_ParentID; string pSql = "select [Cate_Id] from [Dcms_Cate] where [Cate_ParentID]=" + pId.ToString(); DataTable dt = session.GetTable(pSql); if (dt.Rows.Count <= 0) { session.simple("update [Dcms_Cate] set [Cate_HasChild]=0 where [Cate_Id]=" + pId.ToString()); } } } } return "true"; } catch { return "false"; } }
/// <summary> /// 插入一条数据 /// </summary> /// <returns>"true"/"false"</returns> private string doInsert() { try { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Cate cate = new SqlDb.Dcms_Cate(); cate.Cate_AddTime = DateTime.Now; UpdateModelByForm(cate, Request.Form); int parentId = IRequest.GetFormInt("Cate_ParentID", 0); if (parentId > 0) { SqlDb.Dcms_Cate pCate = new SqlDb.Dcms_Cate(); IQuery query = session.GetQuery(pCate).Where(SqlDb.Dcms_Cate._CATE_ID_.EqulesExp(parentId)); List<SqlDb.Dcms_Cate> cateList = query.GetList<SqlDb.Dcms_Cate>(); if (cateList.Count > 0) { cate.Cate_IdPath = cateList[0].Cate_IdPath + parentId.ToString() + ","; //更新是否含有子类 if (cateList[0].Cate_HasChild == 0) { session.simple("update [Dcms_Cate] set [Cate_HasChild]=1 where [Cate_Id]=" + parentId.ToString()); } } } else { cate.Cate_IdPath = ",0,"; } cate.Cate_Lang = Convert.ToString(Utils.GetCookie("LangFlag")); if (cate.Cate_Lang.Length<1) { return "false"; } else { cate.Cate_Guid = Guid.NewGuid().ToString("N"); //提交插入 session.Create(cate); } } return "true"; } catch { return "false"; } }
/// <summary> /// 编辑一条数据 /// </summary> /// <returns>"true"/"false"</returns> private string doUpdate() { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { try { string newcatetitle = IRequest.GetFormString("Cate_Title"); string oldercatetitle = string.Empty; string cateid = IRequest.GetFormString("Cate_Id"); string catemodule = IRequest.GetFormString("Cate_Module"); int id = IRequest.GetFormInt("Cate_Id", 0); if (id > 0) { session.BeginTrans(); int cateParentId = IRequest.GetFormInt("Cate_ParentID", 0); int olderParentId = 0; SqlDb.Dcms_Cate cate = new SqlDb.Dcms_Cate(); IQuery query = session.GetQuery(cate).Where(SqlDb.Dcms_Cate._CATE_ID_.EqulesExp(id)); List <SqlDb.Dcms_Cate> cateList = query.GetList <SqlDb.Dcms_Cate>(); if (cateList.Count > 0) { cate = cateList[0]; olderParentId = cate.Cate_ParentID; oldercatetitle = cate.Cate_Title; string Cate_str_idpath = cate.Cate_IdPath; string catenewidpath = cate.Cate_IdPath; if (cate.Cate_ParentID != cateParentId) //父栏目改变,修改当前新的父栏目 { if (cateParentId == 0) //如果新的父结点是根目录 { cate.Cate_IdPath = ",0,"; catenewidpath = cate.Cate_IdPath; SqlDb.Dcms_Cate subCate = new SqlDb.Dcms_Cate(); if (Cate_str_idpath == ",0,")//如果是根目录,修改该目录下所有的子栏目 { IQuery subCateQuery = session.GetQuery(subCate).Where(SqlDb.Dcms_Cate._CATE_IDPATH_.Like('%', "," + cate.Cate_Id.ToString() + ",", '%')); List <SqlDb.Dcms_Cate> subCateList = subCateQuery.GetList <SqlDb.Dcms_Cate>(); for (int i = 0; i < subCateList.Count; i++) { string sql3 = "update [Dcms_Cate] set Cate_IdPath='" + subCateList[i].Cate_IdPath.Replace(Cate_str_idpath, cate.Cate_IdPath) + "' where cate_id=" + subCateList[i].Cate_Id.ToString(); session.simple(sql3); } } else//如果不是根目录 { IQuery subCateQuery = session.GetQuery(subCate).Where(SqlDb.Dcms_Cate._CATE_IDPATH_.Like('%', Cate_str_idpath, '%')); List <SqlDb.Dcms_Cate> subCateList = subCateQuery.GetList <SqlDb.Dcms_Cate>(); for (int i = 0; i < subCateList.Count; i++) { if (subCateList[i].Cate_Id == cate.Cate_Id || subCateList[i].Cate_IdPath == Cate_str_idpath || (!subCateList[i].Cate_IdPath.Contains(cate.Cate_Id.ToString())))//排除自身和兄弟结点及兄弟结点下的子结点 { continue; } string sql3 = "update [Dcms_Cate] set Cate_IdPath='" + subCateList[i].Cate_IdPath.Replace(Cate_str_idpath, cate.Cate_IdPath) + "' where cate_id=" + subCateList[i].Cate_Id.ToString(); session.simple(sql3); } } } else//如果新的父结点不是根目录 { SqlDb.Dcms_Cate newParentCate = new SqlDb.Dcms_Cate(); IQuery newParentQuery = session.GetQuery(newParentCate).Where(SqlDb.Dcms_Cate._CATE_ID_.EqulesExp(cateParentId)); List <SqlDb.Dcms_Cate> newParentCateList = newParentQuery.GetList <SqlDb.Dcms_Cate>(); if (newParentCateList[0].Cate_IdPath.Contains(cate.Cate_IdPath) && newParentCateList[0].Cate_IdPath != cate.Cate_IdPath && cate.Cate_IdPath != ",0,") { return("父级栏目不能为该栏目下的子栏目!"); } cate.Cate_IdPath = newParentCateList[0].Cate_IdPath + cateParentId.ToString() + ","; catenewidpath = cate.Cate_IdPath; if (newParentCateList[0].Cate_HasChild == 0) { SqlDb.Dcms_Cate subCate = new SqlDb.Dcms_Cate(); if (Cate_str_idpath == ",0,")//如果是根目录,修改该目录下所有的子栏目 { IQuery subCateQuery = session.GetQuery(subCate).Where(SqlDb.Dcms_Cate._CATE_IDPATH_.Like('%', "," + cate.Cate_Id.ToString() + ",", '%')); List <SqlDb.Dcms_Cate> subCateList = subCateQuery.GetList <SqlDb.Dcms_Cate>(); for (int i = 0; i < subCateList.Count; i++) { string sql3 = "update [Dcms_Cate] set Cate_IdPath='" + subCateList[i].Cate_IdPath.Replace(Cate_str_idpath, cate.Cate_IdPath) + "' where cate_id=" + subCateList[i].Cate_Id.ToString(); session.simple(sql3); } } else//如果不是根目录 { IQuery subCateQuery = session.GetQuery(subCate).Where(SqlDb.Dcms_Cate._CATE_IDPATH_.Like('%', Cate_str_idpath, '%')); List <SqlDb.Dcms_Cate> subCateList = subCateQuery.GetList <SqlDb.Dcms_Cate>(); for (int i = 0; i < subCateList.Count; i++) { if (subCateList[i].Cate_Id == cate.Cate_Id || subCateList[i].Cate_IdPath == Cate_str_idpath || (!subCateList[i].Cate_IdPath.Contains(cate.Cate_Id.ToString())))//排除自身和兄弟结点及兄弟结点下的子结点 { continue; } string sql3 = "update [Dcms_Cate] set Cate_IdPath='" + subCateList[i].Cate_IdPath.Replace(Cate_str_idpath, cate.Cate_IdPath) + "' where cate_id=" + subCateList[i].Cate_Id.ToString(); session.simple(sql3); } } newParentCate = newParentCateList[0]; newParentCate.Cate_HasChild = 1; session.Update(newParentCate); } } } UpdateModelByForm(cate, Request.Form); //提交编辑 cate.Cate_IdPath = catenewidpath; session.Update(cate); DataTable subcatedt = session.GetTable("select * from dcms_cate where cate_idpath like '%," + id + ",%'");//取该类别下的所有子类别 if (subcatedt.Rows.Count > 0) { string oldcateidpath_1 = ""; oldcateidpath_1 = cate.Cate_IdPath.Substring(0, cate.Cate_IdPath.IndexOf("," + cateParentId.ToString() + ",") + 1); for (int c = 0; c < subcatedt.Rows.Count; c++) { oldcateidpath_1 = cate.Cate_IdPath + id + "," + subcatedt.Rows[c]["cate_idpath"].ToString().Substring(subcatedt.Rows[c]["cate_idpath"].ToString().IndexOf("," + id + ",") + id.ToString().Length + 2); session.simple("update dcms_cate set cate_idpath='" + oldcateidpath_1 + "' where cate_id=" + subcatedt.Rows[c]["cate_id"].ToString()); } } subcatedt.Dispose(); if (olderParentId != cateParentId)//父栏目改变,修改旧的父栏目 { SqlDb.Dcms_Cate olderParentCate = new SqlDb.Dcms_Cate(); IQuery olderParentQuery = session.GetQuery(olderParentCate).Where(SqlDb.Dcms_Cate._CATE_PARENTID_.EqulesExp(olderParentId)); List <SqlDb.Dcms_Cate> olderParentCateList = olderParentQuery.GetList <SqlDb.Dcms_Cate>(); if (olderParentCateList.Count == 0)//原有的父栏目已没有子栏目更新haschild值 { IQuery tempParentQuery = session.GetQuery(olderParentCate).Where(SqlDb.Dcms_Cate._CATE_ID_.EqulesExp(olderParentId)); List <SqlDb.Dcms_Cate> tempParentCateList = tempParentQuery.GetList <SqlDb.Dcms_Cate>(); olderParentCate = tempParentCateList[0]; olderParentCate.Cate_HasChild = 0; session.Update(olderParentCate); } } } } if (!newcatetitle.Equals(oldercatetitle))//是否更改了栏目名称 { string updatectsql = "update dcms_" + catemodule + " set " + catemodule + "_CateName='" + newcatetitle + "' where " + catemodule + "_CateId=" + cateid; session.simple(updatectsql); } session.CommitTrans(); return("true"); } catch { session.RollbackTrans(); return("false"); } } }
/// 转移数据 /// </summary> /// <returns></returns> private string shift() { string shiftway = IRequest.GetFormString("ShiftWay"); string catelangfrom = IRequest.GetFormString("CateLangFrom"); string catelangto = IRequest.GetFormString("CateLangTo"); int catefrom = IRequest.GetFormInt("CateFrom", 0); int cateto = IRequest.GetFormInt("CateTo", 0); string shifttype = IRequest.GetFormString("ShiftType"); string isdelete = IRequest.GetFormString("IsDelete"); string catelang = IRequest.GetFormString("catelang"); string catetoname = IRequest.GetFormString("CateToName"); using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { try { if (shiftway == "0")//版本转移 { session.BeginTrans(); string Sql = "select * from [Dcms_Cate] where Cate_Lang='" + catelangfrom + "' order by [Cate_Id] asc"; DataTable cateFromDt = session.GetTable(Sql); if (cateFromDt.Rows.Count > 0) { SqlDb.Dcms_Cate cate = new SqlDb.Dcms_Cate(); Dictionary <int, int> dic = new Dictionary <int, int>(); session.Create(cate);//先插入一条获取max cateid int maxcateid = session.ExecuteCount("select Max(Cate_Id) from [Dcms_Cate]", cate); session.simple("delete from [Dcms_Cate] where Cate_Id='" + maxcateid.ToString() + "'"); foreach (DataRow dr in cateFromDt.Rows) { if (shifttype.Equals("All"))//如果是转移栏目和内容 { UpdateModelByDt(cate, dr); if (session.ExecuteCount("select Max(Cate_Id) from [Dcms_Cate]", cate) < maxcateid) { dic.Add(Convert.ToInt32(dr["Cate_Id"].ToString()), maxcateid + 1); } else { dic.Add(Convert.ToInt32(dr["Cate_Id"].ToString()), session.ExecuteCount("select Max(Cate_Id) from [Dcms_Cate]", cate) + 1); } cate.Cate_Lang = catelangto; cate.Cate_IdPath = ",0,"; foreach (KeyValuePair <int, int> kv in dic) { foreach (string key in dr["Cate_IdPath"].ToString().Split(new char[] { ',' })) { if (kv.Key.ToString().Equals(key)) { cate.Cate_IdPath = cate.Cate_IdPath + kv.Value.ToString() + ","; } } if (int.Parse(dr["Cate_ParentID"].ToString()) == kv.Key) { cate.Cate_ParentID = kv.Value; } } session.Create(cate);//插入栏目 string csql = "select * from [dcms_" + dr["Cate_Module"].ToString() + "] where " + dr["Cate_Module"].ToString() + "_cateid=" + dr["Cate_Id"].ToString() + " order by [" + dr["Cate_Module"].ToString() + "_id] asc"; DataTable contentFromDt = session.GetTable(csql); if (contentFromDt.Rows.Count > 0) { Dictionary <int, int> cdic = new Dictionary <int, int>(); session.simple("insert into [dcms_" + dr["Cate_Module"].ToString() + "] (" + dr["Cate_Module"].ToString() + "_cateid) values(0)"); int maxcid = Convert.ToInt32(session.ExecuteScalar("select Max(" + dr["Cate_Module"].ToString() + "_id) from [dcms_" + dr["Cate_Module"].ToString() + "]")); session.simple("delete from [Dcms_" + dr["Cate_Module"].ToString() + "] where " + dr["Cate_Module"].ToString() + "_Id='" + maxcid.ToString() + "'"); foreach (DataRow cdr in contentFromDt.Rows) { if (Convert.ToInt32(session.ExecuteScalar("select Max(" + dr["Cate_Module"].ToString() + "_id) from [dcms_" + dr["Cate_Module"].ToString() + "]")) < maxcid) { cdic.Add(Convert.ToInt32(cdr[dr["Cate_Module"].ToString() + "_id"].ToString()), maxcid + 1); } else { cdic.Add(Convert.ToInt32(cdr[dr["Cate_Module"].ToString() + "_id"].ToString()), Convert.ToInt32(session.ExecuteScalar("select Max(" + dr["Cate_Module"].ToString() + "_id) from [dcms_" + dr["Cate_Module"].ToString() + "]")) + 1); } string columns = ""; for (int i = 1; i < contentFromDt.Columns.Count; i++) { columns += contentFromDt.Columns[i].ColumnName + ","; } columns = columns.Substring(0, columns.LastIndexOf(',')); session.simple("insert into [dcms_" + dr["Cate_Module"].ToString() + "] (" + columns + ") select " + columns + " from [dcms_" + dr["Cate_Module"].ToString() + "] where " + dr["Cate_Module"].ToString() + "_id=" + cdr[dr["Cate_Module"].ToString() + "_id"].ToString()); session.simple("update [dcms_" + dr["Cate_Module"].ToString() + "] set " + dr["Cate_Module"].ToString() + "_cateid=" + dic[Convert.ToInt32(dr["Cate_Id"].ToString())].ToString() + " where " + dr["Cate_Module"].ToString() + "_id=" + cdic[Convert.ToInt32(cdr[dr["Cate_Module"].ToString() + "_id"].ToString())].ToString()); } } } if (shifttype.Equals("Channel"))//如果是只转移栏目 { UpdateModelByDt(cate, dr); if (session.ExecuteCount("select Max(Cate_Id) from [Dcms_Cate]", cate) < maxcateid) { dic.Add(Convert.ToInt32(dr["Cate_Id"].ToString()), maxcateid + 1); } else { dic.Add(Convert.ToInt32(dr["Cate_Id"].ToString()), session.ExecuteCount("select Max(Cate_Id) from [Dcms_Cate]", cate) + 1); } cate.Cate_Lang = catelangto; cate.Cate_IdPath = ",0,"; foreach (KeyValuePair <int, int> kv in dic) { foreach (string key in dr["Cate_IdPath"].ToString().Split(new char[] { ',' })) { if (kv.Key.ToString().Equals(key)) { cate.Cate_IdPath = cate.Cate_IdPath + kv.Value.ToString() + ","; } } if (int.Parse(dr["Cate_ParentID"].ToString()) == kv.Key) { cate.Cate_ParentID = kv.Value; } } session.Create(cate);//插入栏目 } } } } if (shiftway == "1")//栏目转移下只转移内容 { session.BeginTrans(); string Sql = "select * from [Dcms_Cate] where Cate_Id='" + catefrom + "' order by [Cate_Id] asc"; DataTable cateFromDt = session.GetTable(Sql); string moduleStr = cateFromDt.Rows[0]["Cate_Module"].ToString(); string csql = "select * from [dcms_" + moduleStr + "] where " + moduleStr + "_cateid=" + cateFromDt.Rows[0]["Cate_Id"].ToString() + " order by [" + moduleStr + "_id] asc"; DataTable contentFromDt = session.GetTable(csql); if (contentFromDt.Rows.Count > 0) { Dictionary <int, int> cdic = new Dictionary <int, int>(); session.simple("insert into [dcms_" + moduleStr + "] (" + moduleStr + "_cateid) values(0)"); int maxcid = Convert.ToInt32(session.ExecuteScalar("select Max(" + moduleStr + "_id) from [dcms_" + moduleStr + "]")); session.simple("delete from [Dcms_" + moduleStr + "] where " + moduleStr + "_Id='" + maxcid.ToString() + "'"); foreach (DataRow cdr in contentFromDt.Rows) { if (Convert.ToInt32(session.ExecuteScalar("select Max(" + moduleStr + "_id) from [dcms_" + moduleStr + "]")) < maxcid) { cdic.Add(Convert.ToInt32(cdr[moduleStr + "_id"].ToString()), maxcid + 1); } else { cdic.Add(Convert.ToInt32(cdr[moduleStr + "_id"].ToString()), Convert.ToInt32(session.ExecuteScalar("select Max(" + moduleStr + "_id) from [dcms_" + moduleStr + "]")) + 1); } string columns = ""; for (int i = 1; i < contentFromDt.Columns.Count; i++) { columns += contentFromDt.Columns[i].ColumnName + ","; } columns = columns.Substring(0, columns.LastIndexOf(',')); session.simple("insert into [dcms_" + moduleStr + "] (" + columns + ") select " + columns + " from [dcms_" + moduleStr + "] where " + moduleStr + "_id=" + cdr[moduleStr + "_id"].ToString()); string upstr = "update [dcms_" + moduleStr + "] set " + moduleStr + "_CateName=" + "'" + catetoname + "'" + "," + moduleStr + "_cateid=" + cateto + " where " + moduleStr + "_id=" + cdic[Convert.ToInt32(cdr[moduleStr + "_id"].ToString())].ToString(); session.simple(upstr); // session.simple("update [dcms_" + moduleStr + "] set " +moduleStr+"_CateName=" + catetoname + "," + moduleStr + "_cateid=" + cateto + " where " + moduleStr + "_id=" + cdic[Convert.ToInt32(cdr[moduleStr + "_id"].ToString())].ToString()); if (isdelete == "1")//转移内容后删除原来内容 { session.simple("delete from [dcms_" + moduleStr + "] where " + moduleStr + "_id=" + cdr[moduleStr + "_id"].ToString()); } } } } session.CommitTrans(); return("转移成功!"); } catch { session.RollbackTrans(); return("转移失败!"); } } }
///<summary> ///导入测试数据 ///</summary> ///<returns>"true"/"false"</returns> private string testData() { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { try { string xmlpath = HttpContext.Current.Server.MapPath(@"~/sysconfig/TestData.xml"); XmlDocument objXmlDoc = new XmlDocument(); objXmlDoc.Load(xmlpath); XmlNode rootNode = objXmlDoc.SelectSingleNode("root"); //记录测试数据 string xmlPathTestData = HttpContext.Current.Server.MapPath(@"~/sysconfig/TestRecord.xml"); XmlDocument objXmlDocTestData = new XmlDocument(); objXmlDocTestData.Load(xmlPathTestData); XmlNode rootTestData = objXmlDocTestData.DocumentElement; SqlDb.Dcms_Cate cate = new SqlDb.Dcms_Cate(); IQuery query = session.GetQuery(cate).Where(SqlDb.Dcms_Cate._CATE_MODULE_.NotEquls("guestbook").AND(SqlDb.Dcms_Cate._CATE_MANAGEURL_.NotNull())); List <SqlDb.Dcms_Cate> catelist = query.GetList <SqlDb.Dcms_Cate>(); if (catelist.Count > 0) { session.BeginTrans(); for (int i = 0; i < catelist.Count; i++) { if (catelist[i].Cate_ManageUrl.Equals("baseinfo_update.aspx")) { XmlNode objNode = rootNode.ChildNodes[0]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_BaseInfo baseinfo = new SqlDb.Dcms_BaseInfo(); session.simple("DELETE FROM [Dcms_BaseInfo] WHERE [BaseInfo_CateId] IN(" + catelist[i].Cate_Id + ")"); baseinfo.BaseInfo_CateId = catelist[i].Cate_Id; baseinfo.BaseInfo_CateName = catelist[i].Cate_Title; baseinfo.BaseInfo_Title = catelist[i].Cate_Title; baseinfo.BaseInfo_Content = "<p>" + xn.Attributes["title"].Value + "测试内容</p>" + xn.Attributes["content"].Value.Replace("[BR]", "<br /><br />"); baseinfo.BaseInfo_AddTime = DateTime.Now; baseinfo.BaseInfo_State = "1"; session.Create(baseinfo); } if (catelist[i].Cate_ManageUrl.Equals("baseinfo_list.aspx")) { XmlNode objNode = rootNode.ChildNodes[0]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_BaseInfo baseinfo = new SqlDb.Dcms_BaseInfo(); baseinfo.BaseInfo_CateId = catelist[i].Cate_Id; for (int j = 1; j < 6; j++) { baseinfo.BaseInfo_CateName = catelist[i].Cate_Title; baseinfo.BaseInfo_Title = xn.Attributes["title"].Value + "(" + j.ToString() + ")"; baseinfo.BaseInfo_Content = "<p>" + xn.Attributes["title"].Value + "测试内容" + j.ToString() + "</p>" + xn.Attributes["content"].Value.Replace("[BR]", "<br /><br />"); baseinfo.BaseInfo_AddTime = DateTime.Now; baseinfo.BaseInfo_State = "1"; session.Create(baseinfo); //记录测试数据 string addID = session.ExecuteScalar("select max(BaseInfo_Id) from Dcms_BaseInfo"); if (!string.IsNullOrEmpty(addID)) { XmlElement element = objXmlDocTestData.CreateElement("data"); element.SetAttribute("table", "Dcms_BaseInfo"); element.SetAttribute("keyColumn", "BaseInfo_Id"); element.SetAttribute("id", addID); rootTestData.AppendChild(element); } } } if (catelist[i].Cate_ManageUrl.Equals("news_update.aspx")) { XmlNode objNode = rootNode.ChildNodes[1]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_News news = new SqlDb.Dcms_News(); session.simple("DELETE FROM [Dcms_News] WHERE [News_CateId] IN(" + catelist[i].Cate_Id + ")"); news.News_CateId = catelist[i].Cate_Id; news.News_CateName = catelist[i].Cate_Title; news.News_Title = catelist[i].Cate_Title; news.News_Content = "<p>" + catelist[i].Cate_Title + "测试内容</p>" + xn.Attributes["content"].Value.Replace("[BR]", "<br /><br />"); news.News_AddTime = DateTime.Now; news.News_State = "1"; session.Create(news); } if (catelist[i].Cate_ManageUrl.Equals("news_list.aspx")) { XmlNode objNode = rootNode.ChildNodes[1]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_News news = new SqlDb.Dcms_News(); news.News_CateId = catelist[i].Cate_Id; for (int j = 1; j < 6; j++) { news.News_CateName = catelist[i].Cate_Title; news.News_Title = xn.Attributes["title"].Value + "(" + j.ToString() + ")"; news.News_Content = "<p>" + catelist[i].Cate_Title + "测试内容" + j.ToString() + "</p>" + xn.Attributes["content"].Value.Replace("[BR]", "<br /><br />"); news.News_AddTime = DateTime.Now; news.News_State = "1"; session.Create(news); //记录测试数据 string addID = session.ExecuteScalar("select max(News_Id) from Dcms_News"); if (!string.IsNullOrEmpty(addID)) { XmlElement element = objXmlDocTestData.CreateElement("data"); element.SetAttribute("table", "Dcms_News"); element.SetAttribute("keyColumn", "News_Id"); element.SetAttribute("id", addID); rootTestData.AppendChild(element); } } } if (catelist[i].Cate_ManageUrl.Equals("products_update.aspx")) { XmlNode objNode = rootNode.ChildNodes[2]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Products products = new SqlDb.Dcms_Products(); session.simple("DELETE FROM [Dcms_Products] WHERE [Products_CateID] IN(" + catelist[i].Cate_Id + ")"); products.Products_CateID = catelist[i].Cate_Id; products.Products_CateName = catelist[i].Cate_Title; products.Products_Title = catelist[i].Cate_Title; products.Products_MinImage = xn.Attributes["minimage"].Value; products.Products_BigImage = xn.Attributes["bigimage"].Value; products.Products_Introduction = xn.Attributes["content"].Value.Replace("[BR]", "<br /><br />"); products.Products_AddTime = DateTime.Now; products.Products_State = "1"; products.Products_CodeName = "00001"; products.Products_IsHot = "1"; products.Products_IsNew = "1"; session.Create(products); } if (catelist[i].Cate_ManageUrl.Equals("products_list.aspx")) { XmlNode objNode = rootNode.ChildNodes[2]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Products products = new SqlDb.Dcms_Products(); products.Products_CateID = catelist[i].Cate_Id; for (int j = 1; j < 6; j++) { products.Products_CateName = catelist[i].Cate_Title; products.Products_Title = xn.Attributes["title"].Value + "(" + j.ToString() + ")"; products.Products_MinImage = xn.Attributes["minimage"].Value; products.Products_BigImage = xn.Attributes["bigimage"].Value; products.Products_Introduction = "<p>测试内容" + j.ToString() + "</p>" + xn.Attributes["content"].Value.Replace("[BR]", "<br /><br />"); products.Products_AddTime = DateTime.Now; products.Products_State = "1"; products.Products_CodeName = "0000" + j.ToString(); products.Products_IsHot = "1"; products.Products_IsNew = "1"; session.Create(products); //记录测试数据 string addID = session.ExecuteScalar("select max(Products_Id) from Dcms_Products"); if (!string.IsNullOrEmpty(addID)) { XmlElement element = objXmlDocTestData.CreateElement("data"); element.SetAttribute("table", "Dcms_Products"); element.SetAttribute("keyColumn", "Products_Id"); element.SetAttribute("id", addID); rootTestData.AppendChild(element); } } } if (catelist[i].Cate_ManageUrl.Equals("link_update.aspx")) { XmlNode objNode = rootNode.ChildNodes[3]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Link link = new SqlDb.Dcms_Link(); session.simple("DELETE FROM [Dcms_Link] WHERE [Link_CateId] IN(" + catelist[i].Cate_Id + ")"); link.Link_CateId = catelist[i].Cate_Id; link.Link_CateName = catelist[i].Cate_Title; link.Link_Title = catelist[i].Cate_Title; link.Link_Url = xn.Attributes["linkurl"].Value; link.Link_AddTime = DateTime.Now; link.Link_State = "1"; session.Create(link); } if (catelist[i].Cate_ManageUrl.Equals("link_list.aspx")) { XmlNode objNode = rootNode.ChildNodes[3]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Link link = new SqlDb.Dcms_Link(); link.Link_CateId = catelist[i].Cate_Id; for (int j = 1; j < 6; j++) { link.Link_CateName = catelist[i].Cate_Title; link.Link_Title = xn.Attributes["title"].Value + "(" + j.ToString() + ")"; link.Link_Url = xn.Attributes["linkurl"].Value; link.Link_AddTime = DateTime.Now; link.Link_State = "1"; session.Create(link); //记录测试数据 string addID = session.ExecuteScalar("select max(link_Id) from Dcms_Link"); if (!string.IsNullOrEmpty(addID)) { XmlElement element = objXmlDocTestData.CreateElement("data"); element.SetAttribute("table", "Dcms_Link"); element.SetAttribute("id", addID); rootTestData.AppendChild(element); } } } if (catelist[i].Cate_ManageUrl.Equals("down_update.aspx")) { XmlNode objNode = rootNode.ChildNodes[4]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Down down = new SqlDb.Dcms_Down(); session.simple("DELETE FROM [Dcms_Down] WHERE [Down_CateID] IN(" + catelist[i].Cate_Id + ")"); down.Down_CateID = catelist[i].Cate_Id; down.Down_CateName = catelist[i].Cate_Title; down.Down_Title = catelist[i].Cate_Title; down.Down_FileType = xn.Attributes["filetype"].Value; down.Down_LocalPath = xn.Attributes["localpath"].Value; down.Down_AddTime = DateTime.Now; down.Down_State = "1"; session.Create(down); } if (catelist[i].Cate_ManageUrl.Equals("down_list.aspx")) { XmlNode objNode = rootNode.ChildNodes[4]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Down down = new SqlDb.Dcms_Down(); down.Down_CateID = catelist[i].Cate_Id; for (int j = 1; j < 6; j++) { down.Down_CateName = catelist[i].Cate_Title; down.Down_Title = xn.Attributes["title"].Value + "(" + j.ToString() + ")"; down.Down_FileType = xn.Attributes["filetype"].Value; down.Down_LocalPath = xn.Attributes["localpath"].Value; down.Down_AddTime = DateTime.Now; down.Down_State = "1"; session.Create(down); //记录测试数据 string addID = session.ExecuteScalar("select max(Down_Id) from Dcms_Down"); if (!string.IsNullOrEmpty(addID)) { XmlElement element = objXmlDocTestData.CreateElement("data"); element.SetAttribute("table", "Dcms_Down"); element.SetAttribute("keyColumn", "Down_Id"); element.SetAttribute("id", addID); rootTestData.AppendChild(element); } } } if (catelist[i].Cate_ManageUrl.Equals("position_update.aspx")) { XmlNode objNode = rootNode.ChildNodes[5]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Position position = new SqlDb.Dcms_Position(); session.simple("DELETE FROM [Dcms_Position] WHERE [Position_CateId] IN(" + catelist[i].Cate_Id + ")"); position.Position_CateId = catelist[i].Cate_Id; position.Position_CateName = catelist[i].Cate_Title; position.Position_Title = xn.Attributes["title"].Value; position.Position_Num = xn.Attributes["num"].Value; position.Position_Departments = xn.Attributes["departments"].Value; position.Position_Area = xn.Attributes["area"].Value; position.Position_AddTime = DateTime.Now; position.Position_ValidTime = Convert.ToDateTime(xn.Attributes["validtime"].Value); position.Position_Conditions = xn.Attributes["conditions"].Value.Replace("[BR]", "<br /><br />"); position.Position_Description = xn.Attributes["description"].Value.Replace("[BR]", "<br /><br />"); position.Position_Contact = xn.Attributes["contact"].Value.Replace("[BR]", "<br /><br />"); position.Position_State = "1"; session.Create(position); } if (catelist[i].Cate_ManageUrl.Equals("position_list.aspx")) { XmlNode objNode = rootNode.ChildNodes[5]; XmlNode xn = objNode.ChildNodes[0]; SqlDb.Dcms_Position position = new SqlDb.Dcms_Position(); position.Position_CateId = catelist[i].Cate_Id; for (int j = 1; j < 6; j++) { position.Position_CateName = catelist[i].Cate_Title; position.Position_Title = xn.Attributes["title"].Value + "(" + j.ToString() + ")"; position.Position_Num = xn.Attributes["num"].Value; position.Position_Departments = xn.Attributes["departments"].Value + "(" + j.ToString() + ")"; position.Position_Area = xn.Attributes["area"].Value + "(" + j.ToString() + ")"; position.Position_AddTime = DateTime.Now; position.Position_ValidTime = Convert.ToDateTime(xn.Attributes["validtime"].Value); position.Position_Conditions = "<p>测试内容" + j.ToString() + "</p>" + xn.Attributes["conditions"].Value.Replace("[BR]", "<br /><br />"); position.Position_Description = "<p>测试内容" + j.ToString() + "</p>" + xn.Attributes["description"].Value.Replace("[BR]", "<br /><br />"); position.Position_Contact = "<p>测试内容" + j.ToString() + "</p>" + xn.Attributes["contact"].Value.Replace("[BR]", "<br /><br />"); position.Position_State = "1"; session.Create(position); //记录测试数据 string addID = session.ExecuteScalar("select max(Position_Id) from Dcms_Position"); if (!string.IsNullOrEmpty(addID)) { XmlElement element = objXmlDocTestData.CreateElement("data"); element.SetAttribute("table", "Dcms_Position"); element.SetAttribute("keyColumn", "Position_Id"); element.SetAttribute("id", addID); rootTestData.AppendChild(element); } } } } session.CommitTrans(); //记录测试数据 objXmlDocTestData.Save(xmlPathTestData); return("生成成功!"); } return("false"); } catch (Exception ex) { session.RollbackTrans(); return("生成失败!" + ex.Message); } } }
//递归遍历 private void forXML(XmlNode xn, int ParentID) { foreach (XmlNode node in xn.ChildNodes) { SqlDb.Dcms_Cate newcate = new SqlDb.Dcms_Cate(); SqlDb.Dcms_Cate parent = new SqlDb.Dcms_Cate(); ///循环 NewCate list判断guid是否存在,不存在的话就添加,存在的话,修改 int forint = 0; foreach (DataRow dr in CateDs.Rows) { if (dr["Cate_Guid"].ToString() == node.Attributes["Guid"].Value) { forint = 1; } } if (forint == 1) { newcate = getmodel("select * from Dcms_Cate where Cate_Guid='" + node.Attributes["Guid"].Value + "'"); } parent = getmodel("select * from Dcms_Cate where Cate_Id=" + ParentID); newcate.Cate_Key = node.Attributes["ModelKey"].Value; newcate.Cate_Title = node.Attributes["name"].Value; string type = node.Attributes["type"].Value; //是否为新建分类 if (type.Split('|')[1].Split('#').Length < 2) { switch (type.Split('|')[1]) { case "Down": newcate.Cate_Module = "down"; break; case "GuestBook": newcate.Cate_Module = "guestbook"; break; case "Introduction": newcate.Cate_Module = "baseinfo"; break; case "Link": newcate.Cate_Module = "link"; break; case "News": newcate.Cate_Module = "news"; break; case "Position": newcate.Cate_Module = "position"; break; case "Product": newcate.Cate_Module = "products"; break; } // newcate.Cate_ModelKeyId = 0; } else { switch (type.Split('|')[1].Split('#')[0]) { case "Down": newcate.Cate_Module = "down"; break; case "GuestBook": newcate.Cate_Module = "guestbook"; break; case "Introduction": newcate.Cate_Module = "baseinfo"; break; case "Link": newcate.Cate_Module = "link"; break; case "News": newcate.Cate_Module = "news"; break; case "Position": newcate.Cate_Module = "position"; break; case "Product": newcate.Cate_Module = "products"; break; } } newcate.Cate_ModelKeyId = selectmodule(type).ToString(); if (node.Attributes["showtype"].Value == "1") { newcate.Cate_ManageUrl = newcate.Cate_Module + "_list.aspx"; } else { newcate.Cate_ManageUrl = newcate.Cate_Module + "_update.aspx"; } newcate.Cate_Lang = language; newcate.Cate_Guid = node.Attributes["Guid"].Value; newcate.Cate_HasChild = 0; ///如果guid存在修改,如果不存在就添加; if (forint == 1) { session.Update(newcate); } else { if (parent != null) { newcate.Cate_IdPath = parent.Cate_IdPath + ParentID + ","; parent.Cate_HasChild = 1; session.Update(parent); } else { newcate.Cate_IdPath = ",0,"; } newcate.Cate_AddTime = DateTime.Now; newcate.Cate_State = "1"; newcate.Cate_ParentID = ParentID; session.Create(newcate); } //把XML中的GUID保存到arraylis中 CateAl.Add(node.Attributes["Guid"].Value); int MaxId = int.Parse(session.ExecuteScalar("select max(Cate_Id) from Dcms_Cate").ToString()); forXML(node, MaxId); } }
private SqlDb.Dcms_Cate getmodel(string where) { DataTable newtab = session.GetTable(where); if (newtab.Rows.Count < 1) { return(null); } SqlDb.Dcms_Cate recate = new SqlDb.Dcms_Cate(); if (newtab.Rows[0]["Cate_AddTime"].ToString() != "") { recate.Cate_AddTime = DateTime.Parse(newtab.Rows[0]["Cate_AddTime"].ToString()); } recate.Cate_ExField1 = newtab.Rows[0]["Cate_ExField1"].ToString(); recate.Cate_ExField10 = newtab.Rows[0]["Cate_ExField10"].ToString(); recate.Cate_ExField2 = newtab.Rows[0]["Cate_ExField2"].ToString(); recate.Cate_ExField3 = newtab.Rows[0]["Cate_ExField3"].ToString(); recate.Cate_ExField4 = newtab.Rows[0]["Cate_ExField4"].ToString(); recate.Cate_ExField5 = newtab.Rows[0]["Cate_ExField5"].ToString(); recate.Cate_ExField6 = newtab.Rows[0]["Cate_ExField6"].ToString(); recate.Cate_ExField7 = newtab.Rows[0]["Cate_ExField7"].ToString(); recate.Cate_ExField8 = newtab.Rows[0]["Cate_ExField8"].ToString(); recate.Cate_ExField9 = newtab.Rows[0]["Cate_ExField9"].ToString(); recate.Cate_Guid = newtab.Rows[0]["Cate_Guid"].ToString(); if (newtab.Rows[0]["Cate_HasChild"].ToString() != "") { recate.Cate_HasChild = int.Parse(newtab.Rows[0]["Cate_HasChild"].ToString()); } if (newtab.Rows[0]["Cate_Id"].ToString() != "") { recate.Cate_Id = int.Parse(newtab.Rows[0]["Cate_Id"].ToString()); } recate.Cate_IdPath = newtab.Rows[0]["Cate_IdPath"].ToString(); recate.Cate_Image = newtab.Rows[0]["Cate_Image"].ToString(); recate.Cate_Intro = newtab.Rows[0]["Cate_Intro"].ToString(); recate.Cate_Key = newtab.Rows[0]["Cate_Key"].ToString(); recate.Cate_Lang = newtab.Rows[0]["Cate_Lang"].ToString(); recate.Cate_ManageName = newtab.Rows[0]["Cate_ManageName"].ToString(); recate.Cate_ManageUrl = newtab.Rows[0]["Cate_ManageUrl"].ToString(); if (newtab.Rows[0]["Cate_ModelKeyId"].ToString() != "") { recate.Cate_ModelKeyId = newtab.Rows[0]["Cate_ModelKeyId"].ToString(); } recate.Cate_Module = newtab.Rows[0]["Cate_Module"].ToString(); if (newtab.Rows[0]["Cate_Order"].ToString() != "") { recate.Cate_Order = int.Parse(newtab.Rows[0]["Cate_Order"].ToString()); } if (newtab.Rows[0]["Cate_ParentID"].ToString() != "") { recate.Cate_ParentID = int.Parse(newtab.Rows[0]["Cate_ParentID"].ToString()); } recate.Cate_SEODescription = newtab.Rows[0]["Cate_SEODescription"].ToString(); recate.Cate_SEOKeyWord = newtab.Rows[0]["Cate_SEOKeyWord"].ToString(); recate.Cate_SEOTitle = newtab.Rows[0]["Cate_SEOTitle"].ToString(); recate.Cate_State = newtab.Rows[0]["Cate_State"].ToString(); recate.Cate_Title = newtab.Rows[0]["Cate_Title"].ToString(); recate.Cate_Url = newtab.Rows[0]["Cate_Url"].ToString(); return(recate); }