พบกับบทความเกี่ยวกับคอมพิวเตอร์และ programming ได้ที่ http://articles.modoeye.com
Javascript development / ต้องการ search ข้อมูลเดือนปีให้แสดงออกมาจากฐานข้อมูล
supkakai
supkakai
Fri 4 Jan 2008 14:20:19

คือว่าได้ทำการสร้างไฟล์ .jsp ซึ่งเป็นหน้า ฟอร์มไว้เรียบร้อยแล้วอ่ะค่ะ ตอนนี้มาสร้างไฟล์ .java ซึ่งเป็นไฟล์ class โดยฟร์อมในช่องที่ให้กรอก ปีกับเดือนจะเป็นแบบ เลือก(select) ค่ะ  โดยในที่นี้ทำการดัดแปลงมาจากโปรแกรมเก่าซึ่งจะค้นหาแต่เพียงปี แก้ให้เป็นค้นหาทั้งเดือนและปีได้ตามนี้อ่ะค่ะ  แต่ว่ามันไมยอม search ข้อมูลช่วยแนะนำหน่อยซิค่ะว่าต้องแก้ตรงไหน จนปัญญาจริงค่ะ  เพิ่มเริ่มเขียนจาวามาได้ 1 กว่าๆ เองค่ะโดยไม่มีพื้นฐานอะไรเลย  ขอบคุณล่วงหน้าค่ะ

package master;

import java.sql.*;

import space.java.tag.*;
import master.dto.*;
import master.ejb.*;
import mos.java.util.*;

public class CHoliday extends VisualClient {
  public CHoliday() {
  }

  public VisualObject doStart() throws Exception {
    String url = (String)session.getAttribute("URL_AUTH");
    setAccessFunction(MOSPermission.getPermission(USER, SITE, "PPM03"), url);

    if(isNewPage) {
      setOption();
    }

    return vo;
  }

  public void doPost() throws Exception {
    vo.setAll();

    if(isAction("search")) {
      doSearch();
    } else if(isAction("add")) {
      vo.setReadonly("holiday", false);
      session.setAttribute("name", get("name"));
    } else {
      throw new Exception("Unknown Action: " + getAction());
    }
  }

  private void setOption() throws Exception {
    try {
      Date dtNow = DateTime.getNow();
      Integer intYear = DateTime.getYear(dtNow);

     int intYearStart = intYear.intValue()-3;
     int intYearEnd = intYear.intValue() + 2;
     int intSize = intYearEnd - intYearStart;

     String[][] option = new String[intSize][2];

     for(int i=0; i<intSize; i++) {
       String strYear = Converter.toString(intYearStart + i);

       option[i][0] = strYear;
       option[i][1] = strYear;
     }

     vo.setOption("year", option);


     String[][] option_month = new String[12][2];

     for(int j=0; j<12; j++) {
       String strMonth = Converter.toString(j + 1);

       option_month[j][0] = strMonth;
       option_month[j][1] = strMonth;
     }

     vo.setOption("month", option_month);


    } catch(Exception ex) {
     throw new Exception("setOption(): " + ex.getMessage(), ex);
    }
  }

  private void doSearch() throws Exception {
    try {
      Integer tmpYY = getInteger("year");
      int bYear = tmpYY.intValue() - 1;
      int aYear = tmpYY.intValue() + 1;
      String sDate = "31/12/" + bYear;
      String eDate = "01/01/" + aYear;

      HolidaySess holidaySess = Sessma.getHolidaySess();
      HolidayDto dto = holidaySess.getByYear(SITE, Converter.toDate(sDate), Converter.toDate(eDate));

      vo.set("year", Converter.toString(tmpYY));
      vo.set("holiday", dto.list);
    } catch(Exception ex) {
      throw new Exception("doSearch(): " + ex.getMessage(), ex);
    }
  }
}

webmaster
webmaster
Sat 5 Jan 2008 16:27:33
ไม่ค่อยถนัดด้วยครับ ไม่ทราบว่ามีแจ้ง Error ใดหรือไม่ครับ
Reply
Name:
E-mail:
Home | Services | Forum | Classified | Directories | Support | Contact
ATOM feed RSS 0.9 feed RSS 1.0 feed RSS 2.0 feed
Copyright © 2005 - 2007 Modoeye.com, All Rights Reserved.
Disclaimer | Privacy policy | Term of Use | Term of Services
Valid XHTML Valid CSS! PHP: Hypertext Preprocessor MySQL database Apache Powered! FreeBSD Power to serve
Modoeye Sitemap Client login