📄 productalarm.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using MisStock.Components;
using SQLHelper;
namespace MisStock.DesktopModules.Product
{
/// <summary>
/// ProductAlarm 的摘要说明。
/// </summary>
public class ProductAlarm : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button ReturnBtn;
protected System.Web.UI.WebControls.Button LowerBtn;
protected System.Web.UI.WebControls.Button UpperBtn;
protected System.Web.UI.WebControls.DataGrid ProductList;
private void Page_Load(object sender, System.EventArgs e)
{
///判断用户是否登陆
if(Session["UserID"] == null)
{
Response.Redirect("~/Default.aspx");
}
///判断用户是否是超级管理员
if(Components.User.IsAuthorityAdmin(Session["UserID"].ToString()) >= Components.User.USERTYPENORMAL)
{
Response.Write("<script>alert(\"你没有权限,请与管理员联系!\")</script>");
Response.Write("<script>history.back();</script>");
}
if(!Page.IsPostBack)
{
///绑定控件的数据
BindProductData();
///设置按钮的可用性
LowerBtn.Enabled = UpperBtn.Enabled = ProductList.Items.Count <= 0 ? false : true;
}
}
private void BindProductData()
{
///定义获取数据的类
MisStock.Components.Product product = new MisStock.Components.Product();
SqlDataReader recp = product.GetProducts();
///创建DataSet数据源
DataTable dataTable = SystemTools.ConvertDataReaderToDataTable(recp);
DataSet dataSet = new DataSet("Product");
dataSet.Tables.Add(dataTable);
///设定控件的数据源
ProductList.DataSource = dataSet;
///绑定控件的数据
ProductList.DataBind();
}
public string FormatString(string oldString)
{
return(oldString.Length > 50 ? oldString.Substring(0,50) + "..." : oldString);
}
private void ProductAlarmBtn_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e)
{
///定义类
MisStock.Components.Product product = new MisStock.Components.Product();
try
{ ///获取每一行数据
foreach(DataGridItem item in ProductList.Items)
{ ///获取每一行的选择控件
CheckBox checkBtn = (CheckBox)item.FindControl("SelectProduct");
if(checkBtn != null)
{
if(checkBtn.Checked == true)
{
///设置商品数量的报警
product.UpdateProductAlarm(Int32.Parse(ProductList.DataKeys[item.ItemIndex].ToString()),
Int32.Parse(e.CommandArgument.ToString()));
}
}
}
///显示操作结果信息
Response.Write ("<script>window.alert('" + MisSystem.OPERATIONUPDATESUCCESSMESSAGE + "')</script>");
}
catch(Exception ex)
{
///显示修改操作中的失败、错误信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ MisSystem.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
///绑定控件的数据
BindProductData();
}
private void ReturnBtn_Click(object sender, System.EventArgs e)
{
///跳转到管理页面
Response.Redirect("~/DesktopModules/Product/ProductManage.aspx");
}
private void ProductList_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
///设置新的页码,并重新绑定数据
ProductList.CurrentPageIndex = e.NewPageIndex;
BindProductData();
///设置按钮的可用性
LowerBtn.Enabled = UpperBtn.Enabled = ProductList.Items.Count <= 0 ? false : true;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.LowerBtn.Command += new System.Web.UI.WebControls.CommandEventHandler(this.ProductAlarmBtn_Command);
this.UpperBtn.Command += new System.Web.UI.WebControls.CommandEventHandler(this.ProductAlarmBtn_Command);
this.ReturnBtn.Click += new System.EventHandler(this.ReturnBtn_Click);
this.ProductList.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.ProductList_PageIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -