<%@ Page language="c#" Codebehind="qryPlant.aspx.cs" AutoEventWireup="false" Inherits="CQS.QueryDialog.qryPlant" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>select plant</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<LINK href="../CSS/style2.css" type="text/css" rel="stylesheet">
<LINK href="../CSS/style1.css" type="text/css" rel="stylesheet">
<script language="javascript">
var bgColorNotSelect = '#ffffff';
var bgColorSelected = '#fceade';
var selectedLine = null;
function SelectLine(trID)
{
if (document.getElementById(trID) !=null)
{
if (selectedLine==trID)
{
document.getElementById(trID).style.backgroundColor = bgColorNotSelect;
} else {
if (selectedLine !=null){
document.getElementById(selectedLine).style.background = bgColorNotSelect;
}
document.getElementById(trID).style.backgroundColor = bgColorSelected;
}
}
selectedLine=trID;
}
function CancelBtn_OnClick()
{
window.returnValue = null;
window.opener = null;
window.close();
}
function OkBtn_OnClick(strResult)
{
var ret = "";
var obj = document.getElementById(strResult);
var num = 0;
/*for(var i=0;i<obj.options.length;i++)
{
if(obj.options[i].selected)
{
num += 1;
ret = obj.options[i].value;
}
}*/
if (selectedLine != null)
{
num += 1;
ret = selectedLine.substring(selectedLine.indexOf('_')+1,selectedLine.length);
}
if(num <=0 )
{
alert("Please select a plant!");
}
else if(num >1)
{
alert("Only one plant can be selected!");
}
else
{
window.returnValue = ret;
window.opener = null;
window.close();
}
}
</script>
<base target="_self">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<div id="importDiv" style="Z-INDEX: 101; POSITION: absolute">
<TABLE class="DBgrid" id="Table1" style="WIDTH: 100%; HEIGHT: 400px" cellSpacing="1" cellPadding="1">
<tr>
<td colspan="10" valign="top" style="HEIGHT: 1px">
<table class="DBgrid" id="TableTop" style="WIDTH: 100%" cellpadding="1" cellspacing="1">
<tr>
<td width="12%" nowrap><asp:Label ID="lblPlant" Runat="server" text="Cost Element:">Plant:</asp:Label></td>
<td width="32%" nowrap>
<asp:textbox ID="tbPlant" Runat="server" ToolTip="support blurred search"></asp:textbox>
</td>
<td width="12%" nowrap><asp:Label ID="lblName" Runat="server" text="Name:">Name:</asp:Label></td>
<td nowrap colspan="3">
<asp:textbox ID="tbName" Runat="server" ToolTip="support blurred search"></asp:textbox>
</td>
</tr>
<tr>
<td nowrap><asp:Label ID="lblCompany" Runat="server" text="Cost Element:">Company Code:</asp:Label></td>
<td nowrap>
<asp:textbox ID="tbCompany" Runat="server" ToolTip="support blurred search"></asp:textbox>
</td>
<td nowrap><asp:Label ID="lblLocation" Runat="server" text="Cost Element:">Location:</asp:Label></td>
<td width="23%" nowrap><asp:textbox ID="tbLocation" Runat="server" ToolTip="support blurred search"></asp:textbox></td>
<td width="21%"><asp:button id="btnQuery" CssClass="search2" Runat="server" Text="Query"></asp:button></td>
</tr>
</table>
</td>
</tr>
<tr>
<td vAlign="top" align="left" width="90%">
<table class="DBgrid" id="Tableleft" style="WIDTH: 100%" cellSpacing="1" cellPadding="1">
<tr>
<td><asp:label id="lblResult" text="Total:0" Runat="server" ForeColor="red"></asp:label></td>
</tr>
<tr>
<td><asp:datagrid id="DataGrid1" runat="server" ItemStyle-Font-Name="Arial" ItemStyle-Font-Size="9pt"
HeaderStyle-Font-Name="Arial" HeaderStyle-Font-Size="10pt" width="100%" BorderWidth="1px"
BorderColor="#dddddd">
<AlternatingItemStyle CssClass="ais_1"></AlternatingItemStyle>
<ItemStyle Font-Size="9pt" Font-Names="Arial" CssClass="is_1"></ItemStyle>
<HeaderStyle Font-Size="10pt" Font-Names="Arial" CssClass="hs_1"></HeaderStyle>
</asp:datagrid></td>
</tr>
</table>
</td>
<td width="10%" valign="top" align="right">
<table class="DBgrid" id="Tableright" style="WIDTH: 100%" cellpadding="1" cellspacing="1">
<tr>
<td style="HEIGHT: 38px"><INPUT class=btnC_mouseout onmouseover="this.className='btnC_mouseover'" onmouseout="this.className='btnC_mouseout'" onmousedown="this.className='btnC_mousedown'" onmouseup="this.className='btnC_mouseup'"
id="BtnOK" style="WIDTH: 80px" type="button" value="OK" runat="server"
NAME="BtnOK"></td>
</tr>
<tr>
<td><INPUT class=btnC_mouseout onmouseover="this.className='btnC_mouseover'" onmouseout="this.className='btnC_mouseout'" onmousedown="this.className='btnC_mousedown'" onmouseup="this.className='btnC_mouseup'"
style="WIDTH: 80px" onclick="CancelBtn_OnClick();" type="button" value="Cancel"></td>
</tr>
</table>
</td>
</tr>
</TABLE>
</div>
</form>
</body>
</HTML>
.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;
namespace CQS.QueryDialog
{
/// <summary>
/// qryPlant 的摘要描述。
/// </summary>
public class qryPlant: PageCommon
{
protected System.Web.UI.WebControls.Button btnQuery;
protected System.Web.UI.WebControls.Label lblPlant;
protected System.Web.UI.WebControls.TextBox tbPlant;
protected System.Web.UI.WebControls.Label lblCompany;
protected System.Web.UI.WebControls.TextBox tbCompany;
protected System.Web.UI.WebControls.Label lblLocation;
protected System.Web.UI.WebControls.TextBox tbLocation;
protected System.Web.UI.WebControls.ListBox lbResult;
protected System.Web.UI.WebControls.Label lblResult;
protected System.Web.UI.WebControls.Label lblName;
protected System.Web.UI.WebControls.TextBox tbName;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.HtmlControls.HtmlInputButton BtnOK;
#region Web Form 設計工具產生的程式碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 此為 ASP.NET Web Form 設計工具所需的呼叫。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
/// 這個方法的內容。
/// </summary>
private void InitializeComponent()
{
this.btnQuery.Click += new System.EventHandler(this.btnQuery_Click);
this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
CommClass.PubFunction func= new CommClass.PubFunction();
private void Page_Load(object sender, System.EventArgs e) {
//登陸頁面時進行身份驗證和權限檢驗
//Page_login("../");
if (!IsPostBack){
this.BtnOK.Attributes.Add("onclick", "return OkBtn_OnClick('lbResult');");
}
}
private void btnQuery_Click(object sender, System.EventArgs e) {
string s1,s2,s3,s4,cond="";
if (tbPlant.Text.Trim() !=""){
s1=" Plant like '%"+ tbPlant.Text.Trim() +"%' ";
} else {
s1=" 1=1 ";
}
if (tbCompany.Text.Trim() !=""){
s2=" CompanyCode like '%"+ tbCompany.Text.Trim() +"%' ";
} else {
s2=" 1=1 ";
}
if (tbLocation.Text.Trim() !=""){
s3=" Location like '%"+ tbLocation.Text.Trim() +"%' ";
} else {
s3=" 1=1 ";
}
if (tbName.Text.Trim() !=""){
s4=" Name like '%"+ tbName.Text.Trim() +"%' ";
} else {
s4=" 1=1 ";
}
cond=s1 + " and " + s2 + " and "+ s3 + " and "+ s4;
DataSet ds;
if(Request["F_SysCode"]!=null)
{
if(Request["F_SysCode"].ToString().Substring(0,6)=="010030")
ds=func.GetDataTable("select plant, name, companycode, location from pubPlant where Active ='A' and "+ cond);
else
ds=func.GetDataTable("select plant, name, companycode, location from pubPlant where Active ='A' and "+ cond +
func.GetPlantStr(Session["uID"].ToString(),"Plant",Request["state"]==null?"view":Request["state"].ToString()==""?"view":Request["state"].ToString())+" order by plant");
}
else
{
ds=func.GetDataTable("select plant, name, companycode, location from pubPlant where Active ='A' and "+ cond +
func.GetPlantStr(Session["uID"].ToString(),"Plant",Request["state"]==null?"view":Request["state"].ToString()==""?"view":Request["state"].ToString())+" order by plant");
}
DataGrid1.DataSource=ds.Tables[0];
DataGrid1.DataBind();
lblResult.Text="Total:"+ DataGrid1.Items.Count.ToString();
if (DataGrid1.Items.Count ==0){
func.AlertMsg("Can not found anything!");
}
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {
LinkButton DelButton= new LinkButton();
if(e.Item.ItemType==ListItemType.AlternatingItem || (e.Item.ItemType==ListItemType.Item)) {
e.Item.Attributes.Add("onMouseover", "this.bgColor='#eeeeee'");
e.Item.Attributes.Add("onmouseout", "this.bgColor='white'");
e.Item.Attributes.Add("ID","dg_"+e.Item.Cells[0].Text);
e.Item.Attributes.Add("onclick","SelectLine('dg_"+e.Item.Cells[0].Text +"')");
e.Item.Attributes.Add("ondblclick","return OkBtn_OnClick('lbResult');");
e.Item.Attributes.Add("style","cursor:hand");
}
}
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>select plant</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<LINK href="../CSS/style2.css" type="text/css" rel="stylesheet">
<LINK href="../CSS/style1.css" type="text/css" rel="stylesheet">
<script language="javascript">
var bgColorNotSelect = '#ffffff';
var bgColorSelected = '#fceade';
var selectedLine = null;
function SelectLine(trID)
{
if (document.getElementById(trID) !=null)
{
if (selectedLine==trID)
{
document.getElementById(trID).style.backgroundColor = bgColorNotSelect;
} else {
if (selectedLine !=null){
document.getElementById(selectedLine).style.background = bgColorNotSelect;
}
document.getElementById(trID).style.backgroundColor = bgColorSelected;
}
}
selectedLine=trID;
}
function CancelBtn_OnClick()
{
window.returnValue = null;
window.opener = null;
window.close();
}
function OkBtn_OnClick(strResult)
{
var ret = "";
var obj = document.getElementById(strResult);
var num = 0;
/*for(var i=0;i<obj.options.length;i++)
{
if(obj.options[i].selected)
{
num += 1;
ret = obj.options[i].value;
}
}*/
if (selectedLine != null)
{
num += 1;
ret = selectedLine.substring(selectedLine.indexOf('_')+1,selectedLine.length);
}
if(num <=0 )
{
alert("Please select a plant!");
}
else if(num >1)
{
alert("Only one plant can be selected!");
}
else
{
window.returnValue = ret;
window.opener = null;
window.close();
}
}
</script>
<base target="_self">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<div id="importDiv" style="Z-INDEX: 101; POSITION: absolute">
<TABLE class="DBgrid" id="Table1" style="WIDTH: 100%; HEIGHT: 400px" cellSpacing="1" cellPadding="1">
<tr>
<td colspan="10" valign="top" style="HEIGHT: 1px">
<table class="DBgrid" id="TableTop" style="WIDTH: 100%" cellpadding="1" cellspacing="1">
<tr>
<td width="12%" nowrap><asp:Label ID="lblPlant" Runat="server" text="Cost Element:">Plant:</asp:Label></td>
<td width="32%" nowrap>
<asp:textbox ID="tbPlant" Runat="server" ToolTip="support blurred search"></asp:textbox>
</td>
<td width="12%" nowrap><asp:Label ID="lblName" Runat="server" text="Name:">Name:</asp:Label></td>
<td nowrap colspan="3">
<asp:textbox ID="tbName" Runat="server" ToolTip="support blurred search"></asp:textbox>
</td>
</tr>
<tr>
<td nowrap><asp:Label ID="lblCompany" Runat="server" text="Cost Element:">Company Code:</asp:Label></td>
<td nowrap>
<asp:textbox ID="tbCompany" Runat="server" ToolTip="support blurred search"></asp:textbox>
</td>
<td nowrap><asp:Label ID="lblLocation" Runat="server" text="Cost Element:">Location:</asp:Label></td>
<td width="23%" nowrap><asp:textbox ID="tbLocation" Runat="server" ToolTip="support blurred search"></asp:textbox></td>
<td width="21%"><asp:button id="btnQuery" CssClass="search2" Runat="server" Text="Query"></asp:button></td>
</tr>
</table>
</td>
</tr>
<tr>
<td vAlign="top" align="left" width="90%">
<table class="DBgrid" id="Tableleft" style="WIDTH: 100%" cellSpacing="1" cellPadding="1">
<tr>
<td><asp:label id="lblResult" text="Total:0" Runat="server" ForeColor="red"></asp:label></td>
</tr>
<tr>
<td><asp:datagrid id="DataGrid1" runat="server" ItemStyle-Font-Name="Arial" ItemStyle-Font-Size="9pt"
HeaderStyle-Font-Name="Arial" HeaderStyle-Font-Size="10pt" width="100%" BorderWidth="1px"
BorderColor="#dddddd">
<AlternatingItemStyle CssClass="ais_1"></AlternatingItemStyle>
<ItemStyle Font-Size="9pt" Font-Names="Arial" CssClass="is_1"></ItemStyle>
<HeaderStyle Font-Size="10pt" Font-Names="Arial" CssClass="hs_1"></HeaderStyle>
</asp:datagrid></td>
</tr>
</table>
</td>
<td width="10%" valign="top" align="right">
<table class="DBgrid" id="Tableright" style="WIDTH: 100%" cellpadding="1" cellspacing="1">
<tr>
<td style="HEIGHT: 38px"><INPUT class=btnC_mouseout onmouseover="this.className='btnC_mouseover'" onmouseout="this.className='btnC_mouseout'" onmousedown="this.className='btnC_mousedown'" onmouseup="this.className='btnC_mouseup'"
id="BtnOK" style="WIDTH: 80px" type="button" value="OK" runat="server"
NAME="BtnOK"></td>
</tr>
<tr>
<td><INPUT class=btnC_mouseout onmouseover="this.className='btnC_mouseover'" onmouseout="this.className='btnC_mouseout'" onmousedown="this.className='btnC_mousedown'" onmouseup="this.className='btnC_mouseup'"
style="WIDTH: 80px" onclick="CancelBtn_OnClick();" type="button" value="Cancel"></td>
</tr>
</table>
</td>
</tr>
</TABLE>
</div>
</form>
</body>
</HTML>
.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;
namespace CQS.QueryDialog
{
/// <summary>
/// qryPlant 的摘要描述。
/// </summary>
public class qryPlant: PageCommon
{
protected System.Web.UI.WebControls.Button btnQuery;
protected System.Web.UI.WebControls.Label lblPlant;
protected System.Web.UI.WebControls.TextBox tbPlant;
protected System.Web.UI.WebControls.Label lblCompany;
protected System.Web.UI.WebControls.TextBox tbCompany;
protected System.Web.UI.WebControls.Label lblLocation;
protected System.Web.UI.WebControls.TextBox tbLocation;
protected System.Web.UI.WebControls.ListBox lbResult;
protected System.Web.UI.WebControls.Label lblResult;
protected System.Web.UI.WebControls.Label lblName;
protected System.Web.UI.WebControls.TextBox tbName;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.HtmlControls.HtmlInputButton BtnOK;
#region Web Form 設計工具產生的程式碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 此為 ASP.NET Web Form 設計工具所需的呼叫。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
/// 這個方法的內容。
/// </summary>
private void InitializeComponent()
{
this.btnQuery.Click += new System.EventHandler(this.btnQuery_Click);
this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
CommClass.PubFunction func= new CommClass.PubFunction();
private void Page_Load(object sender, System.EventArgs e) {
//登陸頁面時進行身份驗證和權限檢驗
//Page_login("../");
if (!IsPostBack){
this.BtnOK.Attributes.Add("onclick", "return OkBtn_OnClick('lbResult');");
}
}
private void btnQuery_Click(object sender, System.EventArgs e) {
string s1,s2,s3,s4,cond="";
if (tbPlant.Text.Trim() !=""){
s1=" Plant like '%"+ tbPlant.Text.Trim() +"%' ";
} else {
s1=" 1=1 ";
}
if (tbCompany.Text.Trim() !=""){
s2=" CompanyCode like '%"+ tbCompany.Text.Trim() +"%' ";
} else {
s2=" 1=1 ";
}
if (tbLocation.Text.Trim() !=""){
s3=" Location like '%"+ tbLocation.Text.Trim() +"%' ";
} else {
s3=" 1=1 ";
}
if (tbName.Text.Trim() !=""){
s4=" Name like '%"+ tbName.Text.Trim() +"%' ";
} else {
s4=" 1=1 ";
}
cond=s1 + " and " + s2 + " and "+ s3 + " and "+ s4;
DataSet ds;
if(Request["F_SysCode"]!=null)
{
if(Request["F_SysCode"].ToString().Substring(0,6)=="010030")
ds=func.GetDataTable("select plant, name, companycode, location from pubPlant where Active ='A' and "+ cond);
else
ds=func.GetDataTable("select plant, name, companycode, location from pubPlant where Active ='A' and "+ cond +
func.GetPlantStr(Session["uID"].ToString(),"Plant",Request["state"]==null?"view":Request["state"].ToString()==""?"view":Request["state"].ToString())+" order by plant");
}
else
{
ds=func.GetDataTable("select plant, name, companycode, location from pubPlant where Active ='A' and "+ cond +
func.GetPlantStr(Session["uID"].ToString(),"Plant",Request["state"]==null?"view":Request["state"].ToString()==""?"view":Request["state"].ToString())+" order by plant");
}
DataGrid1.DataSource=ds.Tables[0];
DataGrid1.DataBind();
lblResult.Text="Total:"+ DataGrid1.Items.Count.ToString();
if (DataGrid1.Items.Count ==0){
func.AlertMsg("Can not found anything!");
}
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {
LinkButton DelButton= new LinkButton();
if(e.Item.ItemType==ListItemType.AlternatingItem || (e.Item.ItemType==ListItemType.Item)) {
e.Item.Attributes.Add("onMouseover", "this.bgColor='#eeeeee'");
e.Item.Attributes.Add("onmouseout", "this.bgColor='white'");
e.Item.Attributes.Add("ID","dg_"+e.Item.Cells[0].Text);
e.Item.Attributes.Add("onclick","SelectLine('dg_"+e.Item.Cells[0].Text +"')");
e.Item.Attributes.Add("ondblclick","return OkBtn_OnClick('lbResult');");
e.Item.Attributes.Add("style","cursor:hand");
}
}
}
}