using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web.UI.WebControls; namespace FineUIPro.Web.CQMS.QuantityManagement { public partial class WorkTeamStatistics : PageBase { #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetButtonPower(); BindGrid(); } } /// /// 数据绑定 /// public void BindGrid() { string strSql = @"select BaseId,C.ProjectId,a.WorkSection,DrawingNo,DrawingName,Part,ProjectContent,Unit,Amount,WorkTeam, isnull((select sum(DayAmount) from QuantityManagement_DayInput d where d.BaseId=C.BaseId),0) as TotalComplete, Amount-isnull((select sum(DayAmount) from QuantityManagement_DayInput d where d.BaseId=C.BaseId),0) as Remain from QuantityManagement_Base C left join QuantityManagement_Drawing a on a.DrawingId=C.DrawingId where C.ProjectId = @ProjectId"; List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); if (!string.IsNullOrEmpty(this.txtWorkSection.Text.Trim())) { strSql += " AND WorkSection like @WorkSection"; listStr.Add(new SqlParameter("@WorkSection", "%" + this.txtWorkSection.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtDrawingNo.Text.Trim())) { strSql += " AND DrawingNo like @DrawingNo"; listStr.Add(new SqlParameter("@DrawingNo", "%" + this.txtDrawingNo.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtWorkTeam.Text.Trim())) { strSql += " AND WorkTeam like @WorkTeam"; listStr.Add(new SqlParameter("@WorkTeam", "%" + this.txtWorkTeam.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(); //绑定数据 DateTime startDate, endDate, startDate1, endDate1; List days = new List(); int year = DateTime.Now.Year; int month = DateTime.Now.Month; int day = DateTime.Now.Day; if (day >= 26) { startDate = Convert.ToDateTime(DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + "26"); startDate1 = startDate; endDate = DateTime.Now; endDate1 = endDate; } else { DateTime lastMonth = DateTime.Now.AddMonths(-1); startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26"); startDate1 = startDate; endDate = DateTime.Now; endDate1 = endDate; } var dayInputs = from x in Funs.DB.QuantityManagement_DayInput where x.ProjectId == this.CurrUser.LoginProjectId && x.Date >= startDate && x.Date <= endDate orderby x.Date select x; do { days.Add(startDate1); startDate1 = startDate1.AddDays(1); } while (startDate1 <= endDate1); for (int i = 0; i < this.Grid1.Rows.Count; i++) { string baseId = this.Grid1.Rows[i].RowID; int j = 0; decimal monthComplete = 0; foreach (var d in days) { var dayInput = dayInputs.FirstOrDefault(x => x.BaseId == baseId && x.Date == d); if (dayInput != null) { monthComplete += dayInput.DayAmount.Value; } j++; } this.Grid1.Rows[i].Values[11] = monthComplete.ToString("0.##"); } } #endregion #region 分页、排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 查询 /// /// 查询 /// /// /// protected void btnSearch_Click(object sender, EventArgs e) { BindGrid(); } #endregion #region 关闭弹出窗口 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #endregion /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { } #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.DayInputMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnAdd)) { } if (buttonList.Contains(BLL.Const.BtnModify)) { this.Grid1.EnableRowDoubleClickEvent = true; } else { this.Grid1.EnableRowDoubleClickEvent = false; } //if (buttonList.Contains(BLL.Const.BtnSave)) //{ // this.btnImport.Hidden = false; //} } } #endregion } }