標籤:datagridview style http io color ar os java for
前台頁面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="StaffManager.aspx.cs" Inherits="adminmaster_StaffManager"
EnableEventValidation="true" %>
<!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 id="Head1" runat="server">
<title>平台員工允許統計採購資料採購管理</title>
<link href="../Theme/base.css" rel="stylesheet" type="text/css" />
<link href="../Theme/style.css" rel="stylesheet" type="text/css" />
<link href="../Theme/uncontrol.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div class="main">
<fieldset class="fieldset_ts">
<legend class="legends">
<img src="../images/gif_57_007.gif" /><span id="PayTitle" runat="server">平台員工允許統計採購資料採購管理</span></legend>
<div id="divShow1" runat="server" style="width: 100%">
<table style="width: 90%;">
<tr>
<td align="center" valign="middle" style="height: 50px">
<span>採購商或供應商帳號:</span>
<asp:TextBox ID="txtSel" runat="server"></asp:TextBox>
<asp:Button runat="server" Text="查詢" CssClass="btn_2_3" ID="btnSearch" OnClick="btnSearch_Click" />
<asp:Button runat="server" Text="添加" CssClass="btn_2_3" ID="btnInsert" OnClick="btnInsert_Click" />
</td>
</tr>
</table>
</div>
</fieldset>
<div id="divShow2" runat="server" style="width: 100%">
<asp:GridView ID="gvInfo" runat="server" AutoGenerateColumns="False" Width="100%"
EmptyDataText="沒有合格資料!" CssClass="GridViewStyle">
<FooterStyle ForeColor="White" />
<RowStyle CssClass="RowStyle" />
<Columns>
<asp:TemplateField HeaderText="ID" Visible="false">
<ItemTemplate>
<span title=‘<%# DataBinder.Eval(Container.DataItem, "ID").ToString()%>‘></span>
</ItemTemplate>
<ItemStyle Width="6%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="員工帳號">
<ItemTemplate>
<span title=‘<%# DataBinder.Eval(Container.DataItem, "StaffNmae").ToString()%>‘>
<%# this.SubStr(Eval("StaffNmae").ToString(), 20)%></span>
</ItemTemplate>
<ItemStyle Width="6%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="平台帳號">
<ItemTemplate>
<span title=‘<%# this.GetNameByGuid(Eval("[StaffNo]").ToString())%>‘></span>
</ItemTemplate>
<ItemStyle Width="6%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="維護人">
<ItemTemplate>
<span title=‘<%# DataBinder.Eval(Container.DataItem, "StaffUse").ToString()%>
<%# this.SubStr(Eval("StaffUse").ToString(), 20)%>‘></span>
</ItemTemplate>
<ItemStyle Width="6%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="日期">
<ItemTemplate>
<span title=‘<%# DataBinder.Eval(Container.DataItem, "Time").ToString()%>‘>
<%# this.SubStr(Eval("Time").ToString(), 20)%></span>
</ItemTemplate>
<ItemStyle Width="6%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:LinkButton ID="lbtnDel" runat="server" OnCommand="lbtnDel_Command" CommandArgument=‘<%# Bind("ID") %>‘>刪除</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="6%" />
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="PagerStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
<EditRowStyle CssClass="EditRowStyle" />
<AlternatingRowStyle CssClass="AltRowStyle" />
</asp:GridView>
<div id="divPage" style="display: block; text-align: center; width: 95%" runat="server">
<span>共 <span id="count" runat="server" class="red">5</span>條資訊 <span id="counts"
class="red">10</span> 條/頁 當前 <span id="index" class="red" runat="server">1</span>
/ <span id="indexCount" class="red" runat="server">1</span> 頁</span>
<asp:Button runat="server" ID="btnFrist" Text="首頁" CssClass="PagerStyle_btn" Width="50px" OnClick="btnPage_Click" />
<asp:Button runat="server" ID="btnUp" Text="上一頁" CssClass="PagerStyle_btn" OnClick="btnPage_Click" Width="50px" />
<asp:Button runat="server" ID="btnNext" Text="下一頁" CssClass="PagerStyle_btn" OnClick="btnPage_Click" Width="50px" />
<asp:Button runat="server" ID="btnBlack" Text="尾頁" CssClass="PagerStyle_btn" OnClick="btnPage_Click" Width="50px" />
</div>
</div>
<div id="show3" runat="server" visible="false">
員工帳號:<asp:TextBox type="text" ID="StaffNmae" runat="server" Enabled="false" ></asp:TextBox>
平台帳號: <asp:TextBox ID="txtSetxtNamel" runat="server"></asp:TextBox>
<asp:Button runat="server" Text="儲存" CssClass="btn_2_3" ID="btnAdd" OnClick="btnAdd_Click" />
</div>
</div>
<input id="Select_City_Hide" runat="server" type="hidden" value="" />
<input id="Select_City_Hide1" type="hidden" runat="server" value="" />
<input id="hidid" type="hidden" runat="server" value="" />
</form>
</body>
<script src="../js/policy/Select_Event.js" type="text/javascript" language="javascript"></script>
</html>
後台代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Collections;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
using _8000yiLibrary.StaffManagerBusiness;
public partial class adminmaster_StaffManager : System.Web.UI.Page
{
private static int indexPage = 0;
//總頁數
private static int pageCount = 0;
StaffManagerBusinessInfo staff = new StaffManagerBusinessInfo();
protected void Page_Load(object sender, EventArgs e)
{
//判斷當前登陸的使用者this.txtStaffPlatform.Value
if (Session["Account"] != null && ((int)((Account)Session["Account"]).Type == (int)Ao.UserType.AdminPlatForm || (int)((Account)Session["Account"]).Type == (int)Ao.UserType.AdminEmployee))
{
if (!IsPostBack)
{
BingdingData();
}
}
else
{
Response.Redirect("../login.aspx", false);
return;
}
}
/// <summary>
/// 通過guid查詢 名稱
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public string GetNameByGuid(string name)
{
string na = null;
try
{
na = staff.GetNameByGuid(name);
}
catch (Exception ex)
{
StaticErrLog.errlog.ErrContent = ex.ToString(); //錯誤資訊
StaticErrLog.errlog.ErrTime = DateTime.Now; //錯誤發生時間
StaticErrLog.errlog.Methods = "lbtnDel_Command()"; //發生錯誤的方法
StaticErrLog.errlog.Page = "StaffManager.aspx"; // 發生錯誤的頁面
int vv = StaticErrLog.errlog.ErrorRecord(); //記錄錯誤資訊的方法
}
return na;
}
/// <summary>
/// 查詢
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSearch_Click(object sender, EventArgs e)
{
this.show3.Visible = false;
this.divShow2.Visible = true;
//顯示資料
BingdingData();
}
/// <summary>
/// 綁定資料
/// </summary>
private void BingdingData()
{
try
{
//擷取總條數
int itmeCounts = staff.GetPageCounts(this.txtSel.Text.Trim(), 10, ref pageCount);
//總條數
this.count.InnerText = itmeCounts.ToString();
//當前頁數
this.index.InnerText = (indexPage + 1).ToString();
//總頁數
this.indexCount.InnerText = pageCount.ToString();
DataTable tb = staff.GetAllByName(10, indexPage, this.txtSel.Text.Trim());
gvInfo.DataSource = null;
gvInfo.DataSource = tb;
gvInfo.DataKeyNames = new string[] { "ID" };
gvInfo.DataBind();
}
catch (Exception ex)
{
StaticErrLog.errlog.ErrContent = ex.ToString(); //錯誤資訊
StaticErrLog.errlog.ErrTime = DateTime.Now; //錯誤發生時間
StaticErrLog.errlog.Methods = "lbtnDel_Command()"; //發生錯誤的方法
StaticErrLog.errlog.Page = "StaffManager.aspx"; // 發生錯誤的頁面
int vv = StaticErrLog.errlog.ErrorRecord(); //記錄錯誤資訊的方法
}
}
/// <summary>
/// 添加
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnInsert_Click(object sender, EventArgs e)
{
this.show3.Visible = true;
}
/// <summary>
/// 提交儲存
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAdd_Click(object sender, EventArgs e)
{
//判斷當前登陸的使用者this.txtStaffPlatform.Value
if (Session["Account"] != null && ((int)((Account)Session["Account"]).Type == (int)Ao.UserType.AdminPlatForm || (int)((Account)Session["Account"]).Type == (int)Ao.UserType.AdminEmployee))
{
try
{
//判斷當前登陸的使用者this.txtStaffPlatform.Value
if (string.IsNullOrEmpty(this.txtSetxtNamel.Text.Trim()) && string.IsNullOrEmpty(this.StaffNmae.Text.Trim()))
{
Page.RegisterStartupScript("delete", "<script language=‘javascript‘>alert(‘輸入不可為空!‘)</script>");
return;
}
//擷取該平台帳號是否存在
if (staff.SearchStaffName(StaffNmae.Text.Trim()) <= 0)
{
Page.RegisterStartupScript("delete", "<script language=‘javascript‘>alert(‘暫無該員工帳號任何資訊!‘)</script>");
return;
}
//擷取採購或供應商的guid
int guidBuyername = staff.SearchBuyersByname(this.txtSetxtNamel.Text.Trim());
int guidProname = staff.SearchproviderByname(this.txtSetxtNamel.Text.Trim());
if (guidBuyername <= 0 && guidProname <= 0)
{
Page.RegisterStartupScript("delete", "<script language=‘javascript‘>alert(‘暫無該平台帳號任何資訊!‘)</script>");
return;
}
string guidBuyer = staff.GetGuidByBuyername(this.txtSetxtNamel.Text.Trim());
string guidPro = staff.GetGuidByProname(this.txtSetxtNamel.Text.Trim());
string guid = string.Empty;
if (string.IsNullOrEmpty(guidBuyer))
guid = guidPro;
else
guid = guidBuyer;
//擷取該供應商或採購商是否存在
int count = staff.getStaff(this.StaffNmae.Text.Trim(), guid);
if (count >= 1)
{
Page.RegisterStartupScript("delete", "<script language=‘javascript‘>alert(‘該資訊已經存在!‘)</script>");
this.StaffNmae.Text = "";
this.txtSetxtNamel.Text = "";
return;
}
string loginName = (Session["Account"] as Account).UserAccount.ToString();
int num = staff.AddInfo(guid, this.StaffNmae.Text.Trim(), loginName);
if (num == 1)
{
BingdingData();
Page.RegisterStartupScript("delete", "<script language=‘javascript‘>alert(‘添加成功!‘)</script>");
this.show3.Visible = false;
this.divShow2.Visible = true;
}
}
catch (Exception ex)
{
StaticErrLog.errlog.ErrContent = ex.ToString(); //錯誤資訊
StaticErrLog.errlog.ErrTime = DateTime.Now; //錯誤發生時間
StaticErrLog.errlog.Methods = "btnAdd_Click()"; //發生錯誤的方法
StaticErrLog.errlog.Page = "StaffManager.aspx"; // 發生錯誤的頁面
int vv = StaticErrLog.errlog.ErrorRecord(); //記錄錯誤資訊的方法
}
}
else
{
Response.Redirect("../login.aspx", false);
return;
}
}
/// <summary>
/// 刪除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtnDel_Command(object sender, CommandEventArgs e)
{
try
{
int num = staff.DelInof(Convert.ToInt32(e.CommandArgument));
if (num != 0)
{
//刪除成功 重新載入資訊
BingdingData();
Page.RegisterStartupScript("delete", "<script language=‘javascript‘>alert(‘刪除成功!‘)</script>");
}
}
catch (Exception ex)
{
StaticErrLog.errlog.ErrContent = ex.ToString(); //錯誤資訊
StaticErrLog.errlog.ErrTime = DateTime.Now; //錯誤發生時間
StaticErrLog.errlog.Methods = "lbtnDel_Command()"; //發生錯誤的方法
StaticErrLog.errlog.Page = "StaffManager.aspx"; // 發生錯誤的頁面
int vv = StaticErrLog.errlog.ErrorRecord(); //記錄錯誤資訊的方法
}
}
/// <summary>
/// 截取字串,防止字元太多,把表格撐開
/// </summary>
/// <param name="tempStr">需要截取字元的字串</param>
/// <param name="len">截取長度</param>
/// <returns></returns>
public string SubStr(string tempStr, int len)
{
if (tempStr != null && tempStr.Length > len)
{
return tempStr.Substring(0, len) + "......";
}
else
{
return tempStr;
}
}
/// <summary>
/// 首頁 上一頁 下一頁 尾頁
/// </summary>
/// <param name="sendr"></param>
/// <param name="e"></param>
protected void btnPage_Click(object sender, EventArgs e)
{
switch ((sender as Button).Text)
{
case "首頁":
indexPage = 0;
break;
case "上一頁":
if (indexPage >= 1)
{
indexPage--;
}
break;
case "下一頁":
if (indexPage < pageCount - 1)
{
indexPage++;
}
break;
case "尾頁":
if (indexPage <= pageCount)
{
indexPage = pageCount - 1;
}
break;
}
BingdingData();
}
}
asp.net中的DataGridView增刪改查加分頁