Context
Page หรือ Form
State
ทำเป็น abstract class ของ Action
ConcreteState
ConcreteStateA = Add
ConcreteStateB = Change
ConcreteState........
method Handle() ใช้เป็น Save()
method Request() ของ Page ก็ใช้ป็น OnSaveClick()
* Start State ของ Page ได้รับจาก Main Menu *
// Context
public partial class MaterialMaster : System.Web.UI.Page{
// State
public abstract class MaterialMasterActionState {
// Handle()
public abstract void Save(MaterialMaster Context);
}
// ConcreteStateA
public class MaterialAdd : MaterialMasterActionState{
public override void Save(MaterialMaster Context) {
// Save Material into Database
}
}
// ConcreteStateB
public class MaterialChange : MaterialMasterActionState{
public override void Save(MaterialMaster Context) {
// Change Material into Database
}
}
#region ActionState Properties
private MaterialMasterActionState _ActionState;
public MaterialMasterActionState ActionState {
get { return (Session["state"] as MaterialMasterActionState); }
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
switch (Request.QueryString["action"])
{
case "add":
_ActionState = new MaterialAdd(this);
break;
case "change":
_ActionState = new MaterialChange(this);
break;
case "delete":
break;
case "display":
break;
default:
break;
}
if (_ActionState != null) { Session["state"] = _ActionState; }
}
// Request()
void ToolsBar1_SaveButtonClicked(object sender, EventArgs e)
{
// State.Handle()
if (Session["state"] != null)
{
ActionState.Save(this);
}
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น