using System;
using System.Text;
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;
using System.Xml.Linq;
using Winson.EntityOP;
using Winson.EntityOP.Entity;
using Winson.Framework.Utility;

public partial class Data_delete : System.Web.UI.Page
{
    Test test;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!String.IsNullOrEmpty(Request["Action"]))
            {
                switch (Request["Action"].Trim().ToLower())
                {
                    case "delete":
                        Delete();
                        break;
                    case "deletebatch":
                        DeleteBatch();
                        break;
                }
            }
        }
    }

    private void Delete()
    {
        try
        {
            test = new Test();
            test.Entity.Id = String.IsNullOrEmpty(Request["TestId"]) ? 1 : Convert.ToInt32(Request["TestId"]);

            if (test.Delete() > 0)
                ReturnResult("1");
            else
                ReturnResult("0");
        }
        catch (Exception e)
        {
            ReturnResult("0");
        }
    }

    private void DeleteBatch()
    {
        try
        {
            test = new Test();
            string[] id = String.IsNullOrEmpty(Request["TestId"]) ? null : Request["TestId"].Split(',');

            for (int i = 0; i < id.Length; i++)
            {
                test.Entity.Id = Convert.ToInt32(id[i]);
                //上面的第一次不用创建，从第二个实体开始就需要创建新实体了
                test.AppendEntity();
                test.CreateEntity();
            }
            if (test.DeleteBatch())
                ReturnResult("1");
            else
                ReturnResult("0");
        }
        catch (Exception e)//51=a=s=p=x
        {
            ReturnResult("0");
        }
    }


    private void ReturnResult(string str)
    {
        Response.Write(str);
        Response.End();
    }
}
