Exemple #1
0
        /// <summary>
        /// 编辑一条数据
        /// </summary>
        /// <returns>"true"/"false"</returns>
        private string doUpdate()
        {
            try
            {
                //int productsid = IRequest.GetQueryInt("productsid", 0);
                int productsid = IRequest.GetFormInt("Products_ID", 0);
                if (productsid > 0)
                {
                    using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession())
                    {
                        SqlDb.Dcms_Products products = new SqlDb.Dcms_Products();
                        IQuery query = session.GetQuery(products).Where(SqlDb.Dcms_Products._PRODUCTS_ID_.EqulesExp(productsid));
                        IList <SqlDb.Dcms_Products> productslist = query.GetList <SqlDb.Dcms_Products>();
                        if (productslist.Count > 0)
                        {
                            products = productslist[0];
                            UpdateModelByForm(products, Request.Form);

                            session.Update(products);
                        }
                    }
                }
                return("true");
            }
            catch
            {
                return("false");
            }
        }
        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;
                        Products_CateName.Value = cateName;
                        Products_CateID.Value   = CateId.ToString();
                        Products_CateName.Value = cateName;
                    }
                }
            }
            if (Id == 0)
            {
                this.Page.Title     = "新建" + cateName;
                this.lit_Title.Text = "新建" + cateName;
                Products_ID.Value   = "0";
            }
            else if (Id > 0)
            {
                this.Page.Title     = "编辑" + cateName;
                this.lit_Title.Text = "编辑" + cateName;
                lit_id.Text         = Id.ToString();
                Products_ID.Value   = Id.ToString();
            }
            else
            {
                int thisId = 0;
                using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession())
                {
                    SqlDb.Dcms_Products modle = new SqlDb.Dcms_Products();
                    modle.Products_CateID = CateId;
                    IQuery query = session.GetQuery(modle).Where(SqlDb.Dcms_Products._PRODUCTS_CATEID_.EqulesExp());
                    IList <SqlDb.Dcms_Products> datalist = query.GetList <SqlDb.Dcms_Products>();
                    if (datalist.Count > 0)
                    {
                        thisId = datalist[0].Products_ID;
                    }
                }
                this.Page.Title     = "编辑" + cateName;
                this.lit_Title.Text = "编辑" + cateName;
                lit_id.Text         = thisId.ToString();
                Products_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;
                        Products_CateName.Value = cateName;
                        Products_CateID.Value = CateId.ToString();
                        Products_CateName.Value = cateName;
                    }
                }
            }
            if (Id == 0)
            {
                this.Page.Title = "新建" + cateName;
                this.lit_Title.Text = "新建" + cateName;
                Products_ID.Value = "0";
            }
            else if (Id > 0)
            {

                this.Page.Title = "编辑" + cateName;
                this.lit_Title.Text = "编辑" + cateName;
                lit_id.Text = Id.ToString();
                Products_ID.Value = Id.ToString();
            }
            else
            {
                int thisId = 0;
                using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession())
                {
                    SqlDb.Dcms_Products modle = new SqlDb.Dcms_Products();
                    modle.Products_CateID = CateId;
                    IQuery query = session.GetQuery(modle).Where(SqlDb.Dcms_Products._PRODUCTS_CATEID_.EqulesExp());
                    IList<SqlDb.Dcms_Products> datalist = query.GetList<SqlDb.Dcms_Products>();
                    if (datalist.Count > 0)
                    {
                        thisId = datalist[0].Products_ID;
                    }
                }
                this.Page.Title = "编辑" + cateName;
                this.lit_Title.Text = "编辑" + cateName;
                lit_id.Text = thisId.ToString();
                Products_ID.Value = thisId.ToString();
            }
        }
Exemple #4
0
        /// <summary>
        /// 插入一条数据
        /// </summary>
        /// <returns>"true"/"false"</returns>
        private string doInsert()
        {
            try
            {
                using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession())
                {
                    SqlDb.Dcms_Products products = new SqlDb.Dcms_Products();
                    products.Products_AddTime = DateTime.Now;
                    UpdateModelByForm(products, Request.Form);

                    session.Create(products);
                }
                return("true");
            }
            catch
            {
                return("false");
            }
        }
Exemple #5
0
        ///<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;
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// 按页取数据
        /// </summary>
        /// <returns>json</returns>
        private string doSelect()
        {
            StringBuilder sb = new StringBuilder();
            //取Grid提交来的数据开始
            //int uploadId = IRequest.GetQueryInt("id", 0);
            int    rp      = IRequest.GetFormInt("rp", 10);
            int    page    = IRequest.GetFormInt("page", 1);
            string keyword = Utils.chkSQL(IRequest.GetFormString("query"));
            string qtype   = IRequest.GetFormString("qtype");
            int    cateid  = IRequest.GetQueryInt("cateid", 0);

            //string path = getUploadPathByUploadId(uploadId).Replace("\\", "/");
            //取Grid提交来的数据结束
            using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession())
            {
                SqlDb.Dcms_Products products = new SqlDb.Dcms_Products();
                //创建查询
                IQuery query = session.GetQuery(products);

                if (keyword.Length > 0)
                {
                    if (cateid > 0)
                    {
                        query.Where(SqlDb.Dcms_Products._PRODUCTS_TITLE_.Like('%', keyword, '%').AND(SqlDb.Dcms_Products._PRODUCTS_CATEID_.EqulesExp(cateid)));
                    }
                    else
                    {
                        query.Where(SqlDb.Dcms_Products._PRODUCTS_TITLE_.Like('%', keyword, '%'));
                    }
                }
                else
                {
                    if (cateid > 0)
                    {
                        query.Where(SqlDb.Dcms_Products._PRODUCTS_CATEID_.EqulesExp(cateid));
                    }
                }
                query.OrderBy(SqlDb.Dcms_Products._PRODUCTS_ID_, Direction.DESC);
                //取总记录
                int totalCount = query.Count();
                List <SqlDb.Dcms_Products> productsList = query.GetList <SqlDb.Dcms_Products>(page, rp);
                //Json格式
                sb.Append("{\n");
                sb.Append("\"page\":" + page.ToString() + ",\n");
                sb.Append("\"total\":" + totalCount.ToString() + ",\n");
                sb.Append("\"rows\": [\n");
                for (int i = 0; i < productsList.Count; i++)
                {
                    string state = (productsList[i].Products_State == "1") ? "显示" : "关闭";
                    sb.Append("{");
                    sb.Append(string.Format("\"id\":\"{0}\",\"cell\":[\"{1}\",\"{2}\",\"{3}\",\"{4}\"]", productsList[i].Products_ID.ToString(), productsList[i].Products_ID.ToString(), FormatJsonData(productsList[i].Products_Title.ToString()), state, productsList[i].Products_AddTime.ToString("yyyy/MM/dd")));
                    if ((i + 1) == productsList.Count)
                    {
                        sb.Append("}\n");
                    }
                    else
                    {
                        sb.Append("},\n");
                    }
                }
                sb.Append("]\n");
                sb.Append("}");
            }
            return(sb.ToString());
        }
        /// <summary>
        /// 编辑一条数据
        /// </summary>
        /// <returns>"true"/"false"</returns>
        private string doUpdate()
        {
            try
            {
                //int productsid = IRequest.GetQueryInt("productsid", 0);
                int productsid = IRequest.GetFormInt("Products_ID", 0);
                if (productsid > 0)
                {
                    using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession())
                    {
                        SqlDb.Dcms_Products products = new SqlDb.Dcms_Products();
                        IQuery query = session.GetQuery(products).Where(SqlDb.Dcms_Products._PRODUCTS_ID_.EqulesExp(productsid));
                        IList<SqlDb.Dcms_Products> productslist = query.GetList<SqlDb.Dcms_Products>();
                        if (productslist.Count > 0)
                        {
                            products = productslist[0];
                            UpdateModelByForm(products, Request.Form);

                            session.Update(products);

                        }

                    }
                }
                return "true";
            }
            catch
            {
                return "false";
            }
        }
        /// <summary>
        /// 按页取数据
        /// </summary>
        /// <returns>json</returns>
        private string doSelect()
        {
            StringBuilder sb = new StringBuilder();
            //取Grid提交来的数据开始
            //int uploadId = IRequest.GetQueryInt("id", 0);
            int rp = IRequest.GetFormInt("rp", 10);
            int page = IRequest.GetFormInt("page", 1);
            string keyword = Utils.chkSQL(IRequest.GetFormString("query"));
            string qtype = IRequest.GetFormString("qtype");
            int cateid = IRequest.GetQueryInt("cateid", 0);
            //string path = getUploadPathByUploadId(uploadId).Replace("\\", "/");
            //取Grid提交来的数据结束
            using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession())
            {
                SqlDb.Dcms_Products products = new SqlDb.Dcms_Products();
                //创建查询
                IQuery query = session.GetQuery(products);

                if (keyword.Length > 0)
                {
                    if (cateid > 0)
                    {
                        query.Where(SqlDb.Dcms_Products._PRODUCTS_TITLE_.Like('%', keyword, '%').AND(SqlDb.Dcms_Products._PRODUCTS_CATEID_.EqulesExp(cateid)));
                    }
                    else
                    {
                        query.Where(SqlDb.Dcms_Products._PRODUCTS_TITLE_.Like('%', keyword, '%'));
                    }
                }
                else
                {
                    if (cateid > 0)
                    {
                        query.Where(SqlDb.Dcms_Products._PRODUCTS_CATEID_.EqulesExp(cateid));
                    }
                }
                query.OrderBy(SqlDb.Dcms_Products._PRODUCTS_ID_, Direction.DESC);
                //取总记录
                int totalCount = query.Count();
                List<SqlDb.Dcms_Products> productsList = query.GetList<SqlDb.Dcms_Products>(page, rp);
                //Json格式
                sb.Append("{\n");
                sb.Append("\"page\":" + page.ToString() + ",\n");
                sb.Append("\"total\":" + totalCount.ToString() + ",\n");
                sb.Append("\"rows\": [\n");
                for (int i = 0; i < productsList.Count; i++)
                {
                    string state = (productsList[i].Products_State == "1") ? "显示" : "关闭";
                    sb.Append("{");
                    sb.Append(string.Format("\"id\":\"{0}\",\"cell\":[\"{1}\",\"{2}\",\"{3}\",\"{4}\"]", productsList[i].Products_ID.ToString(), productsList[i].Products_ID.ToString(), FormatJsonData(productsList[i].Products_Title.ToString()), state, productsList[i].Products_AddTime.ToString("yyyy/MM/dd")));
                    if ((i + 1) == productsList.Count)
                    {
                        sb.Append("}\n");
                    }
                    else
                    {
                        sb.Append("},\n");
                    }
                }
                sb.Append("]\n");
                sb.Append("}");
            }
            return sb.ToString();
        }
        /// <summary>
        /// 插入一条数据
        /// </summary>
        /// <returns>"true"/"false"</returns>
        private string doInsert()
        {
            try
            {
                using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession())
                {
                    SqlDb.Dcms_Products products = new SqlDb.Dcms_Products();
                    products.Products_AddTime = DateTime.Now;
                    UpdateModelByForm(products, Request.Form);

                    session.Create(products);
                }
                return "true";
            }
            catch
            {
                return "false";
            }
        }
Exemple #10
0
        ///<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);
                }
            }
        }