示例#1
0
        public string GenerateSMSSpreadSheet(HttpResponse response)
        {
            if (_CurrentPAList == null)
                throw new ApasInvaidOperationException(
                "System Error: No payment advice list exists for SMS text generation.");

            lock (criticalSection)
            {
                BCBranch[] aryBranch = BCBranch.getAllBranches();

                ApasSearchManager sMgr = new ApasSearchManager(PALockKey);

                //hold all PAs, halt if unsuccessful
                writeResponse("lblPreparation", "Acquiring exclusive access...",
                    "blueMessage", response);

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

                List<BCAspenUser> oUsers = lMgr.HoldPAListExclusive(_CurrentPAList.Id);

                if (oUsers.Count > 0)
                {
                    String oUserStr = "";
                    foreach (BCAspenUser oUser in oUsers)
                    {
                        oUserStr += oUser.FullName + ", ";
                    }
                    oUserStr = oUserStr.Substring(0,oUserStr.Length - 2);

                    writeResponse("lblPreparation",
                    "Failed",
                    "redMessage", response);

                    foreach (BCBranch objBranch in aryBranch)
                    {
                        writeResponse("lbl" + objBranch.Name.Trim(),
                        "Canceled",
                        "redMessage", response);
                    }

                    writeResponse("lblFinalization",
                   "Canceled",
                   "redMessage", response);

                    return "Failed to acquire exclusive access. " + oUserStr +
                    " is/are currently holding some records.";
                }

                writeResponse("lblPreparation", "Updating records...",
                    "blueMessage", response);
                //resync the PAs
                NHibernateManager.GetCurrentSession().Evict(_CurrentPAList);//remove it before reloading
                _CurrentPAList.Load(_CurrentPAList.Id, false);   //reload to get updated records
                if (_CurrentPAList.IsFrozen == 1)
                    _CurrentPAList.StaticSynchronizePaymentAdvices(PALockKey);
                else
                    _CurrentPAList.SyncPaymentAdvices(PALockKey);

                writeResponse("lblPreparation", "Initializing Excel...",
                    "blueMessage",response);

                ApasExcelManager xl=new ApasExcelManager();
                xl.InitExcelApplication();

                writeResponse("lblPreparation", "Successful",
                    "blueMessage", response);

                String[] aryDay = {"Monday", "Tuesday", "Wednesday", "Thursday",
                    "Friday", "Saturday", "Sunday"};
                //String[] aryDay = { "Monday" };

                int classCount;
                int completeCount;

                foreach (BCBranch objBranch in aryBranch)
                {
                    writeResponse("lbl" + objBranch.Name.Trim(), "Initializing...",
                        "blueMessage", response);

                    String strFile = "/APAS/tmp Excel Files/" +
                        _CurrentPAList.Month.ToString("yyyyMM") +
                        " SMS " + objBranch.Name.Trim() + ".xls";
                    String strLocalFile = HttpContext.Current.Server.MapPath("~"+strFile);

                    xl.CreateNewFile(strLocalFile);

                    foreach (String day in aryDay)
                    {
                        writeResponse("lbl" + objBranch.Name.Trim(),
                            "Processing "+ day +": Acquiring data...",
                            "blueMessage", response);

                        ArrayList result = sMgr.SearchPaymentAdviceByDay(
                            CurrentPAList.Id,
                            day, objBranch.Id);

                        xl.AddNewWorkSheet(day);
                        xl.WriteHeading(
                            "Student Id",
                             "Class Id",
                            "Student Name",
                            "Guardian Name",
                            "Class Description",
                            "Credit Payable",
                            "Amount Payable",
                            "SMS Text",
                            "Contact Number"
                        );

                        classCount = result.Count;
                        completeCount=1;
                        foreach (ApasRegularView objReg in result)
                        {

                            writeResponse("lbl" + objBranch.Name.Trim(),
                            "Processing " + day + ": "+ completeCount +" of "+ classCount  +" classes...",
                            "blueMessage", response);

                            foreach (PaymentAdviceView objPA in objReg.PaymentAdvices)
                            {
                                //don't include in SMS if excluced
                                if (objPA.IsExcluded )
                                    continue;

                                foreach (ClassFeeView objCF in objPA.ClassFees)
                                {
                                    if (objCF.IsExcluded )
                                        continue;

                                    xl.WriteRow(
                                    Convert.ToString(objPA.Student.Id),
                                    Convert.ToString(objCF.RegularClass.Id),
                                    objPA.Student.FullName,
                                    objPA.Student.Guardian.Name.Trim(),
                                    String.Format("{0} {1} {2} - {3}",
                                        objCF.RegularClass.Level,
                                        objCF.RegularClass.Subject,
                                        objCF.RegularClass.TimeStart,
                                        objCF.RegularClass.TimeEnd),
                                    Convert.ToString(objCF.PayableCredit),
                                    Convert.ToString(objCF.PayableFee),
                                    objCF.PaymentAdviceText,
                                    String.IsNullOrEmpty(objPA.Student.Guardian.ContactMobile) ?
                                        objPA.Student.ContactMobile : objPA.Student.Guardian.ContactMobile
                                    );

                                }//objCF

                                foreach (OtherFeeView objOF in objPA.OtherFees)
                                {
                                    if (objOF.IsExcluded)
                                        continue;

                                    xl.WriteRow(
                                    Convert.ToString(objPA.Student.Id),
                                    "N.A",
                                    objPA.Student.FullName,
                                    objPA.Student.Guardian.Name.Trim(),
                                    objOF.OtherFeeType,
                                    "N.A",
                                    "N.A",
                                    objOF.PaymentAdviceText,
                                    String.IsNullOrEmpty(objPA.Student.Guardian.ContactMobile) ?
                                        objPA.Student.ContactMobile : objPA.Student.Guardian.ContactMobile
                                    );
                                }//objOF

                            }//objPA

                            completeCount++;
                        }//objReg

                        xl.FinalizeWorkSheet();

                    }//day

                    writeResponse("lbl" + objBranch.Name.Trim(),
                    "Finalizing...",
                    "blueMessage", response);

                    xl.SaveFile();

                    writeResponse("lbl" + objBranch.Name.Trim(),
                    "Successful : <a href=" + MyUtils.EncodeJsString(HttpContext.Current.Request.ApplicationPath+strFile) + " target=\"_blank\">Download Link</a>",
                    "blueMessage", response);

                }//branch

                writeResponse("lblFinalization", "Closing excel...",
                   "blueMessage", response);
                xl.CloseExcelApplication();

                writeResponse("lblFinalization", "Updating records...",
                   "blueMessage", response);

                //has to reload. Dunno why
                NHibernateManager.GetCurrentSession().Evict(_CurrentPAList);//remove it before reloading
                _CurrentPAList.Load(_CurrentPAList.Id, false);   //reload to get updated records
                CurrentPAList.FreezePaymentAdvices(PALockKey);

                CurrentPAList.SMSGenTime = DateTime.Now;
                CurrentPAList.LastAction = "SMS Text Generated";
                CurrentPAList.LastModifiedBy =
                    ApasAccessControlManager.GetCurrentInstance().LogonUser.Id;
                CurrentPAList.LastModifiedTime = DateTime.Now;
                CurrentPAList.Save();

                lMgr.Release("", new List<SqlParameter>());

                writeResponse("lblFinalization", "Successful",
                   "blueMessage", response);

            }//critial section

            return "success";
        }
 public ArrayList SearchPaymentAdviceByDay(long idPAList, string strDay, int branchId, string lockKey)
 {
     ApasSearchManager s = new ApasSearchManager(lockKey);
     return s.SearchPaymentAdviceByDay(idPAList,strDay, branchId);
 }