Example #1
0
 /// <summary>
 /// 执行SQL语句
 /// </summary>
 /// <param name="sql">SQL</param>
 public DataSet ExecSql(string sql)
 {
     DataSet result = new DataSet();
     using (_DbHelper conn = new _DbHelper(_conn))
     {
         conn.Open();
         try { result = conn.ExecuteDataSet(sql); }
         catch (Exception err) { throw err; }
         finally { conn.Close(); }
     }
     return result;
 }
Example #2
0
 /// <summary>
 /// 执行SQL语句
 /// </summary>
 /// <param name="sqls">SQL</param>
 public int ExecSql(string[] sqls)
 {
     int result = 0;
     using (_DbHelper conn = new _DbHelper(_conn))
     {
         conn.Open();
         conn.BeginTransaction();
         try
         {
             foreach (string sql in sqls)
             {
                 result += conn.ExecuteNonQuery(sql);
             }
             conn.Commit();
         }
         catch (Exception err) { conn.Rollback(); throw err; }
         finally { conn.Close(); }
     }
     return result;
 }
Example #3
0
 /// <summary>
 /// 执行SQL并返回第一行第一列的数据
 /// </summary>
 /// <param name="sql"></param>
 /// <returns></returns>
 public object ExeSqlScalar(string sql)
 {
     object result = new object();
     using (_DbHelper conn = new _DbHelper(_conn))
     {
         conn.Open();
         result = conn.ExecuteScalar(sql);
         conn.Close();
     }
     return result;
 }
Example #4
0
 /// <summary>
 /// 设置连接时的初始化工作
 /// </summary>
 private static void initConn()
 {
     using (_DbHelper conn = new _DbHelper(_conn))
     {
         conn.Open();
         conn.BeginTransaction();
         try
         {
             if (Convert.ToInt32(conn.ExecuteScalar("SELECT COUNT([ID]) FROM [Setting]")) == 0)
             {
                 Dictionary<string, object> vals = new Dictionary<string, object>();
                 vals.Add("Name", "'我的网站'");
                 vals.Add("URL", "'http://www.GF.com/'");
                 vals.Add("ICP", "'备案号'");
                 vals.Add("Language", "'zh-CN'");
                 vals.Add("Theme", "'Amarketer-blue'");
                 vals.Add("Intro", "'我的个人网站'");
                 vals.Add("Keywords", "''");
                 vals.Add("Affiche", "'无'");
                 vals.Add("Filter", "'你妈,我操,日你,贱人,打飞机,干你'");
                 vals.Add("UploadExt", "'.ZIP,.RAR,.PNG,.JPG,.GIF'");
                 vals.Add("Mail", "''");
                 vals.Add("MailFrom", "''");
                 vals.Add("MailHost", "''");
                 vals.Add("MailPort", 0);
                 vals.Add("MailUID", "''");
                 vals.Add("MailPWD", "''");
                 vals.Add("WatermarkSeat", 0);
                 vals.Add("ParArticleNum", 8);
                 vals.Add("ParCommentNum", 10);
                 vals.Add("ParAppendFineArticleNum", 5);
                 vals.Add("ParAppendRandomArticleNum", 5);
                 vals.Add("ParAppendHotArticleNum", 5);
                 vals.Add("ParAppendHotTagNum", 10);
                 vals.Add("ParAppendNewCommentNum", 5);
                 vals.Add("RssNum", 50);
                 vals.Add("RssMode", 0);
                 vals.Add("WatermarkPath", "'Common/Images/Watermark.png'");
                 vals.Add("Key", "''");
                 string fields = string.Empty;
                 string values = string.Empty;
                 foreach (KeyValuePair<string, object> pair in vals)
                 {
                     fields = fields + string.Format("[{0}],", pair.Key);
                     values = values + string.Format("{0},", pair.Value);
                 }
                 fields = fields.Substring(0, fields.Length - 1);
                 values = values.Substring(0, values.Length - 1);
                 conn.ExecuteNonQuery(string.Format("INSERT INTO [Setting] ({0}) VALUES ({1})", fields, values));
             }
             conn.Commit();
         }
         catch (Exception err) { conn.Rollback(); throw err; }
         conn.Close();
     }
 }
 /// <summary>
 /// 后台页面执行过程
 /// </summary>
 /// <param name="sender">系统对象</param>
 /// <param name="e">事件对象</param>
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack) { Page.DataBind(); }
     using (_DbHelper conn = new _DbHelper(SiteCfg.Conn))
     {
         conn.Open();
         conn.BeginTransaction();
         try
         {
             Stopwatch watch = new Stopwatch();
             watch.Start();
             //菜单HTML设置
             StringBuilder parentMenu = new StringBuilder();
             parentMenu.AppendLine("<div class=\"item\" id=\"{$ID}\">");
             parentMenu.AppendLine("\t<div class=\"top\">");
             parentMenu.AppendLine("\t\t<a class=\"menuCap\" rel=\"{$Rel}\">{$Caption}</a><span></span>");
             parentMenu.AppendLine("\t</div>");
             parentMenu.AppendLine("\t<div class=\"content\">");
             parentMenu.AppendLine("\t\t<ul>");
             parentMenu.AppendLine("\t\t{$ItemList}");
             parentMenu.AppendLine("\t\t</ul>");
             parentMenu.AppendLine("\t</div>");
             parentMenu.AppendLine("</div>");
             string menuItem = "<li><a href=\"{$Link}\">{$Caption}</a>{$Icon}</li>";
             //初始化后台基类
             _AdminBase admBase = new _AdminBase(conn);
             //初始化全局数据连接
             admBase.InitConn();
             menuDisplay.Text = new _AdminBase(conn).MenuCode(GetMenuXml(admBase.IsLogin), parentMenu.ToString(), menuItem);
             //是否登录
             if (admBase.IsLogin)
             {
                 //是否是用户控件扩展
                 if (SiteFun.Query("act") == "extend")
                 {
                     try
                     {
                         string folder = SiteFun.Query("folder");
                         string key = SiteFun.Query("key");
                         if (!string.IsNullOrEmpty(folder)) { folder = folder.Replace("..", string.Empty); }
                         XmlDocument extendXml = new XmlDocument();
                         string configXmlPath = Path.Combine(SiteCfg.Router, string.Format("Common/Expand/_Admin/{0}/Config.xml", folder));
                         if (File.Exists(configXmlPath))
                         {
                             extendXml.Load(configXmlPath);
                             //用户控件的文件名
                             string ucFile = string.Empty;
                             foreach (XmlNode node in extendXml.SelectNodes("/root/item"))
                             {
                                 if (node.Attributes["key"].Value == key)
                                 {
                                     ucFile = node.Attributes["file"].Value;
                                     if (!string.IsNullOrEmpty(ucFile)) { ucFile = ucFile.Replace("..", string.Empty); }
                                     break;
                                 }
                             }
                             string ucFilePath = string.Format("Common/Expand/_Admin/{0}/{1}", folder, ucFile);
                             if (File.Exists(Path.Combine(SiteCfg.Router, ucFilePath)))
                             {
                                 Control uc = new UserControl().LoadControl(ucFilePath);
                                 mainDisplay.Controls.Add(uc);
                             }
                             else { mainDisplay.Text = "No " + ucFilePath; }
                         }
                     }
                     catch (Exception er) { mainDisplay.Text = er.Message; }
                 }
                 else { mainDisplay.Text = getMainCode(conn); }
             }
             else { mainDisplay.Text = admBase.LoginWindow(); }
             powered.Text = SiteCfg.Powered;
             if (conn.ExecuteCount > 0) { conn.Commit(); }
             watch.Stop();
             debug.Text = watch.Elapsed.TotalSeconds.ToString("0.0000");
             watch.Reset();
         }
         catch (Exception err)
         {
             if (conn.ExecuteCount > 0) { conn.Rollback(); }
             IMyError exeError = new MyError();
             foreach (IMyError myError in new SiteExpand().GetTypes(typeof(IMyError).FullName))
             {
                 exeError = myError;
                 break;
             }
             exeError.PrintError(err);
         }
         conn.Close();
     }
 }
 /// <summary>
 /// 显示内容
 /// </summary>
 /// <param name="sender">基类对象</param>
 /// <param name="e">事件对象</param>
 protected void Page_Load(object sender, EventArgs e)
 {
     using (_DbHelper conn = new _DbHelper(SiteCfg.Conn))
     {
         conn.Open();
         conn.BeginTransaction();
         try
         {
             XsltTemplate tpl = new XsltTemplate(conn);
             //初始化全局页面类库
             _WebBase wb = new _WebBase();
             wb.InitConn();
             //开始执行
             switch (SiteFun.Query("act"))
             {
                 case "page":
                     {
                         int id = SiteFun.ToInt(SiteFun.Query("id"));
                         string local = SiteFun.Query("local");
                         WebPage webPg = new WebPage(conn);
                         tpl.LoadXslt(Path.Combine(SiteCfg.Router, string.Format(SitePath.ThemePathFormat, webPg.OutTheme, "Page.View")));
                         tpl.BindXml(webPg.OutWrite(id, local));
                         break;
                     }
                 case "tags":
                     {
                         WebTags webTags = new WebTags(conn);
                         tpl.LoadXslt(Path.Combine(SiteCfg.Router, string.Format(SitePath.ThemePathFormat, webTags.OutTheme, "Tag.List")));
                         tpl.BindXml(webTags.OutWrite());
                         break;
                     }
                 case "fellows":
                     {
                         WebFellows webFlw = new WebFellows(conn);
                         tpl.LoadXslt(Path.Combine(SiteCfg.Router, string.Format(SitePath.ThemePathFormat, webFlw.OutTheme, "Fellow.List")));
                         tpl.BindXml(webFlw.OutWrite());
                         break;
                     }
                 case "expand":
                     {
                         foreach (object type in new SiteExpand().GetTypes(typeof(IWebExpand).FullName))
                         {
                             IWebExpand iae = ((IWebExpand)type);
                             if (iae.Key == SiteFun.Query("key"))
                             {
                                 StringBuilder xml = new StringBuilder();
                                 xml.Append("\t\t<expand>\n");
                                 xml.AppendFormat("\t\t\t<css>{0}</css>\n", SiteFun.CDATA(iae.Css));
                                 xml.AppendFormat("\t\t\t<html>{0}</html>\n", SiteFun.CDATA(iae.OutHtml()));
                                 xml.Append("\t\t</expand>\n");
                                 tpl.LoadXslt(Path.Combine(SiteCfg.Router, string.Format(SitePath.ThemePathFormat, iae.OutTheme, "Expand.View")));
                                 tpl.BindXml(new _WebBaseXml(conn).OutBaseXml(iae.Name, xml.ToString()));
                                 break;
                             }
                         }
                         break;
                     }
                 default:
                     {
                         WebArticle webArt = new WebArticle(conn);
                         switch (SiteFun.Query("mode"))
                         {
                             case "view":
                                 {
                                     int id = SiteFun.ToInt(SiteFun.Query("id"));
                                     string local = SiteFun.Query("local");
                                     string pwd = SiteFun.Post("pwd");
                                     int page = SiteFun.ToInt(SiteFun.Query("page"));
                                     int pageSize = webArt.OutSetting.Parameter.CommentNum;
                                     string tplFile = "Article.View";
                                     PostItem postItem = new PostData(conn).GetPost(id);
                                     ColumnItem columnItem = new ColumnData(conn).GetColumn(postItem.ColumnID);
                                     if (postItem.ID == 0) { postItem = new PostData(conn).GetPost(local); }
                                     if (!string.IsNullOrEmpty(columnItem.ViewTemplate) && File.Exists(Path.Combine(SiteCfg.Router, string.Format(SitePath.ThemePathFormat, webArt.OutTheme, columnItem.ViewTemplate)))) { tplFile = columnItem.ViewTemplate; }
                                     tpl.LoadXslt(Path.Combine(SiteCfg.Router, string.Format(SitePath.ThemePathFormat, webArt.OutTheme, tplFile)));
                                     tpl.BindXml(webArt.OutWriteView(id, local, pwd, page, pageSize));
                                     break;
                                 }
                             default:
                                 {
                                     int cid = SiteFun.ToInt(SiteFun.Query("cid"));
                                     string clocal = SiteFun.Query("clocal");
                                     string tag = SiteFun.Query("tag");
                                     string key = SiteFun.Query("key");
                                     int page = SiteFun.ToInt(SiteFun.Query("page"));
                                     int pageSize = webArt.OutSetting.Parameter.ArticleNum;
                                     string tplFile = "Article.List";
                                     //开始处理
                                     ColumnItem column = new ColumnData(conn).GetColumn(cid);
                                     if (column.ID == 0) { column = new ColumnData(conn).GetColumn(clocal); }
                                     if (column.ID == 0 && string.IsNullOrEmpty(tag) && string.IsNullOrEmpty(key) && page == 0 && File.Exists(Path.Combine(SiteCfg.Router, string.Format(SitePath.ThemePathFormat, webArt.OutTheme, "Index")))) { tplFile = "Index"; }
                                     else
                                     {
                                         if (column.ID > 0)
                                         {
                                             if (!string.IsNullOrEmpty(column.ListTemplate) && File.Exists(Path.Combine(SiteCfg.Router, string.Format(SitePath.ThemePathFormat, webArt.OutTheme, column.ListTemplate)))) { tplFile = column.ListTemplate; }
                                             if (column.PageSize > 0) { pageSize = column.PageSize; }
                                         }
                                     }
                                     tpl.LoadXslt(Path.Combine(SiteCfg.Router, string.Format(SitePath.ThemePathFormat, webArt.OutTheme, tplFile)));
                                     tpl.BindXml(webArt.OutWriteList(cid, clocal, tag, key, page, pageSize));
                                     break;
                                 }
                         }
                         break;
                     }
             }
             if (conn.ExecuteCount > 0) { conn.Commit(); }
             tpl.Print();
         }
         catch (Exception err)
         {
             if (conn.ExecuteCount > 0) { conn.Rollback(); }
             IMyError exeError = new MyError();
             foreach (IMyError myError in new SiteExpand().GetTypes(typeof(IMyError).FullName))
             {
                 exeError = myError;
                 break;
             }
             exeError.PrintError(err);
         }
         conn.Close();
     }
 }
 /// <summary>
 /// 显示内容
 /// </summary>
 /// <param name="sender">基类对象</param>
 /// <param name="e">事件对象</param>
 protected void Page_Load(object sender, EventArgs e)
 {
     using (_DbHelper conn = new _DbHelper(SiteCfg.Conn))
     {
         conn.Open();
         conn.BeginTransaction();
         try
         {
             _ServiceBase sb = new _ServiceBase();
             sb.InitConn();
             //开始执行
             switch (SiteFun.Query("act"))
             {
                 case "comment":
                     {
                         new ServiceComment(conn).OutWrite();
                         break;
                     }
                 case "passwordArticle":
                     {
                         new ServicePost(conn).OutWriteOfPasswordArticle();
                         break;
                     }
                 case "rss":
                     {
                         new ServiceRss(conn).OutWrite();
                         break;
                     }
                 case "autoSave":
                     {
                         new ServicePost(conn).OutAutoSavePost();
                         break;
                     }
                 case "rePostContent":
                     {
                         new ServicePost(conn).OutRePostContent();
                         break;
                     }
                 case "artVote":
                     {
                         new ServicePost(conn).OutWriteVote();
                         break;
                     }
                 case "matchTags":
                     {
                         new ServiceTag(conn).GetMatchTags();
                         break;
                     }
                 case "trackback":
                     {
                         new ServiceTrackback(conn).OutWrite();
                         break;
                     }
                 case "verifyCode":
                     {
                         new ServiceVerifyCode().Display();
                         break;
                     }
                 case "getTime":
                     {
                         new ServiceTime().OutWrite();
                         break;
                     }
                 case "expand":
                     {
                         foreach (object type in new SiteExpand().GetTypes(typeof(IServiceExpand).FullName))
                         {
                             IServiceExpand iae = ((IServiceExpand)type);
                             if (iae.Key == SiteFun.Query("key"))
                             {
                                 iae.OutWrite();
                                 break;
                             }
                         }
                         break;
                     }
             }
             if (conn.ExecuteCount > 0) { conn.Commit(); }
         }
         catch (Exception err)
         {
             if (conn.ExecuteCount > 0) { conn.Rollback(); }
             IMyError exeError = new MyError();
             foreach (IMyError myError in new SiteExpand().GetTypes(typeof(IMyError).FullName))
             {
                 exeError = myError;
                 break;
             }
             exeError.PrintError(err);
         }
         conn.Close();
     }
 }