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

📄 investprocess.java

📁 java版虚拟社区,在mysql上运行.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package serverpack;

import java.sql.*;
import java.text.DecimalFormat;

public class InvestProcess {
	
	private Connection conn;
	private Statement stat;
	private Monitor mo;
	private DecimalFormat df;
		
	public InvestProcess(Connection c,Monitor m){conn = c;mo = m;df = new DecimalFormat("#,###,###,###.00");}
	
	public boolean BiderView(MyMessage mm)
	{
		
		try
		{
			String name = new String(mm.GetMes(0));
			stat=conn.createStatement();
			ResultSet rs=stat.executeQuery("select * from bider where softname='"+mm.GetMes(0)+"'");
			if(!rs.next())
			{
				System.out.println(mm.GetMes(0)+" no bider for this project");
				mo.appendmessage(mm.GetMes(0)+" no bider for this project"+"\n");
				mm.SetNum(0);
				mm.SetType("false");
				rs.close();
				stat.close();
				return true;
			}
			else
			{
				int count=0;
				do
				{
					mm.SetMes(rs.getString("softname"),count++);
					mm.SetMes(rs.getString("bider_id"), count++);
					mm.SetMes(rs.getString("bider_name"), count++);
				}while(rs.next());
				mm.SetType("true");
				mm.SetNum(count);
				rs.close();
				stat.close();
				System.out.println(name+" bider view success");
				mo.appendmessage(name+" bider view success"+"\n");
				return true;
			}
		}
		catch(SQLException e)
		{
			System.out.println("SQLException!");
			e.printStackTrace();
		}
		return false;
	}
	public boolean BidView(MyMessage mm)
	{
		try
		{
		stat=conn.createStatement();
	    ResultSet rs=stat.executeQuery("select * from bid");
		if(!rs.next())
		{
			System.out.println("No bid information");
			mo.appendmessage("No bid information"+"\n");
			mm.SetNum(0);
			mm.SetType("false");
			rs.close();
			stat.close();
			return true;
		}
		else
		{
			rs.last();
			int num=rs.getRow()*6;
			mm.SetNum(num);
			int count=0;
			rs.first();
			do
			{
				mm.SetMes(rs.getString("soft_name"),count++);
				mm.SetMes(rs.getString("description"), count++);
				mm.SetMes(rs.getString("time"), count++);
				mm.SetMes(df.format(rs.getFloat("invest_amount")), count++);
				mm.SetMes(rs.getString("investor"), count++);
				mm.SetMes(rs.getString("if_got"), count++);
			}while(rs.next());
			mm.SetType("true");
			rs.close();
			stat.close();
			System.out.println("Bid view success");
			mo.appendmessage("Bid view success"+"\n");
			return true;
		}
		}
		catch(SQLException e)
		{
			System.out.println("SQLException!");
			e.printStackTrace();
		}
		return false;
	}
	public boolean InvestCorpBidInvest(MyMessage mm)
	{
		try{
			String id = new String(mm.GetMes(0));
			String cmd1="select * from bid where soft_name='"+mm.GetMes(1)+"'";
			PreparedStatement pstat1=conn.prepareStatement(cmd1,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			ResultSet rsOfBid=pstat1.executeQuery();
			rsOfBid.first();
			/////////////////////////////////////////
			String cmd2="select * from investcorp_myinvest_".concat(mm.GetMes(0));
			cmd2=cmd2.concat(" where softname='"+mm.GetMes(1)+"'");
			PreparedStatement pstat2=conn.prepareStatement(cmd2,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			ResultSet rsOfInvestMyInvest=pstat2.executeQuery();
			rsOfInvestMyInvest.first();
			////////////////////////////////////////////////////////////////////////
			String cmd3="select * from softdevelop_all_".concat(mm.GetMes(2));
			PreparedStatement pstat3=conn.prepareStatement(cmd3,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			ResultSet rsOfSoftDevelop=pstat3.executeQuery();
			/////////////////////////////////////////////////////////
			Statement stat4=conn.createStatement();
			ResultSet rsOfInvestLogin=stat4.executeQuery("select * from login where id='"+mm.GetMes(0)+"'");
			 rsOfInvestLogin.first();
			////////////////////////////////////////////////////////////
			Statement stat5=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			ResultSet rsOfInvestInBank=stat5.executeQuery("select * from bank_account where id='"+mm.GetMes(0)+"'");
			///////////////////////////////////////////////////////////////////////////////
			Statement stat6=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			ResultSet rsOfDevelopInBank=stat6.executeQuery("select * from bank_account where id='"+mm.GetMes(2)+"'");
			/////////////////////////////////////////////////////////////////////////////
			Statement stat7=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			Statement stat8=conn.createStatement();
			ResultSet rsOfSoftDevelopLogin=stat8.executeQuery("select * from login where id='"+mm.GetMes(2)+"'");
			rsOfSoftDevelopLogin.first();
			if(!rsOfInvestInBank.next())
			{
				System.out.println(id+" investcorp has no account");
				mo.appendmessage(id+" investcorp has no account"+"\n");
				mm.SetType("investnoaccount");
				mm.SetNum(0);
				rsOfBid.close();
				rsOfInvestMyInvest.close();
				rsOfSoftDevelop.close();
				rsOfInvestLogin.close();
				pstat1.close();
				pstat2.close();
				pstat3.close();
				stat4.close();
				return true;
		}
			else if(!rsOfDevelopInBank.next())
			{
				System.out.println(id+" invest fail,softdevelop corp has no account");
				mo.appendmessage(id+" invest fail,softdevelop corp has no account"+"\n");
				mm.SetType("developnoaccount");
				mm.SetNum(0);
				rsOfBid.close();
				rsOfInvestMyInvest.close();
				rsOfSoftDevelop.close();
				rsOfInvestLogin.close();
				pstat1.close();
				pstat2.close();
				pstat3.close();
				stat4.close();
				return true;
			}
			else if(!rsOfBid.getString("investor").equals(rsOfInvestLogin.getString("name")))
			{
				System.out.println(id+" soft does not belong to the investcorp");
				mo.appendmessage(id+" soft does not belong to the investcorp"+"\n");
				mm.SetType("notbelong");
				mm.SetNum(0);
				rsOfBid.close();
				rsOfInvestMyInvest.close();
				rsOfSoftDevelop.close();
				rsOfInvestLogin.close();
				pstat1.close();
				pstat2.close();
				pstat3.close();
				stat4.close();
				return true;
			}
			///////////////////////////////////////////////////////////////
			else if(rsOfInvestInBank.getFloat("account")<rsOfBid.getFloat("invest_amount"))
			{
				System.out.println(id+" investcorp funds inadequate");
				mo.appendmessage(id+" investcorp funds inadequate"+"\n");
				mm.SetType("notenough");
				mm.SetNum(0);
				rsOfInvestInBank.close();
				rsOfSoftDevelop.close();
				rsOfBid.close();
				rsOfInvestMyInvest.close();
				rsOfInvestLogin.close();
				stat4.close();
				stat5.close();
				pstat1.close();
				pstat2.close();
				pstat3.close();
				return true;
			}
			else
			{
				rsOfBid.updateString("if_got","Y");
				rsOfBid.updateRow();
				rsOfSoftDevelop.moveToInsertRow();
				rsOfSoftDevelop.updateString("softname",mm.GetMes(1));
				rsOfSoftDevelop.updateString("description",rsOfInvestMyInvest.getString("description"));
				rsOfSoftDevelop.updateNull("time");
				rsOfSoftDevelop.updateFloat("cost",rsOfInvestMyInvest.getFloat("account"));
				rsOfSoftDevelop.updateFloat("retail",rsOfInvestMyInvest.getFloat("retail"));
				rsOfSoftDevelop.updateString("if_done","N");
				rsOfSoftDevelop.updateInt("ordered",0);
				rsOfSoftDevelop.updateInt("sold",0);
				rsOfSoftDevelop.updateFloat("profit",0);
				rsOfSoftDevelop.updateString("if_invested","Y");
				rsOfInvestLogin.first();
				rsOfSoftDevelop.updateString("investor",rsOfInvestLogin.getString("name"));
				rsOfSoftDevelop.insertRow();
				float newaAccountOfInvest=rsOfInvestInBank.getFloat("account")-rsOfSoftDevelop.getFloat("cost");
				float newaAccountOfDevelop=rsOfDevelopInBank.getFloat("account")+rsOfSoftDevelop.getFloat("cost");
				rsOfDevelopInBank.updateFloat("account",newaAccountOfDevelop);
				rsOfDevelopInBank.updateRow();
				rsOfInvestInBank.updateFloat("account",newaAccountOfInvest);
				rsOfInvestInBank.updateRow();
///////////////////////////////////////////////////////////////////////////
				ResultSet rsOfBankClient=stat7.executeQuery("select * from bank_client");
				rsOfBankClient.moveToInsertRow();
				rsOfBankClient.updateString("id",mm.GetMes(0));
				rsOfBankClient.updateString("name",rsOfInvestLogin.getString("name"));
				rsOfBankClient.updateString("h_type","transfer");
				rsOfBankClient.updateString("to_id",mm.GetMes(2));
				rsOfBankClient.updateString("to_name",rsOfSoftDevelopLogin.getString("name"));
				rsOfBankClient.updateFloat("account",Float.parseFloat(rsOfSoftDevelop.getString("cost")));
				rsOfBankClient.insertRow();
//now update myinvest table
				rsOfInvestMyInvest.updateString("bider_id", mm.GetMes(2));
				rsOfInvestMyInvest.updateString("bider_name", rsOfSoftDevelopLogin.getString("name"));
				rsOfInvestMyInvest.updateRow();
/////////////////////////////////////////////////////////////////////////////////////////////////////////
				rsOfDevelopInBank.close();
				stat6.close();
			}
			mm.SetType("true");
			mm.SetNum(0);
			System.out.println(id+" InvestCorpBidInvest success");
			mo.appendmessage(id+" InvestCorpBidInvest success"+"\n");
			rsOfInvestInBank.close();
			rsOfSoftDevelop.close();
			rsOfBid.close();
			rsOfInvestMyInvest.close();
			rsOfInvestLogin.close();
			rsOfSoftDevelopLogin.close();
			stat4.close();
			stat5.close();
			stat7.close();
			stat8.close();
			pstat1.close();
			pstat2.close();
			pstat3.close();
			return true;
		}
		catch(SQLException e)
		{
			System.out.println("SQLException!");
			e.printStackTrace();
		}
		return false;
	}
	public boolean InvestCorpInvest(MyMessage mm)
	{
		
		try{
			String id = new String(mm.GetMes(0));
			String cmd1="select * from investcorp_myinvest_".concat(mm.GetMes(0));
			String cmd2="select * from softdevelop_all_".concat(mm.GetMes(2));
			cmd2=cmd2.concat(" where softname='"+mm.GetMes(1)+"'");
			PreparedStatement pstat1=conn.prepareStatement(cmd1,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			PreparedStatement pstat2=conn.prepareStatement(cmd2,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			Statement stat1=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			Statement stat2=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			Statement stat3=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			Statement stat4=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			Statement stat5=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			ResultSet rsOfMyInvest=pstat1.executeQuery();
			ResultSet rsOfSoftDevelop=pstat2.executeQuery();
			rsOfSoftDevelop.first();
			ResultSet rsOfDevelopInBank=stat4.executeQuery("select * from bank_account where id='"+mm.GetMes(2)+"'");
			ResultSet rsOfInvestInBank=stat3.executeQuery("select * from bank_account where id='"+mm.GetMes(0)+"'");
			
			if(!rsOfDevelopInBank.next())
			{
				System.out.println(id+" invest fail,develop corp has no account");
				mo.appendmessage(id+" invest fail,develop corp has no account"+"\n");
				rsOfMyInvest.close();
				rsOfSoftDevelop.close();
				rsOfDevelopInBank.close();
				rsOfInvestInBank.close();
				stat1.close();
				stat2.close();
				stat3.close();
				stat4.close();
				pstat1.close();
				pstat2.close();
				mm.SetType("developnoaccount");
				mm.SetNum(0);
				return true;
			}
			else if(!rsOfInvestInBank.next())
			{
				System.out.println(id+" the invest corp has no account");
				mo.appendmessage(id+" the invest corp has no account"+"\n");
				rsOfMyInvest.close();
				rsOfSoftDevelop.close();
				rsOfDevelopInBank.close();
				rsOfInvestInBank.close();
				stat1.close();
				stat2.close();
				stat3.close();
				stat4.close();
				pstat1.close();
				pstat2.close();
				mm.SetType("investnoaccount");
				mm.SetNum(0);
				return true;
			}
			else if("Y".equals(rsOfSoftDevelop.getString("if_invested")))
			{
				System.out.println(id+" this soft has been invested");
				mo.appendmessage(id+" this soft has been invested"+"\n");
				rsOfMyInvest.close();
				rsOfSoftDevelop.close();
				rsOfDevelopInBank.close();
				rsOfInvestInBank.close();
				stat1.close();
				stat2.close();
				stat3.close();
				stat4.close();
				pstat1.close();
				pstat2.close();
				mm.SetType("false");
				mm.SetNum(0);
				return true;
			}
			else if("Y".equals(rsOfSoftDevelop.getString("if_done")))
			{
				System.out.println(id+" this soft has been finished");
				mo.appendmessage(id+" this soft has been finished"+"\n");
				rsOfMyInvest.close();
				rsOfSoftDevelop.close();
				rsOfDevelopInBank.close();
				rsOfInvestInBank.close();
				stat1.close();
				stat2.close();
				stat3.close();
				stat4.close();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -