Example #1
0
        protected void BtnSaveIncludeFile_Click(object sender, EventArgs e)
        {
            IncludeFileInfo includeFileInfo = new IncludeFileInfo();

            includeFileInfo.Id            = BasePage.RequestInt32("id");
            includeFileInfo.Name          = this.TxtName.Text;
            includeFileInfo.FileName      = this.TxtFileName.Text;
            includeFileInfo.Description   = this.TxtDescription.Text;
            includeFileInfo.Template      = this.TxtTemplate.Text;
            includeFileInfo.IncludeType   = (IncludeType)Enum.Parse(typeof(IncludeType), this.RadlIncludeType.SelectedValue);
            includeFileInfo.AssociateType = (AssociateType)Enum.Parse(typeof(AssociateType), this.RadlAssociateType.SelectedValue);
            if (BasePage.RequestStringToLower("action") == "modify")
            {
                if ((includeFileInfo.Name != this.ViewState["Name"].ToString()) && IncludeFile.ExistsName(includeFileInfo.Name))
                {
                    AdminPage.WriteErrMsg("内嵌代码名称已经存在");
                }
                bool flag = string.Compare(includeFileInfo.FileName, this.ViewState["FileName"].ToString(), StringComparison.OrdinalIgnoreCase) != 0;
                if (flag && IncludeFile.ExistsFileName(includeFileInfo.FileName))
                {
                    AdminPage.WriteErrMsg("内嵌代码文件名已经存在");
                }
                if (IncludeFile.Update(includeFileInfo))
                {
                    if (flag)
                    {
                        string includeFilePath = SiteConfig.SiteOption.IncludeFilePath;
                        includeFilePath = "~/" + includeFilePath + "/" + this.ViewState["FileName"].ToString();
                        FileInfo info2 = new FileInfo(HttpContext.Current.Request.MapPath(includeFilePath));
                        if (info2.Exists)
                        {
                            info2.Delete();
                        }
                    }
                    AdminPage.WriteSuccessMsg("修改成功", "IncludeFileManage.aspx");
                }
                else
                {
                    AdminPage.WriteErrMsg("修改失败", "IncludeFileManage.aspx");
                }
            }
            else
            {
                if (IncludeFile.ExistsName(includeFileInfo.Name))
                {
                    AdminPage.WriteErrMsg("内嵌代码名称已经存在");
                }
                if (IncludeFile.ExistsFileName(includeFileInfo.FileName))
                {
                    AdminPage.WriteErrMsg("内嵌代码文件名已经存在");
                }
                if (IncludeFile.Add(includeFileInfo))
                {
                    AdminPage.WriteSuccessMsg("添加成功", "IncludeFileManage.aspx");
                }
                else
                {
                    AdminPage.WriteErrMsg("添加失败", "IncludeFileManage.aspx");
                }
            }
        }