審批流session
第一種:this
【FlowPath代碼】代理
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;orm
/// <summary>
/// FlowPath 的摘要說明
/// </summary>
public partial class FlowPath
{
public string Name
{
get
{
MyDBDataContext Context=new MyDBDataContext();
var query = context.Emp.Where(p => p.UserName == this.EmpId);
if (query.Count() > 0)
{
return query.First().Name;
}
return "";
}server
}
}對象
【登陸源】排序
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
用戶名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
密碼:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="登陸" />
</div>
</form>
</body>索引
【登陸代碼】get
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;input
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["user"] = TextBox1.Text;
Response.Redirect("~/Test/Main.aspx");
}
}
【Main源】
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:UserList ID="UserList1" runat="server" />
<uc2:NodesShow ID="NodesShow1" runat="server" />
</div>
</form>
</body>
【Main代碼】
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Main : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
UserList1.Show += NodesShow1.ShowSession;
}
}
【NodesShow源】
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="NodesShow.ascx.cs" Inherits="NodesShow" %>
<asp:Panel ID="Panel1" runat="server">
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<HeaderTemplate>
<table width="300" border="0" align="center">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="220"><%#Eval("Name") %></td>
<td width="44">
<asp:ImageButton ID="ImageButton1" OnClick="ImageButton1_Click" runat="server" CommandArgument="<%#SetKey() %>" ImageUrl="~/images/delete.png"/></td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/arrow.png" /></td>
<td></td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="提交" OnClick="btnSubmit_Click" />
</asp:Panel>
【NodesShow代碼】
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class NodesShow : System.Web.UI.UserControl
{
private string SetKey()
{
return Eval("Code").ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ShowSession();
}
}
private void ShowSession()
{
if (Session["list"] != null)
{
List<FlowPath>list=Session["list"]as List<FlowPath>;
Repeater1.DataSource = list;
Repeater1.DataBind();
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
}
protected void ImageButton1_Click(object sender, EventArgs e)
{
//刪除的代碼
//1.獲取要刪除的主鍵
string key = (sender as ImageButton).CommandArgument.ToString();
//2.執行刪除
if (Session["list"] != null)
{
List<FlowPath> list = Session["list"] as List<FlowPath>;
FlowPath data=list.Where(p => p.Code == key).First();
list.Remove(data);
Session["list"] = list;
}
//3.刷新
ShowSession();
}
}
【UserList源】
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserList.ascx.cs" Inherits="UserList" %>
<asp:Panel ID="Panel1" runat="server" HorizontalAlign="Center">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<input type="radio" name="rbusers" value="<%#Eval("UserName") %>"><%#Eval("Name") %>
</ItemTemplate>
</asp:Repeater>
<br/>
<asp:Button ID="btnAddNode" runat="server" Text="添加節點" OnClick="btnAddNode_Click" />
</asp:Panel>
【UserList代碼】
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class UserList : System.Web.UI.UserControl
{
//定義代理新類型
public delegate void ShowDelegate();
//使用代理類型定義代理變量
public event ShowDelegate Show;
private MyDBDataContext_Context=new MyDBDataContext();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var query = _Context.Emp;
Repeater1.DataSource=query;
Repeater1.DataBind();
}
}
protected void btnAddNode_Click(object sender, EventArgs e)
{ //1、獲取以前添加的人員列表
if(Session["list"]==null)
{
List<FlowPath>temp=new List<FlowPath>();
Session["list"]=temp;
}
List<FlowPath>list=Session["list"]as List<FlowPath>;
}
//2、添加選中人員
//1.計算人員排序號
list=list.OrderBy(p=>p.Orders).ToList();
int order=1;
if(list.Count>0)
{
order=list.Last().Orders.Value+1;
}
//2.生成節點對象
FlowPath data=new FlowPath();
data.Code=DateTime.Now.ToString("yyyyMMddhhmmss")+order+Session["user"].ToString();
data.EmpId=Request["rbusers"].ToString();
data.Orders=order;
//3.把對象添加到集合當中去
list.Add(data);
//4.把數據送到Session中保存
Session["list"]=list;
//3、從新綁定NodeShow中的Repeater
//從新調用
if(Show!=null)
{
Show();
}
}
第二種:
【FlowPath代碼】
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// FlowPath 的摘要說明
/// </summary>
public partial class FlowPath
{
private MyDBDataContext_Context=new MyDBDataContext();
public string Name
{
get
{
string empID=this.EmpId;
var query=_Context.Emp.Where(p=>p.UserName==empID);
if(query.Count()>0)
{
return query.First().Name;
}
return "";
}
}
}
【登陸源】
<title></title>
</head>
<body>
<form id="form1" runat="server">
用戶名:<asp:TextBox ID="txtUID" runat="server"></asp:TextBox>
<br />
密碼:<asp:TextBox ID="txtPWD" runat="server"></asp:TextBox>
<br />
<asp:Button ID="btnLogin" runat="server" OnClick="btnLogin_Click" Text="登陸" />
</form>
</body>
【登陸代碼】
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
private MyDBDataContext_Context = new MyDBDataContext();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
var query=_Context.Emp.Where(p=>p.UserName==txtUID.Text&&p.password==txtPWD.Text);
if(query.Count()>0)
{
Session["user"]=txtUID.Text;
Response.Redirect("Main.aspx");
}
}
}
【Main源】
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList ID="rblUsers" runat="server" RepeatDirection="Horizontal">
</asp:RadioButtonList>
<br />
<asp:Button ID="Button1" runat="server" Text="添加節點" OnClick="Button1_Click" />
<br />
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div>
<%#Eval("EmpID") %>
<asp:ImageButton ID="ImageButton1" CommandArgument="<%#ShowKey() %>" OnClick="ImageButton1_Click" runat="server" ImageUrl="~/images/delete.png"/>
</div>
</ItemTemplate>
<SeparatorTemplate>
<asp:Image ID="Image1" ImageUrl="~/images/arrow.png" runat="server" />
</SeparatorTemplate>
</asp:Repeater>
</div>
<asp:Button ID="Button2" runat="server" Text="提交" />
</form>
</body>
【Main代碼】
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Main : System.Web.UI.Page{ private MyDBDataConrtext_Context=new MyDBDataContext(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if(Session["list"]==null) { Response.Redirect("Default.aspx"); } //加載人員列表數據 LoadEmp(); } } public string ShowKey() { return Eval("Code").ToString(); } private void LoadEmp() { var query = _Context.Emp; rblUsers.DataSource=query; rblUsers.DataTextField="Name"; rblUsers.DataValueField="UserName"; rblUsers.DataBind(); } protected void Button1_Click(object sender, EventArgs e) { //從集合中把session取出來 if(Session["list"]==null) { List<FlowPath>temp=new List<FlowPath>(); Session["list"]=temp; } List<FlowPath>list=Session["list"]as List<FlowPath>; //找最大索引號 int maxOrders=0; if(list.Count>0) { list=list.OrderByDescending(p=>p.Orders).ToString(); int maxOrder=list.First().Orders.Value; } maxOrder++; //向session中添加對象 FlowPath data=new FlowPath(); data.Code=DateTime.Now.ToString("yyyyMMddhhmmss")+maxOrder.ToString()+Session["user"].ToString(); data.EmpId=rblUsers.SelectedValue; data.Orders=maxOrder; list.Add(data); list=list.OrderBy(p=>p.Orders).ToList(); Session["list"]=list; //頁面顯示 Repeater1.DataSource=list; Repeater1.DataBind(); } protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { //取出要刪除項的主鍵值 ImageButton btn=sender as ImageButton; string key=btn.CommandArgument.ToString(); //從session中刪除對應項 if(Session["list"]=null) { List<FlowPath>list=Session["list"]as List<FlowPath>; var query=list.Where(p=>p.Code==key); if(query.Count()>0) { FlowPath data=query.First(); list.Remove(data); Session["list"]=list; Repeater1.DataSource=list; Repeater1.DataBind(); } } }}