using BLL; using MiniExcelLibs; using Model; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using System.Drawing; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Web; using System.Web.WebSockets; namespace FineUIPro.Web.HJGL.PreDesign { public partial class ProductionSchedulingPlan : PageBase { public int pageSize = 20; public static DataTable GridDataTable = new DataTable(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); this.InitTreeMenu();//加载树 //HJGL_PipelineComponentService.InitMainItemDownList(drpState, true); //HJGL_PipelineComponentService.InitMainItemDownProductionStateList(drpProductionState, true); //var pipeline = (from x in Funs.DB.HJGL_Pipeline // where x.ProjectId == this.CurrUser.LoginProjectId // select x.FlowingSection).Distinct().ToList(); //this.drpFlowingSection.DataTextField = "Value"; //this.drpFlowingSection.DataValueField = "Value"; //this.drpFlowingSection.DataSource = pipeline; //this.drpFlowingSection.DataBind(); //Funs.FineUIPleaseSelect(drpFlowingSection); } } #region 加载树装置-单位-工作区 /// /// 加载树 /// private void InitTreeMenu() { this.tvControlItem.Nodes.Clear(); TreeNode rootNode1 = new TreeNode(); rootNode1.NodeID = "1"; rootNode1.Text = "建筑工程"; rootNode1.CommandName = "建筑工程"; rootNode1.Selectable = false; this.tvControlItem.Nodes.Add(rootNode1); TreeNode rootNode2 = new TreeNode(); rootNode2.NodeID = "2"; rootNode2.Text = "安装工程"; rootNode2.CommandName = "安装工程"; rootNode2.Expanded = true; this.tvControlItem.Nodes.Add(rootNode2); var pUnits = (from x in Funs.DB.Project_ProjectUnit where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList(); // 获取当前用户所在单位 var currUnit = pUnits.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId); var unitWorkList = (from x in Funs.DB.WBS_UnitWork where x.ProjectId == this.CurrUser.LoginProjectId && x.SuperUnitWork == null && x.UnitId != null && x.ProjectType != null select x).ToList(); List unitWork1 = null; List unitWork2 = null; //// 当前为施工单位,只能操作本单位的数据 //if (currUnit != null && currUnit.UnitType == Const.ProjectUnitType_2) //{ // unitWork1 = (from x in unitWorkList // where x.UnitId == this.CurrUser.UnitId && x.ProjectType == "1" // select x).ToList(); // unitWork2 = (from x in unitWorkList // where x.UnitId == this.CurrUser.UnitId && x.ProjectType == "2" // select x).ToList(); //} //else //{ unitWork1 = (from x in unitWorkList where x.ProjectType == "1" select x).ToList(); unitWork2 = (from x in unitWorkList where x.ProjectType == "2" select x).ToList(); //} if (unitWork1.Count() > 0) { foreach (var q in unitWork1) { int a = (from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == q.UnitWorkId && x.PipeArea == "1" && x.PipelineCode.Contains(txtPipelineCode.Text.Trim()) select x.FlowingSection).Distinct().Count(); var unitNamesUnitIds = BLL.UnitService.getUnitNamesUnitIds(q.UnitId); TreeNode tn1 = new TreeNode(); tn1.NodeID = q.UnitWorkId; //tn1.Text = q.UnitWorkName + "【" + a.ToString() + "】" + "管线"; tn1.Text = q.UnitWorkName; tn1.ToolTip = "施工单位:" + unitNamesUnitIds; tn1.CommandName = 1 + "|" + Funs.GetEndPageNumber(a, pageSize); tn1.EnableClickEvent = true; tn1.EnableExpandEvent = true; rootNode1.Nodes.Add(tn1); if (a > 0) { // BindNodes(tn1); TreeNode newNode = new TreeNode(); newNode.Text = "加载流水段..."; newNode.NodeID = "加载流水段..."; tn1.Nodes.Add(newNode); } //if (a > 0) //{ // BindNodes(tn1); //} } } if (unitWork2.Count() > 0) { foreach (var q in unitWork2) { int a = (from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == q.UnitWorkId && x.PipeArea == "1" && x.PipelineCode.Contains(txtPipelineCode.Text.Trim()) select x).Count(); var unitNamesUnitIds = BLL.UnitService.getUnitNamesUnitIds(q.UnitId); TreeNode tn2 = new TreeNode(); tn2.NodeID = q.UnitWorkId; tn2.Text = q.UnitWorkName + "【" + a.ToString() + "】" + "管线"; if (q.UnitWorkId == this.hdUnitWorkId.Text) { tn2.Expanded = true; } tn2.ToolTip = "施工单位:" + unitNamesUnitIds; tn2.CommandName = 1 + "|" + Funs.GetEndPageNumber(a, pageSize); tn2.EnableClickEvent = true; tn2.EnableExpandEvent = true; rootNode2.Nodes.Add(tn2); if (a > 0) { // BindNodes(tn1); TreeNode newNode = new TreeNode(); newNode.Text = "加载流水段..."; newNode.NodeID = "加载流水段..."; tn2.Nodes.Add(newNode); } //if (a > 0) //{ // BindNodes(tn2); //} } } } private void BindNodes(TreeNode node) { List pipeline = new List(); var pipelines = from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.PipeArea == "1" select x; pipeline = (from x in pipelines where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == node.NodeID && x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim()) orderby x.PipelineCode select x).ToList(); int pageindex = int.Parse(node.CommandName.Split('|')[0]); int pageCount = int.Parse(node.CommandName.Split('|')[1]); if (pageindex <= pageCount) { pipeline = pipeline.Skip(pageSize * (pageindex - 1)).Take(pageSize).ToList(); foreach (var item in pipeline) { var comCount = (from x in Funs.DB.HJGL_Pipeline_Component where x.PipelineId == item.PipelineId select x).Count(); TreeNode newNode = new TreeNode(); newNode.Text = item.PipelineCode + "【" + comCount.ToString() + " " + "组件" + "】"; newNode.ToolTip = "管线号【组件数】"; newNode.CommandName = "管线"; newNode.NodeID = item.PipelineId; newNode.EnableClickEvent = true; node.Nodes.Add(newNode); } if (pageindex < pageCount) { TreeNode newNode = new TreeNode(); newNode.Text = "加载"; newNode.NodeID = SQLHelper.GetNewID(); newNode.CommandName = "加载"; newNode.Icon = Icon.ArrowDown; newNode.EnableClickEvent = true; node.Nodes.Add(newNode); } } } #endregion protected void tvControlItem_TreeNodeExpanded(object sender, TreeNodeEventArgs e) { if (e.Node.Nodes[0].NodeID == "加载流水段...") { e.Node.Nodes.Clear(); BindNodes(e.Node); } } #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { if (e.CommandName.Split('|').Length == 2) { this.hdUnitWorkId.Text = this.tvControlItem.SelectedNodeID; } else if (e.CommandName == "管线") { Model.HJGL_Pipeline pipeline = BLL.PipelineService.GetPipelineByPipelineId(this.tvControlItem.SelectedNodeID); this.hdUnitWorkId.Text = string.Empty; if (pipeline != null) { this.hdUnitWorkId.Text = this.tvControlItem.SelectedNode.ParentNode.NodeID; SaveProductionSchedulingPlan(); } } else if (e.CommandName == "加载") { string CommandName = e.Node.ParentNode.CommandName; e.Node.ParentNode.CommandName = (int.Parse(CommandName.Split('|')[0]) + 1) + "|" + int.Parse(CommandName.Split('|')[1]); TreeNode treeNode = e.Node.ParentNode; treeNode.Nodes.Remove(e.Node); BindNodes(e.Node.ParentNode); } this.BindGrid(); } /// /// 保存数据 /// /// private void SaveProductionSchedulingPlan() { if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID)) { var schedulingPlan = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanByPipelineId(this.CurrUser.LoginProjectId, this.tvControlItem.SelectedNodeID); if (schedulingPlan == null) { Model.HJGL_ProductionSchedulingPlan newPlan = new HJGL_ProductionSchedulingPlan(); newPlan.ProductionSchedulingPlanId = SQLHelper.GetNewID(typeof(Model.HJGL_ProductionSchedulingPlan)); newPlan.ProjectId = this.CurrUser.LoginProjectId; newPlan.PipelineId = this.tvControlItem.SelectedNodeID; var pipeline = BLL.PipelineService.GetPipelineByPipelineId(this.tvControlItem.SelectedNodeID); if (pipeline!=null) { newPlan.FlowNum = pipeline.FlowingSection; if (!string.IsNullOrEmpty(pipeline.UnitWorkId)) { newPlan.MainItemName = BLL.UnitWorkService.getUnitWorkByUnitWorkId(pipeline.UnitWorkId).UnitWorkName; } if (!string.IsNullOrEmpty(pipeline.PipingClassId)) { newPlan.Material = BLL.Base_PipingClassService.GetPipingClassByPipingClassId(pipeline.PipingClassId).SteelType; } } BLL.ProductionSchedulingPlanService.AddProductionSchedulingPlan(newPlan); } } } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { if (tvControlItem.SelectedNode == null) return; string strSql = @"SELECT p.ProductionSchedulingPlanId, p.ProjectId, p.PipelineId, p.FlowNum, p.MainItemName, p.Material, p.Caliber, p.Dain, p.TotalDyne, p.TotalPriority, p.PriorityTotalDyne, p.PlanStartDate, p.PlanEndDate, p.Days, p.AvgDailyWorkload, pipeline.UnitWorkId FROM HJGL_ProductionSchedulingPlan p left join HJGL_Pipeline as pipeline on pipeline.PipelineId = p.PipelineId WHERE 1=1 "; List listStr = new List(); if (tvControlItem.SelectedNode.CommandName.Split('|').Length == 2) { strSql += " and pipeline.UnitWorkId =@UnitWorkId"; listStr.Add(new SqlParameter("@UnitWorkId", this.tvControlItem.SelectedNodeID)); } else if (tvControlItem.SelectedNode.CommandName == "管线") { strSql += " and p.PipelineId = @PipelineId "; listStr.Add(new SqlParameter("@PipelineId", this.tvControlItem.SelectedNodeID)); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); GridDataTable = tb; // 2.获取当前分页数据 Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 分页排序 #region 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #endregion #region 维护事件 protected void btnSearch_Click(object sender, EventArgs e) { BindGrid(); } #endregion #region 关闭弹出窗口及刷新页面 /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } protected void btnTreeFind_Click(object sender, EventArgs e) { this.InitTreeMenu(); } #endregion #region 保存 /// /// 保存 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (this.Grid1.Rows.Count > 0) { foreach (JObject mergedRow in Grid1.GetMergedData()) { JObject values = mergedRow.Value("values"); int i = mergedRow.Value("index"); string rowId = Grid1.Rows[i].RowID; var newPlan = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanById(rowId); if (newPlan != null) { newPlan.TotalPriority = values.Value("TotalPriority"); newPlan.PriorityTotalDyne = Funs.GetNewDecimal(values.Value("PriorityTotalDyne")); newPlan.PlanStartDate = Funs.GetNewDateTime(values.Value("PlanStartDate")); newPlan.PlanEndDate = Funs.GetNewDateTime(values.Value("PlanEndDate")); newPlan.Days = Funs.GetNewInt(values.Value("Days")); newPlan.AvgDailyWorkload = Funs.GetNewDecimal(values.Value("AvgDailyWorkload")); BLL.ProductionSchedulingPlanService.UpdateProductionSchedulingPlan(newPlan); } } ShowNotify("保存成功!", MessageBoxIcon.Success); BindGrid(); } } #endregion #region 导出 protected void btnOut_Click(object sender, EventArgs e) { } #endregion } }