using BLL; using FineUIPro.Web.HJGL.WeldingManage; using Microsoft.Office.Interop.Word; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web.UI.DataVisualization.Charting; using System.Threading.Tasks; namespace FineUIPro.Web.WeldingProcess.WeldingManage { public partial class WeldReportEdit : PageBase { #region 定义项 /// /// 焊接日报主键 /// public string WeldingDailyId { get { return (string)ViewState["WeldingDailyId"]; } set { ViewState["WeldingDailyId"] = value; } } /// /// 单位工程 /// public string UnitWorkId { get { return (string)ViewState["UnitWorkId"]; } set { ViewState["UnitWorkId"] = value; } } #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.WeldingDailyId = Request.Params["WeldingDailyId"]; // 焊口属性 this.drpJointAttribute.DataTextField = "Text"; this.drpJointAttribute.DataValueField = "Value"; this.drpJointAttribute.DataSource = BLL.DropListService.HJGL_JointAttribute(); this.drpJointAttribute.DataBind(); Funs.FineUIPleaseSelect(drpJointAttribute); this.PageInfoLoad(); // 加载页面 if (!string.IsNullOrEmpty(this.WeldingDailyId)) { List GetWeldingDailyItem = BLL.WeldingDailyService.GetWeldingDailyItem(this.WeldingDailyId); this.BindGrid(GetWeldingDailyItem); // 初始化页面 } else { this.BindGrid(null); } this.CalculationAmount(); } } #endregion #region 超量焊工提示 /// /// 超量焊工提示 /// private void CalculationAmount() { this.lbAmount.Hidden = true; this.lbAmount.Text = string.Empty; DateTime? date = Funs.GetNewDateTime(this.txtWeldingDate.Text); string txtValue = string.Empty; if (date.HasValue) { //var weldJoints = BLL.WeldJointService.GetWeldlinesByWeldingDailyId(this.WeldingDailyId); //foreach (var item in weldJoints) //{ // bool cWelder = BLL.Pipeline_WeldJointService.GetWelderLimitDN(this.ProjectId, item.CoverWelderId, date.Value); // bool bWelder = cWelder; // if (item.BackingWelderId != item.CoverWelderId) // { // bWelder = BLL.Pipeline_WeldJointService.GetWelderLimitDN(this.ProjectId, item.BackingWelderId, date.Value); // } // if (cWelder || bWelder) // { // if (cWelder) // { // var coverWelder = BLL.SitePerson_PersonService.GetSitePersonById(item.CoverWelderId); // if (coverWelder != null) // { // string txt = coverWelder.WelderCode + ";"; // if (!txtValue.Contains(txt)) // { // txtValue += txt; // } // } // } // if (bWelder) // { // var floorWelder = BLL.SitePerson_PersonService.GetSitePersonById(item.BackingWelderId); // if (floorWelder != null) // { // string txt = floorWelder.WelderCode + ";"; // if (!txtValue.Contains(txt)) // { // txtValue += txt; // } // } // } // } //} } if (!string.IsNullOrEmpty(txtValue)) { this.lbAmount.Text = txtValue; this.lbAmount.Hidden = false; } } #endregion #region 加载页面输入提交信息 /// /// 加载页面输入提交信息 /// private void PageInfoLoad() { BLL.UnitService.InitUnitByProjectIdUnitTypeDropDownList(this.drpUnit, this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2, true); BLL.UnitWorkService.InitUnitWorkDropDownList(this.drpUnitWork, this.CurrUser.LoginProjectId, true); var report = BLL.WeldingDailyService.GetPipeline_WeldingDailyByWeldingDailyId(this.WeldingDailyId); if (report != null) { this.txtWeldingDailyCode.Text = report.WeldingDailyCode; if (!string.IsNullOrEmpty(report.UnitId)) { this.drpUnit.SelectedValue = report.UnitId; } if (!string.IsNullOrEmpty(report.UnitWorkId)) { this.drpUnitWork.SelectedValue = report.UnitWorkId; } this.UnitWorkId = report.UnitWorkId; this.txtWeldingDate.Text = string.Format("{0:yyyy-MM-dd}", report.WeldingDate); this.hdTablerId.Text = report.Tabler; this.txtTabler.Text = Person_PersonsService.GetPersonsNameById(report.Tabler); this.txtTableDate.Text = string.Format("{0:yyyy-MM-dd}", report.TableDate); this.txtRemark.Text = report.Remark; } else { this.UnitWorkId = Request.Params["unitWorkId"]; if (!string.IsNullOrEmpty(UnitWorkId)) { var w = BLL.UnitWorkService.getUnitWorkByUnitWorkId(UnitWorkId); drpUnit.SelectedValue = w.UnitId; this.drpUnitWork.SelectedValue = w.UnitWorkId; } this.SimpleForm1.Reset(); ///重置所有字段 this.txtTabler.Text = this.CurrUser.PersonName; this.hdTablerId.Text = this.CurrUser.PersonId; //txtWeldingDate.MaxDate = DateTime.Now; this.txtWeldingDate.Text = string.Format("{0:yyyy-MM-dd}", System.DateTime.Now); this.txtTableDate.Text = string.Format("{0:yyyy-MM-dd}", System.DateTime.Now); string perfix = string.Format("{0:yyyyMMdd}", System.DateTime.Now) + "-" + this.CurrUser.PersonName + "-"; this.txtWeldingDailyCode.Text = BLL.SQLHelper.RunProcNewId("SpGetThreeNumber", "dbo.HJGL_WeldingDaily", "WeldingDailyCode", this.CurrUser.LoginProjectId, perfix); } } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid(List weldingDailyItem) { var task = new List(); var list = from x in Funs.DB.View_HJGL_WeldingTask where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == this.UnitWorkId select x; if (weldingDailyItem != null) { var weldJointIds = (from x in list where (x.TaskDate.Value.Date <= Convert.ToDateTime(txtWeldingDate.Text) && x.WeldingDailyId == null/*|| x.WeldingDailyId == this.WeldingDailyId*/) select x).ToList(); weldJointIds = weldJointIds.GroupBy(x => x.WeldJointId, (key, group) => group.OrderByDescending(x => x.TaskDate).First()).ToList(); task = weldJointIds; //foreach (var weldJointId in weldJointIds) //{ // task.Add(list.FirstOrDefault(x => x.WeldJointId == weldJointId)); //} if (drpJointAttribute.SelectedValue != Const._Null) { task = task.Where(x => x.JointAttribute == drpJointAttribute.SelectedValue).ToList(); } if (drpUnit.SelectedValue != Const._Null) { task = task.Where(x => x.UnitId == drpUnit.SelectedValue).ToList(); } if (!string.IsNullOrEmpty(this.txtPipelineCode.Text.Trim())) { task = task.Where(x => x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim())).ToList(); } // dt = this.LINQToDataTable(task); } else { var weldJointIds = (from x in list where x.UnitWorkId == this.UnitWorkId && x.TaskDate.Value.Date <= Convert.ToDateTime(txtWeldingDate.Text) && x.WeldingDailyId == null select x).ToList(); weldJointIds = weldJointIds.GroupBy(x => x.WeldJointId, (key, group) => group.OrderByDescending(x => x.TaskDate).First()).ToList(); task = weldJointIds; //foreach (var weldJointId in weldJointIds) //{ // task.Add(list.FirstOrDefault(x => x.WeldJointId == weldJointId /*&& x.CoverWelderId != null*/)); //} if (drpJointAttribute.SelectedValue != Const._Null) { task = task.Where(x => x.JointAttribute == drpJointAttribute.SelectedValue).ToList(); } if (drpUnit.SelectedValue != Const._Null) { task = task.Where(x => x.UnitId == drpUnit.SelectedValue).ToList(); } if (!string.IsNullOrEmpty(this.txtPipelineCode.Text.Trim())) { task = task.Where(x => x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim())).ToList(); } //dt = this.LINQToDataTable(task); } task = task.OrderBy(x => x.PipelineCode).ThenBy(x => x.WeldJointNum).ToList(); Grid1.RecordCount = task.Count; Grid1.DataSource = task; Grid1.DataBind(); //for (int i = 0; i < this.Grid1.Rows.Count; i++) //{ // var hotProesssItem = Funs.DB.HJGL_HotProess_TrustItem.FirstOrDefault(x => x.WeldJointId == this.Grid1.Rows[i].DataKeys[1].ToString()); // if (hotProesssItem != null) //已生成热处理委托,不能编辑或删除 // { // // Grid1.Rows[i].RowSelectable = false; // } // var pointBatchItem = Funs.DB.HJGL_Batch_PointBatchItem.FirstOrDefault(x => x.WeldJointId == this.Grid1.Rows[i].DataKeys[1].ToString() && x.PointState != null); // if (pointBatchItem != null) //已生成委托,不能编辑或删除 // { // // Grid1.Rows[i].RowSelectable = false; // } //} //if (weldingDailyItem != null) //{ // var Dailytask = (from x in Funs.DB.View_HJGL_WeldingTask // where x.WeldingDailyId == this.WeldingDailyId // select new // { // x.PipelineCode, // x.WeldTaskId // }).Distinct().ToList(); // if (!string.IsNullOrEmpty(this.txtPipelineCode.Text.Trim())) // { // Dailytask = Dailytask.Where(x => x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim())).ToList(); // } // var weldTaskIds = Dailytask.Select(x => x.WeldTaskId).ToArray(); // this.Grid1.SelectedRowIDArray = weldTaskIds; // var a = this.Grid1.SelectedRowIDArray; //} } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { //List GetWeldingDailyItem = this.CollectGridJointInfo(); this.BindGrid(null); } #endregion //private static bool canSave; //是否可以保存 public string ConvertPipeArea(object PipeArea) { string stateName = string.Empty; if (PipeArea != null && !string.IsNullOrEmpty(PipeArea.ToString())) { string txt = PipelineService.GetPipeArea().FirstOrDefault(x => x.Value == PipeArea.ToString())?.Text; return txt; } return stateName; } #region 焊接日报 提交事件 // 检查用户权限 private bool HasPermission() { return CommonService.GetAllButtonPowerList(CurrUser.LoginProjectId, CurrUser.PersonId, Const.HJGL_WeldTaskMenuId, Const.BtnSave); } // 获取焊接信息 private List GetWeldJointView() { return Funs.DB.View_HJGL_WeldJoint .Where(x => x.WeldingDailyId == WeldingDailyId) .OrderBy(x => x.PipelineCode) .ThenBy(x => x.WeldJointCode) .ToList(); } // 创建新的焊接日报 private Model.HJGL_WeldingDaily CreateNewWeldingDaily() { Model.HJGL_WeldingDaily newWeldingDaily = new Model.HJGL_WeldingDaily { WeldingDailyCode = this.txtWeldingDailyCode.Text.Trim(), ProjectId = CurrUser.LoginProjectId, UnitWorkId = this.UnitWorkId, WeldingDate = Funs.GetNewDateTime(this.txtWeldingDate.Text) ?? DateTime.Now, Tabler = this.hdTablerId.Text, TableDate = Funs.GetNewDateTime(this.txtTableDate.Text), Remark = this.txtRemark.Text.Trim(), UnitId = this.drpUnit.SelectedValue }; if (this.drpUnitWork.SelectedValue != BLL.Const._Null) { newWeldingDaily.UnitWorkId = this.drpUnitWork.SelectedValue; } return newWeldingDaily; } //焊工资质判断 private void CheckWelderQualification() { #region 焊工资质判断这里取消 //foreach (var item in GetWeldingDailyItem) //{ // bool canSave = false; // var jot = BLL.WeldJointService.GetWeldJointByWeldJointId(item.WeldJointId); // var joty = BLL.Base_WeldTypeService.GetWeldTypeByWeldTypeId(jot.WeldTypeId); // string weldType = string.Empty; // if (joty != null && joty.WeldTypeCode.Contains("B")) // { // weldType = "对接焊缝"; // } // else // { // weldType = "角焊缝"; // } // string floorWelder = item.BackingWelderId; // string cellWelder = item.CoverWelderId; // decimal? dia = item.Dia; // decimal? sch = Funs.GetNewDecimal(item.Thickness.HasValue ? item.Thickness.Value.ToString() : ""); // string wmeCode = string.Empty; // var wm = BLL.Base_WeldingMethodService.GetWeldingMethodByWeldingMethodId(jot.WeldingMethodId); // if (wm != null) // { // wmeCode = wm.WeldingMethodCode; // } // string[] wmeCodes = wmeCode.Split('+'); // //string location = item.JOT_Location; // string ste = jot.Material1Id; // string jointAttribute = jot.JointAttribute; // List floorWelderQualifys = (from x in Funs.DB.Welder_WelderQualify // where x.WelderId == floorWelder && x.WeldingMethod != null // && x.MaterialType != null && x.WeldType != null // && x.ThicknessMax != null && x.SizesMin != null // select x).ToList(); // List cellWelderQualifys = (from x in Funs.DB.Welder_WelderQualify // where x.WelderId == cellWelder && x.WeldingMethod != null // && x.MaterialType != null && x.WeldType != null // && x.ThicknessMax != null && x.SizesMin != null // select x).ToList(); // // 打底和盖面同一焊工 // if (floorWelder == cellWelder) // { // if (floorWelderQualifys != null && floorWelderQualifys.Count() > 0) // { // if (wmeCodes.Count() <= 1) // 一种焊接方法 // { // canSave = OneWmeIsOK(floorWelderQualifys, wmeCode, jointAttribute, weldType, ste, dia, sch); // } // else // 大于一种焊接方法,如氩电联焊 // { // canSave = TwoWmeIsOK(floorWelderQualifys, cellWelderQualifys, wmeCodes[0], wmeCodes[1], jointAttribute, weldType, ste, dia, sch); // } // } // } // // 打底和盖面焊工不同 // else // { // bool isok1 = false; // bool isok2 = false; // if (wmeCodes.Count() <= 1) // 一种焊接方法 // { // if (floorWelderQualifys != null && floorWelderQualifys.Count() > 0) // { // isok1 = OneWmeIsOK(floorWelderQualifys, wmeCode, jointAttribute, weldType, ste, dia, sch); // } // if (cellWelderQualifys != null && cellWelderQualifys.Count() > 0) // { // isok2 = OneWmeIsOK(cellWelderQualifys, wmeCode, jointAttribute, weldType, ste, dia, sch); // } // if (isok1 && isok2) // { // canSave = true; // } // } // else // { // canSave = TwoWmeIsOK(floorWelderQualifys, cellWelderQualifys, wmeCodes[0], wmeCodes[1], jointAttribute, weldType, ste, dia, sch); // } // } // if (canSave == false) // { // eventArg = eventArg + jot.WeldJointCode + ","; // } //} #endregion } /// /// 编辑焊接日报 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (!HasPermission()) { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } if (this.drpUnit.SelectedValue==BLL.Const._Null) { ShowNotify("请选择单位名称!", MessageBoxIcon.Warning); return; } if (BLL.WeldingDailyService.IsExistWeldingDailyCode(this.txtWeldingDailyCode.Text, !string.IsNullOrEmpty(this.WeldingDailyId) ? this.WeldingDailyId : "", CurrUser.LoginProjectId)) { ShowNotify("日报编号已存在,请重新录入", MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(this.txtWeldingDate.Text) || string.IsNullOrEmpty(this.txtWeldingDailyCode.Text.Trim())) { ShowNotify("日报告号、焊接日期不能为空", MessageBoxIcon.Warning); return; } // 创建新的焊接日报 var newWeldingDaily = CreateNewWeldingDaily(); // 获取焊接信息 var weldJointView = GetWeldJointView(); string errlog = string.Empty; string eventArg = string.Empty; // 焊工资质判断 // CheckWelderQualification(weldJointView); if (eventArg == string.Empty) //焊工焊接的所有焊口资质都符合要求) { if (!string.IsNullOrEmpty(this.WeldingDailyId)) { newWeldingDaily.WeldingDailyId = this.WeldingDailyId; BLL.WeldingDailyService.UpdateWeldingDaily(newWeldingDaily); //BLL.Sys_LogService.AddLog(BLL.Const.System_6, this.CurrUser.LoginProjectId, this.CurrUser.PersonId, Const.HJGL_WeldReportMenuId, Const.BtnModify, this.WeldingDailyId); } else { this.WeldingDailyId = SQLHelper.GetNewID(typeof(Model.HJGL_WeldingDaily)); newWeldingDaily.WeldingDailyId = this.WeldingDailyId; BLL.WeldingDailyService.AddWeldingDaily(newWeldingDaily); //BLL.Sys_LogService.AddLog(BLL.Const.System_6, this.CurrUser.LoginProjectId, this.CurrUser.PersonId, Const.HJGL_WeldReportMenuId, Const.BtnAdd, this.WeldingDailyId); } foreach (JObject mergedRow in Grid1.GetMergedData()) { JObject values = mergedRow.Value("values"); int i = mergedRow.Value("index"); string rowId = Grid1.Rows[i].RowID; if (this.Grid1.SelectedRowIDArray.Contains(rowId)) { var t = BLL.WeldTaskService.GetWeldTaskById(rowId); var newWeldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(t.WeldJointId); if (newWeldJoint != null) { newWeldJoint.JointAttribute = values.Value("JointAttribute"); var coverWelderCode = (from x in Funs.DB.SitePerson_Person where x.ProjectId == CurrUser.LoginProjectId && x.WelderCode == values.Value("CoverWelderCode") select x).FirstOrDefault(); if (coverWelderCode != null) { t.CoverWelderId = coverWelderCode.PersonId; newWeldJoint.CoverWelderId = coverWelderCode.PersonId; newWeldJoint.CoverWelderTeamGroupId = coverWelderCode.TeamGroupId; } var backingWelderCode = (from x in Funs.DB.SitePerson_Person where x.ProjectId == CurrUser.LoginProjectId && x.WelderCode == values.Value("BackingWelderCode") select x).FirstOrDefault(); if (backingWelderCode != null) { t.BackingWelderId = backingWelderCode.PersonId; newWeldJoint.BackingWelderId = backingWelderCode.PersonId; newWeldJoint.BackingWelderTeamGroupId = backingWelderCode.TeamGroupId; } WeldTaskService.UpdateWeldTask(t); WeldJointService.UpdateWeldJoint(newWeldJoint); //if (!string.IsNullOrEmpty(values.Value("JointAttribute").ToString())) //{ // newWeldJoint.JointAttribute = values.Value("JointAttribute").ToString(); //} //BLL.WeldJointService.UpdateWeldJoint(newWeldJoint); BLL.WeldJointService.UpdateWeldJointAddG(newWeldJoint.WeldJointId, newWeldJoint.JointAttribute, Const.BtnAdd); } } } // 获取组批条件 var batchC = BLL.Project_SysSetService.GetSysSetBySetId("5", CurrUser.LoginProjectId); if (batchC != null) { string batchCondition = batchC.SetValue; // 新建日报 if (weldJointView.Count() == 0) { foreach (string row in Grid1.SelectedRowIDArray) { var t = BLL.WeldTaskService.GetWeldTaskById(row); var newWeldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(t.WeldJointId); errlog += InsertWeldingDailyItem(t.WeldJointId, t.CoverWelderId, t.BackingWelderId, newWeldJoint.JointAttribute, newWeldingDaily.WeldingDate, batchCondition, true); } } else { for (int i = 0; i < Grid1.Rows.Count; i++) { if (Grid1.SelectedRowIDArray.Contains(Grid1.Rows[i].RowID)) { var t = BLL.WeldTaskService.GetWeldTaskById(Grid1.Rows[i].RowID); var newWeldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(t.WeldJointId); errlog += InsertWeldingDailyItem(t.WeldJointId, t.CoverWelderId, t.BackingWelderId, newWeldJoint.JointAttribute, newWeldingDaily.WeldingDate, batchCondition, true); } else { var t = BLL.WeldTaskService.GetWeldTaskById(Grid1.Rows[i].RowID); errlog += BLL.WeldingDailyService .DeleteWeldingDailyItemByweldJointId(t.WeldJointId); } } } // 日报已存在的情况 暂时 //else //{ // var weldJoints = from x in weldJointView select x.WeldJointId; // foreach (var item in GetWeldingDailyItem) // { // // 如日报明细存在则只更新焊口信息,如进批条件改变,则只有删除后再重新增加 // if (weldJoints.Contains(item.WeldJointId)) // { // var newWeldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(item.WeldJointId); // newWeldJoint.WeldingDailyId = this.WeldingDailyId; // newWeldJoint.WeldingDailyCode = this.txtWeldingDailyCode.Text.Trim(); // newWeldJoint.CoverWelderId = item.CoverWelderId; // newWeldJoint.BackingWelderId = item.BackingWelderId; // if (!string.IsNullOrEmpty(item.JointAttribute)) // { // newWeldJoint.JointAttribute = item.JointAttribute; // } // BLL.WeldJointService.UpdateWeldJoint(newWeldJoint); // //更新焊口号 修改固定焊口号后 +G // BLL.WeldJointService.UpdateWeldJointAddG(newWeldJoint.WeldJointId, newWeldJoint.JointAttribute, Const.BtnAdd); // } // else // { // errlog += InsertWeldingDailyItem(item, newWeldingDaily.WeldingDate, batchCondition, true); // } // } //} } else { errlog += "请设置项目的组批条件"; } #region 焊工每天超过60达因的提示(暂不用) // 焊工每天超过60达因的提示(暂不用) //foreach (var item in GetWeldingDailyItem) //{ // if (!string.IsNullOrEmpty(item.CoverWelderId) && !string.IsNullOrEmpty(item.BackingWelderId)) // { // bool cWelder = BLL.Pipeline_WeldJointService.GetWelderLimitDN(this.ProjectId, item.CoverWelderId, newWeldingDaily.WeldingDate.Value); // bool bWelder = cWelder; // if (item.CoverWelderId != item.BackingWelderId) // { // bWelder = BLL.Pipeline_WeldJointService.GetWelderLimitDN(this.ProjectId, item.BackingWelderId, newWeldingDaily.WeldingDate.Value); // } // if (cWelder || bWelder) // { // if (cWelder) // { // var coverWelder = BLL.SitePerson_PersonService.GetSitePersonById(item.CoverWelderId); // if (coverWelder != null) // { // string txt = Resources.Lan.WelderCode + coverWelder.WelderCode + Resources.Lan.WeldingDiameter; // if (!errlog.Contains(txt)) // { // errlog += txt; // } // } // } // if (bWelder) // { // var backingWelder = BLL.SitePerson_PersonService.GetSitePersonById(item.BackingWelderId); // if (backingWelder != null) // { // string txt = Resources.Lan.WelderCode + backingWelder.WelderCode + Resources.Lan.WeldingDiameter; // if (!errlog.Contains(txt)) // { // errlog += txt; // } // } // } // } // } //} #endregion System.Threading.Tasks.Task.Run(() => { ChanggeState(); }); if (string.IsNullOrEmpty(errlog)) { ShowNotify("保存成功!", MessageBoxIcon.Success); drpJointAttribute_SelectedIndexChanged(null, null); BindGrid(null); //PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } else { // string okj = ActiveWindow.GetWriteBackValueReference(newWeldReportMain.WeldingDailyId) + ActiveWindow.GetHidePostBackReference(); Alert.ShowInTop("保存成功!" + "焊接明细中" + errlog, "提交结果", MessageBoxIcon.Warning); drpJointAttribute_SelectedIndexChanged(null, null); BindGrid(null); // ShowAlert("焊接明细中" + errlog, MessageBoxIcon.Warning); } } else { Alert.ShowInTop("焊工无资质焊接的焊口:" + eventArg, "提交结果", MessageBoxIcon.Warning); } } protected void btnAccept_Click(object sender, EventArgs e) { //PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(txtWeldingDailyCode.Text) + ActiveWindow.GetHidePostBackReference()); } #endregion #region 焊工资质判断 /// /// 一种焊接方法资质判断 /// /// /// /// /// /// /// /// /// private bool OneWmeIsOK(List welderQualifys, string wmeCode, string jointAttribute, string weldType, string ste, decimal? dia, decimal? sch) { bool isok = false; var mat = BLL.Base_MaterialService.GetMaterialByMaterialId(ste); var welderQ = from x in welderQualifys where wmeCode.Contains(x.WeldingMethod) && (mat == null || x.MaterialType.Contains(mat.MetalType ?? "")) && x.WeldType.Contains(weldType) select x; if (welderQ.Count() > 0) { if (jointAttribute == "安装口") { welderQ = welderQ.Where(x => x.IsCanWeldG == true); } if (welderQ.Count() > 0) { if (weldType == "1") // 1-对接焊缝 2-表示角焊缝,当为角焊缝时,管径和壁厚不限制 { var welderDiaQ = welderQ.Where(x => x.SizesMin <= dia || x.SizesMax == 0); if (welderDiaQ.Count() > 0) { var welderThick = welderDiaQ.Where(x => x.ThicknessMax >= sch || x.ThicknessMax == 0); // 只要有一个不限(为0)就通过 if (welderThick.Count() > 0) { isok = true; } } } else { isok = true; } } } return isok; } /// /// 两种焊接方法资质判断 /// /// /// /// /// /// /// /// /// /// /// private bool TwoWmeIsOK(List floorWelderQualifys, List cellWelderQualifys, string wmeCode1, string wmeCode2, string jointAttribute, string weldType, string ste, decimal? dia, decimal? sch) { bool isok = false; decimal? fThicknessMax = 0; decimal? cThicknessMax = 0; var mat = BLL.Base_MaterialService.GetMaterialByMaterialId(ste); var floorQ = from x in floorWelderQualifys where wmeCode1.Contains(x.WeldingMethod) && (mat == null || x.MaterialType.Contains(mat.MetalType ?? "")) && x.WeldType.Contains(weldType) // && (dia == null || x.SizesMin<=dia) select x; var cellQ = from x in cellWelderQualifys where wmeCode2.Contains(x.WeldingMethod) && (mat == null || x.MaterialType.Contains(mat.MetalType ?? "")) && x.WeldType.Contains(weldType) // && (dia == null || x.SizesMin <= dia) select x; if (floorQ.Count() > 0 && cellQ.Count() > 0) { if (jointAttribute == "安装口") { floorQ = floorQ.Where(x => x.IsCanWeldG == true); cellQ = cellQ.Where(x => x.IsCanWeldG == true); } if (floorQ.Count() > 0 && cellQ.Count() > 0) { if (weldType == "1") // 1-对接焊缝 2-表示角焊缝,当为角焊缝时,管径和壁厚不限制 { var floorDiaQ = floorQ.Where(x => x.SizesMin <= dia || x.SizesMax == 0); var cellDiaQ = cellQ.Where(x => x.SizesMin <= dia || x.SizesMax == 0); if (floorDiaQ.Count() > 0 && cellDiaQ.Count() > 0) { var fThick = floorDiaQ.Where(x => x.ThicknessMax == 0); var cThick = cellDiaQ.Where(x => x.ThicknessMax == 0); // 只要有一个不限(为0)就通过 if (fThick.Count() > 0 || cThick.Count() > 0) { isok = true; } else { fThicknessMax = floorQ.Max(x => x.ThicknessMax); cThicknessMax = cellQ.Max(x => x.ThicknessMax); if ((fThicknessMax + cThicknessMax) >= sch) { isok = true; } } } } else { isok = true; } } } return isok; } #endregion #region 日报明细插入(更新焊口信息),组批等 /// /// 日报明细插入(更新焊口信息),组批等 /// /// /// /// private string InsertWeldingDailyItem(string weldJointId, string coverWelderId, string backingWelderId, string jointAttribute, DateTime? weldingDate, string batchCondition, bool isSave) { string errlog = string.Empty; var newWeldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(weldJointId); if (newWeldJoint != null && string.IsNullOrEmpty(newWeldJoint.WeldingDailyId)) { if (!string.IsNullOrEmpty(coverWelderId) && !string.IsNullOrEmpty(backingWelderId)) { newWeldJoint.WeldingDailyId = this.WeldingDailyId; newWeldJoint.WeldingDailyCode = this.txtWeldingDailyCode.Text.Trim(); newWeldJoint.CoverWelderId = coverWelderId; newWeldJoint.BackingWelderId = backingWelderId; newWeldJoint.CoverWelderTeamGroupId = SitePerson_PersonService.GetSitePersonByProjectIdPersonId(this.CurrUser.LoginProjectId,coverWelderId).TeamGroupId; newWeldJoint.BackingWelderTeamGroupId = SitePerson_PersonService.GetSitePersonByProjectIdPersonId(this.CurrUser.LoginProjectId, backingWelderId).TeamGroupId; //if (item.WeldingLocationId != Const._Null) //{ // newWeldJoint.WeldingLocationId = item.WeldingLocationId; //} newWeldJoint.JointAttribute = jointAttribute; BLL.WeldJointService.UpdateWeldJoint(newWeldJoint); // 更新焊口号 修改固定焊口号后 +G BLL.WeldJointService.UpdateWeldJointAddG(newWeldJoint.WeldJointId, newWeldJoint.JointAttribute, Const.BtnAdd); if (isSave) { errlog = PointBatchService.AddBatchByWeldJointId(weldJointId, weldingDate, batchCondition);//自动组批 } } else { errlog = "焊口" + "【" + newWeldJoint.WeldJointCode + "】" + "未选择焊工"; } } return errlog; } #endregion #region 收集Grid页面信息 /// /// 收集Grid页面信息 /// /// private List CollectGridJointInfo() { List GetWeldingDailyItem = null; List getNewWeldReportItem = new List(); if (!string.IsNullOrEmpty(this.hdItemsString.Text)) { GetWeldingDailyItem = BLL.WeldingDailyService.GetWeldReportAddItem(this.hdItemsString.Text); } else if (string.IsNullOrEmpty(this.hdItemsString.Text) && this.WeldingDailyId != null) { GetWeldingDailyItem = BLL.WeldingDailyService.GetWeldingDailyItem(this.WeldingDailyId); } JArray mergedData = Grid1.GetMergedData(); foreach (JObject mergedRow in mergedData) { string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); string rowID = values.Value("WeldJointId").ToString(); var item = GetWeldingDailyItem.FirstOrDefault(x => x.WeldJointId == rowID); if (item != null) { var coverWelderCode = (from x in Funs.DB.SitePerson_Person where x.ProjectId == CurrUser.LoginProjectId && x.WelderCode == values.Value("CoverWelderId") select x).FirstOrDefault(); if (coverWelderCode != null) { item.CoverWelderCode = coverWelderCode.WelderCode; item.CoverWelderId = coverWelderCode.PersonId; } var backingWelderCode = (from x in Funs.DB.SitePerson_Person where x.ProjectId == CurrUser.LoginProjectId && x.WelderCode == values.Value("BackingWelderId") select x).FirstOrDefault(); if (backingWelderCode != null) { item.BackingWelderCode = backingWelderCode.WelderCode; item.BackingWelderId = backingWelderCode.PersonId; } if (!string.IsNullOrEmpty(values.Value("JointAttribute"))) { item.JointAttribute = values.Value("JointAttribute").ToString(); } getNewWeldReportItem.Add(item); } } return getNewWeldReportItem; } #endregion #region Grid 关闭弹出窗口事件 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { List GetWeldingDailyItem = BLL.WeldingDailyService.GetWeldReportAddItem(this.hdItemsString.Text); this.BindGrid(GetWeldingDailyItem); //SetDrpByDrpUnitChange(); //this.hdItemsString.Text = string.Empty; } #endregion #region 右键删除事件 /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { List GetWeldingDailyItem = this.CollectGridJointInfo(); foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var item = GetWeldingDailyItem.FirstOrDefault(x => x.WeldJointId == rowID); var p = BLL.PointBatchDetailService.GetBatchDetailByJotId(rowID); if (item != null && (p == null || (p != null && p.PointState == null))) { GetWeldingDailyItem.Remove(item); // 删除焊口所在批明细信息 if (p != null) { BLL.PointBatchDetailService.DeleteBatchDetail(item.WeldJointId); } // // 更新焊口信息 var updateWeldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(item.WeldJointId); if (updateWeldJoint != null) { updateWeldJoint.WeldingDailyId = null; updateWeldJoint.WeldingDailyCode = null; updateWeldJoint.CoverWelderId = null; updateWeldJoint.BackingWelderId = null; updateWeldJoint.CoverWelderTeamGroupId= null; updateWeldJoint.BackingWelderTeamGroupId = null; BLL.WeldJointService.UpdateWeldJoint(updateWeldJoint); } } else { Alert.ShowInTop("不能删除,已检测并审核!", MessageBoxIcon.Warning); } } BindGrid(GetWeldingDailyItem); ShowNotify("删除成功!", MessageBoxIcon.Success); } } #endregion #region 查找 protected void WeldingDateText_OnTextChanged(object sender, EventArgs e) { string perfix = string.Format("{0:yyyyMMdd}", Funs.GetNewDateTimeOrNow(this.txtWeldingDate.Text.Trim())) + "-" + this.CurrUser.PersonName + "-"; this.txtWeldingDailyCode.Text = BLL.SQLHelper.RunProcNewId("SpGetThreeNumber", "dbo.HJGL_WeldingDaily", "WeldingDailyCode", this.CurrUser.LoginProjectId, perfix); BindGrid(null); } /// /// 查找未焊接焊口 /// /// /// protected void ckSelect_Click(object sender, EventArgs e) { //string weldJointIds = string.Empty; //for (int i = 0; i < Grid1.Rows.Count; i++) //{ // string weldJointId = Grid1.DataKeys[i][0].ToString(); // weldJointIds = weldJointIds + weldJointId + "|"; //} //if (weldJointIds != string.Empty) //{ // weldJointIds = weldJointIds.Substring(0, weldJointIds.Length - 1); //} string weldJointIds = hdItemsString.Text.Trim(); if (!string.IsNullOrEmpty(this.drpUnit.SelectedValue) && this.drpUnit.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpUnitWork.SelectedValue) && this.drpUnitWork.SelectedValue != BLL.Const._Null) { string strList = this.drpUnitWork.SelectedValue + "|" + this.drpUnit.SelectedValue + "|" + this.WeldingDailyId; string window = String.Format("SelectDailyWeldJoint.aspx?strList={0}&weldJointIds={1}", strList, Server.UrlEncode(weldJointIds), "编辑 - "); //PageContext.RegisterStartupScript(Window1.GetSaveStateReference(hdItemsString.ClientID) + Window1.GetShowReference(window)); } else { Alert.ShowInTop("请选择单位和单位工程", MessageBoxIcon.Warning); } } #endregion protected void drpJointAttribute_SelectedIndexChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.WeldingDailyId)) { List GetWeldingDailyItem = BLL.WeldingDailyService.GetWeldingDailyItem(this.WeldingDailyId); this.BindGrid(GetWeldingDailyItem); // 初始化页面 } else { this.BindGrid(null); } } private void ChanggeState() { if (!string.IsNullOrEmpty(this.WeldingDailyId) && Grid1.SelectedRowIDArray.Length > 0) { foreach (var rowId in Grid1.SelectedRowIDArray) { var t = BLL.WeldTaskService.GetWeldTaskById(rowId); var newWeldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(t.WeldJointId); var daily = BLL.WeldingDailyService.GetPipeline_WeldingDailyByWeldingDailyId(WeldingDailyId); BLL.HJGL_PipelineComponentjointService.UpdateStateByWeldJointId(newWeldJoint.WeldJointId, (DateTime)daily.WeldingDate);//更改预制口实际时间和状态 PipelineService.UpdataDateByWeldJointId(newWeldJoint.WeldJointId);//更改安装口时间和状态 } /*List GetWeldingDailyItem = BLL.WeldingDailyService.GetWeldingDailyItem(this.WeldingDailyId); foreach (var item in GetWeldingDailyItem) { var daily = BLL.WeldingDailyService.GetPipeline_WeldingDailyByWeldingDailyId(WeldingDailyId); BLL.HJGL_PipelineComponentjointService.UpdateStateByWeldJointId(item.WeldJointId, (DateTime)daily.WeldingDate);//更改预制口实际时间和状态 PipelineService.UpdataDateByWeldJointId(item.WeldJointId);//更改安装口时间和状态 }*/ } } protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) { DataRowView row = e.DataItem as DataRowView; var id = row["WeldJointId"].ToString(); var hotProesssItem = Funs.DB.HJGL_HotProess_TrustItem.FirstOrDefault(x => x.WeldJointId == id); if (hotProesssItem != null) //已生成热处理委托,不能编辑或删除 { e.RowSelectable = false; // Grid1.DeleteRow(e.RowID); // Grid1.DeleteRow(e.RowID); } var pointBatchItem = Funs.DB.HJGL_Batch_PointBatchItem.FirstOrDefault(x => x.WeldJointId == id && x.PointState != null); if (pointBatchItem != null) //已生成委托,不能编辑或删除 { e.RowSelectable = false; // Grid1.DeleteRow(e.RowID); // Grid1.DeleteRow(e.RowID); } //for (int i = 0; i < this.Grid1.Rows.Count; i++) //{ // var hotProesssItem = Funs.DB.HJGL_HotProess_TrustItem.FirstOrDefault(x => x.WeldJointId == this.Grid1.Rows[i].DataKeys[1].ToString()); // if (hotProesssItem != null) //已生成热处理委托,不能编辑或删除 // { // Grid1.Rows[i].RowSelectable = false; // } // var pointBatchItem = Funs.DB.HJGL_Batch_PointBatchItem.FirstOrDefault(x => x.WeldJointId == this.Grid1.Rows[i].DataKeys[1].ToString() && x.PointState != null); // if (pointBatchItem != null) //已生成委托,不能编辑或删除 // { // Grid1.Rows[i].RowSelectable = false; // } //} } #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.WeldingDailyId)) { List GetWeldingDailyItem = BLL.WeldingDailyService.GetWeldingDailyItem(this.WeldingDailyId); this.BindGrid(GetWeldingDailyItem); // 初始化页面 } else { this.BindGrid(null); } } #endregion #region 批量填充焊工 /// /// /// /// /// protected void btnSaveWelder_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(drpCanWelder.SelectedValue)) { string[] selectedRowId = Grid1.SelectedRowIDArray; for (int i = 0; i < selectedRowId.Count(); i++) { string weldTaskId = selectedRowId[i]; var weldTask = BLL.WeldTaskService.GetWeldTaskById(weldTaskId); if (weldTask != null && string.IsNullOrEmpty(weldTask.CoverWelderId) && string.IsNullOrEmpty(weldTask.BackingWelderId)) { BLL.WeldTaskService.UpdateWelderTask(weldTaskId, drpCanWelder.SelectedValue); } } this.BindGrid(null); this.Grid1.SelectedRowIDArray = selectedRowId; drpCanWelder.Items.Clear(); } } protected void btnSelectWelder_Click(object sender, EventArgs e) { GetCanWelderDropDownList(); } /// /// 获取能焊焊工下拉列表 /// /// private void GetCanWelderDropDownList() { drpCanWelder.Items.Clear(); string[] selectedRowId = Grid1.SelectedRowIDArray; List canWelder = null; var taskList = from x in Funs.DB.HJGL_WeldTask where x.ProjectId == this.CurrUser.LoginProjectId select x; for (int i = 0; i < selectedRowId.Count(); i++) { Model.HJGL_WeldTask task = taskList.FirstOrDefault(x => x.WeldTaskId == selectedRowId[i]); if (!string.IsNullOrEmpty(task.CanWelderId)) { List jotCanWelder = task.CanWelderId.Split(',').ToList(); if (i == 0) { canWelder = jotCanWelder; } else { canWelder = canWelder.Intersect(jotCanWelder).ToList(); } } else { canWelder = null; break; } } if (canWelder != null) { var welder = from x in canWelder join y in Funs.DB.SitePerson_Person on x equals y.PersonId select new { WelderId = x, y.WelderCode }; drpCanWelder.DataValueField = "WelderId"; drpCanWelder.DataTextField = "WelderCode"; drpCanWelder.DataSource = welder; drpCanWelder.DataBind(); } } #endregion } }