?? productid.aspx.cs
字號:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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 com.unicafe.ui;
using com.unicafe.common;
using com.unicafe.security;
namespace com.ascs.plp.publics
{
/// <summary>
/// KC_ProductId 的摘要說明。
/// </summary>
public class ProductId : com.unicafe.ui.UnicafePage
{
protected System.Web.UI.WebControls.CheckBox CheckBox1;
protected System.Web.UI.WebControls.CheckBox CheckBox2;
protected System.Web.UI.WebControls.CheckBox CheckBox3;
protected System.Web.UI.WebControls.CheckBox CheckBox4;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Data.SqlClient.SqlConnection sqlcn_plp;
protected System.Data.SqlClient.SqlCommand cmd;
protected System.Data.DataTable dt_CPJBXX;
protected System.Data.DataView dv_CPJBXX;
protected System.Data.SqlClient.SqlDataReader dr;
protected string sql,CPMCStatement,SCCSStatement,CPXHStatement,CPGGStatement,EnableLimit;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁面
this.VerifyPage();
sqlcn_plp = new SqlConnection (com.unicafe.common.Configuration.GetDBConnectionString());
cmd = sqlcn_plp.CreateCommand();
if (!this.IsPostBack)
{
try
{
ViewState["FormName"] = this.Request.QueryString["FormName"];
ViewState["ControlName"] = this.Request.QueryString["ControlName"];
}
catch
{
this.Response.Write("<script language=javascript>window.close();</script>");
return;
}
// 給綁定DataGrid控件的SQL語句進行賦值(注意,SQL語句賦值之后不要再修改)
ViewState["sql"] = "Select CPDM, CPMC, SCCS, CPXH, CPGG From CPJBXX Where CPDM is Null ";
string sql = ViewState["sql"].ToString();
//處理DataGrid控件(綁定DataGrid控件 -> 檢查是否需要定位 -> 給導航文本賦值)
if(CommonService.HandleDataGrid(this, sql, DataGrid1, "Data2", Label1, Label2, Label3) == false)
this.Response.Redirect("../../publics/Error.aspx?errmsg=在處理數據時發生錯誤。");
}
else
{
//檢查回發的請求操作是否是要進入上頁或下頁
if(CommonService.PageNavigate(this, DataGrid1, "Data2", Label1, Label2, Label3) == false)
this.Response.Redirect("../../publics/Error.aspx?errmsg=在處理數據時發生錯誤。");
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.CheckBox1.CheckedChanged += new System.EventHandler(this.CheckBox1_CheckedChanged);
this.CheckBox2.CheckedChanged += new System.EventHandler(this.CheckBox2_CheckedChanged);
this.CheckBox3.CheckedChanged += new System.EventHandler(this.CheckBox3_CheckedChanged);
this.CheckBox4.CheckedChanged += new System.EventHandler(this.CheckBox4_CheckedChanged);
this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click);
this.ID = "ProductId";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
/// *****************************************************************************
/// BEIGIN
/// <summary>
/// 查詢事件處理函數
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LinkButton1_Click(object sender, System.EventArgs e)
{
BindGrid();
}
/// *****************************************************************************
/// END
/// *****************************************************************************
/// *****************************************************************************
/// BEIGIN
/// <summary>
/// 與DataGrid1綁定數據
/// </summary>
/// *****************************************************************************
private void BindGrid()
{
//根據選擇的條件進行查詢條件的組合和生成
sql = "Select CPDM, CPMC, SCCS, CPXH, CPGG From CPJBXX Where CPDM Like '%' ";
if (CheckBox1.Checked == true && TextBox1.Text.Trim() != "")
{
CPMCStatement = "And CPMC Like '%" + TextBox1.Text + "%' ";
}
else
{
CPMCStatement = "";
}
if (CheckBox2.Checked == true && TextBox2.Text.Trim() != "")
{
SCCSStatement = "And SCCS Like '%" + TextBox2.Text + "%' ";
}
else
{
SCCSStatement = "";
}
if (CheckBox3.Checked == true && TextBox3.Text.Trim() != "")
{
CPXHStatement = "And CPXH Like '%" + TextBox3.Text + "%' ";;
}
else
{
CPXHStatement = "";
}
if (CheckBox4.Checked == true && TextBox4.Text.Trim() != "")
{
CPGGStatement = "And CPGG Like '%" + TextBox4.Text + "%' ";
}
else
{
CPGGStatement = "";
}
if(this.Request.QueryString["EnableLimit"] == null || this.Request.QueryString["EnableLimit"] == "T")
{
EnableLimit = "And SFSY = '1'";
}
else
{
EnableLimit = "";
}
ViewState["sql"] = sql + CPMCStatement + SCCSStatement + CPXHStatement + CPGGStatement + EnableLimit;
sql = ViewState["sql"].ToString();
//處理DataGrid控件(綁定DataGrid控件 -> 給導航文本賦值)
if(CommonService.ReBindDataGrid(this, sql, DataGrid1, "Data2", Label1, Label2, Label3) == false)
this.Response.Redirect("../../publics/Error.aspx?errmsg=在處理數據時發生錯誤。");
}
/// *****************************************************************************
/// END
/// *****************************************************************************
/// *****************************************************************************
/// BEIGIN
/// <summary>
/// 產品名稱復選框狀態改變事件處理函數
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// *****************************************************************************
private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
if (CheckBox1.Checked == true)
{
TextBox1.Enabled = true;
}
else
{
TextBox1.Enabled = false;
}
}
/// *****************************************************************************
/// END
/// *****************************************************************************
/// ******************************************************************
/// BEIGIN
/// <summary>
/// 為數據行添加對鼠標移動的響應代碼
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// ******************************************************************
protected void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemIndex >= 0)
{
e.Item.Attributes["onMouseOver"] = "javascript:this.bgColor='LemonChiffon';";
e.Item.Attributes["onMouseOut"] = "javascript:this.bgColor='white';";
e.Item.Attributes["onClick"] = "javascript:__doPostBack('DataGrid1:_ctl" +(Convert.ToInt16(e.Item.ItemIndex+3)).ToString() + ":_ctl0','')";
e.Item.Attributes["style"] = "cursor:hand";
}
}
/// ******************************************************************
/// END
/// ******************************************************************
/// *****************************************************************************
/// BEIGIN
/// <summary>
/// 生產廠商復選框狀態改變事件處理函數
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// *****************************************************************************
private void CheckBox2_CheckedChanged(object sender, System.EventArgs e)
{
if (CheckBox2.Checked == true)
{
TextBox2.Enabled = true;
}
else
{
TextBox2.Enabled = false;
}
}
/// *****************************************************************************
/// END
/// *****************************************************************************
/// *****************************************************************************
/// BEIGIN
/// <summary>
/// 產品型號復選框狀態改變事件處理函數
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// *****************************************************************************
private void CheckBox3_CheckedChanged(object sender, System.EventArgs e)
{
if (CheckBox3.Checked == true)
{
TextBox3.Enabled = true;
}
else
{
TextBox3.Enabled = false;
}
}
/// *****************************************************************************
/// END
/// *****************************************************************************
/// *****************************************************************************
/// BEIGIN
/// <summary>
/// 產品規格復選框狀態改變事件處理函數
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// *****************************************************************************
private void CheckBox4_CheckedChanged(object sender, System.EventArgs e)
{
if (CheckBox4.Checked == true)
{
TextBox4.Enabled = true;
}
else
{
TextBox4.Enabled = false;
}
}
/// *****************************************************************************
/// END
/// *****************************************************************************
/// *****************************************************************************
/// BEIGIN
/// <summary>
/// 產品列表選擇項改變事件處理函數
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// *****************************************************************************
private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string ReturnForm = ViewState["FormName"].ToString();
string ReturnControl = ViewState["ControlName"].ToString();
string sId = DataGrid1.SelectedItem.Cells[1].Text;
string sScript = "";
sScript += "<script language=javascript>";
sScript += " window.opener." + ReturnForm + "." + ReturnControl + ".value = '" + sId + "';";
if (this.Request.QueryString["Submit"] == "T")
sScript += " window.opener." + ReturnForm + "." + ReturnControl + ".value = '" + sId + "';window.opener." + ReturnForm + ".submit();";
sScript += " window.close();";
sScript += "</script>";
Response.Write(sScript);
}
/// *****************************************************************************
/// END
/// *****************************************************************************
/// *****************************************************************************
/// BEIGIN
/// <summary>
/// 產品列表分頁事件處理函數
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DataGrid1_Page(Object sender, DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
/// *****************************************************************************
/// END
/// *****************************************************************************
//
//
// /// *****************************************************************************
// /// BEIGIN
// /// <summary>
// /// 返回事件處理函數
// /// </summary>
// /// <param name="sender"></param>
// /// <param name="e"></param>
// private void Button2_Click(object sender, System.EventArgs e)
// {
// string ReturnForm = ViewState["FormName"].ToString();
// string ReturnControl = ViewState["ControlName"].ToString();
// string sId = Text1.Value;
// string sScript = "";
// sScript += "<script language=javascript>";
// sScript += " window.opener." + ReturnForm + "." + ReturnControl + ".value = '" + sId + "';";
// sScript += " window.close();";
// sScript += "</script>";
// Response.Write(sScript);
// }
// /// *****************************************************************************
// /// END
// /// *****************************************************************************
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -