/// <summary> /// Delete by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>true for successfully deleted</returns> public bool Delete(clsCompaniesKeys keys) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "dbo.[sp_Companies_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("clsCompanies::DeleteByKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
protected void grd_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.ToString() == "_Edit") { Response.Redirect("AddCompany.aspx?id=" + e.CommandArgument + ""); } else if (e.CommandName.ToString() == "_delete") { clsCompaniesFactory fac = new clsCompaniesFactory(); clsCompaniesKeys key = new clsCompaniesKeys(Convert.ToInt32(e.CommandArgument)); fac.Delete(key); } }
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", "current"); HtmlGenericControl ManageLabel = (HtmlGenericControl)Master.FindControl("ManageLabel"); ManageLabel.Attributes.Add("class", "select"); HtmlGenericControl ManageEmergenti = (HtmlGenericControl)Master.FindControl("ManageEmergenti"); ManageEmergenti.Attributes.Add("class", "select"); 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"); Session["Songs"] = null; Session["eSongs"] = null; if (Request.QueryString != null && Request.QueryString["id"] != null) { hf.Value = Request.QueryString["id"]; clsCompaniesFactory fac = new clsCompaniesFactory(); clsCompaniesKeys key = new clsCompaniesKeys(Convert.ToInt32(hf.Value)); clsCompanies Company = fac.GetByPrimaryKey(key); txtcompany.Text = Company.Company; txtFullName.Text = Company.FullName; ddlFirst.SelectedValue = Company.Data == true ? "0" : "1"; } } else { Response.Redirect("Login.aspx"); } } }
/// <summary> /// Select by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>clsCompanies business object</returns> public clsCompanies SelectByPrimaryKey(clsCompaniesKeys keys) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "dbo.[sp_Companies_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()) { clsCompanies businessObject = new clsCompanies(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch (Exception ex) { throw new Exception("clsCompanies::SelectByPrimaryKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
protected void btn_Click(object sender, EventArgs e) { clsCompaniesFactory fac = new clsCompaniesFactory(); if (string.IsNullOrEmpty(hf.Value)) { List <clsCompanies> lbl = fac.GetAllBy(clsCompanies.clsCompaniesFields.Company, txtcompany.Text); if (lbl != null && lbl.Count > 0) { pnlSuccess.Visible = false; pnlError.Visible = true; } else { clsCompanies Company = new clsCompanies(); Company.FullName = txtFullName.Text; Company.Company = txtcompany.Text; Company.Data = ddlFirst.SelectedValue == "1" ? false : true; fac.Insert(Company); pnlSuccess.Visible = true; lblSuccess.Text = "company added successfully"; pnlError.Visible = false; } } else { clsCompaniesKeys key = new clsCompaniesKeys(Convert.ToInt32(hf.Value)); clsCompanies Company = fac.GetByPrimaryKey(key); Company.FullName = txtFullName.Text; Company.Company = txtcompany.Text; Company.Data = ddlFirst.SelectedValue == "1" ? false : true; fac.Update(Company); pnlSuccess.Visible = true; lblSuccess.Text = "company updated successfully"; pnlError.Visible = false; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["User"] != null) { Session["eSongs"] = null; HtmlGenericControl ManageSongs = (HtmlGenericControl)Master.FindControl("ManageSongs"); ManageSongs.Attributes.Add("class", "current"); 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", "select"); 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"); if (Request.QueryString != null && Request.QueryString["id"] != null) { hf.Value = Request.QueryString["id"]; hfprevid.Value = Request.QueryString["id"]; clsSongsFactory fac = new clsSongsFactory(); List <clsSongs> Songs = fac.GetAllByVersions(Convert.ToInt32(hf.Value)); pnlButtons.Visible = true; pnlSave.Visible = false; if (Songs != null && Songs.Count > 0 && Session["Songs"] == null) { grd.DataSource = Songs; grd.DataBind(); Session["Songs"] = Songs; clsSongs Song = Songs.First(x => x.IdSong == Convert.ToInt32(hf.Value)); lblVersion.Text = Song.VERSION; chkAbsoluteBegin.Checked = Song.IncludeInNewTalent; chkAlternativeCharts.Checked = Song.AlternativeChart; chkFirstPlay.Checked = Song.IncludeInFirstPlay; lblGenre.Text = Song.GENRE; lblLanguage.Text = Song.LANGUAGE; lblRadio.Text = Song.RadioDate == null ? "" : Song.RadioDate.Value.ToString("dd/MM/yyyy"); lblTvShow.Text = Song.TVSHOW; lblArtist.Text = Song.ARTIST; lblTitle.Text = Song.TITLE; lblAuthor.Text = Song.Author; lblPublisher.Text = Song.Publisher; lblDuration.Text = Song.Duration; lblISRC.Text = Song.ISRC; lblLabel.Text = Song.LABEL; clsCompaniesFactory facC = new clsCompaniesFactory(); clsCompaniesKeys k = new clsCompaniesKeys(Songs[0].CompanyId.Value); clsCompanies c = facC.GetByPrimaryKey(k); lblCompany.Text = c.FullName; } else { Songs = (List <clsSongs>)Session["Songs"]; grd.DataSource = Songs; grd.DataBind(); clsSongs Song = Songs.Where(x => x.IdSong == Convert.ToInt32(hf.Value)).FirstOrDefault(); pnlButtons.Visible = false; pnlSave.Visible = true; lblVersion.Text = Song.VERSION; chkAbsoluteBegin.Checked = Song.IncludeInNewTalent; chkAlternativeCharts.Checked = Song.AlternativeChart; chkFirstPlay.Checked = Song.IncludeInFirstPlay; lblGenre.Text = Song.GENRE; lblLanguage.Text = Song.LANGUAGE; lblRadio.Text = Song.RadioDate.Value.ToString("dd/MM/yyyy"); lblTvShow.Text = Song.TVSHOW; lblArtist.Text = Song.ARTIST; lblTitle.Text = Song.TITLE; lblAuthor.Text = Song.Author; lblPublisher.Text = Song.Publisher; lblDuration.Text = Song.Duration; lblISRC.Text = Song.ISRC; lblLabel.Text = Song.LABEL; clsCompaniesFactory facC = new clsCompaniesFactory(); clsCompaniesKeys k = new clsCompaniesKeys(Song.CompanyId.Value); clsCompanies c = facC.GetByPrimaryKey(k); lblCompany.Text = c.FullName; } } } else { Response.Redirect("Login.aspx"); } } }