MVC
//下拉--------------------------------------------------------------------------------------------------------------------------
视图传typeid ---- @Html.DropDownList("typeid")
public ActionResult selectctl()
{
ViewBag.typeid = new SelectList(bll.getSelect(), "typeid", "typename");
return View();
}
// 三元
@Html.Raw(@item.sta==0?"正常" : "下架")
@Html.TextBox("name", "", new { id="name"})-------------------<input id="name" name="name" type="text" value="" />
//js加载下拉框数据
function selectload() {
$.ajax({
type: "get",
url: "/Admin/getselect",
dataType: "json",
success: function (obj) {
$("#Select2").empty();
for (var i = 0; i < obj.length; i++) {
$("#Select2").append("<option value='" + obj[i].RId + "'>" + obj[i].RName + "</option>")
}
}
})
}
function uupt(obj) {
var ids = $(obj).parent().parent().find('td');
$("#RAccountid").val(ids.eq(0).text()),
$("#RAccount").val(ids.eq(1).text());
}
---------------------------------------------------------------------------- 验证码---------------------------------------------------------------------------------
<img src="/ValidateCode.ashx " οnclick="this.src = '/ValidateCode.ashx?d='+new Date()" />
var RegCode = Request["RegCode"];
if (RegCode.ToUpper() != Session["checkCode"].ToString().ToUpper())
---------------------------------------------------------------------------- 随机数---------------------------------------------------------------------------------
var num = "";
for (var i = 0; i < 6; i++) {
num += Math.floor(Math.random() * 10);
}
---------------------------------------------------------------------------- 随机数---------------------------------------------------------------------------------
var num = "";
for (var i = 0; i < 6; i++) {
num += Math.floor(Math.random() * 10);
}
<td><input type="checkbox" name="checkid" value="@item.productid" class="b"></td>
//全选
function selectAll()
{
var checkAll = document.getElementById("all").checked;
var checkedid = document.getElementsByName("checkid");
for (var i in checkedid)
{
checkedid[i].checked = checkAll;
}
}
//批量删除--------------------------------------------------------------------------------------------------------------------------
function DelDate()
{
var id = "";
for (var i = 0; i < $('.b').length; i++) {
if ($('.b').eq(i).attr("checked") == "checked")
{
id += $('.b').eq(i).val() + ",";
}
}
if (id.length == 0)
{
alert("至少选一条数据");
return;
}
if (confirm('确认批量删除?')) {
$.ajax({
type: "post",
url: "/Index/DelSelect",
data: { id: id },
success: function (data) {
if (data == 1) {
alert("删除成功");
location.href = '/Index/Index';
}
else {
alert("删除失败");
}
}
})
}
}
// 批量--------------------------------------------------------------------------------------------------------------------------
[HttpPost]
public int DelSelect()
{
string result = Request["id"].Substring(0, Request["id"].Length - 1);
string[] reg = result.Split(',');
foreach (var item in reg)
{
if (bll.Del(Convert.ToInt32(item)) > 0)
{
continue;
}
else
{
return 0;
}
}
return 1;
}
//下拉--------------------------------------------------------------------------------------------------------------------------
视图传typeid ---- @Html.DropDownList("typeid")
public ActionResult selectctl()
{
ViewBag.typeid = new SelectList(bll.getSelect(), "typeid", "typename");
return View();
}
//分页--------------------------------------------------------------------------------------------------------------------------
@using Webdiyer.WebControls.Mvc;
@Html.Pager(Model, new PagerOptions { PageIndexParameterName = "PageIndex" })
public ActionResult Index( int PageIndex=1)
{
int PageSize = 6;
PagedList<ProductModel> list = bll.showPro().ToPagedList<ProductModel>(PageIndex, PageSize);
ViewBag.typeid = new SelectList(bll.getSelect(), "typeid", "typename");
return View(list);
}
// 三元
@Html.Raw(@item.sta==0?"正常" : "下架")
@Html.TextBox("name", "", new { id="name"})-------------------<input id="name" name="name" type="text" value="" />
//SQL 分页--------------------------------------------------------------------------------------------------------------------------
select top " + PageSize + " * from RoomModel where Roomid not in (select top ((" + Pageindex + "-1) *" + PageSize + ") Roomid from RoomModel)"
select top {0} * from ( SELECT ROW_NUMBER() OVER(ORDER BY studentid ) AS nid,* FROM student ) as temp where nid> {1}", pageSize, (pageIndex - 1) * pageSize);
//存储过程分页 ---------------------------------------------------------------------------------------------------------------------------------
public static DataTable GetTableByProPger(string ProName, int PageIndex, int PageSize, out int RowCount)
{
using (SqlConnection conn = new SqlConnection(Constring))
{
conn.Open();
SqlCommand cmd = new SqlCommand(ProName, conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter[] para ={
new SqlParameter("@PageIndex",DbType.Int32),
new SqlParameter("@PageSize",DbType.Int32),
new SqlParameter("@RowCount",DbType.Int32),
};
para[0].Value = PageIndex;
para[1].Value = PageSize;
para[2].Direction = ParameterDirection.Output;
cmd.Parameters.AddRange(para);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
RowCount = int.Parse(para[2].Value.ToString());
return dt;
}
}
//---------------------------------------------------------------------------------------------------------------------------------
public List<Email> email_list(int PageIndex, int PageSize, out int RowCount)
{
DataTable dt = DbHelper.GetTableByProPger(" ", PageIndex, PageSize, out RowCount);
List<Email> list = new List<Email>();
foreach (DataRow Row in dt.Rows)
{
list.Add(new Email{
Eid = Convert.ToInt32(Row["Eid"]),
Title = Row["Title"].ToString(),
});
}
return list;
}
//---------------------------------------------------------------------------------------------------------------------------------
int PageIndex = 1;
int PageSize = 10;
if (Request["PageIndex"] != null && int.TryParse(Request["PageIndex"], out PageIndex)){
}
else{
PageIndex = 1;
}
if (PageIndex < 1){
PageIndex = 1;
}
if (Session["PageCount"] != null && PageIndex > Convert.ToInt32(Session["PageCount"])) {
PageIndex = Convert.ToInt32(Session["PageCount"]);
}
int RowCount = 0;
List<Email> list = client.email_list(PageIndex, PageSize, out RowCount).ToList();
Session["PageIndex"] = PageIndex;
Session["PageCount"] = RowCount % PageSize == 0 ? RowCount / PageSize : (RowCount / PageSize) + 1;
---------------------------------------------------------------------------------------------------------------------------------
<a href="/Email_/InboxEmail?PageIndex=@(Convert.ToInt32(Session["PageIndex"])-1)">上一页</a>
@for (int i = 0; i < Convert.ToInt32(Session["PageCount"]); i++)
{
if ((i + 1) == Convert.ToInt32(Session["PageIndex"]))
{ <a href="/Email_/InboxEmail?PageIndex=@(i+1)" style="font-size:25px;color:red">@(i + 1)</a> }
else
{
<a href="/Email_/InboxEmail?PageIndex=@(i+1)">@(i + 1)</a>
@:
}
}
<a href="/Email_/InboxEmail?PageIndex= @Session["PageCount"]">尾页</a>
//---------------------------------------------------------------------------------------------------------------------------------
create procedure [dbo].[Sel_tb_Film]
@PageIndex int,
@PageSize int,
@RowCount int output
as
begin-------------------------------------------------------------------
select COUNT(*) from SMS_Model;
select top (@PageSize) * from SMS_Model where SMS_ID not in (select top ((@PageIndex-1) * @PageSize ) SMS_ID from SMS_Model )
end---------------------------------------------------------------------
exec Sel_tb_Film 1, 20,10
//--------------------------------------------------------------MODEL登陆----------------------------------------------------------------------------
public User_Model Login(User_Model MODEL)
{
return bll.Login(MODEL);
}
//-------------------------------------------------------------------------------------------------------------------
public User_Model Login(User_Model MODEL)
{
string sql = string.Format(" select * from User_Model where Email='{0}' and pwd='{1}'", MODEL.Email, MODEL.pwd);
User_Model U = new User_Model();
DataTable dt = DbHelper.GetTable(sql);
if (dt.Rows.Count <= 0 || dt == null)
{
return null;
}
else
{
//U.ID = Convert.ToInt32(dt.Rows[0]["ID"].ToString());
U.pwd = dt.Rows[0]["pwd"].ToString();
U.Email = dt.Rows[0]["Email"].ToString();
}
return U;
}
-------------------------------------------------------------------------------------------------------------------
public ActionResult Loginn(User_Model MODEL)
{
var pwd = Request["pwd"];
var name = Request["Email"];
User_Model m = client.Login(MODEL);
if (m != null)
{
Session["name"] = m.Email;
return Content("<script>alert('登陆成功');location.href='/Email_/Index'</script> ");
}
else
{
return Content("<script>alert('登陆失败');location.href='/Email_/Login'</script> ");
}
}
---------------------------------------------------------------------------- 万能分页---------------------------------------------------------------------------------
ALTER proc [dbo].[wanneng_pager]
@TableName varchar(100),
@FileID varchar(100),
@SqlWhere varchar(max),
@PageSize int,
@PageIndex int,
@RowCount int output
as
begin
declare @sql nvarchar(500)
set @sql = 'select top('+CONVERT(nvarchar(max),@PageSize)+') * from (select ROW_NUMBER() over(order by '+@FileID+') '+@FileID+'1 ,* from '+@TableName+' where 1=1 '+@SqlWhere+') as '+@TableName+'1 where '+@FileID+'1 > '+CONVERT(nvarchar(max),(@PageIndex - 1)*@PageSize)+';';
set @sql += 'select @Count = count(1) from '+@TableName+' where 1=1 '+@SqlWhere+';' ;
exec sp_executesql @sql,N'@Count int out',@RowCount out
end
---------------------------------------------------------------------------- 验证码---------------------------------------------------------------------------------
<img src="/ValidateCode.ashx " οnclick="this.src = '/ValidateCode.ashx?d='+new Date()" />
var RegCode = Request["RegCode"];
if (RegCode.ToUpper() != Session["checkCode"].ToString().ToUpper())
---------------------------------------------------------------------------- 随机数---------------------------------------------------------------------------------
var num = "";
for (var i = 0; i < 6; i++) {
num += Math.floor(Math.random() * 10);
}