/// <summary> /// Delete by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>true for successfully deleted</returns> public bool Delete(clsSongsKeys keys) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "dbo.[sp_Songs_DeleteByPrimaryKey]"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.Add(new SqlParameter("@IdSong", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, keys.IdSong)); MainConnection.Open(); sqlCommand.ExecuteNonQuery(); return(true); } catch (Exception ex) { throw new Exception("clsSongs::DeleteByKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
protected void grd_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "_detail") { Session["Songs"] = null; Response.Redirect("songdetail.aspx?id=" + e.CommandArgument); } else if (e.CommandName == "_Edit") { Response.Redirect("EditSong.aspx?id=" + e.CommandArgument); } else if (e.CommandName == "_delete") { clsSongsFactory fac = new clsSongsFactory(); clsSongsKeys key = new clsSongsKeys(Convert.ToInt32(e.CommandArgument)); List<clsSongs> Songs = fac.GetAllBy(clsSongs.clsSongsFields.ParentSongId, e.CommandArgument); if (Songs != null && Songs.Count > 1) { pnlError.Visible = true; pnlSuccess.Visible = false; lblError.Text = "Can't delete this Song"; } else { fac.Delete(key); LoadData(); pnlSuccess.Visible = true; pnlError.Visible = false; lblSuccess.Text = "Song deleted successfully"; } } }
/// <summary> /// Select by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>clsSongs business object</returns> public clsSongs SelectByPrimaryKey(clsSongsKeys keys) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "dbo.[sp_Songs_SelectByPrimaryKey]"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.Add(new SqlParameter("@IdSong", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, keys.IdSong)); MainConnection.Open(); IDataReader dataReader = sqlCommand.ExecuteReader(); if (dataReader.Read()) { clsSongs businessObject = new clsSongs(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch (Exception ex) { throw new Exception("clsSongs::SelectByPrimaryKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
protected void btnSave_Click(object sender, EventArgs e) { bool error = false; if (Session["Songs"] != null) { string previd = hfprevid.Value; List <clsSongs> Songs1 = (List <clsSongs>)Session["Songs"]; for (int i = 0; i < Songs1.Count; i++) { if (Songs1[i].IdSong.ToString() == previd) { Songs1[i].VERSION = lblVersion.Text; string[] d = lblRadio.Text.Split('/'); DateTime date = new DateTime(Convert.ToInt16(d[2]), Convert.ToInt16(d[1]), Convert.ToInt16(d[0])); Songs1[i].RadioDate = date; Songs1[i].GENRE = lblGenre.Text; Songs1[i].LANGUAGE = lblLanguage.Text; Songs1[i].TVSHOW = lblTvShow.Text; Songs1[i].IncludeInNewTalent = chkAbsoluteBegin.Checked; Songs1[i].AlternativeChart = chkAlternativeCharts.Checked; Songs1[i].IncludeInFirstPlay = chkFirstPlay.Checked; Songs1[i].Duration = lblDuration.Text; Songs1[i].ISRC = lblISRC.Text; } } Session["Songs"] = Songs1; List <clsSongs> Songs = (List <clsSongs>)Session["Songs"]; if (Songs.Count > 0) { foreach (clsSongs s in Songs) { if (string.IsNullOrEmpty(s.VERSION) || string.IsNullOrEmpty(s.LANGUAGE) || string.IsNullOrEmpty(s.GENRE) || string.IsNullOrEmpty(s.RadioDate.ToString())) { error = true; break; } } if (!error) { foreach (clsSongs s in Songs) { clsSongsFactory fac = new clsSongsFactory(); clsSongsKeys key = new clsSongsKeys(s.IdSong); clsSongs _song = fac.GetByPrimaryKey(key); if (_song != null) { fac.Update(s); Session["SuccessMsg"] = "Record Updated Successfully."; } else { fac.Insert(s); Session["SuccessMsg"] = "Record Added Successfully."; } } Session["Songs"] = null; Response.Redirect("Songs.aspx"); } else { Session["ErrorMsg"] = "Error occured! Please try again later."; pnlError.Visible = true; lblError.Text = "Please provide all data."; } } else { pnlError.Visible = true; lblError.Text = "Some error ocurred please go back anf try again"; } } else { pnlError.Visible = true; lblError.Text = "Some error ocurred please go back anf try again"; } }