using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
namespace FineUIPro.Web.Personal
{
public partial class BusinessTrip : PageBase
{
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Funs.DropDownPageSize(this.ddlPageSize);
if (this.CurrUser != null && this.CurrUser.PageSize.HasValue)
{
Grid1.PageSize = this.CurrUser.PageSize.Value;
}
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
this.BindGrid();
////权限按钮方法
this.GetButtonPower();
}
}
///
/// 绑定数据
///
private void BindGrid()
{
string strSql = @"SELECT trip.BusinessTripId,trip.ProjectId,trip.UserId,trip.ArriveDate,trip.LeaveDate,Users.UserName,Project.ProjectName,case trip.Type when '1' then '项目出差' when '2' then '其他出差' else '' end AS TypeStr,case when trip.ArriveDate is not null and trip.LeaveDate is not null then cast(DATEDIFF(day,trip.ArriveDate,trip.LeaveDate)+1 as nvarchar(10)) else '' end AS Days "
+ @" From dbo.Person_BusinessTrip AS trip"
+ @" LEFT JOIN Sys_User AS Users ON Users.UserId=trip.UserId"
+ @" LEFT JOIN Base_Project AS Project ON Project.ProjectId=trip.ProjectId"
+ @" WHERE 1=1";
List listStr = new List();
if (this.rblType.SelectedValue != "0")
{
strSql += " AND trip.Type = @Type";
listStr.Add(new SqlParameter("@Type", this.rblType.SelectedValue));
}
if (this.CurrUser.UserId != BLL.Const.sysglyId && this.CurrUser.UserId != BLL.Const.hfnbdId)
{
strSql += " AND trip.UserId = @UserId";
listStr.Add(new SqlParameter("@UserId", this.CurrUser.UserId));
}
if (!string.IsNullOrEmpty(this.txtUserName.Text.Trim()))
{
strSql += " AND UserName LIKE @UserName";
listStr.Add(new SqlParameter("@UserName", "%" + this.txtUserName.Text.Trim() + "%"));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
if (this.rblType.SelectedValue == "0" || this.rblType.SelectedValue == "1")
{
this.Grid1.Columns[3].Hidden = false;
}
else
{
this.Grid1.Columns[3].Hidden = true;
}
int days = 0;
foreach (DataRow row in table.Rows)
{
days += Funs.GetNewIntOrZero(row["Days"].ToString());
}
JObject summary = new JObject();
summary.Add("LeaveDate", "合计:");
summary.Add("Days", days);
Grid1.SummaryData = summary;
}
#region 分页
///
/// 分页
///
///
///
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
///
/// 分页显示条数下拉框
///
///
///
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
BindGrid();
}
#endregion
#region 删除数据
///
/// 批量删除数据
///
///
///
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
var trip = Person_BusinessTripService.GetPersonBusinessTripById(rowID);
if (trip != null)
{
BLL.Person_BusinessTripService.DeletePersonBusinessTrip(rowID);
}
}
BindGrid();
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
}
else
{
ShowNotify("请至少选中一行!", MessageBoxIcon.Warning);
}
}
#endregion
protected void btnNew_Click(object sender, EventArgs e)
{
var noEndTrip = (from x in Funs.DB.Person_BusinessTrip where x.UserId == this.CurrUser.UserId && (x.ArriveDate == null || x.LeaveDate == null) select x).FirstOrDefault();
if (noEndTrip != null)
{
ShowNotify("尚有一条记录到达/离开日期为空,请先完善信息后再新增出差记录!", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("BusinessTripEdit.aspx", "编辑 - ")));
}
#region 编辑
///
/// 编辑
///
///
///
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInParent("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string Id = Grid1.SelectedRowID;
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("BusinessTripEdit.aspx?BusinessTripId={0}", Id, "编辑 - ")));
}
///
/// Grid行双击事件
///
///
///
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
btnMenuEdit_Click(null, null);
}
#endregion
#region 查询
///
/// 查询
///
///
///
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#endregion
#region 获取按钮权限
///
/// 获取按钮权限
///
///
///
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.BusinessTripMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
this.btnNew.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnModify))
{
this.btnMenuEdit.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnMenuDelete.Hidden = false;
}
}
}
#endregion
protected void Window1_Close(object sender, EventArgs e)
{
BindGrid();
}
protected void rblType_SelectedIndexChanged(object sender, EventArgs e)
{
BindGrid();
}
#region 导出按钮
/// 导出按钮
///
///
///
protected void btnOut_Click(object sender, EventArgs e)
{
}
#endregion
}
}