using System; using System.Collections.Generic; using System.Linq; using BLL; using NPOI.SS.Formula.Functions; namespace FineUIPro.Web.WeldingProcess.CheckManage { public partial class RepairNotice : PageBase { protected void Page_Load(object sender, EventArgs e) { string ndeItemId = Request.Params["NDEItemID"]; var q = BLL.Batch_NDEItemService.GetNDEItemViewById(ndeItemId); txtPipeCode.Text = q.PipelineCode; txtWeldJointCode.Text = q.WeldJointCode; txtWelder.Text = q.WelderCode; txtJudgeGrade.Text = q.JudgeGrade; txtRepairLocation.Text = q.RepairLocation; txtCheckDefects.Text = BLL.Base_DefectService.GetDefectNameStrByDefectIdStr(q.CheckDefects); var repair = BLL.RepairRecordService.GetRepairRecordByNdeItemId(ndeItemId); if (repair == null) { var mark = from x in BLL.Funs.DB.Repair_RepairRecord where x.WeldJointId == q.WeldJointId && x.DetectionTypeId == q.DetectionTypeId orderby x.RepairMark descending select x; if (mark.Count() == 0) { if (q.PassFilm != q.TotalFilm) { txtRepairMark.Text = "R1"; } if (q.Remark.Contains("修磨")) { txtRepairMark.Text = "P1"; } if (q.Remark.Contains("异物")) { txtRepairMark.Text = "S1"; } } else { string m = mark.First().RepairMark; string first = m.Substring(0, 1); string last = m.Substring(1, 1); int n = Convert.ToInt32(last) + 1; txtRepairMark.Text = first + n.ToString(); } btnSubmit.Hidden = false; } else { btnSubmit.Hidden = true; txtRepairMark.Text = "R1"; if (!string.IsNullOrEmpty(repair.PhotoUrl)) { imgPhoto.ImageUrl = repair.PhotoUrl; } } } protected void btnSubmit_Click(object sender, EventArgs e) { string ndeItemId = Request.Params["NDEItemID"]; var q = BLL.Batch_NDEItemService.GetNDEItemViewById(ndeItemId); var repair = BLL.RepairRecordService.GetRepairRecordByNdeItemId(ndeItemId); Model.Repair_RepairRecord newItem = new Model.Repair_RepairRecord(); string newJointCode = string.Empty; if (repair == null) { if (q.CheckResult != null) { newItem.RepairRecordId = SQLHelper.GetNewID(typeof(Model.Repair_RepairRecord)); string code = q.TrustBatchCode; //if (code.Substring(code.Length - 2, 1) == "R") //{ // string first = code.Substring(0, code.Length - 1); // string last = code.Substring(code.Length - 1); // int n = Convert.ToInt32(last) + 1; // newItem.RepairRecordCode = first + n.ToString(); // newJointCode = q.WeldJointCode.Substring(0, q.WeldJointCode.Length - 2) + "R" + n.ToString(); //} //else //{ // if (q.CheckResult != "1") // 不合格 // { // if (code.Substring(code.Length - 3, 2) == "EX") // { // newItem.RepairRecordCode = q.TrustBatchCode.Substring(0, code.Length - 3) + "-" + "EX1R1"; // } // else // { // newItem.RepairRecordCode = q.TrustBatchCode + "R1"; // } // if (!q.WeldJointCode.Contains("R1")) // { // newJointCode = q.WeldJointCode + "R1"; // } // else // { // newJointCode = q.WeldJointCode; // } // } // else // 合格但有修磨或异物 // { // if (q.Remark.Contains("修磨")) // { // newItem.RepairRecordCode = q.TrustBatchCode + "P1"; // if (!q.WeldJointCode.Contains("P1")) // { // newJointCode = q.WeldJointCode + "P1"; // } // else // { // newJointCode = q.WeldJointCode; // } // } // if (q.Remark.Contains("异物")) // { // newItem.RepairRecordCode = q.TrustBatchCode + "S1"; // if (!q.WeldJointCode.Contains("S1")) // { // newJointCode = q.WeldJointCode + "S1"; // } // else // { // newJointCode = q.WeldJointCode; // } // } // } // #region 原逻辑 // //if (code.Substring(code.Length - 3, 2) == "EX") // //{ // // newItem.RepairRecordCode = q.TrustBatchCode.Substring(0, code.Length - 3) + "-" + "EX1R1"; // // if (!q.WeldJointCode.Contains("R1")) // // { // // newJointCode = q.WeldJointCode + "R1"; // // } // // else // // { // // newJointCode = q.WeldJointCode; // // } // //} // //else // //{ // // if (q.Remark.Contains("修磨")) // // { // // newItem.RepairRecordCode = q.TrustBatchCode + "P1"; // // if (!q.WeldJointCode.Contains("P1")) // // { // // newJointCode = q.WeldJointCode + "P1"; // // } // // else // // { // // newJointCode = q.WeldJointCode; // // } // // } // // else if (q.Remark.Contains("异物")) // // { // // newItem.RepairRecordCode = q.TrustBatchCode + "S1"; // // if (!q.WeldJointCode.Contains("S1")) // // { // // newJointCode = q.WeldJointCode + "S1"; // // } // // else // // { // // newJointCode = q.WeldJointCode; // // } // // } // // else // // { // // newItem.RepairRecordCode = q.TrustBatchCode + "R1"; // // if (!q.WeldJointCode.Contains("R1")) // // { // // newJointCode = q.WeldJointCode + "R1"; // // } // // else // // { // // newJointCode = q.WeldJointCode; // // } // // } // //} // #endregion //} if (code.Substring(code.Length - 2, 1)=="R"|| code.Substring(code.Length - 2, 1) == "P" || code.Substring(code.Length - 2, 1) == "S") { newItem.RepairRecordCode = code.Substring(0,code.Length - 2) + txtRepairMark.Text; newJointCode = q.WeldJointCode.Substring(0, q.WeldJointCode.Length - 2)+txtRepairMark.Text; } else { newItem.RepairRecordCode = code + txtRepairMark.Text; newJointCode = q.WeldJointCode + txtRepairMark.Text; } var isExistRepairRecordCode = from x in Funs.DB.Repair_RepairRecord where x.RepairRecordCode == newItem.RepairRecordCode select x; if (isExistRepairRecordCode.Count() > 0) { ShowNotify("该返修号已存在!请修改已存在的返修号", MessageBoxIcon.Warning); return; } // 回写焊口号 var weldJoint = BLL.Pipeline_WeldJointService.GetWeldJointByWeldJointId(q.WeldJointId); //joint.WeldJointCode = newJointCode; //joint.OldWeldJointCode = q.WeldJointCode; //Funs.DB.SubmitChanges(); Model.Pipeline_WeldJoint newWeldJoint = new Model.Pipeline_WeldJoint { WeldJointId = SQLHelper.GetNewID(typeof(Model.Pipeline_WeldJoint)), ProjectId = weldJoint.ProjectId, PipelineId = weldJoint.PipelineId, WeldJointCode = newJointCode, WeldTypeId = weldJoint.WeldTypeId, Material1Id = weldJoint.Material1Id, Material2Id = weldJoint.Material2Id, Thickness = weldJoint.Thickness, Dia = weldJoint.Dia, Size = weldJoint.Size, JointAttribute = weldJoint.JointAttribute, JointArea = weldJoint.JointArea, WeldingMethodId = weldJoint.WeldingMethodId, IsHotProess = weldJoint.IsHotProess, WeldingLocationId = weldJoint.WeldingLocationId, WeldMatId = weldJoint.WeldMatId, WeldSilkId = weldJoint.WeldSilkId, GrooveTypeId = weldJoint.GrooveTypeId, PipeSegment = weldJoint.PipeSegment, PipeAssembly1Id = weldJoint.PipeAssembly1Id, PipeAssembly2Id = weldJoint.PipeAssembly2Id, PipeAssemblyCount = weldJoint.PipeAssemblyCount, HeartNo1 = weldJoint.HeartNo1, HeartNo2 = weldJoint.HeartNo2, LastTemp = weldJoint.LastTemp, CellTemp = weldJoint.CellTemp, PrepareTemp = weldJoint.PrepareTemp, Electricity = weldJoint.Electricity, Voltage = weldJoint.Voltage, TestPackageNo = weldJoint.TestPackageNo, WeldingDailyCode = weldJoint.WeldingDailyCode, BackingWelderId = weldJoint.BackingWelderId, CoverWelderId = weldJoint.CoverWelderId, WeldingDailyId = weldJoint.WeldingDailyId, PipingClassId = weldJoint.PipingClassId, Specification = weldJoint.Specification, DoneDin = weldJoint.DoneDin, SystemNumber = weldJoint.SystemNumber, Remark = weldJoint.Remark, IsGoldJoint = weldJoint.IsGoldJoint, IsPMI = weldJoint.IsPMI, WPQId = weldJoint.WPQId, DetectionType = weldJoint.DetectionType, PageNum = weldJoint.PageNum, ANSISCH = weldJoint.ANSISCH, OldWeldJointCode = weldJoint.OldWeldJointCode, }; string WeldJointId= BLL.Pipeline_WeldJointService.AddWeldJointRef(newWeldJoint); newItem.ProjectId = q.ProjectId; newItem.UnitId = q.UnitId; newItem.InstallationId = q.InstallationId; newItem.WorkAreaId = q.WorkAreaId; newItem.NoticeDate = DateTime.Now; newItem.NDEItemID = ndeItemId; newItem.WeldJointId = WeldJointId; newItem.DetectionTypeId = q.DetectionTypeId; newItem.WelderId = q.BackingWelderId; newItem.RepairLocation = q.RepairLocation; newItem.CheckDefects = txtCheckDefects.Text; newItem.RepairMark = txtRepairMark.Text; newItem.PhotoUrl = imgPhoto.ImageUrl; BLL.RepairRecordService.AddRepairRecord(newItem); } else { ShowNotify("没有检测结果!不能生成委托单", MessageBoxIcon.Warning); } } else { ShowNotify("已生成返修通知单!不能重复生成", MessageBoxIcon.Warning); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); //repair.CheckDefects = txtCheckDefects.Text; //repair.RepairMark = txtRepairMark.Text; //repair.PhotoUrl = imgPhoto.ImageUrl; //BLL.RepairRecordService.UpdateRepairRecord(repair); } ShowNotify("生成返修通知单!", MessageBoxIcon.Success); } #region 上传电子签名图片 /// /// 上传照片 /// /// /// protected void filePhoto_FileSelected(object sender, EventArgs e) { if (filePhoto.HasFile) { string fileName = filePhoto.ShortFileName; if (!ValidateFileType(fileName)) { ShowNotify("无效的文件类型!"); return; } fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_"); fileName = DateTime.Now.Ticks.ToString() + "_" + fileName; filePhoto.SaveAs(Server.MapPath("~/upload/" + fileName)); imgPhoto.ImageUrl = "~/upload/" + fileName; // 清空文件上传组件 filePhoto.Reset(); } } #endregion } }