using System; using System.Collections.Generic; using System.Data; using System.Linq; using BLL; namespace FineUIPro.Web.WeldingProcess.TrustManage { public partial class OpenResetPoint : PageBase { #region 定义项 /// /// 批主键 /// public string PointBatchId { get { return (string)ViewState["PointBatchId"]; } set { ViewState["PointBatchId"] = value; } } #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.PointBatchId = Request.Params["PointBatchId"]; this.BindGrid(); } } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { List toDoMatterList = BLL.Batch_PointBatchItemService.GetViewPointBatchItemByPointBatchId(this.PointBatchId); DataTable tb = this.LINQToDataTable(toDoMatterList); // 2.获取当前分页数据 //var table = this.GetPagedDataTable(GridNewDynamic, tb1); Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); string ids = string.Empty; for (int i = 0; i < this.Grid1.Rows.Count; i++) { var pointItem = BLL.Batch_PointBatchItemService.GetPointBatchItemByPointBatchItemId(this.Grid1.Rows[i].DataKeys[0].ToString()); if (pointItem != null && pointItem.PointState == "1") { ids += pointItem.PointBatchItemId + ","; } } if (!string.IsNullOrEmpty(ids)) { ids = ids.Substring(0, ids.Length - 1); this.Grid1.SelectedRowIDArray = ids.Split(','); } } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { this.BindGrid(); } #endregion #region 确定按钮 /// /// 确定按钮 /// /// /// protected void btnAccept_Click(object sender, EventArgs e) { Model.HJGLDB db = Funs.DB; string[] selectedRowIDArray = Grid1.SelectedRowIDArray; // 判断批进入哪个委托单 var getBatchTrusts = from x in db.Batch_BatchTrust where x.TopointBatch.Contains(this.PointBatchId) select x; var firstBatchTrust = getBatchTrusts.FirstOrDefault(); for (int i = 0; i < this.Grid1.Rows.Count; i++) { string pointBatchItemId = this.Grid1.Rows[i].DataKeys[0].ToString(); if (selectedRowIDArray.Contains(pointBatchItemId)) { // 找到已点口的明细ID var item = db.Batch_PointBatchItem.FirstOrDefault(p => p.PointBatchItemId == pointBatchItemId && p.PointState == "1"); if (item == null) { string trustBatchItemId = string.Empty; BLL.Batch_PointBatchItemService.UpdatePointBatchItem(pointBatchItemId, "1", DateTime.Now.Date, null); var q = BLL.Batch_PointBatchItemService.GetPointBatchItemByPointBatchItemId(pointBatchItemId); if (getBatchTrusts.Count() == 1) { if (BLL.Batch_PointBatchService.GetIsGenerateTrust(pointBatchItemId)) // 生成委托单的条件判断 { Model.Batch_BatchTrustItem trustItem = new Model.Batch_BatchTrustItem(); trustBatchItemId = SQLHelper.GetNewID(typeof(Model.Batch_BatchTrustItem)); trustItem.TrustBatchItemId = trustBatchItemId; trustItem.WeldJointId = q.WeldJointId; trustItem.TrustBatchId = firstBatchTrust.TrustBatchId; trustItem.PointBatchItemId = pointBatchItemId; trustItem.CreateDate = DateTime.Now; Batch_BatchTrustItemService.AddBatchTrustItem(trustItem); Model.Batch_NDE che = db.Batch_NDE.FirstOrDefault(y => y.TrustBatchId == firstBatchTrust.TrustBatchId); var pointBatch = BLL.Batch_PointBatchService.GetPointBatchById(this.PointBatchId); if (che != null) { Model.Batch_NDEItem checkItem = new Model.Batch_NDEItem { NDEItemID = BLL.SQLHelper.GetNewID(typeof(Model.Batch_NDEItem)), NDEID = che.NDEID, TrustBatchItemId = trustBatchItemId, DetectionTypeId = pointBatch.DetectionTypeId, CheckResult = null }; BLL.Batch_NDEItemService.AddNDEItem(checkItem); } // 回写委托单已创建 q.IsBuildTrust = true; db.SubmitChanges(); } } } } else { var noSubmit = from x in db.Batch_PointBatchItem join y in db.Batch_BatchTrustItem on x.PointBatchItemId equals y.PointBatchItemId join z in db.Batch_NDEItem on y.TrustBatchItemId equals z.TrustBatchItemId where x.PointBatchItemId == pointBatchItemId && z.SubmitDate.HasValue select x; // 未提交 if (noSubmit.Count() == 0) { // 删除委托单下的明细(等于1表示第一次进入委托单,大于1表示这个批已不止一次进入委托单,说明已检测过,不能再打开重新点口) if (getBatchTrusts.Count() == 1) { // 找到已点口的明细ID var item = db.Batch_PointBatchItem.FirstOrDefault(p => p.PointBatchItemId == pointBatchItemId && p.PointState == "1"); // 找到委托单里的明细 if (item != null) { var trust = db.Batch_BatchTrustItem.FirstOrDefault(p => p.PointBatchItemId == item.PointBatchItemId && p.TrustBatchId == firstBatchTrust.TrustBatchId); if (trust != null) { string trustBatchId = trust.TrustBatchId; Model.Batch_NDEItem checkItem = db.Batch_NDEItem.FirstOrDefault(x => x.TrustBatchItemId == trust.TrustBatchItemId); if (checkItem != null) { string checkId = checkItem.NDEID; if (checkItem.SubmitDate == null) { // 删除检测单里明细 Batch_NDEItemService.DeleteNDEItemByNDEItemID(checkItem.NDEItemID); var c = BLL.Batch_NDEItemService.GetNDEItemByNDEID(checkId); if (c.Count() == 0) { // 当没有明细时删除对应主表 BLL.Batch_NDEService.DeleteNDEById(checkId); } } } if ((checkItem != null && checkItem.SubmitDate == null) || checkItem == null) { // 删除委托单里明细 Batch_BatchTrustItemService.DeleteTrustItemByTrustBatchItemId(trust.TrustBatchItemId); var t = BLL.Batch_BatchTrustItemService.GetBatchTrustItemByTrustBatchId(trustBatchId); if (t.Count() == 0) { // 当没有明细时删除对应主表 BLL.Batch_BatchTrustService.DeleteBatchTrustById(trustBatchId); } } } } } // 未选中 var pItem = db.Batch_PointBatchItem.FirstOrDefault(p => p.PointBatchItemId == pointBatchItemId); pItem.IsBuildTrust = null; db.SubmitChanges(); BLL.Batch_PointBatchItemService.UpdatePointBatchItem(pointBatchItemId, null, null, null); } } BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PointManageMenuId, Const.BtnOpenResetPoint, this.PointBatchId); } if (selectedRowIDArray.Count() > 0) { BLL.Batch_PointBatchService.UpdatePointBatch(this.PointBatchId, DateTime.Now); } else { BLL.Batch_PointBatchService.UpdatePointBatch(this.PointBatchId, null); } PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } #endregion } }