GridView的用法
来源:互联网 发布:排序算法的稳定性 编辑:程序博客网 时间:2024/05/21 10:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>预警阀值设置</title>
<script type="text/javascript" src="../../JavaScript/validityDigit.js"></script>
<link rel="stylesheet" type="text/css" href="../../css/TotalStly.css">
<style type="text/css">
.wrap
{
width: 100%;
min-width: 900px;
_width: expression((document.documentElement.clientWidth||document.body.clientWidth)<900? "900px" : "" );
}
</style>
</head>
<body>
<form id="form1" runat="server">
<!-- <asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>-->
<div style="width:1000px;margin:0 auto;" class="wrap">
<div>
<table height="25" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#e5f1f4" style="border-bottom:2px solid #48BADB;">
<tr >
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
<td><div align="left" class="title">xxxxx</div></td>
</tr>
</table>
</div>
<div style="height:10px">
</div>
<div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="40">省公司</td>
<td width="130"><asp:DropDownList ID="txt_company" runat="server" AutoPostBack="True" OnSelectedIndexChanged="txt_company_SelectedIndexChanged" Width="120">
<asp:ListItem Value="1">--请选择省公司--</asp:ListItem>
</asp:DropDownList></td>
<td width="40">电 厂</td>
<td width="190"><asp:DropDownList ID="txt_plant" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="txt_plant_SelectedIndexChanged" Width="180px">
<asp:ListItem Value="1">--请选择电厂--</asp:ListItem>
</asp:DropDownList></td>
<td width="40">机 组</td>
<td width="130"><asp:DropDownList ID="txt_unit" runat="server" AutoPostBack="True"
Width="120" >
<asp:ListItem Value="-1">--请选择机组--</asp:ListItem>
</asp:DropDownList></td>
<td width="60">预警对象</td>
<td width="150"><asp:DropDownList ID="ddlBaoJing0" runat="server"
AutoPostBack="True" Width="140px"
onselectedindexchanged="ddlBaoJing0_SelectedIndexChanged">
<asp:ListItem>--请选择分类--</asp:ListItem>
<asp:ListItem>热耗率</asp:ListItem>
<asp:ListItem>供电煤耗</asp:ListItem>
<asp:ListItem>高压缸效率</asp:ListItem>
<asp:ListItem>低压缸效率</asp:ListItem>
<asp:ListItem>厂用电</asp:ListItem>
<asp:ListItem>锅炉效率</asp:ListItem>
<asp:ListItem>排烟温度</asp:ListItem>
<asp:ListItem>清洁系数</asp:ListItem>
<asp:ListItem>空预器漏风率A</asp:ListItem>
<asp:ListItem>空预器漏风率B</asp:ListItem>
<asp:ListItem>#1轴承转子振动</asp:ListItem>
<asp:ListItem>#2轴承转子振动</asp:ListItem>
<asp:ListItem>#3轴承转子振动</asp:ListItem>
<asp:ListItem>#4轴承转子振动</asp:ListItem>
<asp:ListItem>发电机转子振动(汽机端)</asp:ListItem>
<asp:ListItem>发电机转子振动(励磁端)</asp:ListItem>
<asp:ListItem>励磁机轴承转子振动</asp:ListItem>
<asp:ListItem>真空</asp:ListItem>
</asp:DropDownList></td>
<td><asp:Button ID="btn_query" Text="查询" runat="server" Width="60"
OnClick="btn_query_Click" style="height: 26px"/></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
<div style="padding:8px 0;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<asp:GridView ID="GridView" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="AlarmThresholdId" ForeColor="#333333"
onrowcancelingedit="GridView1_RowCancelingEdit1"
onrowdatabound="GridView1_RowDataBound1" onrowdeleting="GridView1_RowDeleting1"
onrowediting="GridView1_RowEditing1" onrowupdating="GridView1_RowUpdating1"
Width="80%">
<columns>
<asp:BoundField HeaderText="序号" >
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" Width="5%" />
</asp:BoundField>
<asp:TemplateField HeaderText="预警对象">
<ControlStyle Width="100px" />
<ItemTemplate>
<asp:Label ID="labPointDeScription" runat="server" Text='<%# Bind("PointDeScription") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlPointDeScription_f" runat="server" AutoPostBack="True"
Width="140px">
<asp:ListItem>热耗率</asp:ListItem>
<asp:ListItem>供电煤耗</asp:ListItem>
<asp:ListItem>高压缸效率</asp:ListItem>
<asp:ListItem>低压缸效率</asp:ListItem>
<asp:ListItem>厂用电</asp:ListItem>
<asp:ListItem>锅炉效率</asp:ListItem>
<asp:ListItem>排烟温度</asp:ListItem>
<asp:ListItem>清洁系数</asp:ListItem>
<asp:ListItem>空预器漏风率A</asp:ListItem>
<asp:ListItem>空预器漏风率B</asp:ListItem>
<asp:ListItem>#1轴承转子振动</asp:ListItem>
<asp:ListItem>#2轴承转子振动</asp:ListItem>
<asp:ListItem>#3轴承转子振动</asp:ListItem>
<asp:ListItem>#4轴承转子振动</asp:ListItem>
<asp:ListItem>发电机转子振动(汽机端)</asp:ListItem>
<asp:ListItem>发电机转子振动(励磁端)</asp:ListItem>
<asp:ListItem>励磁机轴承转子振动</asp:ListItem>
<asp:ListItem>真空</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="规则">
<itemtemplate>
<%# GetAlarmRule(Eval("AlarmRule").ToString())%>
</itemtemplate>
<edititemtemplate>
<asp:HiddenField ID="HDFSex" runat="server" Value='<%# Eval("AlarmRule") %>' />
<asp:DropDownList ID="DDLSex" runat="server" Width="90px" />
</edititemtemplate>
<itemstyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
<FooterTemplate>
<asp:HiddenField ID="HDFAlarmRule" runat="server" Value='<%# Eval("AlarmRule") %>' />
<asp:DropDownList ID="ddlAlarmRule_f" runat="server" Width="90px" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="阀值">
<itemtemplate>
<asp:Label ID="labAlarmValue" runat="server" Text='<%# Bind("AlarmValue") %>'></asp:Label>
</itemtemplate>
<edititemtemplate>
<asp:TextBox ID="txt_AlarmValue_e" runat="server" Text='<%# Bind("AlarmValue") %>' onKeyUp="value=value.replace(/[^\d|chun]/g,'')"></asp:TextBox>
</edititemtemplate>
<FooterTemplate>
<asp:TextBox ID="txt_AlarmValue_f" runat="server" onKeyUp="value=value.replace(/[^\d|chun]/g,'')"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="提示信息">
<ItemTemplate>
<asp:Label ID="labAlarmTip" runat="server" Text='<%# Bind("AlarmTip") %>'></asp:Label>
</ItemTemplate>
<edititemtemplate>
<asp:TextBox ID="txt_AlarmTip_e" runat="server" Text='<%# Bind("AlarmTip") %>'></asp:TextBox>
</edititemtemplate>
<FooterTemplate>
<asp:TextBox ID="txt_AlarmTip_f" runat="server" Width="80px"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="机组编号">
<ItemTemplate>
<%# GetName(Eval("UnitId").ToString())%>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" Text="添 加" />
<asp:Button ID="btnCancel" runat="server" OnClick="btnCancel_Click"
Text="取 消" />
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" HeaderText="编辑">
<itemstyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:CommandField>
<asp:CommandField ShowDeleteButton="True" HeaderText="删除">
<itemstyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:CommandField>
</columns>
<footerstyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<pagerstyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<headerstyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</td>
</tr>
<tr>
<td><div style="width:80%;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="65">
<asp:Button ID="bt_first" runat="server" Text="首页" Width="60" onclick="bt_first_Click"
/></td>
<td width="65">
<asp:Button ID="bt_up" runat="server" Text="上一页" Width="60" onclick="bt_up_Click"
/></td>
<td width="65">
<asp:Button ID="bt_next" runat="server" Text="下一页" Width="60" onclick="bt_next_Click"
/></td>
<td width="65">
<asp:Button ID="bt_last" runat="server" Text="尾页" Width="60" onclick="bt_last_Click1"
/></td>
<td width="85"><asp:TextBox ID="txtpage" runat="server" ReadOnly="True" Width="60px"></asp:TextBox></td>
<td><asp:Button ID="Btn_Add" runat="server" OnClick="Btn_Add_Click" Text="添加" Width="60" /></div></td>
</tr>
</table></td>
</tr>
</table>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
public partial class Page_ParameterImport_AlarmThresholdSet : System.Web.UI.Page
{
const int PageSize = 10;
private int PageCount/*总页数*/, RecCount/*总记录*/, CurrentPage/*当前页*/;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//绑定下拉框
bindCompany();
ViewState["CurrentPage"] = 0;
emptybin();
txtpage.Text = "0" + "/" + "0";
}
}
public String GetName(string x)
{
if (x != "")
{
CTS.Model.Unit model_unit = new CTS.Model.Unit();
CTS.BLL.Unit bll_unit = new CTS.BLL.Unit();
if (bll_unit.Exists(Convert.ToInt32(x)))
{
model_unit = bll_unit.GetModel(Convert.ToInt32(x));
String str_Unitname = model_unit.UnitName;
return str_Unitname;
}
}
return x;
}
public String GetAlarmRule(string x)
{
string str_AlarmRule="";
if (x=="0")
{
str_AlarmRule = "小于";
}
else if (x == "1")
{
str_AlarmRule = "大于";
}
else
{
str_AlarmRule = "";
}
return str_AlarmRule;
}
//查询绑定
public void initselect()
{
{
CTS.BLL.AlarmThreshold BLL_AlarmThreshold = new CTS.BLL.AlarmThreshold();
RecCount = BLL_AlarmThreshold.GetRecordCount(getSelect());
PageCount = RecCount / PageSize;
if (RecCount % PageSize != 0)
{
PageCount += 1;
}
ViewState["PageCount"] = PageCount;
ViewState["RecCount"] = RecCount;
CurrentPage = 1;
ViewState["CurrentPage"] = 1;
int start, end;
getRange(CurrentPage, out start, out end);
DataSet ds = BLL_AlarmThreshold.GetListByPage(getSelect(), "AlarmThresholdId", start, end);
if (BLL_AlarmThreshold.GetRecordCount(getSelect()) > 0)
{
GridView.DataSource = ds.Tables[0];
GridView.DataBind();
setPageTip();
}
else
{
emptybin();
ViewState["CurrentPage"] = 0;
setPageTip();
}
}
}
//绑定当前页
public void bindcurrent()
{
int CurrentPage = (int)ViewState["CurrentPage"];
int start, end;
getRange(CurrentPage, out start, out end);
CTS.BLL.AlarmThreshold BLL_AlarmThreshold = new CTS.BLL.AlarmThreshold();
DataSet ds = BLL_AlarmThreshold.GetListByPage(getSelect(), "AlarmThresholdId", start, end);
GridView.DataSource = ds.Tables[0];
GridView.DataBind();
setPageTip();
}
//添加时的绑定
public void addbind()
{
int CurrentPage = (int)ViewState["CurrentPage"];
CTS.BLL.AlarmThreshold BLL_AlarmThreshold = new CTS.BLL.AlarmThreshold();
RecCount = BLL_AlarmThreshold.GetRecordCount(getSelect());
PageCount = RecCount / PageSize;
if (RecCount % PageSize != 0)
{
PageCount += 1;
}
ViewState["PageCount"] = PageCount;
ViewState["CurrentPage"] = CurrentPage;
int start, end;
getRange(CurrentPage, out start, out end);
DataSet ds = BLL_AlarmThreshold.GetListByPage(getSelect(), "AlarmThresholdId", start, end);
GridView.DataSource = ds.Tables[0];
GridView.DataBind();
setPageTip();
}
//绑定公司
protected void bindCompany()
{
txt_company.Items.Clear();
CTS.BLL.View_unitinfo_company com = new CTS.BLL.View_unitinfo_company();
DataSet ds = com.GetAllList();
ListItem firstItem = new ListItem();
firstItem.Text = "--请选择省公司--";
firstItem.Value = "-1";
txt_company.Items.Add(firstItem);
foreach (DataRow dr in ds.Tables[0].Rows)
{
ListItem li = new ListItem();
li.Text = dr["companyname"].ToString();
li.Value = dr["navigationId"].ToString();
txt_company.Items.Add(li);
}
}
//绑定电厂
protected void txt_company_SelectedIndexChanged(object sender, EventArgs e)
{
txt_plant.Items.Clear();
txt_unit.Items.Clear();
int id = Convert.ToInt32(txt_company.SelectedValue);
CTS.BLL.View_unitinfo_plant plant = new CTS.BLL.View_unitinfo_plant();
List<CTS.Model.View_unitinfo_plant> models = plant.GetModelList("pid=" + id.ToString());
ListItem firstItem = new ListItem();
firstItem.Text = "--请选择电厂--";
firstItem.Value = "-1";
txt_plant.Items.Add(firstItem);
foreach (CTS.Model.View_unitinfo_plant pl in models)
{
ListItem li = new ListItem();
li.Text = pl.navigationName;
li.Value = pl.navigationId.ToString();
txt_plant.Items.Add(li);
}
}
//电厂和机组的关联绑定机组
protected void txt_plant_SelectedIndexChanged(object sender, EventArgs e)
{
txt_unit.Items.Clear();
ListItem firstItem = new ListItem();
firstItem.Text = "--请选择机组--";
firstItem.Value = "-1";
txt_unit.Items.Add(firstItem);
int id = Convert.ToInt32(txt_plant.SelectedValue);
CTS.BLL.Unit unit = new CTS.BLL.Unit();
List<CTS.Model.Unit> models = unit.GetModelList("NavigationId=" + id.ToString());
foreach (CTS.Model.Unit pl in models)
{
ListItem li = new ListItem();
li.Text = pl.UnitName;
li.Value = pl.UnitId.ToString();
txt_unit.Items.Add(li);
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//编辑是的下拉框
DropDownList ddlSex = (DropDownList)e.Row.FindControl("DDLSex");
ddlSex.Items.Clear();
ddlSex.Items.Add(new ListItem("大于","1"));
ddlSex.Items.Add(new ListItem("小于", "0"));
//DropDownList初始被选择的项
ddlSex.SelectedValue = ((HiddenField)e.Row.FindControl("HDFSex")).Value;
}
}
protected void GridView1_RowEditing1(object sender, GridViewEditEventArgs e)
{
GridView.EditIndex = e.NewEditIndex;
//绑定当前页
bindcurrent();
}
//编辑保存到数据库中
protected void GridView1_RowUpdating1(object sender, GridViewUpdateEventArgs e)
{
//主键ID
string ID = GridView.DataKeys[e.RowIndex].Value.ToString();
CTS.BLL.AlarmThreshold BLL_AlarmThreshold = new CTS.BLL.AlarmThreshold();
CTS.Model.AlarmThreshold model_AlarmThreshold = BLL_AlarmThreshold.GetModel(Convert.ToInt32(ID));
//预警ID
model_AlarmThreshold.AlarmThresholdId = Convert.ToInt32(ID);
//预警规则
string str_AlarmRule = ((DropDownList)GridView.Rows[e.RowIndex].FindControl("DDLSex")).SelectedValue;
model_AlarmThreshold.AlarmRule = Convert.ToInt32(str_AlarmRule);
//阀值
string str_AlarmValue = ((TextBox)(GridView.Rows[e.RowIndex].FindControl("txt_AlarmValue_e"))).Text.ToString().Trim();
if (str_AlarmValue != "")
{
model_AlarmThreshold.AlarmValue = Convert.ToInt32(str_AlarmValue);
}
else
{
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "alert", "alert('阀值不能为空请输入阀值');", true);
}
//提示信息
model_AlarmThreshold.AlarmTip = ((TextBox)(GridView.Rows[e.RowIndex].FindControl("txt_AlarmTip_e"))).Text.ToString().Trim();
string str_UnitId = txt_unit.SelectedValue;
model_AlarmThreshold.UnitId = Convert.ToInt32(str_UnitId);
if(ID!="")
{
BLL_AlarmThreshold.Update(model_AlarmThreshold);
}
GridView.EditIndex = -1;
//绑定当前页
bindcurrent();
}
//取消
protected void GridView1_RowCancelingEdit1(object sender, GridViewCancelEditEventArgs e)
{
GridView.EditIndex = -1;
bindcurrent();
}
//绑定列
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex != -1)
{
int indexID = this.GridView.PageIndex * this.GridView.PageSize + e.Row.RowIndex + 1;
e.Row.Cells[0].Text = indexID.ToString();
}
if (((DropDownList)e.Row.FindControl("DDLSex")) != null)
{
DropDownList ddlSex = (DropDownList)e.Row.FindControl("DDLSex");
ddlSex.Items.Clear();
ddlSex.Items.Add(new ListItem("大于", "1"));
ddlSex.Items.Add(new ListItem("小于", "0"));
ddlSex.SelectedValue = ((HiddenField)e.Row.FindControl("HDFSex")).Value;
}
if (((DropDownList)e.Row.FindControl("ddlAlarmRule_f")) != null)
{
DropDownList AlarmRule = (DropDownList)e.Row.FindControl("ddlAlarmRule_f");
AlarmRule.Items.Clear();
AlarmRule.Items.Add(new ListItem("大于", "1"));
AlarmRule.Items.Add(new ListItem("小于", "0"));
AlarmRule.SelectedValue = ((HiddenField)e.Row.FindControl("HDFAlarmRule")).Value;
}
}
//删除
protected void GridView1_RowDeleting1(object sender, GridViewDeleteEventArgs e)
{
string ID = GridView.DataKeys[e.RowIndex].Value.ToString();
CTS.BLL.AlarmThreshold BLL_AlarmThreshold = new CTS.BLL.AlarmThreshold();
if (ID!="")
{
BLL_AlarmThreshold.Delete(Convert.ToInt32(ID));
}
int CurrentPage = (int)ViewState["CurrentPage"];
RecCount = BLL_AlarmThreshold.GetRecordCount(getSelect());
if (RecCount == 0)
{
emptybin();
txtpage.Text = "0" + "/" + "0";
}
else
{
PageCount = RecCount / PageSize;
if (RecCount % PageSize != 0)
{
PageCount += 1;
}
if (PageCount < CurrentPage)
{
CurrentPage = CurrentPage - 1;
ViewState["PageCount"] = PageCount;
ViewState["CurrentPage"] = CurrentPage;
int start, end;
getRange(CurrentPage, out start, out end);
DataSet ds = BLL_AlarmThreshold.GetListByPage(getSelect(), "AlarmThresholdId", start, end);
GridView.DataSource = ds.Tables[0];
GridView.DataBind();
setPageTip();
}
else
{
ViewState["PageCount"] = PageCount;
bindcurrent();
}
}
}
//显示添加
protected void Btn_Add_Click(object sender, EventArgs e)
{
if (txt_unit.SelectedValue != "-1" && txt_unit.Text != "")
{
GridView.ShowFooter = true;
CTS.BLL.AlarmThreshold BLL_AlarmThreshold = new CTS.BLL.AlarmThreshold();
RecCount = BLL_AlarmThreshold.GetRecordCount(getSelect());
if (RecCount == 0)
{
initselect();
}
else
{
if ((int)ViewState["CurrentPage"]==0)
{
initselect();
}
else
{
bindcurrent();
}
}
}
else
{
if (txt_company.SelectedValue == "-1" || txt_company.Text == "")
{
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "alert", "alert('请选择公司');", true);
return;
}
else if (txt_plant.SelectedValue == "-1" || txt_plant.Text == "")
{
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "alert", "alert('请选择电厂');", true);
return;
}
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "alert", "alert('请选择机组');", true);
}
}
//空表
protected void emptybin()
{
DataTable dt = new DataTable();
dt.Columns.Add("PointDeScription", System.Type.GetType("System.String"));
dt.Columns.Add("AlarmRule", System.Type.GetType("System.String"));
dt.Columns.Add("AlarmValue", System.Type.GetType("System.String"));
dt.Columns.Add("AlarmTip", System.Type.GetType("System.String"));
dt.Columns.Add("UnitId", System.Type.GetType("System.String"));
dt.Columns.Add("AlarmThresholdId", System.Type.GetType("System.String"));
DataRow dr = dt.NewRow();
dr["PointDeScription"] = "";
dr["AlarmRule"] = "";
dr["AlarmValue"] = "";
dr["AlarmTip"] = "";
dr["UnitId"] = "";
dr["AlarmThresholdId"] = "";
dt.Rows.Add(dr);
GridView.DataSource = dt;
GridView.DataBind();
GridView.Rows[0].Cells[6].Font.Underline = true;
GridView.Rows[0].Cells[7].Font.Underline = true;
GridView.Rows[0].Cells[6].Text = "编辑";
GridView.Rows[0].Cells[7].Text = "删除";
}
//查询
protected void btn_query_Click(object sender, EventArgs e)
{
GridView.ShowFooter = false;
if (txt_unit.SelectedValue != "-1" && txt_unit.Text != "")
{
initselect();
}
else
{
emptybin();
txtpage.Text = "0" + "/" + "0";
if (txt_company.SelectedValue == "-1" || txt_company.Text == "")
{
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "alert", "alert('请选择公司');", true);
return;
}
else if (txt_plant.SelectedValue == "-1" || txt_plant.Text == "")
{
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "alert", "alert('请选择电厂');", true);
return;
}
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "alert", "alert('请选择机组');", true);
}
}
//查询条件
private string getSelect()
{
string strSql = "";
//时间
if (txt_unit.SelectedValue != "-1")
{
string strID = "UnitId=" + txt_unit.SelectedValue;
if (ddlBaoJing0.SelectedValue != "--请选择分类--")
{
strSql = "PointDeScription='" + ddlBaoJing0.SelectedValue + "'";
strSql = strSql + " and " + strID;
}
else
{
strSql = strID;
}
}
return strSql;
}
//编辑状态时的下拉框改变从新绑定
protected void List_Alarm_SelectedIndexChanged1(object sender, EventArgs e)
{
//
bindcurrent();
}
//添加记录
protected void btnAdd_Click(object sender, EventArgs e)
{
CTS.BLL.AlarmThreshold BLL_AlarmThreshold = new CTS.BLL.AlarmThreshold();
CTS.Model.AlarmThreshold model_AlarmThreshold = new CTS.Model.AlarmThreshold();
DropDownList DDLPointDeScription = GridView.FooterRow.FindControl("ddlPointDeScription_f") as DropDownList;
DropDownList DDLAlarmRule = GridView.FooterRow.FindControl("ddlAlarmRule_f") as DropDownList;
TextBox txtAlarmValue = GridView.FooterRow.FindControl("txt_AlarmValue_f") as TextBox;
TextBox txtAlarmTip = GridView.FooterRow.FindControl("txt_AlarmTip_f") as TextBox;
model_AlarmThreshold.PointDeScription = DDLPointDeScription.SelectedItem.Text;
model_AlarmThreshold.AlarmRule = Convert.ToInt32(DDLAlarmRule.SelectedValue);
if (txtAlarmValue.Text == "")
{
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "alert", "alert('阀值不能为空请输入阀值');", true);
return;
}
else
{
model_AlarmThreshold.AlarmValue = Convert.ToInt32(txtAlarmValue.Text);
}
model_AlarmThreshold.AlarmTip = txtAlarmTip.Text;
model_AlarmThreshold.UnitId =Convert.ToInt32(txt_unit.SelectedValue);
string strsql = "";
string str_PointDeScription = "PointDeScription='" + DDLPointDeScription.SelectedItem.Text + "'";
strsql = str_PointDeScription;
string str_AlarmRule = "AlarmRule=" + Convert.ToInt32(DDLAlarmRule.SelectedValue);
strsql = strsql + " and " + str_AlarmRule;
if (txtAlarmValue.Text!="")
{
string str_AlarmValue = "AlarmValue=" + Convert.ToInt32(txtAlarmValue.Text);
strsql = strsql + " and " + str_AlarmValue;
}
string str_UnitId = "UnitId=" + Convert.ToInt32(txt_unit.SelectedValue);
strsql = strsql + " and " + str_UnitId;
int count=BLL_AlarmThreshold.GetModelList(strsql).Count;
if (count==0)
{
BLL_AlarmThreshold.Add(model_AlarmThreshold);
}
else
{
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "alert", "alert('已经有相同功能数据');", true);
}
GridView.ShowFooter = false;
RecCount = BLL_AlarmThreshold.GetRecordCount(getSelect());
if (RecCount==1)
{
initselect();
}
else
{
addbind();
}
}
//取消
protected void btnCancel_Click(object sender, EventArgs e)
{
GridView.ShowFooter = false;
CTS.BLL.AlarmThreshold BLL_AlarmThreshold = new CTS.BLL.AlarmThreshold();
RecCount = BLL_AlarmThreshold.GetRecordCount(getSelect());
if (RecCount == 0)
{
initselect();
}
else
{
bindcurrent();
}
}
//当前页页数/总页数
private void setPageTip()
{
txtpage.Text = ViewState["CurrentPage"] + "/" + ViewState["PageCount"];
}
//分页中的start,end
private void getRange(int curpage, out int start, out int end)
{
start = PageSize * (curpage - 1) + 1;
end = curpage * PageSize;
}
protected void bt_first_Click(object sender, EventArgs e)
{
if (txt_unit.SelectedValue != "-1" && txt_unit.Text != "")
{
initselect();
}
}
protected void bt_up_Click(object sender, EventArgs e)
{
if (txt_unit.SelectedValue != "-1" && txt_unit.Text != "")
{
int CurrentPage = (int)ViewState["CurrentPage"];
CurrentPage = CurrentPage - 1;
if (CurrentPage < 1)
{
///
}
else
{
ViewState["CurrentPage"] = CurrentPage;
int start, end;
getRange(CurrentPage, out start, out end);
CTS.BLL.AlarmThreshold BLL_AlarmThreshold = new CTS.BLL.AlarmThreshold();
DataSet ds = BLL_AlarmThreshold.GetListByPage(getSelect(), "AlarmThresholdId", start, end);
GridView.DataSource = ds.Tables[0];
GridView.DataBind();
setPageTip();
}
}
}
protected void bt_next_Click(object sender, EventArgs e)
{
if (txt_unit.SelectedValue != "-1" && txt_unit.Text != "")
{
int CurrentPage = (int)ViewState["CurrentPage"];
CurrentPage = CurrentPage + 1;
if (CurrentPage > (int)ViewState["PageCount"])
{
///
}
else
{
ViewState["CurrentPage"] = CurrentPage;
CurrentPage = (int)ViewState["CurrentPage"];
int start, end;
getRange(CurrentPage, out start, out end);
CTS.BLL.AlarmThreshold BLL_AlarmThreshold = new CTS.BLL.AlarmThreshold();
DataSet ds = BLL_AlarmThreshold.GetListByPage(getSelect(), "AlarmThresholdId", start, end);
GridView.DataSource = ds.Tables[0];
GridView.DataBind();
setPageTip();
}
}
}
protected void bt_last_Click1(object sender, EventArgs e)
{
if (txt_unit.SelectedValue != "-1" && txt_unit.Text != "")
{
CurrentPage = (int)ViewState["PageCount"];
if (CurrentPage < 1)
{
}
else
{
ViewState["CurrentPage"] = CurrentPage;
int start, end;
getRange(CurrentPage, out start, out end);
CTS.BLL.AlarmThreshold BLL_AlarmThreshold = new CTS.BLL.AlarmThreshold();
DataSet ds = BLL_AlarmThreshold.GetListByPage(getSelect(), "AlarmThresholdId", start, end);
GridView.DataSource = ds.Tables[0];
GridView.DataBind();
setPageTip();
}
}
}
protected void ddlBaoJing0_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
- GRIDVIEW 控件的用法
- GridView的用法
- gridview的用法
- GridView的用法详解
- GridView的RowDataBound用法
- 关于gridview的用法
- GridView的编辑用法
- Gridview的基本用法
- GridView 的用法
- GridView的用法
- GridView的各种用法
- GridView的简单用法
- GridView的用法
- GridView的简单用法
- GridView的用法
- GridView的用法
- android gridview的用法
- GridView的基本用法
- 【转】C#获取网页源代码
- 布局中使用include技巧
- 错误 "Unable to find manifest signing certificate in the certificat"
- 类方法(class method)和实例方法(instance method)
- Spring定时器配置(修订版)
- GridView的用法
- asp conn.asp
- CMenu
- poj 2516 Minimum Cost
- __attribute__ ((packed))
- Perl: Perl/CGI脚本语言编程学习资料及开发工具下载大全 (2013-3-9更新)
- javascript 按回车键相应按钮提交事件
- Hibernate从入门到精通(三)Hibernate配置文件 .
- myodbc设置字符集