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 AjaxPro;
using System.Data.OleDb;
public partial class admini_ArticleLB : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!CheckLogin()) return;
        Utility.RegisterTypeForAjax(typeof(admini_ArticleLB));
    }

    [AjaxMethod]
 
    public ArrayList getData(int cNum, int RowShowNum)
    {
        string sql = "";
        int _page = (cNum - 1) * RowShowNum;
        if (cNum == 1)
            sql =string.Format( "SELECT TOP {0} * FROM ARTICLE ORDER BY ID DESC ",RowShowNum);
        else
            sql = string.Format("SELECT TOP {0} * FROM ARTICLE  WHERE ID NOT IN (SELECT TOP {1} ID FROM ARTICLE ORDER BY ID DESC) ORDER BY ID DESC", RowShowNum, _page);
        ArrayList al = new ArrayList();
        try
        {
            
            int count = (int)SqlHelper.GetSingle("select count(id) from article");
            OleDbDataReader dr = SqlHelper.ExecuteReader(sql);
            while (dr.Read())
            {
                ArrayList list = new ArrayList();
                list.Add(dr["id"]);
               
                string ut = dr["arttitle"].ToString();
                if (WebClass.GetBytesLength(ut) > 25)
                    ut = WebClass.CutString(ut, 25);
                list.Add(ut);
                list.Add(dr["artauthor"]);
             
               

                string t = dr["arttext"].ToString();
                if (WebClass.GetBytesLength(t) > 25)
                    t = WebClass.CutString(t, 25);
                list.Add(Server.HtmlEncode(t));
                string artfrom = dr["artfrom"].ToString();
                if (WebClass.GetBytesLength(artfrom) > 15)
                    artfrom = WebClass.CutString(artfrom, 15);
                list.Add(artfrom);
                list.Add(dr["arthit"]);
                list.Add(dr["artstatus"]);
                list.Add((DateTime.Parse(dr["arttime"].ToString())).ToString("yyyy-MM-dd"));
                al.Add(list);//5-1-a-s-p-x
            }
            al.Add(cNum);
            al.Add(count);
            return al;
        }

        catch (Exception ex) 
        {
            al.Add(ex.Message);
            return al;
        }
    }

    [AjaxPro.AjaxMethod]
    public string del(int key)
    {
        string sql = "DELETE FROM ARTICLE WHERE ID = " + key;
        try
        {
            int n = SqlHelper.ExecuteSql(sql);
            if (n > 0)
                return "1";
            else
                return "0";
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
    }
}
