HTML CODE
<form runat="server" id="Form1">
<asp:ScriptManager runat="server" id="up122ff"></asp:ScriptManager>
<div class="grid">
<asp:UpdatePanel runat="server" id="htiti123" UpdateMode="Conditional">
<contenttemplate>
<TABLE cellSpacing=0 width="100%"><TBODY><TR class="forumno category"><TD style="HEIGHT: 2px" colSpan=3>
管理注册企业</TD></TR><TR><TD style="HEIGHT: 26px" colSpan=3> 注册用户名:<asp:TextBox id="tuser" runat="server" __designer:wfdid="w6" CssClass="input2" Width="91px"></asp:TextBox>
企业关键字<asp:TextBox id="ttile" runat="server" __designer:wfdid="w7" CssClass="input2" Width="132px"></asp:TextBox>
猎头企业<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="-1">全部</asp:ListItem>
<asp:ListItem Value="1">是</asp:ListItem>
<asp:ListItem Value="0">否</asp:ListItem>
</asp:DropDownList>
<asp:Button id="Button3" οnclick="Button3_Click" runat="server"
__designer:wfdid="w8" CssClass="button" Text="查找企业" Width="70px"></asp:Button> <asp:Label id="lb_where" runat="server" __designer:wfdid="w9" Visible="False"></asp:Label></TD></TR></TBODY></TABLE>
<asp:DataList id="DataList1" runat="server" __designer:wfdid="w10" Width="733px"
DataKeyField="id" ShowFooter="False" CellPadding="0" BorderWidth="0px">
<ItemTemplate>
<TABLE style="TABLE-LAYOUT: fixed; WIDTH: 745px; BACKGROUND-COLOR: gainsboro" cellSpacing=1 cellPadding=2 border=0>
<TBODY><TR><TD style="WIDTH: 4%; HEIGHT: 23px; BACKGROUND-COLOR: white">
<asp:CheckBox id="a" runat="server" __designer:wfdid="w6"></asp:CheckBox></TD>
<TD style="OVERFLOW: hidden; WIDTH: 13%; HEIGHT: 23px; TEXT-OVERFLOW: ellipsis; BACKGROUND-COLOR: #ffffff"
colSpan=1>
<asp:Label id="lb_id" runat="server" __designer:wfdid="w7" Text='<%# Eval("id") %>' Visible="False"></asp:Label> <A style="OVERFLOW: hidden; TEXT-OVERFLOW: ellipsis" href='Edit_Company.aspx?username=<%# Eval("username") %>'><%# Eval("CompanyName") %></A></TD>
<TD style="OVERFLOW: hidden; WIDTH: 8%; HEIGHT: 23px; TEXT-OVERFLOW: ellipsis; BACKGROUND-COLOR: #ffffff; text-align: center;"><%# Eval("all_jobs") %></TD>
<TD style="WIDTH: 17%; HEIGHT: 23px; BACKGROUND-COLOR: white"><A title="给企业添加招聘信息" href='Add_Job.aspx?Username=<%# Eval("userName") %>'>
添加</A> | <A title="添加广告" href='admin_image_jobs.aspx?Username=<%# Eval("userName") %>'>
广告</A> | <A title="添加重点招聘" href='admin_link_right.aspx?Username=<%# Eval("userName") %>'>
重点</A> </TD>
<TD style="WIDTH: 10%; HEIGHT: 23px; BACKGROUND-COLOR: white"><%# Eval("add_time","{0:d}") %></TD>
<TD style="WIDTH:10%; HEIGHT: 23px; BACKGROUND-COLOR: white"><%# Eval("lastlogintime","{0:d}") %></TD>
<TD style="WIDTH: 5%; HEIGHT: 23px; BACKGROUND-COLOR: white"><%# strState(Eval("state")) %></TD>
<TD style="WIDTH: 10%; HEIGHT: 23px; BACKGROUND-COLOR: white"><%# strCheck(Eval("usertype")) %></TD>
<td style="WIDTH: 8%; HEIGHT: 23px; BACKGROUND-COLOR: white">
<A href='admin_linkman.aspx?Username=<%# Eval("userName") %>'> 联系人</A></td>
<td style="WIDTH: 7%; HEIGHT: 23px; BACKGROUND-COLOR: white">
<asp:Label ID="Label1" runat="server" Text='<%# Eval("sales") %>'></asp:Label> </td>
<td style="WIDTH: 3%; HEIGHT: 23px; BACKGROUND-COLOR: white">
<A href='admin_fuwu.aspx?Username=<%# Eval("userName") %>'> 服务 </A>
</td>
<TD style="WIDTH: 3%; HEIGHT: 23px; BACKGROUND-COLOR: white"><A href='add_note.aspx?username=<%# Eval("username") %>'>
留言</A></TD>
<td style="WIDTH: 3%; HEIGHT: 23px; BACKGROUND-COLOR: white">
<A href='admin_hetong2.aspx?username=<%# Eval("userName") %>'>合同</A></td>
</TR></TBODY></TABLE>
</ItemTemplate>
<EditItemTemplate>
</EditItemTemplate>
<HeaderTemplate>
<TABLE style="WIDTH:100%; BACKGROUND-COLOR: gainsboro; table-layout:fixed"
cellSpacing=1 cellPadding=2 border=0>
<TBODY>
<TR>
<TD style="WIDTH: 4%; HEIGHT: 23px; BACKGROUND-COLOR: white">
</td>
<td colspan="1" style="overflow: hidden; width: 13%; height: 23px; text-overflow: ellipsis;
background-color: #ffffff">
<a style="overflow:hidden; text-overflow:ellipsis;">
公司名称
</a>
</td>
<TD style="WIDTH: 8%; HEIGHT: 23px; BACKGROUND-COLOR: #ffffff; overflow:hidden; text-overflow:ellipsis;">
职位数
</td>
<TD style="WIDTH: 17%; HEIGHT: 23px; BACKGROUND-COLOR: white">
添加各类招聘
</td>
<td style="width: 10%; height: 23px; background-color: white">
注册时间
</td> <td style="width: 10%; height: 23px; background-color: white">
最后登陆时间
</td>
<td style="width: 5%; height: 23px; background-color: white">
状态
</td>
<td style="width: 10%; height: 23px; background-color: white">
会员类别
</td>
<td style="width: 8%; height: 23px; background-color: white">
联系人</td>
<td style="width: 7%; height: 23px; background-color: white">
Sales </td>
<td style="width: 3%; height: 23px; background-color: white">
服务 </td>
<TD style="WIDTH: 3%; HEIGHT: 23px; BACKGROUND-COLOR: white">
留言</td>
<td style="WIDTH: 3%; HEIGHT: 23px; BACKGROUND-COLOR: white">
合同</td>
</tr>
</tbody>
</table>
</HeaderTemplate>
</asp:DataList> <TABLE class="top" style="width: 100%"><TBODY><TR><TD style="WIDTH: 893px; HEIGHT: 1px" align=left colSpan=2><asp:CheckBox id="cbox" runat="server" __designer:wfdid="w11" Text="全选" OnCheckedChanged="cbox_CheckedChanged" AutoPostBack="True"></asp:CheckBox>
<asp:Button ID="Button4" runat="server" οnclick="Button4_Click" Text="分配给Sales"
Width="97px" />
<asp:Button ID="Button5" runat="server" οnclick="Button5_Click" Text="收回Sales"
Width="71px" />
<asp:Button ID="Button1" runat="server" __designer:wfdid="w12"
CausesValidation="False" CssClass="button" οnclick="Button1_Click"
Text="删除选中的公司" Width="108px" />
<asp:Button ID="Button8" runat="server" οnclick="Button8_Click"
Text="设为猎头招聘" />
<asp:Button ID="Button9" runat="server" οnclick="Button9_Click" Text="取消猎头" />
</TD></TR><TR><TD>
一共有<asp:Label id="lb_count" runat="server" __designer:wfdid="w13" ForeColor="Red"></asp:Label>
条数据,每页显示<asp:Label id="lb_size" runat="server" __designer:wfdid="w14" Text="10" ForeColor="Red"></asp:Label>
条数据,当前为第<asp:Label id="lb_page" runat="server" __designer:wfdid="w15" Text="1" ForeColor="Red"></asp:Label>
页,一共有<asp:Label id="lb_allpage" runat="server" __designer:wfdid="w16" ForeColor="Red"></asp:Label>
页<asp:Button ID="Button6" runat="server" οnclick="Button6_Click" Text="上一页"
Width="46px" />
<asp:Button ID="Button7" runat="server" οnclick="Button7_Click" Text="下一页"
Width="41px" />
跳转到第 <asp:TextBox id="tpage" runat="server" __designer:wfdid="w19" CssClass="input2" Width="28px"></asp:TextBox>
页 <asp:Button id="Button2" οnclick="Button2_Click" runat="server"
__designer:wfdid="w20" CssClass="button" Text="确定" Width="35px"></asp:Button>
</TD></TR></TBODY></TABLE>
</contenttemplate>
</asp:UpdatePanel>
</div>
</form>
C# CODE
protected void Button1_Click(object sender, EventArgs e)
{
string sid = this.return_id();
if (sid != "-1")
{
CompanyInfo.Delete_Company(sid);
this.pagecut();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
if (DB.IsNumeric(this.tpage.Text))
{
int num = int.Parse(this.tpage.Text);
int num2 = int.Parse(this.lb_allpage.Text);
if (num >= num2)
{
num = num2;
}
if (num <= 1)
{
num = 1;
}
this.lb_page.Text = num.ToString();
this.pagecut();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
this.lb_where.Text = "1=1";
if (this.ttile.Text != "")
{
this.lb_where.Text = this.lb_where.Text + " and [CompanyName] like '%" + this.ttile.Text + "%'";
}
if (this.tuser.Text != "")
{
this.lb_where.Text = this.lb_where.Text + " and UserName='" + this.tuser.Text + "'";
}
if (this.DropDownList1.SelectedValue != "-1")
{
this.lb_where.Text = this.lb_where.Text + " and LieTou='" +this.DropDownList1.SelectedValue.Trim() + "'";
}
this.pagecut();
}
protected void cbox_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < this.DataList1.Items.Count; i++)
{
if (((CheckBox) this.DataList1.Items[i].FindControl("a")).Checked)
{
((CheckBox) this.DataList1.Items[i].FindControl("a")).Checked = false;
}
else
{
((CheckBox) this.DataList1.Items[i].FindControl("a")).Checked = true;
}
}
}
public void padding(string tbname, string FieldKey, string FieldShow, string Where, string FieldOrder, int PageCurrent, int PageSize)
{
SqlConnection connection = DB.CreatCon();
connection.Open();
SqlCommand command = new SqlCommand("P_viewPage", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@TableName", SqlDbType.VarChar, 500));
command.Parameters["@TableName"].Value = tbname;
command.Parameters.Add(new SqlParameter("@PrimaryKey", SqlDbType.VarChar, 500));
command.Parameters["@PrimaryKey"].Value = FieldKey;
command.Parameters.Add(new SqlParameter("@FieldList", SqlDbType.VarChar, 800));
command.Parameters["@FieldList"].Value = FieldShow;
command.Parameters.Add(new SqlParameter("@Where", SqlDbType.VarChar, 800));
command.Parameters["@Where"].Value = Where;
command.Parameters.Add(new SqlParameter("@Order", SqlDbType.VarChar, 800));
command.Parameters["@Order"].Value = FieldOrder;
command.Parameters.Add(new SqlParameter("@SortType", SqlDbType.VarChar, 800));
command.Parameters["@SortType"].Value = 2;
command.Parameters.Add(new SqlParameter("@RecorderCount", SqlDbType.VarChar, 800));
command.Parameters["@RecorderCount"].Value = 0;
command.Parameters.Add(new SqlParameter("@PageIndex", SqlDbType.Int));
command.Parameters["@PageIndex"].Value = PageCurrent;
command.Parameters.Add(new SqlParameter("@PageSize", SqlDbType.Int));
command.Parameters["@PageSize"].Value = PageSize;
command.Parameters.Add(new SqlParameter("@TotalPageCount", SqlDbType.Int));
command.Parameters["@TotalPageCount"].Direction = ParameterDirection.Output;
command.Parameters.Add(new SqlParameter("@TotalCount", SqlDbType.Int));
command.Parameters["@TotalCount"].Direction = ParameterDirection.Output;
SqlDataReader reader = command.ExecuteReader();
this.DataList1.DataSource = reader;
this.DataList1.DataBind();
connection.Close();
this.lb_allpage.Text = Convert.ToString(command.Parameters["@TotalPageCount"].Value);
this.lb_count.Text = Convert.ToString(command.Parameters["@TotalCount"].Value);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.IsPostBack)
{
UserList.Is_LoginUser();
this.lb_where.Text = "1=1";
this.pagecut();
this.Button1.Attributes.Add("onClick", "return confirm('确认删除吗?')");
}
}
public void pagecut()
{
this.padding("Company", "id", "id,UserName,CompanyName,all_jobs,add_time,lastlogintime,state,usertype,sales", this.lb_where.Text, "id desc", int.Parse(this.lb_page.Text), 10);
//this.padding("Company", "Company.id", "Company.id,Company.UserName,CompanyName,all_jobs,add_time,LastLogin,state,usertype", this.lb_where.Text, "Company.id desc", int.Parse(this.lb_page.Text), 10);
}
public string return_id()
{
string str = ",";
for (int i = 0; i < this.DataList1.Items.Count; i++)
{
if (((CheckBox) this.DataList1.Items[i].FindControl("a")).Checked)
{
str = str + ((Label) this.DataList1.Items[i].FindControl("lb_id")).Text + ",";
}
}
if (str != ",")
{
return str.Substring(0, str.Length - 1).Substring(1);
}
return (str = "-1");
}
public string strCheck(object o)
{
if (o.ToString() == "1")
{
return "<font color=blue>正式会员</font>";
}
return "<font color=/"#a9a9a9/">试用会员</font>";
}
public string strState(object o)
{
if (o.ToString() == "0")
{
return "<font color=blue>开启</font>";
}
return "<font color=/"#a9a9a9/">关闭</font>";
}
protected void Button4_Click(object sender, EventArgs e)
{
string sid = this.return_id();
if (sid != "-1")
{
Response.Redirect("Setsales.aspx?sales="+sid);
}
}
protected void Button5_Click(object sender, EventArgs e)
{
string sid = this.return_id();
if (sid != "-1")
{
SqlConnection connection = DB.CreatCon();
connection.Open();
string sales = "";
string sql = "update Company set sales='" + sales + "' where id in (" + sid + ")";
try
{
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.ExecuteNonQuery();
this.pagecut();
}
catch
{
Response.Write("<script>alert(/"操作失败!/")</script>");
}
connection.Close();
}
}
protected void Button6_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(this.lb_page.Text) > 1)
{
this.lb_page.Text = Convert.ToString((uint)(Convert.ToUInt32(this.lb_page.Text) - 1));
this.pagecut();
}
}
protected void Button7_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(this.lb_page.Text) < Convert.ToInt32(this.lb_allpage.Text))
{
this.lb_page.Text = Convert.ToString((uint)(Convert.ToUInt32(this.lb_page.Text) + 1));
this.pagecut();
}
}
protected void Button8_Click(object sender, EventArgs e)
{
string sid = this.return_id();
if (sid != "-1")
{
SqlConnection connection = DB.CreatCon();
connection.Open();
string sales = "";
string sql = "update Company set LieTou='1' where id in (" + sid + ")";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.ExecuteNonQuery();
WebMessage m = new WebMessage("提示!", "猎头服务已添加!", "ok.gif", HttpContext.Current.Request.Url.PathAndQuery);
m.SaveMessage(m);
base.Response.Redirect("message.aspx");
connection.Close();
}
}
protected void Button9_Click(object sender, EventArgs e)
{
string sid = this.return_id();
if (sid != "-1")
{
SqlConnection connection = DB.CreatCon();
connection.Open();
string sales = "";
string sql = "update Company set LieTou='0' where id in (" + sid + ")";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.ExecuteNonQuery();
this.pagecut();
WebMessage m = new WebMessage("提示!", "猎头服务已取消!", "ok.gif", HttpContext.Current.Request.Url.PathAndQuery);
m.SaveMessage(m);
base.Response.Redirect("message.aspx");
connection.Close();
}
}
SQL CODE
-----------分页储存过程
ALTER PROC PageView
@tbname sysname, --要分页显示的表名
@FieldKey sysname, --用于定位记录的主键(惟一键)字段,只能是单个字段
@PageCurrent int=1, --要显示的页码
@PageSize int=10, --每页的大小(记录数)
@FieldShow nvarchar(1000)='', --以逗号分隔的要显示的字段列表,如果不指定,则显示所有字段
@FieldOrder nvarchar(1000)='', --以逗号分隔的排序字段列表,可以指定在字段后面指定DESC/ASC
--用于指定排序顺序
@Where nvarchar(1000)='', --查询条件
@PageCount int OUTPUT --总页数
AS
DECLARE @sql nvarchar(4000)
SET NOCOUNT ON
--检查对象是否有效
IF OBJECT_ID(@tbname) IS NULL
BEGIN
RAISERROR(N'对象"%s"不存在',1,16,@tbname)
RETURN
END
IF OBJECTPROPERTY(OBJECT_ID(@tbname),N'IsTable')=0
AND OBJECTPROPERTY(OBJECT_ID(@tbname),N'IsView')=0
AND OBJECTPROPERTY(OBJECT_ID(@tbname),N'IsTableFunction')=0
BEGIN
RAISERROR(N'"%s"不是表、视图或者表值函数',1,16,@tbname)
RETURN
END
--分页字段检查
IF ISNULL(@FieldKey,N'')=''
BEGIN
RAISERROR(N'分页处理需要主键(或者惟一键)',1,16)
RETURN
END
--其他参数检查及规范
IF ISNULL(@PageCurrent,0)<1 SET @PageCurrent=1
IF ISNULL(@PageSize,0)<1 SET @PageSize=10
IF ISNULL(@FieldShow,N'')=N'' SET @FieldShow=N'*'
IF ISNULL(@FieldOrder,N'')=N''
SET @FieldOrder=N''
ELSE
SET @FieldOrder=N'ORDER BY '+LTRIM(@FieldOrder)
IF ISNULL(@Where,N'')=N''
SET @Where=N''
ELSE
SET @Where=N'WHERE ('+@Where+N')'
--如果@PageCount为NULL值,则计算总页数(这样设计可以只在第一次计算总页数,以后调用时,把总页数传回给存储过程,避免再次计算总页数,对于不想计算总页数的处理而言,可以给@PageCount赋值)
IF @PageCount IS NULL
BEGIN
SET @sql=N'SELECT @PageCount=COUNT(*)'
+N' FROM '+@tbname
+N' '+@Where
EXEC sp_executesql @sql,N'@PageCount int OUTPUT',@PageCount OUTPUT
SET @PageCount=(@PageCount+@PageSize-1)/@PageSize
END
--计算分页显示的TOPN值
DECLARE @TopN varchar(20),@TopN1 varchar(20)
SELECT @TopN=@PageSize,
@TopN1=@PageCurrent*@PageSize
--第一页直接显示
IF @PageCurrent=1
EXEC(N'SELECT TOP '+@TopN
+N' '+@FieldShow
+N' FROM '+@tbname
+N' '+@Where
+N' '+@FieldOrder)
ELSE
BEGIN
SELECT @PageCurrent=@TopN1,
@sql=N'SELECT @n=@n-1,@s=CASE WHEN @n<'+@TopN
+N' THEN @s+N'',''+QUOTENAME(RTRIM(CAST('+@FieldKey
+N' as varchar(8000))),N'''''''') ELSE N'''' END FROM '+@tbname
+N' '+@Where
+N' '+@FieldOrder
SET ROWCOUNT @PageCurrent
EXEC sp_executesql @sql,
N'@n int,@s nvarchar(4000) OUTPUT',
@PageCurrent,@sql OUTPUT
SET ROWCOUNT 0
IF @sql=N''
EXEC(N'SELECT TOP 0'
+N' '+@FieldShow
+N' FROM '+@tbname)
ELSE
BEGIN
SET @sql=STUFF(@sql,1,1,N'')
--执行查询
EXEC(N'SELECT TOP '+@TopN
+N' '+@FieldShow
+N' FROM '+@tbname
+N' WHERE '+@FieldKey
+N' IN('+@sql
+N') '+@FieldOrder)
END
END