国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > HTML > 正文

webservice結(jié)合dhtml的簡(jiǎn)單例子(一,webservice)

2024-08-26 00:15:33
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
    前段事件在網(wǎng)上看到一個(gè)基于web的財(cái)務(wù)系統(tǒng),它是通過(guò)activex實(shí)現(xiàn)的,實(shí)際上如果用webservice結(jié)合dhtml,那完全可以拋開(kāi)activex。下面是個(gè)簡(jiǎn)單的例子。
首先是webservice , 很簡(jiǎn)單,我就不詳細(xì)說(shuō)明了,看注釋就可以了。

文件 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>一個(gè)webservice的例子</br>
    /// <br>author:[email protected]</br>
    /// <br>date:  2001/12/21</br>
    /// <br>history: 2001//12/21完成</br>
    /// </summary>
    /// <remarks>
    /// 這個(gè)webservice實(shí)現(xiàn)的功能很簡(jiǎn)單
    /// 主要功能有兩個(gè),一個(gè)是取得預(yù)定義的item數(shù)組
    /// 另一個(gè)是保存record類型的紀(jì)錄
    /// </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() ;

            //增加一些實(shí)驗(yàn)數(shù)據(jù)
            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對(duì)象</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>
        ///  保存紀(jì)錄
        /// </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錯(cuò)誤!")) ;
                }
                return true ;
            }
            catch(exception e)
            {
                throw(new exception(e.tostring())) ;
                //return false ;
            }
        }//end method
    }//end class

    /// <summary>
    /// 一個(gè)簡(jiǎn)單的類,用來(lái)對(duì)應(yīng)象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>
    /// 簡(jiǎn)單的示例用類
    /// 結(jié)構(gòu)很簡(jiǎn)單,三個(gè)成員變量
    /// 一個(gè)int類型的編號(hào),
    /// 一個(gè)item類型,一個(gè)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>
    /// 一個(gè)簡(jiǎn)單的示例用類
    /// 結(jié)構(gòu)很簡(jiǎn)單,只有兩個(gè)成員變量,一個(gè)name , 一個(gè)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>
        /// 構(gòu)造函數(shù)
        /// </summary>
        public demo()
        {
            this.m_intamount = 0 ;
            this.m_strname = "" ;
        }

        /// <summary>
        /// 重載構(gòu)造函數(shù)
        /// </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


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 尼勒克县| 昌乐县| 武定县| 闽清县| 广东省| 逊克县| 沁源县| 三门峡市| 宁城县| 茂名市| 凯里市| 布拖县| 新田县| 天峨县| 东乡县| 明水县| 钟山县| 斗六市| 孝感市| 图木舒克市| 巴中市| 呼和浩特市| 商南县| 吕梁市| 福建省| 襄汾县| 社旗县| 芦山县| 永定县| 江西省| 阳泉市| 湟源县| 贵阳市| 竹溪县| 宣化县| 宁远县| 宿州市| 上高县| 阿荣旗| 桐梓县| 巩义市|