public bool Save(E_tb_TestReport eTestReport) { //检验数据 List <E_ReportData> ReportDataList = new List <E_ReportData>(); string strJson = eTestReport.TestReportDataJson; if (!string.IsNullOrEmpty(strJson)) { strJson = strJson.Replace("\r\n", "").Replace("\n", ""); ReportDataList = JsonHelper.JsonDeserialize <List <E_ReportData> >(strJson); } //删除原有检验数据 tTestReportData.DeleteByWhere("ReportID=" + eTestReport.ReportID); foreach (E_ReportData item in ReportDataList) { E_tb_TestReportData eTestReportData = new E_tb_TestReportData(); eTestReportData.ReportID = eTestReport.ReportID; eTestReportData.TestName = item.TestName; eTestReportData.TestStandard = item.TestStandard; eTestReportData.TestResult = item.TestResult; eTestReportData.QualifiedLevel = item.QualifiedLevel; eTestReportData.TestPersonnelName = item.TestPersonnelName; eTestReportData.RecordID = int.Parse(item.RecordID); eTestReportData.RecordFilePath = item.RecordFilePath; tTestReportData.Add(eTestReportData); } //结论 DataTable TestReportDataDT = tTestReportData.GetList("ReportID=" + eTestReport.ReportID + " and QualifiedLevel=''").Tables[0]; eTestReport.EditPersonnelID = CurrentUserInfo.PersonnelID; eTestReport.AreaID = tInPersonnel.GetModel(eTestReport.MainTestPersonnelID.Value).AreaID; eTestReport.RecordIDS = eTestReport.RecordIDS.TrimEnd(','); eTestReport.TaskNoS = eTestReport.TaskNoS.TrimEnd(','); eTestReport.UpdateTime = DateTime.Now; tTestReport.Update(eTestReport); //判断检验报告是否审核通过 if (eTestReport.ApprovalPersonnelID > 0 && eTestReport.examinePersonnelID > 0 && eTestReport.MainTestPersonnelID > 0) { dTestReport.ExpePlanPass(eTestReport.ReportID.ToString()); } return(true); }
/// <summary> /// 更新检验报告 /// </summary> /// <param name="eOriginalRecord"></param> /// <param name="eExpePlan"></param> public JsonResult UpdateTestReport(int RecordID) { E_tb_OriginalRecord eOriginalRecord = _dOriginalRecord.GetModel(new E_tb_OriginalRecord() { RecordID = RecordID }); E_tb_ExpePlan eExpePlan = _dExpePlan.GetExpePlanInfo(new E_tb_ExpePlan() { TaskNo = eOriginalRecord.TaskNo }); tb_Sample eSample = tSample.GetModel(eOriginalRecord.SampleID.Value); string productNum = eSample.protNum;//产品批次 E_tb_TestReport eTestReport = null; var tempmodel = tTestReport.GetModelList(" A.SampleNum = '" + eSample.sampleNum + "'"); if (tempmodel != null && tempmodel.Count > 0) { eTestReport = tempmodel.First(); eTestReport.SampleNum = eSample.sampleNum; //样品编号 eTestReport.SampleName = eSample.name; //样品名称 } if (eTestReport == null) { eTestReport = new E_tb_TestReport(); eTestReport.productNum = productNum; //批次号 eTestReport.SampleNum = eSample.sampleNum; //样品编号 eTestReport.SampleName = eSample.name; //样品名称 eTestReport.ProductionTime = eSample.productDate; //生产日期 eTestReport.Specifications = eSample.modelType; //规格型号 eTestReport.ShelfLife = eSample.expirationDate; //保质期 string Department = "/"; if (eSample.isDetection) { Department = eSample.detectionCompany; } else { var client = new BLL.ClientManage.T_tb_ClientManage().GetModel(Convert.ToInt32(eSample.InspectCompany)); Department = (client != null ? client.ClientName : ""); } eTestReport.Department = Department; //送/抽检单位 eTestReport.SendTestAddress = eSample.InspectAddress; //送检单位地址 eTestReport.SamplingPlace = eSample.detectionAdress; //抽样地点 eTestReport.SamplingCompany = eSample.detectionCompany; //抽样单位 eTestReport.SamplingPersonnel = eSample.detectionUser; //抽样者 eTestReport.Packing = eSample.packaging; //包装形式 eTestReport.SamplingTime = eSample.detectionDate; //抽样日期 eTestReport.TestBasis = new BLL.Laboratory.T_tb_Project().GetModel(eOriginalRecord.ProjectID.Value).ExpeMethod; eTestReport.TestTime = eOriginalRecord.DetectTime; //检验日期 DataTable dt = tOriginalRecord.GetRecordIDListBySampleID(int.Parse(eExpePlan.SampleID.ToString())); string RecordIDS = ""; if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { RecordIDS += dt.Rows[i]["RecordID"].ToString() + ","; } RecordIDS = RecordIDS.TrimEnd(','); } eTestReport.RecordIDS = RecordIDS;//原始记录IDS DataTable dtExpePlan = tExpePlan.GetList("SampleID=" + eExpePlan.SampleID.ToString()).Tables[0]; string TaskNoS = ""; if (dtExpePlan != null && dtExpePlan.Rows.Count > 0) { for (int i = 0; i < dtExpePlan.Rows.Count; i++) { TaskNoS += dtExpePlan.Rows[i]["PlanID"].ToString() + ","; } TaskNoS = TaskNoS.TrimEnd(','); } eTestReport.TaskNoS = TaskNoS;//任务单号 对应的检验计划IDS eTestReport.EditPersonnelID = CurrentUserInfo.PersonnelID; eTestReport.AreaID = CurrentUserInfo.AreaID; eTestReport.AddTime = Convert.ToDateTime(DateTime.Now.ToShortDateString()); eTestReport.UpdateTime = DateTime.Now; eTestReport.ReportID = tTestReport.Add(eTestReport); } else { DataTable dt = tOriginalRecord.GetRecordIDListBySampleID(int.Parse(eExpePlan.SampleID.ToString())); string RecordIDS = ""; if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { RecordIDS += dt.Rows[i]["RecordID"].ToString() + ","; } RecordIDS = RecordIDS.TrimEnd(','); } eTestReport.RecordIDS = RecordIDS;//原始记录IDS DataTable dtExpePlan = tExpePlan.GetList("SampleID=" + eExpePlan.SampleID.ToString()).Tables[0]; string TaskNoS = ""; if (dtExpePlan != null && dtExpePlan.Rows.Count > 0) { for (int i = 0; i < dtExpePlan.Rows.Count; i++) { TaskNoS += dtExpePlan.Rows[i]["PlanID"].ToString() + ","; } TaskNoS = TaskNoS.TrimEnd(','); } eTestReport.TaskNoS = TaskNoS;//任务单号 对应的检验计划IDS eTestReport.AreaID = CurrentUserInfo.AreaID; eTestReport.EditPersonnelID = CurrentUserInfo.PersonnelID; eTestReport.UpdateTime = DateTime.Now; eTestReport.TestBasis = new BLL.Laboratory.T_tb_Project().GetModel(eOriginalRecord.ProjectID.Value).ExpeMethod; tTestReport.Update(eTestReport); } //更新检验报告数据 List <E_tb_TestReportData> eTestReportDataList = tTestReportData.GetModelList("RecordFilePath='" + eOriginalRecord.FilePath + "'"); if (eTestReportDataList != null) { E_tb_Project eProject = tProject.GetModel(Convert.ToInt32(eOriginalRecord.ProjectID)); if (eProject.IsPesCheck != null && int.Parse(eProject.IsPesCheck.ToString()) == 1)//判断是否为农药残留检查项目 { foreach (E_tb_TestReportData eTestReportData in eTestReportDataList) { eTestReportData.RecordID = eOriginalRecord.RecordID; //原始记录ID eTestReportData.ReportID = eTestReport.ReportID; //检验报告ID eTestReportData.TestStandard = eProject.ExpeMethod; //检验标准 if (!String.IsNullOrEmpty(eOriginalRecord.InsStand)) { String[] strs = eOriginalRecord.InsStand.Split(':'); if (strs == null || strs.Length <= 2) { strs = eOriginalRecord.InsStand.Split(':'); } if (strs != null && strs.Length >= 2) { String str = strs[1]; int result = 0; if (!String.IsNullOrEmpty(str)) { // 正则表达式剔除非数字字符(不包含小数点.) str = Regex.Replace(str, @"[^\d.\d]", ""); // 如果是数字,则转换为decimal类型 if (Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$")) { result = int.Parse(str); } if (!String.IsNullOrEmpty(eTestReportData.TestResult)) { Decimal _testResult = Convert.ToDecimal(eTestReportData.TestResult); if (_testResult <= result) { eTestReportData.QualifiedLevel = "合格"; } else { eTestReportData.QualifiedLevel = "不合格"; } } } } } tTestReportData.Update(eTestReportData); } } else { foreach (E_tb_TestReportData eTestReportData in eTestReportDataList) { eTestReportData.RecordID = eOriginalRecord.RecordID; //原始记录ID eTestReportData.ReportID = eTestReport.ReportID; //检验报告ID eTestReportData.TestName = eProject.ProjectName; //检验名称/检验项目名称 eTestReportData.TestStandard = eProject.ExpeMethod; //检验标准 if (!String.IsNullOrEmpty(eOriginalRecord.InsStand)) { String[] strs = eOriginalRecord.InsStand.Split(':'); if (strs == null || strs.Length <= 2) { strs = eOriginalRecord.InsStand.Split(':'); } if (strs != null && strs.Length >= 2) { String str = strs[1]; int result = 0; if (!String.IsNullOrEmpty(str)) { // 正则表达式剔除非数字字符(不包含小数点.) str = Regex.Replace(str, @"[^\d.\d]", ""); // 如果是数字,则转换为decimal类型 if (Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$") && !string.IsNullOrEmpty(str)) { result = int.Parse(str); } if (!String.IsNullOrEmpty(eTestReportData.TestResult) && !string.IsNullOrEmpty(str)) { Decimal _testResult = Convert.ToDecimal(eTestReportData.TestResult); if (_testResult <= result) { eTestReportData.QualifiedLevel = "合格"; } else { eTestReportData.QualifiedLevel = "不合格"; } } } } } tTestReportData.Update(eTestReportData); } } } return(Json(new { result = true, msg = "更新成功!" }, JsonRequestBehavior.AllowGet)); }
public string Save(E_tb_TestReport eTestReport) { string msg = "0"; try { //检验数据 List <E_ReportData> ReportDataList = new List <E_ReportData>(); string strJson = eTestReport.TestReportDataJson; if (!string.IsNullOrEmpty(strJson)) { strJson = strJson.Replace("\r\n", ""); ReportDataList = JsonHelper.JsonDeserialize <List <E_ReportData> >(strJson); } //删除原有检验数据 tTestReportData.DeleteByWhere("ReportID=" + eTestReport.ReportID); foreach (E_ReportData item in ReportDataList) { E_tb_TestReportData eTestReportData = new E_tb_TestReportData(); eTestReportData.ReportID = eTestReport.ReportID; eTestReportData.TestName = item.TestName; eTestReportData.TestStandard = item.TestStandard; eTestReportData.TestResult = item.TestResult; eTestReportData.QualifiedLevel = item.QualifiedLevel; eTestReportData.TestPersonnelName = item.TestPersonnelName; eTestReportData.RecordID = int.Parse(item.RecordID); eTestReportData.RecordFilePath = item.RecordFilePath; tTestReportData.Add(eTestReportData); } //结论 //eTestReport.Conclusion = "合格"; DataTable TestReportDataDT = tTestReportData.GetList("ReportID=" + eTestReport.ReportID + " and QualifiedLevel=''").Tables[0]; //if (TestReportDataDT != null && TestReportDataDT.Rows.Count > 0) //{ // eTestReport.Conclusion = ""; //} //TestReportDataDT = tTestReportData.GetList("ReportID=" + eTestReport.ReportID + " and QualifiedLevel='不合格'").Tables[0]; //if (TestReportDataDT != null && TestReportDataDT.Rows.Count > 0) //{ // eTestReport.Conclusion = "不合格"; //} eTestReport.EditPersonnelID = CurrentUserInfo.PersonnelID; eTestReport.AreaID = new BLL.PersonnelManage.T_tb_InPersonnel().GetModel(eTestReport.MainTestPersonnelID.Value).AreaID; //if (CurrentUserInfo.DataRange != 1) //{ // eTestReport.AreaID = CurrentUserInfo.AreaID; //} eTestReport.RecordIDS = eTestReport.RecordIDS.TrimEnd(','); eTestReport.TaskNoS = eTestReport.TaskNoS.TrimEnd(','); eTestReport.UpdateTime = DateTime.Now; tTestReport.Update(eTestReport); //判断检验报告是否审核通过 if (eTestReport.ApprovalPersonnelID > 0 && eTestReport.examinePersonnelID > 0 && eTestReport.MainTestPersonnelID > 0) { tExpePlan.UpdateStatusByPlanIDS(eTestReport.TaskNoS, eTestReport.ReportID); } msg = "1"; } catch (Exception ex) { msg = ex.Message; } return(msg); }