using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.OleDb;
using System.Data;


public partial class list : System.Web.UI.Page
{
    public string StrClassId = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        #region 实验室管理制度
        DataTable dt_gzzd = FrontFunc.GetDataByClassID("4", "307", "");
        foreach (DataRow dr in dt_gzzd.Rows)
        {
            lit_sysglzd.Text += "<li><span class='new_icon1'></span><a href='sysglzd_show.aspx?gid=" + dr["ID"] + "' title='" + dr["Title"] + "'>" + FrontFunc.Cutstring(dr["Title"].ToString(), 13) + "</a></li>";
        }
        #endregion

        #region 校外实习基地  友情链接
        DataTable dt_link1 = FrontFunc.GetLinks("5", "校外实习基地");
        DataTable dt_link2 = FrontFunc.GetLinks("6", "友情链接");

        foreach (DataRow dr in dt_link1.Rows)
        {
            lit_xwsxjd.Text += "<li><a href='" + dr["LinkPath"] + "' title='" + dr["Title"] + "'>" + FrontFunc.Cutstring(dr["Title"].ToString(), 10) + "</a></li>";
        }

        foreach (DataRow dr in dt_link2.Rows)
        {
            lit_link2.Text += "<li><span class='new_icon1'></span><a href='" + dr["LinkPath"] + "' title='" + dr["Title"] + "'>" + FrontFunc.Cutstring(dr["Title"].ToString(), 10) + "</a></li>";
        }
        #endregion

        if (Request.QueryString["ClassId"] != null && Request.QueryString["ClassId"].ToString() != "")
        {

            string strsql1 = "select * from NT_Class where ID=" + Request.QueryString["ClassId"].ToString();
            DataTable dt_dh1 = DbHelperOleDb.ExecuteDataSet(CommandType.Text, strsql1, null).Tables[0];
            if (dt_dh1 != null && dt_dh1.Rows.Count > 0)
            {
                if (dt_dh1.Rows[0]["CreateClassId"].ToString() == "0")
                {
                    StrClassId = dt_dh1.Rows[0]["ID"].ToString();
                }
                else
                {
                    string strsql2 = "select * from NT_Class where ID=" + dt_dh1.Rows[0]["CreateClassId"].ToString();
                    DataTable dt_dh2 = DbHelperOleDb.ExecuteDataSet(CommandType.Text, strsql2, null).Tables[0];
                    if (dt_dh2 != null && dt_dh2.Rows.Count > 0)
                    {
                        if (dt_dh2.Rows[0]["CreateClassId"].ToString() == "0")
                        {
                            StrClassId = dt_dh2.Rows[0]["ID"].ToString();
                        }
                        else
                        {
                            string strsql3 = "select * from NT_Class where ID=" + dt_dh2.Rows[0]["CreateClassId"].ToString();
                            DataTable dt_dh3 = DbHelperOleDb.ExecuteDataSet(CommandType.Text, strsql3, null).Tables[0];
                            if (dt_dh3 != null && dt_dh3.Rows.Count > 0)
                            {
                                if (dt_dh3.Rows[0]["CreateClassId"].ToString() == "0")
                                {
                                    StrClassId = dt_dh3.Rows[0]["ID"].ToString();
                                }

                            }
                        }
                    }
                }
            }

            string sql = "select * from NT_Class where ID=" + Request.QueryString["ClassId"].ToString();
            DataTable dt = DbHelperOleDb.ExecuteDataSet(CommandType.Text, sql, null).Tables[0];
            if (dt != null && dt.Rows.Count > 0)
            {
                lit_sy.Text += "<span class='right green'><a href='index.aspx'>首页</a> > ";
                lit_sy.Text += "<a href='list.aspx?ClassId=" + Request.QueryString["ClassId"].ToString() + "'>" + dt.Rows[0]["ClassName"] + "</a></span>";
                lit_sy.Text += "<div class='ht f16 bold'>" + dt.Rows[0]["ClassName"] + "</div>";
            }

            BindData();
        }
    }

    private void BindData()
    {
        if (Request.QueryString["ClassId"] != null && Request.QueryString["ClassId"].ToString() != "")
        {
            string sql_CountFirst = string.Empty;
            sql_CountFirst += " select";
            sql_CountFirst += " count(*)";
            sql_CountFirst += " from NT_Data ";
            sql_CountFirst += "where ClassId=" + Request.QueryString["ClassId"].ToString() + "";

            string sql = "select * from NT_Data where ClassId=" + Request.QueryString["ClassId"].ToString() + " order by ID asc";
            DataTable dt = WebControlsFunc.GetDataTableByAspNetPager(AspNetPager1, sql_CountFirst, sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    lit_sysb.Text += "<dl class='yqsb clear'><dt><img src='" + dr["TitlePicture"] + "' /></dt>";
                    lit_sysb.Text += "<dd><div class='top f14 bold'>" + dr["Title"] + "</div>";
                    lit_sysb.Text += "<div class='cen'>" + FrontFunc.Cutstring(dr["Content"].ToString(), 105) + "</div>";
                    lit_sysb.Text += "<p class='right'><input class='more_input1' onclick=\"window.location.href='show.aspx?nid=" + dr["ID"].ToString() + "'\" type='button' name='button' id='button' value='查看详情'></p>";
                    lit_sysb.Text += "</dd></dl>";
                }
            }
        }


    }

    #region 分页事件
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        BindData();
    }
    #endregion

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (this.txt_Account.Text.Trim() == "" || this.txt_Pwd.Text.Trim() == "")
        {
            JavaScriptFunc.Alert(this.Page, "用户名和密码不能为空");
        }
        else
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select * from NT_Member ");
            sb.Append(" where Account=@Account and Password=@Password");
            OleDbParameter[] parameters = { new OleDbParameter("@Account", OleDbType.VarChar), new OleDbParameter("@Password", OleDbType.VarChar) };
            parameters[0].Value = StringFunc.DataFilter(txt_Account.Text.Trim());
            parameters[1].Value = StringFunc.DataFilter(PageFunc.GetMd5(txt_Pwd.Text.Trim()));

            OleDbDataReader odr = DbHelperOleDb.ExecuteDataReader(CommandType.Text, sb.ToString(), parameters);

            if (odr.HasRows)
            {
                while (odr.Read())
                {
                    Session["Account1"] = odr["Account"];
                    Session["Name1"] = odr["Name"];
                    Session["ID1"] = odr["ID"];
                }
            }
            else
            {
                JavaScriptFunc.Alert(this.Page, "用户名和密码不正确");
            }
        }
    }

}
