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

📄 datesaveimport.java

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

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


public class DateSaveImport 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 ();
 		//得到操作日期及事件id
		sYear = request.getParameter ("year");
		sMonth = request.getParameter ("month");
		sDay = request.getParameter ("day");
		sAction = request.getParameter ("action");
        int nYear,nMonth,nDay,nId=1;
		
		if (sYear ==null) 
			sYear="";
		if (sYear.trim ()=="")
		    nYear=0;
		else{
			try{
			   nYear=Integer.valueOf  (sYear).intValue ();
			}catch(Exception e)
			{
				nYear = 0;
			}
		   }
		if (sMonth ==null) 
			sMonth="";
		if (sMonth.trim ()=="")
		{   
		    htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"请输入正确月份","history.back()");
			htmlOut.outHtml();
			return;
		}
		else{
			try{
			   nMonth=Integer.valueOf  (sMonth).intValue ();
			}catch(Exception e)
			{
				htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"请输入正确月份","history.back()");
				htmlOut.outHtml();
				return;
			}
		}			
		if (sDay ==null) 
			sDay="";
		if (sDay.trim ()=="")
		{
	        htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"请输入正确日子","history.back()");
			htmlOut.outHtml();
			return;
		}
		
		else{
			try{
			   nDay=Integer.valueOf  (sDay).intValue ();
			}catch(Exception e)
			{
			htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"请输入正确日期","history.back()");
			htmlOut.outHtml();
			return;;
			}
		}
		//得到操作标识,edit为修改,add为增加,cancel为取消。
         
		//得到计划的相关信息,如时间、标题、内容等
		String sTitle = new String ();
		String sType = new String ();
		String sContent = new String();
        String sEachYear;
		String sAwoke;
		sAwoke = request.getParameter ("remind");
		sTitle = request.getParameter ("title");
		sContent = request.getParameter ("mem");
		sType = request.getParameter ("type");
		sEachYear = request.getParameter ("eachyear");
        if ((sEachYear==null) || (sEachYear.trim() ==""))
			sEachYear="当年";
        if (sEachYear.trim().compareTo ("yes")==0)
			sEachYear="每年";
		else
			sEachYear="当年";			
		if ((sAwoke==null)||(sAwoke.trim()==""))
			sAwoke="不提醒";
		else
			sAwoke=CommonMethods.DealWithGBCodeOfRequest (sAwoke.trim());
		//处理事件类型
		if (sType==null)
			sType="其他";
		else
			sType=CommonMethods.DealWithGBCodeOfRequest (sType.trim());
		if ((sTitle==null)||(sTitle==""))
			sTitle="无标题";
		else
			sTitle=CommonMethods.DealWithGBCodeOfRequest (sTitle.trim());
		if (sTitle.trim()=="")
			sTitle="无标题";
		if (sContent==null)
     		sContent="";
		else
			sContent=CommonMethods.DealWithGBCodeOfRequest (sContent.trim());
			if (sTitle.length ()>40)
	{
		    htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"日子题目太长,应在20个汉字内","history.back()");
			htmlOut.outHtml();
			return;
	}
	if (sContent.length ()>160)
	{
		    htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"日子说明内容太长,应在80个汉字内","history.back()");
			htmlOut.outHtml();
			return;
	}
	sTitle=CommonMethods.DealWithSQLParameter (sTitle);
	sContent=CommonMethods.DealWithSQLParameter (sContent);

	/////////////
  
	//查找最大id号
  String flag= "";
  String sId=new String ();
	sId = request.getParameter ("id");
		if (sId==null)
			sId="";
		if (sId.compareTo ("")==0){
		       DBOperater DB = new DBOperater ("ps_ImportDay");
               ResultSet rs = DB.executeQuery ("select id from ps_ImportDay where username ='"+name+"'ORDER BY id DESC");
               if(rs!=null){
               try{
               if( rs.next () )
                   nId = rs.getInt (1)+1;
			
			   }catch(Exception e){
				   DB.close ();
                   return;
               }
               }
			   else
			   nId= 1 ;
			   DB.close ();
			   flag="add";
		       }
		else{
			try{
			   nId=Integer.valueOf  (sId).intValue ();
			   if (nId<1)
				   nId=1;
			   flag="edit";
			}catch(Exception e)
			{
				return;
			}
		}					
    Calendar calendar=Calendar.getInstance ();
   int nEndYear,nEndMonth,nEndDay;
   if(sAwoke.trim().compareTo ("提前1天提醒")==0){
	   calendar.set(nYear,nMonth-1,nDay-1);
	   nEndYear=calendar.get(calendar.YEAR );
	   nEndMonth=calendar.get(calendar.MONTH )+1;
	   nEndDay = calendar.get(calendar.DATE );
   }
   else if(sAwoke.trim().compareTo ("提前2天提醒")==0){
	   calendar.set(nYear,nMonth-1,nDay-2);
	   nEndYear=calendar.get(calendar.YEAR );
	   nEndMonth=calendar.get(calendar.MONTH )+1;
	   nEndDay = calendar.get(calendar.DATE );
   }
   else if(sAwoke.trim().compareTo ("提前3天提醒")==0){
	   calendar.set(nYear,nMonth-1,nDay-3);
	   nEndYear=calendar.get(calendar.YEAR );
	   nEndMonth=calendar.get(calendar.MONTH )+1;
	   nEndDay = calendar.get(calendar.DATE );
   }
   else if(sAwoke.trim ().compareTo ("提前1周提醒")==0){
	   calendar.set(nYear,nMonth-1,nDay-7);
	   nEndYear=calendar.get(calendar.YEAR );
	   nEndMonth=calendar.get(calendar.MONTH )+1;
	   nEndDay = calendar.get(calendar.DATE );
   }
   else{
		nEndYear=nYear;
		nEndMonth=nMonth;
		nEndDay=nDay;
   }
   DBOperater DB1= new DBOperater ("ps_ImportDay");
   if (flag.trim ().compareTo ("add")==0)
   DB1.executeUpdate (" INSERT INTO ps_importday ( username,datetype, dateyear, datemonth, dateday, datetitle, datecontent, datestyle, dateawoke,    id,dateEndYear,dateEndMonth,dateEndDay)  VALUES ( '"
 				  +name+"', '"+sType+"', '"+nYear+"', '"+nMonth+"', '"+nDay+"', '"+sTitle+"',  '"+sContent+"', '"+sEachYear+"', '"+sAwoke+"',   '"+nId+"', '"+nEndYear+"', '"+nEndMonth+"', '"+nEndDay+"')");
   else if (flag.trim().compareTo ("edit")==0)
   DB1.executeUpdate ("UPDATE ps_importday    SET datetype = '"+sType+"', dateyear = '"+nYear+"', datemonth ='"+nMonth+"', dateday ='"+nDay+"' , datetitle =  '"+sTitle+"',   datecontent = '"+sContent+
					  "', datestyle =  '"+sEachYear+"',    dateawoke = '"+sAwoke+"',    dateendyear =  '"+nEndYear+"',     dateendmonth =  '"+nEndMonth+"',          dateendday = '"+nEndDay+"'where username='"+name+"'and id='"+nId+"'");
   DB1.close ();
   if(sAction.compareTo ("save")==0)
		{
			String returnUrl;
			response.sendRedirect ("DateShowImport");
		}
		else if(sAction.compareTo ("add")==0)
		{
			response.sendRedirect ("/DateEditImport.htm");
		}
		else if (sAction.compareTo ("birthday")==0)
		{
			//out.println ("设置成功");
			return;
		}
		else 
		{
		    htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"无法取得行为方式","history.back()");
			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 + -