sunithamcsit 0 Newbie Poster

hi everybody,

In my code i have to display day_of_week from Monday to Sunday.
and as well as I have to display dates of that particular weeek dynamically.here iam highlighting the code that need to modify.
please I structed here please help me to overcome this problem.
If possible give me some hot code to modify.

Date dnow = new java.util.Date();

            int iMonth = Integer.parseInt(DateEx.dateToStringFormat(dnow,"MM"));
            int iYear = Integer.parseInt(DateEx.dateToStringFormat(dnow,"YYYY"));
            int iDay = Integer.parseInt(DateEx.dateToStringFormat(dnow,"DD"));
            int iWeek = 0;

            Calendar cWeek = Calendar.getInstance();
            if (request.getParameter("cweek") != null) {
                iWeek = Integer.parseInt(request.getParameter("cweek"));
            } else {
                cWeek.set(iYear, iMonth+1, iDay);
                iWeek = cWeek.get(cWeek.WEEK_OF_MONTH);
                cWeek.set(iYear, iMonth+1, 1);
                if (cWeek.get(cWeek.DAY_OF_WEEK) != 1) {
                    iWeek = iWeek - 1;
            }
            }
            if (iWeek==0)
                iWeek=1;

            String strMonth = null;
            String strYear = null;
            String strFP = null;
            Date dFDay = null;
            Date dLDay = null;
            Date dend = null;
            int curYear = 0;
            int curMonth = 0;
            int iSDate = 1;
            int iFDate = 1;

            ArrayList[] aL = new ArrayList[32];

            try {
                if (page.get("query") != null) {    //Search
                    curMonth = Integer.parseInt(page.get("sMonth"));
                    curYear = Integer.parseInt(page.get("sYear"));
                    iWeek=1;

                    scheduleDet = new FPSScheduleDetail();
                    if (page.get("FPCode") != null) {
                        scheduleDet.sFPCode = page.get("FPCode");
                    } else {
                        if (request.getParameter("fpcode") != null)
                            scheduleDet.sFPCode = request.getParameter("fpcode");
                    }
                } else {
                    if (request.getParameter("cyear") != null) {
                        curYear = Integer.parseInt(request.getParameter("cyear"));
                    } else {
                        curYear = iYear;
                    }

                    if (request.getParameter("cmonth") != null) {
                        curMonth = Integer.parseInt(request.getParameter("cmonth"));
                    } else {
                        curMonth = iMonth;
                    }
                    scheduleDet = new FPSScheduleDetail();
                    scheduleDet.sFPCode = page.get("FPCode");

                    if (request.getParameter("fpcode") != null)
                        scheduleDet.sFPCode = request.getParameter("fpcode");
                }

        if (iWeek != 0){
                    //scheduleDet = new FPSScheduleDetail();
                    //scheduleDet.sFPCode = page.get("FPCode");

                    if (scheduleDet.sFPCode == null)
                        scheduleDet.sFPCode = secu.getFpCode();

                    //if (request.getParameter("fpcode") != null)
                    //  scheduleDet.sFPCode = request.getParameter("fpcode");

                    strMonth = Integer.toString(curMonth);
                    strYear = Integer.toString(curYear);
                    iYear = curYear;
                    iMonth = curMonth;

                    dend = DateEx.endMonthDate(iYear,iMonth);

                    Calendar cDay = Calendar.getInstance();

                    for (int i = 1; i < 32; i++) {
                        cDay.set(iYear, iMonth - 1, i);
                        if (cDay.get(cDay.DAY_OF_WEEK) == 1) {
                            iSDate = i;
                            iFDate = i;
                            break;
                        }
                    }
                    iSDate = 1;
                    iFDate = 1;
                    iSDate = iSDate + ((iWeek - 1) * 7);
                    
                    cDay.set(iYear, iMonth-1, iSDate);
                    cDay.add(cDay.DATE, +7);

                    dFDay = DateEx.stringToDateTime(Integer.toString(iSDate) + "/" + strMonth + "/" + strYear + " 00:00");
                    dLDay = DateEx.stringToDateTime(cDay.get(cDay.DATE) + "/" + (cDay.get(cDay.MONTH)+1) + "/" + cDay.get(cDay.YEAR) + " 00:00");

                }
                
            } catch(Exception ex) {
                page.writeErr(ex);
            }

            page.print("<TABLE><TR>");
            page.print("<TD CLASS='xtd'>Submenu : > </TD>");
            //page.print("<TD CLASS='xtd'><A HREF='wschdlr?miid=" + miid + "'> Weekly Schedule </TD>");
            page.print("<TD CLASS='xtd'><A HREF='mschdlr?miid=" + miid + "&fpcode=" + scheduleDet.sFPCode +"'> Monthly Schedule </TD>");
            page.print("</TR></TABLE>");
            page.print("<BR>");

            page.print("<FORM name='Schedule' action='wschdlr' method=POST>");

            RefCodeInfo[] refInfo = null;
            RefCodeInfo[] apptInfo = bizRef.getAPPT(sLang);
            if (request.getParameter("midd") != null) {
                miid = request.getParameter("midd");
            }

            if (miid.equalsIgnoreCase(pageid[0])) {
                refInfo = new RefCodeInfo[1];
                refInfo[0] = new RefCodeInfo();
                refInfo[0].sRefCode = secu.getFpCode();
                refInfo[0].sRefCodeDesc = refInfo[0].sRefCode + " - " + dbFP.getFPName(refInfo[0].sRefCode);
            } else if (miid.equalsIgnoreCase(pageid[1])) {
                FPStructureInfo[] stucInfo = dbFP.getFPDownline(secu.getFpCode());
                if (stucInfo != null) {
                    refInfo = new RefCodeInfo[stucInfo.length + 1];
                    for (int i = 0; i <= stucInfo.length; i++) {
                        refInfo[i] = new RefCodeInfo();
                        if (i == 0) {
                            refInfo[i].sRefCode = secu.getFpCode();
                            refInfo[i].sRefCodeDesc = refInfo[i].sRefCode + " - " + dbFP.getFPName(refInfo[i].sRefCode);
                            continue;
                        }
                        refInfo[i].sRefCode = stucInfo[i - 1].sFPCode;
                        refInfo[i].sRefCodeDesc = stucInfo[i - 1].sFPCode + " - " + dbFP.getFPName(stucInfo[i - 1].sFPCode);
                    }
                }
            } else if (miid.equalsIgnoreCase(pageid[2])) {
                FinancialPlannerInfo[] fpInfo = dbFP.getAllFP();
                if (fpInfo != null) {
                    refInfo = new RefCodeInfo[fpInfo.length];
                    for (int i = 0; i < fpInfo.length; i++) {
                        refInfo[i] = new RefCodeInfo();
                        refInfo[i].sRefCode = fpInfo[i].sFPCode;
                        refInfo[i].sRefCodeDesc = fpInfo[i].sFPCode + " - " + fpInfo[i].sFPName;
                    }
                }
            }

            page.print("<TABLE><TR>");
            page.print("<TD CLASS='xtd'>" + dbutil.getLabel(conmgr.env.getUserId(), "FPSSCHEDULE.FPCODE") + "</TD>");
            page.print("<TD CLASS='xtd'>" + htmlutil.printDropDownRefCode("FPCode", refInfo, scheduleDet.sFPCode, true, false, true, true, false) + "&nbsp &nbsp</TD>");
            page.print("<TD CLASS='xtd'>" + dbutil.getLabel(conmgr.env.getUserId(), "ENQUIRY.YEAR") + "</TD>");
            page.print("<TD CLASS='xtd'>" + htmlutil.printTextBox("sYear", Integer.toString(iYear), 4, 4) + "&nbsp </TD>");
            page.print("<TD CLASS='xtd'>" + dbutil.getLabel(conmgr.env.getUserId(), "ENQUIRY.MONTH") + "</TD>");

            //page.print("<TD CLASS='xtd'>" + htmlutil.printTextBox("sMonth", Integer.toString(iMonth), 2, 2) + "&nbsp </TD>");

            RefCodeInfo[] refMonth = null;
            refMonth = new RefCodeInfo[12];
            String sLM = null;
            sLM = Integer.toString(iMonth);

            if (sLM.length() == 1)
                sLM = "0" + sLM;

            page.print("<TD CLASS='xtd'>" + html.printDropDownMonth("sMonth", refMonth, sLM, true, false, false, true, true) + "&nbsp </TD>");
            page.print("<TD CLASS='xtd'><INPUT TYPE=SUBMIT NAME='query' VALUE=" + dbutil.getLabelOnly(conmgr.env.getUserId(), "B_ENQUIRY") + "> &nbsp&nbsp" + dbutil.getLabel(conmgr.env.getUserId(), "FPSSCHEDULE.WEEK") + " &nbsp</TD>");

            if (scheduleDet.sFPCode == null) {
                strFP = request.getParameter("fpcode");
            } else {
                strFP = scheduleDet.sFPCode;
            }

            iFDate = iFDate + (4 * 7);
            int daysinMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            if (((iYear % 4) == 0) && (((iYear % 100) != 0) || ((iYear % 400) == 0)))
                daysinMonth[1] = 29;

            for (int i = 1; i < 6; i++) {
                page.print("<TD CLASS='xtd'>");

                if (i==5 && iFDate > daysinMonth[iMonth - 1]) {

                } else {
                    if (i != iWeek) {
                        page.print("<TD CLASS='xtd'><A HREF='wschdlr?cmonth="+ curMonth + "&cyear=" + curYear + "&cweek=" + i + "&miid=" + miid +"&fpcode=" + strFP +"'>" + i + "</A></TD>");
                    } else {
                        page.print("<TD CLASS='xtd'>" + i + "</TD>");
                    }
                }
                page.print("</TD>");
            }

            page.print("</TR></TABLE>");
            page.print(html.printHiddenField("miid", miid));
            page.print(html.printHiddenField("fpcode", scheduleDet.sFPCode));
            page.print("</FORM>");

        schdDet = dbSchedule.getScheduleByFP(strFP, dFDay, dLDay);

            int iACount = Integer.parseInt(DateEx.dateToStringFormat(dFDay,"DD"));
            int iDate = 0;

            for (int i2 = 0; i2 < 32; i2++) {
            if(aL[i2] == null)
                aL[i2] = new ArrayList();
            }

            if (schdDet != null) {
                for (int i = 0; i < schdDet.length; i++) {
                    //for (int i2 = iACount; i2 < iACount + 7; i2++) {
                    for (int i2 = 1; i2 < 32; i2++) {
                        Calendar cl = Calendar.getInstance();
                        cl.setTime(schdDet[i].dtApptDateTime);
                        iDate = cl.get(Calendar.DAY_OF_MONTH);

                        if(iDate == i2) {
                            aL[i2].add(schdDet[i]);
                        }
                    }
                }
            }

            //show calendar

            SimpleDateFormat sd1 = new SimpleDateFormat("MMMMM");

            page.print("<CENTER>");
            page.print("<FORM NAME='fweek' ACTION='wschdlr' METHOD=POST>");
            page.print("<TABLE CELLPADDING='3' CELLSPACING='0' WIDTH='95%' BORDER='2' BGCOLOR='FFFFFF'>");
            page.print("<TR VALIGN='MIDDLE' ALIGN='CENTER'>");
            page.print("<TD COLSPAN='7'>");
            page.print("<TABLE CELLPADDING='0' CELLSPACING='0' WIDTH='100%' BORDER='0'>");
            page.print("<TR VALIGN='MIDDLE' ALIGN='CENTER'>");
            page.print("<TH WIDTH='100%' CLASS='xtd2'>" + dbutil.getLabel(conmgr.env.getUserId(), "FPSSCHEDULE.WEEK") + " " + iWeek + "&nbsp &nbsp" + sd1.format(dend) + " " + curYear + "</TH>");
            page.print("</TR></TABLE></TD></TR>");

            //start print details

            page.print("<TR VALIGN='TOP' ALIGN='CENTER' BGCOLOR='FFFFFF'>");

            SimpleDateFormat sd = new SimpleDateFormat("EEEEE");
            Calendar c = Calendar.getInstance();
            Calendar c2 = Calendar.getInstance();

            for (int iDay2 = 1; iDay2 < 8; iDay2++) {
                //c.set(Calendar.DAY_OF_WEEK,iDay2);
                c.set(c.get(c.YEAR), dend.getMonth(), iDay2);
                page.print("<TD WIDTH='14%' CLASS='xtd'>"+ sd.format(c.getTime()) + "<BR>");

                c2.set(iYear, iMonth-1, Integer.parseInt(DateEx.dateToStringFormat(dFDay,"DD")));
                c2.add(c2.DATE, + (iDay2-1));

                //page.print("(" + c2.get(c2.DATE) + "/" + (c2.get(c2.MONTH)+1) + "/" + c2.get(c2.YEAR) + ")" + "</TH>");
                //page.print("<A HREF='feschdlr?miid=11005&mode=2&reload=&ApptDate="+ c2.get(c2.DATE) + "/" + (c2.get(c2.MONTH)+1) + "/" + c2.get(c2.YEAR) +"&FPCode="+ strFP +"'>" + "(" + c2.get(c2.DATE) + "/" + (c2.get(c2.MONTH)+1) + "/" + c2.get(c2.YEAR) + ")" + "</A></TD>");                page.print("<A HREF='feschdlr?miid=11005&ApptDate="+ c2.get(c2.DATE) + "/" + (c2.get(c2.MONTH)+1) + "/" + c2.get(c2.YEAR) +"'>" + "(" + c2.get(c2.DATE) + "/" + (c2.get(c2.MONTH)+1) + "/" + c2.get(c2.YEAR) + ")" + "</A></TD>");
            }
            page.print("</TR>");

            int iC1 = 0;
            int iC2 = 0;

            for (int iC=iACount; iC < iACount + 7; iC++) {
                page.print("<TD WIDTH='14%' HEIGHT='100' VALIGN='TOP' ALIGN='LEFT' CLASS='xtd'><BR>");
                page.print("<TABLE CELLPADDING='0' CELLSPACING='0' WIDTH='100%' BORDER='0' BGCOLOR='FFFFFF'>");

                if (iC > daysinMonth[iMonth - 1]) {
                    iC2 = iC2 + 1;
                    iC1 = iC2;
                } else {
                    iC1 = iC;
                }

                if (! aL[iC1].isEmpty()) {
                    for (int iSDet=0; iSDet < aL[iC1].size(); iSDet++) {
                        FPSScheduleDetail a = (FPSScheduleDetail)aL[iC1].get(iSDet);

                        page.print("<TR>");
                        //page.print("<TD CLASS='xtd3'><A HREF='feschdlr?miid=11005&mode=2&ApptId="+ a.sApptId +"'>" + "<BR>" + DateEx.dateToStringFormat(a.dtApptDateTime,"HH:NN") + "<BR>" + dbClient.getClientName(a.sClientNo) + "<BR>" + a.sApptCode + "</A></TD>");

                        page.print("<TD CLASS='xtd3'><A HREF='feschdlr?miid=11005&mode=2&ApptId="+ a.sApptId +"'>");
                        page.print("<FONT SIZE='5'>" + DateEx.dateToStringFormat(a.dtApptDateTime,"HH:NN") + " - " + DateEx.dateToStringFormat(a.dtApptDateEnd,"HH:NN") + "</FONT>");

                        if (cv.isMandatory(a.sClientNo))
                            page.print("<BR>" + dbClient.getClientName(a.sClientNo) + "<BR>" + LookUpUtil.codeToDesc(apptInfo, a.sApptCode));
                        else
                            page.print("<BR> NOT ASSIGN <BR>" + LookUpUtil.codeToDesc(apptInfo, a.sApptCode));

                        if (a.sRstDesc != null)
                            page.print("<BR>" + a.sRstDesc + "<BR>");

                        if (a.sRemarks != null)
                            page.print("<BR>" + a.sRemarks + "<BR>");

                            page.print("<BR><BR><BR><BR></A></TD></TR>");
                    }
                }
                page.print("</TABLE>");
                page.print("</TD>");
            }

            page.print(html.printHiddenField("miid", miid));
            page.print("</TABLE></FORM>");
            page.print("</CENTER");