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 nspEmail.Lables;
using nspEmail;

public partial class Admin_Email_EmailTemplateList : Base.BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CheckRights("Basic", "D1");
            //  Bind(); 
            string strUrlTo = Request.RawUrl;
            strUrlTo = strUrlTo.Substring(0, strUrlTo.IndexOf(".aspx")) + ".aspx";
            PageNo1.Strurl = strUrlTo;
            PageNo1.PageSize = 12;
            PageNo1.Table = "W_EmailTemplate";
            PageNo1.FldName = "ID";
            PageNo1.StrGetFields = "*";
            PageNo1.Where = "1=1";
            if (Request.QueryString["page"] != null && Request.QueryString["page"] != "")
            {
                PageNo1.Pageindex = Convert.ToInt32(Request.QueryString["page"].ToString());
                DataTable dt = PageNo1.BindView();
                if (dt.Rows.Count == 0)
                {
                    lblMessage.Visible = true;
                    lblMessage.Text = "暂无数据！";
                }
                else
                    lblMessage.Visible = false;
                dlstEmailTemplate.DataSource = dt.DefaultView;
                dlstEmailTemplate.DataBind();
            }
            else
            {
                DataTable dt = PageNo1.BindView();
                PageNo1.Pageindex = 1;
                dlstEmailTemplate.DataSource = dt.DefaultView;
                dlstEmailTemplate.DataBind();
            }
        }
    }
    protected void dlstEmailTemplate_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        int id = int.Parse(dlstEmailTemplate.DataKeys[e.Item.ItemIndex].ToString());
        EmailTemplate email = new EmailTemplate();
        email.Delete(id);
        string strUrlTo = Request.RawUrl;
        strUrlTo = strUrlTo.Substring(0, strUrlTo.IndexOf(".aspx")) + ".aspx";
        Response.Redirect(strUrlTo + "?page=1");
        Response.End();
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < dlstEmailTemplate.Items.Count; i++)
        {
            CheckBox cbox = (CheckBox)dlstEmailTemplate.Items[i].FindControl("CheckBox1");
            if (cbox.Checked == true)
            {
                int id = int.Parse(dlstEmailTemplate.DataKeys[i].ToString());
                EmailTemplate email = new EmailTemplate();
                email.Delete(id);
            }

        }
        string strUrlTo = Request.RawUrl;
        strUrlTo = strUrlTo.Substring(0, strUrlTo.IndexOf(".aspx")) + ".aspx";
        Response.Redirect(strUrlTo + "?page=1");
        Response.End();
    }
}
