diff --git a/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs b/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs index 1f0de904..5048d357 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs @@ -923,6 +923,150 @@ WHERE b.CourseNo ! = A.SceneNo OR b.CourseName ! = A.CourseName;"; AND E.Reverse6 IS NULL"; await Db.Ado.ExecuteCommandAsync(sql); + + sql = @"SELECT A.* + FROM [120.26.205.42].[GhrUshio].[dbo].Ghrz_Ushio_TravelReportApply_GHR50_V A + LEFT JOIN [120.26.205.42].[GhrUshio].[dbo].[Ghre_StaffTraining ] B + ON B.Reverse6 = cast (A.TravelReportApplyId AS VARCHAR (200)) where ExternalTrainApplyNo is not null"; + + var dtReportApplys = await Db.Ado.GetDataTableAsync(sql); + + for (int i = 0; i < dtReportApplys.Rows.Count; i++) + { + var TravelReportApplyId = dtReportApplys.Rows[i]["TravelReportApplyId"].ObjToString(); + var staffNo = dtReportApplys.Rows[i]["StaffNo"].ObjToString(); + var ExternalTrainApplyNo = dtReportApplys.Rows[i]["ExternalTrainApplyNo"].ObjToString(); + var ExternalTrainApplyNoArray = ExternalTrainApplyNo.Split(',').ToList(); + + var staffId = await Db.Ado.GetIntAsync($"select StaffId from [120.26.205.42].[GhrUshio].[dbo].ghra_staff where staffNo='{staffNo}'"); + + + for (int j = 0; j < ExternalTrainApplyNoArray.Count; j++) + { + long? CourseId = null; + string BeginDate = string.Empty; + string EndDate = string.Empty; + string CourseName = string.Empty; + ExternalTrainApplyNo = ExternalTrainApplyNoArray[j]; + if (ExternalTrainApplyNo.IsNullOrEmpty()) + continue; + + sql = @$" select * from [120.26.205.42].[GhrUshio].[dbo].Ghrz_Ushio_ExternalTrainApply + where applyNo='{ExternalTrainApplyNo}'"; + var dtExternalTrainApplyApplys = await Db.Ado.GetDataTableAsync(sql); + if (dtExternalTrainApplyApplys.Rows.Count > 0) + { + var TrainNeeds = dtExternalTrainApplyApplys.Rows[0]["TrainNeeds"].ObjToString(); + BeginDate = dtExternalTrainApplyApplys.Rows[0]["BeginDate"].ObjToString(); + EndDate = dtExternalTrainApplyApplys.Rows[0]["EndDate"].ObjToString(); + + if (TrainNeeds.Contains("*")) + { + TrainNeeds = TrainNeeds.Replace("*", null); + sql = @$"select * from [120.26.205.42].[GhrUshio].[dbo].Ghre_GHR50plan where planID={TrainNeeds}"; + var dtTrainRequestApplys = await Db.Ado.GetDataTableAsync(sql); + if (dtTrainRequestApplys.Rows.Count > 0) + { + CourseId = dtTrainRequestApplys.Rows[i]["CourseId"].ObjToLong(); + CourseName = dtTrainRequestApplys.Rows[i]["CourseName"].ObjToString(); + //var CourseSource = dtTrainRequestApplys.Rows[i]["CourseSource"].ObjToString(); + + } + + } + else if (TrainNeeds.Contains("-")) + { + TrainNeeds = TrainNeeds.Replace("-", null); + CourseId = TrainNeeds.ObjToLong(); + } + else + { + sql = @$"SELECT * FROM [120.26.205.42].[GhrUshio].[dbo].Ghrz_Ushio_TrainRequestApply WHERE WorkID = {TrainNeeds}"; + + var dtTrainRequestApplys = await Db.Ado.GetDataTableAsync(sql); + if (dtTrainRequestApplys.Rows.Count > 0) + { + CourseId = dtTrainRequestApplys.Rows[i]["CourseId"].ObjToLong(); + CourseName = dtTrainRequestApplys.Rows[i]["CourseName"].ObjToString(); + //var CourseSource = dtTrainRequestApplys.Rows[i]["CourseSource"].ObjToString(); + } + } + } + + if (CourseId == 0 || CourseId is null) + { + sql = @$"select CourseId from [120.26.205.42].[GhrUshio].[dbo].Ghre_Course + where courseName ='{CourseName}'"; + + CourseId = await Db.Ado.GetIntAsync(sql); + if (CourseId == 0) + await Db.Ado.ExecuteCommandAsync(@$"INSERT INTO [120.26.205.42].[GhrUshio].[dbo].Ghre_Course (CourseNo, + CourseName, + CreateDate, + EnableYN, + CompanyID, + SubCompanyID, + CreateBy, + CreateProg, + IsDefault, + Reverse1) + SELECT '{CourseName}', + '{CourseName}', + getdate (), + 'Y', + 0, + 0, + 0, + '', + 0, + NULL"); + + } + + sql = @$"select CourseId from [120.26.205.42].[GhrUshio].[dbo].Ghre_Course + where Reverse1='{CourseId}' or courseName ='{CourseName}'"; + CourseId = await Db.Ado.GetIntAsync(sql); + + if (CourseId != null) + { + + sql = @$"INSERT INTO [120.26.205.42].[GhrUshio].[dbo].[Ghre_StaffTraining ] ( + Reverse6, + StaffId, + CourseId, + BeginDate, + EndDate, + CreateDate, + EnableYN, + CompanyID, + SubCompanyID, + CreateBy, + CreateProg, + IsDefault, + Reverse1, + Reverse2, + Reverse3, + ispass) + SELECT '{TravelReportApplyId}', + {staffId} StaffId, + {CourseId} CourseId, + '{BeginDate}' BeginTime, + '{EndDate}' EndTime, + getdate (), + 'Y', + 0, + 0, + 0, + '', + 0, + 0 StandardHour, + 0 Score, + 0 CreditPoints, + 'Y'"; + } + } + } + #endregion }