/// <summary> /// 新增工程品檢記錄 /// </summary> /// <param name="model">model</param> /// <param name="tran">SqlTransaction</param> /// <returns></returns> public bool AddProjectQCRecord(ProjectQCRecord model, SqlTransaction tran) { try { MappingHelper.HandleNullProperty(model); StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ProjectQCRecord_pqc("); strSql.Append("pqc_RecordID,pqc_SPLID,pqc_iQCTimes,pqc_iProdQTY,pqc_iQCQTY,pqc_dQCBeginTime,pqc_dQCEndTime,pqc_cType,pqc_cMode,pqc_lSync,pqc_dAddDate,pqc_dLastDate)"); strSql.Append(" values ("); strSql.Append("@pqc_RecordID,@pqc_SPLID,@pqc_iQCTimes,@pqc_iProdQTY,@pqc_iQCQTY,@pqc_dQCBeginTime,@pqc_dQCEndTime,@pqc_cType,@pqc_cMode,@pqc_lSync,@pqc_dAddDate,@pqc_dLastDate)"); SqlParameter[] parameters = { DbHelperSQL.MakeInParam("@pqc_RecordID", SqlDbType.UniqueIdentifier,16, model.RecordID), DbHelperSQL.MakeInParam("@pqc_SPLID", SqlDbType.UniqueIdentifier,16, model.pqc_SPLID), DbHelperSQL.MakeInParam("@pqc_iQCTimes", SqlDbType.Int,4, model.pqc_iQCTimes), DbHelperSQL.MakeInParam("@pqc_iProdQTY", SqlDbType.Int,4, model.pqc_iProdQTY), DbHelperSQL.MakeInParam("@pqc_iQCQTY", SqlDbType.Int,4, model.pqc_iQCQTY), DbHelperSQL.MakeInParam("@pqc_dQCBeginTime", SqlDbType.DateTime, 0, model.pqc_dQCBeginTime), DbHelperSQL.MakeInParam("@pqc_dQCEndTime", SqlDbType.DateTime, 0, model.pqc_dQCEndTime), DbHelperSQL.MakeInParam("@pqc_cType", SqlDbType.NVarChar,10, model.pqc_cType), DbHelperSQL.MakeInParam("@pqc_cMode", SqlDbType.NVarChar,20, model.pqc_cMode), DbHelperSQL.MakeInParam("@pqc_lSync", SqlDbType.Bit,1, 0),//model.pqc_lSync; DbHelperSQL.MakeInParam("@pqc_dAddDate", SqlDbType.DateTime, 0, DateTime.Now), DbHelperSQL.MakeInParam("@pqc_dLastDate", SqlDbType.DateTime, 0, DateTime.Now) }; DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, strSql.ToString(), parameters); //品檢問題 if (model.QCProblems != null && model.QCProblems.Count > 0) { for (int i = 0; i < model.QCProblems.Count; i++) { ProjectQCRecordProblem problem = model.QCProblems[i]; if (problem != null && problem.RecordID != null && problem.RecordID != Guid.Empty) { StringBuilder strSqlProblem = new StringBuilder(); strSqlProblem.Append("insert into ProjectQCProblem_pqcp("); strSqlProblem.Append("pqcp_RecordID,pqcp_PQCID,pqcp_iSeq,pqcp_iProblemID,pqcp_lSync,pqcp_dAddDate,pqcp_dLastDate,pqcp_iDefectiveQty,pqcp_iWasteQty)"); strSqlProblem.Append(" values ("); strSqlProblem.Append("@pqcp_RecordID,@pqcp_PQCID,@pqcp_iSeq,@pqcp_iProblemID,@pqcp_lSync,@pqcp_dAddDate,@pqcp_dLastDate,@pqcp_iDefectiveQty,@pqcp_iWasteQty)"); SqlParameter[] rParameters = { DbHelperSQL.MakeInParam("@pqcp_RecordID", SqlDbType.UniqueIdentifier,16, problem.RecordID), DbHelperSQL.MakeInParam("@pqcp_PQCID", SqlDbType.UniqueIdentifier,16, model.RecordID), DbHelperSQL.MakeInParam("@pqcp_iSeq", SqlDbType.Int,4, problem.pqcp_iSeq), DbHelperSQL.MakeInParam("@pqcp_iProblemID", SqlDbType.Int, 4, problem.pqcp_iProblemID), DbHelperSQL.MakeInParam("@pqcp_lSync", SqlDbType.Bit,1, 0), DbHelperSQL.MakeInParam("@pqcp_dAddDate", SqlDbType.DateTime, 0,DateTime.Now), DbHelperSQL.MakeInParam("@pqcp_dLastDate", SqlDbType.DateTime, 0, DateTime.Now), DbHelperSQL.MakeInParam("@pqcp_iDefectiveQty", SqlDbType.Int, 4, problem.pqcp_iDefectiveQty), DbHelperSQL.MakeInParam("@pqcp_iWasteQty", SqlDbType.Int, 4, problem.pqcp_iWasteQty) }; DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, strSqlProblem.ToString(), rParameters); } } } return true; } catch (Exception ex) { throw ex; } }
/// <summary> /// 獲取指定的品檢問題顯示記錄 /// </summary> /// <param name="qcRecord">品檢記錄</param> /// <param name="SubRecordID">品檢問題記錄ID</param> /// <returns></returns> private QCPloblemViewInfo GetQCViewInfo(ProjectQCRecord qcRecord, Guid SubRecordID) { QCPloblemViewInfo qcViewInfo = null; if (qcRecord != null) { List<ProjectQCQualityIssues> listIssues = base.QCQualityIssues; if (qcRecord.QCProblems != null) { ProjectQCRecordProblem problem = qcRecord.QCProblems.Where(x => x.RecordID == SubRecordID).FirstOrDefault(); if (problem != null) { qcViewInfo = new QCPloblemViewInfo(qcRecord); qcViewInfo.SubRecordID = problem.RecordID; qcViewInfo.ProblemSeq = "問題" + problem.pqcp_iSeq.ToString(); qcViewInfo.DefectiveQty = problem.pqcp_iDefectiveQty; qcViewInfo.WasteQty = problem.pqcp_iWasteQty; qcViewInfo.ProblemID = problem.pqcp_iProblemID; if (listIssues != null) { ProjectQCQualityIssues issue = listIssues.FirstOrDefault(x => x.Code.Trim() == problem.pqcp_iProblemID.ToString()); if (issue != null) { qcViewInfo.ProblemName = issue.Description.Trim(); qcViewInfo.ProblemDealMethod = issue.Solution.Trim(); } } } } } return qcViewInfo; }
/// <summary> /// 為品檢記錄添加一個品檢問題記錄 /// </summary> /// <param name="qcRecord">品檢記錄</param> /// <param name="WasteQty">廢品數量</param> /// <param name="DefectiveQty">次品數量</param> /// <param name="ProblemID">問題ID</param> private void AddQCIssueRecord(ProjectQCRecord qcRecord, int WasteQty, int DefectiveQty, int ProblemID) { int iMaxSeq = 0; if (qcRecord.QCProblems == null) { qcRecord.QCProblems = new List<ProjectQCRecordProblem>(); } else { if (qcRecord.QCProblems.Count > 0) { ProjectQCRecordProblem emptyProblem = qcRecord.QCProblems.Where(x => x.RecordID == Guid.Empty).FirstOrDefault(); if (emptyProblem != null) { qcRecord.QCProblems.Remove(emptyProblem); } ProjectQCRecordProblem problemOrderByMax = qcRecord.QCProblems.OrderByDescending(x => x.pqcp_iSeq).FirstOrDefault(); if (problemOrderByMax != null) { iMaxSeq = problemOrderByMax.pqcp_iSeq + 1; } else { iMaxSeq = 1; } } else { iMaxSeq = 1; } } ProjectQCRecordProblem problem = new ProjectQCRecordProblem(); problem.RecordID = Guid.NewGuid(); problem.pqcp_iWasteQty = WasteQty; problem.pqcp_iDefectiveQty = DefectiveQty; problem.pqcp_iProblemID = ProblemID; problem.pqcp_iSeq = iMaxSeq; problem.RecordEditStatus = 1; qcRecord.QCProblems.Add(problem); }
/// <summary> /// 創建品檢記錄 /// </summary> /// <param name="IsAutoAdd">是否系統自動新增</param> /// <returns></returns> private ProjectQCRecord CreateQCRecord(bool IsAutoAdd) { int iMaxRecord = 0; ProjectQCRecord recLastQC = base.QCRecords.Where(p => p.pqc_SPLID == base.ShiftProjectID).OrderByDescending(p => p.pqc_iQCTimes).FirstOrDefault(); if (recLastQC != null) { iMaxRecord = recLastQC.pqc_iQCTimes;//獲取當前班次內工程的最新品檢次數 } ProjectQCRecord l_objQCRecord = new ProjectQCRecord(); l_objQCRecord.RecordID = Guid.NewGuid(); l_objQCRecord.AddDate = DateTime.Now; l_objQCRecord.LastDate = DateTime.Now; l_objQCRecord.pqc_iQCQTY = 0; l_objQCRecord.pqc_iQCTimes = iMaxRecord + 1; if (IsAutoAdd) { l_objQCRecord.pqc_iProdQTY = base.RealTimeProductionQty; l_objQCRecord.pqc_dQCBeginTime = DateTime.Now; l_objQCRecord.pqc_cMode = CustEnum.RecordMode.AUTO.ToString(); l_objQCRecord.pqc_cType = CustEnum.RecordType.NORMAL.ToString(); } else { l_objQCRecord.pqc_iProdQTY = 0; l_objQCRecord.pqc_cMode = CustEnum.RecordMode.MANUAL.ToString(); l_objQCRecord.pqc_cType = CustEnum.RecordType.SUPPLEMENT.ToString(); } l_objQCRecord.pqc_dQCEndTime = null; l_objQCRecord.pqc_SPLID = base.ShiftProjectID; l_objQCRecord.RecordEditStatus = 1; AddEmptyQCIssueRecord(l_objQCRecord);//添加空的問題記錄,用於顯示 return l_objQCRecord; }
/// <summary> /// 為品檢記錄添加一個空的品檢問題記錄 /// </summary> /// <param name="qcRecord">品檢記錄</param> private void AddEmptyQCIssueRecord(ProjectQCRecord qcRecord) { if (qcRecord.QCProblems == null) { qcRecord.QCProblems = new List<ProjectQCRecordProblem>(); } ProjectQCRecordProblem problem = new ProjectQCRecordProblem(); problem.RecordID = Guid.Empty; problem.pqcp_iDefectiveQty = 0; problem.pqcp_iProblemID = -1; problem.pqcp_iSeq = 1; problem.pqcp_iWasteQty = 0; problem.RecordEditStatus = 1; qcRecord.QCProblems.Add(problem); }