⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addnewad.aspx.cs

📁 PURPOSE OF THE PROJECT: This Application would facilitate the huge process of managing the Ad detai
💻 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.Configuration;

namespace MegaMartAudio
{
	/// <summary>
	/// Summary description for AddNewAd.
	/// </summary>
	public class AddNewAd : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button btnUpdate;
		protected System.Web.UI.HtmlControls.HtmlInputFile MyFile;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator5;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator3;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator4;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator5;
		protected System.Web.UI.WebControls.Label lblProd;
		protected System.Web.UI.WebControls.Label lblPath;
		protected System.Web.UI.WebControls.Label lblVer;
		protected System.Web.UI.WebControls.Label lblCont;
		protected System.Web.UI.WebControls.Label lblDur;
		protected System.Web.UI.WebControls.Label lblVoc;
		protected System.Web.UI.WebControls.Label lblMod;
		protected System.Web.UI.WebControls.Label lblName;
		protected System.Web.UI.WebControls.Label lblEnterNewAD;
		protected System.Web.UI.WebControls.DropDownList cboProducts;
		protected System.Web.UI.WebControls.DropDownList cboModels;
		protected System.Web.UI.WebControls.TextBox txtAdVoice;
		protected System.Web.UI.WebControls.TextBox txtAdDuration;
		protected System.Web.UI.WebControls.TextBox txtAdContent;
		protected System.Web.UI.WebControls.TextBox txtAdVersion;
		protected System.Web.UI.WebControls.TextBox txtAdName;
		protected System.Web.UI.WebControls.Label lblResult;
		protected System.Web.UI.WebControls.Label lblPMNotGiven;
		protected System.Web.UI.WebControls.Label lblFile;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["sintID"] != null)
			{
				if(!IsPostBack)
				{
					//string strCon=ConfigurationSettings.AppSettings["DB"];
					string strCon="Server=.;database=MegaMartAudio;uid=sa;pwd=sa";
					SqlConnection con = new SqlConnection(strCon);

					DataSet ds=new DataSet();

					string strCmd="select * from MMA_PRODUCTS_TB";
					SqlCommand cmd = new SqlCommand(strCmd,con);

				
					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");
				}
			}

			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.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
			this.cboProducts.SelectedIndexChanged += new System.EventHandler(this.PDd_SelectedIndexChanged);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void PDd_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(cboProducts.SelectedIndex == 0)
			{
				cboModels.Enabled = false;
				}
			else
			{
				cboModels.Enabled = true;
		
				//string strCon=ConfigurationSettings.AppSettings["DB"];
				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");
			
			}
			
		}

		private void btnUpdate_Click(object sender, System.EventArgs e)
		{
			if(MyFile.PostedFile.ContentLength == 0)
			{
				lblFile.Text = "Please select a file!";
			}
			else if(!MyFile.PostedFile.FileName.EndsWith("wav"))
			{
				lblFile.Text = "Please select a .wav file!";
			}
			else
			{
			
				if(cboProducts.SelectedIndex!=0 && cboModels.SelectedIndex!=0)
				{
					//string strCon=ConfigurationSettings.AppSettings["DB"];
					string strCon="Server=.;database=MegaMartAudio;uid=sa;pwd=sa";
					SqlConnection con = new SqlConnection(strCon);
	
					con.Open();
					SqlCommand cmd = new SqlCommand("insert into MMA_ADS_TB(FK_ADS_PROD_ID, FK_ADS_MOD_ID, FK_ADS_USERS_ID, ADS_VOICE, ADS_DURATION, ADS_CONTENT, ADS_VERSION, ADS_RELEASE, ADS_NAME, ADS_STATUS, ADS_MODDATE, ADS_REMARKS) values(@pid,@mid,@uid,@advoice,@adduration,@adcontent,@adversion,@adrelease,@adname,'Not Evaluated',@admoddate,'None')",con);
		
					cmd.Parameters.Add("@pid",SqlDbType.Int);
					cmd.Parameters.Add("@mid",SqlDbType.Int);
					cmd.Parameters.Add("@uid",SqlDbType.Int);
					cmd.Parameters.Add("@advoice",SqlDbType.VarChar,30);
					cmd.Parameters.Add("@adduration",SqlDbType.VarChar,10);
					cmd.Parameters.Add("@adcontent",SqlDbType.VarChar,30);
					cmd.Parameters.Add("@adversion",SqlDbType.VarChar,10);
					cmd.Parameters.Add("@adrelease",SqlDbType.VarChar,30);
					cmd.Parameters.Add("@adname",SqlDbType.VarChar,30);
					cmd.Parameters.Add("@admoddate",SqlDbType.VarChar,30);


			
					cmd.Parameters["@pid"].Value = cboProducts.SelectedValue;
					cmd.Parameters["@mid"].Value = cboModels.SelectedValue;
					cmd.Parameters["@uid"].Value = Session["sintID"];				
					cmd.Parameters["@advoice"].Value = txtAdVoice.Text;
					cmd.Parameters["@adduration"].Value = txtAdDuration.Text;
					cmd.Parameters["@adcontent"].Value = txtAdContent.Text;
					cmd.Parameters["@adversion"].Value = txtAdVersion.Text;
					cmd.Parameters["@adrelease"].Value = DateTime.Now.ToString();
					cmd.Parameters["@adname"].Value = txtAdName.Text;
					cmd.Parameters["@admoddate"].Value = DateTime.Now.ToString();




					cmd.ExecuteNonQuery();
					con.Close();

					//string s2 = "StillHoping.txt";
					MyFile.PostedFile.SaveAs(Server.MapPath("./Audio Files/") + txtAdName.Text + ".wav");

					lblResult.Text = "Advertisement added";
					cboProducts.SelectedIndex = 0;
					cboModels.SelectedIndex = 0;
					txtAdVoice.Text="";
					txtAdDuration.Text="";
					txtAdContent.Text="";
					txtAdVersion.Text="";
	
					txtAdName.Text="";
			

				}
				else
				{
					lblPMNotGiven.Text="Both Product and Model should be selected";
				}
			}
			
			
			
		}

		

		private void Home_Click(object sender, System.EventArgs e)
		{
		Response.Redirect("StaffHome.aspx");
		}

		private void LogOut_Click(object sender, System.EventArgs e)
		{
			Response.Redirect("Login.aspx");
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -