private void GetDataAsync(int index)
        {
            GetDataDelegate d = new GetDataDelegate(GetData);

            d.BeginInvoke(index, new AsyncCallback(DataLoaded), null);
        }
예제 #2
0
        public IList <AlertEntity> GetTable2(params String[] s)
        {
            DateSelected = DateSelected.AddDays(1).AddHours(-1);
            IAsyncResult ar1 = d1.BeginInvoke(null, null);
            IAsyncResult ar2 = d2.BeginInvoke(null, null);
            IAsyncResult ar3 = d3.BeginInvoke(null, null);

            while (!ar1.IsCompleted && !ar2.IsCompleted && !ar3.IsCompleted)
            {
                Thread.Sleep(50);                                                              //wait
            }
            IList <AlertTempEntity> l1 = d1.EndInvoke(ar1);
            IList <AlertTempEntity> l2 = d2.EndInvoke(ar2);
            IList <AlertTempEntity> l3 = d3.EndInvoke(ar3);
            IList <AlertTempEntity> l4 = new List <AlertTempEntity>();



            foreach (AlertTempEntity AmntRes in l3)
            {
                int AmtResCi = l2.Where(p => p.rsTime <= AmntRes.rsTime &&
                                        p.rentLoc == AmntRes.rentLoc && p.crGrp == AmntRes.crGrp).Sum(p => p.Amnt);
                int AmntFea = l1.Where(p => p.rsTime <= AmntRes.rsTime &&
                                       p.rentLoc == AmntRes.rentLoc && p.crGrp == AmntRes.crGrp).Sum(p => p.Amnt);

                if ((AmntFea - AmntRes.Amnt + AmtResCi) < 0)
                {
                    l4.Add(new AlertTempEntity
                    {
                        rsTime  = AmntRes.rsTime,
                        crGrp   = AmntRes.crGrp,
                        rentLoc = AmntRes.rentLoc,
                        Amnt    = AmntFea + AmtResCi - AmntRes.Amnt
                    });
                }
            }
            l4 = l4.OrderBy(d => d.Amnt).ThenBy(d => d.rentLoc).ThenBy(d => d.crGrp).ToList();
            AlertEntity[] ax = _alertsRetQ.GetQueryable(l4).ToArray();

            var lx = new List <AlertEntity>();

            String[] a1 = ax.Where(p => !String.IsNullOrEmpty(p.NextHour)).Select(p => p.NextHour).ToArray();
            String[] a2 = ax.Where(p => !String.IsNullOrEmpty(p.Follow4Hours)).Select(p => p.Follow4Hours).ToArray();
            String[] a3 = ax.Where(p => !String.IsNullOrEmpty(p.RestOfDay)).Select(p => p.RestOfDay).ToArray();
            String[] a4 = ax.Where(p => !String.IsNullOrEmpty(p.Custom)).Select(p => p.Custom).ToArray();

            Boolean b = true;

            Int32[] i = { 0, 0, 0, 0 };
            while (b)
            {
                string s1 = String.Empty, s2 = String.Empty, s3 = String.Empty, s4 = string.Empty;
                b = false;
                if (i[0] < a1.Length)
                {
                    s1 = a1[i[0]++];
                    b  = true;
                }
                if (i[1] < a2.Length)
                {
                    s2 = a2[i[1]++];
                    b  = true;
                }
                if (i[2] < a3.Length)
                {
                    s3 = a3[i[2]++];
                    b  = true;
                }
                if (i[3] < a4.Length)
                {
                    s4 = a4[i[3]++];
                    b  = true;
                }

                if (b)
                {
                    lx.Add(new AlertEntity
                    {
                        NextHour     = s1,
                        Follow4Hours = s2,
                        RestOfDay    = s3,
                        Custom       = s4,
                    });
                }
            }
            return(lx);
        }