.cs 页面
public partial class ProjectSeven_HRSpecial : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridView();
}
}
protected void BindGridView()
{
string strSql = "select * from HRSPECIAL_Repair where 0=0";
if (!string.IsNullOrEmpty(this.txtDept.Text.Trim()))
{
strSql += "and DEPT_NAME like '" + this.txtDept.Text.Trim() + "'";
}
if (!string.IsNullOrEmpty(this.HidDept.Value.Trim()))
{
strSql += "and DEPT like '" + this.HidDept.Value.Trim() + "' ";
}
if (!string.IsNullOrEmpty(this.txtHrbp.Text.Trim()))
{
strSql += " and HRBP_NAME like '" + this.txtHrbp.Text.Trim() + "' ";
}
if (!string.IsNullOrEmpty(this.HidHrbp.Value.Trim()))
{
strSql += "and HRBP like '" + this.HidHrbp.Value.Trim() + "' ";
}
DataTable table = DbHelperSQL.Query(strSql).Tables[0];
GridView1.DataSource = table;
GridView1.DataBind();
RecCount.Text = GridView1.PageCount.ToString();
PageIn.Text = (GridView1.PageIndex + 1).ToString();
RowCounts.Text = table.Rows.Count.ToString();
PageIndex.Text = (GridView1.PageIndex + 1).ToString();
}
protected void btnSearch_Click(object sender, EventArgs e)
{
BindGridView();
}
protected void btnClear_Click(object sender, EventArgs e)
{
this.txtDept.Text = "";
this.HidDept.Value = "";
this.txtHrbp.Text = "";
this.HidHrbp.Value = "";
BindGridView();
}
protected void btnSave_Click(object sender, EventArgs e)
{
string dept = this.HidDept.Value.Trim();
string deptname = this.txtDept.Text.Trim();
string hrbp = this.HidHrbp.Value.Trim();
string hrbpname = this.txtHrbp.Text.Trim();
if (dept == "" || hrbp == "")
{
ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script language='javascript'>alert('请将信息填写完整!')</script>");
}
else
{
string strSql = "insert into HRSPECIAL_Repair(DEPT,DEPT_NAME,HRBP,HRBP_NAME) values('" + dept + "','" + deptname + "','" + hrbp + "','" + hrbpname + "')";
if (DbHelperSQL.ExecuteSql(strSql) > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script language='javascript'>alert('保存成功')</script>");
this.txtDept.Text = "";
this.HidDept.Value = "";
this.txtHrbp.Text = "";
this.HidHrbp.Value = "";
BindGridView();
}
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindGridView();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
BindGridView();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string dept = ((HiddenField)GridView1.Rows[e.RowIndex].Cells[0].Controls[1]).Value;
string deptName = ((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[3]).Text;
string hrbp = ((HiddenField)GridView1.Rows[e.RowIndex].Cells[1].Controls[3]).Value;
string hrbpName = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[1]).Text;
string guid = GridView1.DataKeys[e.RowIndex].Value.ToString();
if (dept == "" || hrbp == "")
{
ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script language='javascript'>alert('请将信息填写完整!')</script>");
}
else
{
string strSql = "update HRSPECIAL_Repair set DEPT='" + dept + "',DEPT_NAME='" + deptName + "',HRBP='" + hrbp + "',HRBP_NAME='" + hrbpName + "' where GUID='" + guid + "'";
if (DbHelperSQL.ExecuteSql(strSql) > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script language='javascript'>alert('保存成功')</script>");
GridView1.EditIndex = -1;
BindGridView();
}
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string guid = GridView1.DataKeys[e.RowIndex].Value.ToString();
string strSql = "delete from HRSPECIAL_Repair where GUID='" + guid + "'";
if (DbHelperSQL.ExecuteSql(strSql) > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script language='javascript'>alert('删除成功')</script>");
BindGridView();
}
}
//分页及数据显示
protected void goindex_Click(object sender, EventArgs e)
{
int currentPage = 0;
try
{
currentPage = int.Parse(PageIndex.Text) - 1;
}
catch
{
return;
}
if (currentPage < 0)
{
return;
}
this.GridView1.PageIndex = int.Parse(PageIndex.Text) - 1;
BindGridView();
}
}
前台页面:
<head runat="server">
<title></title>
<script type="text/javascript">
function SelUser(FormType) {
var win = null;
var tp = (window.screen.availHeight - 500) / 2;
var lf = (window.screen.availWidth - 750) / 2;
if (win != null) {
try {
win.close();
}
catch (e2) {
win = null;
}
}
win = window.open("../../com/SelectUser.aspx?FormType=" + escape(FormType), null, "scrollbars=yes, resizable=no, toolbar=no, menubar=no, location=no, directories=no,width=750,height=500,top=" + tp + ",left=" + lf);
}
function CheckDept(FormType) {
var win = null;
var tp = (window.screen.availHeight - 500) / 2;
var lf = (window.screen.availWidth - 750) / 2;
if (win != null) {
try {
win.close();
}
catch (e2) {
win = null;
}
}
win = window.open("../../com/selDept.aspx?FormType=" + escape(FormType) + "", null, "scrollbars=yes, resizable=no, toolbar=no, menubar=no, location=no, directories=no,width=750,height=400,top=" + tp + ",left=" + lf);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<fieldset>
<legend>查询区域</legend>
<table width="100%" border="0" cellpadding="1" cellspacing="1">
<tr>
<td class="SilverTr" align="left" style="width: 20%;">
部门:
</td>
<td style="width: 20%">
<asp:TextBox ID="txtDept" runat="server"></asp:TextBox>
<asp:HiddenField ID="HidDept" runat="server" />
<input type="button" id="btnDept" value="..." onclick="CheckDept('deptcheck')" />
</td>
<td class="SilverTr" align="left" style="width: 20%;">
HRBP:
</td>
<td style="width: 20%">
<asp:TextBox ID="txtHrbp" runat="server"></asp:TextBox>
<asp:HiddenField ID="HidHrbp" runat="server" />
<input type="button" id="btnHrbp" value="..." onclick="SelUser('PM_Hrbp')" />
</td>
<td>
<asp:Button ID="btnSearch" runat="server" Text="查询" OnClick="btnSearch_Click" />
<asp:Button ID="btnClear" runat="server" Text="重置" OnClick="btnClear_Click" />
<asp:Button ID="btnSave" runat="server" Text="保存" OnClick="btnSave_Click" />
</td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>显示区域</legend>
<div style="padding-right: 0px; overflow-y: auto; padding-left: 0px; scrollbar-face-color: black;
padding-bottom: 0px; scrollbar-highlight-color: #d4d0c8; overflow: auto; width: 100%;
scrollbar-shadow-color: #919192; scrollbar-3dlight-color: #d4d0c8; line-height: 100%;
scrollbar-arrow-color: #919192; padding-top: 0px; scrollbar-track-color: #d4d0c8;
scrollbar-darkshadow-color: #d4d0c8; letter-spacing: 1pt; height: auto;">
</div>
<div>
共条<asp:Label ID="RowCounts" runat="server"></asp:Label>数据 第<asp:Label ID="PageIn"
runat="server"></asp:Label>/<asp:Label ID="RecCount" runat="server" />页
<asp:TextBox ID="PageIndex" runat="server" Width="25px"></asp:TextBox>
<asp:Button ID="goindex" runat="server" Text="GO" OnClick="goindex_Click" />
</div>
<div>
<asp:GridView ID="GridView1" runat="server" PageSize="20" BackColor="#CCCCFF" AutoGenerateColumns="False"
Width="100%" EmptyDataText="No Data!" DataKeyNames="GUID" EnableModelValidation="True"
OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting"
OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="部门">
<EditItemTemplate>
<asp:HiddenField ID="HidDEPT" runat="server" Value='<%# Eval("DEPT") %>' />
<asp:TextBox ID="txtDEPT" runat="server" Text='<%# Eval("DEPT_NAME") %>'></asp:TextBox>
<input id="btnDEPT" type="button" value="..." onclick='var type= "deptname-" + document.all[this.sourceIndex - 1].name;CheckDept(type);' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("DEPT_Name") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="40%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="HRBP">
<EditItemTemplate>
<asp:TextBox ID="txtHRBP" runat="server" Text='<%# Eval("HRBP_Name") %>'></asp:TextBox>
<asp:HiddenField ID="HidHRBP" runat="server" Value='<%# Eval("HRBP") %>' />
<input id="btnHRBP" type="button" value="..." onclick='var type= "hrbpname-" + document.all[this.sourceIndex - 1].name;SelUser(type);' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("HRBP_NAME") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="40%" />
</asp:TemplateField>
<asp:CommandField HeaderText="编辑" ShowEditButton="True">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" Width="10%" />
</asp:CommandField>
<asp:CommandField HeaderText="删除" ShowDeleteButton="True">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" Width="10%" />
</asp:CommandField>
</Columns>
<PagerSettings FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PreviousPageText="上一页"
Mode="NextPreviousFirstLast" />
<RowStyle BackColor="#EFF3FB" />
<PagerStyle ForeColor="Black" HorizontalAlign="Center" />
<EditRowStyle BackColor="#2461BF" />
<HeaderStyle BackColor="#EEF3F6" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
</fieldset>
</form>
</body>
</html>