public async Task <object> GetAuditItem(string audittypeID) { var data = await _repoAuditDType.FindAll(x => x.Audit_Type_ID.Trim() == audittypeID). GroupBy(x => x.Audit_Item_ID).Select(y => new{ Audit_Item_ID = y.Key }).ToListAsync(); var result = (from a in data select new { Audit_Item_ID = a.Audit_Item_ID, oderby = (a.Audit_Item_ID.Split(".")).Count() == 1?0:a.Audit_Item_ID.Split(".")[1].ToInt() }); result = result.OrderBy(x => x.Audit_Item_ID.Split(".")[0].ToInt()).ThenBy(x => x.oderby); return(result); }
public async Task <List <ScoreRecordQuesDto> > GetListQuesScoreRecord(string auditTypeId) { MES_Audit_Type_M auditType; auditType = _repoTypeM.FindAll().Where(x => x.Audit_Type_ID.Trim() == auditTypeId.Trim()).FirstOrDefault(); List <ScoreRecordQuesDto> data = new List <ScoreRecordQuesDto>(); if (auditType != null) { var queryAudiiTypeD = _repoTypeD.FindAll().Where(x => x.Audit_Type_ID.Trim() == auditType.Audit_Type_ID.Trim() && x.Visible == true); data = await queryAudiiTypeD.Select(x => new ScoreRecordQuesDto { Audit_Type_ID = x.Audit_Type_ID, Audit_Item_ID = x.Audit_Item_ID, Quesion = x.Audit_Item_LL, QuesionLL = x.Audit_Item_LL, QuesionEN = x.Audit_Item_EN, QuesionZW = x.Audit_Item_ZW, TypeDrating0 = x.Rating_0, TypeDrating1 = x.Rating_1, TypeDrating2 = x.Rating_2, orderby = 0 }).OrderBy(x => x.Audit_Item_ID).ToListAsync(); data = data.Select(x => { x.orderby = (x.Audit_Item_ID.Split(".")).Count() == 1 ? 0 : x.Audit_Item_ID.Split(".")[1].ToInt(); return(x); }).ToList(); data = data.OrderBy(x => x.Audit_Item_ID.Split(".")[0].ToInt()).ThenBy(x => x.orderby).ToList(); } return(data); }
public async Task <List <ScoreRecordQuesDto> > GetListQuesScoreRecord(string auditType2, string auditType1) { MES_Audit_Type_M auditTypeID; if (auditType1 == "精實系統/WS") { auditTypeID = _auditTypeMRepository.FindAll().Where(x => x.Audit_Type1 == auditType1).FirstOrDefault(); } else { auditTypeID = _auditTypeMRepository.FindAll().Where(x => x.Audit_Type1 == auditType1 && x.Audit_Type2 == auditType2).FirstOrDefault(); } List <ScoreRecordQuesDto> data = new List <ScoreRecordQuesDto>(); if (auditTypeID != null) { var queryAudiiTypeD = _auditTypeDRepository.FindAll().Where(x => x.Audit_Type_ID.Trim() == auditTypeID.Audit_Type_ID.Trim()); data = await queryAudiiTypeD.Select(x => new ScoreRecordQuesDto { Audit_Type_ID = x.Audit_Type_ID, Audit_Item_ID = x.Audit_Item_ID, Quesion = x.Audit_Item_LL, QuesionLL = x.Audit_Item_LL, QuesionEN = x.Audit_Item_EN, QuesionZW = x.Audit_Item_ZW }).ToListAsync(); } return(data); }
public async Task <bool> Upgrade(string audit_Type_ID) { string auditID = await GetAuditTypeID(); var auditTypeM = _repoAuditType.FindAll().Where(x => x.Audit_Type_ID.Trim() == audit_Type_ID.Trim()).FirstOrDefault(); auditTypeM.Audit_Type_ID = auditID; auditTypeM.Updated_Time = DateTime.Now; auditTypeM.Version = auditTypeM.Version + 1; auditTypeM.Status = "1"; // .Select(x=> // { // x.Audit_Type_ID=auditID; // x.Updated_Time = DateTime.Now; // x.Version = x.Version +1; // x.Status ="1"; // return x; // }).ToList(); var auditTypeD = _repoAuditTypeD.FindAll().Where(x => x.Audit_Type_ID.Trim() == audit_Type_ID.Trim()).ToList() .Select(x => { x.Audit_Type_ID = auditID; x.Updated_Time = DateTime.Now; return(x); }).ToList(); var listAuditTypeM = _mapper.Map <MES_Audit_Type_M>(auditTypeM); var listAuditTypeD = _mapper.Map <List <MES_Audit_Type_D> >(auditTypeD); //add DB _repoAuditType.Add(listAuditTypeM); _repoAuditTypeD.AddMultiple(listAuditTypeD); try { //Save return(await _repoAuditType.SaveAll()); } catch (Exception) { return(false); } }
public int SumEachRating1InAuditTypeDAndAuditRateD(string recordId) { var auditTypeM = _auditTypeMRepository.FindAll(x => x.Audit_Kind.Trim() == "WS").FirstOrDefault(); var listAuditTypeD = _auditTypeDRepository.FindAll(x => x.Audit_Type_ID.Trim() == auditTypeM.Audit_Type_ID.Trim()).ToList(); var listAuditRateD = _auditRateDRepository.FindAll(x => x.Record_ID == recordId).ToList(); //bien luu tong cua tich tung phan tu int result = 0; foreach (var i in listAuditTypeD) { foreach (var j in listAuditRateD) { if (i.Audit_Item_ID == j.Audit_Item_ID) { result += i.Rating_1 * j.Rating_1; } } } return(result); }
public int SumEachRating1InAuditTypeDAndAuditRateD(string recordId) { var auditTypeM = _auditTypeMRepository.FindAll().Where(x => x.Audit_Type1.Trim() == "精實系統/WS").FirstOrDefault(); var listAuditTypeD = _auditTypeDRepository.FindAll().Where(x => x.Audit_Type_ID.Trim() == auditTypeM.Audit_Type_ID.Trim()).ToList(); var listAuditRateD = _auditRateDRepository.FindAll().Where(x => x.Record_ID == recordId).ToList(); // biến lưu tổng của tích từng phần tử int result = 0; foreach (var i in listAuditTypeD) { foreach (var j in listAuditRateD) { if (i.Audit_Item_ID == j.Audit_Item_ID) { result += i.Rating_1 * j.Rating_1; } } } return(result); }
public async Task <List <AuditType_D_Dto> > GetAllAsyn() { return(await _repoauditTypeD.FindAll().ProjectTo <AuditType_D_Dto>(_configMapper).OrderByDescending(x => x.Updated_Time).ToListAsync()); }
public async Task <object> GetDataChart(string id, int type) { PaginationParams paginationParams = new PaginationParams(); ScoreRecordParam scoreRecordParam = new ScoreRecordParam(); DateTime today = DateTime.Now; var firstDayLastOfMonth = new DateTime(today.Year, today.AddMonths(-1).Month, 1); if (today.Month == 1) { firstDayLastOfMonth = new DateTime(today.Year - 1, today.AddMonths(-1).Month, 1); } var lastDayLastOfMonth = firstDayLastOfMonth.AddMonths(1).AddDays(-1); scoreRecordParam.FromDate = firstDayLastOfMonth.ToString("yyyy/MM/dd"); scoreRecordParam.ToDate = lastDayLastOfMonth.ToString("yyyy/MM/dd"); //Query data by Factory var queryLables = _iMesAuditrepo.FindAll().Where(x => x.Status == 1 && x.Line_Seq > 0); var queryData = await _iSMEReocrdService.GetLisSMEScoreRecord(paginationParams, scoreRecordParam, false, true); //GetLables chart by Factory var listLables = await queryLables.Where(x => x.PDC_ID != "6" && x.PDC_ID != "8" && x.PDC_ID != "C" && x.PDC_ID != "D" && x.PDC_ID != "G").Select(x => x.PDC_ID).Distinct().ToListAsync(); listLables.Insert(0, "Overall"); //get name pdc var listLables_name = await queryLables.Where(x => x.PDC_ID != "6" && x.PDC_ID != "8" && x.PDC_ID != "C" && x.PDC_ID != "D" && x.PDC_ID != "G").OrderBy(x => x.PDC_ID).Select(x => x.PDC_Name).ToListAsync(); listLables_name = listLables_name.Distinct().ToList(); listLables_name.Insert(0, "Overall"); //Get Data Chart var dataChart = queryData.ToList(); // Get table weakness DateTime d1 = Convert.ToDateTime(scoreRecordParam.FromDate + " 00:00:00"); DateTime d2 = Convert.ToDateTime(scoreRecordParam.ToDate + " 23:59:59"); var auditrateM = _rateMRepository.FindAll().Where(x => (x.Audit_Type2 == "Module1" || x.Audit_Type2 == "Module3") && x.PDC != "6" && x.PDC != "8" && x.PDC != "C" && x.PDC != "D" && x.PDC != "G" && x.Audit_Kind == "SME" && x.Record_Date >= d1 && x.Record_Date <= d2); var auditrateD = _rateDRepository.FindAll().Where(x => x.Rating_0 == 1); var AuditTypeD = _typeDRepository.FindAll(); var Title = ""; //HCE var queryJoinRateMD = auditrateM.Join(auditrateD, x => x.Record_ID, y => y.Record_ID, (x, y) => new { x.Audit_Kind, x.Audit_Type2, x.Audit_Type_ID, x.PDC, x.Building, x.Line, y.Audit_Item_ID }); var dataJoin = queryJoinRateMD.GroupJoin(AuditTypeD, x => new { x.Audit_Type_ID, x.Audit_Item_ID }, z => new { z.Audit_Type_ID, z.Audit_Item_ID }, (x, z) => new { AuditRatMD = x, TypeD = z }) .SelectMany(y => y.TypeD.DefaultIfEmpty(), (y, z) => new { AuditRatMD = y.AuditRatMD, TypeD = z }).ToList(); var resultTest = dataJoin.GroupBy(x => x).Select(z => new { AudiKind = z.Key.AuditRatMD.Audit_Kind, Audit_Type2 = z.Key.AuditRatMD.Audit_Type2, PDC = z.Key.AuditRatMD.PDC, Building = z.Key.AuditRatMD.Building, Line = z.Key.AuditRatMD.Line, Audit_Item_ID = z.Key.AuditRatMD.Audit_Item_ID, Audit_Item_ZW = z.Key.TypeD.Audit_Item_ZW, Audit_Item_EN = z.Key.TypeD.Audit_Item_EN, Audit_Item_LL = z.Key.TypeD.Audit_Item_LL, cnt = z.Count(), Weakness = "Factory" }).OrderBy(z => z.Audit_Type2).ToList(); //End HCE //line_seq >0 var listLine = queryLables.Select(x => x.Line_ID).ToList(); resultTest = resultTest.Where(x => listLine.Contains(x.Line)).ToList(); //Get data chart & lables by DEPT if (type == 1) { var Dept_name = queryLables.Where(x => x.PDC_ID == id).Select(x => x.PDC_Name).FirstOrDefault(); dataChart = queryData.Where(x => x.PDC == id).ToList(); listLables = await queryLables.Where(x => x.PDC_ID == id).Select(x => x.Building).Distinct().ToListAsync(); //get name building listLables_name = await queryLables.Where(x => x.PDC_ID == id).OrderBy(x => x.Building).Select(x => x.Building_Name).ToListAsync(); listLables_name = listLables_name.Distinct().ToList(); listLables.Insert(0, "Dept " + id); listLables_name.Insert(0, "Dept " + Dept_name); resultTest = resultTest.Where(x => x.PDC.Trim() == id.Trim()).ToList(); Title = "Dept " + Dept_name; } //Get data chart & lables by Building if (type == 2) { var Building_Name = queryLables.Where(x => x.Building == id).Select(x => x.Building_Name).FirstOrDefault(); dataChart = queryData.Where(x => x.Building == id).ToList(); var temp = queryLables.Where(x => x.Building == id && x.IsSME == true).Select(x => new { Line_ID = x.Line_ID, Line_Seq = x.Line_Seq }).Distinct(); listLables = await temp.OrderBy(x => x.Line_Seq).Select(x => x.Line_ID).ToListAsync(); //get Name Line listLables_name = await queryLables.Where(x => x.Building == id && x.IsSME == true).OrderBy(x => x.Line_Seq).Select(x => x.Line_Name.Trim()).ToListAsync(); listLables_name = listLables_name.Distinct().ToList(); listLables.Insert(0, Building_Name); listLables_name.Insert(0, Building_Name); resultTest = resultTest.Where(x => x.Building.Trim() == id.Trim()).ToList(); Title = id + " Building"; } //Get lables Line if (type == 3) { var modelAuditOrg = await queryLables.Where(x => x.Line_ID == id).FirstOrDefaultAsync(); listLables = new List <string>() { "Overall", "Dept " + modelAuditOrg.PDC_ID, modelAuditOrg.Building, modelAuditOrg.Line_ID }; listLables_name = new List <string>() { "Overall", "Dept " + modelAuditOrg.PDC_Name, modelAuditOrg.Building_Name, modelAuditOrg.Line_Name }; resultTest = resultTest.Where(x => x.Line.Trim() == id.Trim()).ToList(); Title = modelAuditOrg.Line_Name; } //Chart var chartModule1 = DataChart(dataChart.Where(x => x.AuditType2 == "Module1" && listLine.Contains(x.LineId)). ToList(), listLables, type, id); var chartModule3 = DataChart(dataChart.Where(x => x.AuditType2 == "Module3" && listLine.Contains(x.LineId)). ToList(), listLables, type, id); if (type == 0) { listLables_name = listLables_name.Select(x => { x = x != "Overall" ? "Dept " + x : x; return(x); }).ToList(); Title = "Factory"; } var month = DateTime.Now.Month - 1; object result = new { chartModule1, chartModule3, listLables = listLables_name, month, resultTest, Title }; return(result); }