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

📄 softsellprocess.java

📁 java版虚拟社区,在mysql上运行.
💻 JAVA
字号:
package serverpack;

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

public class SoftSellProcess {
	
	private Connection conn;
	private Statement stat;
	private Monitor mo;
	private DecimalFormat df;
		
	public SoftSellProcess(Connection c,Monitor m){conn = c;mo = m;df = new DecimalFormat("#,###,###,###.00");}
	
	public boolean SoftSellBalance(MyMessage mm)
	{
		try{
			String id = new String(mm.GetMes(0));
			Statement stat1=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			ResultSet rsOfSell=stat1.executeQuery("select * from softsell_all_".concat(mm.GetMes(0)));
			Statement stat2=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			Statement stat3=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			ResultSet rsOfSellInBank=stat3.executeQuery("select * from bank_account where id='"+mm.GetMes(0)+"'");
			Statement stat4=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			Statement stat5=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			Statement stat6=conn.createStatement();
		    ResultSet rsOfSellLogin=stat6.executeQuery("select * from login where id='"+mm.GetMes(0)+"'");
		    rsOfSellLogin.first();
		  
		    Statement stat8=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
		    Statement stat9=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			if(!rsOfSellInBank.next())
			{
				System.out.println(id+" does not have an account in bank");
				mo.appendmessage(id+" does not have an account in bank"+"\n");
				mm.SetType("noaccount");
				mm.SetNum(0);
				rsOfSell.close();
				rsOfSellInBank.close();
				rsOfSellLogin.close();
				stat1.close();
				stat2.close();
				stat3.close();
				stat4.close();
				stat5.close();
				stat6.close();
				
				stat8.close();
				stat9.close();
				return true;
			}
			else{
				while(rsOfSell.next())
				{
					ResultSet rsOfSoftDevelop=stat2.executeQuery(("select * from softdevelop_all_".concat(rsOfSell.getString("develop_id"))).concat(" where softname='"+rsOfSell.getString("softname")+"'"));
					rsOfSoftDevelop.first();
					float sellamount=(rsOfSell.getInt("sold")-rsOfSoftDevelop.getInt("sold"))*rsOfSell.getFloat("retail");
					ResultSet rsOfDevelopInBank=stat4.executeQuery("select * from bank_account where id='"+rsOfSell.getString("develop_id")+"'");
					
					if(sellamount*0.9>rsOfSellInBank.getFloat("account"))
					{
						System.out.println(id+" sell Corp account inadequate");
						mo.appendmessage(id+" sell Corp account inadequate"+"\n");
						mm.SetType("notenough");
						mm.SetNum(0);
						rsOfSellInBank.close();
						rsOfSellLogin.close();
						rsOfSoftDevelop.close();
						rsOfDevelopInBank.close();
						stat1.close();
						stat2.close();
						stat3.close();
						stat4.close();
						stat5.close();
						stat6.close();
						stat8.close();
						stat9.close();
						return true;
					}
					else if("N".equals(rsOfSoftDevelop.getString("if_invested")))
					{
						if(!rsOfDevelopInBank.next()||sellamount==0)
						{	
						}
					    else{
						//update bank_account for sell&develop
							float newAccount=rsOfSellInBank.getFloat("account")-(float)(sellamount*0.9);
							rsOfSellInBank.updateFloat("account",newAccount);
							rsOfSellInBank.updateRow();
							newAccount=rsOfDevelopInBank.getFloat("account")+(float)(0.9*sellamount);
							rsOfDevelopInBank.first();
							rsOfDevelopInBank.updateFloat("account",newAccount);
							rsOfDevelopInBank.updateRow();
							//insert a new record into bank_client now
							ResultSet rsOfBankClient=stat5.executeQuery("select * from bank_client");
							rsOfBankClient.moveToInsertRow();
							rsOfBankClient.updateString("id",mm.GetMes(0));
							rsOfBankClient.updateString("name",rsOfSellLogin.getString("name"));
							rsOfBankClient.updateString("h_type","transfer");
							rsOfBankClient.updateString("to_id",rsOfSell.getString("develop_id"));
							rsOfBankClient.updateString("to_name",rsOfSell.getString("develop_name"));
							rsOfBankClient.updateFloat("account",(float)(sellamount*0.9));
							rsOfBankClient.insertRow();
							//update softdevelop_all_(id)
							rsOfSoftDevelop.updateInt("sold",rsOfSell.getInt("sold"));
							rsOfSoftDevelop.updateFloat("profit",(float)(sellamount*0.9)+rsOfSoftDevelop.getFloat("profit"));
							rsOfSoftDevelop.updateRow();
							rsOfSoftDevelop.close();
							rsOfDevelopInBank.close();
					    }
					}
					else{
						ResultSet rsOfInvestInBank=stat8.executeQuery("select * from bank_account where name='"+rsOfSoftDevelop.getString("investor")+"'");
					    if(!rsOfDevelopInBank.next()||!rsOfInvestInBank.next()||sellamount==0)
						{	
						}
						else{
							//update bank_account for sell&develop&invest
							float newAccount=rsOfSellInBank.getFloat("account")-(float)(sellamount*0.9);
							rsOfSellInBank.updateFloat("account",newAccount);
							rsOfSellInBank.updateRow();
							newAccount=rsOfDevelopInBank.getFloat("account")+(float)(0.4*sellamount);
							rsOfDevelopInBank.updateFloat("account",newAccount);
							rsOfDevelopInBank.updateRow();
							newAccount=rsOfInvestInBank.getFloat("account")+(float)(sellamount*0.5);
							rsOfInvestInBank.updateFloat("account",newAccount);
							rsOfInvestInBank.updateRow();
							//insert two new records into bank_client now
							ResultSet rsOfBankClient=stat5.executeQuery("select * from bank_client");
							rsOfBankClient.moveToInsertRow();
							rsOfBankClient.updateString("id",mm.GetMes(0));
							rsOfBankClient.updateString("name",rsOfSellLogin.getString("name"));
							rsOfBankClient.updateString("h_type","transfer");
							rsOfBankClient.updateFloat("account",(float)(sellamount*0.4));
							rsOfBankClient.updateNull("time");
							rsOfBankClient.updateString("to_id",rsOfSell.getString("develop_id"));
							rsOfBankClient.updateString("to_name",rsOfSell.getString("develop_name"));
							
							rsOfBankClient.insertRow();
							//bank_client record of transference to invest
							rsOfBankClient.moveToInsertRow();
							rsOfBankClient.updateString("id",mm.GetMes(0));
							rsOfBankClient.updateString("name",rsOfSellLogin.getString("name"));
							rsOfBankClient.updateString("h_type","transfer");
							rsOfBankClient.updateString("to_id",rsOfInvestInBank.getString("id"));
							rsOfBankClient.updateString("to_name",rsOfInvestInBank.getString("name"));
							rsOfBankClient.updateNull("time");
							rsOfBankClient.updateFloat("account",(float)(sellamount*0.5));
							rsOfBankClient.insertRow();
							//update softdevelop_all_(id)
							rsOfSoftDevelop.updateInt("sold",rsOfSell.getInt("sold"));
							rsOfSoftDevelop.updateFloat("profit",(float)(sellamount*0.4)+rsOfSoftDevelop.getFloat("profit"));
							rsOfSoftDevelop.updateRow();
							//update investcorp_myinvest profit
							ResultSet rsOfInvest=stat9.executeQuery(("select * from investcorp_myinvest_".concat(rsOfInvestInBank.getString("id"))).concat(" where softname='"+rsOfSell.getString("softname")+"'"));
							rsOfInvest.first();
							rsOfInvest.updateFloat("profit",(float)(rsOfInvest.getFloat("profit")+sellamount*0.5));
							rsOfInvest.updateRow();
							rsOfSoftDevelop.close();
							rsOfDevelopInBank.close();
							rsOfInvestInBank.close();
						}
					}
				}
				mm.SetType("true");
				mm.SetNum(0);
				System.out.println(id+" SoftSellBalance success");
				mo.appendmessage(id+" SoftSellBalance success"+"\n");
				rsOfSellInBank.close();
				rsOfSellLogin.close();
				rsOfSell.close();
				stat1.close();
				stat2.close();
				stat3.close();
				stat4.close();
				stat5.close();
				stat6.close();
				stat8.close();
				stat9.close();
				return true;
			}
		}
		catch(SQLException e)
		{
			e.printStackTrace();
			System.out.println("SQLException!");
		}
		return false;
	}
		
	public boolean SoftSellAllView(MyMessage mm)
	{
		try
		{
			String id = new String(mm.GetMes(0));
			String cmd="select * from softsell_all_".concat(mm.GetMes(0));
			PreparedStatement pstat=conn.prepareStatement(cmd);
			ResultSet rs=pstat.executeQuery();
			if(!rs.next())
			{
		       mm.SetType("false");
		       mm.SetNum(0);
		       System.out.println("No such softsell company existed");// will not
		       rs.close();
		       pstat.close();
		       return true;
			}
			else{
				rs.last();
				int num=rs.getRow();
				rs.beforeFirst();
				int count=0;
				while(rs.next())
				{
					mm.SetMes(rs.getString("softname"), count++);
					mm.SetMes(rs.getString("description"), count++);
					mm.SetMes(df.format(rs.getFloat("retail")), count++);
					mm.SetMes(rs.getString("stored"), count++);
					mm.SetMes(rs.getString("sold"), count++);
					mm.SetMes(rs.getString("develop_id"), count++);
					mm.SetMes(rs.getString("develop_name"), count++);
				}
				rs.close();
			    pstat.close();
			    mm.SetType("true");
			    mm.SetNum(num*7);
			    System.out.println(id+" SoftSellAllView success");
				mo.appendmessage(id+" SoftSellAllView success"+"\n");
			    return true;
			}
		}
		catch(SQLException e){
			e.printStackTrace();
			System.out.println("SQLException!");
		 
		}
		return false;
	}
	
	public boolean SoftSellFeedbackView(MyMessage mm)
	{
		try
		{
			String id = new String(mm.GetMes(0));
			String cmd="select * from softsell_feedback_".concat(mm.GetMes(0));
			PreparedStatement pstat=conn.prepareStatement(cmd);
			ResultSet rs=pstat.executeQuery();
			if(!rs.next())
			{
		       mm.SetType("false");
		       mm.SetNum(0);
		       System.out.println(id+" no feedback information");
		       mo.appendmessage(id+" no feedback information"+"\n");
		       rs.close();
		       pstat.close();
		       return true;
			}
			else{
				rs.last();
				int num=rs.getRow();
				rs.beforeFirst();
				int count=0;
				while(rs.next())
				{
					mm.SetMes(rs.getString("softname"), count++);
					mm.SetMes(rs.getString("develop_id"), count++);
					mm.SetMes(rs.getString("develop_name"), count++);
					mm.SetMes(rs.getString("feedback"), count++);
					mm.SetMes(rs.getString("customer_name"), count++);
				}
				rs.close();
			    pstat.close();
			    mm.SetType("true");
			    mm.SetNum(count);
			    System.out.println(id+" SoftSellFeedbackView success");
			    mo.appendmessage(id+" SoftSellFeedbackView success"+"\n");
			    return true;
			}
		}
		catch(SQLException e){
			e.printStackTrace();
			System.out.println("SQLException!");
		 
		}
		return false;
	}
	
	public boolean SoftSellCustomerView(MyMessage mm)
	{
		try
		{
			String id = new String(mm.GetMes(0));
			String cmd="select * from softsell_customer_".concat(mm.GetMes(0));
			PreparedStatement pstat=conn.prepareStatement(cmd);
			ResultSet rs=pstat.executeQuery();
			if(!rs.next())
			{
		       mm.SetType("false");
		       mm.SetNum(0);
		       System.out.println(id+" no customer information");
			   mo.appendmessage(id+" no customer information"+"\n");
		       rs.close();
		       pstat.close();
		       return true;
			}
			else{
				rs.last();
				int num=rs.getRow();
				rs.beforeFirst();
				int count=0;
				while(rs.next())
				{
					mm.SetMes(rs.getString("softname"), count++);
					mm.SetMes(rs.getString("customer_id"), count++);
					mm.SetMes(rs.getString("customer_name"), count++);
					mm.SetMes(df.format(rs.getFloat("retail")), count++);
					mm.SetMes(rs.getString("time"), count++);
				}
				 rs.close();
			     pstat.close();
			     mm.SetType("true");
			     mm.SetNum(num*5);
			     System.out.println(id+" SoftSellCustomerView success");
				 mo.appendmessage(id+" SoftSellCustomerView success"+"\n");
			     return true;
			}
		}
		catch(SQLException e){
			e.printStackTrace();
			System.out.println("SQLException!");
		 
		}
		return false;
	}
	public boolean SoftSellFinanceView(MyMessage mm)
	{
		try
		{
			String id = new String(mm.GetMes(0));
			String cmd="select * from softsell_all_".concat(mm.GetMes(0));
			PreparedStatement pstat=conn.prepareStatement(cmd);
			ResultSet rs=pstat.executeQuery();
			float soldall=0;
			if(!rs.next())
			{
				rs.close();
				pstat.close();
				mm.SetType("true");
				mm.SetNum(2);
				mm.SetMes(""+0, 0);
				mm.SetMes(""+0,1);
				return true;
			}
			else
			{
				do
				{
					soldall+=rs.getInt("sold")*rs.getFloat("retail");
				}while(rs.next());
			}
			mm.SetType("true");
			mm.SetNum(2);
			mm.SetMes(df.format(soldall), 0);
			mm.SetMes(df.format(soldall*0.1),1);
			System.out.println(id+" SoftSellFinanceView success");
			mo.appendmessage(id+" SoftSellFinanceView success"+"\n");
			rs.close();
			pstat.close();
			return true;
		}
		catch(SQLException e){
			e.printStackTrace();
			System.out.println("SQLException!");
		 
		}
		return false;
	}

}

⌨️ 快捷键说明

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