public ArrayList SearchPaymentAdviceByCriteria(long idPAList,
        StringSearchPredicate[] aryS, IntegerSearchPredicate[] aryI,
        string lockKey)
    {
        ApasSearchManager s = new ApasSearchManager(lockKey);

        List<SearchPredicate> c = new List<SearchPredicate>();

        foreach (StringSearchPredicate ps in aryS)
        {
            ps.PredicateTemplate = " {0} like '%'+{1}+'%' ";
            c.Add(ps);
        }

        foreach (IntegerSearchPredicate pi in aryI)
        {
            pi.PredicateTemplate = " {0} = {1} ";
            c.Add(pi);
        }

        return s.SearchPaymentAdviceByCriteria(idPAList,c);
    }
示例#2
0
        //public ArrayList SearchPaymentAdviceByDay
        //(long idPAList, string strDay, int branchId){
        //    try{
        //        return SearchPaymentAdviceByDayImpl(idPAList, strDay, branchId);
        //    }catch(Exception e){
        //        string source = "APAS";
        //        string log = "Application";
        //        string strEvent = "Exception";
        //        string machine = ".";
        //        if(!EventLog.SourceExists(source,machine)){
        //            EventLog.CreateEventSource(source, log, machine);
        //        }
        //        EventLog eLog = new EventLog(log, machine, source);
        //        eLog.WriteEntry(e.StackTrace);
        //        throw e;
        //    }
        //}
        public ArrayList SearchPaymentAdviceByDay(long idPAList, string strDay, int branchId)
        {
            //1. Create criteria to query PAs in the chosen day
            //2. Aggregate PAs under their principal RegularView
            //2.1. If principal class is not in the chosen day, don't display
            //2.2. If non-principal classes are in the chosen day, add a dummy reference

            ISession ses = NHibernateManager.GetCurrentSession();
            EntityConverter ecov = new EntityConverter();

            Dictionary<int, ApasRegularView> result = new Dictionary<int, ApasRegularView>();
            ApasRegularView pReg;
            ApasRegular tempReg;
            int pRegId;

            PALockManager lMgr = new PALockManager(
               ApasAccessControlManager.GetCurrentInstance().LogonUser.Id,
               PALockKey);

            List<SearchPredicate> criteria = new List<SearchPredicate>();
            StringSearchPredicate sp = new StringSearchPredicate();
            sp.FieldName = "strDayRegular";
            sp.TableName = "Regular";
            sp.Value = strDay;
            sp.PredicateTemplate = " {0} = {1} ";

            criteria.Add(sp);

            IntegerSearchPredicate ip = new IntegerSearchPredicate();
            ip.FieldName = "intIdBranch";
            ip.TableName = "Branch";
            ip.Value = branchId;
            ip.PredicateTemplate = " {0} = {1} ";

            criteria.Add(ip);

            IList<PaymentAdvice> pList = executeQuery(idPAList, criteria);

            //if no result, return
            if (pList.Count == 0)
                return new ArrayList();

            //aggregate PAs under respective ApasRegularViews
            foreach (PaymentAdvice objPA in pList)
            {

                //check if chosen day of week is principal day for the objPA.
                //Principal day = leftmost day of week start from monday
                int[] aryDow = new int[objPA.ClassFees.Count];
                ApasRegular[] aryReg = new ApasRegular[aryDow.Length];

                int i = 0;
                foreach (ClassFee objCF in objPA.ClassFees.Values)
                {
                    tempReg = objCF.GetAssociatedClass();

                    aryDow[i] = convertDow(tempReg.Day);
                    aryReg[i] = tempReg;
                    i++;
                }

                Array.Sort(aryDow, aryReg);

                pRegId = aryReg[0].Id; //principal class Id

                //add all the classes in the chosen day to result dictionary
                foreach (ApasRegular objAR in aryReg)
                {
                    if (objAR.Day.ToLower() == strDay.ToLower() &&
                        !result.ContainsKey(objAR.Id))
                        result.Add(objAR.Id, ecov.ConvertRegular(objAR));
                }

                //check if principal class is in chosen day
                if (result.TryGetValue(pRegId, out pReg))
                {
                    //lock
                    lMgr.Hold(objPA.Id);

                    ses.Evict(objPA);

                    //requery the objPA
                    PaymentAdvice principalPA = new PaymentAdvice(objPA.Id, false, PALockKey);

                    //add to class
                    pReg.PaymentAdvices.Add(ecov.ConvertPaymentAdvice(principalPA));

                }

                foreach (ClassFee objCF in objPA.ClassFees.Values)
                {
                    //add dummy references
                    if (objCF.IdRegular != pRegId &&
                        result.ContainsKey(objCF.IdRegular))
                    {
                        result[objCF.IdRegular].PaymentAdviceReferences.Add
                        (ecov.ConvertPaymentAdviceReference(objPA, ecov.ConvertRegular(aryReg[0])));
                    }
                }

            }

            //put the result into an arraylist
            ArrayList resultArray = new ArrayList();
            foreach (ApasRegularView objARV in result.Values)
            {
                resultArray.Add(objARV);
            }

            return resultArray;
        }