namespace FineUIPro.Web.InterFace
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.Linq;
    using BLL;
    public partial class InterFaceTask : PageBase
    {
        /// 
        /// 加载页面
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnNew.OnClientClick = Window1.GetShowReference("InterFaceTaskEdit.aspx", "接口任务新增") + "return false;";
                ////权限按钮方法
                this.GetButtonPower();
                ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
                // 绑定表格
                BindGrid();
            }
        }
        /// 
        /// 绑定数据
        /// 
        private void BindGrid()
        {
            Model.InterFaceTask interFaceTask=new Model.InterFaceTask();
            interFaceTask.InterFaceName = txtInterFaceName.Text;
            var q= BLL.InterFaceTaskService.GetInterFaceTaskByModle(interFaceTask);
            Grid1.DataSource = q;
            Grid1.DataBind();
        }
        #region 获取按钮权限
        /// 
        /// 获取按钮权限
        /// 
        /// 
        /// 
        private void GetButtonPower()
        {
            if (this.CurrUser != null)
            {
                var buttonList = BLL.CommonService.GetAllButtonList(string.Empty, this.CurrUser.UserId, BLL.Const.UserMenuId);
                if (buttonList.Count() > 0)
                {
                    if (buttonList.Contains(BLL.Const.BtnModify))
                    {
                        //this.btnEdit.Hidden = false;
                        //this.btnMenuEdit.Hidden = false;
                    }
                }
            }
        }
        #endregion
        #region 分页
        /// 
        /// 分页
        /// 
        /// 
        /// 
        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            BindGrid();
        }
        /// 
        /// 分页显示条数下拉框
        /// 
        /// 
        /// 
        protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
            BindGrid();
        }
        #endregion
        /// 
        /// 排序
        /// 
        /// 
        /// 
        protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
        {
            Grid1.SortDirection = e.SortDirection;
            Grid1.SortField = e.SortField;
            BindGrid();
        }
        /// 
        /// 关闭窗口
        /// 
        /// 
        /// 
        protected void Window1_Close(object sender, EventArgs e)
        {
            BindGrid();
        }
        /// 
        /// 选择行事件
        /// 
        /// 
        /// 
        protected void btnSelectRows_Click(object sender, EventArgs e)
        {
        }
        /// 
        /// 编辑
        /// 
        /// 
        /// 
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            this.EditData();
        }
        /// 
        /// Grid行双击事件
        /// 
        /// 
        /// 
        protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
        {
            this.EditData();
        }
        /// 
        /// 右键编辑事件
        /// 
        /// 
        /// 
        protected void btnMenuEdit_Click(object sender, EventArgs e)
        {
            this.EditData();
        }
        /// 
        /// 编辑数据方法
        /// 
        private void EditData()
        {
            if (Grid1.SelectedRowIndexArray.Length == 0)
            {
                Alert.ShowInParent("请至少选择一条记录!", MessageBoxIcon.Warning);
                return;
            }
            string Id = Grid1.SelectedRowID;
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("InterFaceTaskEdit.aspx?InterFaceTaskId={0}", Id, "编辑 - ")));
        }
        #region 判断是否可删除
        /// 
        /// 判断是否可以删除
        /// 
        /// 
        private bool judgementDelete(string id, bool isShow)
        {
            return false;
        }
        //private bool judgementDelete(string id, bool isShow)
        //{
        //    string content = string.Empty;
        //    if (Funs.DB.Law_LawRegulationList.FirstOrDefault(x => x.CompileMan == id) != null)
        //    {
        //        content = "该用户已在【法律法规】中使用,不能删除!";
        //    }
        //    if (Funs.DB.Law_HSSEStandardsList.FirstOrDefault(x => x.CompileMan == id) != null)
        //    {
        //        content = "该用户已在【标准规范】中使用,不能删除!";
        //    }
        //    if (Funs.DB.Edu_Online_Examinee.FirstOrDefault(x => x.UserId == id) != null)
        //    {
        //        content = "该用户已在【考生信息】中使用,不能删除!";
        //    }
        //    if (string.IsNullOrEmpty(content))
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        if (isShow)
        //        {
        //            Alert.ShowInTop(content);
        //        }
        //        return false;
        //    }
        //}
        #endregion
        protected void btnStart_Click(object sender, EventArgs e)
        {
            var Id = Grid1.SelectedRowID;
            BLL.InterFaceTaskService.ExecuteTasks(Id);
        }
        #region 查询
        /// 
        /// 用户类别选择
        /// 
        /// 
        /// 
        protected void cbRoleCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.BindGrid();
        }
        /// 
        /// 查询
        /// 
        /// 
        /// 
        protected void TextBox_TextChanged(object sender, EventArgs e)
        {
            this.BindGrid();
        }
        #endregion
    }
}