using Aspose.Words; using BLL; using Model; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web.UI.WebControls; using System.Windows.Forms; namespace FineUIPro.Web.HJGL.WeldingManage { public partial class SelectTaskWeldJoint : PageBase { #region 定义项 /// /// 单位主键 /// public string UnitId { get { return (string)ViewState["UnitId"]; } set { ViewState["UnitId"] = value; } } /// /// 单位工程主键 /// public string UnitWorkId { get { return (string)ViewState["UnitWorkId"]; } set { ViewState["UnitWorkId"] = value; } } // 任务日期 public string TaskDate { get { return (string)ViewState["TaskDate"]; } set { ViewState["TaskDate"] = value; } } /// /// 日报主键 /// public string WeldingDailyId { get { return (string)ViewState["WeldingDailyId"]; } set { ViewState["WeldingDailyId"] = value; } } /// /// 被选择项列表 /// public List SelectedList { get { return (List)ViewState["SelectedList"]; } set { ViewState["SelectedList"] = value; } } public List Tree_hJGL_Pipelines; public int pageindex=1; public int pageindex_2=1; public int pageSize=20; #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { HJGL_MaterialService.materialStockItems_FIELD = new List(); HJGL_MaterialService.materialStockItems_SHOP = new List(); pageindex = 1; pageindex_2 = 1; Tree_hJGL_Pipelines =new List (); this.txtTaskDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now.AddDays(1)); this.txtTaskCode.Text = BLL.WeldTaskService.GetTaskCodeByDate(this.CurrUser.LoginProjectId, this.txtTaskDate.Text); BLL.Base_WeldingLocationServie.InitWeldingLocationDropDownList(drpWeldingLocation, true); ///焊接属性 this.drpJointAttribute.DataTextField = "Text"; this.drpJointAttribute.DataValueField = "Value"; this.drpJointAttribute.DataSource = BLL.DropListService.HJGL_JointAttribute(); this.drpJointAttribute.DataBind(); ///机动化程度 this.drpWeldingMode.DataTextField = "Text"; this.drpWeldingMode.DataValueField = "Value"; this.drpWeldingMode.DataSource = BLL.DropListService.HJGL_WeldingMode(); this.drpWeldingMode.DataBind(); //this.SelectedList = new List(); //this.NoSelectedList = new List(); string strList = Request.Params["strList"]; List list = Funs.GetStrListByStr(strList, '|'); if (list.Count() == 3) { this.UnitWorkId = list[0]; this.UnitId = list[1]; Model.Base_Unit unit = BLL.UnitService.GetUnitByUnitId(this.UnitId); if (unit != null) { this.txtUnitName.Text = unit.UnitName; } TaskDate = list[2]; if (!string.IsNullOrEmpty(TaskDate)) { txtTaskDate.Text = TaskDate; txtTaskDate.Enabled = false; var task = (from x in Funs.DB.HJGL_WeldTask where x.UnitWorkId == UnitWorkId && x.TaskDate.Value.Date.ToString() == Convert.ToDateTime(txtTaskDate.Text.Trim()).ToString("yyyy-MM-dd") select x).FirstOrDefault(); if (task != null) { txtTaskCode.Text = task.TaskCode; } txtTaskCode.Enabled = false; } string projectId = string.Empty; Model.WBS_UnitWork UnitWork = BLL.UnitWorkService.getUnitWorkByUnitWorkId(this.UnitWorkId); if (UnitWorkId != null) { projectId = UnitWork.ProjectId; this.txtUnitWorkName.Text = UnitWork.UnitWorkName; } } this.InitTreeMenu();//加载树 } } #endregion #region 加载树 /// /// 加载树 /// private void InitTreeMenu() { pageindex = 1; pageindex_2 = 1; this.tvControlItem.Nodes.Clear(); TreeNode rootNode1 = new TreeNode(); rootNode1.NodeID = BLL.PipelineService.PipeArea_SHOP; rootNode1.Text = "工厂预制"; rootNode1.CommandName = "工厂预制"; rootNode1.EnableClickEvent = true; rootNode1.EnableExpandEvent = true; this.tvControlItem.Nodes.Add(rootNode1); int a = (from x in PipelineService.hJGL_Pipelines where x.UnitWorkId == this.UnitWorkId && x.UnitId == this.UnitId && x.PipeArea == PipelineService.PipeArea_SHOP select x).Count(); if (a > 0) { // BindNodes(tn1); TreeNode newNode = new TreeNode(); newNode.Text = "加载管线..."; newNode.NodeID = "加载管线..."; rootNode1.Nodes.Add(newNode); } TreeNode rootNode2 = new TreeNode(); rootNode2.NodeID = BLL.PipelineService.PipeArea_FIELD; rootNode2.Text = "现场安装"; rootNode2.CommandName = "现场安装"; rootNode2.EnableClickEvent = true; rootNode2.EnableExpandEvent = true; this.tvControlItem.Nodes.Add(rootNode2); int b = (from x in PipelineService.hJGL_Pipelines where x.UnitWorkId == this.UnitWorkId && x.UnitId == this.UnitId && x.PipeArea == PipelineService.PipeArea_FIELD select x).Count(); if (b > 0) { // BindNodes(tn1); TreeNode newNode = new TreeNode(); newNode.Text = "加载管线..."; newNode.NodeID = "加载管线..."; rootNode2.Nodes.Add(newNode); } //TreeNode rootNode = new TreeNode(); //rootNode.Text = "管线号"; //rootNode.NodeID = "0"; //rootNode.Expanded = true; //this.tvControlItem.Nodes.Add(rootNode); } void AddTreeNode(string PipeArea , TreeNode node ) { var iso = (from x in PipelineService.hJGL_Pipelines where x.UnitWorkId == this.UnitWorkId && x.UnitId == this.UnitId && x.PipeArea == PipeArea orderby x.PipelineCode select x).ToList(); if (!string.IsNullOrEmpty(this.txtPipelineCode.Text)) { iso = (from x in iso where x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim()) orderby x.PipelineCode select x).ToList(); } int pagenum = 1 ; switch (PipeArea) { case "1": pagenum = pageindex; break; case "2": pagenum = pageindex_2; break; } var Count = iso.Count(); if (pagenum <= Funs.GetEndPageNumber(Count,pageSize)) { iso = iso.Skip(pageSize * (pagenum - 1)).Take(pageSize).ToList(); ; var joints = from x in WeldJointService.hJGL_WeldJoints select x; foreach (var item in iso) { TreeNode newNode = new TreeNode(); int totalJointNum = joints.Count(x => x.PipelineId == item.PipelineId); int weldJointNum = joints.Count(x => x.PipelineId == item.PipelineId && x.WeldingDailyId != null); bool istrue = BLL.HJGL_MaterialService.isInStockByPipeline(item.PipelineId, this.CurrUser.LoginProjectId); if (istrue) { newNode.CssClass = "tn-color-green"; } newNode.Text = item.PipelineCode + "(" + (totalJointNum - weldJointNum).ToString() + ")"; newNode.NodeID = item.PipelineId; newNode.ToolTip = item.PipelineCode; newNode.EnableClickEvent = true; node.Nodes.Add(newNode); } if (pagenum < Count) { TreeNode newNode = new TreeNode(); newNode.Text = "加载"; newNode.NodeID = SQLHelper.GetNewID(); newNode.Icon = Icon.ArrowDown; newNode.CommandName = PipeArea; newNode.EnableClickEvent = true; node.Nodes.Add(newNode); } } } protected void tvControlItem_TreeNodeExpanded(object sender, TreeNodeEventArgs e) { if (e.Node.Nodes[0].NodeID == "加载管线...") { e.Node.Nodes.Clear(); if (e.Node.CommandName == "工厂预制") { AddTreeNode(BLL.PipelineService.PipeArea_SHOP, e.Node); } else if (e.Node.CommandName == "现场安装") { AddTreeNode(BLL.PipelineService.PipeArea_FIELD, e.Node); } } } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { string pipelineId = this.tvControlItem.SelectedNodeID; var toDoMatterList = (from x in Funs.DB.View_HJGL_NoWeldJointFind where x.PipelineId == pipelineId && x.WeldingDailyId == null &&x.JointAttribute==drpJointAttribute.SelectedValue && (string.IsNullOrEmpty(drpWeldTypeCode.SelectedValue) || x.WeldTypeCode.Contains(drpWeldTypeCode.SelectedValue)) select x).ToList(); //去除任务表已存在的焊口 if (!string.IsNullOrEmpty(TaskDate)) { var task = from x in Funs.DB.HJGL_WeldTask where x.UnitWorkId == UnitWorkId && x.TaskDate.Value.Date.ToString() == Convert.ToDateTime(txtTaskDate.Text.Trim()).ToString("yyyy-MM-dd") select x; if (task.Count() > 0) { foreach (var item in task) { Model.View_HJGL_NoWeldJointFind jot = toDoMatterList.FirstOrDefault(e => e.WeldJointId == item.WeldJointId); if (jot != null) { toDoMatterList.Remove(jot); } } } } DataTable tb = this.LINQToDataTable(toDoMatterList); // 2.获取当前分页数据 Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); //string[] arr = new string[this.Grid1.Rows.Count]; //int a = 0; //for (int i = 0; i < this.Grid1.Rows.Count; i++) //{ // string rowId = this.Grid1.Rows[i].DataKeys[0].ToString(); // if (weldJointIds.Contains(rowId)) // { // arr[a] = rowId; // } // a++; //} //Grid1.SelectedRowIDArray = arr; } #endregion #region 管线查询 /// /// 查询 /// /// /// protected void btnQuery_Click(object sender, EventArgs e) { this.InitTreeMenu(); this.BindGrid(); } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { if (e.Node.Text == "加载") { if (e.Node.CommandName == "1") { pageindex = pageindex + 1; TreeNode treeNode = e.Node.ParentNode; treeNode.Nodes.Remove(e.Node); AddTreeNode(BLL.PipelineService.PipeArea_SHOP, e.Node.ParentNode); } else if (e.Node.CommandName == "2") { pageindex_2 = pageindex_2 + 1; TreeNode treeNode = e.Node.ParentNode; treeNode.Nodes.Remove(e.Node); AddTreeNode(BLL.PipelineService.PipeArea_FIELD, e.Node.ParentNode); } } else { this.BindGrid(); } } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { this.BindGrid(); } #endregion #region 提交按钮 /// /// 提交按钮 /// /// /// protected void btnAccept_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(txtTaskDate.Text) + ActiveWindow.GetHidePostBackReference()); //if (string.IsNullOrEmpty(this.txtTaskCode.Text.Trim())) //{ // ShowNotify("请输入焊接任务单编号", MessageBoxIcon.Warning); // return; //} //if (!string.IsNullOrEmpty(txtTaskDate.Text)) //{ // if (!string.IsNullOrEmpty(TaskDate)) // { // SaveTask(true); // } // else // { // var task = from x in Funs.DB.HJGL_WeldTask // where x.UnitWorkId == UnitWorkId // && x.TaskDate.Value.Date.ToString() == Convert.ToDateTime(txtTaskDate.Text.Trim()).ToString("yyyy-MM-dd") // select x; // if (task.Count() > 0) // { // ShowNotify("所选预计焊接日期已存在,请重新选择!", MessageBoxIcon.Warning); // return; // } // else // { // SaveTask(true); // } // } //} //else //{ // ShowNotify("请选择预计焊接日期", MessageBoxIcon.Warning); // return; //} } protected void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtTaskCode.Text.Trim())) { ShowNotify("请输入焊接任务单编号", MessageBoxIcon.Warning); return; } if (!string.IsNullOrEmpty(txtTaskDate.Text)) { if (!string.IsNullOrEmpty(TaskDate)) { SaveTask(false); BindGrid(); } else { var task = from x in Funs.DB.HJGL_WeldTask where x.UnitWorkId == UnitWorkId && x.TaskDate.Value.Date.ToString() == Convert.ToDateTime(txtTaskDate.Text.Trim()).ToString("yyyy-MM-dd") select x; if (task.Count() > 0) { ShowNotify("所选预计焊接日期已存在,请重新选择!", MessageBoxIcon.Warning); return; } else { SaveTask(false); TaskDate = txtTaskDate.Text; BindGrid(); } } } else { ShowNotify("请选择预计焊接日期", MessageBoxIcon.Warning); return; } } private void SaveTask(bool IsCloseForm) { var weldingRods = from x in Funs.DB.Base_Consumables where x.ConsumablesType == "2" select x; var weldingWires = from x in Funs.DB.Base_Consumables where x.ConsumablesType == "1" select x; string[] selectRowId = Grid1.SelectedRowIDArray; for (int i = 0; i < selectRowId.Count(); i++) { string canWeldingRodName = string.Empty; string canWeldingWireName = string.Empty; Model.HJGL_WeldTask NewTask = new Model.HJGL_WeldTask(); NewTask.ProjectId = this.CurrUser.LoginProjectId; NewTask.UnitWorkId = this.UnitWorkId; NewTask.UnitId = this.UnitId; NewTask.TaskCode = this.txtTaskCode.Text.Trim(); NewTask.WeldTaskId = SQLHelper.GetNewID(); NewTask.WeldJointId = selectRowId[i]; Model.HJGL_WeldJoint weldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(NewTask.WeldJointId); if (weldJoint != null) { NewTask.WeldingRod = weldJoint.WeldingRod; NewTask.WeldingWire = weldJoint.WeldingWire; //获取可替代焊丝焊条 var mat = BLL.Base_MaterialService.GetMaterialByMaterialId(weldJoint.Material1Id); string matClass = mat.MaterialClass; var matRod = weldingRods.FirstOrDefault(x => x.ConsumablesId == weldJoint.WeldingRod); if (matRod != null) { foreach (var item in weldingRods) { if (matClass == "Fe-1" || matClass == "Fe-3") { if (IsCoverClass(matRod.SteelType, item.SteelType)) { canWeldingRodName = canWeldingRodName + item.ConsumablesName + ","; } } else { if (matRod.SteelType == item.SteelType) { canWeldingRodName = canWeldingRodName + item.ConsumablesName + ","; } } } if (!string.IsNullOrEmpty(canWeldingRodName)) { NewTask.CanWeldingRodName = canWeldingRodName.Substring(0, canWeldingRodName.Length - 1); } } var matWire = weldingWires.FirstOrDefault(x => x.ConsumablesId == weldJoint.WeldingWire); if (matWire != null) { foreach (var item in weldingWires) { if (matClass == "Fe-1" || matClass == "Fe-3") { if (IsCoverClass(matWire.SteelType, item.SteelType)) { canWeldingWireName = canWeldingWireName + item.ConsumablesName + ","; } } else { if (matWire.SteelType == item.SteelType) { canWeldingWireName = canWeldingWireName + item.ConsumablesName + ","; } } } if (!string.IsNullOrEmpty(canWeldingWireName)) { NewTask.CanWeldingWireName = canWeldingWireName.Substring(0, canWeldingWireName.Length - 1); } } } //NewTask.JointAttribute = drpJointAttribute.SelectedValue; NewTask.JointAttribute = weldJoint.JointAttribute; NewTask.WeldingMode = drpWeldingMode.SelectedValue; NewTask.TaskDate = Convert.ToDateTime(txtTaskDate.Text); NewTask.Tabler = this.CurrUser.PersonId; NewTask.TableDate = DateTime.Now; BLL.WeldTaskService.AddWeldTask(NewTask); } //string pipelineId = this.tvControlItem.SelectedNodeID; //var model = BLL.PipelineService.GetPipelineByPipelineId(pipelineId); //model.State = 1; //PipelineService.UpdatePipeline(model); ShowNotify("保存成功!", MessageBoxIcon.Success); if (IsCloseForm) { PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(txtTaskDate.Text) + ActiveWindow.GetHidePostBackReference()); } //PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } /// /// 判断耗材强度是否大于WPS耗材强度,如是为true,否则为false /// /// /// /// private bool IsCoverClass(string wpsClass, string matClass) { bool isCover = false; int wpsSn = 0; int matSn = 0; if (wpsClass.Length > 2 && matClass.Length > 2) { string wpsPre = wpsClass.Substring(0, wpsClass.Length - 2); string matPre = matClass.Substring(0, matClass.Length - 2); string wps = wpsClass.Substring(wpsClass.Length - 1, 1); wpsSn = Funs.GetNewInt(wps).HasValue ? Funs.GetNewInt(wps).Value : 0; string mat = matClass.Substring(matClass.Length - 1, 1); matSn = Funs.GetNewInt(mat).HasValue ? Funs.GetNewInt(mat).Value : 0; if (wpsPre == matPre && matSn >= wpsSn) { return true; } } return isCover; } #endregion protected void txtTaskDate_TextChanged(object sender, EventArgs e) { this.txtTaskCode.Text = BLL.WeldTaskService.GetTaskCodeByDate(this.CurrUser.LoginProjectId, this.txtTaskDate.Text); } protected void drpJointAttribute_SelectedIndexChanged(object sender, EventArgs e) { BindGrid(); } /// /// 行绑定事件(没有焊接方法无法选择) /// /// /// protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) { DataRowView row = e.DataItem as DataRowView; if (string.IsNullOrEmpty(row["WeldingMethodCode"].ToString())) { e.RowSelectable = false; }; } } }