Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using ABI.Common;
- using ABI.MDM.Common;
- using Profisee.MasterDataMaestro.Services.DataContracts.MasterDataServices;
- using Profisee.Services.Sdk.AcceleratorFramework;
- using Profisee.Services.Sdk.Common.Contracts.DataContext;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Security.Principal;
- using System.Text;
- using System.Web;
- using System.Web.Mvc;
- namespace ABI.Controllers
- {
- public partial class ReportsController : Controller
- {
- // GET: Reports
- public ActionResult Report()
- {
- DropdownLists.GetBooksList();
- DropdownLists.ParentBrand();
- DropdownLists.PtsLevelList();
- return View("~/Views/Dashboard/Report.cshtml");
- }
- public JsonResult GetChildBooks(string parentBookCode, string brand, string ptsLevel)
- {
- var sbp = new StringBuilder();
- sbp.Append(string.Format("[SourceTestspecificationCode] = '{0}' ", parentBookCode));
- if (!string.IsNullOrEmpty(brand))
- sbp.Append(string.Format("AND [Brand] ='{0}' ", brand));
- if (!string.IsNullOrEmpty(ptsLevel))
- sbp.Append(string.Format("AND [PtsLevel] ='{0}' ", ptsLevel));
- //Getting Child Book Details
- var bec_childBooks = new BrowseEntityContext
- {
- Filter = sbp.ToString(),
- MemberType = MemberType.Leaf,
- PageNumber = 1,
- PageSize = 10000
- };
- var childBkCodes = Helper.GetMemberCollection(Entities.Catalog, bec_childBooks);
- var TestSpecificationList = childBkCodes.Select(x => x.MemberId);
- var sb = new StringBuilder();
- sb.Append(string.Format("[TestSpecificationCode] ='{0}' ", parentBookCode));
- var bc = new BrowseEntityContext
- {
- Filter = sb.ToString(),
- MemberType = MemberType.Leaf,
- PageNumber = 1,
- PageSize = 100000
- };
- var ptsParameters = Helper.GetMemberCollectionSelAttr(Entities.PtsDetail, bc, new Collection<string> { "ParameterCode", "ParameterType" });
- var parameters = ptsParameters.Select(m => new
- {
- code = m.Attributes.FirstOrDefault(x => x.Name == "ParameterCode").Value,
- value = ((MemberIdentifier)m.Attributes.FirstOrDefault(x => x.Name == "ParameterType").Value).Name + "/" + m.Attributes.FirstOrDefault(x => x.Name == "ParameterCode").Value
- }).Distinct();
- return Json(new { TestSpecificationList = TestSpecificationList, ParameterCodes = parameters }, JsonRequestBehavior.AllowGet);
- }
- public string ParentChildReport(string parentBookCode, string[] selChildBkCodes, string[] selParams)
- {
- IEnumerable<BookParameters> PCDifferences = null;
- StringBuilder cbSb = new StringBuilder();
- StringBuilder pcSb = new StringBuilder();
- StringBuilder finalSb = new StringBuilder();
- try
- {
- //Getting Parent Book Details
- var bc_parentbkParamsList = new BrowseEntityContext
- {
- Filter = string.Format("[TestSpecificationCode] = '{0}' ", parentBookCode),
- MemberType = MemberType.Leaf,
- PageNumber = 1,
- PageSize = 100000
- };
- var pbkParamsList = Helper.GetMdmMemberCollection(Entities.PtsDetail, bc_parentbkParamsList);
- IEnumerable<BookParameters> parentBookParams = GetBookParamsList(pbkParamsList);
- if (parentBookParams != null && parentBookParams.Count() > 0)
- {
- if (selChildBkCodes == null || selChildBkCodes.Count() == 0) /// For all child books
- {
- //Getting Child Book Details
- var bec_childBooks = new BrowseEntityContext
- {
- Filter = string.Format("[SourceTestspecificationCode] = '{0}' ", parentBookCode),
- MemberType = MemberType.Leaf,
- PageNumber = 1,
- PageSize = 10000
- };
- var childBkCodes = Helper.GetMemberCollection(Entities.Catalog, bec_childBooks);
- foreach (var cb in childBkCodes)
- {
- if (cbSb.Length == 0)
- cbSb.Append(string.Format("[TestSpecificationCode] = '{0}' ", cb.MemberId.Code));
- else
- cbSb.Append(string.Format("OR [TestSpecificationCode] = '{0}' ", cb.MemberId.Code));
- }
- }
- else // for selected child books
- {
- foreach (var cb in selChildBkCodes)
- {
- if (cbSb.Length == 0)
- cbSb.Append(string.Format("[TestSpecificationCode] = '{0}' ", cb));
- else
- cbSb.Append(string.Format("OR [TestSpecificationCode] = '{0}' ", cb));
- }
- }
- if (selParams != null)
- { // ParameterCode
- foreach (var pCode in selParams)
- {
- if (pcSb.Length == 0)
- pcSb.Append(string.Format("[ParameterCode] = '{0}' ", pCode));
- else
- pcSb.Append(string.Format("OR [ParameterCode] = '{0}' ", pCode));
- }
- }
- if (cbSb.Length != 0)
- {
- finalSb.Append(string.Format(" ({0}) ", cbSb));
- if (pcSb.Length != 0)
- finalSb.Append(string.Format("AND ({0}) ", pcSb));
- var bc_bkparamsList = new BrowseEntityContext
- {
- Filter = finalSb.ToString(),
- MemberType = MemberType.Leaf,
- PageNumber = 1,
- PageSize = 100000
- };
- var cbkparamsList = Helper.GetMdmMemberCollection(Entities.PtsDetail, bc_bkparamsList);
- IEnumerable<BookParameters> childBookParams = GetBookParamsList(cbkparamsList);
- if (childBookParams != null && childBookParams.Count() > 0)
- {
- var diffCParamsList = (from p in parentBookParams
- join c in childBookParams on p.ParameterCode equals c.ParameterCode
- where p.RedLow != c.RedLow ||
- p.RedHigh != c.RedHigh ||
- p.Target != c.Target ||
- p.YellowLow != c.YellowLow ||
- p.YellowHigh != c.YellowHigh ||
- p.SamplePoint != c.SamplePoint ||
- p.ProcessIndicator != c.ProcessIndicator ||
- p.ManGoodPractice != c.ManGoodPractice ||
- p.MethodOfAnalysis != c.MethodOfAnalysis ||
- p.SpecificationLevel != c.SpecificationLevel ||
- p.Frequency != c.Frequency ||
- p.ParameterStatus != c.ParameterStatus ||
- p.Notification != c.Notification ||
- p.NotificationInterval != c.NotificationInterval
- select c);
- var ptbookParams = (from p in parentBookParams
- join d in diffCParamsList on p.ParameterCode equals d.ParameterCode
- select p);
- if (diffCParamsList != null && diffCParamsList.Count() > 0)
- {
- PCDifferences = (ptbookParams.Union(diffCParamsList));
- PCDifferences = PCDifferences.OrderBy(x => x.ParameterCode).ThenBy(x => x.TestSpecCode);
- var GroupList = PCDifferences.GroupBy(item => item.ParameterCode)
- .Select(group => new
- {
- ParameterCode = group.Key,
- items = group.ToList()
- }).ToList();
- return Newtonsoft.Json.JsonConvert.SerializeObject(GroupList);
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- }
- return Newtonsoft.Json.JsonConvert.SerializeObject(PCDifferences);
- }
- public IEnumerable<BookParameters> GetBookParamsList(Collection<MdmMember> memberList,bool ParamHistoryCode=false)
- {
- IEnumerable<BookParameters> bkParameters = new List<BookParameters>();
- try
- {
- bkParameters = memberList.Select(item => new BookParameters
- {
- Name = ((MemberIdentifier)item.GetMemberValue("TestSpecificationCode")).Name as string,
- TestSpecCode = ((MemberIdentifier)item.GetMemberValue("TestSpecificationCode")).Code as string,
- Code = item.MemberId.Code,
- Target = (item.GetMemberValue("Target")) as string,
- RedLow = (item.GetMemberValue("RedToleranceMin")) as string,
- RedHigh = (item.GetMemberValue("YellowToleranceMin")) as string,
- YellowHigh = (item.GetMemberValue("YellowToleranceMax")) as string,
- YellowLow = (item.GetMemberValue("RedToleranceMax")) as string,
- ParameterCode = (item.GetMemberValue("ParameterCode")) as string,
- ParameterType = ((MemberIdentifier)item.GetMemberValue("ParameterType")).Name as string,
- SamplePoint = ((MemberIdentifier)item.GetMemberValue("SamplePoint")).Name as string,
- ProcessIndicator = ((MemberIdentifier)item.GetMemberValue("ProcessIndicator")).Name as string,
- ManGoodPractice = ((MemberIdentifier)item.GetMemberValue("MandatoryOrGoodPractice")).Name as string,
- MethodOfAnalysis = ((MemberIdentifier)item.GetMemberValue("MethodOfAnalysis")).Name as string,
- SpecificationLevel = ((MemberIdentifier)item.GetMemberValue("SpecificationLevel")).Name as string,
- Frequency = ((MemberIdentifier)item.GetMemberValue("MinimumFrequency")).Name as string,
- ParameterStatus = ((MemberIdentifier)item.GetMemberValue("ParameterStatus")).Name as string,
- Notification = ((MemberIdentifier)item.GetMemberValue("ISNotification")).Code != null ? ((MemberIdentifier)item.GetMemberValue("ISNotification")).Code.ToString() : "",
- NotificationInterval = Convert.ToString((item.GetMemberValue("ISNotification_Interval"))),
- ParamHistoryCode = ParamHistoryCode ? ((MemberIdentifier)item.GetMemberValue("TestParameter")).Code as string : ""
- });
- }
- catch (Exception ex)
- {
- }
- return bkParameters;
- }
- public ActionResult BooksComparisonReport()
- {
- DropdownLists.ProcessStreamList();
- Session["SubStream"] = new SelectList("");
- Session["TestSpecification"] = new SelectList("");
- return View("~/Views/Dashboard/BooksComparisonReport.cshtml");
- }
- public ActionResult RawMaterialReport()
- {
- if (Session["PtsLevelList"] == null)
- DropdownLists.PtsLevelList();
- DropdownLists.ProcessStreamList();
- Session["SubStream"] = new SelectList("");
- Session["TestSpecification"] = new SelectList("");
- return View("~/Views/Dashboard/RawMaterialReport.cshtml");
- }
- public JsonResult GetSamePSBooks(string processStream, string substream, string selBookCode = "")
- {
- IEnumerable<MemberIdentifier> testSpecificationList = null;
- try
- {
- StringBuilder sb = new StringBuilder();
- if (processStream != "")
- sb.Append(string.Format("[ProcessStream] ='{0}' ", processStream));
- if (substream != "")
- sb.Append(string.Format("AND [Substream] ='{0}' ", substream));
- var bc_TestSpec = new BrowseEntityContext
- {
- Filter = sb.ToString(),
- MemberType = MemberType.Leaf,
- PageNumber = 1,
- PageSize = 1000
- };
- var testSpecificationCollection = Helper.GetMemberCollectionSelAttr(Entities.Catalog, bc_TestSpec, new Collection<string>());
- testSpecificationList = testSpecificationCollection.Select(x => x.MemberId);
- if (selBookCode != "")
- {
- testSpecificationList = testSpecificationCollection.Where(x => x.MemberId.Code != selBookCode).Select(x => x.MemberId);
- }
- }
- catch (Exception ex)
- {
- CodeLogs.Error("Error in Loading booksList" + ex.Message.ToString());
- }
- return Json(testSpecificationList, JsonRequestBehavior.AllowGet);
- }
- public JsonResult GetRMBooks(string ps, string ptslevel, string subStream, string BookName)
- {
- IEnumerable<MemberIdentifier> BooksList = null;
- try
- {
- var sb = new StringBuilder();
- var rb = new StringBuilder();
- if (!string.IsNullOrEmpty(ptslevel))
- sb.Append(string.Format(" [PtsLevel] ='{0}' ", ptslevel));
- if (!string.IsNullOrEmpty(ps))
- sb.Append(string.Format("AND [ProcessStream] ='{0}' ", ps));
- if (!string.IsNullOrEmpty(subStream))
- sb.Append(string.Format("AND [Substream] ='{0}' ", subStream));
- //if (!string.IsNullOrEmpty(BookName))
- // rb.Append(string.Format("AND [Substream] ='{0}' ", BookName));
- var bc = new BrowseEntityContext
- {
- Filter = sb.ToString(),
- MemberType = MemberType.Leaf,
- PageNumber = 1,
- PageSize = 1000
- };
- var ptsBooks = Helper.GetMdmMemberCollection(Entities.Catalog, bc);
- BooksList = ptsBooks.Select(x => x.MemberId);
- //var code = ptsBooks.FirstOrDefault().MemberId.Code;
- //if (code!=null)
- // rb.Append(string.Format("[TestSpecificationCode] = '{0}'", code));
- //var bk = new BrowseEntityContext
- //{
- // Filter = rb.ToString(),
- // MemberType = MemberType.Leaf,
- // PageNumber = 1,
- // PageSize = 1000
- //};
- //var TestParameterList = Helper.GetMdmMemberCollection(Entities.PtsDetail, bk);
- //IEnumerable<BookParameters> bookParams = GetBookParamsList(TestParameterList);
- }
- catch (Exception ex)
- {
- }
- return Json(BooksList, JsonRequestBehavior.AllowGet);
- }
- public JsonResult GetReportRM(string BookName)
- {
- IEnumerable<BookParameters> bookParams = null;
- try
- {
- var rb = new StringBuilder();
- var code = BookName;//ptsBooks.FirstOrDefault().MemberId.Code;
- if (code != null)
- rb.Append(string.Format("[TestSpecificationCode] = '{0}'", code));
- var bk = new BrowseEntityContext
- {
- Filter = rb.ToString(),
- MemberType = MemberType.Leaf,
- PageNumber = 1,
- PageSize = 1000
- };
- var TestParameterList = Helper.GetMdmMemberCollection(Entities.PtsDetail, bk);
- bookParams = GetBookParamsList(TestParameterList);
- }
- catch (Exception ex)
- {
- }
- return Json(bookParams, JsonRequestBehavior.AllowGet);
- }
- public string BookComparisonReport(string parentBookCode, string[] selBkCodes, string category, string specLevel = "")
- {
- IEnumerable<BookParameters> PCDifferences = null;
- StringBuilder cbSb = new StringBuilder();
- StringBuilder pcSb = new StringBuilder();
- StringBuilder finalSb = new StringBuilder();
- try
- {
- //Getting Parent Book Details
- var bc_parentbkParamsList = new BrowseEntityContext
- {
- Filter = string.Format("[TestSpecificationCode] = '{0}' ", parentBookCode),
- MemberType = MemberType.Leaf,
- PageNumber = 1,
- PageSize = 100000
- };
- var pbkParamsList = Helper.GetMdmMemberCollection(Entities.PtsDetail, bc_parentbkParamsList);
- IEnumerable<BookParameters> parentBookParams = GetBookParamsList(pbkParamsList);
- if (parentBookParams != null && parentBookParams.Count() > 0)
- {
- // for selected child books
- foreach (var cb in selBkCodes)
- {
- if (cbSb.Length == 0)
- cbSb.Append(string.Format("[TestSpecificationCode] = '{0}' ", cb));
- else
- cbSb.Append(string.Format("OR [TestSpecificationCode] = '{0}' ", cb));
- }
- if (cbSb.Length != 0)
- {
- finalSb.Append(string.Format(" ({0}) ", cbSb));
- var bc_bkparamsList = new BrowseEntityContext
- {
- Filter = finalSb.ToString(),
- MemberType = MemberType.Leaf,
- PageNumber = 1,
- PageSize = 100000
- };
- var cbkparamsList = Helper.GetMdmMemberCollection(Entities.PtsDetail, bc_bkparamsList);
- IEnumerable<BookParameters> selBookParams = GetBookParamsList(cbkparamsList);
- if (category != "ALL")
- {
- if (selBookParams != null && selBookParams.Count() > 0)
- {
- IEnumerable<BookParameters> diffCParamsList = null;
- IEnumerable<BookParameters> ptbookParams = null;
- if (specLevel != "")
- {
- diffCParamsList = (from p in parentBookParams
- join c in selBookParams on p.ParameterCode equals c.ParameterCode
- where c.SpecificationLevel == specLevel &&
- (p.RedLow != c.RedLow ||
- p.RedHigh != c.RedHigh ||
- p.Target != c.Target ||
- p.YellowLow != c.YellowLow ||
- p.YellowHigh != c.YellowHigh ||
- p.SamplePoint != c.SamplePoint ||
- p.ProcessIndicator != c.ProcessIndicator ||
- p.ManGoodPractice != c.ManGoodPractice ||
- p.MethodOfAnalysis != c.MethodOfAnalysis ||
- p.Frequency != c.Frequency ||
- p.ParameterStatus != c.ParameterStatus ||
- p.Notification != c.Notification ||
- p.NotificationInterval != c.NotificationInterval) && p.SpecificationLevel == c.SpecificationLevel
- select c);
- ptbookParams = (from p in parentBookParams
- join d in diffCParamsList on p.ParameterCode equals d.ParameterCode
- where p.SpecificationLevel == specLevel
- select p);
- }
- else
- {
- diffCParamsList = (from p in parentBookParams
- join c in selBookParams on p.ParameterCode equals c.ParameterCode
- where
- (p.RedLow != c.RedLow ||
- p.RedHigh != c.RedHigh ||
- p.Target != c.Target ||
- p.YellowLow != c.YellowLow ||
- p.YellowHigh != c.YellowHigh ||
- p.SamplePoint != c.SamplePoint ||
- p.ProcessIndicator != c.ProcessIndicator ||
- p.ManGoodPractice != c.ManGoodPractice ||
- p.MethodOfAnalysis != c.MethodOfAnalysis ||
- p.SpecificationLevel != c.SpecificationLevel ||
- p.Frequency != c.Frequency ||
- p.ParameterStatus != c.ParameterStatus ||
- p.Notification != c.Notification ||
- p.NotificationInterval != c.NotificationInterval)
- select c);
- ptbookParams = (from p in parentBookParams
- join d in diffCParamsList on p.ParameterCode equals d.ParameterCode
- select p);
- }
- if (diffCParamsList != null && diffCParamsList.Count() > 0)
- {
- PCDifferences = (ptbookParams.Union(diffCParamsList));
- PCDifferences = PCDifferences.OrderBy(x => x.ParameterCode).ThenBy(x => x.TestSpecCode);
- var GroupList = PCDifferences.GroupBy(item => item.ParameterCode)
- .Select(group => new
- {
- ParameterCode = group.Key,
- items = group.ToList()
- }).ToList();
- return Newtonsoft.Json.JsonConvert.SerializeObject(GroupList);
- }
- }
- }
- else
- {
- PCDifferences = (parentBookParams.Union(selBookParams));
- if(specLevel!="")
- PCDifferences = PCDifferences.Where(x=>x.SpecificationLevel==specLevel).OrderBy(x => x.ParameterCode).ThenBy(x => x.TestSpecCode);
- else
- PCDifferences = PCDifferences.OrderBy(x => x.ParameterCode).ThenBy(x => x.TestSpecCode);
- var GroupList = PCDifferences.GroupBy(item => item.ParameterCode)
- .Select(group => new
- {
- ParameterCode = group.Key,
- items = group.ToList()
- }).ToList();
- return Newtonsoft.Json.JsonConvert.SerializeObject(GroupList);
- }
- }
- }
- }
- catch (Exception ex)
- {
- }
- return Newtonsoft.Json.JsonConvert.SerializeObject(PCDifferences);
- }
- public ActionResult VersionReport()
- {
- DropdownLists.ProcessStreamList();
- Session["SubStream"] = new SelectList("");
- Session["TestSpecification"] = new SelectList("");
- return View();
- }
- public string BookVersionComparisonReport(string BookCode)
- {
- IEnumerable<BookParameters> PCDifferences = null;
- try
- {
- var parentBook = Helper.GetMdmMember(Entities.Catalog, BookCode);
- string bookVersion = (parentBook.GetMemberValue("Version")) as string;
- string LatestValidatedVersion = (parentBook.GetMemberValue("LatestValidatedVersion")) as string;
- if (bookVersion.Trim() != LatestValidatedVersion.Trim())
- {
- //Getting Parent Book Details
- var bc_parentbkParamsList = new BrowseEntityContext
- {
- Filter = string.Format("[TestSpecificationCode] = '{0}' ", BookCode),
- MemberType = MemberType.Leaf,
- PageNumber = 1,
- PageSize = 100000
- };
- StringBuilder sb = new StringBuilder();
- sb.Append(string.Format("[TestSpecificationCode] = '{0}' ", BookCode));
- sb.Append(string.Format("AND [Version] = '{0}' ", LatestValidatedVersion));
- var bc_oldParamsList = new BrowseEntityContext
- {
- Filter = sb.ToString(),
- MemberType = MemberType.Leaf,
- PageNumber = 1,
- PageSize = 100000
- };
- var pbkParamsList = Helper.GetMdmMemberCollection(Entities.PtsDetail, bc_parentbkParamsList);
- var oldParamsList = Helper.GetMdmMemberCollection(Entities.ParameterHistory, bc_oldParamsList);
- IEnumerable<BookParameters> parentBookParams = GetBookParamsList(pbkParamsList);
- IEnumerable<BookParameters> oldBookParams = GetBookParamsList(oldParamsList, true);
- if (parentBookParams != null && parentBookParams.Count() > 0)
- {
- PCDifferences = (from newParams in parentBookParams
- join oldParams in oldBookParams on newParams.Code equals oldParams.ParamHistoryCode
- select newParams);
- PCDifferences = (PCDifferences.Union(oldBookParams));
- PCDifferences = PCDifferences.OrderBy(x => x.ParameterCode).ThenBy(x => x.TestSpecCode);
- var GroupList = PCDifferences.GroupBy(item => item.ParameterCode)
- .Select(group => new
- {
- ParameterCode = group.Key,
- items = group.ToList()
- }).ToList();
- return Newtonsoft.Json.JsonConvert.SerializeObject(GroupList);
- }
- }
- }
- catch (Exception ex)
- {
- }
- return Newtonsoft.Json.JsonConvert.SerializeObject(PCDifferences);
- }
- public ActionResult ChangeRequestActionReport()
- {
- if (Session["PtsLevelList"] == null)
- DropdownLists.PtsLevelList();
- #region Add Owned Books to Session
- try
- {
- var bc_TestSpec = new BrowseEntityContext
- {
- MemberType = MemberType.Leaf,
- PageNumber = 1,
- PageSize = 1000,
- Filter = new StringBuilder().Append(string.Format("[UserId] = '{0}'", WindowsIdentity.GetCurrent().Name.ToUpper().ToString().Trim())).ToString()
- };
- var TestSpecificationCollection = Helper.GetMdmMemberCollection(Entities.BookOwner, bc_TestSpec);
- var filter = new StringBuilder();
- var i = 0;
- foreach (var book in TestSpecificationCollection)
- {
- filter.Append(string.Format(" [code] = '{0}' ",((book.Member.Attributes.FirstOrDefault(x => x.Name == "BookId").Value) as MemberIdentifier).Code)).ToString();
- if (i < TestSpecificationCollection.Count - 1)
- filter.Append(string.Format(" OR")).ToString();
- i++;
- }
- filter.Append(string.Format(" AND [PtsLevel] = '{0}'", "Master")).ToString();
- var bc_OwnedBooks = new BrowseEntityContext
- {
- MemberType = MemberType.Leaf,
- PageNumber = 1,
- PageSize = 1000,
- Filter = filter.ToString()
- };
- var BooksOwned = Helper.GetMdmMemberCollection(Entities.Catalog, bc_OwnedBooks);
- var TestSpecificationList = TestSpecificationCollection.Select(x => x.Member.Attributes);
- Session["TestSpecification"] = new SelectList(TestSpecificationList, "Code", "Name");
- }
- catch (Exception ex)
- {
- CodeLogs.Error("Error in Loading booksList" + ex.Message.ToString());
- }
- #endregion
- return View();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement