using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using xabaraCOM;

public partial class WebXabara_eWebPre : System.Web.UI.Page
{
    admin a = new admin();
    classify c = new classify();
    sqlServer sql = new sqlServer();
    javasrcipt js = new javasrcipt();

    protected void Page_Load(object sender, EventArgs e)
    {
        a.check(string.Empty);
        if (!IsPostBack)
        {
            DataTable dt;

            string sidTemp = xabara.isNum(Request["sid"]).ToString();
            string strSql = "select treeTid,NewTitle,NewsAuthor,linkHttp,NewContent,ReadNums,PostDate from NewsXabara where Nid=" + sidTemp;
            dt = sql.getDataTable(strSql);
            if (dt.Rows.Count > 0)
            {
                string url = dt.Rows[0]["linkHttp"].ToString().Trim();
                if (url != "" && !string.IsNullOrEmpty(url as string)) //直接指向网址
                {
                    Response.Redirect(url, true);
                }
                else
                {
                    newsTitle.Text = dt.Rows[0]["NewTitle"].ToString().Trim();
                    if (!string.IsNullOrEmpty(dt.Rows[0]["NewsAuthor"].ToString() as string))
                    {
                        newsInfo.Text = "作者：" + dt.Rows[0]["NewsAuthor"].ToString().Trim() + "&nbsp;&nbsp;";
                    }
                    newsInfo.Text += "发布时间：" + Convert.ToDateTime(dt.Rows[0]["PostDate"]).ToString("yyyy-MM-dd HH:mm:ss");
                    newsInfo.Text += "&nbsp;&nbsp;阅览数：" + dt.Rows[0]["readNums"].ToString().Trim();
                    newsContent.Text = dt.Rows[0]["NewContent"].ToString();
                }
            }
            else
            {
                js.div(false, "", "text", "没有该篇文章存在！", 300, 0, Server.UrlDecode(url.currently), "goto");
            }
            dt.Dispose();

            //预览审核按钮
            if (xabara.isNum(Request.QueryString["ifPass"]) > 0)
            {
                adminIF.Visible = false;
            }
        }
    }

    protected void preBottom_Click(object sender, EventArgs e)
    {
        Response.Redirect("?ifPass=" + xabara.isNum(Request.QueryString["ifPass"]).ToString() + "&cType=" + xabara.safeSql(Request.QueryString["cType"]), true);
    }

    protected void adminIF_Click(object sender, EventArgs e)
    {
        string requestID = Request.QueryString["sid"];
        if (a.postIF > 0)
        {
            string[] strValue = new string[1];
            if (xabara.isNum(Request.QueryString["ifPass"]) < 0)
            {
                strValue[0] = "0";
            }
            else
            {
                strValue[0] = "1";
            }

            sql.update("NewsXabara", "@adminPass", strValue, " Nid=" + requestID);

            Response.Redirect("?ifPass=" + Request.QueryString["ifPass"] + "&cType=" + xabara.safeSql(Request.QueryString["cType"]), true);
        }
        else
        {
            js.div(false, "", "text", "您无权操作，请联系管理员！", 300, 0, "", "");
        }
    }
}
