属性在项目中的使用

写了一个项目,总结一下属性在asp.net开发中应用。
1。页面收集数据与显示数据

 1 private  Magna.BWWMS.Model.DealWay DealWay
 2          {
 3            set
 4            {
 5                this.drplDealWay.SelectedValue = value.DealWayID;
 6                this.radlIsIn.SelectedValue = value.IsIn;
 7            }

 8            get
 9            {
10                _DealWay.DealWayID = this.drplDealWay.SelectedValue;
11                _DealWay.IsIn = this.radlIsIn.SelectedValue;
12                _DealWay.Description = this.drplDealWay.SelectedItem.Text;
13                return _DealWay;
14            }

15        }

2。页面按钮等控件的状态控制,不会状态控制代码不会在页面cs文件中到处跑,受到集中控制
 1 private  Magna.BWWMS.Model.ReceiptBreak ReceiptBreak
 2          {
 3            set
 4            {
 5                ViewState["ReceiptBreak"= value;
 6                this.txtBreakAge1.Text = value.Breakage.ToString();
 7                if(value.BreakReason.ReasonID != "")
 8                    this.drplBreakReason.SelectedValue = value.BreakReason.ReasonID;
 9                else
10                    this.drplBreakReason.SelectedIndex = 0;
11                if(value.DealWay.DealWayID != "")
12                    this.drplDealWay.SelectedValue = value.DealWay.DealWayID;
13                else
14                    this.drplDealWay.SelectedIndex = 0;
15            
16                this.btnAddReceiptBreak.Enabled = (value.BreakID !=""&& ViewReceipt.BillStatus.Status =="030");
17                this.btnAddReceiptBreak.CssClass = (value.BreakID !=""&& ViewReceipt.BillStatus.Status =="030")?"ImgButton":"ImgButton_V";
18
19                this.btnSaveReceiptBreak.Enabled = (ReceiptDtl.ReceiptDtlID !=""&& ViewReceipt.BillStatus.Status =="030");
20                this.btnSaveReceiptBreak.CssClass = (ReceiptDtl.ReceiptDtlID !=""&& ViewReceipt.BillStatus.Status =="030")?"ImgButton":"ImgButton_V";
21                this.btnSaveReceiptBreak.Text = (value.ReceiptDtlId !="")?"修改保存":"新增保存";
22            }

23            get
24            {
25                if(ViewState["ReceiptBreak"!= null)
26                    _ReceiptBreak =(Magna.BWWMS.Model.ReceiptBreak) ViewState["ReceiptBreak"];
27                _ReceiptBreak.Breakage = System.Convert.ToDecimal(txtBreakAge1.Text);
28                _ReceiptBreak.BreakReason = new Magna.BWWMS.Model.BreakReason(this.drplBreakReason.SelectedValue);
29                _ReceiptBreak.DealWay = new Magna.BWWMS.Model.DealWay(this.drplDealWay.SelectedValue,this.drplDealWay.SelectedItem.Text,this.radlIsIn.SelectedValue);
30                _ReceiptBreak.ReceiptDtlId = ReceiptDtl.ReceiptDtlID;
31                _ReceiptBreak.CargoInformation = ReceiptDtl.CargoInformation;
32                _ReceiptBreak.CargoMultiPack = ReceiptDtl.CargoMultiPack;
33                _ReceiptBreak.Basic = Basic;
34                return _ReceiptBreak;
35            }

36        }

37

3。自定义对象定义时使用属性,使用Arraylist等对象,便于绑定到页面控件如datadrid,dropdownlist等

4.在属性中初始化对象,值转换等
 1 public  BillStatus BillStatus   
 2          {
 3            get
 4            {
 5                if(_BillStatus == null)
 6                    _BillStatus = new BillStatus();
 7                return _BillStatus;
 8            }

 9            set
10            {
11                this._BillStatus = value;
12            }

13        }

你可能感兴趣的:(属性)