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

📄 stockchannel.java

📁 JAVA邮件系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.io.*;
import java.text.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class StockChannel extends Channel
{
	StockChannel()
	{
		channelName = "股票";
	}
	
	public void makeChannel(Person p,TemplateList tempList,HtmlOut desHtml)
	{
		SingleTemplate st;
		st = tempList.searchTemplate("频道右");
		if(st==null)
			return ;
		int nKey = st.getKeyNum ();
		String sKey ;
		for(int i=0;i<nKey;i++){
			desHtml.addString (st.getStringAt (i));
			sKey = st.getKeyAt (i);
			if( sKey.compareTo("cgi-path")==0 )
				desHtml.addString (CommonMethods.sHostNameCGI);
			if( sKey.compareTo("标题")==0 )
				desHtml.addString (	channelName );
			if( sKey.compareTo("EditCGI")==0 )
				desHtml.addString ("EditChannel?channel=stock");
			if( sKey.compareTo("CloseCGI")==0 )
				desHtml.addString ("CloseChannel?channel=stock");
			if( sKey.compareTo("内容")==0 )
				makeChannelContents( p, tempList, desHtml);
		}
		desHtml.addString(st.getEndString());
	}
	
	public boolean editChannel(Person p,HtmlOut desHtml)
	{
		TemplateList tempList = CommonMethods.getEditStockTemplate();
		
		SingleTemplate st;
		st = tempList.searchTemplate("ROOT");
		if(st==null){
			desHtml.setErrorID (desHtml.SINGLE_TEMPLATE_NOTFIND ,
								"","模板错误"
								,"Login");
			return false;
		}
		int nKey = st.getKeyNum ();
		String sKey ;
		for(int i=0;i<nKey;i++){
			desHtml.addString (st.getStringAt (i));
			sKey = st.getKeyAt (i);
			if( sKey.compareTo("cgi-path")==0 )
				desHtml.addString (CommonMethods.sHostNameCGI);
			if( sKey.compareTo("股票内容")==0 )
				makeChannelContents(p,tempList,desHtml);
		}
		desHtml.addString(st.getEndString());
		return true;
	}
	
	public void makeChannelContents(Person p,TemplateList tempList,HtmlOut desHtml)
	{
		DBOperater DB = new DBOperater ("stock");
		String queryString;
    String sTime="";
		ResultSet rs,rsSZ,rsSH;
    String queryStringSH,queryStringSZ;
    double dSszsSH=0,dSszsSZ=0,dZjzsSH=0,dZjzsSZ=0;
    queryStringSH="select sszs,zjzs from zq_zs where zsmc='上证指数' order by time desc";
    queryStringSZ="select sszs,zjzs from zq_zs where zsmc='深证成份指数' order by time desc";

    rsSH=DB.executeQuery (queryStringSH);
    try{
      if ( rsSH!=null && rsSH.next())
      {
       dSszsSH=rsSH.getDouble (1);
       dZjzsSH=rsSH.getDouble (2);
      }
      }
    catch(Exception e){
      dSszsSH=0;
      dZjzsSH=0;
      System.out.println(" 上证指数错误:"+e.toString ());
    }
    rsSZ=DB.executeQuery (queryStringSZ);
    try{
    if ( rsSZ!=null && rsSZ.next())
    {
      dSszsSZ=rsSZ.getDouble (1);
      dZjzsSZ=rsSZ.getDouble (2);
    }
       }catch(Exception e){
      dSszsSZ=0;
      dZjzsSZ=0;
      System.out .println("get SZZS error:"+e.toString ());
    }
		try
		{
      queryString = "select stockcode,zq_zqinfo.zqjc,warntype,zq_sshq.RQ,zq_sshq.ZRSP,zq_sshq.JRKP,zq_sshq.ZGJ,zq_sshq.ZDJ,zq_sshq.ZXJ,zq_sshq.CJSS,zq_sshq.SD";
			queryString = queryString + " from userstock,zq_zqinfo,zq_sshq where username='" +
						  CommonMethods.DealWithSQLParameter (p.getName())
						  + "' and stockcode = zq_zqinfo.zqid and stockcode = zq_sshq.zqid order by stockcode";
	   	    	rs = DB.executeQuery(queryString);


	   	    	// 生成这个用户的股票列表
			// 显示行情

	   	    	SingleTemplate st0,st1;

	   	    	String code,name,kaiprice,shouprice,curprice,maxprice,minprice,value,diff,diffv;
	   	    	double curpriceV,kaipriceV,shoupriceV,maxpriceV,minpriceV,diffV,diffvV;
	   	    	String editwarn;
            String sColor="#000000";

	   	    	int warntype;
	   	    	
	   	    	st0 = tempList.searchTemplate("股票列表");
    			st1 = tempList.searchTemplate("单支股票");
	   	    	int i1,i2;
	   	    	for(i1=0;i1<st0.getKeyNum();i1++)
	   	    	{
	   	    		desHtml.addString(st0.getStringAt(i1));
					if(st0.getKeyAt(i1).compareTo("cgi-path")==0){
						desHtml.addString(CommonMethods.sHostNameCGI);
					}
          if(st0.getKeyAt (i1).compareTo ("上证指数")==0)
          {
            desHtml.addString (CommonMethods.FormatDouble (dZjzsSH,3)+"");
          }
          if(st0.getKeyAt (i1).compareTo("深成指")==0)
          {
            desHtml.addString (CommonMethods.FormatDouble (dZjzsSZ,3)+"");
          }
          if(st0.getKeyAt (i1).compareTo ("上颜色")==0)
          {

            if (dZjzsSH - dSszsSH > 0)
              desHtml.addString ("#FF0000");
            else if(dZjzsSH - dSszsSH < 0)
              desHtml.addString ("#339966");
            else
              desHtml.addString ("#000000");
          }
          if(st0.getKeyAt (i1).compareTo ("深颜色")==0)
          {

           if (dZjzsSZ - dSszsSZ >0)
              desHtml.addString ("#FF0000");
            else if(dZjzsSZ -dSszsSZ <0)
              desHtml.addString ("#339966");
            else
              desHtml.addString ("#000000");
          }
          if(st0.getKeyAt (i1).compareTo ("上涨跌")==0)
          {
           if (dZjzsSH - dSszsSH >0)
              desHtml.addString ("  ↑"+CommonMethods.FormatDouble ((dZjzsSH - dSszsSH) ,3));
            else if(dZjzsSH-dSszsSH <0)
              desHtml.addString ("  ↓"+CommonMethods.FormatDouble ((dSszsSH - dZjzsSH ),3));
            else
              desHtml.addString ("  →0.000");
           }
          if(st0.getKeyAt (i1).compareTo ("深涨跌")==0)
          {
           if (dZjzsSZ - dSszsSZ>0)
              desHtml.addString ("  ↑"+CommonMethods.FormatDouble ((dZjzsSZ - dSszsSZ ),3));
            else if(dZjzsSZ-dSszsSZ<0)
              desHtml.addString ("  ↓"+CommonMethods.FormatDouble ((dSszsSZ - dZjzsSZ),3));
            else
              desHtml.addString ("  →0");
           }
          if(st0.getKeyAt(i1).compareTo("时间")==0)
              { desHtml.addString (sTime);

              }
	   	    		if(st0.getKeyAt(i1).compareTo("全部股票")==0)
	   	    		{
			   	    	while( rs!=null && rs.next())
   				    	{
   				    		code = rs.getString("stockcode");
   				    		name = rs.getString(2);
   				    		warntype = rs.getInt(3);
                  sTime=rs.getString (4);
							shouprice=rs.getString(5);
							kaiprice=rs.getString(6);
   				    		maxprice = rs.getString(7);
   				    		minprice = rs.getString(8);
   				    		curprice = rs.getString(9);
   				    		value = rs.getString(10);
   				    		diff = rs.getString(11);

							//get the value of the price;
							curpriceV = CommonMethods.GetDouble (curprice,0);
							shoupriceV = CommonMethods.GetDouble (shouprice,0);
							kaipriceV = CommonMethods.GetDouble (kaiprice,0);
       				if( curpriceV-shoupriceV>0 )
              {
								diffV = curpriceV-shoupriceV + 0.00001;
                sColor="#FF0000";
              }
							else   if(curpriceV-shoupriceV<0)
              {
								diffV = curpriceV-shoupriceV - 0.00001;
                sColor="#339966";
                }
              else {
               diffV = curpriceV-shoupriceV - 0.00001;
                sColor="#000000";
              }
							maxpriceV = CommonMethods.GetDouble (maxprice,0);
							minpriceV = CommonMethods.GetDouble (minprice,0);
							if(shoupriceV!=0)
								diffvV = diffV*100/shoupriceV;
							else
								diffvV = 0;
							
							//make format of the float value;
							maxprice = CommonMethods.FormatDouble(maxpriceV,2);
							minprice = CommonMethods.FormatDouble(minpriceV,2);
							diff = CommonMethods.FormatDouble(diffV,2);
							diffv = CommonMethods.FormatDouble(diffvV,2);
							curprice = CommonMethods.FormatDouble(curpriceV,2);
							kaiprice = CommonMethods.FormatDouble(kaipriceV,2);
							shouprice = CommonMethods.FormatDouble(shoupriceV,2);
							
   				    		editwarn = "<a href=\"" + CommonMethods.GetCGIDir() + "ServeStock?action=editWarn&stockcode=" + code + "\">";
   				    		for(i2=0;i2<st1.getKeyNum();i2++)
   				    		{
   				    			desHtml.addString(st1.getStringAt(i2));
								if(st1.getKeyAt(i2).compareTo("cgi-path")==0){
									desHtml.addString(CommonMethods.sHostNameCGI);
								}
								
   				    			if(st1.getKeyAt(i2).compareTo("股票名称")==0)
   				    				desHtml.addString(name);
   				    			if(st1.getKeyAt(i2).compareTo("当前价")==0)
   				    				desHtml.addString(curprice);
   				    			if(st1.getKeyAt(i2).compareTo("今开盘")==0)
   				    				desHtml.addString(kaiprice);
   				    			if(st1.getKeyAt(i2).compareTo("昨收盘")==0)
   				    				desHtml.addString(shouprice);
   				    			if(st1.getKeyAt(i2).compareTo("涨跌")==0)
   				    				desHtml.addString(diff);

   				    		//	if(st1.getKeyAt(i2).compareTo("幅度%")==0)
   				    	 //			desHtml.addString(diffv);
   				    			if(st1.getKeyAt(i2).compareTo("最高")==0)
   				    				desHtml.addString(maxprice);
   				    			if(st1.getKeyAt(i2).compareTo("最低")==0)
   				    				desHtml.addString(minprice);
   				    			if(st1.getKeyAt(i2).compareTo("成交量")==0)
   				    		 {
                       double dValue=0;
                       try{
                          dValue=Double.valueOf (value).doubleValue ();
                       }catch(Exception e){
                          dValue=0;
                    }
                    dValue=dValue/100;
   				    			desHtml.addString(dValue+"");
                    }
                    if(st1.getKeyAt(i2).compareTo("颜色")==0)
                      desHtml.addString(sColor);
   				    			if(st1.getKeyAt(i2).compareTo("股价提醒")==0)
   				    			{
   				    				if(warntype==0)
   				    				{
   				    					editwarn = editwarn + "警报编辑</a><br>";
	   				    				desHtml.addString(editwarn);
	   				    			}
	   				    			else
	   				    			{
   				    					editwarn = editwarn + "警报编辑</a>";
	   				    				desHtml.addString(editwarn);
	   				    			}
	   				    		}
   				    			if(st1.getKeyAt(i2).compareTo("股票代码")==0)
   				    			{
   				    				desHtml.addString(code);
   				    			}
   				    		}
   				    		desHtml.addString(st1.getEndString());
   				    	}
	   	    		}
	   	    		
	   	    	}
	   	    	desHtml.addString(st0.getEndString());
	   	    			   		    	
			
		} catch(Exception ex) {
		}
		DB.close ();
	}
	
	// 增加股票 
	boolean addStock(String stockcode,Person p,HtmlOut desHtml)
	{
		if(!checkStockCode(stockcode))
		{
			desHtml.setErrorID (desHtml.SHOW_SIMPLE_MESSAGE ,"",

⌨️ 快捷键说明

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