/// <summary> /// Save evaluation information to sap result. /// </summary> /// <param name="evaInfo">The evaluation information.</param> /// <returns></returns> private ResultViewModel SendToEvaluationSapResult(Data.Pocos.Evaluation evaInfo) { var result = new ResultViewModel(); try { var evaluationResult = _summaryEvaluation.GetDetail(evaInfo.Id); var periodItem = _unitOfWork.GetRepository <PeriodItem>().GetCache(x => x.Id == evaInfo.PeriodItemId).FirstOrDefault(); var sapResult = new EvaluationSapResult { ComCode = evaInfo.ComCode, PurOrg = evaInfo.PurchasingOrg, SendToSap = false, Vendor = evaInfo.VendorNo, WeightKey = evaInfo.WeightingKey, YearMonth = UtilityService.DateTimeToString(periodItem.EndEvaDate.Value, "yy.MM") }; this.DeclareScore(sapResult, evaluationResult.Summarys); _unitOfWork.GetRepository <EvaluationSapResult>().Add(sapResult); } catch (Exception ex) { result = UtilityService.InitialResultError(ex.Message); _logger.LogError(ex, "The Errors Message : "); } return(result); }
/// <summary> /// Generate main content table. /// </summary> /// <param name="workbook">The npoi workbook interface.</param> /// <param name="sheet1">The npoi sheet interface.</param> /// <param name="summaryList">The evaluation summary result. </param> /// <param name="evaluationList">The evaluation data collection.</param> /// <param name="rowIndex">The row data index.</param> /// <param name="cellHeaderIndex">The max cell table generate.</param> private void GenerateContentTable(IWorkbook workbook, ISheet sheet1, SummaryEvaluationViewModel summary, Data.Pocos.Evaluation evaluation, ref int rowIndex, PeriodItem periodItem, IEnumerable <Hremployee> empList) { rowIndex++; IRow contentRow = sheet1.CreateRow(rowIndex); int cellContentIndex = 0; string[] mainContent = new string[] { evaluation.DocNo, evaluation.ComCode, UtilityService.DateTimeToString(periodItem.StartEvaDate.Value, "dd.MM.yyyy"), UtilityService.DateTimeToString(periodItem.EndEvaDate.Value, "dd.MM.yyyy"), periodItem.PeriodName, evaluation.VendorNo, summary.VendorName, summary.WeightingKey, summary.PurchasingOrgName, }; foreach (var content in mainContent) { ExcelService.CreateContentCell(workbook, sheet1, contentRow, cellContentIndex, content); cellContentIndex++; } rowIndex += 2; var evaTemplate = _evaluationTemplateBll.LoadTemplate(evaluation.EvaluationTemplateId.Value); this.GenerateScoreHeader(workbook, sheet1, ref rowIndex, summary); foreach (var user in summary.UserLists) { var emp = empList.FirstOrDefault(x => x.Aduser == user.AdUser); string evaluatorName = $" คุณ{emp?.FirstnameTh} {emp?.LastnameTh}"; IRow userContent = sheet1.CreateRow(rowIndex); ExcelService.CreateContentCell(workbook, sheet1, userContent, 1, evaluatorName, horizontalAlignment: HorizontalAlignment.Left); ExcelService.SetCellContentStyle(workbook, userContent, 2, 2); sheet1.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 1, 2)); var evaLogs = user.EvaluationLogs.FirstOrDefault(); this.GenerateCriteriaContent(workbook, sheet1, ref rowIndex, evaluation.WeightingKey, summary, evaTemplate, evaLogs); rowIndex += 2; } }
/// <summary> /// Get evaluation information data. /// </summary> /// <param name="data">The evaluation information data.</param> /// <returns></returns> private SummaryEvaluationViewModel GetHeaderInformation(Data.Pocos.Evaluation data) { var vendor = _unitOfWork.GetRepository <Data.Pocos.Vendor>().GetCache(x => x.VendorNo == data.VendorNo).FirstOrDefault(); var purOrg = _unitOfWork.GetRepository <PurchaseOrg>().GetCache(x => x.PurchaseOrg1 == data.PurchasingOrg).FirstOrDefault(); var company = _unitOfWork.GetRepository <Hrcompany>().GetCache(x => x.SapcomCode == data.ComCode).FirstOrDefault(); return(new SummaryEvaluationViewModel { Id = data.Id, CompanyName = company?.LongText, VendorName = vendor?.VendorName, PurchasingOrgName = purOrg?.PurchaseName, WeightingKey = data.WeightingKey, }); }
/// <summary> /// Save evaluation result score to sap result table and upadte status flag. /// </summary> /// <param name="evaInfo">The evaluation information.</param> private void Save(Data.Pocos.Evaluation evaInfo) { using (var scope = new TransactionScope()) { var result = this.SendToEvaluationSapResult(evaInfo); if (result.IsError) { evaInfo.SendToEvaluationSapResultStatus = ConstantValue.SendToEvaluationSapResultFailed; } else { evaInfo.SendToEvaluationSapResultStatus = ConstantValue.SendToEvaluationSapResultComplete; } _unitOfWork.GetRepository <Data.Pocos.Evaluation>().Update(evaInfo); _unitOfWork.Complete(scope); } }