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

📄 companynews.ascx.cs

📁 asp.net 2.0 WebPart应用. 使用Web部件创建模块化的Web门户应用; 个人化特性和自定义特性; 将自定义用户控件作为Web部件使用; 创建一个个人化特性的提供程序;
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class CompanyNews : WebPartBase
{

protected bool _HR = true;
[ Personalizable(PersonalizationScope.User), 
  WebBrowsable, 
  WebDisplayName("Show HR News"),
  WebDescription("Use this property to show/hide HR news")]
public bool HR {
  get { return _HR; }
  set { _HR = value; }
}

  protected bool _Sales = true;
  [ Personalizable(PersonalizationScope.User), 
    WebBrowsable,
    WebDisplayName("Show Sales News"), 
    WebDescription("Use this property to show/hide sales news")]
  public bool Sales  {
    get { return _Sales; }
    set { _Sales = value; }
  }

  protected bool _Technology = true;
  [ Personalizable(PersonalizationScope.User), 
    WebBrowsable,
    WebDisplayName("Show Technology News"),
    WebDescription("Use this property to show/hide tech news")]
  public bool Technology  {
    get { return _Technology; }
    set { _Technology = value; }
  }

  public enum TimeframeEnum {
    Today,
    Week,
    Month
  }

  protected TimeframeEnum _Timeframe = TimeframeEnum.Month;
  [ Personalizable(PersonalizationScope.Shared), 
    WebBrowsable,
    WebDisplayName("Select a news timeframe"),
    WebDescription("Use this property to set timeframe")]
  public TimeframeEnum Timeframe {
    get { return _Timeframe; }
    set { _Timeframe = value; }
  }

  protected void Page_PreRender(object sender, EventArgs e)
  {
    // hide/show news controls
    lblSalesNews.Visible = Sales;
    lblTechNews.Visible = Technology;
    lblHRNews.Visible = HR;

    // assign web part title
    switch (Timeframe)
    {
      case TimeframeEnum.Today:
        this.Title = "News for " + DateTime.Now.ToString("MMMM d, yyyy");
        break;
      case TimeframeEnum.Week:
        DateTime day = DateTime.Today;
        while (day.DayOfWeek != DayOfWeek.Monday) {
          day = day.AddDays(-1);
        }
        this.Title = "News for the week of " + day.ToShortDateString();
        break;
      case TimeframeEnum.Month:
        this.Title = "News for " + DateTime.Today.ToString("MMMM yyyy");
        break;
    }
  }
}

⌨️ 快捷键说明

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