惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
V
V2EX - 技术
S
Secure Thoughts
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
S
Securelist
S
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
Intezer
Google Online Security Blog
Google Online Security Blog
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
The Cloudflare Blog
I
InfoQ
L
LangChain Blog
U
Unit 42
P
Proofpoint News Feed
S
Schneier on Security
S
Security Affairs
Y
Y Combinator Blog
T
Tenable Blog
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
GbyAI
GbyAI
AWS News Blog
AWS News Blog

博客园 - Scott Xu(南方小鬼)

C#发现之旅第一讲 C#-XML开发 XPath Operators Basic XPath Axes Basic XPath Syntax Basic XPath Basic XSLT Basic 深入浅出之正则表达式(二) 深入浅出之正则表达式(一) 通过Microsoft.Feeds获取feeds My Best Loves C#(3.0) 深入浅出系列之相关概念 C#(3.0) 深入浅出系列 Expression Studio 2.0 中文版发布了 一定能影响你的简单十句话 众说不一,“八零”后程序员到底怎么了? SQL Server 2005 实用例子 你最应该雇佣的程序员的十个特征 .net component 开发系列1(学习) C# 中的设计模式3:Abstract Factory(学习笔记)
多个检索页面,分析,Silverlight绘图
Scott Xu(南方小鬼) · 2008-03-07 · via 博客园 - Scott Xu(南方小鬼)

一.业务需求

  1. 用户输入检索条件(会有多个检索页面)
  2. 得出检索数据,绘制相关图形

二.技术分析

     需要两张页面,第一张页面,是一个检索页面的代表,用户输入检索条件,服务器调用业务逻辑层,处理检索条件,得出检索结果,检索结果保存为DataTable,作为第一个页面的属性AnalysisResult,然后Server.Transfer到新的Silverlight绘图页面,第二个页面获取前一个页面的AnalysisResult,交给Silverlight,然后绘图。

三.具体实现

     由于有多个检索页面,所以先写一个接口,让所有检索页面实现该接口。

using System.Data; 

namespace WanFangData.Retrieve
{
    
public interface IRetrievePage
    
{
        DataTable AnalysisResult 
get; }
    }

}
 

     然后新建一个检索页面WebForm1,实现该接口

using System;
using System.Data;
using WanFangData.Retrieve;
using WanFangData.Analyse; 

namespace WanFangData.Web
{
    
public partial class WebForm1 : System.Web.UI.Page,IRetrievePage
    
{
        
private DataTable _analysisresult; 

        
protected void Button1_Click(object sender, EventArgs e)
        
{
            _analysisresult 
= gjfx.getGJFX(TextBox1.Text, TextBox2.Text);  //调用业务逻辑层
            Server.Transfer("WebForm2.aspx");
        }
 

        
IRetrievePage Members
    }

}

     Silverlight绘图页面获取前一个页面的AnalysisResult属性,将其序列化成JSON,在Silverlight的onload事件里,把JSON传入,Silverlight获得JSON字符串后,反序列化成类对象,然后根据类对象的属性值绘图。

WebForm2

<div id="SilverlightControlHost" class="silverlightHost"> 

    
<script type="text/javascript">
        
var authorArray=<%=JsonString%>;
        createSilverlight();
    
</script> 

</div> 

using System;
using System.Data;
using WanFangData.Analyse; 
using WanFangData.Common; 

namespace WanFangData.Web
{
    
public partial class WebForm2 : System.Web.UI.Page
    
{
        
public string JsonString;
        
protected void Page_Load(object sender, EventArgs e)
        
{
            
if (!IsPostBack)
            
{
                
if (Context.Handler.ToString() != "ASP.webform2_aspx")
                
{
                    IAnalysisPage webform 
= (IAnalysisPage)Context.Handler;
                    JsonString 
= JSONHelper.SerializerDatatable(webform.AnalysisResult);
                  }

                
else
                
{
                    Response.Redirect(
"Error.aspx");
                }

            }

        }

    }

}
 

在Silverlight Project里面的js文件里,onLoad事件调用GetJSONData方法,传进JSON字符串,即userContext

onLoad:function(sender,userContext,args)
{    
   
var cont=sender.Content.PipeLineControl;  //这里的PipeLineControl是在Page类的构造函数里注册的
   cont.GetJSONData(userContext);
} 

再来看看Page.xaml.cs文件

[Scriptable]
public partial class Page : Canvas
{
    
public Page()
    
{
       
// 注册可被外部javascript调用的对象。
        WebApplication.Current.RegisterScriptableObject("PipeLineControl"this);
        
this.Loaded += this.Page_Loaded;
    }
 

    [Scriptable]
    
public void GetJSONData(string jsonData)
    
{
        JavaScriptSerializer jss 
= new JavaScriptSerializer();
        GroupClass gc 
= jss.Deserialize<GroupClass>(jsonData);
        
this.TextBlock1.SetValue(TextBlock.TextProperty, gc.SomeProperty);
    }


    
public void Page_Loaded(object o, EventArgs e)
    
{
        InitializeComponent(); 
    }

}
 

     jss反序列化成类GroupClass的一个对象,然后把这个对象的某个属性值赋给TextBlock1的TextProperty

关于SL绘图,下次再说

本文原创,水平有限,大家多多指教哈~~