示例#1
0
 protected void BtnNext_Click(object sender, EventArgs e)
 {
     if ((this.RbtDataType.SelectedIndex <= 2) || this.TestDbSource())
     {
         string iname       = this.TxtLabelName.Text.Trim();
         string path        = WebConfigurationManager.AppSettings["EasyOne:LabelXsltPath"];
         string xmlfilepath = string.Empty;
         if (!string.IsNullOrEmpty(this.m_LabelName))
         {
             xmlfilepath = HttpContext.Current.Server.MapPath(path) + @"\" + this.ViewState["oldlabelname"].ToString() + ".config";
         }
         else
         {
             xmlfilepath = HttpContext.Current.Server.MapPath(path) + @"\" + iname + ".config";
         }
         if (this.SaveToXmlFile(xmlfilepath))
         {
             if (string.IsNullOrEmpty(this.m_LabelName))
             {
                 if (!LabelManage.Exists(iname))
                 {
                     BasePage.ResponseRedirect("LabelProperty.aspx?action=add&name=" + base.Server.UrlEncode(iname));
                 }
                 else
                 {
                     this.NReq.Text    = "该标签已存在!";
                     this.NReq.IsValid = false;
                 }
             }
             else if (string.Compare(this.ViewState["oldlabelname"].ToString(), iname, StringComparison.OrdinalIgnoreCase) != 0)
             {
                 if (File.Exists(base.Server.MapPath(this.m_LabelLibPath) + @"\" + iname + ".config"))
                 {
                     this.NReq.Text    = "您不能改成已存在的标签名!";
                     this.NReq.IsValid = false;
                 }
                 else
                 {
                     File.Delete(HttpContext.Current.Server.MapPath(this.m_LabelLibPath) + @"\" + this.ViewState["oldlabelname"].ToString() + ".config");
                     File.Copy(xmlfilepath, HttpContext.Current.Server.MapPath(this.m_LabelLibPath) + @"\" + iname + ".config");
                     if (File.Exists(base.Server.MapPath(path) + @"\" + iname + ".config"))
                     {
                         File.Delete(HttpContext.Current.Server.MapPath(path) + @"\" + iname + ".config");
                     }
                     File.Move(xmlfilepath, HttpContext.Current.Server.MapPath(path) + @"\" + iname + ".config");
                     BasePage.ResponseRedirect("LabelProperty.aspx?action=modify&name=" + base.Server.UrlEncode(iname));
                 }
             }
             else
             {
                 BasePage.ResponseRedirect("LabelProperty.aspx?action=modify&name=" + base.Server.UrlEncode(iname));
             }
         }
         else
         {
             AdminPage.WriteErrMsg("保存失败!", "LabelManage.aspx");
         }
     }
 }
 protected void EBtnUpload_Click(object sender, EventArgs e)
 {
     if (this.Page.IsValid && this.FileUpload1.HasFile)
     {
         string fileName = this.FileUpload1.FileName;
         if (Path.GetExtension(fileName) == ".config")
         {
             if (!LabelManage.Exists(Path.GetFileNameWithoutExtension(fileName)))
             {
                 string path = WebConfigurationManager.AppSettings["EasyOne:LabelXsltPath"];
                 path = HttpContext.Current.Server.MapPath(path) + @"\" + fileName;
                 this.FileUpload1.SaveAs(path);
                 bool        flag     = false;
                 XmlDocument document = new XmlDocument();
                 try
                 {
                     document.Load(path);
                     if (((document.SelectSingleNode("root") != null) && (document.SelectSingleNode("root/LabelType") != null)) && (document.SelectSingleNode("root/LabelTemplate") != null))
                     {
                         flag = true;
                     }
                 }
                 catch (XmlException)
                 {
                     flag = false;
                 }
                 if (flag)
                 {
                     string str3         = "~/" + SiteConfig.SiteOption.LabelDir;
                     string destFileName = HttpContext.Current.Server.MapPath(str3) + @"\" + fileName;
                     try
                     {
                         File.Copy(path, destFileName, false);
                     }
                     catch (IOException)
                     {
                         File.Delete(path);
                         AdminPage.WriteErrMsg("上传错误!请检查标签文件格式是否正确");
                     }
                     AdminPage.WriteSuccessMsg("上传成功", "javascript:opener.location.reload();window.close();");
                 }
                 else
                 {
                     AdminPage.WriteErrMsg("文件不是规范的标签文件");
                     File.Delete(path);
                 }
             }
             else
             {
                 AdminPage.WriteErrMsg("标签已存在,请改名后上传");
             }
         }
         else
         {
             AdminPage.WriteErrMsg("请上传.config文件");
         }
     }
 }