638 lines
		
	
	
		
			28 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			638 lines
		
	
	
		
			28 KiB
		
	
	
	
		
			C#
		
	
	
	
using System;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.Linq;
 | 
						|
using System.Web;
 | 
						|
using System.Web.UI;
 | 
						|
using System.Web.UI.WebControls;
 | 
						|
using System.Data;
 | 
						|
using System.Data.SqlClient;
 | 
						|
using BLL;
 | 
						|
using Newtonsoft.Json.Linq;
 | 
						|
using System.IO;
 | 
						|
using NPOI.SS.Util;
 | 
						|
using NPOI.SS.Formula.Functions;
 | 
						|
 | 
						|
namespace FineUIPro.Web.JDGL.Check
 | 
						|
{
 | 
						|
    public partial class WeekPlan : PageBase
 | 
						|
    {
 | 
						|
        protected void Page_Load(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            if (!IsPostBack)
 | 
						|
            {
 | 
						|
                GetButtonPower();
 | 
						|
                btnWeekItem.OnClientClick = Window2.GetShowReference("WeekItem.aspx") + "return false;";
 | 
						|
                //btnNew.OnClientClick = Window1.GetShowReference("WeekPlanEdit.aspx") + "return false;";
 | 
						|
                InitDropDownList();
 | 
						|
                //this.drpWeekNo.DataTextField = "Text";
 | 
						|
                //this.drpWeekNo.DataValueField = "Value";
 | 
						|
                //var weekPlans = (from x in Funs.DB.JDGL_WeekPlan where x.ProjectId == this.CurrUser.LoginProjectId orderby x.StartDate descending select x.WeekNo).Distinct().OrderByDescending(x => x).ToList();
 | 
						|
                //if (weekPlans.Count() > 0)
 | 
						|
                //{
 | 
						|
                //    ListItem[] list = new ListItem[weekPlans.Count()];
 | 
						|
                //    for (int i = 0; i < weekPlans.Count(); i++)
 | 
						|
                //    {
 | 
						|
                //        list[i] = new ListItem(weekPlans[i], weekPlans[i]);
 | 
						|
                //    }
 | 
						|
                //    this.drpWeekNo.DataSource = list;
 | 
						|
                //    this.drpWeekNo.DataBind();
 | 
						|
                //    this.drpWeekNo.SelectedValue = list[0].Value;
 | 
						|
                //}
 | 
						|
                //else
 | 
						|
                //{
 | 
						|
                //    this.drpWeekNo.DataSource = null;
 | 
						|
                //    this.drpWeekNo.DataBind();
 | 
						|
                //}
 | 
						|
                BindGrid();
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        ///  初始化下拉框
 | 
						|
        /// </summary>
 | 
						|
        private void InitDropDownList()
 | 
						|
        {
 | 
						|
            WeekItemService.InitWeekItemDropDownList(this.drpWeekNo, this.CurrUser.LoginProjectId, false);
 | 
						|
 | 
						|
            //获取当前时间所在周号,存在默认选中当前时间点所在周,否则选择最后一个周
 | 
						|
            var item = WeekItemService.GetWeekItemByDateNow(this.CurrUser.LoginProjectId);
 | 
						|
            if (item != null)
 | 
						|
            {//存在默认选中当前时间点所在周
 | 
						|
                this.drpWeekNo.SelectedValue = item.WeekNo.ToString();
 | 
						|
                this.txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", item.StartDate);
 | 
						|
                this.txtEndDate.Text = string.Format("{0:yyyy-MM-dd}", item.EndDate);
 | 
						|
            }
 | 
						|
            else
 | 
						|
            {
 | 
						|
                var items = WeekItemService.GetWeekItemList(this.CurrUser.LoginProjectId);
 | 
						|
                if (items.Any())
 | 
						|
                {//否则选择最后一个周
 | 
						|
                    item = items.First();
 | 
						|
                    this.drpWeekNo.SelectedValue = item.WeekNo.ToString();
 | 
						|
                    this.txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", item.StartDate);
 | 
						|
                    this.txtEndDate.Text = string.Format("{0:yyyy-MM-dd}", item.EndDate);
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        #region 获取按钮权限
 | 
						|
        /// <summary>
 | 
						|
        /// 获取按钮权限
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="button"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        private void GetButtonPower()
 | 
						|
        {
 | 
						|
            if (Request.Params["value"] == BLL.Const._Null)
 | 
						|
            {
 | 
						|
                return;
 | 
						|
            }
 | 
						|
            var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.WeekPlanMenuId);
 | 
						|
            if (buttonList.Count() > 0)
 | 
						|
            {
 | 
						|
                if (buttonList.Contains(BLL.Const.BtnSave))
 | 
						|
                {
 | 
						|
                    this.btnWeekItem.Hidden = false;
 | 
						|
                    this.btnNew.Hidden = false;
 | 
						|
                    //this.btnModify.Hidden = false;
 | 
						|
                    //this.btnMenuDel.Hidden = false;
 | 
						|
                    //this.btnMenuDel2.Hidden = false;
 | 
						|
                }
 | 
						|
                if (buttonList.Contains(BLL.Const.BtnModify))
 | 
						|
                {
 | 
						|
                    this.btnModify.Hidden = false;
 | 
						|
                }
 | 
						|
                if (buttonList.Contains(BLL.Const.BtnDelete))
 | 
						|
                {
 | 
						|
                    this.btnMenuDel.Hidden = false;
 | 
						|
                    this.btnMenuDel2.Hidden = false;
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
        #endregion
 | 
						|
 | 
						|
        protected void btnModify_Click(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeekPlanEdit.aspx?WeekNo={0}", this.drpWeekNo.SelectedValue), "编辑 - 周进度计划"));
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 加载Grid
 | 
						|
        /// </summary>
 | 
						|
        private void BindGrid()
 | 
						|
        {
 | 
						|
            //string weekNo2 = string.Empty;
 | 
						|
            string weekNo2 = !string.IsNullOrEmpty(this.drpWeekNo.SelectedValue) ? this.drpWeekNo.SelectedValue : "0";
 | 
						|
            //var weekPlan = Funs.DB.JDGL_WeekPlan.FirstOrDefault(x => x.ProjectId == this.CurrUser.LoginProjectId && x.WeekNo == weekNo2);
 | 
						|
            //if (weekPlan != null)
 | 
						|
            //{
 | 
						|
            //    if (weekPlan.StartDate != null)
 | 
						|
            //    {
 | 
						|
            //        this.txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", weekPlan.StartDate);
 | 
						|
            //    }
 | 
						|
            //    if (weekPlan.EndDate != null)
 | 
						|
            //    {
 | 
						|
            //        this.txtEndDate.Text = string.Format("{0:yyyy-MM-dd}", weekPlan.EndDate);
 | 
						|
            //    }
 | 
						|
            //    //var lastWeekPlan = (from x in Funs.DB.JDGL_WeekPlan where x.ProjectId == this.CurrUser.LoginProjectId && x.StartDate < weekPlan.StartDate orderby x.StartDate descending select x).FirstOrDefault();
 | 
						|
            //    //if (lastWeekPlan != null)
 | 
						|
            //    //{
 | 
						|
            //    //    weekNo2 = lastWeekPlan.WeekNo;
 | 
						|
            //    //}
 | 
						|
            //}
 | 
						|
            //else
 | 
						|
            //{
 | 
						|
            //    this.txtStartDate.Text = string.Empty;
 | 
						|
            //    this.txtEndDate.Text = string.Empty;
 | 
						|
            //}
 | 
						|
 | 
						|
            //本周计划
 | 
						|
            //            string strSql2 = @"select mp.*,u.UnitName,uw.UnitWorkName,cn.ProfessionalName,case mp.IsOK when 1 then '已完成' when 0 then '未完成' else '' end as IsOKStr 
 | 
						|
            //,DutyPersonName = STUFF((SELECT ',' + p.UserName FROM dbo.Sys_User as p where PATINDEX('%,' + RTRIM(p.UserId) + ',%', ',' + mp.DutyPerson + ',') > 0 FOR XML PATH('')), 1, 1,'') 
 | 
						|
            //from [dbo].[JDGL_WeekPlan] mp
 | 
						|
            //left join Base_Unit u on u.UnitId=mp.UnitId
 | 
						|
            //left join WBS_UnitWork uw on uw.UnitWorkId=mp.UnitWork
 | 
						|
            //left join Base_CNProfessional cn on cn.CNProfessionalId=mp.Major
 | 
						|
            //where mp.ProjectId=@ProjectId2 and mp.WeekNo=@WeekNo2 order by mp.SortIndex";
 | 
						|
            //            List<SqlParameter> listStr2 = new List<SqlParameter>();
 | 
						|
            //            listStr2.Add(new SqlParameter("@ProjectId2", this.CurrUser.LoginProjectId));
 | 
						|
 | 
						|
            //            listStr2.Add(new SqlParameter("@WeekNo2", weekNo2));
 | 
						|
            //            SqlParameter[] parameter2 = listStr2.ToArray();
 | 
						|
            //            DataTable tb2 = SQLHelper.GetDataTableRunText(strSql2, parameter2);
 | 
						|
 | 
						|
            //本周计划
 | 
						|
            DataTable tb2 = BindData(this.CurrUser.LoginProjectId, weekNo2);
 | 
						|
            Grid2.RecordCount = tb2.Rows.Count;
 | 
						|
            //tb = GetFilteredTable(Grid2.FilteredData, tb);
 | 
						|
            var table2 = this.GetPagedDataTable(Grid2, tb2);
 | 
						|
            Grid2.DataSource = table2;
 | 
						|
            Grid2.DataBind();
 | 
						|
 | 
						|
            //            //下周计划
 | 
						|
            //            string strSql = @"select mp.*,u.UnitName,uw.UnitWorkName,cn.ProfessionalName,case mp.IsOK when 1 then '已完成' when 0 then '未完成' else '' end as IsOKStr 
 | 
						|
            //,DutyPersonName = STUFF((SELECT ',' + p.UserName FROM dbo.Sys_User as p where PATINDEX('%,' + RTRIM(p.UserId) + ',%', ',' + mp.DutyPerson + ',') > 0 FOR XML PATH('')), 1, 1,'') 
 | 
						|
            //from [dbo].[JDGL_WeekPlan] mp
 | 
						|
            //left join Base_Unit u on u.UnitId=mp.UnitId
 | 
						|
            //left join WBS_UnitWork uw on uw.UnitWorkId=mp.UnitWork
 | 
						|
            //left join Base_CNProfessional cn on cn.CNProfessionalId=mp.Major
 | 
						|
            //where mp.ProjectId=@ProjectId and mp.WeekNo=@WeekNo order by mp.SortIndex";
 | 
						|
            //            List<SqlParameter> listStr = new List<SqlParameter>();
 | 
						|
            //            listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
 | 
						|
            //            string weekNo = string.Empty;
 | 
						|
            //            if (!string.IsNullOrEmpty(this.drpWeekNo.SelectedValue))
 | 
						|
            //            {
 | 
						|
            //                //weekNo = this.drpWeekNo.SelectedValue;
 | 
						|
            //                weekNo = (int.Parse(this.drpWeekNo.SelectedValue) + 1).ToString();
 | 
						|
            //            }
 | 
						|
            //            listStr.Add(new SqlParameter("@WeekNo", weekNo));
 | 
						|
            //            SqlParameter[] parameter = listStr.ToArray();
 | 
						|
            //            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
 | 
						|
 | 
						|
 | 
						|
            string weekNo = string.Empty;
 | 
						|
            if (!string.IsNullOrEmpty(this.drpWeekNo.SelectedValue))
 | 
						|
            {
 | 
						|
                //weekNo = this.drpWeekNo.SelectedValue;
 | 
						|
                weekNo = (int.Parse(this.drpWeekNo.SelectedValue) + 1).ToString();
 | 
						|
            }
 | 
						|
            //下周计划
 | 
						|
            DataTable tb = BindData(this.CurrUser.LoginProjectId, weekNo);
 | 
						|
            Grid1.RecordCount = tb.Rows.Count;
 | 
						|
            //tb = GetFilteredTable(Grid1.FilteredData, tb);
 | 
						|
            var table = this.GetPagedDataTable(Grid1, tb);
 | 
						|
            Grid1.DataSource = table;
 | 
						|
            Grid1.DataBind();
 | 
						|
        }
 | 
						|
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 加载数据
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="projectId"></param>
 | 
						|
        /// <param name="weekNo"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        private DataTable BindData(string projectId, string weekNo)
 | 
						|
        {
 | 
						|
            string strSql = @"select mp.*,u.UnitName,uw.UnitWorkName,cn.ProfessionalName,case mp.IsOK when 1 then '已完成' when 0 then '未完成' else '' end as IsOKStr 
 | 
						|
,DutyPersonName = STUFF((SELECT ',' + p.UserName FROM dbo.Sys_User as p where PATINDEX('%,' + RTRIM(p.UserId) + ',%', ',' + mp.DutyPerson + ',') > 0 FOR XML PATH('')), 1, 1,'') 
 | 
						|
from [dbo].[JDGL_WeekPlan] mp
 | 
						|
left join Base_Unit u on u.UnitId=mp.UnitId
 | 
						|
left join WBS_UnitWork uw on uw.UnitWorkId=mp.UnitWork
 | 
						|
left join Base_CNProfessional cn on cn.CNProfessionalId=mp.Major
 | 
						|
where mp.ProjectId=@ProjectId and mp.WeekNo=@WeekNo order by mp.SortIndex";
 | 
						|
            List<SqlParameter> listStr = new List<SqlParameter>();
 | 
						|
            listStr.Add(new SqlParameter("@ProjectId", projectId));
 | 
						|
            listStr.Add(new SqlParameter("@WeekNo", weekNo));
 | 
						|
            SqlParameter[] parameter = listStr.ToArray();
 | 
						|
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
 | 
						|
            return tb;
 | 
						|
        }
 | 
						|
 | 
						|
        #region  月份选择事件
 | 
						|
        /// <summary>
 | 
						|
        /// 月份选择事件
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        protected void txtWeeks_TextChanged(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            BindGrid();
 | 
						|
        }
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region  保存按钮
 | 
						|
        /// <summary>
 | 
						|
        /// 保存按钮
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        protected void btnSave_Click(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            if (this.Grid1.Rows.Count > 0)
 | 
						|
            {
 | 
						|
                JArray mergedData = Grid1.GetMergedData();
 | 
						|
                foreach (JObject mergedRow in mergedData)
 | 
						|
                {
 | 
						|
                    JObject values = mergedRow.Value<JObject>("values");
 | 
						|
                    int i = mergedRow.Value<int>("index");
 | 
						|
                    Model.JDGL_WeekPlan WeekPlan = BLL.WeekPlanService.GetWeekPlanById(this.Grid1.Rows[i].RowID);
 | 
						|
                    if (WeekPlan != null)
 | 
						|
                    {
 | 
						|
                        WeekPlan.CompileMan = this.CurrUser.UserId;
 | 
						|
                        WeekPlan.CompileDate = DateTime.Now;
 | 
						|
                        BLL.WeekPlanService.UpdateWeekPlan(WeekPlan);
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                Alert.ShowInTop("保存成功!", MessageBoxIcon.Success);
 | 
						|
            }
 | 
						|
            else
 | 
						|
            {
 | 
						|
                Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
 | 
						|
                return;
 | 
						|
            }
 | 
						|
        }
 | 
						|
        #endregion
 | 
						|
 | 
						|
        protected void btnMenuDel_Click(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            if (Grid1.SelectedRowIndexArray.Length > 0)
 | 
						|
            {
 | 
						|
                foreach (int rowIndex in Grid1.SelectedRowIndexArray)
 | 
						|
                {
 | 
						|
                    string rowID = Grid1.DataKeys[rowIndex][0].ToString();
 | 
						|
                    BLL.WeekPlanService.DeleteWeekPlanByWeekPlanId(rowID);
 | 
						|
                }
 | 
						|
                //var weekPlans = (from x in Funs.DB.JDGL_WeekPlan where x.ProjectId == this.CurrUser.LoginProjectId orderby x.StartDate descending select x.WeekNo).Distinct().OrderByDescending(x => x).ToList();
 | 
						|
                //if (weekPlans.Count() > 0)
 | 
						|
                //{
 | 
						|
                //    ListItem[] list = new ListItem[weekPlans.Count()];
 | 
						|
                //    for (int i = 0; i < weekPlans.Count(); i++)
 | 
						|
                //    {
 | 
						|
                //        list[i] = new ListItem(weekPlans[i], weekPlans[i]);
 | 
						|
                //    }
 | 
						|
                //    this.drpWeekNo.DataSource = list;
 | 
						|
                //    this.drpWeekNo.DataBind();
 | 
						|
                //    this.drpWeekNo.SelectedValue = list[0].Value;
 | 
						|
                //}
 | 
						|
                //else
 | 
						|
                //{
 | 
						|
                //    this.drpWeekNo.DataSource = null;
 | 
						|
                //    this.drpWeekNo.DataBind();
 | 
						|
                //}
 | 
						|
                BindGrid();
 | 
						|
                ShowNotify("删除数据成功!", MessageBoxIcon.Success);
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        protected void btnMenuDel2_Click(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            if (Grid2.SelectedRowIndexArray.Length > 0)
 | 
						|
            {
 | 
						|
                foreach (int rowIndex in Grid2.SelectedRowIndexArray)
 | 
						|
                {
 | 
						|
                    string rowID = Grid2.DataKeys[rowIndex][0].ToString();
 | 
						|
                    BLL.WeekPlanService.DeleteWeekPlanByWeekPlanId(rowID);
 | 
						|
                }
 | 
						|
                BindGrid();
 | 
						|
                ShowNotify("删除数据成功!", MessageBoxIcon.Success);
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        #region 导入
 | 
						|
        /// <summary>
 | 
						|
        /// 导入按钮
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        protected void btnImport_Click(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeekPlanIn.aspx?ProjectId={0}", this.CurrUser.LoginProjectId), "导入 - 周进度计划"));
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 关闭导入弹出窗口
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        protected void Window1_Close(object sender, WindowCloseEventArgs e)
 | 
						|
        {
 | 
						|
            InitDropDownList();
 | 
						|
            //var weekPlans = (from x in Funs.DB.JDGL_WeekPlan where x.ProjectId == this.CurrUser.LoginProjectId orderby x.StartDate descending select x.WeekNo).Distinct().OrderByDescending(x => x).ToList();
 | 
						|
            //if (weekPlans.Count() > 0)
 | 
						|
            //{
 | 
						|
            //    ListItem[] list = new ListItem[weekPlans.Count()];
 | 
						|
            //    for (int i = 0; i < weekPlans.Count(); i++)
 | 
						|
            //    {
 | 
						|
            //        list[i] = new ListItem(weekPlans[i], weekPlans[i]);
 | 
						|
            //    }
 | 
						|
            //    this.drpWeekNo.DataSource = list;
 | 
						|
            //    this.drpWeekNo.DataBind();
 | 
						|
            //    this.drpWeekNo.SelectedValue = list[0].Value;
 | 
						|
            //}
 | 
						|
            //else
 | 
						|
            //{
 | 
						|
            //    this.drpWeekNo.DataSource = null;
 | 
						|
            //    this.drpWeekNo.DataBind();
 | 
						|
            //}
 | 
						|
            BindGrid();
 | 
						|
        }
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region 新增
 | 
						|
        /// <summary>
 | 
						|
        /// 新增
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        protected void btnNew_Click(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            string weekNo = this.drpWeekNo.SelectedValue;
 | 
						|
            if (string.IsNullOrWhiteSpace(weekNo))
 | 
						|
            {
 | 
						|
                Alert.ShowInParent("请选择周!若没有周数据,请先自定义新增周!", MessageBoxIcon.Warning);
 | 
						|
                return;
 | 
						|
            }
 | 
						|
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeekPlanEdit.aspx?WeekNo={0}", weekNo), "新增 - 周进度计划"));
 | 
						|
        }
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region 统计
 | 
						|
        /// <summary>
 | 
						|
        /// 统计分析
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        protected void BtnAnalyse_Click(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeekPlanStatisc.aspx"), "统计 - 周进度计划"));
 | 
						|
        }
 | 
						|
        #endregion
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 周号选择触发事件
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        protected void drpWeekNo_SelectedIndexChanged(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            var weekNo = this.drpWeekNo.SelectedValue;
 | 
						|
            var item = BLL.WeekItemService.GetWeekItemByProjectIdAndWeekNo(this.CurrUser.LoginProjectId, int.Parse(weekNo));
 | 
						|
            if (item != null)
 | 
						|
            {
 | 
						|
                this.drpWeekNo.SelectedValue = item.WeekNo.ToString();
 | 
						|
                this.txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", item.StartDate);
 | 
						|
                this.txtEndDate.Text = string.Format("{0:yyyy-MM-dd}", item.EndDate);
 | 
						|
            }
 | 
						|
            BindGrid();
 | 
						|
        }
 | 
						|
 | 
						|
        #region 导出按钮
 | 
						|
        /// 导出按钮
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param> 
 | 
						|
        protected void btnOut_Click(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            if (Grid1.Rows.Count == 0)
 | 
						|
            {
 | 
						|
                ShowNotify("无数据可导出!", MessageBoxIcon.Warning);
 | 
						|
                return;
 | 
						|
            }
 | 
						|
            string rootPath = Server.MapPath("~/");
 | 
						|
            string initTemplatePath = string.Empty;
 | 
						|
            string uploadfilepath = string.Empty;
 | 
						|
            string newUrl = string.Empty;
 | 
						|
            string filePath = string.Empty;
 | 
						|
            initTemplatePath = Const.WeekPlanOutTemplateUrl;
 | 
						|
            uploadfilepath = rootPath + initTemplatePath;
 | 
						|
            newUrl = uploadfilepath.Replace(".xlsx", "(" + this.drpWeekNo.SelectedItem.Text + ").xlsx");
 | 
						|
            File.Copy(uploadfilepath, newUrl);
 | 
						|
            // 第一步:读取文件流
 | 
						|
            NPOI.SS.UserModel.IWorkbook workbook;
 | 
						|
            using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
 | 
						|
            {
 | 
						|
                workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
 | 
						|
            }
 | 
						|
            Model.SGGLDB db = Funs.DB;
 | 
						|
 | 
						|
            string weekNo2 = !string.IsNullOrEmpty(this.drpWeekNo.SelectedValue) ? this.drpWeekNo.SelectedValue : "0";
 | 
						|
            string weekNo = string.Empty;
 | 
						|
            if (!string.IsNullOrEmpty(this.drpWeekNo.SelectedValue))
 | 
						|
            {
 | 
						|
                //weekNo = this.drpWeekNo.SelectedValue;
 | 
						|
                weekNo = (int.Parse(this.drpWeekNo.SelectedValue) + 1).ToString();
 | 
						|
            }
 | 
						|
            DataTable tb = BindData(this.CurrUser.LoginProjectId, weekNo);
 | 
						|
            DataTable tb2 = BindData(this.CurrUser.LoginProjectId, weekNo2);
 | 
						|
 | 
						|
            // 创建单元格样式
 | 
						|
            NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle();
 | 
						|
            cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
						|
            cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
						|
            cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
						|
            cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
						|
            cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
 | 
						|
            cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
 | 
						|
            cellStyle.WrapText = true;
 | 
						|
            var font = workbook.CreateFont();
 | 
						|
            font.FontHeightInPoints = 11;
 | 
						|
            cellStyle.SetFont(font);
 | 
						|
            NPOI.SS.UserModel.ICellStyle cellStyleT = workbook.CreateCellStyle();
 | 
						|
            cellStyleT.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
						|
            cellStyleT.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
						|
            cellStyleT.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
						|
            cellStyleT.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
 | 
						|
            cellStyleT.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
 | 
						|
            cellStyleT.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
 | 
						|
            cellStyleT.WrapText = true;
 | 
						|
            var fontT = workbook.CreateFont();
 | 
						|
            fontT.FontHeightInPoints = 16;
 | 
						|
            cellStyleT.SetFont(fontT);
 | 
						|
            // 第二步:创建新数据行
 | 
						|
            NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
 | 
						|
            NPOI.SS.UserModel.IRow row = null;
 | 
						|
            NPOI.SS.UserModel.ICell cell;
 | 
						|
            int i = 2;
 | 
						|
            for (int j = 0; j < tb2.Rows.Count; j++)
 | 
						|
            {
 | 
						|
                // 第二步:创建新数据行
 | 
						|
                row = sheet.CreateRow(i);
 | 
						|
                // 添加数据
 | 
						|
                cell = row.CreateCell(0);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue((i - 1).ToString());
 | 
						|
                cell = row.CreateCell(1);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue(tb2.Rows[j]["UnitWorkName"].ToString());
 | 
						|
                cell = row.CreateCell(2);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue(tb2.Rows[j]["ProfessionalName"].ToString());
 | 
						|
                cell = row.CreateCell(3);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue(tb2.Rows[j]["WorkContent"].ToString());
 | 
						|
                cell = row.CreateCell(4);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue(tb2.Rows[j]["UnitName"].ToString());
 | 
						|
                cell = row.CreateCell(5);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue(tb2.Rows[j]["DutyPersonName"].ToString());
 | 
						|
                cell = row.CreateCell(6);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                string planDate = string.Empty;
 | 
						|
                if (tb2.Rows[j]["PlanDate"] != DBNull.Value)
 | 
						|
                {
 | 
						|
                    planDate = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(tb2.Rows[j]["PlanDate"].ToString()));
 | 
						|
                }
 | 
						|
                cell.SetCellValue(planDate);
 | 
						|
                cell = row.CreateCell(7);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue(tb2.Rows[j]["IsOKStr"].ToString());
 | 
						|
                cell = row.CreateCell(8);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue(tb2.Rows[j]["Remark"].ToString());
 | 
						|
                i++;
 | 
						|
            }
 | 
						|
            row = sheet.CreateRow(i);
 | 
						|
            // 添加数据
 | 
						|
            cell = row.CreateCell(0);
 | 
						|
            cell.CellStyle = cellStyleT;
 | 
						|
            cell.SetCellValue("下周计划");
 | 
						|
            cell = row.CreateCell(1);
 | 
						|
            cell.CellStyle = cellStyleT;
 | 
						|
            cell.SetCellValue(string.Empty);
 | 
						|
            cell = row.CreateCell(2);
 | 
						|
            cell.CellStyle = cellStyleT;
 | 
						|
            cell.SetCellValue(string.Empty);
 | 
						|
            cell = row.CreateCell(3);
 | 
						|
            cell.CellStyle = cellStyleT;
 | 
						|
            cell.SetCellValue(string.Empty);
 | 
						|
            cell = row.CreateCell(4);
 | 
						|
            cell.CellStyle = cellStyleT;
 | 
						|
            cell.SetCellValue(string.Empty);
 | 
						|
            cell = row.CreateCell(5);
 | 
						|
            cell.CellStyle = cellStyleT;
 | 
						|
            cell.SetCellValue(string.Empty);
 | 
						|
            cell = row.CreateCell(6);
 | 
						|
            cell.CellStyle = cellStyleT;
 | 
						|
            cell.SetCellValue(string.Empty);
 | 
						|
            cell = row.CreateCell(7);
 | 
						|
            cell.CellStyle = cellStyleT;
 | 
						|
            cell.SetCellValue(string.Empty);
 | 
						|
            cell = row.CreateCell(8);
 | 
						|
            cell.CellStyle = cellStyleT;
 | 
						|
            cell.SetCellValue(string.Empty);
 | 
						|
            sheet.AddMergedRegion(new CellRangeAddress(i, i, 0, 8));
 | 
						|
            row.Height = (short)(30 * 17);
 | 
						|
            i++;
 | 
						|
            row = sheet.CreateRow(i);
 | 
						|
            cell = row.CreateCell(0);
 | 
						|
            cell.CellStyle = cellStyle;
 | 
						|
            cell.SetCellValue("序号");
 | 
						|
            cell = row.CreateCell(1);
 | 
						|
            cell.CellStyle = cellStyle;
 | 
						|
            cell.SetCellValue("工序/单位工程");
 | 
						|
            cell = row.CreateCell(2);
 | 
						|
            cell.CellStyle = cellStyle;
 | 
						|
            cell.SetCellValue("专业");
 | 
						|
            cell = row.CreateCell(3);
 | 
						|
            cell.CellStyle = cellStyle;
 | 
						|
            cell.SetCellValue("工作项");
 | 
						|
            cell = row.CreateCell(4);
 | 
						|
            cell.CellStyle = cellStyle;
 | 
						|
            cell.SetCellValue("责任单位");
 | 
						|
            cell = row.CreateCell(5);
 | 
						|
            cell.CellStyle = cellStyle;
 | 
						|
            cell.SetCellValue("五环责任人");
 | 
						|
            cell = row.CreateCell(6);
 | 
						|
            cell.CellStyle = cellStyle;
 | 
						|
            cell.SetCellValue("计划完成时间");
 | 
						|
            cell = row.CreateCell(7);
 | 
						|
            cell.CellStyle = cellStyle;
 | 
						|
            cell.SetCellValue("完成状态");
 | 
						|
            cell = row.CreateCell(8);
 | 
						|
            cell.CellStyle = cellStyle;
 | 
						|
            cell.SetCellValue("备注");
 | 
						|
            i++;
 | 
						|
            int a = 1;
 | 
						|
            for (int j = 0; j < tb.Rows.Count; j++)
 | 
						|
            {
 | 
						|
                // 第二步:创建新数据行
 | 
						|
                row = sheet.CreateRow(i);
 | 
						|
                // 添加数据
 | 
						|
                cell = row.CreateCell(0);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue(a.ToString());
 | 
						|
                cell = row.CreateCell(1);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue(tb.Rows[j]["UnitWorkName"].ToString());
 | 
						|
                cell = row.CreateCell(2);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue(tb.Rows[j]["ProfessionalName"].ToString());
 | 
						|
                cell = row.CreateCell(3);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue(tb.Rows[j]["WorkContent"].ToString());
 | 
						|
                cell = row.CreateCell(4);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue(tb.Rows[j]["UnitName"].ToString());
 | 
						|
                cell = row.CreateCell(5);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue(tb.Rows[j]["DutyPersonName"].ToString());
 | 
						|
                cell = row.CreateCell(6);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                string planDate = string.Empty;
 | 
						|
                if (tb.Rows[j]["PlanDate"] != DBNull.Value)
 | 
						|
                {
 | 
						|
                    planDate = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(tb.Rows[j]["PlanDate"].ToString()));
 | 
						|
                }
 | 
						|
                cell.SetCellValue(planDate);
 | 
						|
                cell = row.CreateCell(7);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue(tb.Rows[j]["IsOKStr"].ToString());
 | 
						|
                cell = row.CreateCell(8);
 | 
						|
                cell.CellStyle = cellStyle;
 | 
						|
                cell.SetCellValue(tb.Rows[j]["Remark"].ToString());
 | 
						|
                i++;
 | 
						|
                a++;
 | 
						|
            }
 | 
						|
            // 第三步:写入文件流
 | 
						|
            using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
 | 
						|
            {
 | 
						|
                workbook.Write(stream);
 | 
						|
                workbook.Close();
 | 
						|
            }
 | 
						|
            string fileName = Path.GetFileName(newUrl);
 | 
						|
            FileInfo info = new FileInfo(newUrl);
 | 
						|
            long fileSize = info.Length;
 | 
						|
            Response.Clear();
 | 
						|
            Response.ContentType = "application/x-zip-compressed";
 | 
						|
            Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
 | 
						|
            Response.AddHeader("Content-Length", fileSize.ToString());
 | 
						|
            Response.TransmitFile(newUrl, 0, fileSize);
 | 
						|
            Response.Flush();
 | 
						|
            Response.Close();
 | 
						|
            File.Delete(newUrl);
 | 
						|
        }
 | 
						|
        #endregion
 | 
						|
    }
 | 
						|
} |