Front page:
<%@ 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 ">
<title> platform employees allow statistics procurement data procurement management </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 "/>
<body>
<form id= "Form1" runat= "Server" >
<div class= "Main" >
<fieldset class= "Fieldset_ts" >
<legend class= "Legends" >
<span id=" Paytitle "runat=" Server "> Platform staff Allow statistics procurement data purchase management </span></legend >
<div id= "DivShow1" runat= "Server" style= "width:100%" >
<table style= "width:90%;" >
<tr>
<TD align= "center" valign= "Middle" style= "height:50px" >
<span> Buyer or Supplier account:</span>
<asp:textbox id= "Txtsel" runat= "Server" ></asp:TextBox>
<asp:button runat= "Server" text= "query" cssclass= "Btn_2_3" id= "btnsearch" onclick= "btnSearch_Click"/>
<asp:button runat= "Server" text= "Add" 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= "No qualifying data!" 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= "Employee Account" >
<ItemTemplate>
<span title= ' <%# databinder.eval (Container.DataItem, "Staffnmae"). ToString ()%> ' >
<%# this. SUBSTR (Eval ("Staffnmae"). ToString (),%></span>
</ItemTemplate>
<itemstyle width= "6%"/>
</asp:TemplateField>
<asp:templatefield headertext= "Platform Account" >
<ItemTemplate>
<span title= ' <%# this. Getnamebyguid (Eval ("[Staffno]"). ToString ())%> ' ></span>
</ItemTemplate>
<itemstyle width= "6%"/>
</asp:TemplateField>
<asp:templatefield headertext= "Maintenance person" >
<ItemTemplate>
<span title= ' <%# databinder.eval (Container.DataItem, "Staffuse"). ToString ()%>
<%# this. SUBSTR (Eval ("Staffuse"). ToString (),%> ' ></span>
</ItemTemplate>
<itemstyle width= "6%"/>
</asp:TemplateField>
<asp:templatefield headertext= "Date" >
<ItemTemplate>
<span title= ' <%# databinder.eval (Container.DataItem, "time"). ToString ()%> ' >
<%# this. SUBSTR (Eval ("Time"). ToString (),%></span>
</ItemTemplate>
<itemstyle width= "6%"/>
</asp:TemplateField>
<asp:templatefield headertext= "Operation" >
<ItemTemplate>
<asp:linkbutton id= "Lbtndel" runat= "Server" oncommand= "Lbtndel_command" commandargument= ' <%# Bind ("ID")%> ' > Delete </asp:LinkButton>
</ItemTemplate>
<itemstyle width= "6%"/>
</asp:TemplateField>
</Columns>
<pagerstyle cssclass= "PagerStyle"/>
<selectedrowstyle cssclass= "SelectedRowStyle"/>
<editrowstyle cssclass= "EditRowStyle"/>
<alternatingrowstyle cssclass= "Altrowstyle"/>
</asp:GridView>
<div id= "Divpage" style= "display:block; Text-align:center; width:95% "runat=" Server >
<span> Total <span id= "Count" runat= "server" class= "Red" >5</span> message <span id= "counts"
class= "Red" >10</span> bar/page current <span id= "index" class= "Red" runat= "Server" >1</span>
/<span id= "Indexcount" class= "Red" runat= "Server" >1</span> page </span>
<asp:button runat= "Server" id= "btnfrist" text= "Home" cssclass= "pagerstyle_btn" width= "50px" onclick= "Btnpage_click" />
<asp:button runat= "Server" id= "Btnup" text= "prev" cssclass= "pagerstyle_btn" onclick= "Btnpage_click" Width= "50px"/ >
<asp:button runat= "Server" id= "Btnnext" text= "Next" cssclass= "Pagerstyle_btn" onclick= "Btnpage_click" Width= "50px" />
<asp:button runat= "Server" id= "Btnblack" text= "Last" cssclass= "pagerstyle_btn" onclick= "Btnpage_click" Width= "50px" />
</div>
</div>
<div id= "SHOW3" runat= "Server" visible= "false" >
Employee Account: <asp:textbox type= "text" id= "Staffnmae" runat= "Server" enabled= "false" ></asp:TextBox>
Platform account: <asp:textbox id= "Txtsetxtnamel" runat= "Server" ></asp:TextBox>
<asp:button runat= "Server" text= "save" 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>
Background code:
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;
Total pages
private static int pagecount = 0;
Staffmanagerbusinessinfo staff = new Staffmanagerbusinessinfo ();
protected void Page_Load (object sender, EventArgs e)
{
Determine the current logged-on user 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>
Query name by 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 (); Error message
StaticErrLog.errlog.ErrTime = DateTime.Now; Error occurrence time
StaticErrLog.errlog.Methods = "Lbtndel_command ()"; How the error occurred
StaticErrLog.errlog.Page = "staffmanager.aspx"; The page where the error occurred
int vv = StaticErrLog.errlog.ErrorRecord (); Ways to log error messages
}
Return na;
}
<summary>
Inquire
</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;
Show data
Bingdingdata ();
}
<summary>
Binding Data
</summary>
private void Bingdingdata ()
{
Try
{
Get total number of bars
int itmecounts = staff. Getpagecounts (This.txtSel.Text.Trim (), ten, ref PageCount);
Total number of bars
This.count.InnerText = Itmecounts.tostring ();
Current page
This.index.InnerText = (indexpage + 1). ToString ();
Total pages
This.indexCount.InnerText = Pagecount.tostring ();
DataTable TB = staff. Getallbyname (Ten, 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 (); Error message
StaticErrLog.errlog.ErrTime = DateTime.Now; Error occurrence time
StaticErrLog.errlog.Methods = "Lbtndel_command ()"; How the error occurred
StaticErrLog.errlog.Page = "staffmanager.aspx"; The page where the error occurred
int vv = StaticErrLog.errlog.ErrorRecord (); Ways to log error messages
}
}
<summary>
Add to
</summary>
<param name= "Sender" ></param>
<param name= "E" ></param>
protected void Btninsert_click (object sender, EventArgs e)
{
This.show3.Visible = true;
}
<summary>
Commit Save
</summary>
<param name= "Sender" ></param>
<param name= "E" ></param>
protected void btnAdd_Click (object sender, EventArgs e)
{
Determine the current logged-on user 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
{
Determine the current logged-on user this.txtStaffPlatform.Value
if (string. IsNullOrEmpty (This.txtSetxtNamel.Text.Trim ()) && string. IsNullOrEmpty (this. StaffNmae.Text.Trim ()))
{
Page.registerstartupscript ("delete", "<script language= ' JavaScript ' >alert (' input cannot be empty! ') </script> ");
Return
}
Gets whether the platform account exists
if (staff. Searchstaffname (StaffNmae.Text.Trim ()) <= 0)
{
Page.registerstartupscript ("delete", "<script language= ' JavaScript ' >alert (' No information on this employee account! ') </script> ");
Return
}
Get the GUID of the purchase or vendor
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 (' No information on the platform account! ') </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;
Gets whether the vendor or purchaser exists
int count = Staff.getstaff (this. StaffNmae.Text.Trim (), GUID);
if (Count >= 1)
{
Page.registerstartupscript ("delete", "<script language= ' JavaScript ' >alert (' This information already exists! ') </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 (' Add success! ') </script> ");
This.show3.Visible = false;
This.divShow2.Visible = true;
}
}
catch (Exception ex)
{
StaticErrLog.errlog.ErrContent = ex. ToString (); Error message
StaticErrLog.errlog.ErrTime = DateTime.Now; Error occurrence time
StaticErrLog.errlog.Methods = "btnAdd_Click ()"; How the error occurred
StaticErrLog.errlog.Page = "staffmanager.aspx"; The page where the error occurred
int vv = StaticErrLog.errlog.ErrorRecord (); Ways to log error messages
}
}
Else
{
Response.Redirect (".. /login.aspx ", false);
Return
}
}
<summary>
Delete
</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)
{
Remove successful Reload information
Bingdingdata ();
Page.registerstartupscript ("delete", "<script language= ' JavaScript ' >alert (' Delete succeeded! ') </script> ");
}
}
catch (Exception ex)
{
StaticErrLog.errlog.ErrContent = ex. ToString (); Error message
StaticErrLog.errlog.ErrTime = DateTime.Now; Error occurrence time
StaticErrLog.errlog.Methods = "Lbtndel_command ()"; How the error occurred
StaticErrLog.errlog.Page = "staffmanager.aspx"; The page where the error occurred
int vv = StaticErrLog.errlog.ErrorRecord (); Ways to log error messages
}
}
<summary>
intercepts strings, prevents too many characters, and keeps tables open
</summary>
<param name= "TempStr" > string to intercept characters </param>
<param name= "len" > Intercept length </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>
Home previous Next last page
</summary>
<param name= "Sendr" ></param>
<param name= "E" ></param>
protected void Btnpage_click (object sender, EventArgs e)
{
Switch (sender as Button). Text)
{
Case "Home":
indexpage = 0;
Break
Case "Previous page":
if (indexpage >= 1)
{
indexpage--;
}
Break
Case "Next page":
if (Indexpage < pageCount-1)
{
indexpage++;
}
Break
Case "Last":
if (indexpage <= PageCount)
{
Indexpage = pageCount-1;
}
Break
}
Bingdingdata ();
}
}
DataGridView additions and deletions in ASP.