Beispiel #1
0
        public static IList <PagerManageInfo> GetPagerList(string type)
        {
            string key = "CK_Label_PagerLabelList_Type_" + type;
            List <PagerManageInfo> list = new List <PagerManageInfo>();

            if (SiteCache.Get(key) == null)
            {
                string str2;
                if (HttpContext.Current != null)
                {
                    str2 = HttpContext.Current.Server.MapPath("~/" + PagerLabelLibPath);
                }
                else
                {
                    str2 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PagerLabelLibPath);
                }
                DirectoryInfo info = new DirectoryInfo(str2);
                if (info.Exists)
                {
                    foreach (FileInfo info2 in info.GetFiles())
                    {
                        try
                        {
                            using (StreamReader reader = info2.OpenText())
                            {
                                XmlDocument document = new XmlDocument();
                                document.Load(reader);
                                PagerManageInfo item = new PagerManageInfo();
                                item.Name  = Path.GetFileNameWithoutExtension(info2.Name);
                                item.Type  = document.SelectSingleNode("root/LabelType").InnerText;
                                item.Image = document.SelectSingleNode("root/LabelImage").InnerText;
                                item.Intro = document.SelectSingleNode("root/LabelIntro").InnerText;
                                if (string.IsNullOrEmpty(item.Image))
                                {
                                    item.Image = "~/Admin/Images/LabelIco/def.ico";
                                }
                                item.UpDateTime = info2.LastWriteTime;
                                if (((type == item.Type) || string.IsNullOrEmpty(type)) || (type == "全部分类"))
                                {
                                    list.Add(item);
                                }
                            }
                        }
                        catch (XmlException exception)
                        {
                            exception.ToString();
                        }
                    }
                }
                SiteCache.Insert(key, list, new CacheDependency(str2));//add sql
                return(list);
            }
            return((List <PagerManageInfo>)SiteCache.Get(key));
        }
        private void FillData()
        {
            this.ViewState["PagerName"] = BasePage.RequestString("Name");
            PagerManageInfo pagerByName = PagerManage.GetPagerByName(this.ViewState["PagerName"].ToString());

            this.TxtLabelName.Text         = pagerByName.Name;
            this.ViewState["oldlabelname"] = pagerByName.Name;
            this.TxtLabelType.Text         = pagerByName.Type;
            this.TxtLabelTemplate.Text     = pagerByName.Template.ToString();
            this.TxtLabelIntro.Text        = pagerByName.Intro;
        }
Beispiel #3
0
        public static IList <PagerManageInfo> GetPagerList(string searchType, string keyword)
        {
            string str;
            List <PagerManageInfo> list = new List <PagerManageInfo>();

            if (HttpContext.Current != null)
            {
                str = HttpContext.Current.Server.MapPath("~/" + PagerLabelLibPath);
            }
            else
            {
                str = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PagerLabelLibPath);
            }
            DirectoryInfo info = new DirectoryInfo(str);

            if (info.Exists)
            {
                foreach (FileInfo info2 in info.GetFiles())
                {
                    try
                    {
                        using (StreamReader reader = info2.OpenText())
                        {
                            XmlDocument document = new XmlDocument();
                            document.Load(reader);
                            PagerManageInfo item = new PagerManageInfo();
                            item.Name  = Path.GetFileNameWithoutExtension(info2.Name);
                            item.Type  = document.SelectSingleNode("root/LabelType").InnerText;
                            item.Image = document.SelectSingleNode("root/LabelImage").InnerText;
                            item.Intro = document.SelectSingleNode("root/LabelIntro").InnerText;
                            if (string.IsNullOrEmpty(item.Image))
                            {
                                item.Image = "~/Admin/Images/LabelIco/def.ico";
                            }
                            item.UpDateTime = info2.LastWriteTime;
                            if ((searchType == "0") && (item.Name.IndexOf(keyword, 0, StringComparison.CurrentCultureIgnoreCase) >= 0))
                            {
                                list.Add(item);
                            }
                            if ((searchType == "1") && (item.Template.ToString().IndexOf(keyword, 0, StringComparison.CurrentCultureIgnoreCase) >= 0))
                            {
                                list.Add(item);
                            }
                        }
                    }
                    catch (XmlException exception)
                    {
                        exception.ToString();
                    }
                }
            }
            return(list);
        }
        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            if (!this.Page.IsValid)
            {
                return;
            }
            if (this.ViewState["action"].ToString() == "add")
            {
                if (PagerManage.Exists(this.TxtLabelName.Text))
                {
                    AdminPage.WriteErrMsg("标签名重复");
                }
            }
            else if ((string.Compare(this.ViewState["oldlabelname"].ToString(), this.TxtLabelName.Text, StringComparison.OrdinalIgnoreCase) > 0) && PagerManage.Exists(this.TxtLabelName.Text))
            {
                AdminPage.WriteErrMsg("您不能修改成已存在的标签名");
            }
            PagerManageInfo ainfo = new PagerManageInfo();

            ainfo.Name     = this.TxtLabelName.Text;
            ainfo.Type     = this.TxtLabelType.Text;
            ainfo.Template = new StringBuilder(this.TxtLabelTemplate.Text);
            ainfo.Intro    = this.TxtLabelIntro.Text;
            bool   flag = false;
            string str  = this.ViewState["action"].ToString();

            if (str != null)
            {
                if (!(str == "add"))
                {
                    if (str == "modify")
                    {
                        flag = PagerManage.Update(ainfo, this.ViewState["oldlabelname"].ToString());
                        goto Label_0148;
                    }
                }
                else
                {
                    flag = PagerManage.Add(ainfo);
                    goto Label_0148;
                }
            }
            flag = PagerManage.Add(ainfo);
Label_0148:
            if (flag)
            {
                BasePage.ResponseRedirect("PagerManage.aspx");
            }
        }
Beispiel #5
0
        public static bool Add(PagerManageInfo ainfo)
        {
            string path = HttpContext.Current.Server.MapPath("~/" + PagerLabelLibPath) + @"\" + ainfo.Name + ".config";
            string str2 = HttpContext.Current.Server.MapPath("~/" + PagerLabelLibPath);

            try
            {
                if (!Directory.Exists(str2))
                {
                    Directory.CreateDirectory(str2);
                }
                if (!File.Exists(path))
                {
                    XmlDocument document = new XmlDocument();
                    XmlNode     newChild = document.CreateNode(XmlNodeType.XmlDeclaration, "", "");
                    document.AppendChild(newChild);
                    XmlElement element  = document.CreateElement("", "root", "");
                    XmlElement element2 = document.CreateElement("", "LabelType", "");
                    element2.InnerText = ainfo.Type;
                    element.AppendChild(element2);
                    XmlElement element3 = document.CreateElement("", "LabelImage", "");
                    element3.InnerText = ainfo.Image;
                    element.AppendChild(element3);
                    XmlElement element4 = document.CreateElement("", "LabelIntro", "");
                    element4.InnerText = ainfo.Intro;
                    element.AppendChild(element4);
                    XmlElement element5 = document.CreateElement("", "LabelTemplate", "");
                    element5.InnerText = ainfo.Template.ToString();
                    element.AppendChild(element5);
                    document.AppendChild(element);
                    using (StreamWriter writer = new StreamWriter(path, false, Encoding.GetEncoding("utf-8")))
                    {
                        writer.Write(document.InnerXml);
                    }
                    return(true);
                }
                return(false);
            }
            catch (IOException)
            {
                return(false);
            }
            catch (XmlException)
            {
                return(false);
            }
        }
Beispiel #6
0
        public static bool Update(PagerManageInfo ainfo, string oldName)
        {
            string path = VirtualPathUtility.AppendTrailingSlash(HttpContext.Current.Server.MapPath("~/" + PagerLabelLibPath));

            try
            {
                if (string.Compare(oldName, ainfo.Name, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    path = path + ainfo.Name + ".config";
                    XmlDocument document = new XmlDocument();
                    XmlNode     newChild = document.CreateNode(XmlNodeType.XmlDeclaration, "", "");
                    document.AppendChild(newChild);
                    XmlElement element  = document.CreateElement("", "root", "");
                    XmlElement element2 = document.CreateElement("", "LabelType", "");
                    element2.InnerText = ainfo.Type;
                    element.AppendChild(element2);
                    XmlElement element3 = document.CreateElement("", "LabelImage", "");
                    element3.InnerText = ainfo.Image;
                    element.AppendChild(element3);
                    XmlElement element4 = document.CreateElement("", "LabelIntro", "");
                    element4.InnerText = ainfo.Intro;
                    element.AppendChild(element4);
                    XmlElement element5 = document.CreateElement("", "LabelTemplate", "");
                    element5.InnerText = ainfo.Template.ToString();
                    element.AppendChild(element5);
                    document.AppendChild(element);
                    using (StreamWriter writer = new StreamWriter(path, false, Encoding.GetEncoding("utf-8")))
                    {
                        writer.Write(document.InnerXml);
                    }
                    return(true);
                }
                Delete(oldName);
                return(Add(ainfo));
            }
            catch (IOException)
            {
                return(false);
            }
            catch (XmlException)
            {
                return(false);
            }
        }
Beispiel #7
0
        public static PagerManageInfo GetPagerByName(string name)
        {
            string str;

            if (HttpContext.Current != null)
            {
                str = HttpContext.Current.Server.MapPath("~/" + PagerLabelLibPath) + @"\" + name + ".config";
            }
            else
            {
                str = AppDomain.CurrentDomain.BaseDirectory + PagerLabelLibPath + @"\" + name + ".config";
            }
            if (File.Exists(str))
            {
                try
                {
                    PagerManageInfo info;
                    FileInfo        info2    = new FileInfo(str);
                    XmlDocument     document = new XmlDocument();
                    using (StreamReader reader = info2.OpenText())
                    {
                        document.Load(reader);
                        info            = new PagerManageInfo();
                        info.Image      = document.SelectSingleNode("root/LabelImage").InnerText;
                        info.Intro      = document.SelectSingleNode("root/LabelIntro").InnerText;
                        info.Template   = new StringBuilder(document.SelectSingleNode("root/LabelTemplate").InnerText);
                        info.Type       = document.SelectSingleNode("root/LabelType").InnerText;
                        info.Name       = name;
                        info.UpDateTime = info2.LastWriteTime;
                    }
                    return(info);
                }
                catch (IOException)
                {
                    return(new PagerManageInfo(true));
                }
                catch (XmlException)
                {
                    return(new PagerManageInfo(true));
                }
            }
            return(new PagerManageInfo(true));
        }