using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


public partial class admin_News_AddNews :BasePage
{
    public EasyAccess AccessHelper = new EasyAccess();
    protected void Page_Load(object sender, EventArgs e)
    {
       if (!IsPostBack)
       {
           NewsInfo();
           
       }
    }
    public void NewsInfo()
    {
        string sql = "select * from news where id=" + Request.QueryString["nid"].ToInt32() + "";
        DataSet ds = AccessHelper.ExecuteDataSet(sql);
        if (ds != null)
        {
            TextBox1.Text = ds.Tables[0].Rows[0]["n_title"].ToString();
            TextBox2.Text = ds.Tables[0].Rows[0]["n_User"].ToString();
            FCKeditor1.Value = ds.Tables[0].Rows[0]["n_content"].ToString();
           TextBox3.Text= ds.Tables[0].Rows[0]["n_date"].ToString().ToDateTime().ToShortDateString();
           DropDownList1.SelectedValue = ds.Tables[0].Rows[0]["tid"].ToString();
            ddllist();
           string childid = ds.Tables[0].Rows[0]["childtype"].ToString();
            if (!childid.IsNull())
            {
                DropDownList2.SelectedValue = childid;
            }
           

        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue == "0")
        {
            JWindow.ShowDialog("请选择信息分类.");
            return;
        }
        string sql = "update news set n_title='"+TextBox1.Text+"',n_user='"+TextBox2.Text+"',n_content='"+FCKeditor1.Value+"',n_date='"+TextBox3.Text+"',tid='"+DropDownList1.SelectedValue+"',ischild='0' where id=" + Request.QueryString["nid"].ToInt32() + "";
      if (DropDownList2.Visible)
      {
          if (DropDownList2.SelectedValue == "0")
          {
              JWindow.ShowDialog("请选择信息子分类.");
              return;
          }
           sql = "update news set n_title='" + TextBox1.Text + "',n_user='" + TextBox2.Text + "',n_content='" + FCKeditor1.Value + "',n_date='" + TextBox3.Text + "',tid='" + DropDownList1.SelectedValue + "',childtype='"+DropDownList2.SelectedValue+"',ischild='1' where id=" + Request.QueryString["nid"].ToInt32() + "";

      }
        bool IsOK = AccessHelper.ExecuteNonQuery(sql);
        if (IsOK)
        {
            JWindow.ShowDialog("信息更新成功！");
        }
        else{
            JWindow.ShowDialog("信息更新失败！");
        }
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddllist();
    }
    private void ddllist()
    {
       string tid = DropDownList1.SelectedValue.ToString();
        switch (tid)
        {
            case "10102813384223"://文件下载
                DropDownList2.Visible = true; DropDownList2.Items.Clear();
                DropDownList2.Items.Insert(0, new ListItem("==请选择==", "0"));
                DropDownList2.Items.Insert(1, new ListItem("招标文件", "1"));
                DropDownList2.Items.Insert(2, new ListItem("资格预审文件", "2"));
                DropDownList2.Items.Insert(3, new ListItem("工程量清单", "3"));
                DropDownList2.Items.Insert(4, new ListItem("补遗书", "4"));
                DropDownList2.Items.Insert(5, new ListItem("图纸", "5"));
                DropDownList2.Items.Insert(6, new ListItem("其他", "6"));
                break;
            case "10102813400000"://公示
                DropDownList2.Visible = true;
                DropDownList2.Items.Clear();
                DropDownList2.Items.Insert(0, new ListItem("==请选择==", "0"));
                DropDownList2.Items.Insert(1, new ListItem("资格预审结果公示", "7"));
                DropDownList2.Items.Insert(2, new ListItem("中标公示", "8"));
                DropDownList2.Items.Insert(3, new ListItem("招标人报价公示", "9"));
                break;
            default:
                DropDownList2.Visible = false;
                break;
        }
    }
}
