/// <summary> /// Delete by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>true for successfully deleted</returns> public bool Delete(clsEmergentiKeys keys) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "dbo.[sp_Emergenti_DeleteByPrimaryKey]"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, keys.ID)); MainConnection.Open(); sqlCommand.ExecuteNonQuery(); return(true); } catch (Exception ex) { throw new Exception("clsEmergenti::DeleteByKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
protected void grd_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "_Edit") { Response.Redirect("EditChart.aspx?id=" + e.CommandArgument); } else if (e.CommandName == "_delete") { clsEmergentiFactory fac = new clsEmergentiFactory(); clsEmergentiKeys key = new clsEmergentiKeys(Convert.ToInt32(e.CommandArgument)); List <clsEmergenti> Emergenti = fac.GetAllBy(clsEmergenti.clsEmergentiFields.ID, e.CommandArgument); if (Emergenti != null && Emergenti.Count > 1) { pnlError.Visible = true; pnlSuccess.Visible = false; lblError.Text = "Can't delete this Emergenti"; } else { fac.Delete(key); LoadData(); pnlSuccess.Visible = true; pnlError.Visible = false; lblSuccess.Text = "Emergenti deleted successfully"; } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["User"] != null) { HtmlGenericControl ManageSongs = (HtmlGenericControl)Master.FindControl("ManageSongs"); ManageSongs.Attributes.Add("class", "select"); HtmlGenericControl ManageCompany = (HtmlGenericControl)Master.FindControl("ManageCompany"); ManageCompany.Attributes.Add("class", "select"); HtmlGenericControl ManageLabel = (HtmlGenericControl)Master.FindControl("ManageLabel"); ManageLabel.Attributes.Add("class", "select"); HtmlGenericControl ManageEmergenti = (HtmlGenericControl)Master.FindControl("ManageEmergenti"); ManageEmergenti.Attributes.Add("class", "current"); HtmlGenericControl ImportData = (HtmlGenericControl)Master.FindControl("ImportData"); ImportData.Attributes.Add("class", "select"); HtmlGenericControl audienceFigures = (HtmlGenericControl)Master.FindControl("audienceFigures"); audienceFigures.Attributes.Add("class", "select"); HtmlGenericControl digitalData = (HtmlGenericControl)Master.FindControl("digitalData"); digitalData.Attributes.Add("class", "select"); HtmlGenericControl MoveFiles = (HtmlGenericControl)Master.FindControl("MoveFiles"); MoveFiles.Attributes.Add("class", "select"); HtmlGenericControl Promoter = (HtmlGenericControl)Master.FindControl("Promoter"); Promoter.Attributes.Add("class", "select"); LoadData(); Session["Emergenti"] = null; Session["eEmergenti"] = null; if (Request.QueryString != null && Request.QueryString["id"] != null) { hf.Value = Request.QueryString["id"]; clsEmergentiFactory fac = new clsEmergentiFactory(); clsEmergentiKeys key = new clsEmergentiKeys(Convert.ToInt32(hf.Value)); clsEmergenti Emergenti = fac.GetByPrimaryKey(key); ddlSettimana.SelectedItem.Value = Emergenti.Settimana; lbl_1.Text = Emergenti.Posizione; txtArt_1.Text = Emergenti.Artista; txtTit_1.Text = Emergenti.Titolo; txtEtt_1.Text = Emergenti.Anno; } LoadData(); } else { Response.Redirect("Login.aspx"); } } }
/// <summary> /// Select by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>clsEmergenti business object</returns> public clsEmergenti SelectByPrimaryKey(clsEmergentiKeys keys) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "dbo.[sp_Emergenti_SelectByPrimaryKey]"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, keys.ID)); MainConnection.Open(); IDataReader dataReader = sqlCommand.ExecuteReader(); if (dataReader.Read()) { clsEmergenti businessObject = new clsEmergenti(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch (Exception ex) { throw new Exception("clsEmergenti::SelectByPrimaryKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }