webservice结合dhtml的简单例子(一,webservice)

前段事件在网上看到一个基于web的财务系统,它是通过activex实现的,实际上如果用webservice结合dHTML,那完全可以抛开activex。下面是个简单的例子。
首先是webservice , 很简单,我就不详细说明了,看注释就可以了。

文件 study.asmx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.XML.Serialization ;

namespace StudyXML
{
/// <summary>
/// <br>一个webservice的例子</br>
/// <br>Author:Bigeagle@163.net</br>
/// <br>Date: 2001/12/21</br>
/// <br>History: 2001//12/21完成</br>
/// </summary>
/// <remarks>
/// 这个webservice实现的功能很简单
/// 主要功能有两个,一个是取得预定义的Item数组
/// 另一个是保存Record类型的纪录
/// </remarks>
public class Study : System.Web.Services.WebService
{

private ArrayList m_arrItems ;

private ArrayList m_arrReocrds ;

public Study()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
this.m_arrReocrds = new ArrayList() ;

this.m_arrItems = new ArrayList() ;

//增加一些实验数据
for(int i = 0 ; i < 100 ; i )
{
this.m_arrItems.Add(new Item("ItemName" i.ToString()
, "ItemValue" (i 1).ToString())) ;
}


}

/// <summary>
///
/// </summary>
/// <param name="a_strItemName">Item name</param>
/// <returns>Item对象</returns>
private Item GetItem(string a_strItemName)
{
//throw(new Exception(Server.UrlDecode(a_strItemName))) ;
for(int i = 0 ; i < this.m_arrItems.Count ; i )
{
Item item = (Item)this.m_arrItems[i] ;
if(item.Name == Server.UrlDecode(a_strItemName).Trim())
{
return item ;
}
}

return null ;
}

#region Component Designer generated code

//Required by the Web Services Designer
private IContainer components = null;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion


[WebMethod]
public void AddItem(string a_strName , string a_strValue)
{
this.m_arrItems.Add(new Item(a_strName , a_strValue));
}


/// <summary>
/// 取得Item列表
/// </summary>
/// <returns>arraylist</returns>
[WebMethod]
[XMLInclude(typeof(Item))]
public ArrayList GetItems()
{
return this.m_arrItems ;
}

/// <summary>
/// 保存纪录
/// </summary>
/// <param name="a_strItemName"></param>
/// <param name="a_strDemoName"></param>
/// <param name="a_intDemoAmount"></param>
/// <returns>如果成功返回false,否则返回false</returns>
[WebMethod]
public bool SaveRecord(string a_strItemName
, string a_strDemoName , int a_intDemoAmount)
{
try
{
Item item = this.GetItem(a_strItemName) ;
if(item != null)
{
this.m_arrReocrds.Add(new Record(this.m_arrReocrds.Count 1
, item
, new Demo(a_strDemoName , a_intDemoAmount))) ;
}
else
{
throw(new Exception("指定Item的Name错误!")) ;
}
return true ;
}
catch(Exception e)
{
throw(new Exception(e.ToString())) ;
//return false ;
}
}//end method
}//end class

/// <summary>
/// 一个简单的类,用来对应象select的option这类东西
/// </summary>
public class Item
{
private string m_strName ;
private string m_strValue ;

public string Name
{
get
{
return this.m_strName ;
}
set
{
this.m_strName = value ;
}
}

public string Value
{
get
{
return this.m_strValue ;
}
set
{
this.m_strValue = value ;
}
}

public Item(string a_strName , string a_strValue)
{
this.m_strName = a_strName ;
this.m_strValue = a_strValue ;
}
public Item()
{
this.m_strName = "" ;
this.m_strValue = "" ;
}
}//end class

/// <summary>
/// 简单的示例用类
/// 结构很简单,三个成员变量
/// 一个int类型的编号,
/// 一个item类型,一个Demo类型
/// </summary>
public class Record
{
private int m_intID ;
private Item m_objMyItem ;
private Demo m_objMyDemo ;

public Record()
{
this.m_intID = 0 ;
this.m_objMyDemo = new Demo() ;
this.m_objMyItem = new Item() ;
}

public Record(int a_intID , Item a_objItem , Demo a_objDemo)
{
this.m_intID = a_intID ;
this.m_objMyDemo = a_objDemo ;
this.m_objMyItem = a_objItem ;
}
}//end calss

/// <summary>
/// 一个简单的示例用类
/// 结构很简单,只有两个成员变量,一个name , 一个amount
/// </summary>
public class Demo
{
private string m_strName ;
private int m_intAmount ;

public string Name
{
get
{
return this.m_strName ;
}
set
{
this.m_strName = value ;
}

}

public int Amount
{
get
{
return this.m_intAmount ;
}
set
{
this.m_intAmount = value ;
}
}


/// <summary>
/// 构造函数
/// </summary>
public Demo()
{
this.m_intAmount = 0 ;
this.m_strName = "" ;
}

/// <summary>
/// 重载构造函数
/// </summary>
/// <param name="a_strName"></param>
/// <param name="a_intAmount"></param>
public Demo(string a_strName , int a_intAmount)
{
this.m_intAmount = a_intAmount ;
this.m_strName = a_strName ;
}

}//end class

}//end namespace
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
项目:使用AngularJs编写的简单 益智游戏(附源代码)  这是一个简单的 javascript 项目。这是一个拼图游戏,也包含一个填字游戏。这个游戏玩起来很棒。有两个不同的版本可以玩这个游戏。你也可以玩填字游戏。 关于游戏 这款游戏的玩法很简单。如上所述,它包含拼图和填字游戏。您可以通过移动图像来玩滑动拼图。您还可以选择要在滑动面板中拥有的列数和网格数。 另一个是填字游戏。在这里你只需要找到浏览器左侧提到的那些单词。 要运行此游戏,您需要在系统上安装浏览器。下载并在代码编辑器中打开此项目。然后有一个 index.html 文件可供您修改。在命令提示符中运行该文件,或者您可以直接运行索引文件。使用 Google Chrome 或 FireFox 可获得更好的用户体验。此外,这是一款多人游戏,双方玩家都是人类。 这个游戏包含很多 JavaScript 验证。这个游戏很有趣,如果你能用一点 CSS 修改它,那就更好了。 总的来说,这个项目使用了很多 javascript 和 javascript 库。如果你可以添加一些具有不同颜色选项的级别,那么你一定可以利用其库来提高你的 javascript 技能。 演示: 该项目为国外大神项目,可以作为毕业设计的项目,也可以作为大作业项目,不用担心代码重复,设计重复等,如果需要对项目进行修改,需要具备一定基础知识。 注意:如果装有360等杀毒软件,可能会出现误报的情况,源码本身并无病毒,使用源码时可以关闭360,或者添加信任。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值