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 DayInputStatistics : PageBase { /// /// 加载表头 /// protected void Page_Init(object sender, EventArgs e) { InitGrid(); } #region 表头 /// /// 表头 /// private void InitGrid() { DateTime startDate, endDate; 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"); endDate = DateTime.Now; } else { DateTime lastMonth = DateTime.Now.AddMonths(-1); startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26"); endDate = DateTime.Now; } do { days.Add(startDate); startDate = startDate.AddDays(1); } while (startDate <= endDate); GroupField gd = Grid1.Columns[11] as GroupField; for (int i = 0; i < days.Count; i++) { RenderField d = new RenderField(); d.ColumnID = string.Format("{0:MM-dd}", days[i]); d.Width = Unit.Pixel(60); d.DataField = "Day" + (i + 1).ToString(); d.FieldType = FieldType.Double; d.HeaderText = string.Format("{0:MM-dd}", days[i]); d.HeaderTextAlign = TextAlign.Center; d.TextAlign = TextAlign.Center; gd.Columns.Add(d); } } #endregion #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.txtDrawingNo.Text.Trim())) { strSql += " AND DrawingNo like @DrawingNo"; listStr.Add(new SqlParameter("@DrawingNo", "%" + this.txtDrawingNo.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtPart.Text.Trim())) { strSql += " AND Part like @Part"; listStr.Add(new SqlParameter("@Part", "%" + this.txtPart.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtProjectContent.Text.Trim())) { strSql += " AND ProjectContent like @ProjectContent"; listStr.Add(new SqlParameter("@ProjectContent", "%" + this.txtProjectContent.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) { this.Grid1.Rows[i].Values[12 + j] = dayInput.DayAmount.Value.ToString("0.##"); monthComplete += dayInput.DayAmount.Value; } j++; } this.Grid1.Rows[i].Values[12+days.Count]= monthComplete.ToString("0.##"); } } #endregion #region 分页、排序 /// /// 分页下拉 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 分页索引事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } /// /// 排序 /// /// /// 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 } }