public static List <ProjectYieldViewModule> GetYieldByBRNum(string pjkey, string BRNUM, ProjectViewModels pvm, Cache mycache, string yieldtype)
        {
            var retlist = new List <ProjectYieldViewModule>();

            var brs = BRNUM.Split(new string[] { ";", ",", " " }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var br in brs)
            {
                var ret = new ProjectYieldViewModule();
                ret.ProjectKey = pjkey;

                var plist = ProjectTestData.RetrieveProjectTestDataByBR(pjkey, br, yieldtype, false, mycache);

                var tplist    = new List <ProjectTestData>();
                var datacount = plist.Count - 1;
                for (int idx = datacount; idx >= 0; idx--)
                {
                    tplist.Add(plist[idx]);
                }

                RetrieveFirstYield(ret, tplist, pvm);

                RetrieveCummYield(ret, plist, pvm);

                if (ret.FirstYields.Count > 0)
                {
                    ret.XKey = br;
                    retlist.Add(ret);
                }
            }

            return(retlist);
        }
        private static void RetrieveCummYield(ProjectYieldViewModule pyvm, List <ProjectTestData> plist, ProjectViewModels pvm)
        {
            var yielddict = new Dictionary <string, TestYield>();
            var sndict    = new Dictionary <string, bool>();

            foreach (var p in plist)
            {
                if (!sndict.ContainsKey(p.WhichTest + ":" + p.ModuleSerialNum))
                {
                    sndict.Add(p.WhichTest + ":" + p.ModuleSerialNum, true);
                    if (yielddict.ContainsKey(p.WhichTest))
                    {
                        yielddict[p.WhichTest].InputCount = yielddict[p.WhichTest].InputCount + 1;
                        if (string.Compare(p.ErrAbbr, "PASS", true) == 0)
                        {
                            yielddict[p.WhichTest].OutputCount = yielddict[p.WhichTest].OutputCount + 1;
                        }
                        RegisterError(p.ErrAbbr, p.WhichTest, pyvm.LErrorMap);
                    }
                    else
                    {
                        var tempyield = new TestYield();
                        tempyield.InputCount = 1;
                        if (string.Compare(p.ErrAbbr, "PASS", true) == 0)
                        {
                            tempyield.OutputCount = 1;
                        }
                        else
                        {
                            tempyield.OutputCount = 0;
                        }
                        tempyield.WhichTest = p.WhichTest;

                        RegisterError(p.ErrAbbr, p.WhichTest, pyvm.LErrorMap);
                        yielddict.Add(p.WhichTest, tempyield);
                    }
                }
            }

            if (pvm.SumDatasetList.Count > 0)
            {
                foreach (var s in pvm.SumDatasetList)
                {
                    if (yielddict.ContainsKey(s.Station))
                    {
                        pyvm.LastYields.Add(yielddict[s.Station]);
                    }
                }
            }
            else if (pvm.StationList.Count > 0)
            {
                foreach (var s in pvm.StationList)
                {
                    if (yielddict.ContainsKey(s.Station))
                    {
                        pyvm.LastYields.Add(yielddict[s.Station]);
                    }
                }
            }
        }
        public static ProjectYieldViewModule GetYieldByDateRange(string pjkey, string sdate, string edate, ProjectViewModels pvm, Cache mycache)
        {
            var ret = new ProjectYieldViewModule();

            ret.ProjectKey = pjkey;
            ret.StartDate  = DateTime.Parse(sdate);
            ret.EndDate    = DateTime.Parse(edate);

            var startdate = DateTime.Parse(DateTime.Parse(sdate).ToString("yyyy-MM-dd") + " 07:30:00").ToString();
            var enddate   = DateTime.Parse(DateTime.Parse(edate).ToString("yyyy-MM-dd") + " 07:30:00").ToString();

            if (startdate == enddate)
            {
                return(ret);
            }

            var plist = ProjectTestData.RetrieveProjectTestData(pjkey, startdate, DateTime.Parse(enddate).AddYears(5).ToString(), false, mycache);

            if (plist.Count == 0)
            {
                return(ret);
            }


            var fdatalist = new List <ProjectTestData>();
            var enddatet  = DateTime.Parse(enddate);

            foreach (var item in plist)
            {
                if (enddatet >= item.TestTimeStamp)
                {
                    fdatalist.Add(item);
                }
            }

            //var fdatalist = ProjectTestData.RetrieveProjectTestData(pjkey, startdate, enddate, false);
            RetrieveRealTimeYield(ret, fdatalist, pvm);

            var tplist    = new List <ProjectTestData>();
            var datacount = fdatalist.Count - 1;

            for (int idx = datacount; idx >= 0; idx--)
            {
                tplist.Add(fdatalist[idx]);
            }

            //var tplist = ProjectTestData.RetrieveProjectTestData(pjkey, startdate, enddate, true);

            var snstationdict = ProjectTestData.RetrieveSNBeforeDateWithStation(pjkey, startdate, mycache);
            var sndict        = new Dictionary <string, bool>();

            foreach (var kvpair in snstationdict)
            {
                var endindex = kvpair.Key.LastIndexOf('-');
                var sn       = kvpair.Key.Substring(0, endindex);
                if (!sndict.ContainsKey(sn))
                {
                    sndict.Add(sn, true);
                }
            }


            //var sndict = ProjectTestData.RetrieveSNBeforeDate(pjkey, startdate);
            var validatedict = new Dictionary <string, bool>();

            foreach (var item in tplist)
            {
                if (!sndict.ContainsKey(item.ModuleSerialNum))
                {
                    if (!validatedict.ContainsKey(item.ModuleSerialNum))
                    {
                        validatedict.Add(item.ModuleSerialNum, true);
                    }
                }
            }

            //var plist = ProjectTestData.RetrieveProjectTestData(pjkey, startdate,DateTime.Parse(enddate).AddYears(5).ToString(), false);
            var filteredPjData2 = new List <ProjectTestData>();

            foreach (var item in plist)
            {
                if (validatedict.ContainsKey(item.ModuleSerialNum))
                {
                    filteredPjData2.Add(item);
                }
            }
            RetrieveSNYield(ret, filteredPjData2, pvm);


            //plist = ProjectTestData.RetrieveProjectTestData(pjkey, startdate, enddate, true);
            //snlist = ProjectTestData.RetrieveSNBeforeDateWithStation(pjkey, startdate);
            validatedict = new Dictionary <string, bool>();
            var filteredPjData = new List <ProjectTestData>();

            foreach (var item in tplist)
            {
                if (!snstationdict.ContainsKey(item.ModuleSerialNum + "-" + item.WhichTest))
                {
                    filteredPjData.Add(item);
                    if (!validatedict.ContainsKey(item.ModuleSerialNum))
                    {
                        validatedict.Add(item.ModuleSerialNum, true);
                    }
                }
            }

            RetrieveFirstYield(ret, filteredPjData, pvm);


            //plist = ProjectTestData.RetrieveProjectTestData(pjkey, startdate, enddate, false);
            filteredPjData2 = new List <ProjectTestData>();
            foreach (var item in fdatalist)
            {
                if (validatedict.ContainsKey(item.ModuleSerialNum))
                {
                    filteredPjData2.Add(item);
                }
            }

            RetrieveCummYield(ret, filteredPjData2, pvm);

            plist.Clear();
            snstationdict.Clear();
            sndict.Clear();
            validatedict.Clear();
            GC.Collect();
            GC.WaitForPendingFinalizers();

            return(ret);
        }