📄 servermessage_invest.java
字号:
package server;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.util.StringTokenizer;
import javax.swing.JTextArea;
public class ServerMessage_Invest
{
InvestCorpdb db=new InvestCorpdb("投资","user","user");
JTextArea jtaControl;
void GetInfo(DataOutputStream dos,DataInputStream dis,JTextArea jtaControl,String strIP,int kind) throws SQLException
{
this.jtaControl=jtaControl;
byte [] data=new byte[1024];
int num;
if(kind==1)/**新建投资项目**/
{
try {
num=dis.read(data);
jtaControl.append("服务器:接受"+strIP+"需查询公司名称\n");
String strMeg=new String(data,0,num,"GB2312"); /** **/
db.InsertNew(strMeg.trim(),1);
jtaControl.append("服务器:向"+strIP+"项\n");
/*dos.write("true".getBytes());*/
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
if(kind==2)/**竞标结束**/
{
try {
num=dis.read(data);
jtaControl.append("服务器:接受"+strIP+"完成投标的项目名\n");
String strMeg=new String(data,0,num,"GB2312"); /** **/
db.Delete(strMeg,1);
db.InsertNew(strMeg.trim(),2);
jtaControl.append("服务器:向"+strIP+"项\n");
/*dos.write("true".getBytes());*/
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
if(kind==3)/**任务完成**/
{
try {
num=dis.read(data);
String strMeg=new String(data,0,num,"GB2312"); /** **/
db.Delete(strMeg,2);
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
if(kind==4)
{
try {
num=dis.read(data);
String strMeg=new String(data,0,num,"GB2312"); /** **/
StringTokenizer stn = new StringTokenizer(strMeg, "/");
String[] temp = new String[3];
int i = 0;
while (stn.hasMoreTokens()) {
temp[i] = stn.nextToken();
i++;
}
db.QueryData(temp[1].trim(),5);
System.out.println(db.isExist());
db.updatedata(temp[0],Integer.valueOf(temp[2]));
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
void DownLoad(DataOutputStream dos,DataInputStream dis,JTextArea jtaControl,String strIP,int kind)
{
this.jtaControl=jtaControl;
byte [] data=new byte[1024];
int num;
if(kind==1)
{
try {
num = dis.read(data);
jtaControl.append("服务器:接受"+strIP+"需查询公司名称\n");
String strMeg=new String(data,0,num,"GB2312"); /** **/
db.QueryData(strMeg.trim(),1);
jtaControl.append("服务器:开始向"+strIP+"传递公司投资信息\n");
} catch (IOException e1) {
e1.printStackTrace();
}
try {
while(true)
{
if(db.isExist())
{
Item ItemInfo=db.GetInfo2(1);
dos.writeBoolean(true);//name
dis.read(data);
dos.write(ItemInfo.getName().getBytes("GB2312"));//name
dis.read(data);
dos.write(ItemInfo.getComp().getBytes("GB2312"));
dis.read(data);
dos.writeLong(ItemInfo.getMoney());//strCharacter
dis.read(data);
jtaControl.append("服务器:向"+strIP+"传递一条公司投资信息\n");
}
else
{
dos.writeBoolean(false);
dis.read(data);
jtaControl.append("服务器:向"+strIP+"传递投资投资信息完毕\n");
break;
}
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
if(kind==2)
{
db.QueryData(null,2);
while(true)
{
try {
if(db.isExist())
{
Item ItemInfo=db.GetInfo2(1);
dos.writeBoolean(true);//name
dis.read(data);
System.out.println(ItemInfo.getName());
dos.write(ItemInfo.getName().getBytes("GB2312"));//name
dis.read(data);
dos.write(ItemInfo.getInvest().getBytes("GB2312"));
System.out.println(ItemInfo.getInvest());
dis.read(data);
dos.writeLong(ItemInfo.getMoney());//strCharacter
System.out.println(ItemInfo.getMoney());
dis.read(data);
jtaControl.append("服务器:向"+strIP+"传递一条公司投资信息\n");
}
else
{
dos.writeBoolean(false);
dis.read(data);
jtaControl.append("服务器:向"+strIP+"传递投资投资信息完毕\n");
break;
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
if(kind==3)
{
try {
num = dis.read(data);
jtaControl.append("服务器:接受"+strIP+"需查询公司名称\n");
String strMeg=new String(data,0,num,"GB2312"); /** **/
db.QueryData(strMeg.trim(),3);
jtaControl.append("服务器:开始向"+strIP+"传递公司投资信息\n");
} catch (IOException e1) {
e1.printStackTrace();
}
try {
while(true)
{
if(db.isExist())
{
Item ItemInfo=db.GetInfo2(1);
dos.writeBoolean(true);//name
dis.read(data);
dos.write(ItemInfo.getName().getBytes("GB2312"));//name
dis.read(data);
dos.write(ItemInfo.getInvest().getBytes("GB2312"));
dis.read(data);
dos.writeLong(ItemInfo.getMoney());//strCharacter
dis.read(data);
jtaControl.append("服务器:向"+strIP+"传递一条公司投资信息\n");
}
else
{
dos.writeBoolean(false);
dis.read(data);
jtaControl.append("服务器:向"+strIP+"传递投资投资信息完毕\n");
break;
}
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
if(kind==4)
{
try {
num = dis.read(data);
jtaControl.append("服务器:接受"+strIP+"需查询公司名称\n");
String strMeg=new String(data,0,num,"GB2312"); /** **/
db.QueryData(strMeg.trim(),4);
jtaControl.append("服务器:开始向"+strIP+"传递公司投资信息\n");
} catch (IOException e1) {
e1.printStackTrace();
}
try {
while(true)
{
if(db.isExist())
{
Item ItemInfo=db.GetInfo2(2);
dos.writeBoolean(true);//name
dis.read(data);
dos.write(ItemInfo.getName().getBytes("GB2312"));//name
dis.read(data);
dos.write(ItemInfo.getInvest().getBytes("GB2312"));
dis.read(data);
dos.writeLong(ItemInfo.getMoney());//strCharacter
dis.read(data);
jtaControl.append("服务器:向"+strIP+"传递一条公司投资信息\n");
}
else
{
dos.writeBoolean(false);
dis.read(data);
jtaControl.append("服务器:向"+strIP+"传递投资投资信息完毕\n");
break;
}
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -