Example #1
0
    protected void Save_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            Musics _mus = new Musics(this.ConnectionString);
            if (ViewState["musId"] != null)
            {
                _mus.LitePopulate(ViewState["musId"], false);
            }

            _mus.Title = HttpUtility.HtmlEncode(txt_Title.Text);
            _mus.Status = Convert.ToInt32(dd_Status.SelectedValue);
            _mus.CategoryId = Convert.ToInt32(dd_Category.SelectedValue);

            String _imgType = "";
            if (fu_File.HasFile)
            {
                _imgType = fu_File.FileName.Split('.')[1];
                _mus.FileType = _imgType;
            }

            if (_mus.Save())
            {
                if (fu_File.HasFile)
                {
                    String _path = Server.MapPath(String.Format(ConfigurationManager.AppSettings["MusicFilePath"], _mus.ID.ToString(), _imgType));
                    fu_File.SaveAs(_path);
                }
                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", "alert('Record has been updated successfully.');self.location = 'MusicList.aspx';", true);
            }
            else
            {
                lbl_Error.Text = "An unexpected error has occurred. Please try again.";
                lbl_Error.Visible = true;
            }
        }
    }
Example #2
0
 protected void Publish_Click(Object sender, EventArgs e)
 {
     Musics _st = null;
     foreach (GridViewRow I in dgMusics.Rows)
     {
         Label _id = (Label)I.FindControl("lbl_MusId");
         if (_id != null)
         {
             DropDownList _ddst = (DropDownList)I.FindControl("dd_Status");
             TextBox _sort = (TextBox)I.FindControl("txt_Sort");
             _st = new Musics(this.ConnectionString);
             _st.LitePopulate(_id.Text, false);
             if (!_st.Status.ToString().Equals(_ddst.SelectedValue))
             {
                 _st.Status = Convert.ToInt32(_ddst.SelectedValue);
             }
             if (Regex.IsMatch(_sort.Text, @"^\d+$"))
             {
                 _st.Sort = Convert.ToInt32(_sort.Text);
             }
             _st.Save();
         }
     }
     this.DataBind();
 }