1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Web;
|
---|
5 | using System.Web.UI;
|
---|
6 | using System.Web.UI.WebControls;
|
---|
7 | using WebControls.HLAdminService;
|
---|
8 |
|
---|
9 | namespace WebControls {
|
---|
10 | public partial class OKBNamedDetailControl : System.Web.UI.UserControl {
|
---|
11 |
|
---|
12 | // delegate for the stored event
|
---|
13 | public delegate void OKBItemStoredDelegate(Object sender, EventArgs e);
|
---|
14 |
|
---|
15 | //event for the store button
|
---|
16 | public event OKBItemStoredDelegate OKBItemStored;
|
---|
17 |
|
---|
18 | //private namedOKBItem
|
---|
19 | private static NamedOKBItem namedOKBItem;
|
---|
20 |
|
---|
21 | /*
|
---|
22 | * Page_load is always executed when the control will be refreshed
|
---|
23 | */
|
---|
24 | protected void Page_Load(object sender, EventArgs e) {
|
---|
25 | if (UCWidth == null) {
|
---|
26 | UCWidth = "100%";
|
---|
27 | }
|
---|
28 | if (UCHeight == null) {
|
---|
29 | UCHeight = "150";
|
---|
30 | }
|
---|
31 | this.Panel1.Width = new Unit(UCWidth);
|
---|
32 | this.Panel1.Height = new Unit(UCHeight);
|
---|
33 |
|
---|
34 | if (IsPostBack) {
|
---|
35 | namedOKBItem = (NamedOKBItem)ViewState["namedOKBItem"];
|
---|
36 | }
|
---|
37 | this.setEnableState();
|
---|
38 |
|
---|
39 | }
|
---|
40 |
|
---|
41 | /*
|
---|
42 | * setNamedOKBItem, set a new OKBItem to the Control
|
---|
43 | * the Item is stored in the viewstate of the control
|
---|
44 | */
|
---|
45 | public void setNamedOKBItem(NamedOKBItem okbItem) {
|
---|
46 | namedOKBItem = okbItem;
|
---|
47 | if (namedOKBItem != null) {
|
---|
48 | tbName.Text = namedOKBItem.Name;
|
---|
49 | tbDescription.Text = namedOKBItem.Description;
|
---|
50 | tbName.DataBind();
|
---|
51 | tbDescription.DataBind();
|
---|
52 | }
|
---|
53 | ViewState["namedOKBItem"] = namedOKBItem;
|
---|
54 | this.setEnableState();
|
---|
55 | }
|
---|
56 |
|
---|
57 | /*
|
---|
58 | * getNamedOKBItem, to get the current stored OKBItem
|
---|
59 | */
|
---|
60 | public NamedOKBItem getNamedOKBItem() {
|
---|
61 | return namedOKBItem;
|
---|
62 | }
|
---|
63 |
|
---|
64 | /*
|
---|
65 | * setEnableState, is to se the enabledstate of the store button
|
---|
66 | */
|
---|
67 | private void setEnableState() {
|
---|
68 | if (namedOKBItem == null) {
|
---|
69 | this.Visible = false;
|
---|
70 | } else {
|
---|
71 | this.Visible = true;
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | private bool isModified() {
|
---|
76 | if (namedOKBItem.Name == tbName.Text && namedOKBItem.Description == tbDescription.Text) {
|
---|
77 | return false;
|
---|
78 | } else {
|
---|
79 | return true;
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | /*
|
---|
84 | * DataBind is to bind data manually
|
---|
85 | */
|
---|
86 | public override void DataBind() {
|
---|
87 | base.DataBind();
|
---|
88 | tbName.DataBind();
|
---|
89 | tbDescription.DataBind();
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | /*
|
---|
94 | * btnStore_Click, is always executed, if the store button is clicked
|
---|
95 | */
|
---|
96 | protected void btnStore_Click(object sender, EventArgs e) {
|
---|
97 | if (namedOKBItem != null) {
|
---|
98 | namedOKBItem.Name = tbName.Text;
|
---|
99 | namedOKBItem.Description = tbDescription.Text;
|
---|
100 | ViewState["namedOKBItem"] = namedOKBItem;
|
---|
101 | base.DataBind();
|
---|
102 | this.setEnableState();
|
---|
103 | if (null != OKBItemStored) {
|
---|
104 | OKBItemStored(this, EventArgs.Empty);
|
---|
105 | }
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | private string UCWidth;
|
---|
111 | private string UCHeight;
|
---|
112 |
|
---|
113 | public string Width { get { return UCWidth; } set { UCWidth = value; } }
|
---|
114 | public string Height { get { return UCHeight; } set { UCHeight = value; } }
|
---|
115 |
|
---|
116 |
|
---|
117 |
|
---|
118 | /*
|
---|
119 | * tbName_TextChanged, is to refresh the view State of the control
|
---|
120 | */
|
---|
121 | protected void tbName_TextChanged(object sender, EventArgs e) {
|
---|
122 | setEnableState();
|
---|
123 | }
|
---|
124 |
|
---|
125 | /*
|
---|
126 | * tbDescription_TextChanged, is to refresh the view State of the control
|
---|
127 | */
|
---|
128 | protected void tbDescription_TextChanged(object sender, EventArgs e) {
|
---|
129 | setEnableState();
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | }
|
---|
134 | } |
---|