protected void btn_Click(object sender, EventArgs e) { clsLabelsFactory fac = new clsLabelsFactory(); if (string.IsNullOrEmpty(hf.Value)) { List <clsLabels> lbl = fac.GetAllBy(clsLabels.clsLabelsFields.Title, txtLable.Text); if (lbl != null && lbl.Count > 0) { pnlSuccess.Visible = false; pnlError.Visible = true; } else { clsLabels label = new clsLabels(); label.Title = txtLable.Text; label.Data = ddlFirst.SelectedValue == "1" ? false : true; fac.Insert(label); pnlSuccess.Visible = true; lblSuccess.Text = "Label added successfully"; pnlError.Visible = false; } } else { clsLabelsKeys key = new clsLabelsKeys(Convert.ToInt32(hf.Value)); clsLabels label = fac.GetByPrimaryKey(key); label.Title = txtLable.Text; label.Data = ddlFirst.SelectedValue == "1" ? false : true; fac.Update(label); pnlSuccess.Visible = true; lblSuccess.Text = "Label updated successfully"; pnlError.Visible = false; } }
/// <summary> /// update row in the table /// </summary> /// <param name="businessObject">business object</param> /// <returns>true for successfully updated</returns> public bool Update(clsLabels businessObject) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "dbo.[sp_Labels_Update]"; 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, businessObject.Id)); sqlCommand.Parameters.Add(new SqlParameter("@Title", SqlDbType.NVarChar, 2147483647, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.Title)); sqlCommand.Parameters.Add(new SqlParameter("@Data", SqlDbType.Bit, 1, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.Data)); MainConnection.Open(); sqlCommand.ExecuteNonQuery(); return(true); } catch (Exception ex) { throw new Exception("clsLabels::Update::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
/// <summary> /// Populate business object from data reader /// </summary> /// <param name="businessObject">business object</param> /// <param name="dataReader">data reader</param> internal void PopulateBusinessObjectFromReader(clsLabels businessObject, IDataReader dataReader) { businessObject.Id = dataReader.GetInt32(dataReader.GetOrdinal(clsLabels.clsLabelsFields.Id.ToString())); businessObject.Title = dataReader.GetString(dataReader.GetOrdinal(clsLabels.clsLabelsFields.Title.ToString())); businessObject.Data = dataReader.GetBoolean(dataReader.GetOrdinal(clsLabels.clsLabelsFields.Data.ToString())); }
/// <summary> /// Populate business objects from the data reader /// </summary> /// <param name="dataReader">data reader</param> /// <returns>list of clsLabels</returns> internal List <clsLabels> PopulateObjectsFromReader(IDataReader dataReader) { List <clsLabels> list = new List <clsLabels>(); while (dataReader.Read()) { clsLabels businessObject = new clsLabels(); PopulateBusinessObjectFromReader(businessObject, dataReader); list.Add(businessObject); } return(list); }
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", "current"); 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"]; clsLabelsFactory fac = new clsLabelsFactory(); clsLabelsKeys key = new clsLabelsKeys(Convert.ToInt32(hf.Value)); clsLabels lvl = fac.GetByPrimaryKey(key); txtLable.Text = lvl.Title; ddlFirst.SelectedValue = lvl.Data == true ? "0" : "1"; } } else { Response.Redirect("Login.aspx"); } } }
/// <summary> /// Select by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>clsLabels business object</returns> public clsLabels SelectByPrimaryKey(clsLabelsKeys keys) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "dbo.[sp_Labels_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()) { clsLabels businessObject = new clsLabels(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch (Exception ex) { throw new Exception("clsLabels::SelectByPrimaryKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
protected void Button1_Click(object sender, EventArgs e) { clsLabelsFactory fac = new clsLabelsFactory(); List <clsLabels> lbl = fac.GetAllBy(clsLabels.clsLabelsFields.Title, txtLable.Text); if (lbl != null && lbl.Count > 0) { pnlSuccess.Visible = false; pnlError.Visible = true; lblError.Text = "Label already exists"; } else { clsLabels label = new clsLabels(); label.Title = txtLable.Text; label.Data = ddlFirst.SelectedValue == "1" ? false : true; fac.Insert(label); pnlSuccess.Visible = true; lblSuccess.Text = "Label added successfully"; pnlError.Visible = false; } LoadData(); }