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

public partial class admin_art_so_au_edit : BasePage
{
  
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //实例化公共操作类
            public_select ps = new public_select();
            //作者信息绑定
            DataView dv = ps.Getps("Fm_author","*","");
            List_author.DataSource = dv;
            List_author.DataTextField = "au_name";
            List_author.DataValueField = "au_id";
            List_author.DataBind();
            //来源信息绑定
            DataView dv1 = ps.Getps("Fm_source","*","");
            List_source.DataSource = dv1;
            List_source.DataTextField = "so_name";
            List_source.DataValueField = "so_id";
            List_source.DataBind();
        }
    }
    //作者循环生成添加文本框
    protected void Button2_ServerClick(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        DataColumn dc = new DataColumn();
        dc.ColumnName = "dc1";
        dt.Columns.Add(dc);
        dc.DataType = DbType.Int16.GetType();
        int rows = 0;
        try
        {
            rows = int.Parse(TextBox1.Text.Trim());
        }
        catch
        { }
        for (int i = 1; i <= rows; i++)
        {
            DataRow dr = dt.NewRow();
            dr["dc1"] = i;
            dt.Rows.Add(dr);
        }
        Repeater1.DataSource = dt;
        Repeater1.DataBind();
    }
    //来源循环添加文本框
    protected void Button5_ServerClick(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        DataColumn dc = new DataColumn();
        dc.ColumnName = "dc1";
        dt.Columns.Add(dc);
        dc.DataType = DbType.Int16.GetType();
        int rows = 0;
        try
        {
            rows = int.Parse(TextBox2.Text.Trim());
        }
        catch
        { }
        for (int i = 1; i <= rows; i++)
        {
            DataRow dr = dt.NewRow();
            dr["dc1"] = i;
            dt.Rows.Add(dr);
        }
        Repeater2.DataSource = dt;
        Repeater2.DataBind();
    }
    //保存新的数据
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        //实例化公共操作类
        public_select ps = new public_select();
        //保存作者新数据
        foreach(RepeaterItem dr in Repeater1.Items)
        {
            //寻找TextBox控件
            TextBox txt = dr.FindControl("txt_auname") as TextBox;
            if(txt.Text!="")
            {
                 ps.Queryps("insert into Fm_author values('" +txt.Text+ "')");
            }
        }
        //保存来源新数据
        foreach (RepeaterItem row in Repeater2.Items)
        {
            //寻找TextBox控件
            TextBox txt1 = row.FindControl("txt_soname") as TextBox;
            if (txt1.Text != "")
            {
                ps.Queryps("insert into Fm_source values('"+txt1.Text+"')");
            }
        }
        Response.Redirect("Erro.aspx?eid=新纪录保存成功!&url=art_so_au_edit.aspx", true);
    }
    //作者信息删除
    protected void Button1_Click(object sender, EventArgs e)
    {
        //实例化公共操作类
        public_select ps = new public_select();
        foreach(ListItem row in List_author.Items)
        {
            if(row.Selected==true)
            {
                ps.Queryps("delete from Fm_author where au_id="+int.Parse(row.Value)+"");
            }
        }
        Response.Redirect("Erro.aspx?eid=作者信息删除成功!&url=art_so_au_edit.aspx", true);
    }
    //来源信息删除
    protected void Button3_Click(object sender, EventArgs e)
    {
        //实例化公共操作类
        public_select ps = new public_select();
        foreach (ListItem row in List_source.Items)
        {
            if (row.Selected == true)
            {
                ps.Queryps("delete from Fm_source where so_id=" + int.Parse(row.Value) + "");
            }
        }
        Response.Redirect("Erro.aspx?eid=来源信息删除成功!&url=art_so_au_edit.aspx", true);
    }
}
