asp.net中的DataGridView增删改查加分页

2020-12-13 15:56

阅读:221

YPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

标签:datagridview   style   http   io   color   ar   os   java   for   

前台页面:

EnableEventValidation="true" %>




平台员工允许统计采购数据采购管理









平台员工允许统计采购数据采购管理







采购商或供应商帐号:







EmptyDataText="没有符合条件的数据!" CssClass="GridViewStyle">





‘>





‘>






‘>







‘>






‘>






‘>删除












5条信息 class="red">10 条/页 当前 1
/ 1









员工账号:
平台账号:










后台代码:

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;
}
}
///


/// 通过guid查询 名称
///

///
///
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;
}
///
/// 查询
///

///
///
protected void btnSearch_Click(object sender, EventArgs e)
{
this.show3.Visible = false;
this.divShow2.Visible = true;
//显示数据
BingdingData();
}
///
/// 绑定数据
///

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(); //记录错误信息的方法
}
}
///


/// 添加
///

///
///
protected void btnInsert_Click(object sender, EventArgs e)
{
this.show3.Visible = true;
}
///
/// 提交保存
///

///
///
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", "");
return;
}
//获取该平台账号是否存在
if (staff.SearchStaffName(StaffNmae.Text.Trim()) {
Page.RegisterStartupScript("delete", "");
return;
}
//获取采购或供应商的guid
int guidBuyername = staff.SearchBuyersByname(this.txtSetxtNamel.Text.Trim());
int guidProname = staff.SearchproviderByname(this.txtSetxtNamel.Text.Trim());
if (guidBuyername {
Page.RegisterStartupScript("delete", "");
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", "");
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", "");
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;
}
}
///


/// 删除
///

///
///
protected void lbtnDel_Command(object sender, CommandEventArgs e)
{
try
{
int num = staff.DelInof(Convert.ToInt32(e.CommandArgument));
if (num != 0)
{
//删除成功 重新加载信息
BingdingData();
Page.RegisterStartupScript("delete", "");
}
}
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(); //记录错误信息的方法
}
}
///
/// 截取字符串,防止字符太多,把表格撑开
///

/// 需要截取字符的字符串
/// 截取长度
///
public string SubStr(string tempStr, int len)
{
if (tempStr != null && tempStr.Length > len)
{
return tempStr.Substring(0, len) + "......";
}
else
{
return tempStr;
}
}
///
/// 首页 上一页 下一页 尾页
///

///
///
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 {
indexPage++;
}
break;
case "尾页":
if (indexPage {
indexPage = pageCount - 1;
}
break;
}
BingdingData();
}
}

asp.net中的DataGridView增删改查加分页

标签:datagridview   style   http   io   color   ar   os   java   for   

原文地址:http://www.cnblogs.com/ingstyle/p/4077811.html


评论


亲,登录后才可以留言!