コード例 #1
0
 /// <summary>
 /// 提交页面窗体
 /// </summary>
 /// <returns>返回发布页面控件代码</returns>
 public string Post()
 {
     StringBuilder sr = new StringBuilder();
     int id = SiteFun.ToInt(SiteFun.Query("id"));
     CommentData cmtData = new CommentData(conn);
     CommentItem old = cmtData.GetComment(id);
     PostItem postItem = new PostData(conn).GetPost(old.PostID);
     if (SiteFun.IsPost)
     {
         bool sendMail = false;
         if (SiteFun.ToInt(SiteFun.Post("sendMail")) != 0) { sendMail = true; }
         CommentItem postVal = new CommentItem();
         postVal.ID = id;
         postVal.PostID = postItem.ID;
         postVal.Author = old.Author;
         postVal.Mail = old.Mail;
         postVal.URL = old.URL;
         postVal.Title = old.Title;
         postVal.Content = old.Content;
         postVal.Reply = SiteFun.Post("reply");
         postVal.Trackback = SiteFun.ToInt(SiteFun.Post("isTb")) == 0 ? false : true;
         postVal.Publish = old.Publish;
         postVal.Verify = SiteFun.ToInt(SiteFun.Post("verify")) == 0 ? false : true;
         if (string.IsNullOrEmpty(postVal.Author)) { sr.Append(AdminUI.ErrorBox(SiteDat.GetLan("MsgNoAuthor"))); }
         else
         {
             if (string.IsNullOrEmpty(postVal.Mail)) { sr.Append(AdminUI.ErrorBox(SiteDat.GetLan("MsgNoMail"))); }
             else
             {
                 if (string.IsNullOrEmpty(postVal.Content)) { sr.Append(AdminUI.ErrorBox(SiteDat.GetLan("MsgNoContent"))); }
                 else
                 {
                     try
                     {
                         if (sendMail)
                         {
                             SettingBasicItem basic = new SettingData(conn).GetSetting().Basic;
                             SiteMail mail = new SiteMail();
                             mail.To = old.Mail;
                             mail.Subject = string.Format(SiteDat.GetLan("MailTitle"), basic.Name);
                             mail.From = basic.MailFrom;
                             mail.Body = string.Format("<p><b>{0}: </b>{1}</p><p><b>{2}: </b>{3}</p><p><b>{4}: </b>{5}</p>", SiteDat.GetLan("Content"), SiteFun.ClearHtml(old.Content), SiteDat.GetLan("Reply"), SiteFun.ClearHtml(postVal.Reply), SiteDat.GetLan("URL"), string.Format(SitePath.ArticleLinkFormat, basic.URL, postItem.Local));
                             mail.Host = basic.MailHost;
                             mail.Port = basic.MailPort;
                             mail.UserName = basic.MailUserID;
                             mail.Password = basic.MailPassword;
                             mail.Send();
                         }
                         sr.Append(AdminUI.SuccessBox(SiteDat.GetLan("MsgSaveSucc"), "?act=comment&mode=list"));
                     }
                     catch (Exception err) { sr.Append(AdminUI.ErrorBox(err.Message)); }
                     old = cmtData.GetComment(cmtData.UpdateComment(postVal));
                 }
             }
         }
         ClearCache();
     }
     //取得默认值
     sr.Append(AdminUI.AdminBoxStart(true));
     sr.Append(HtmlUI.FormStart());
     sr.Append(HtmlUI.TableStart("onCenter"));
     sr.Append(HtmlUI.TrStart());
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Author")) + HtmlUI.CreateTd(SiteFun.HtmlEncode(old.Author)));
     sr.Append(HtmlUI.TrFinal());
     sr.Append(HtmlUI.TrStart());
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Mail")) + HtmlUI.CreateTd(SiteFun.HtmlEncode(old.Mail)));
     sr.Append(HtmlUI.TrFinal());
     sr.Append(HtmlUI.TrStart());
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Website")) + HtmlUI.CreateTd(HtmlUI.Link(SiteFun.HtmlEncode(old.URL), old.URL, null, true)));
     sr.Append(HtmlUI.TrFinal());
     sr.Append(HtmlUI.TrStart());
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Article")) + HtmlUI.CreateTd(SiteFun.HtmlEncode(postItem.Title)));
     sr.Append(HtmlUI.TrFinal());
     sr.Append(HtmlUI.TrStart());
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Content")) + HtmlUI.CreateTd(SiteFun.HtmlEncode(old.Content)));
     sr.Append(HtmlUI.TrFinal());
     sr.Append(HtmlUI.TrStart());
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Reply")) + HtmlUI.CreateTd(AdminUI.Editor("reply", SiteFun.HtmlEncode(old.Reply))));
     sr.Append(HtmlUI.TrFinal());
     sr.Append(HtmlUI.TrStart());
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("DateTime")) + HtmlUI.CreateTd(old.Publish));
     sr.Append(HtmlUI.TrFinal());
     sr.Append(HtmlUI.TrStart());
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Virtue")) + HtmlUI.CreateTd(HtmlUI.CheckBoxInput(SiteDat.GetLan("Trackback"), "isTb", 1, old.Trackback) + HtmlUI.CheckBoxInput(SiteDat.GetLan("Verify"), "verify", 1, old.Verify) + HtmlUI.CheckBoxInput(SiteDat.GetLan("MailNotice"), "sendMail", 1, false)));
     sr.Append(HtmlUI.TrFinal());
     sr.Append(HtmlUI.TrStart());
     sr.Append(HtmlUI.CreateTh() + HtmlUI.CreateTd(HtmlUI.SubmitButton() + HtmlUI.ResetButton()));
     sr.Append(HtmlUI.TrFinal());
     sr.Append(HtmlUI.TableFinal());
     sr.Append(HtmlUI.FormFinal());
     sr.Append(AdminUI.AdminBoxFinal());
     return sr.ToString();
 }
コード例 #2
0
ファイル: AdminDB.cs プロジェクト: guyuefeng/GeneralFramework
 /// <summary>
 /// 备份和恢复
 /// </summary>
 public string Backup()
 {
     StringBuilder sr = new StringBuilder();
     string backupPath = Path.Combine(SiteCfg.Router, "Common/Data/Backup/");
     if (SiteFun.IsPost)
     {
         try
         {
             bool dbSel = SiteFun.ToInt(SiteFun.Post("dbSel")) > 0;
             bool attachSel = SiteFun.ToInt(SiteFun.Post("attachSel")) > 0;
             bool delBackup = SiteFun.ToInt(SiteFun.Post("del")) > 0;
             bool sendMail = SiteFun.ToInt(SiteFun.Post("sendMail")) > 0;
             string fileName = SiteFun.Post("fileName");
             //开始备份数据
             if (dbSel || attachSel)
             {
                 if (dbSel)
                 {
                     string dbFile = HttpContext.Current.Server.MapPath(SiteCfg.DBPath);
                     string tmpSavFileName = string.Format("{1}-{0}.bak", Path.GetFileNameWithoutExtension(dbFile), DateTime.Now.ToString("yyyyMMdd"));
                     File.Copy(dbFile, Path.Combine(backupPath, tmpSavFileName), true);
                 }
                 //开始备份附件
                 if (attachSel)
                 {
                     //Folder.CopyFolder(Path.Combine(SiteCfg.Router, @"Attach\"), Path.Combine(rootFolder, @"Attach\"));
                 }
                 sr.Append(AdminUI.SuccessBox(SiteDat.GetLan("MsgBackupSucc")));
             }
             else
             {
                 if (sendMail)
                 {
                     SettingBasicItem basic = new SettingData(conn).GetSetting().Basic;
                     SiteMail mail = new SiteMail();
                     string dt = DateTime.Now.ToString("yyyy-MM-dd");
                     mail.To = basic.Mail;
                     mail.Subject = string.Format("{0} DB BAK, {1}", basic.Name, dt);
                     mail.From = basic.MailFrom;
                     mail.Body = "Time: " + dt;
                     mail.Host = basic.MailHost;
                     mail.Port = basic.MailPort;
                     mail.UserName = basic.MailUserID;
                     mail.Password = basic.MailPassword;
                     mail.Send(Path.Combine(backupPath, fileName));
                     sr.Append(AdminUI.SuccessBox(SiteDat.GetLan("MsgBackupSucc")));
                 }
                 if (delBackup)
                 {
                     File.Delete(Path.Combine(backupPath, fileName));
                     sr.Append(AdminUI.SuccessBox(SiteDat.GetLan("MsgDelBackupSucc")));
                 }
             }
         }
         catch (Exception err) { sr.Append(AdminUI.ErrorBox(err.Message)); }
     }
     sr.Append(AdminUI.AdminBoxStart(true));
     sr.Append(HtmlUI.FormStart());
     sr.Append(HtmlUI.TableStart("onCenter"));
     sr.Append(HtmlUI.TrStart());
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Backup")) + HtmlUI.CreateTd(HtmlUI.CheckBoxInput(SiteDat.GetLan("Database"), "dbSel", 1, false)));
     /*sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Backup")) + HtmlUI.CreateTd(HtmlUI.CheckBoxInput(SiteDat.GetLan("Database"), "dbSel", 1, false) + HtmlUI.CheckBoxInput(SiteDat.GetLan("Attach"), "attachSel", 1, false)));*/
     sr.Append(HtmlUI.TrFinal());
     sr.Append(HtmlUI.TrStart());
     sr.Append(HtmlUI.CreateTh() + HtmlUI.CreateTd(HtmlUI.SubmitButton() + HtmlUI.ResetButton()));
     sr.Append(HtmlUI.TrFinal());
     sr.Append(HtmlUI.TableFinal());
     sr.Append(HtmlUI.FormFinal());
     sr.Append(AdminUI.AdminBoxFinal());
     //列表
     sr.Append(AdminUI.AdminBoxStart(true));
     sr.Append(HtmlUI.TableStart());
     sr.Append(HtmlUI.TrStart());
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("FileName")));
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("DateTime")));
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Size")));
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Delete")));
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("MailNotice")));
     sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Operate")));
     sr.Append(HtmlUI.TrFinal());
     //循环
     int i = 1;
     foreach (string file in Directory.GetFiles(backupPath))
     {
         i++;
         FileInfo fileInfo = new FileInfo(file);
         sr.Append(HtmlUI.FormStart());
         sr.Append(HtmlUI.TrStart(i % 2 == 0 ? " cRow" : null));
         sr.Append(HtmlUI.CreateTd(fileInfo.Name));
         sr.Append(HtmlUI.CreateTd(fileInfo.CreationTime));
         sr.Append(HtmlUI.CreateTd(SiteFun.ToInt(fileInfo.Length / 1024) + " Kb"));
         sr.Append(HtmlUI.CreateTd(HtmlUI.CheckBoxInput("del", 1, false)));
         sr.Append(HtmlUI.CreateTd(HtmlUI.CheckBoxInput("sendMail", 1, false)));
         sr.Append(HtmlUI.CreateTd(HtmlUI.HiddenInput("fileName", SiteFun.HtmlEncode(fileInfo.Name)) + HtmlUI.SubmitButton()));
         sr.Append(HtmlUI.TrFinal());
         sr.Append(HtmlUI.FormFinal());
     }
     //循环结束
     sr.Append(HtmlUI.TableFinal());
     sr.Append(AdminUI.AdminBoxFinal());
     return sr.ToString();
 }