You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/WebSearchEngine/UserSettings/PageSettings.aspx.cs

183 lines
6.6 KiB
C#

2 years ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using DSWeb.Models;
using DSWeb.EntityDA;
namespace DSWeb.UserSettings
{
public partial class PageSettings : System.Web.UI.Page
{
private string strGID;
private string strUserID;
private string strHandle;//值为save保存用户设置 值为uid通过用户GID获取设置 值为gid通过设置表GID获取信息
private string strPostSetting;//获取用户POST过来的用户设置数据
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString();
}
if (strHandle != null)
{
if (strHandle.Trim().ToLower().Equals("save"))
{
strPostSetting = Request.Form["hid_setting"].ToString();
}
if (strHandle.Trim().ToLower().Equals("uid"))
{
strUserID = Request.QueryString["gid"].ToString();
}
if (strHandle.Trim().ToLower().Equals("gid"))
{
strGID = Request.QueryString["gid"].ToString();
}
}
if (Request.QueryString["gid"] == null && Request.QueryString["uid"] == null)
{
Response.Write("-2");
}
//Response.Write(GetUserGridSetting());
}
private XmlDocument SaveUserSetting(GridEntity gridEntity)
{
XmlDocument xmlDoc = new XmlDocument();
XmlElement root = xmlDoc.CreateElement("user-settings");
//xmlDoc.AppendChild(root);
XmlElement xGid = xmlDoc.CreateElement("gid");
xGid.InnerText = gridEntity.GID;
root.AppendChild(xGid);
XmlElement xUserID = xmlDoc.CreateElement("userid");
xUserID.InnerText = gridEntity.UserID;
root.AppendChild(xUserID);
XmlElement xCreateTime = xmlDoc.CreateElement("create-time");
xCreateTime.InnerText = gridEntity.CreateTime.ToString();
root.AppendChild(xCreateTime);
XmlElement xColumns = xmlDoc.CreateElement("columns");
foreach (GridColumnEntity column in gridEntity.Columns)
{
XmlElement nName = xmlDoc.CreateElement("name");
nName.InnerText = column.Name;
xColumns.AppendChild(nName);
XmlElement nDescription = xmlDoc.CreateElement("description");
nDescription.InnerText = column.Description;
xColumns.AppendChild(nDescription);
XmlElement nIndex = xmlDoc.CreateElement("index");
nIndex.InnerText = column.Index.ToString();
xColumns.AppendChild(nIndex);
}
root.AppendChild(xColumns);
XmlElement xGroupBy = xmlDoc.CreateElement("group-by");
xGroupBy.InnerText = gridEntity.GroupBy;
root.AppendChild(xGroupBy);
XmlElement xPage = xmlDoc.CreateElement("page");
XmlElement nPageDefault = xmlDoc.CreateElement("page-default");
nPageDefault.InnerText = gridEntity.PagePreCount.ToString();
xPage.AppendChild(nPageDefault);
XmlElement nPagePre = xmlDoc.CreateElement("page-pre");
nPagePre.InnerText = gridEntity.DefaultPrePageCount.ToString() ;
xPage.AppendChild(nPagePre);
root.AppendChild(xPage);
return xmlDoc;
}
private string GetUserGridSetting()
{
string xmlResult = "";
UserSettingDA userSettingDA = new UserSettingDA();
UserSettingEntity userSettingEntity = new UserSettingEntity();
GridEntity gridEntity = new GridEntity();
if (strHandle.Trim().Equals("uid"))
{
userSettingEntity = userSettingDA.GetUserSettingByUserID(strGID);
}
else if (strHandle.Trim().Equals("gid"))
{
userSettingEntity = userSettingDA.GetUserSettingByGID(strGID);
}
if (userSettingEntity != null)
{
if (!userSettingEntity.Xml.Trim().Equals(""))
{
XmlDocument xmlSettingDoc = new XmlDocument();
try
{
xmlSettingDoc.LoadXml(userSettingEntity.Xml.Trim());
gridEntity.GID = xmlSettingDoc.ChildNodes[0].ChildNodes[0].ToString();
gridEntity.UserID = xmlSettingDoc.ChildNodes[0].ChildNodes[1].ToString();
gridEntity.CreateTime = DateTime.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[2].ToString());
IList<GridColumnEntity> columnsEntities = new List<GridColumnEntity>();
int iColCount = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes.Count;
for (int i = 0; i < iColCount; i++)
{
GridColumnEntity columnEntity = new GridColumnEntity();
columnEntity.GID = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[0].ToString();
columnEntity.Name = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[1].ToString();
columnEntity.Description = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[2].ToString();
columnEntity.Index = int.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[3].ToString());
columnsEntities.Add(columnEntity);
}
gridEntity.Columns = columnsEntities;
gridEntity.DefaultPrePageCount = int.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[4].ToString());
gridEntity.PagePreCount = int.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[5].ToString());
}
catch (Exception error)
{
throw (error);
}
}
}
xmlResult = SaveUserSetting(gridEntity).ToString();
return xmlResult;
}
}
}