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_news_eWebAdd : System.Web.UI.Page
{
    admin a = new admin();
    sqlServer sql = new sqlServer();
    classify c = new classify();
    fileDocument f = new fileDocument();
    javasrcipt js = new javasrcipt();

    protected void Page_Load(object sender, EventArgs e)
    {
        a.check("|news|");

        if (!IsPostBack)
        {
            string type = Request.QueryString["cType"];
            string adminIDs = a.newsIDs;
            if (type.Equals("help"))
            {
                adminIDs = a.helpIDs;
                newsName.Text = "添加文章";
                PostTitle.Text = "添加文章";
            }

            //Response.Write(adminIDs);

            c.bindingDropDownList(adminIDs, true, 0, type, DropDownListClass);

            Session.Add("upFileID", xabara.rnd("name", 5).ToUpper());//上传图片文件名ID关联"
            pDate.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            Session.Add("upPreFile", string.Empty); //预览图初始值

            regExpression reg = new regExpression();
            titleRegExpress.ValidationExpression = reg.CHAR(1, 100);
            titleRegExpress.ErrorMessage = reg.charError(1, 100);
            dateRegExpree.ValidationExpression = reg.dateTime;
            dateRegExpree.ErrorMessage = reg.dateTimeError;
            RegHttp.ValidationExpression = reg.urlHttp;
            RegHttp.ErrorMessage = reg.urlHttpError;
        }
    }

    protected void PostNews_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(myEditor.Text as string))
        {
            string strTitle = newsTitle.Text.Trim();
            string upFileIDsession = Session["upFileID"].ToString();//上传图片文件名ID关联"
            if (string.IsNullOrEmpty(upFileIDsession as string))
            {
                upFileIDsession = xabara.rnd("name", 5);
            }

            string strSql = "select * from NewsXabara where NewTitle='" + strTitle + "' and treeTid=" + DropDownListClass.Text;
            DataTable dt = sql.getDataTable(strSql);
            if (dt.Rows.Count > 0)
            {
                js.div(false, "", "text", "该篇文章已存在！", 350, 0, "", "");
            }
            else
            {
                string dimStr = "@treeTid,@upPreImg,@NewTitle,@upNameID,@NewContent,@ReadNums,@PostDate,@TopDate,@adminPass,@AdminIP,@AdminID,@keyWord,@titleFontB,@titleFontC,@NewsAuthor,@linkHttp,@newsFrom";

                string[] strValue = new string[20];
                strValue[0] = DropDownListClass.Text;

                string preImg = Session["upPreFile"].ToString();
                strValue[1] = preImg;                
                strValue[2] = strTitle;
                strValue[3] = upFileIDsession;
                strValue[4] = f.emotImg(upFileIDsession, myEditor.Text, false);
                strValue[5] = "0";
                strValue[6] = pDate.Text;
                strValue[7] = pDate.Text;
                strValue[8] = a.postIF.ToString();
                strValue[9] = new ipAddress().address();
                strValue[10] = a.uid;
                strValue[11] = newsKeyWords.Text.Trim();
                if (checkBold.Checked)
                    strValue[12] = "1";
                else
                    strValue[12] = "0";
                strValue[13] = colorList.Text.Trim();
                strValue[14] = newAuthor.Text.Trim();
                strValue[15] = newsHttp.Text.Trim();
                strValue[16] = fromWhere.Text.Trim();

                sql.log(a.uid, "admin", "发布：" + strTitle);

                string returnStr = sql.add("NewsXabara", dimStr, strValue);
                Session.Add("upFileID", string.Empty); //ID关联清空
                Session.Add("upPreFile", string.Empty); //预览图文件名清空
                Response.Redirect("?ifPass=" + a.postIF.ToString() + "&cType=" + xabara.safeSql(Request.QueryString["cType"]), true);
            }
            dt.Dispose();
        }
        else
        {
            js.div(false, "", "text", "内容不能为空！", 300, 0, "", "");
        }
    }

    protected void preTitle_Click(object sender, EventArgs e)
    {
        string title = newsTitle.Text.Trim();
        preTitleLable.Text = title;

        if (!string.IsNullOrEmpty(title as string))
        {
            if (checkBold.Checked)
            {
                preTitleLable.Text = "<strong>" + title + "</strong>";
            }

            if (!string.IsNullOrEmpty(colorList.Text as string))
            {
                preTitleLable.Text = "<font color='" + colorList.Text.Trim() + "'>" + preTitleLable.Text + "</font>";
            }
        }
        else
        {
            preTitleLable.Text = "<font color='red'>请输入标题内容后再预览效果</font>";
        }
    }
}