使用GirdView展现MOSS自定义列表
前台展现代码:
展现页面ascx
1 <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DealProjectItems.ascx.cs" Inherits="ProjectManager.MyUserControl.DealItems.DealProjectItems" %>
2 <asp:Panel ID="PanelDealProjectMain" runat="server" Visible="false">
3 <div>待批项目</div>
4 <div style="text-align: center">
5 <asp:GridView ID="GridViewDealProjectItems" runat="server"
6 AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF"
7 BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal"
8 style="text-align: center" Width="98%">
9 <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
10 <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
11 <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
12 <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
13 <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#FFFFFF" />
14 <AlternatingRowStyle BackColor="#F7F7F7" />
15 <Columns>
16 <asp:HyperLinkField DataNavigateUrlFields="ID"
17 DataNavigateUrlFormatString="/ProjectManagement/Lists/ProjectSiteList/DispForm.aspx?ID={0}"
18 DataTextField="项目名称" HeaderStyle-ForeColor="#FFFFFF" HeaderText="项目名称">
19 <HeaderStyle ForeColor="White"></HeaderStyle>
20 </asp:HyperLinkField>
21 <asp:BoundField DataField="项目编号" HeaderStyle-ForeColor="#FFFFFF"
22 HeaderText="项目编号">
23 <HeaderStyle ForeColor="White"></HeaderStyle>
24 </asp:BoundField>
25 <asp:BoundField DataField="行业" HeaderStyle-ForeColor="#FFFFFF" HeaderText="行业">
26 <HeaderStyle ForeColor="White"></HeaderStyle>
27 </asp:BoundField>
28 <asp:BoundField DataField="项目类别" HeaderStyle-ForeColor="#FFFFFF"
29 HeaderText="项目类别">
30 <HeaderStyle ForeColor="White"></HeaderStyle>
31 </asp:BoundField>
32 <asp:BoundField DataField="地区省" HeaderStyle-ForeColor="#FFFFFF"
33 HeaderText="地区省">
34 <HeaderStyle ForeColor="White"></HeaderStyle>
35 </asp:BoundField>
36 <asp:BoundField DataField="地区市" HeaderStyle-ForeColor="#FFFFFF"
37 HeaderText="地区市">
38 <HeaderStyle ForeColor="White"></HeaderStyle>
39 </asp:BoundField>
40 <asp:BoundField DataField="项目负责人" HeaderStyle-ForeColor="#FFFFFF"
41 HeaderText="项目负责人">
42 <HeaderStyle ForeColor="White"></HeaderStyle>
43 </asp:BoundField>
44 <asp:BoundField DataField="审批状态" HeaderStyle-ForeColor="#FFFFFF"
45 HeaderText="审批状态">
46 <HeaderStyle ForeColor="White"></HeaderStyle>
47 </asp:BoundField>
48 <asp:BoundField DataField="项目优先级" HeaderStyle-ForeColor="#FFFFFF"
49 HeaderText="项目优先级">
50 <HeaderStyle ForeColor="White"></HeaderStyle>
51 </asp:BoundField>
52 </Columns>
53 </asp:GridView>
54
55 </div>
56 <asp:Label ID="Lable_ProjectMessage" ForeColor="Red" Text="暂时没有需要审批的项目。" Visible="False" runat="server">
57 </asp:Label>
58 </asp:Panel>
1 <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DealProjectItems.ascx.cs" Inherits="ProjectManager.MyUserControl.DealItems.DealProjectItems" %>
2 <asp:Panel ID="PanelDealProjectMain" runat="server" Visible="false">
3 <div>待批项目</div>
4 <div style="text-align: center">
5 <asp:GridView ID="GridViewDealProjectItems" runat="server"
6 AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF"
7 BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal"
8 style="text-align: center" Width="98%">
9 <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
10 <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
11 <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
12 <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
13 <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#FFFFFF" />
14 <AlternatingRowStyle BackColor="#F7F7F7" />
15 <Columns>
16 <asp:HyperLinkField DataNavigateUrlFields="ID"
17 DataNavigateUrlFormatString="/ProjectManagement/Lists/ProjectSiteList/DispForm.aspx?ID={0}"
18 DataTextField="项目名称" HeaderStyle-ForeColor="#FFFFFF" HeaderText="项目名称">
19 <HeaderStyle ForeColor="White"></HeaderStyle>
20 </asp:HyperLinkField>
21 <asp:BoundField DataField="项目编号" HeaderStyle-ForeColor="#FFFFFF"
22 HeaderText="项目编号">
23 <HeaderStyle ForeColor="White"></HeaderStyle>
24 </asp:BoundField>
25 <asp:BoundField DataField="行业" HeaderStyle-ForeColor="#FFFFFF" HeaderText="行业">
26 <HeaderStyle ForeColor="White"></HeaderStyle>
27 </asp:BoundField>
28 <asp:BoundField DataField="项目类别" HeaderStyle-ForeColor="#FFFFFF"
29 HeaderText="项目类别">
30 <HeaderStyle ForeColor="White"></HeaderStyle>
31 </asp:BoundField>
32 <asp:BoundField DataField="地区省" HeaderStyle-ForeColor="#FFFFFF"
33 HeaderText="地区省">
34 <HeaderStyle ForeColor="White"></HeaderStyle>
35 </asp:BoundField>
36 <asp:BoundField DataField="地区市" HeaderStyle-ForeColor="#FFFFFF"
37 HeaderText="地区市">
38 <HeaderStyle ForeColor="White"></HeaderStyle>
39 </asp:BoundField>
40 <asp:BoundField DataField="项目负责人" HeaderStyle-ForeColor="#FFFFFF"
41 HeaderText="项目负责人">
42 <HeaderStyle ForeColor="White"></HeaderStyle>
43 </asp:BoundField>
44 <asp:BoundField DataField="审批状态" HeaderStyle-ForeColor="#FFFFFF"
45 HeaderText="审批状态">
46 <HeaderStyle ForeColor="White"></HeaderStyle>
47 </asp:BoundField>
48 <asp:BoundField DataField="项目优先级" HeaderStyle-ForeColor="#FFFFFF"
49 HeaderText="项目优先级">
50 <HeaderStyle ForeColor="White"></HeaderStyle>
51 </asp:BoundField>
52 </Columns>
53 </asp:GridView>
54
55 </div>
56 <asp:Label ID="Lable_ProjectMessage" ForeColor="Red" Text="暂时没有需要审批的项目。" Visible="False" runat="server">
57 </asp:Label>
58 </asp:Panel>
后台代码:
class DealProjectItems
1 using System;
2 using System.Collections;
3 using System.Configuration;
4 using System.Data;
5 using System.Data.SqlClient;
6 using System.Web;
7 using System.Web.Security;
8 using System.Web.UI;
9 using System.Web.UI.HtmlControls;
10 using System.Web.UI.WebControls;
11 using System.Web.UI.WebControls.WebParts;
12
13 using Microsoft.SharePoint;
14
15 namespace ProjectManager.MyUserControl.DealItems
16 {
17 public partial class DealProjectItems : System.Web.UI.UserControl
18 {
19 /// <summary>
20 /// 待批项目记录
21 /// </summary>
22 private DataTable DealItems;
23
24 protected void Page_Load(object sender, EventArgs e)
25 {
26 ///判断当前用户是否是项目总监和站点集管理员
27 if (SPContext.Current.Web.CurrentUser.IsSiteAdmin || this.IsMajordomo(SPContext.Current.Web.CurrentUser))
28 {
29 //显示待办项目
30 this.PanelDealProjectMain.Visible = true;
31 this.InitDealItemsColumns();
32 this.InitDealItemsData();
33 if (this.DealItems.Rows.Count > 0)
34 {
35 this.Lable_ProjectMessage.Visible = false;
36 this.GridViewDealProjectItems.DataSource = this.DealItems.DefaultView;
37 }
38 else
39 {
40 //显示提示信息
41 this.Lable_ProjectMessage.Visible = true;
42 }
43 this.GridViewDealProjectItems.DataBind();
44 }
45 else
46 {
47 //隐藏待办项目
48 this.PanelDealProjectMain.Visible = false;
49 }
50 }
51
52 /// <summary>
53 /// 初始化列
54 /// </summary>
55 private void InitDealItemsColumns()
56 {
57 if (this.DealItems == null)
58 {
59 this.DealItems = new DataTable();
60 this.DealItems.Columns.Add("ID");
61 this.DealItems.Columns.Add("项目名称");
62 this.DealItems.Columns.Add("项目编号");
63 this.DealItems.Columns.Add("行业");
64 this.DealItems.Columns.Add("项目类别");
65 this.DealItems.Columns.Add("地区省");
66 this.DealItems.Columns.Add("地区市");
67 this.DealItems.Columns.Add("项目负责人");
68 this.DealItems.Columns.Add("审批状态");
69 this.DealItems.Columns.Add("项目优先级");
70 }
71
72 }
73
74 /// <summary>
75 /// 初始化数据
76 /// </summary>
77 private void InitDealItemsData()
78 {
79 SPSecurity.RunWithElevatedPrivileges(delegate()
80 {
81 SPSite site = new SPSite(SPContext.Current.Site.Url);
82 SPWeb projectWeb = site.AllWebs[SPContext.Current.Web.ID];
83 SPList projectList = projectWeb.Lists["项目站点"];
84
85 SPField projectManagerField = projectList.Fields["项目负责人"];
86
87 foreach (SPListItem item in projectList.Items)
88 {
89 if (!item["审批状态"].ToString().Equals("0"))
90 {
91 DataRow row = this.DealItems.Rows.Add(new object[0]);
92 row["ID"] = item["ID"].ToString();
93 row["项目名称"] = item["项目名称"].ToString();
94 row["项目编号"] = item["项目编号"].ToString();
95 row["行业"] = item["行业"].ToString();
96 row["项目类别"] = item["项目类别"].ToString().Substring(item["项目类别"].ToString().IndexOf('_') + 1);
97 row["地区省"] = item["地区省"].ToString();
98 row["地区市"] = item["地区市"].ToString().Substring(item["地区市"].ToString().IndexOf('_') + 1);
99 row["项目负责人"] = ((SPFieldUserValue)projectManagerField.GetFieldValue(item["项目负责人"].ToString())).User.Name;
100
101 if (item["审批状态"].ToString().Equals("1"))
102 row["审批状态"] = "已拒绝";
103 else if (item["审批状态"].ToString().Equals("2"))
104 row["审批状态"] = "待定";
105
106 row["项目优先级"] = item["项目优先级"].ToString();
107 }
108 }
109 });
110 }
111
112 /// <summary>
113 /// 是否是项目总监
114 /// </summary>
115 /// <param name="currentUser">当前登陆用户</param>
116 /// <returns></returns>
117 private bool IsMajordomo(SPUser currentUser)
118 {
119 bool result = false;
120
121 SPSecurity.RunWithElevatedPrivileges(delegate()
122 {
123 SPSite site = new SPSite(currentUser.ParentWeb.Site.Url);
124 SPWeb projectWeb = site.AllWebs["ProjectManagement"];
125 SPGroup majordomoGroup = projectWeb.SiteGroups["项目总监"];
126 if (majordomoGroup != null)
127 {
128 foreach (SPUser user in majordomoGroup.Users)
129 {
130 if (user.LoginName.Equals(currentUser.LoginName))
131 {
132 result = true;
133 break;
134 }
135 }
136 }
137
138 });
139
140 return result;
141 }
142
143 }
144 }
1 using System;
2 using System.Collections;
3 using System.Configuration;
4 using System.Data;
5 using System.Data.SqlClient;
6 using System.Web;
7 using System.Web.Security;
8 using System.Web.UI;
9 using System.Web.UI.HtmlControls;
10 using System.Web.UI.WebControls;
11 using System.Web.UI.WebControls.WebParts;
12
13 using Microsoft.SharePoint;
14
15 namespace ProjectManager.MyUserControl.DealItems
16 {
17 public partial class DealProjectItems : System.Web.UI.UserControl
18 {
19 /// <summary>
20 /// 待批项目记录
21 /// </summary>
22 private DataTable DealItems;
23
24 protected void Page_Load(object sender, EventArgs e)
25 {
26 ///判断当前用户是否是项目总监和站点集管理员
27 if (SPContext.Current.Web.CurrentUser.IsSiteAdmin || this.IsMajordomo(SPContext.Current.Web.CurrentUser))
28 {
29 //显示待办项目
30 this.PanelDealProjectMain.Visible = true;
31 this.InitDealItemsColumns();
32 this.InitDealItemsData();
33 if (this.DealItems.Rows.Count > 0)
34 {
35 this.Lable_ProjectMessage.Visible = false;
36 this.GridViewDealProjectItems.DataSource = this.DealItems.DefaultView;
37 }
38 else
39 {
40 //显示提示信息
41 this.Lable_ProjectMessage.Visible = true;
42 }
43 this.GridViewDealProjectItems.DataBind();
44 }
45 else
46 {
47 //隐藏待办项目
48 this.PanelDealProjectMain.Visible = false;
49 }
50 }
51
52 /// <summary>
53 /// 初始化列
54 /// </summary>
55 private void InitDealItemsColumns()
56 {
57 if (this.DealItems == null)
58 {
59 this.DealItems = new DataTable();
60 this.DealItems.Columns.Add("ID");
61 this.DealItems.Columns.Add("项目名称");
62 this.DealItems.Columns.Add("项目编号");
63 this.DealItems.Columns.Add("行业");
64 this.DealItems.Columns.Add("项目类别");
65 this.DealItems.Columns.Add("地区省");
66 this.DealItems.Columns.Add("地区市");
67 this.DealItems.Columns.Add("项目负责人");
68 this.DealItems.Columns.Add("审批状态");
69 this.DealItems.Columns.Add("项目优先级");
70 }
71
72 }
73
74 /// <summary>
75 /// 初始化数据
76 /// </summary>
77 private void InitDealItemsData()
78 {
79 SPSecurity.RunWithElevatedPrivileges(delegate()
80 {
81 SPSite site = new SPSite(SPContext.Current.Site.Url);
82 SPWeb projectWeb = site.AllWebs[SPContext.Current.Web.ID];
83 SPList projectList = projectWeb.Lists["项目站点"];
84
85 SPField projectManagerField = projectList.Fields["项目负责人"];
86
87 foreach (SPListItem item in projectList.Items)
88 {
89 if (!item["审批状态"].ToString().Equals("0"))
90 {
91 DataRow row = this.DealItems.Rows.Add(new object[0]);
92 row["ID"] = item["ID"].ToString();
93 row["项目名称"] = item["项目名称"].ToString();
94 row["项目编号"] = item["项目编号"].ToString();
95 row["行业"] = item["行业"].ToString();
96 row["项目类别"] = item["项目类别"].ToString().Substring(item["项目类别"].ToString().IndexOf('_') + 1);
97 row["地区省"] = item["地区省"].ToString();
98 row["地区市"] = item["地区市"].ToString().Substring(item["地区市"].ToString().IndexOf('_') + 1);
99 row["项目负责人"] = ((SPFieldUserValue)projectManagerField.GetFieldValue(item["项目负责人"].ToString())).User.Name;
100
101 if (item["审批状态"].ToString().Equals("1"))
102 row["审批状态"] = "已拒绝";
103 else if (item["审批状态"].ToString().Equals("2"))
104 row["审批状态"] = "待定";
105
106 row["项目优先级"] = item["项目优先级"].ToString();
107 }
108 }
109 });
110 }
111
112 /// <summary>
113 /// 是否是项目总监
114 /// </summary>
115 /// <param name="currentUser">当前登陆用户</param>
116 /// <returns></returns>
117 private bool IsMajordomo(SPUser currentUser)
118 {
119 bool result = false;
120
121 SPSecurity.RunWithElevatedPrivileges(delegate()
122 {
123 SPSite site = new SPSite(currentUser.ParentWeb.Site.Url);
124 SPWeb projectWeb = site.AllWebs["ProjectManagement"];
125 SPGroup majordomoGroup = projectWeb.SiteGroups["项目总监"];
126 if (majordomoGroup != null)
127 {
128 foreach (SPUser user in majordomoGroup.Users)
129 {
130 if (user.LoginName.Equals(currentUser.LoginName))
131 {
132 result = true;
133 break;
134 }
135 }
136 }
137
138 });
139
140 return result;
141 }
142
143 }
144 }