📄 policymanage.java
字号:
button_6.setBounds(164, 405, 45, 16);
label_7 = new Label(this, SWT.NONE);
label_7.setText("回复对象:");
label_7.setBounds(212, 407, 54, 12);
label_7.setVisible(false);
button = new Button(this, SWT.NONE);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
flag = true;
int add_id = Integer.parseInt(ID);
String email = "";
String phone = "";
String message = "";
if(button_6.getSelection() && combo.getSelectionIndex() == -1)
{
messageBox = new MessageBox(parent.getShell(),SWT.ICON_INFORMATION);
messageBox.setMessage("请选择回复对象");
messageBox.setText("提示");
messageBox.open();
flag = false;
}
if(flag)
{
if(text_5.getText().equals(""))
{
messageBox = new MessageBox(parent.getShell(),SWT.ICON_INFORMATION);
messageBox.setMessage("请输入公告内容");
messageBox.setText("提示");
messageBox.open();
flag = false;
}
else
message = text_5.getText();
}
if(flag)
{
if(button_6.getSelection())
{
type = 1;
parentID = Integer.parseInt(combo.getItem(combo.getSelectionIndex()));
}
else
{
type = 0;
}
}
if(flag)
try{
datetime = Date.valueOf(text_4.getText());
}
catch(Exception px)
{
messageBox = new MessageBox(parent.getShell(),SWT.ICON_ERROR);
messageBox.setMessage("日期格式错误,请重新输入");
messageBox.setText("提示");
messageBox.open();
flag = false;
}
if(flag)
{
email = text_2.getText();
phone = text_3.getText();
}
if(flag)
{
messageBox = new MessageBox(parent.getShell(),SWT.ICON_QUESTION|SWT.OK|SWT.CANCEL);
messageBox.setMessage("发布人: " + text_1.getText() +
"\nE-mail: " + email +
"\n联系电话: " + phone +
"\n日期: " + datetime +
"\n公告内容: " + message +
"\n\n要发布该公告吗?");
messageBox.setText("确认");
if(messageBox.open() == SWT.OK)
{
if(type == 0)
{
if(addPolicy(add_id,type,email,phone,datetime,message))
{
messageBox = new MessageBox(parent.getShell(),SWT.ICON_INFORMATION);
messageBox.setMessage("公告已成功发布");
messageBox.setText("提示");
messageBox.open();
}
else
{
messageBox = new MessageBox(parent.getShell(),SWT.ICON_ERROR);
messageBox.setMessage("发布公告失败,请检查输入信息是否正确");
messageBox.setText("发布公告失败");
messageBox.open();
flag = false;
}
}
else
{
if(addPolicy(add_id,type,email,phone,datetime,parentID,message))
{
messageBox = new MessageBox(parent.getShell(),SWT.ICON_INFORMATION);
messageBox.setMessage("公告已成功发布");
messageBox.setText("提示");
messageBox.open();
}
else
{
messageBox = new MessageBox(parent.getShell(),SWT.ICON_ERROR);
messageBox.setMessage("发布公告失败,请检查输入信息是否正确");
messageBox.setText("发布公告失败");
messageBox.open();
flag = false;
}
}
}
}
if(flag)
clearAll();
}
});
button.setText("发 送");
button.setBounds(484, 403, 85, 22);
button.setVisible(false);
button_1 = new Button(this, SWT.NONE);
button_1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
clearAll();
}
});
button_1.setText("重 写");
button_1.setBounds(575, 403, 85, 22);
searchName(ID,text_1,button);
}
protected void clearAll(){
text_2.setText("");
text_3.setText("");
text_4.setText("");
text_5.setText("");
button_2.setSelection(true);
}
public void searchName(String ID,Text text,Button button){//sql
if(!ID.equals("Admin"))
{
Connection con;
Statement stmt;
try{
DBCon dbc = new DBCon();
con = DriverManager.getConnection(dbc.url,id,pwd);
stmt = con.createStatement();
String query = "select Name " +
" from Staff " +
" where ID = "+ ID +";";
ResultSet rs = stmt.executeQuery(query);
while( rs.next()){
text.setText(rs.getString("Name"));
}
dbc.dbClose(con,rs);
}
catch(Exception e){
e.printStackTrace();
}
}
else
{
text.setText("Admin");
button.setEnabled(false);
}
}
public void replyObject(Combo combo){//sql
Connection con;
Statement stmt;
try{
DBCon dbc = new DBCon();
con = DriverManager.getConnection(dbc.url,id,pwd);
stmt = con.createStatement();
String query = "select ID " +
" from Policy ";
ResultSet rs = stmt.executeQuery(query);
while( rs.next()){
combo.add(rs.getString("ID"));
}
dbc.dbClose(con,rs);
}
catch(Exception e){
e.printStackTrace();
}
}
public boolean addPolicy(int staffid,int type,String email,String phone,Date date,String message){//sql
Connection con;
try{
DBCon dbc = new DBCon();
con = DriverManager.getConnection(dbc.url,id,pwd);
CallableStatement cs = con.prepareCall("{call dbo.sp_AddPolicyNull(?,?,?,?,?,?)}");
cs.setInt(1, staffid);
cs.setInt(2, type);
cs.setString(3, email);
cs.setString(4, phone);
cs.setDate(5, date);
cs.setString(6, message);
cs.execute();
dbc.dbClose(con);
return true;
}
catch(Exception e){
e.printStackTrace();
return false;
}
}
public boolean addPolicy(int staffid,int type,String email,String phone,Date date,int parent,String message){//sql
Connection con;
try{
DBCon dbc = new DBCon();
con = DriverManager.getConnection(dbc.url,id,pwd);
CallableStatement cs = con.prepareCall("{call dbo.sp_AddPolicy(?,?,?,?,?,?,?)}");
cs.setInt(1, staffid);
cs.setInt(2, type);
cs.setString(3, email);
cs.setString(4, phone);
cs.setDate(5, date);
cs.setInt(6, parent);
cs.setString(7, message);
cs.execute();
dbc.dbClose(con);
return true;
}
catch(Exception e){
e.printStackTrace();
return false;
}
}
public void delPolicy(String del_id){
Connection con;
try{
DBCon dbc = new DBCon();
con = DriverManager.getConnection(dbc.url,id,pwd);
CallableStatement cs = con.prepareCall("{call dbo.sp_DelPolicy(?)}");
cs.setString(1,del_id);
cs.execute();
dbc.dbClose(con);
}
catch(Exception e){
e.printStackTrace();
}
}
public void searchPolicy(){//sql
Connection con;
Statement stmt;
String ptype = "";
try{
table.clearAll();
table.removeAll();
DBCon dbc = new DBCon();
con = DriverManager.getConnection(dbc.url,id,pwd);
stmt = con.createStatement();
String query = "select a.ID as ID,b.Name as StaffName,a.Type,a.[E-mail],a.Phone,a.InputDate,a.ParentID,a.Message " +
" from Policy a,Staff b " +
" where a.StaffID = b.ID" +
" ORDER BY ID";
ResultSet rs = stmt.executeQuery(query);
while( rs.next()){
if(rs.getString("Type").equals("1"))
ptype = "回复";
else
ptype = "公告";
new TableItem(table, SWT.BORDER);
table.getItem(table.getItemCount()-1).setText(new String[]{rs.getString("ID"),
rs.getString("StaffName"),ptype,rs.getString("E-mail"),
rs.getString("Phone"),rs.getString("InputDate"),rs.getString("ParentID"),
rs.getString("Message")});
}
dbc.dbClose(con,rs);
}
catch(Exception e){
e.printStackTrace();
}
}
public void listPolicy(){//sql
Connection con;
Statement stmt;
String ptype = "";
try{
list.removeAll();
DBCon dbc = new DBCon();
con = DriverManager.getConnection(dbc.url,id,pwd);
stmt = con.createStatement();
String query = "select a.ID as ID,b.Name as StaffName,a.Type,a.[E-mail],a.Phone,a.InputDate,a.ParentID,a.Message " +
" from Policy a,Staff b " +
" where a.StaffID = b.ID" +
" ORDER BY ID";
ResultSet rs = stmt.executeQuery(query);
while( rs.next()){
list.add("公告编号:" + rs.getString("ID"));
if(rs.getString("Type").equals("1"))
{
ptype = "回复";
list.add("公告类型:" + ptype + "\t 回复公告ID:" + rs.getString("ParentID") + "\t 发布日期:" + rs.getString("InputDate"));
}
else
{
ptype = "公告";
list.add("公告类型:" + ptype + "\t 发布日期:" + rs.getString("InputDate"));
}
list.add("发布人:" + rs.getString("StaffName") + "\t 发布人邮箱:" + rs.getString("E-mail") + "\t 联系电话:" + rs.getString("Phone"));
list.add("公告内容:" + rs.getString("Message"));
list.add("");
}
dbc.dbClose(con,rs);
}
catch(Exception e){
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -