放在独立窗体或母版里,活专门用文件封装
<script language ="javascript" >
function setTab(m,n){
 var tli=document.getElementById("menu"+m).getElementsByTagName("li");
 var mli=document.getElementById("main"+m).getElementsByTagName("ul");
 for(i=0;i<tli.length;i++){
  tli[i].className=i==n?"hover":"";
  mli[i].style.display=i==n?"block":"none";
}
 }
 </script>
//前台页面
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/SpaceMold.Master"
    CodeBehind="AfficheWF.aspx.cs" Inherits="OfficeAnywhere.AfficheManage.AfficheWF" %>
   
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID ="head"><link href="../CSS/Stylesheet1.css" rel="stylesheet" type="text/css" /></asp:Content>
<asp:Content ID="Content2" runat="server" ContentPlaceHolderID="ContentPlaceHolder5">
    <div class="All">
        <ul class="menu1" id="menu1">
            <li onclick="setTab(1,0)" class="hover">公告浏览</li>
            <asp:LoginView ID="LoginView1" runat="server">
             <RoleGroups>
             <asp:RoleGroup Roles="systemAdmin">
             <ContentTemplate>
            <li onclick="setTab(1,1)">添加公告</li>
            <li onclick="setTab(1,2)">修改公告</li>
            </ContentTemplate>
             </asp:RoleGroup>
             </RoleGroups>
             </asp:LoginView>
             <asp:LoginView ID="LoginView2" runat="server">
             <RoleGroups>
             <asp:RoleGroup Roles="committeeChairman ">
             <ContentTemplate>
             <li onclick="setTab(1,0)" class="hover">公告浏览</li>
            <li onclick="setTab(1,1)">添加公告</li>
            <li onclick="setTab(1,2)">修改公告</li>
            </ContentTemplate>
             </asp:RoleGroup>
             </RoleGroups>
             </asp:LoginView>
        </ul>
        <div id="main1">
            <ul class="block">
                <li>
                    <dl class="announcScan">
                        <dd>
                            <img src="../Images/pointImage/02562155.gif" />
                            近期最新公告:</dd>
                        <dd class="gridview">
                            <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#000000"
                                BorderStyle="solid" BorderWidth="1px" CellPadding="1" Width="436px" PageSize="6"
                                onselectedindexchanged="GridView1_SelectedIndexChanged1"
                                AutoGenerateSelectButton="True" CssClass="gridviewtxt">
                                <FooterStyle BackColor="White" ForeColor="#000066" />
                                <RowStyle ForeColor="#000066" />
                                <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                                <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                                <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                            </asp:GridView>
                        </dd>
                        <dd class="page">
                            <img src="../Images/pointImage/left.png" />
                            <asp:Button ID="Button1" runat="server" Text="上一页" onclick="Button1_Click" CssClass="btn" />
                            <asp:Button ID="Button2" runat="server" Text="下一页" onclick="Button2_Click"  CssClass="btn"/><img   src="../Images/pointImage/right.png" /></dd>
                        <dd class="newAnnounce">
                            相应公告内容显示:</dd>
                        <dd>
                            <asp:TextBox ID="txtShow" runat="server" TextMode="MultiLine" CssClass="gridview" ReadOnly="true"></asp:TextBox>
                        </dd>
                    </dl>
                </li>
            </ul>
            <ul>
                <li class="announcAdd">
                    <dl>
                        <dd>
                            消息标题:&nbsp;&nbsp;<asp:TextBox ID="txtAddTitle" runat="server" CssClass="textBox"></asp:TextBox></dd>
                        <dd>
                            消息内容:&nbsp;&nbsp;<asp:TextBox ID="txtAddText" runat="server" TextMode="MultiLine"  CssClass="TextArea1"></asp:TextBox></dd>
                       
                        <dd>
                                <asp:Button ID="BtnRenew" runat="server" Text="重置" CssClass="btn" OnClick="btnSubmit_Click" /><asp:Button
                                ID="btnSubmit" runat="server" Text="提交" CssClass="btn" OnClick="BtnRenew_Click" /></dd>
                    </dl>
                </li>
            </ul>
            <ul>
                <li class="announcUpadte">
                    <dl>
                        <dd class="textColor">
                            注意:该修改栏目只能对当前的公告进行修改</dd>
                        <dd>
                            消息标题:&nbsp;&nbsp;<asp:TextBox ID="txtUpadteTitle" runat="server" CssClass="textBox"></asp:TextBox></dd>
                        <dd>
                            消息内容:&nbsp;&nbsp;<asp:TextBox ID="txtUpadteText" runat="server" TextMode="MultiLine" CssClass="TextArea1"></asp:TextBox></dd>

                        </dd>
                        <dd>
                          <asp:Button
                                ID="BtnRenew1" runat="server" Text="重置"
        CssClass="btn" onclick="BtnRenew1_Click1" />
                           <asp:Button ID="btnSubmit1" runat="server" Text="提交" CssClass="btn"
            onclick="btnSubmit1_Click" />
                            </dd>
                    </dl>
                </li>
            </ul>
        </div>
     
    </div>
</asp:Content>
//CSS文件中的内容
/*系统公告*/
 .All{ font-size:14px; color:#5c81a7; font-weight:600;}
     .menu1{ width:94px;font-size:15px; font-family:华文楷体; margin:5px 3px 4px 10px;}
  .menu1 li{ display:block; padding:4px; width:74px; height:16px; text-align:center; margin:4px auto 10px 10px; cursor:pointer; background-color:#ebf3fb;border:1px solid #58d5f7;}
  .menu1 li.hover{color:#bd0a01;font-weight:700;border-bottom-style:none; background-color:#d3e7f8;}
   #main1 ul{ display:none; list-style:none;height:449px; width:460px; float:right; margin:-108px 5px 5px 3px; border:1px solid #d4d4d4; }
      #main1 ul.block{ display:block;}
    
      /*添加公告模块*/
      .announcAdd { margin-left:12px;}
         .announcAdd  dd{ margin:20px;}
         .textBox { height:20px; font-size:15px; width:300px; border:1px solid #aacbee; background-color:#fafefe;}
         .TextArea1{ margin:8px auto -225px 1px;border:1px solid #aacbee;background-color:#fafefe; width:300px; height:239px;}
         .announcAdd  .adderId{ margin:253px 200px auto 8px;}
         .DropDownList{ height:20px; width:150px; float:right; margin:-20px 100px auto 120px; text-align:center;background-color:#fafefe;}
         .announcAdd .btn{ background-image:url(http://www.cnblogs.com/Images/Background/BtnBackGronud.png);  color :White; text-align:center; float:right; width:60px;font-weight:600; margin-top:250px; margin-left:15px;}
     
      /*浏览公告模块*/
      .announcScan { margin-left:12px;}
        .announcScan a{text-decoration:none; color:#5c81a7;}
        .announcScan a:hover{ text-decoration:underline;}
        .announcScan a:visited{ color:#65a9da;}
        .announcScan dd{ margin-top:7px;}
        .announcScan .gridview{ background-color:#bbfcac;  width:437px; height:120px;border:1px solid #aacbee; margin-top:10px;}
        .announcScan .page{ float:right; margin-right:15px;}
        .announcScan .newAnnounce{ margin-top:25px;}
        .announcScan .btn{ background-color:White; color:#5c81a7;text-decoration:underline; cursor:pointer;}
       
      /*修改公告模块*/
      .announcUpadte { margin-left:12px;}
         .announcUpadte  dd{ margin:18px;}
         .announcUpadte .textBox { height:20px; font-size:15px; width:300px; border:1px solid #aacbee; background-color:#fafefe;}
         .announcUpadte .TextArea1{ margin:8px auto -235px 1px;border:1px solid #aacbee;background-color:#fafefe;}
         .announcUpadte .adderId{ margin:253px 200px auto 8px;}
         .announcUpadte .DropDownList{ height:20px; width:150px; float:right; margin:-17px 100px auto 120px; text-align:center;background-color:#fafefe;}
         .announcUpadte .btn{ background-image:url(http://www.cnblogs.com/Images/Background/BtnBackGronud.png);  color :White; text-align:center; float:right; width:60px;font-weight:600; margin-top:250px; margin-right:10px;}
         .announcUpadte .textColor{ color:#0000ff; text-align:center; margin-top:-2px;} 
//后台事件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OfficeAnywhere.AfficheManage.BLL;

namespace OfficeAnywhere.AfficheManage
{
    public partial class AfficheWF : BasePage
    {
        private Affiche affiche;
        private int smid = 1;
        private static int fenye = 0;
        private static int memId;
        protected void Page_Load(object sender, EventArgs e)
        {
            affiche = new Affiche();
            if (!IsPostBack)
            {
                try
                {
                    memId = Profile.MemID;
                    if (memId.ToString() == null || memId < 1)
                    {
                        Response.Redirect("~/Default.aspx");
                    }
                }
                catch
                {
                    Response.Redirect("~/Default.aspx");
                }
                try
                {
                    GridView1.DataSource = affiche.SeeTable("fenye", fenye);
                    GridView1.DataBind();
                    txtUpadteTitle.Text = affiche.SeeTable("Update", 0).Rows[0]["SMTitle"].ToString();
                    txtUpadteText.Text = affiche.SeeTable("Update", 0).Rows[0]["SMText"].ToString();
                }
                catch
                {
                    Response.Redirect("~/Default.aspx");
                }
            }
            txtShow.Text = affiche.SeeTable("Update", 0).Rows[0]["SMText"].ToString();
            GridView1.DataSource = affiche.SeeTable("fenye", fenye);
            GridView1.DataBind();
            smid = (int)affiche.SeeTable("Update", 0).Rows[0]["SMID"];
        }

        //重置
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            txtAddTitle.Text = "";
            txtAddText.Text = "";
        }
        //公告添加提交
        protected void BtnRenew_Click(object sender, EventArgs e)
        {
            if (txtAddTitle.Text.Trim() != "" && txtAddText.Text.Trim() != "")
            {

                try
                {
                    lock (e)
                    {
                        affiche = new Affiche();
                        affiche.Adds(txtAddTitle.Text.Trim(), txtAddText.Text.Trim(), memId, DateTime.Now);
                        GridView1.DataSource = affiche.SeeTable("fenye", 0);
                        GridView1.DataBind();
                        txtUpadteTitle.Text = affiche.SeeTable("Update", 0).Rows[0]["SMTitle"].ToString();
                        txtUpadteText.Text = affiche.SeeTable("Update", 0).Rows[0]["SMText"].ToString();
                        txtShow.Text = txtAddText.Text;
                    }
                }
                catch
                {
                    Response.Redirect("~/Default.aspx");
                }
            }
            else
            {
                Page.RegisterStartupScript("", "<script>alert('标题和内容均不能为空哟!')</script>");
            }
        }
        protected void BtnRenew1_Click1(object sender, EventArgs e)
        {
            //修改重置
            try
            {
                txtUpadteTitle.Text = affiche.SeeTable("Update", 0).Rows[0]["SMTitle"].ToString();
                txtUpadteText.Text = affiche.SeeTable("Update", 0).Rows[0]["SMText"].ToString();
            }
            catch
            {
                Response.Redirect("~/Default.aspx");
            }
        }

        protected void GridView1_PageIndexChanged(object sender, EventArgs e)
        {
            GridView1.DataSource = affiche.SeeTable("DaTaGridView", 0);
            GridView1.DataBind();
        }
        protected void btnSubmit1_Click(object sender, EventArgs e)
        {
            //修改提交
            if (txtUpadteText.Text.Trim() != "" && txtUpadteTitle.Text.Trim() != "")
            {
                try
                {
                    lock (e)
                    {
                        affiche = new Affiche();
                        affiche.Amend(smid, txtUpadteTitle.Text.Trim(), txtUpadteText.Text.Trim(), memId, DateTime.Now);
                        GridView1.DataSource = affiche.SeeTable("fenye", 0);
                        txtShow.Text = txtUpadteText.Text;
                        GridView1.DataBind();
                    }
                }
                catch
                {
                    Response.Redirect("~/Default.aspx");
                }
            }
            else
            {
                txtShow.Text = "对不起,您添加的公告没有成功,请重新添加!注意:内容和标题均不能为空哟!";
            }
        }

        protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
        {
            //选择单条的公告进行显示
            try
            {
                txtShow.Text = affiche.SeeTable(GridView1.Rows[GridView1.SelectedIndex].Cells[1].Text, 0).Rows[0][0].ToString();
            }
            catch
            {
                Response.Redirect("~/Default.aspx");
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            try
            {
                //上一页
                fenye = fenye + 6;
                if (fenye <= (int)Single.Parse(affiche.SeeTable("DaTaGridView", 0).Rows[0][0].ToString()))
                {
                    GridView1.DataSource = affiche.SeeTable("fenye", fenye);
                    GridView1.DataBind();
                }
                else
                {
                    fenye = (int)Single.Parse(affiche.SeeTable("DaTaGridView", 0).Rows[0][0].ToString());
                    GridView1.DataSource = affiche.SeeTable("fenye", fenye);
                    GridView1.DataBind();
                }
            }
            catch
            {
                Response.Redirect("~/Default.aspx");
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                //下一页
                fenye = fenye - 6;
                if (fenye >= 0)
                {
                    GridView1.DataSource = affiche.SeeTable("fenye", fenye);
                    GridView1.DataBind();
                }
                else
                {
                    fenye = 0;
                }
            }
            catch
            {
                Response.Redirect("~/Default.aspx");
            }
        }
    }
}


 

Posted on 2009-09-27 17:29  邬江-远波  阅读(724)  评论(0编辑  收藏  举报