package basic_set;
import java.util.*;
import javax.servlet.http.*;
import database.*;
import org.apache.struts.action.*;
import org.apache.struts.actions.*;
/**
<p>文件名称 : Manager_Action.java</p>
<p>文件作用 : 基础信息设置服务</p>
本服务主要针对2个表的管理操作:增加,修改,显示,删除
1.表:b_type,在跳转的时候使用 t=type
2.表:b_infor,在跳转的时候使用 t=infor
3.如有需要其它的操作,请使用者以外的数字 >10
@author 2006-11-15
@version 1.0.1
*/
public class Basic_Set_Action extends DispatchAction
{
Basic_Set_Function m_comm = new Basic_Set_Function();
ActionErrors m_errors = new ActionErrors();
ActionMessages error_messages = new ActionMessages();
Comm_function m_function=new Comm_function();
int m_remark_length=200;
/**
* 表[b_type]增加状态
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
public ActionForward b_type_add(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
HttpSession session = request.getSession(true);
if (session.getAttribute("login_name") == null) {
return mapping.findForward("overtime");
}
Basic_Set_Form m_Form = (Basic_Set_Form) form;
m_Form.setM_id(m_comm.get_b_type_max_id_plus_one());
m_Form.setM_b_type("");
m_Form.setM_b_remark("");
request.setAttribute("b_type",m_Form);
return mapping.findForward("b_type_addmodify");
}
/**
* 表[b_infor]增加状态
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
public ActionForward b_infor_add(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
Basic_Set_Form m_Form = (Basic_Set_Form) form;
HttpSession session = request.getSession(true);
if (session.getAttribute("login_name") == null) {
return mapping.findForward("overtime");
}
m_Form.setM_id(m_comm.get_b_infor_max_id_plus_one());
m_Form.setM_b_infor("");
m_Form.setM_b_remark("");
request.setAttribute("b_infor",m_Form);
return mapping.findForward("b_infor_addmodify");
}
/**
* 表[b_type]修改状态
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
public ActionForward b_infor_modify(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
Basic_Set_Form m_Form = (Basic_Set_Form) form;
HttpSession session = request.getSession(true);
if (session.getAttribute("login_name") == null) {
return mapping.findForward("overtime");
}
String m_id=m_Form.getM_id();//request.getParameter("id");
ArrayList m_list = new ArrayList();
m_list=m_comm.m_get_b_infor(m_id);
for(int i=0;i<m_list.size();i++)
{
m_Form=(Basic_Set_Form)m_list.get(i);
}
m_Form.setAddmodify("修改");
request.setAttribute("b_infor",m_Form);
return mapping.findForward("b_infor_addmodify");
}
/**
* 表[b_infor]执行删除操作
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
public ActionForward b_infor_del_do(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
String[] values = new String[1];
String message="";
Basic_Set_Form m_Form = (Basic_Set_Form) form;
values[0] = m_Form.getM_id();
if (m_comm.RecordDelete_b_infor(values))
{
message="删除序号:【" + m_Form.getM_id() +
"】信息:【" + m_Form.getM_b_infor() +
"】成功!";
} else {
message="删除【" + m_Form.getM_b_infor() +
"】失败,可能不存在此记录!";
}
m_Form.setM_do_message(message);
m_Form.setM_id(m_Form.getM_b_type_id());
request.setAttribute("do_message", m_Form);
return mapping.findForward("do_message_b_infor");
}
/**
* 表[b_type]删除状态
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
public ActionForward b_infor_del(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
String m_id="";
Basic_Set_Form m_Form = (Basic_Set_Form) form;
HttpSession session = request.getSession(true);
if (session.getAttribute("login_name") == null) {
return mapping.findForward("overtime");
}
m_id=m_Form.getM_id();
m_Form.setM_id(m_id);
m_Form.setM_b_infor(m_comm.get_b_infor(m_id));
request.setAttribute("b_type",m_Form);
return mapping.findForward("b_infor_del");
}
/**
* 表[b_type]修改状态
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
public ActionForward b_type_modify(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
Basic_Set_Form m_Form = (Basic_Set_Form) form;
HttpSession session = request.getSession(true);
if (session.getAttribute("login_name") == null) {
return mapping.findForward("overtime");
}
String m_id=request.getParameter("id");
String[] id =new String[1];
id[0]=m_id;
ArrayList m_list = new ArrayList();
m_list=m_comm.m_get_b_type(id);
for(int i=0;i<m_list.size();i++)
{
m_Form=(Basic_Set_Form)m_list.get(i);
}
m_Form.setAddmodify("修改");
request.setAttribute("b_type",m_Form);
return mapping.findForward("b_type_addmodify");
}
/**
* 表[b_type]执行删除
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
public ActionForward b_type_del_do(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
Basic_Set_Form m_Form = (Basic_Set_Form) form;
HttpSession session = request.getSession(true);
if (session.getAttribute("login_name") == null) {
return mapping.findForward("overtime");
}
String[] values = new String[1];
values[0] = m_Form.getM_id();
String m_count="";
String str="";
//首先判断是否存在子数据
m_count = m_comm.get_b_infor_count(m_Form.getM_id());
if(Integer.parseInt(m_count)>0)
{
str="序号:【"
+ m_Form.getM_id()
+ "】类型:【"
+ m_Form.getM_b_type()
+ "】其存在信息子数据,请先删除子数据,再删除本数据。";
m_Form.setM_do_message(str);
}
else
{
if (m_comm.RecordDelete(values))
{
m_Form.setM_do_message("删除序号:【" + m_Form.getM_id() + "】类型:【" +
m_Form.getM_b_type() + "】成功!");
} else {
m_Form.setM_do_message("删除【" + m_Form.getM_b_type() +
"】失败,可能不存在此记录!");
}
}
request.setAttribute("do_message", m_Form);
return mapping.findForward("do_message");
}
/**
* 表[b_type]删除状态
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
public ActionForward b_type_del(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
String m_id="";
Basic_Set_Form m_Form = (Basic_Set_Form) form;
HttpSession session = request.getSession(true);
if (session.getAttribute("login_name") == null) {
return mapping.findForward("overtime");
}
m_id=request.getParameter("id");
m_Form.setM_id(m_id);
m_Form.setM_b_type(m_comm.get_b_type(m_id));
request.setAttribute("b_type",m_Form);
return mapping.findForward("b_type_del");
}
/**
* 表[b_type]表格显示
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
public ActionForward b_type_view(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
HttpSession session = request.getSession(true);
if (session.getAttribute("login_name") == null) {
return mapping.findForward("overtime");
}
String m_academy_id=(String)session.getAttribute("academy_id");
if(m_academy_id.equals("0"))
{
request.setAttribute("list", m_comm.get_b_type());
return mapping.findForward("b_type");
}
else
{
//当前用户无法登陆
return mapping.findForward("message");
}
}
/**
* 表[b_infor]分页表格显示
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
public ActionForward b_infor_view(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
// 以下查询结果需要分页显示:分以下四个步骤
// 第一步:首次得到分页码
Basic_Set_Form m_Form = (Basic_Set_Form) form;
HttpSession session = request.getSession(true);
if (session.getAttribute("login_name") == null) {
return mapping.findForward("overtime");
}
int curPage = 1;
if (request.getParameter("cur_page") == null)
{
curPage = 1;
}
else
{
curPage = Integer.parseInt(request.getParameter("cur_page"));
}
//第二步:得到需要传递的参数=在页面显示+在SQL里面使用
String m_id = m_Form.getM_id();
//重要说明,在连接的时候,如下,就可以获得m_id的数据了,m_id是一个Form属性
//jsp: paramId="m_id" paramName="rs" paramProperty="m_id"
m_Form.setM_b_type_id(m_id);
m_Form.setM_b_type(m_comm.get_b_type(m_id));
//第三步:给页面传递信息
request.setAttribute("b_type",m_Form);
//第四步:把得到的值放入输入里面,然后传递给业务函数里面使用
String[] m_id_str_array = new String[1];
if (m_id.equals(""))
{
m_id_str_array = null;
}
else
{
m_id_str_array[0] = m_Form.getM_id();
}
//开始分页 : 得到分页的当前页码 + SQL查询参数
PageResultSet pageResultSet=m_comm.getB_infor_Table(curPage,m_id_str_array,15);
ArrayList m_list = (ArrayList)pageResultSet.getData();
ArrayList m_list_rs =new ArrayList();
if (m_list.size() == 0)
{
//out.print("<tr ><td colspan=7>");
//out.print("<font color='red'>当前查询没有记录!</font></td></tr>");
}
else
{
for (int i = 0; i < m_list.size(); i++)
{
//使用数组方式得到值
String[] m_value = new String[6];
m_value = (String [])m_list.get(i);
Basic_Set_Form m_form = new Basic_Set_Form();
//设置隔行颜色差别
if(i%2==0)
{
m_form.setLine_color(database.Constant.m_line_color1);
}
else
{
m_form.setLine_color(database.Constant.m_line_color2);
}
m_form.setNo(i+1);
m_form.setM_id(m_value[0]);
m_form.setM_b_infor(m_value[1]);
m_form.setM_b_remark(m_value[2]);
m_form.setM_record_date(m_value[3]);
m_form.setM_record_time(m_value[4]);
m_form.setM_reporter(m_value[5]);
m_list_rs.add(m_form);
}
}
request.setAttribute("list",m_list_rs);
request.setAttribute("divpage_tools",pageResultSet.getToolBar("basic_set.do?method=b_infor_view"));
return mapping.findForward("b_infor");
}
/**
* 表[b_infor]调用执行 增加 or 修改动作的 中转方法
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
public ActionForward b_infor_addmodify_do(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
String whereId[] = new String[1];
boolean f_exist_id = false;
Basic_Set_Form m_Form = (Basic_Set_Form) form;
HttpSession session = request.getSession(true);
//超时验证
if (session.getAttribute("login_name") == null)
{
return mapping.findForward("overtime");
}
boolean back=false;
error_messages.clear();
//判断输入的是否为空,增加和修改都要判断这些值是否为空
if(m_function.isNull(m_Form.getM_b_infor()))
{
error_messages.add("isNull",new ActionMessage("error.is.null"));
this.saveMessages(request,error_messages);
back=true;
}
//判断是否超过指定长度
if(m_Form.getM_b_remark().trim().length()>=m_remark_length)
{
error_messages.add("remark_length",new ActionMessage("error.b_infor.remark.length"));
this.saveMessages(request,error_messages);
back=true;
}
if(back==true)
{
request.setAttribute("b_infor",m_Form);
return mapping.findForward("b_infor_addmodify");
}
String m_reporter = (String) session.getAttribute("login_name");
//检验当前序号是否在数据库存在,如果不存在表示增加/如果存在表示修改
whereId[0] = m_Form.getM_id();
f_exist_id = m_comm.RecordExistB_Infor_Id(whereId);
if (f_exist_id==false)
{ //增加记录
return b_infor_add_done(mapping, form, request, m_reporter);
}
else //修改记录
{
return b_infor_modify_done(mapping,form,request,m_reporter);
}
}
/**
* 表[b_infor]调用执行 增加动作
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param m_reporter String
* @return ActionForward
*/
public ActionForward b_infor_add_done(ActionMapping mapping,ActionForm form,
HttpServletRequest request,
String m_reporter)
{
Basic_Set_Form m_Form = (Basic_Set_Form) form;
//得到 [b_type].[id]
String m_b_type_id=m_comm.get_id(m_Form.getM_b_type());
//判断是否重复
String whereb_type[] =new String[2];
whereb_type[0]=m_Form.getM_b_infor();
whereb_type[1]=m_b_type_id;
boolean f_exist_b_type = false;
f_exist_b_type = m_comm.RecordExistB_infor(whereb_type);
//增加 : b_type不重复 + id也不存在,
if (f_exist_b_type==false)
{
boolean f_add = false;
String[] values = new String[7];
values[0] = m_Form.getM_id();
values[1] = m_b_type_id; //从b_type里面得到id
values[2] = m_Form.getM_b_infor();
values[3] = m_Form.getM_b_remark();
values[4] = Comm_function.GetCurrentDate();
values[5] = Comm_function.GetCurrentTime();
values[6] = m_reporter;
f_add = m_comm.RecordAdd_b_infor(values);
if (f_add == true) {
m_Form.setM_do_message("增加信息:【" +
m_Form.getM_b_infor() + "】成功!");
} else {
m_Form.setM_do_message("增加异常失败!");
}
}
else
{
m_Form.setM_do_message("输入的【"+m_Form.getM_b_infor()+"】已经存在,不能输入重复的值!增加失败");
}
m_Form.setM_id(m_Form.getM_b_type_id());
request.setAttribute("do_message", m_Form);
return mapping.findForward("do_message_b_infor");
}
/**
* 表[b_infor]修改执行
判断:修改输入的b_type是否已经已经在其它记录中存在,如果存在,判断其对应的序号是否为当前序号
如果不是,那么就修改了和其它记录相同,如果id=id,那么就可以修改本条记录
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param m_reporter String
* @return ActionForward
*/
public ActionForward b_infor_modify_done(ActionMapping mapping,ActionForm form,
HttpServletRequest request,
String m_reporter)
{
// 修改表[b_infor]
// 修改满足条件: 在同一个[b_type_id]下面不能重复[b_infor],用户可以修改[b_info]
// 第一步骤:检测[b_infor]是否重复
// 首先 :检测 [b_infor] 是否存在,如果存在,判断对应的[id]=Form.getM_id(),
// 如果相同,那么表示修改了同一个记录,如果不是,那么修改成为了其他的记录,
// 这个时候就不能修改
boolean flag = false;
boolean if_exist_b_infor = false;
Basic_Set_Form m_Form = (Basic_Set_Form) form;
String m_b_infor = m_Form.getM_b_infor(); // 得到更新字段[b_infor]的字符串
String m_id = m_Form.getM_id(); // 得到序号
String m_b_type_id =m_Form.getM_b_type_id();
String[] value = new String[2];
value[0] = m_b_infor;
value[1] = m_b_type_id;
if_exist_b_infor = m_comm.RecordExistB_infor(value);
String str_id = m_comm.get_b_infor_id(m_b_infor);//通过当前的[b_infor]得到id
//如果存在b_type,并且id<>m_id,那说明这个值在其它的记录存在
if ((if_exist_b_infor) && (!str_id.equals(m_id)))
{
//这个b_type已经在其它记录号,被输入过,所以不能修改
m_Form.setM_do_message("修改的记录序号:【" + m_id + "】信息【" + m_b_infor +
"】已经存在,即修改失败!");
} else {
String[] values = new String[6];
values[0] = m_Form.getM_b_infor();
values[1] = m_Form.getM_b_remark();
values[2] = Comm_function.GetCurrentDate();
values[3] = Comm_function.GetCurrentTime();
values[4] = m_reporter;
values[5] = m_Form.getM_id();
flag = m_comm.RecordModify_b_infor(values);
if (flag == true) {
m_Form.setM_do_message("修改:【" +
m_Form.getM_b_infor() + "】成功!");
} else {
m_Form.setM_do_message("修改异常失败!");
}
}
m_Form.setM_id(m_Form.getM_b_type_id());
request.setAttribute("do_message",
m_Form);
return mapping.findForward(
"do_message_b_infor");
}
/**
* 表[b_type]调用执行 增加 or 修改动作的 中转方法
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
public ActionForward b_type_addmodify_do(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
String whereId[] = new String[1];
boolean f_exist_id = false;
Basic_Set_Form m_Form = (Basic_Set_Form) form;
HttpSession session = request.getSession(true);
//超时验证
if (session.getAttribute("login_name") == null)
{
return mapping.findForward("overtime");
}
boolean back=false;
error_messages.clear();
//判断输入的是否为空,增加和修改都要判断这些值是否为空
if(m_function.isNull(m_Form.getM_b_type()))
{
error_messages.add("isNull",new ActionMessage("error.is.null"));
this.saveMessages(request,error_messages);
back=true;
}
//判断是否超过指定长度
if(m_Form.getM_b_remark().trim().length()>=m_remark_length)
{
error_messages.add("remark_length",new ActionMessage("error.b_infor.remark.length"));
this.saveMessages(request,error_messages);
back=true;
}
if(back==true)
{
request.setAttribute("b_type",m_Form);
return mapping.findForward("b_type_addmodify");
}
String m_reporter = (String) session.getAttribute("login_name");
//检验当前序号是否在数据库存在,如果不存在表示增加/如果存在表示修改
whereId[0] = m_Form.getM_id();
f_exist_id = m_comm.RecordExistId(whereId);
if (f_exist_id==false)
{ //增加记录
return b_type_add_done(mapping,form,request,m_reporter);
}
else //修改记录
{
return b_type_modify_done(mapping,form,request,m_reporter);
}
}
/**
* 表[b_type]调用执行 修改动作
* @param form ActionForm
* @param request HttpServletRequest
* @param m_reporter String
*/
public ActionForward b_type_modify_done(ActionMapping mapping,ActionForm form,
HttpServletRequest request,
String m_reporter)
{
Basic_Set_Form m_Form = (Basic_Set_Form) form;
//当存在这条记录的时候
boolean f = false;
String m_b_type=m_Form.getM_b_type();
String m_id=m_Form.getM_id();
/*----------------------------------------------------------
判断:修改输入的b_type是否已经已经在其它记录中存在,如果存在,判断其对应的序号是否为当前序号
如果不是,那么就修改了和其它记录相同,如果id=id,那么就可以修改本条记录
----------------------------------------------------------*/
String[] v=new String[1];
v[0]=m_b_type;
boolean f_exist=false;
f_exist = m_comm.RecordExistB_type(v);
String str_id = m_comm.get_id(m_b_type);
//如果存在b_type,并且id<>m_id,那说明这个值在其它的记录存在
if ((f_exist)&&(!str_id.equals(m_id)))
{
//这个b_type已经在其它记录号,被输入过,所以不能修改
m_Form.setM_do_message("修改的记录序号:【"+m_id
+"】类型【"
+m_b_type
+"】已经存在,即修改失败!");
}
else
{
String[] values = new String[6];
values[0] = m_Form.getM_b_type();
values[1] = m_Form.getM_b_remark();
values[2] = Comm_function.GetCurrentDate();
values[3] = Comm_function.GetCurrentTime();
values[4] = m_reporter;
values[5] = m_Form.getM_id();
f = m_comm.RecordModify(values);
if (f == true)
{
m_Form.setM_do_message("修改类型:【" +
m_Form.getM_b_type() + "】成功!");
}
else
{
m_Form.setM_do_message("修改异常失败!");
}
}
request.setAttribute("do_message",m_Form);
return mapping.findForward("do_message");
}
/**
*表[b_type]增加执行 修改动作
* @param form ActionForm
* @param request HttpServletRequest
* @param m_reporter String
*/
public ActionForward b_type_add_done(ActionMapping mapping,ActionForm form,
HttpServletRequest request,
String m_reporter)
{
Basic_Set_Form m_Form = (Basic_Set_Form) form;
//首先假设,增加情况,判断是否重复
String whereb_type[] = new String[1];
whereb_type[0] = m_Form.getM_b_type();
boolean f_exist_b_type = false;
f_exist_b_type = m_comm.RecordExistB_type(whereb_type);
//增加 : b_type不重复
if (f_exist_b_type==false)
{
boolean f_add=false;
String[] values=new String[6];
values[0]=m_Form.getM_id();
values[1]=m_Form.getM_b_type();
values[2]=m_Form.getM_b_remark();
values[3]=Comm_function.GetCurrentDate();
values[4]=Comm_function.GetCurrentTime();
values[5]=m_reporter;
f_add = m_comm.RecordAdd(values);
if (f_add==true)
{
m_Form.setM_do_message("增加类型:【"+m_Form.getM_b_type()+"】成功!");
}
else
{
m_Form.setM_do_message("增加异常失败!");
}
}
else
{
//不能增加相同的 b_type值,因为表中关键字:id + b_type
m_Form.setM_do_message("输入的【"+m_Form.getM_b_type()+"】已经存在,不能输入重复的值!增加失败");
}
request.setAttribute("do_message",m_Form);
return mapping.findForward("do_message");
}
}