⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dateupdatething.java

📁 JAVA邮件系统
💻 JAVA
字号:
/* 
 *
 */

import java.io.*;
import java.text.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DateUpdateThing extends HttpServlet {

    
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
		HtmlOut htmlOut = new HtmlOut(response);
		// 得到名字和口令
		String name,pass;

		Person person = new Person();
		person.setName (CommonMethods.GetUserName(request));
		pass = CommonMethods.GetUserPass (request);
		//判断用户名及密码是否合法
		if( person.getName ()==null || (!person.checkPassword(pass)) )
		{
	    	htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"请先登录!","Login?action=reLog");
			htmlOut.outHtml();
			return;
		}
		name= person.getName ().trim();
		//定义得到的时间的变量
		String sYear= new String ();
		String sMonth= new String();
		String sDay= new String ();
//		String sAction = new String ();
		String sId = new String ();
		//相应的整形变量
		int nYear= 0;
		int nMonth= 0;
		int nDay= 0;
		int id=0;
		int nYearBegin=0;
		int nMonthBegin=0;
		int nDayBegin=0;
		int nHoursBegin=0;
		int nMinuteBegin=0;
		int nYearEnd=0;
		int nMonthEnd=0;
		int nDayEnd=0;
		int nHoursEnd=0;
		int nMinuteEnd=0;
		
		sYear = request.getParameter("y");
		sMonth = request.getParameter ("m");
		sDay = request.getParameter ("d");
        //sAction = request.getParameter ("action");
		sId = request.getParameter ("id");
	/*	if (sAction==null)
			sAction="add";*/
		//判断年月日是否为空
		if ((sYear ==null ) ||(sMonth==null) || (sDay==null)){
	    	htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
							"请选择正确的日期","Login");
            htmlOut.outHtml();
			return;
		}
		//将年、月、日、时、分从字符型改为数字型 begin
		Calendar myCalendar = Calendar.getInstance ();
		MyCalendar calendar=new MyCalendar ();
		try{
			nYear=Integer.valueOf(sYear).intValue ();
		}catch(Exception e){
			nYear= myCalendar.get (myCalendar.YEAR );
		}
		try{
			nMonth=Integer.valueOf(sMonth).intValue ();
		}catch(Exception e){
			nMonth =myCalendar.get (myCalendar.MONTH );
		}
		try{
			nDay= Integer.valueOf(sDay).intValue ();
		}catch(Exception e){
			nDay = myCalendar.get (myCalendar.DATE );
		}

		//end
		String sTitle = new String();//计划标题
		String sType = new String ();
		String sContent = new String ();
		String action= new String (); //edit or add
		//
		if ((sId==null)||(sId.trim ()=="")){
		    id=1;
			action="add";
		}
		else{
			try{
			   id=Integer.valueOf  (sId).intValue ();
			   action="edit";
			}catch(Exception e)
			{
			  id=1;
			  action="add";
			}
		}
		//	
		String sDateAwoke = new String ();
		int nAwokeDay=0;
		int nAwokeHours=0;
		int nAwokeMinute=0;
		int nAwokeType = 0;
		String sWholeDay = new String ();
		String sHowLong = new String ();
		String sRepeat = new String ();
		//if (sAction.trim ().compareTo ("edit")==0)
		if (action.trim().compareTo ("edit")==0)
		{
			DBOperater DB = new DBOperater ("ps_DatePlan");
			ResultSet rs=DB.executeQuery ("  SELECT * FROM ps_dateplan WHERE id = '"+id	+"'and username='" +name+"' ");
				if (rs!=null)
					try{
						if (rs.next ()){
							nYearBegin=rs.getInt(3);
							nMonthBegin=rs.getInt(4);
							nDayBegin=rs.getInt (5);
							nHoursBegin=rs.getInt(6);
							nMinuteBegin=rs.getInt(7);
							sContent = rs.getString(8);
							if (sContent==null)
								sContent="";
							sTitle = rs.getString(9);
							if (sTitle==null)
								sTitle = "";
							sType = rs.getString(10);
							sDateAwoke= rs.getString(11);   
							nAwokeDay = rs.getInt(12);
							nAwokeHours= rs.getInt(13);
							nHoursEnd = rs.getInt(17);
							nMinuteEnd = rs.getInt(18);
							sRepeat=rs.getString (19);
							sWholeDay = rs.getString(21);
							sHowLong = rs.getString(22);
							nAwokeMinute = rs.getInt (23);
							nAwokeType = rs.getInt (24);
							if (nMinuteEnd < nMinuteBegin)
							{
								nMinuteEnd = nMinuteEnd + 60 - nMinuteBegin;
								nHoursEnd = nHoursEnd -1;
							}
							else
								nMinuteEnd = nMinuteEnd - nMinuteBegin;
							if (nHoursEnd < nHoursBegin)
							    nHoursEnd = nHoursEnd + 24 - nHoursBegin;
							else 
								nHoursEnd = nHoursEnd - nHoursBegin;
						}
					}catch(Exception e){
						DB.close ();
						return;
					}
				DB.close ();
		}
		else {
			sTitle="";
			sType="约会";
			sContent="";
		    nYearBegin=nYear;
		    nMonthBegin=nMonth;
		    nDayBegin=nDay;
		    nHoursBegin=myCalendar.get(myCalendar.HOUR_OF_DAY  );
		    nMinuteBegin=0;
		    nMinuteEnd=0;
			nHoursEnd=0;
		    sDateAwoke= "yes";   
			sRepeat="一周";
			sWholeDay = "period";
			sHowLong = "to";
			nAwokeType = 0;
		}
	    if ((nYear >=2050 ) || (nYear < 1900) || (nYear ==1900 && nMonth==1))
		{
			htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"请选择界于1900年2月到2050年之间的年份","Login");
			htmlOut.outHtml ();
			return;
		}
		if ((nMonth >=1)&&(nMonth <=12))
			;
		else{
			htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"请选择界于1-12之间的月份","Login");
			htmlOut.outHtml ();
			return;
		}
		if ((nDay>=1)&&(nDay <=calendar.getMaxDay (nYear,nMonth) ))
			;
		else {
				htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"请选择界于1-"+calendar.getMaxDay (nYear,nMonth)+"之间的日期","Login");
				htmlOut.outHtml ();
				return;		
		}
		//得到模板
		TemplateList tempList=CommonMethods.getDateEditThingTemplate (); 
		SingleTemplate st;
		st = tempList.searchTemplate ("ROOT");
		if(st==null)
			return ;
		//替换模板文件
		String sKey ;
		
		int nKey = st.getKeyNum ();
		for(int i=0;i<nKey;i++){
           	htmlOut.addString (st.getStringAt (i));
			sKey = st.getKeyAt (i);
			if( sKey.compareTo("cgi-path")==0 )
				htmlOut.addString (CommonMethods.sHostNameCGI);
			if( sKey.compareTo("年")==0 )
				htmlOut.addString (sYear);
	        if( sKey.compareTo ("月")==0)
				htmlOut.addString (sMonth);
			if(sKey.compareTo("日")==0)
				htmlOut.addString (sDay);
            if (sKey.compareTo ("开始年")==0)
				htmlOut.addString (nYearBegin+"");
			if (sKey.compareTo ("开始月")==0)
				htmlOut.addString (nMonthBegin+"");
			if (sKey.compareTo ("开始日")==0)
				htmlOut.addString (nDayBegin+"");
			if (sKey.compareTo ("开始时")==0)
				htmlOut.addString (nHoursBegin+"");
			if (sKey.compareTo ("开始分")==0)
				htmlOut.addString (nMinuteBegin+"");
			if (sKey.compareTo ("持续时")==0)
				htmlOut.addString (nHoursEnd+"");
			if (sKey.compareTo ("持续分")==0)
				htmlOut.addString (nMinuteEnd+"");
			if(sKey.compareTo("id")==0)
				htmlOut.addString (sId);
			if (sKey.compareTo ("内容")==0)
				htmlOut.addStringPlain (sContent);
			if (sKey.compareTo ("标题")==0)
				htmlOut.addStringPlain (sTitle);
			if (sKey.compareTo ("类型")==0)
				htmlOut.addStringPlain(sType);
			if (sKey.compareTo ("提前天")==0)
				htmlOut.addString (nAwokeDay+"");
			if (sKey.compareTo ("提前时")==0)
			    htmlOut.addString (nAwokeHours+"");
			if (sKey.compareTo ("提前分")==0)
				htmlOut.addString (nAwokeMinute+"");
			if (sKey.compareTo ("重复")==0)
				htmlOut.addString (sHowLong);
			if (sKey.compareTo ("重复时间")==0)
				htmlOut.addString (sRepeat);
			if (sKey.compareTo ("提醒")==0)
				htmlOut.addString (sDateAwoke);
			if (sKey.compareTo ("持续")==0)
				htmlOut.addString (sWholeDay);
			if (sKey.compareTo ("年历")==0)
				htmlOut.addString ("DateShowYear?y="+nYear);
			if (( sKey.compareTo ("寻呼")==0) && (nAwokeType / 2)==1)
				htmlOut.addString ("寻呼");
			if ((sKey.compareTo ("SMS")==0) && (nAwokeType % 2 )==1)
				htmlOut.addString ("SMS");
	}		

	    htmlOut.addString (st.getEndString());

		htmlOut.outHtml();
			
		return;
    }
	
       public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
		doGet(request,response);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -