📄 advertisements.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 System.Web.Configuration;
namespace MegaMartAudio
{
/// <summary>
/// Summary description for Advertisements.
/// </summary>
public class Advertisements : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgAds;
protected System.Web.UI.WebControls.Label lblStatus;
protected System.Web.UI.WebControls.Label lblModels;
protected System.Web.UI.WebControls.Label lblProd;
protected System.Web.UI.WebControls.DropDownList cboAds;
protected System.Web.UI.WebControls.DropDownList cboModels;
protected System.Web.UI.WebControls.DropDownList cboProducts;
protected System.Web.UI.WebControls.Label lblNewStaff;
protected System.Web.UI.WebControls.Button cmdAdd;
private void Page_Load(object sender, System.EventArgs e)
{
//Check if its a valid session
if(Session["sintID"] != null)
{
//Code to be executed the first time the page is loaded
if(!IsPostBack)
{
//string strCon=ConfigurationSettings.AppSettings["DB"];
string strCon="Server=.;database=MegaMartAudio;uid=sa;pwd=sa";
SqlConnection con = new SqlConnection(strCon);
//Populating the Products Drop Down List with the Product Names
string strCmd="select * from MMA_PRODUCTS_TB";
SqlCommand cmd = new SqlCommand(strCmd,con);
DataSet ds=new DataSet();
SqlDataAdapter da=new SqlDataAdapter(cmd);
da.Fill(ds);
cboProducts.DataSource=ds;
cboProducts.DataTextField="PROD_PNAME";
cboProducts.DataValueField="PK_PROD_ID";
cboProducts.DataBind();
cboProducts.Items.Insert(0,"All");
//Populating the DataGrid with Product Name, Model Name, User name,
//Status of the Ad and the remarks given to the AD
SqlConnection con1 = new SqlConnection(strCon);
SqlCommand cmd2 = new SqlCommand("select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW",con1);
DataSet ds2=new DataSet();
SqlDataAdapter da2=new SqlDataAdapter(cmd2);
da2.Fill(ds2);
dgAds.DataSource = ds2;
dgAds.DataBind();
}
}
//Redirect the user to 'Unauthorised' Page if its an invalid session
else
{
Response.Redirect("Unauthorised.aspx");
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dgAds.SelectedIndexChanged += new System.EventHandler(this.dgAds_SelectedIndexChanged);
this.cboAds.SelectedIndexChanged += new System.EventHandler(this.cboAds_SelectedIndexChanged);
this.cboModels.SelectedIndexChanged += new System.EventHandler(this.cboModels_SelectedIndexChanged);
this.cboProducts.SelectedIndexChanged += new System.EventHandler(this.cboProducts_SelectedIndexChanged);
this.cmdAdd.Click += new System.EventHandler(this.cmdAdd_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void cmdAdd_Click(object sender, System.EventArgs e)
{
//Redirect the user to 'AddStaff' Page when the manager wants to add a new user
Response.Redirect("AddStaff.aspx");
}
private void cboProducts_SelectedIndexChanged(object sender, System.EventArgs e)
{
string cmdStr2="";
//When a particular product is selected
if(cboProducts.SelectedIndex !=0)
{
//Enable the Models Dropdownlist
//and populate it with the appropriate model names
cboModels.Enabled = true;
string strCon="Server=.;database=MegaMartAudio;uid=sa;pwd=sa";
SqlConnection con = new SqlConnection(strCon);
SqlCommand cmd = new SqlCommand("select * from MMA_MODELS_TB where FK_MOD_PROD_ID = @pid",con);
cmd.Parameters.Add("@pid",SqlDbType.Int);
cmd.Parameters["@pid"].Value = cboProducts.SelectedValue;
DataSet ds=new DataSet();
SqlDataAdapter da=new SqlDataAdapter(cmd);
da.Fill(ds);
cboModels.DataSource=ds;
cboModels.DataTextField="MOD_NAME";
cboModels.DataValueField="PK_MOD_ID";
cboModels.DataBind();
cboModels.Items.Insert(0,"All");
//Check the ad status selected in the AdsDropDownList
//If the status 'all' is selected
if(cboAds.SelectedIndex == 0)
{
cmdStr2 = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue);
}
//If the status 'Accepted' is selected
if(cboAds.SelectedIndex == 1)
{
cmdStr2 = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue)+ "and ALDTLS_ASTATUS = 'Accepted'";
}
//If the status 'Rejected' is selected
if(cboAds.SelectedIndex == 2)
{
cmdStr2 = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue)+ "and ALDTLS_ASTATUS = 'Rejected'";
}
//If the status 'Not Evaluated' is selected
if(cboAds.SelectedIndex == 3)
{
cmdStr2 = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue)+ "and ALDTLS_ASTATUS = 'Not Evaluated'";
}
}
//when no product is selecte i.e 'all' is selected
//display all the ads in all products and all models irrespecive of the ad status
else
{
cboModels.Enabled = false;
cboModels.SelectedIndex = 0;
cboAds.SelectedIndex = 0;
cmdStr2 = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW";
}
//binding the datagrid
string conStr2="Server=.;database=MegaMartAudio;uid=sa;pwd=sa";
SqlConnection con2 = new SqlConnection(conStr2);
SqlCommand cmd2 = new SqlCommand(cmdStr2,con2);
DataSet ds2=new DataSet();
SqlDataAdapter da2=new SqlDataAdapter(cmd2);
da2.Fill(ds2);
dgAds.DataSource = ds2;
dgAds.DataBind();
}
private void cboModels_SelectedIndexChanged(object sender, System.EventArgs e)
{
string cmdStr="";
if(cboModels.SelectedIndex !=0)
{
if(cboAds.SelectedIndex == 0)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue) + "and ALDTLS_MID =" + Convert.ToInt32(cboModels.SelectedValue);
}
if(cboAds.SelectedIndex == 1)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue) + "and ALDTLS_MID =" + Convert.ToInt32(cboModels.SelectedValue)+ "and ALDTLS_ASTATUS = 'Accepted'";
}
if(cboAds.SelectedIndex == 2)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue) + "and ALDTLS_MID =" + Convert.ToInt32(cboModels.SelectedValue)+ "and ALDTLS_ASTATUS = 'Rejected'";
}
if(cboAds.SelectedIndex == 3)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue) + "and ALDTLS_MID =" + Convert.ToInt32(cboModels.SelectedValue)+ "and ALDTLS_ASTATUS = 'Not Evaluated'";
}
}
else
{
cboAds.SelectedIndex = 0;
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue);
}
string strCon="Server=.;database=MegaMartAudio;uid=sa;pwd=sa";
SqlConnection con = new SqlConnection(strCon);
SqlCommand cmd = new SqlCommand(cmdStr,con);
DataSet ds=new DataSet();
SqlDataAdapter da=new SqlDataAdapter(cmd);
da.Fill(ds);
dgAds.DataSource = ds;
dgAds.DataBind();
}
private void cboAds_SelectedIndexChanged(object sender, System.EventArgs e)
{
string cmdStr="";
if(cboAds.SelectedIndex == 0)
{
if(cboProducts.SelectedIndex!=0 && cboModels.SelectedIndex != 0)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue) + "and ALDTLS_MID =" + Convert.ToInt32(cboModels.SelectedValue);
}
else if(cboProducts.SelectedIndex!=0 && cboModels.SelectedIndex == 0)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue);
}
else if(cboProducts.SelectedIndex==0)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW ";
}
}
if(cboAds.SelectedIndex == 1)
{
if(cboProducts.SelectedIndex!=0 && cboModels.SelectedIndex != 0)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue) + "and ALDTLS_MID =" + Convert.ToInt32(cboModels.SelectedValue) + "and ALDTLS_ASTATUS = 'Accepted'";
}
else if(cboProducts.SelectedIndex!=0 && cboModels.SelectedIndex == 0)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue) + "and ALDTLS_ASTATUS = 'Accepted'";
}
else if(cboProducts.SelectedIndex==0)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_ASTATUS = 'Accepted'";
}
}
if(cboAds.SelectedIndex == 2)
{
if(cboProducts.SelectedIndex!=0 && cboModels.SelectedIndex != 0)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue) + "and ALDTLS_MID =" + Convert.ToInt32(cboModels.SelectedValue) + "and ALDTLS_ASTATUS = 'Rejected'";
}
else if(cboProducts.SelectedIndex!=0 && cboModels.SelectedIndex == 0)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue) + "and ALDTLS_ASTATUS = 'Rejected'";
}
else if(cboProducts.SelectedIndex==0)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_ASTATUS = 'Rejected'";
}
}
if(cboAds.SelectedIndex == 3)
{
if(cboProducts.SelectedIndex!=0 && cboModels.SelectedIndex != 0)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue) + "and ALDTLS_MID =" + Convert.ToInt32(cboModels.SelectedValue) + "and ALDTLS_ASTATUS = 'Not Evaluated'";
}
else if(cboProducts.SelectedIndex!=0 && cboModels.SelectedIndex == 0)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_PID = " + Convert.ToInt32(cboProducts.SelectedValue) + "and ALDTLS_ASTATUS = 'Not Evaluated'";
}
else if(cboProducts.SelectedIndex==0)
{
cmdStr = "select ALDTLS_PNAME as Product, ALDTLS_MNAME as Model, ALDTLS_UNAME as [Submitted By], ALDTLS_ASTATUS as Status, ALDTLS_AREMARKS as Remarks, ALDTLS_AID as AdID from MMA_ALLDETAILS_VW where ALDTLS_ASTATUS = 'Not Evaluated'";
}
}
string strCon="Server=.;database=MegaMartAudio;uid=sa;pwd=sa";
SqlConnection con = new SqlConnection(strCon);
SqlCommand cmd = new SqlCommand(cmdStr,con);
DataSet ds=new DataSet();
SqlDataAdapter da=new SqlDataAdapter(cmd);
da.Fill(ds);
dgAds.DataSource = ds;
dgAds.DataBind();
}
private void LinkButton1_Click(object sender, System.EventArgs e)
{
Response.Redirect("Login.aspx");
}
private void dgAds_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgAds.CurrentPageIndex = e.NewPageIndex;
}
private void dgAds_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -