CS代码
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using hn.teacher.DBoperation;
using hn.teacher.wdclass;
using hn.teacher.DBAccess;
using System.Data.SqlClient;
using hn.teacher.wdclass;
using hn.teacher.Manage.ProManage;
public partial class SysManage_ProjectManage_ShowProject : MainPage
{
private DBAccess dba = new DBAccess();
clsUserInfo user = new clsUserInfo();
public string OrgID;
public string firstOrgName;
public string secondOrgName;
public string className;
private string flagQuery ;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//ddl_CLASSIFY.Items.Add("国培");
//ddl_CLASSIFY.Items.Add("省培");
ddl_CLASSIFY.Items.Insert(0, new ListItem("--项目分类--", ""));
bind_ddl_SENATEID();
btn_Delete.Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
if (Session["flagButtonSearchClick"] != null)
{
flagQuery = Session["flagButtonSearchClick"].ToString();
}
//Session.Remove("flagButtonSearchClick");
//OrgID = Request.QueryString["OrgID"];
//firstOrgName = Request.QueryString["FirstOrgName"];
//secondOrgName = Request.QueryString["SecondOrgName"];
//className = Request.QueryString["ClassName"];
//GridView1.Columns.Clear();
bindGridView();
hideButton();
//dlBind();
//setLabel();
}
}
private void hideButton()
{
int userID = 0;
userID = int.Parse(this.UserID);
DataTable dt = dba.SelectT_PUB_USER_ROLE_BYUID(userID);
string role = dt.Rows[0]["ROLE_ID"].ToString();
if (role == "1")
{
btn_Delete.Visible = true;
}
else
{
btn_Delete.Visible = false;
}
}
private void bind_ddl_SENATEID()
{
DataTable dt = new DataTable();
dt = dba.SelectT_PUB_USER_ROLE_USER_ID_BY_ROLE_ID();
ddl_SENATEID.DataValueField = "USER_ID";
ddl_SENATEID.DataTextField = "NAME";
ddl_SENATEID.DataSource = dt;
ddl_SENATEID.DataBind();
ddl_SENATEID.Items.Insert(0, new ListItem("--省教务--", "-1"));
// ddl_SENATEID.SelectedIndex = 0;
}
/// <summary>
/// 设置当前位置标签
/// </summary>
public void setLabel()
{
}
/// <summary>
/// 设置控件可见性
/// </summary>
/// <param name="flag"></param>
public void InitPage(bool flag)
{
btn_All.Visible = flag;
btn_Cancel.Visible = flag;
btn_Delete.Visible = flag;
Label1.Visible = flag;
Label6.Visible = flag;
Label7.Visible = flag;
labBackPage.Visible = flag;
labPage.Visible = flag;
lnkbtnBack.Visible = flag;
lnkbtnNext.Visible = flag;
lnkbtnOne.Visible = flag;
lnkbtnUp.Visible = flag;
}
/// <summary>
/// 绑定GRIDVIEW和分页
/// </summary>
public void bindGridView()
{
if (Session["flagButtonSearchClick"] != null)
{
flagQuery = Session["flagButtonSearchClick"].ToString();
}
int curpage = Convert.ToInt32(this.labPage.Text);
PagedDataSource ps = new PagedDataSource();
DataTable dt = new DataTable();
if (this.GetSession().LsRole.Count >= 0 && this.GetSession().LsRole.Contains("9") && this.GetSession().IsNotContainsRole("1,2"))
{
//假如仅是区域管理人员操作,那么就只能针对他被分配的项目进行操作,下面获取它所在的项目
clsProData cpd = new clsProData();
dt = cpd.GetProjectListByUserAndDute(txt_PROJECTNAME.Text.Trim(), ddl_SENATEID.Text.Trim(), ddl_CLASSIFY.Text.Trim(), this.GetSession().UserID, UserDuteEnum.ArearManager);
}
else
{
if (flagQuery != "true")
{
dt = dba.SelectT_LEARNING_PROJECTsAll();
}
else
{
//查询
dt = dba.SelectT_LEARNING_PROJECT_BY_QUERY(txt_PROJECTNAME.Text.ToString(), int.Parse(ddl_SENATEID.Text.Trim()), ddl_CLASSIFY.Text.Trim());
}
}
if (dt.Rows.Count == 0)
{
lab_IsEmpty.Text = "数据条数为零!";
}
else
{
dt.Columns.Add("OrgName", typeof(string));
lab_IsEmpty.Text = "";
for (int i = 0; i < dt.Rows.Count; i++)
{
string sql="select * from t_pub_org where OrgID='"+dt.Rows[i]["ORG_ID"].ToString()+"'";
BDBoperation bdb = new BDBoperation();
DataTable dtTemp = bdb.RunQuery(sql);
if (dtTemp.Rows.Count > 0)
{
dt.Rows[i]["OrgName"] = dtTemp.Rows[0]["OrgName"].ToString();
}
else
{
dt.Rows[i]["OrgName"] = "";
}
}
}
ps.DataSource = dt.DefaultView;
ps.AllowPaging = true;
ps.PageSize = 10;
ps.CurrentPageIndex = curpage - 1;//todo:
this.lnkbtnUp.Enabled = true;
this.lnkbtnNext.Enabled = true;
this.lnkbtnBack.Enabled = true;
this.lnkbtnOne.Enabled = true;
if (curpage == 1)
{
this.lnkbtnOne.Enabled = false;
this.lnkbtnUp.Enabled = false;
}
if (curpage == ps.PageCount)
{
this.lnkbtnNext.Enabled = false;
this.lnkbtnBack.Enabled = false;
}
this.labBackPage.Text = Convert.ToString(ps.PageCount);
this.GridView1.DataSource = ps;
this.GridView1.DataBind();
//}
}
//第一页
protected void lnkbtnOne_Click(object sender, EventArgs e)
{
this.labPage.Text = "1";
this.bindGridView();
}
//上一页
protected void lnkbtnUp_Click(object sender, EventArgs e)
{
this.labPage.Text = Convert.ToString(Convert.ToUInt32(this.labPage.Text) - 1);
this.bindGridView();
}
//下一页
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text) + 1);
this.bindGridView();
}
//最后一页
protected void lnkbtnBack_Click(object sender, EventArgs e)
{
this.labPage.Text = this.labBackPage.Text;
this.bindGridView();
}
//GRIDVIEW中删除按钮
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//int projectID = int.Parse(GridView1.Rows[0].Cells[1].Text.ToString());
int projectID = int.Parse(GridView1.Rows[e.RowIndex].Cells[1].Text.ToString());
try
{
bool flag = dba.DeleteT_LEARNING_PROJECT(projectID);
if (flag == false)
{
Page.RegisterStartupScript("info", "<Script>alert('删除失败')</Script>");
}
else
{
Page.RegisterStartupScript("info", "<Script>alert('删除成功')</Script>");
this.bindGridView();
}
}
catch
{
//Response.Write("<Script>alert('操作失败')</Script>");
}
}
//GRIDVIEW中编辑按钮
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
string PROJECTID = GridView1.Rows[e.NewEditIndex].Cells[1].Text.ToString();
string curState = GridView1.Rows[e.NewEditIndex].Cells[6].Text;
LinkButton lkb2 = ((LinkButton)GridView1.Rows[e.NewEditIndex].Cells[11].Controls[0]);
clsProData clp = new clsProData();
if (curState == "未开始" || curState == "已结束")
{
clp.SetProgjectStat("1", PROJECTID);
GridView1.Rows[e.NewEditIndex].Cells[6].Text = "进行中";
lkb2.Text = "结束";
GridView1.Rows[e.NewEditIndex].BackColor = System.Drawing.Color.White;
}
else
{
try
{
clp.SetProgjectStat("2", PROJECTID);
GridView1.Rows[e.NewEditIndex].Cells[6].Text = "已结束";
lkb2.Text = "继续";
GridView1.Rows[e.NewEditIndex].BackColor = System.Drawing.Color.Red;
}
catch (Exception er)
{
this.WriterJsToPage(ClsAlertInfo.alertInfo(er.Message));
}
}
}
//全选
protected void btn_All_Click(object sender, EventArgs e)
{
//int name = GridView1.Rows[0].Cells["PROJECTNAME"];
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox ck = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1") as CheckBox;
if (ck != null)
{
ck.Checked = true;
}
}
}
//取消
protected void btn_Cancel_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox ck = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1") as CheckBox;
if (ck != null)
{
ck.Checked = false;
}
}
}
//批量删除
protected void btn_Delete_Click(object sender, EventArgs e)
{
if (IsDel)
{
bool flag_all = true;
clsProData cpd = new clsProData();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox ck = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1") as CheckBox;
if (ck.Checked == true)
{
int projectID = int.Parse(GridView1.Rows[i].Cells[1].Text.ToString());
if (cpd.IsIncludeAciveProjectTearm(projectID.ToString()))
{
this.WriterJsToPage(ClsAlertInfo.alertInfo("当前项目还包含有未结束的项目分期,不能对项目进行结束操作!"));
return;
}
bool flag = dba.DeleteT_LEARNING_PROJECT(projectID);
if (flag == false)
{
flag_all = false;
Page.RegisterStartupScript("info", "<Script>alert('删除成功')</Script>");
}
}
}
if (flag_all == true)
{
this.bindGridView();
}
}
else
{
this.WriterJsToPage(ClsAlertInfo.alertInfo(ClsAlertInfo.alertDelWarn));
}
}
//查询
protected void btn_Search_Click(object sender, EventArgs e)
{
Session["flagButtonSearchClick"] = "true";
labPage.Text = "1"; ///记得归位
bindGridView();
}
//新建
protected void btn_Add_Click(object sender, EventArgs e)
{
if (IsAdd)
{
Response.Redirect("AddAndEditProject.aspx");
}
else
{
ClsAlertInfo.alertInfo(ClsAlertInfo.alertAddWarn);
}
}
//批量导入
//protected void btn_Import_Click(object sender, EventArgs e)
//{
//}
protected void btn_reset_Click(object sender, EventArgs e)
{
txt_PROJECTNAME.Text = "";
ddl_SENATEID.SelectedIndex = -1;
ddl_CLASSIFY.SelectedIndex = -1;
ddl_CLASSIFY.Text = "";
ddl_SENATEID.Text = "";
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
LinkButton lkb1 = ((LinkButton)e.Row.Cells[12].Controls[0]);
LinkButton lkb2 = ((LinkButton)e.Row.Cells[11].Controls[0]);
string pState = e.Row.Cells[6].Text;
if (pState == "2")
{
e.Row.BackColor = System.Drawing.Color.Red;
e.Row.Cells[6].Text = "已结束";
lkb2.Text = "继续";
lkb1.Visible = false;
}
else if (pState == "1")
{
e.Row.BackColor = System.Drawing.Color.White;
e.Row.Cells[6].Text = "进行中";
lkb2.Text = "结束";
lkb1.Visible = false;
}
else
{
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#00FF00");
e.Row.Cells[6].Text = "未进行";
lkb2.Text = "开始";
int userID = int.Parse(this.UserID);
DataTable dt = dba.SelectT_PUB_USER_ROLE_BYUID(userID);
lkb1.Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
if (dt.Rows.Count > 0 && "1" == dt.Rows[0]["ROLE_ID"].ToString().Trim()) //如果是系统管理员。删除可见
{
}
else
{
string d = lkb1.Text;
lkb1.Visible = false;
}
}
}
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "view")
{
int index = Convert.ToInt16(e.CommandArgument);
String pid = GridView1.Rows[index].Cells[1].Text.ToString();
string url="../../ProManage/index.aspx?id="+pid.ToString().Trim();
Page.RegisterStartupScript("URL","<script>window.open('" + url + "','_blank','width=900,height:700,resizable=yes,toolbar=yes,menubar=yes,scrollbars=yes,location=yes')</script>");
}
}
protected void btn_reset_Click1(object sender, EventArgs e)
{
txt_PROJECTNAME.Text = "";
ddl_SENATEID.SelectedIndex = 0;
ddl_CLASSIFY.SelectedIndex = 0;
}
protected void Button2_Click(object sender, EventArgs e)
{
int p = 0;
try
{
p = Convert.ToInt32(this.TextBox3.Text.ToString());
}
catch (Exception ee)
{
RegisterStartupScript("key", "<Script>alert('请输入正确有效的页码')</Script>");
}
labPage.Text = p.ToString();
try
{
this.bindGridView();
}
catch
{
RegisterStartupScript("key", "<Script>alert('请输入正确有效的页码')</Script>");
}
}
}
2、页面设计
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ShowProject.aspx.cs" Inherits="SysManage_ProjectManage_ShowProject" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../css/layout.css" rel="Stylesheet" type="text/css" />
<link href="../css/botton.css" rel="Stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery-1.7.1.js"></script>
<title>项目列表</title>
<style type="text/css">
body
{
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #F1F1F1;
}
</style>
<script language="javascript" type="text/javascript" src="../../../JS/CustomPop.js" charset="gb2312"></script>
<script type="text/javascript">
function PopProjectManage(pid) {
var url = "../../ProManage/index.aspx?id=" + pid;
//location.href = url;
window.open(url);
//popWin(url);
}
function EditProject(pid) {
var url = "AddAndEditProject.aspx?PROJECTID=" + pid;
location.href = url;
}
function EditProgessPakage(pid) {
window.location.href = "PushCourse.aspx?pid="+ pid;
}
function EditProjectTearm(pid) {
window.location.href = "PushCourse.aspx?pid=" + pid;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="content">
<div class="position-bar"><p>平台管理中心 > 项目管理</p></div>
<!--主要内容-->
<div class="content-main-box">
<div class="weather-box">
<h1 class="title-main"><span><img src="../images/ico7.png" /></span>管理员,您好 欢迎使用平台管理中心</h1> </div>
<div class="table-box">
<table width="100%">
<tr style="height:30px;">
<td>
<asp:Label ID="Label8" runat="server" Text="项目名称:"></asp:Label>
 <asp:TextBox ID="txt_PROJECTNAME" runat="server"></asp:TextBox>
<asp:DropDownList ID="ddl_SENATEID" runat="server" AutoPostBack="True"
Visible="False">
</asp:DropDownList>
<asp:DropDownList ID="ddl_CLASSIFY" runat="server">
<asp:ListItem>国培</asp:ListItem>
<asp:ListItem>省培</asp:ListItem>
<asp:ListItem>市培</asp:ListItem>
<asp:ListItem>县培</asp:ListItem>
</asp:DropDownList>
<asp:Button
ID="btn_reset" runat="server" Text="清空" OnClick="btn_reset_Click1" Width="40" Height="20" />
<asp:Button ID="btn_Search" runat="server" Text="查询" OnClick="btn_Search_Click" Width="40" Height="20" />
<asp:Button ID="btn_Add" runat="server" Text="新建" OnClick="btn_Add_Click" Width="40" Height="20" />
</td>
</tr>
</table>
<table id="table1" width="100%" style="border-bottom-color:white" class="numbox" >
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
OnRowDeleting="GridView1_RowDeleting" Width="100%"
OnRowEditing="GridView1_RowEditing" OnRowDataBound="GridView1_RowDataBound" OnRowCommand="GridView1_RowCommand" >
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
<ItemStyle BackColor="White" />
</asp:TemplateField>
<asp:BoundField DataField="PROJECTID" HeaderText="项目编号" >
<ItemStyle BackColor="White" />
</asp:BoundField>
<asp:BoundField DataField="PROJECTNAME" HeaderText="项目名称" >
<ItemStyle BackColor="White" />
</asp:BoundField>
<asp:BoundField DataField="OrgName" HeaderText="机构名称" >
<ItemStyle BackColor="White" />
</asp:BoundField>
<%-- <asp:TemplateField HeaderText="机构名称">
<ItemTemplate>
<a href="javascript:EditProject('<%# DataBinder.Eval(Container, "DataItem.PROJECTID")%>')">编辑</a>
</ItemTemplate>
<ItemStyle BackColor="White" />
</asp:TemplateField>--%>
<asp:BoundField DataField="SENATEID" HeaderText="省教务编号" Visible="False" >
<ItemStyle BackColor="White" />
</asp:BoundField>
<asp:BoundField DataField="CLASSIFY" HeaderText="类型" >
<ItemStyle BackColor="White" />
</asp:BoundField>
<asp:BoundField DataField="STATE" HeaderText="项目状态" >
<ItemStyle BackColor="White" />
</asp:BoundField>
<asp:BoundField DataField="BEGINTIME" HeaderText="开始时间" DataFormatString="{0:d}" >
<ItemStyle BackColor="White" />
</asp:BoundField>
<asp:BoundField DataField="ENDTIME" HeaderText="结束时间" DataFormatString="{0:d}" >
<ItemStyle BackColor="White" />
</asp:BoundField>
<asp:TemplateField HeaderText="课程管理">
<ItemTemplate>
<a href="javascript:EditProgessPakage('<%# DataBinder.Eval(Container, "DataItem.PROJECTID")%>')">选择科目</a>
</ItemTemplate>
<ItemStyle BackColor="White" />
</asp:TemplateField>
<asp:TemplateField HeaderText="编辑">
<ItemTemplate>
<a href="javascript:EditProject('<%# DataBinder.Eval(Container, "DataItem.PROJECTID")%>')">编辑</a>
</ItemTemplate>
<ItemStyle BackColor="White" />
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" HeaderText="更改状态" >
<ItemStyle BackColor="White" />
</asp:CommandField>
<asp:CommandField ShowDeleteButton="True" >
<ItemStyle BackColor="White" />
</asp:CommandField>
<asp:TemplateField HeaderText="" ShowHeader="False">
<ItemTemplate>
<a href="javascript:PopProjectManage('<%# DataBinder.Eval(Container, "DataItem.PROJECTID")%>')">管理</a>
</ItemTemplate>
<ItemStyle BackColor="White" />
</asp:TemplateField>
</Columns>
<PagerStyle HorizontalAlign="Left" />
<SelectedRowStyle Font-Bold="True" />
<HeaderStyle Font-Bold="True" />
</asp:GridView>
</td>
</tr>
<tr valign="top">
<td align="left">
<asp:Label ID="lab_IsEmpty" runat="server" ForeColor="#FF3300"></asp:Label>
<asp:Button ID="btn_All" runat="server" Text="全选" OnClick="btn_All_Click" />
<asp:Button ID="btn_Cancel" runat="server" Text="取消" OnClick="btn_Cancel_Click" />
<asp:Button ID="btn_Delete" runat="server" Text="批量删除" OnClick="btn_Delete_Click" />
<asp:Label ID="Label7" runat="server" Font-Size="Small" Text="当前页码为: ["></asp:Label>
<asp:Label ID="labPage" runat="server" Font-Size="Small" Text="1"></asp:Label>
<asp:Label ID="Label6" runat="server" Font-Size="Small" Text="] 总页码为: ["></asp:Label>
<asp:Label ID="labBackPage" Font-Size="Small" runat="server"></asp:Label>
<asp:Label ID="Label1" runat="server" Font-Size="Small" Text="] "></asp:Label>
<asp:LinkButton ID="lnkbtnOne" runat="server" Font-Underline="False" ForeColor="Red" Font-Size="Small"
OnClick="lnkbtnOne_Click">第一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnUp" runat="server" Font-Underline="False" ForeColor="Red" Font-Size="Small"
OnClick="lnkbtnUp_Click">上一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnNext" runat="server" Font-Underline="False" ForeColor="Red" Font-Size="Small"
OnClick="lnkbtnNext_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnBack" runat="server" Font-Underline="False" ForeColor="Red" Font-Size="Small"
OnClick="lnkbtnBack_Click">最后一页</asp:LinkButton>
<asp:Button ID="Button2" runat="server" Text="跳转到" οnclick="Button2_Click" />
<asp:TextBox ID="TextBox3" runat="server" Width="41px"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Text="页"></asp:Label>
</td>
</tr>
</table>
</div>
</div>
<!--主要内容结束-->
</div>
</form>
</body>
</html>