using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using JY.Model;
using JY.BLL;
using Maticsoft.DBUtility;

public partial class OrderForm_Manage : PasePage
{
    JY.BLL.OrderForm bll = new JY.BLL.OrderForm();
    JY.Model.PageEntity model = new JY.Model.PageEntity();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    private int GetInt(object obj, int defaultValue)
    {
        if (obj != null)
        {
            try
            {
                defaultValue = Convert.ToInt32(obj);
            }
            catch
            {
            }
        }
        return defaultValue;
    }

    /// <summary>
    /// 获取列表数据
    /// </summary>
    private void BindData()
    {
        int pageIndex = GetInt(Request.QueryString["Page"], 1);
        Pagination.Pagination _page = new Pagination.Pagination();

        _page.ItemUnit = "个号码";
        _page.ImagesPath = "~/Images/ui_form/";
        _page.Sequence = pageIndex;
        _page.PageSize = pager.PageSize;
        _page.TableName = "  OrderForm ";
        _page.SearchField = " * ";

        _page.SearchSentence = " and OrderForm.Isdelete=0 ";

        if (Request.QueryString["keyWord"] != null && Request.QueryString["keyWord"] != "")
        {
            _page.SearchSentence += " and (OrderFormId like '%" + Server.UrlDecode(Request.QueryString["keyWord"]) + "%' or Purchaser  like '%" + Server.UrlDecode(Request.QueryString["keyWord"]) + "%') ";
            txtKeyword.Text = Server.UrlDecode(Request.QueryString["keyWord"]);
        }

        _page.SortSentence = " Order By OrderForm.Id desc ";
        _page.Primarykey = " OrderForm.Id ";
        DataTable dt = _page.GetDataTable();

        rptOrderForm.DataSource = dt;
        rptOrderForm.DataBind();

        pager.RecordCount = _page.RecordCount;
        //显示记录信息   [ 共1508条 第1页 共151页 ]
        pager.CustomInfoHTML = "<span>共有&nbsp;<b>" + pager.RecordCount.ToString() + "</b>&nbsp;条记录，";
        pager.CustomInfoHTML += " 当前第&nbsp;<font color=\"red\"><b>" + pageIndex.ToString() + "</b></font>&nbsp;页，";
        pager.CustomInfoHTML += " 共&nbsp;<b>" + pager.PageCount.ToString() + "</b>&nbsp;页</span>";

    }

    /// <summary>
    /// 查询
    /// </summary>
    protected void btnquery_Click(object sender, EventArgs e)
    {
        string strUrl = "OrderForm_Manage.aspx?1=1";

        if (txtKeyword.Text.Trim() != "")
        {
            strUrl += "&keyWord=" + Server.UrlEncode(txtKeyword.Text.Trim());
        }
        Response.Redirect(strUrl);
    }

    /// <summary>
    /// 触发活动表的ItemCommand事件
    /// </summary>
    protected void rptOrderForm_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "Del")
            {
                JY.BLL.OrderForm bll = new JY.BLL.OrderForm();
                JY.Model.OrderForm model = bll.GetModel(Convert.ToInt32(e.CommandArgument.ToString()));
                model.IsDelete = true;

                bll.Update(model);
            }
            this.BindData();
        }
        catch (Exception er)
        {
            publicHandle.ShowMessage(this, er.Message);
        }
    }
    
    /// <summary>
    /// 批量删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btndel_Click(object sender, EventArgs e)
    {
        try
        {
            if (hidBatchDelId.Value.Trim() != "")
            {
                if (bll.DeleteList(hidBatchDelId.Value))
                {
                    //Response.Write("<script type='text/javascript'>alert('批量删除成功！')</script>");
                    //BindDate();
                    string strUrl = "OrderForm_Manage.aspx";
                    if (Session["urlLink"] != null)
                    {
                        strUrl = Session["urlLink"].ToString();
                        Session["urlLink"] = null;
                    }
                    publicHandle.ShowMessage(this.Page, "批量删除成功", strUrl);
                }
                else
                {
                    publicHandle.ShowMessage(this.Page, "批量删除失败！");
                }
            }
        }
        catch (Exception ex)
        {
            publicHandle.ShowMessage(this, ex.Message);
        }
    }
}
