📄 dateeditthing.java
字号:
/*
*
*/
import java.io.*;
import java.text.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DateEditThing 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.USER_NEED_LOGIN,"",
"用户不存在或用户密码错误",
"Login?action=reLog");
return;
}
name= person.getName ().trim();
//定义得到的时间的变量
String sYear=new String();
String sMonth = new String ();
String sDay = new String ();
String sId = new String ();
String sAction = new String ();
String sHowLong = "";
Calendar now = Calendar.getInstance ();
//得到操作日期及事件id
sYear = request.getParameter ("y");
sMonth = request.getParameter ("m");
sDay = request.getParameter ("d");
sAction = request.getParameter ("action");
int nYear,nMonth,nDay,nId=1;
if (sYear ==null)
sYear="";
if (sYear.trim ()=="")
nYear=now.get (now.YEAR );
else{
try{
nYear=Integer.valueOf (sYear).intValue ();
}catch(Exception e)
{
nYear = now.get(now.YEAR );
}
}
if (sMonth ==null)
sMonth="";
if (sMonth.trim ()=="")
nMonth=now.get (now.MONTH ) + 1;
else{
try{
nMonth=Integer.valueOf (sMonth).intValue ();
}catch(Exception e)
{
nMonth = now.get(now.MONTH ) + 1;
}
}
if (sDay ==null)
sDay="";
if (sDay.trim ()=="")
nDay=now.get (now.DATE );
else{
try{
nDay=Integer.valueOf (sDay).intValue ();
}catch(Exception e)
{
nDay = now.get(now.DATE );
}
}
int nAwokeType=0;
int length=0;
if (request.getParameter ("awoke")==null){
nAwokeType = 0;
}
else
{
length = request.getParameterValues ("awoke").length ;
String [] sAwokeType = new String [length];
sAwokeType = request.getParameterValues ("awoke");
for (int i=0;i<length;i++)
{
sAwokeType[i]=CommonMethods.DealWithGBCodeOfRequest (sAwokeType[i]);
if ((sAwokeType[i]==null)||(sAwokeType[i].trim ().length ()==0))
continue;
if (sAwokeType[i].trim ().compareTo ("SMS")==0)
nAwokeType +=1;
if (sAwokeType[i].trim ().compareTo ("寻呼")==0)
nAwokeType +=2;
}
}
String flag= new String ();
sId = request.getParameter ("id");
if (sId==null)
sId="";
if (sId.compareTo ("")==0){
DBOperater DB = new DBOperater ("ps_DatePlan");
ResultSet rs = DB.executeQuery ("select id from ps_DatePlan 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;
}
}
//得到操作标识,edit为修改,add为增加,cancel为取消。
//得到计划的相关信息,如时间、标题、内容等
String sYearBegin = new String ();
String sMonthBegin = new String ();
String sDayBegin = new String ();
String sHoursBegin = new String ();
String sMinuteBegin = new String ();
String sHoursEnd = new String ();
String sMinuteEnd = new String ();
String sTitle = new String ();
String sType = new String ();
String sContent = new String();
String sRduration = new String ();//是否重复,to持续指定的时间,forever永远重复(截止到本系统能够识别的最大日期)
String sIsWholeDay = new String();//时间是否确定,period到某一特时间,wholeday时间不确定
String sAwokeDay = new String ();
String sAwokeHours = new String ();
String sAwokeMinute = new String ();
String sAwoke = new String ();
int nAwokeDay,nAwokeMinute,nAwokeHours;
int nType;
if (sAwoke==null)
sAwoke="no";
sAwoke=sAwoke.trim ();
sAwokeDay = request.getParameter ("ad");
sAwokeHours = request.getParameter ("ah");
sAwokeMinute = request.getParameter ("am");
if (sAwokeDay==null)
sAwokeDay="0";
if (sAwokeHours==null)
sAwokeHours="0";
if (sAwokeMinute==null)
sAwokeMinute="0";
try{
nAwokeDay=Integer.valueOf (sAwokeDay.trim ()).intValue ();
}catch(Exception e)
{
nAwokeDay=0;
}
try{
nAwokeHours=Integer.valueOf (sAwokeHours.trim ()).intValue ();
}catch(Exception e)
{
nAwokeHours=0;
}
try{
nAwokeMinute=Integer.valueOf (sAwokeMinute.trim ()).intValue ();
}catch(Exception e)
{
nAwokeMinute=0;
}
sAwoke = request.getParameter ("awoket");//yes or no
sYearBegin = request.getParameter ("y1");
sMonthBegin =request.getParameter ("m1");
sDayBegin = request.getParameter ("d1");
sHoursBegin = request.getParameter ("h1");
sMinuteBegin = request.getParameter ("mi1");
sTitle = request.getParameter ("title");
sContent = request.getParameter ("content");
sType = request.getParameter ("type");
//处理事件类型
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个汉字内",
"ShowDay");
htmlOut.outHtml();
return;
}
if (sContent.length ()>160)
{
htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
"日记内容太长,应在80个汉字内",
"ShowDay");
htmlOut.outHtml();
return;
}
sTitle=CommonMethods.DealWithSQLParameter (sTitle);
sContent=CommonMethods.DealWithSQLParameter (sContent);
int nYearBegin,nMonthBegin,nDayBegin,nHoursBegin,nMinuteBegin;
int nYearEnd=0,nMonthEnd=0,nDayEnd=0,nHoursEnd=0,nMinuteEnd=0;
//将得到的日期参数从字符型转换为数字型
if (sYearBegin==null)
{
nYearBegin=now.get(now.YEAR );
}
else{
try{
nYearBegin = Integer.valueOf (sYearBegin).intValue ();
}catch(Exception e){
nYearBegin = now.get (now.YEAR );
}
}
if (sMonthBegin==null)
{
nMonthBegin=now.get(now.MONTH ) +1 ;
}
else{
try{
nMonthBegin = Integer.valueOf (sMonthBegin).intValue ();
}catch(Exception e){
nMonthBegin = now.get (now.MONTH ) + 1;
}
}
if (sDayBegin==null)
{
nDayBegin=now.get(now.DATE );
}
else{
try{
nDayBegin = Integer.valueOf (sDayBegin).intValue ();
}catch(Exception e){
nDayBegin =now.get (now.DATE );
}
}
if (sMinuteBegin==null)
{
nMinuteBegin=now.get(now.MINUTE );
}
else{
try{
nMinuteBegin = Integer.valueOf (sMinuteBegin).intValue ();
}catch(Exception e){
nMinuteBegin =now.get (now.MINUTE );
}
}
if (sHoursBegin==null)
{
nHoursBegin=now.get(now.HOUR_OF_DAY );
}
else{
try{
nHoursBegin = Integer.valueOf (sHoursBegin).intValue ();
}catch(Exception e){
nHoursBegin =now.get (now.HOUR_OF_DAY );
}
}
Calendar begin=Calendar.getInstance ();
Calendar end = Calendar.getInstance ();
begin.set(nYearBegin,nMonthBegin-1,nDayBegin);
sRduration = request.getParameter("rdurationt");
sIsWholeDay = request.getParameter ("iswholedayt");
if (sRduration ==null)
sRduration="";
if (sRduration.trim().compareTo ("forever")==0){
nYearEnd=2049;
nMonthEnd=12;
nDayEnd=31;
//当持续时间为永远时
}
else if(sRduration.trim ().compareTo ("to")==0){
sHowLong=request.getParameter ("dtype");
if (sHowLong==null)
end.set (nYearBegin,nMonthBegin-1,nDayBegin);
else{
sHowLong=CommonMethods.DealWithGBCodeOfRequest (sHowLong.trim());
if (sHowLong.compareTo ("二周")==0)
end.set(nYearBegin,nMonthBegin-1,nDayBegin+14);
if (sHowLong.compareTo ("一周")==0)
end.set(nYearBegin,nMonthBegin-1,nDayBegin+7);
if (sHowLong.compareTo ("一月")==0)
end.set (nYearBegin,nMonth,nDayBegin);
if (sHowLong.compareTo ("二月")==0)
end.set (nYearBegin,nMonth+1,nDayBegin);
if (sHowLong.compareTo ("三月")==0)
end.set(nYearBegin,nMonth+2,nDayBegin);
if (sHowLong.compareTo ("半年")==0)
end.set (nYearBegin,nMonth+5,nDayBegin);
if (sHowLong.compareTo ("一年")==0)
end.set (nYearBegin+1,nMonth-1,nDayBegin);
if (sHowLong.compareTo ("二年")==0)
end.set(nYearBegin+2,nMonth-1,nDayBegin);
}
}
else{
return;
}
nYearEnd=end.get(end.YEAR );
nMonthEnd=end.get(end.MONTH )+1;
nDayEnd = end.get(end.DATE );
if (sIsWholeDay==null)
{
return;
}
else{
if (sIsWholeDay.trim ().compareTo ("period")==0){
sHoursEnd = request.getParameter ("h2");
sMinuteEnd = request.getParameter ("mi2");
if (sHoursEnd==null)
{
nHoursEnd=0;
}
else{
try{
nHoursEnd = Integer.valueOf (sHoursEnd).intValue ();
}catch(Exception e){
nHoursEnd =0;
}
}
if (sMinuteEnd==null)
{
nMinuteEnd=0;
}
else{
try{
nMinuteEnd = Integer.valueOf (sMinuteEnd).intValue ();
}catch(Exception e){
nMinuteEnd =0;
}
}
end.set (nYearEnd,nMonthEnd,nDayEnd,nHoursBegin+nHoursEnd,nMinuteBegin+nMinuteEnd);
nHoursEnd = end.get(end.HOUR_OF_DAY );
nMinuteEnd = end.get(end.MINUTE );
}
else if (sIsWholeDay.trim ().compareTo ("isWholeDay")==0){
nHoursEnd=-1;
nMinuteEnd=-1;
}
}
//当操作标识为edit时,根据用户名及计划id更新数据库
if (flag.compareTo ("edit")==0){
String queryString= new String ();
if ((nHoursEnd==-1)&&(nMinuteEnd==-1))
queryString=" UPDATE ps_dateplan SET datebeginyear = '"+nYearBegin+"', datebeginmonth = '"+nMonthBegin
+"',datebeginday = '"+nDayBegin+"', datebeginhours = '"+0+"', datebeginminute = '"+0
+"',datecontent = '"+sContent+"', datetitle = '"+sTitle+"', datestyle = '"+sType+"', dateawoke = '"+sAwoke+"',awokeday = '"+nAwokeDay
+"',awokehours = '"+nAwokeHours+", dateendyear = '"
+nYearEnd+"',dateendmonth = '"+nMonthEnd+"',dateendday = '"+nDayEnd+"', dateendhours = '"+23+"', dateendminute = '"
+59+"', planrepeat = '"+sHowLong+"',wholeday = '"+sIsWholeDay+"', howlong = '"+sRduration+"', awokeminute = '"+nAwokeMinute+"',awoketype = '"+nAwokeType+"' WHERE ( id = '"+nId+"' ) AND ( username = '"+name+"' ) ";
else
queryString=" UPDATE ps_dateplan SET datebeginyear = '"+nYearBegin+"', datebeginmonth = '"+nMonthBegin
+"',datebeginday = '"+nDayBegin+"', datebeginhours = '"+nHoursBegin+"', datebeginminute = '"+nMinuteBegin
+"',datecontent = '"+sContent+"', datetitle = '"+sTitle+"', datestyle = '"+sType+"', dateawoke = '"+sAwoke+"',awokeday = '"+nAwokeDay
+"',awokehours = '"+nAwokeHours+"',dateendyear = '"
+nYearEnd+"',dateendmonth = '"+nMonthEnd+"',dateendday = '"+nDayEnd+"', dateendhours = '"+nHoursEnd+"', dateendminute = '"
+nMinuteEnd+"', planrepeat = '"+sHowLong+"', wholeday = '"+sIsWholeDay+"', howlong = '"+sRduration+"', awokeminute = '"+nAwokeMinute+"',awoketype = '"+nAwokeType+"' WHERE ( id = '"+nId+"' ) AND ( username = '"+name+"' ) ";
DBOperater DB= new DBOperater ("ps_DatePlan");
DB.executeUpdate (queryString);
DB.close ();
}
//当操作标识为add时,增加用户计划
else if(flag.compareTo ("add")==0){
String queryString= new String ();
if ((nHoursEnd==-1)&&(nMinuteEnd==-1))
queryString="INSERT INTO ps_dateplan( id,username,datebeginyear,datebeginmonth, datebeginday,"
+"datebeginhours,datebeginminute,datecontent,datetitle, datestyle, dateawoke,"
+"awokeday,awokehours,dateendyear,dateendmonth, dateendday, dateendhours,"
+"dateendminute,planrepeat,showcolor, wholeday, howlong ,awokeminute,awoketype)"
+" VALUES ( '"+nId+"', '"+name+"', '"+nYearBegin+"','"+nMonthBegin+"', '"+nDayBegin
+"','"+0+"', '"+0+"', '"+sContent+"', '"+sTitle+"', '"+sType
+"','"+sAwoke+"', '"+nAwokeDay+"', '"+nAwokeHours+"', '"+nYearEnd+"', '"+nMonthEnd+"', '"+nDayEnd
+"', '"+23+"','"+59+"', '"+sHowLong+"', '"+null+"', '"+sIsWholeDay+"', '"+sRduration+"','"+nAwokeMinute+"','"+nAwokeType+"')";
else
queryString="INSERT INTO ps_dateplan( id,username,datebeginyear,datebeginmonth, datebeginday,"
+"datebeginhours,datebeginminute,datecontent,datetitle, datestyle, dateawoke,"
+"awokeday,awokehours,dateendyear,dateendmonth, dateendday, dateendhours,"
+"dateendminute,planrepeat,showcolor, wholeday, howlong ,awokeminute,awoketype)"
+" VALUES ( '"+nId+"', '"+name+"', '"+nYearBegin+"','"+nMonthBegin+"', '"+nDayBegin
+"','"+nHoursBegin+"', '"+nMinuteBegin+"', '"+sContent+"', '"+sTitle+"', '"+sType
+"','"+sAwoke+"', '"+nAwokeDay+"', '"+nAwokeHours+"', '"+nYearEnd+"', '"+nMonthEnd+"', '"+nDayEnd
+"', '"+nHoursEnd+"','"+nMinuteEnd+"', '"+sHowLong+"', '"+null+"', '"+sIsWholeDay+"', '"+sRduration+"','"+nAwokeMinute+"','"+nAwokeType+"')";
DBOperater DB = new DBOperater ("ps_DatePlan");
DB.executeUpdate (queryString);
DB.close ();
htmlOut.setRedirect("DateUpdateThing");
}
else{
return;
}
//当操作标识为cancel时,直接返回日历的页面
if(sAction.compareTo ("add")==0)
{
String returnUrl;
returnUrl="DateUpdateThing?y="+nYear+"&m="+nMonth+"&d="+nDay+"&action=add";
response.sendRedirect (returnUrl);
}
else if(sAction.compareTo ("save")==0)
{
String returnUrl;
returnUrl="DateShowDay?y="+nYear+"&m="+nMonth+"&d="+nDay;
response.sendRedirect (returnUrl);
}
else
{
return;
}
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request,response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -