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

首頁 > 編程 > .NET > 正文

剛寫好的Asp.Net時間和日期的Label控件。作為講解Asp.net控件開發的第一部分:繼承開發

2024-07-10 13:03:56
字體:
來源:轉載
供稿:網友
//==========================================================================
//名稱: zyq.webcontrols.cultural.datetimepick.datetimepicklabel
//       asp.net服務控件
//版本: 1.0.0.0
//作者: 張宇慶
//日期: 2003.2.12
//email: [email protected]
//說明: 本控件及源代碼只是為《計算機世界》開發者俱樂部asp.net論壇學習如何開發asp.net
//       服務器端控件而開發。未經本人同意請勿用作商業用途。
//
//==========================================================================
using system;
using system.globalization;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
using system.componentmodel;
using zyq;
using zyq.webcontrols.cultural.datetimepick;   
namespace zyq.webcontrols.cultural.datetimepick
{
    
    /// <summary>
    /// datetimepicklabel由system.web.ui.webcontrols.label繼承。
    /// 使用system.globalization.cultureinfo類來顯示格式化了的時間。
    /// </summary>
    [toolboxdata("<{0}:datetimepicklabel runat=server></{0}:datetimepicklabel>")]
    public class datetimepicklabel : system.web.ui.webcontrols.label
    {
        #region 私有變量定義
        private bool _autofit;
        private datetime _dt;
        private string text;
        private dateformatoption _dfo;
        private dtformatsetting datetimeset;
        zyqcultrueinfo myinfo;
        #endregion
        #region 屬性
        [bindable(true),browsable(false),
            category("appearance")]
        public override string text
        {
            get
            {
                return text;
            }

//            set
//            {
//                text =value;        
//            }
        }
        [browsable(true),category("behavior"),defaultvalue(false),description("設定是否自動適應客戶端瀏覽器的文化區域設定。如果此屬性為true,則datetimeformatshow屬性的所有設置將被忽略。")]
        public bool autofitclientbrowser
        {
            get{ return this._autofit;}
            set{this._autofit = value;}
        }

        [browsable(true),category("日期時間設置"),description("設定日期"),bindable(true)]
        [refreshproperties(refreshproperties.repaint)]
        public datetime dt
        {
            get
            {
                if(this._dt.tostring() != null)
                     return this._dt;
                return datetime.now;
            }
            set
            {
                this._dt =value;
                if(this.datetimeformatshow != null)
                    this.text=value.tostring(this.datetimeformatshow.formatestring,(new zyqcultrueinfo(this.datetimeformatshow.languageandcountry,true)).datetimeformat);
            }
        }
        [browsable(true),category("日期時間設置"),typeconverter(typeof(dtformatsettingconverter)),designerserializationvisibility(designerserializationvisibility.content),description("設定時間和日期的格式")
        ,refreshproperties(refreshproperties.repaint)]    
        public dtformatsetting datetimeformatshow
        {
            get
            {
                if(this.datetimeset ==null)
                {
                    this.datetimeset= new dtformatsetting();
                    this.datetimeset.datetimeformatchanged +=new datetimeformateeventhandler(ontextchanged);                 
                    this.text=this.dt.tostring(this.datetimeset.formatestring,(new zyqcultrueinfo(this.datetimeset.languageandcountry,true)).datetimeformat);
                }
                return this.datetimeset;
            }
            set
            {
                this.datetimeset=value;                
                this.datetimeset.datetimeformatchanged +=new datetimeformateeventhandler(ontextchanged);                 
                this.text=this.dt.tostring(value.formatestring,(new zyqcultrueinfo(value.languageandcountry,true)).datetimeformat);
            }
        }
        [browsable(true),category("日期時間設置"),description("設定時間和日期的格式類型。此屬性只在autofitclientbrowser屬性為true時,才起作用。")]
        public dateformatoption datetimeoption
        {
            get{return this._dfo;}
            set
            {
                this._dfo = value;
                if(this.autofitclientbrowser)
                    if(this.site !=null)
                        if(this.site.designmode)
                            this.autofit(cultureinfo.currentculture.name.tolower());  
            }
        }
        
        #endregion
        #region 構造
        public datetimepicklabel():base()
        {
            myinfo=new zyqcultrueinfo(datetimeformatshow.languageandcountry,true);
            _dt= datetime.now;
            this.text=dt.tostring(this.datetimeformatshow.formatestring,myinfo.datetimeformat);
        }
        #endregion
        #region 重寫相關受保護的函數和方法
        protected override void oninit(eventargs e)
        {            
            base.oninit(e);
        }
        protected override void onprerender(eventargs e)
        {    
            if(page !=null)
            {
                if(this.autofitclientbrowser)
                {
                    this.autofit(this.context.request.userlanguages[0].tolower());      
//                    page.response.charset =this.myinfo.name;  
                    page.response.write(this.context.request.userlanguages[0]+"--"+this.myinfo.name+"<br>");
                }
            }
            this.tooltip =this.datetimeformatshow.formatestring+"(space,/"./",/"//",/"-/",/":/")";
            this.text =this.dt.tostring(this.datetimeformatshow.formatestring,this.myinfo.datetimeformat);               
        }
        /// <summary>
        /// 將此控件呈現給指定的輸出參數。
        /// </summary>
        /// <param name="output"> 要寫出到的 html 編寫器 </param>
        protected override void render(htmltextwriter output)
        {
            base.render(output);
        }
        #endregion
        #region 事件處理
        private void ontextchanged(object sender, formatchangeeventargs e)
        {
            try
            {
                if(this.myinfo !=null)
                    this.myinfo =null;
                this.myinfo = new zyqcultrueinfo(e.dtsetting.languageandcountry,true);
                this.text =this.dt.tostring(e.dtsetting.formatestring,myinfo.datetimeformat );
            }
            catch(exception ee)
            {
                page.response.write(ee.message+"<br>");
                this.myinfo=null;
                
            }
            finally
            {
            
            }
        }
        #endregion
        #region 私有方法和函數
        private void autofit(string value)
        {
            if(this.myinfo !=null)
                this.myinfo =null;
            this.myinfo =new zyqcultrueinfo(value,true);
            this.datetimeformatshow = new dtformatsetting();
            this.datetimeformatshow.languageandcountry = this.myinfo.name.tolower();                    
            this.datetimeformatshow.formatestring=this.myinfo.getformatstring(this.datetimeoption.tostring());
        }
        #endregion
    }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 寿宁县| 西宁市| 正镶白旗| 介休市| 辽源市| 修文县| 永登县| 新宁县| 洛南县| 怀远县| 梁平县| 游戏| 微博| 陆河县| 囊谦县| 凤山县| 长丰县| 沈丘县| 孝感市| 中山市| 襄城县| 钟山县| 三亚市| 岳阳市| 安远县| 怀集县| 南安市| 光山县| 土默特右旗| 永丰县| 沽源县| 马龙县| 娄底市| 晋中市| 永春县| 兴仁县| 灵川县| 获嘉县| 宣武区| 兰州市| 马龙县|