示例#1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);

            using (OLMSDBEntities oLMSDB = new OLMSDBEntities())
            {
                string name = MusicCreate.Text;

                var MusicCreaterName = oLMSDB.Artists.FirstOrDefault(s => s.Name == name);
                if (MusicCreaterName == null)
                {
                    Artists artistss = new Artists
                    {
                        Name = name
                    };
                    oLMSDB.Artists.Add(artistss);
                    if (oLMSDB.SaveChanges() == -1)
                    {
                        string strUrl = "<script>alert('歌手添加失败');</script>";
                        Response.Write(strUrl);
                    }
                }
                MusicCreaterName = oLMSDB.Artists.FirstOrDefault(s => s.Name == name);
                var artists = oLMSDB.Albums.FirstOrDefault(s => s.AlbumId == id);
                artists.Title    = MusicName.Text;
                artists.ArtistId = MusicCreaterName.ArtistId;
                artists.GenreId  = Convert.ToInt32(DropDownList1.SelectedValue);
                artists.Price    = Convert.ToDecimal(MusicPrice.Text);
                if (FileUpload1.HasFile)
                {
                    artists.AlbumArtUrl = "/Content/Images/" + FileUpload1.FileName.ToString();
                }

                if (oLMSDB.SaveChanges() > 0)
                {
                    string strUrl = "<script>alert('修改成功');window.location.href='MusicManager.aspx'</script>";
                    Response.Write(strUrl);
                }
                else
                {
                    string strUrl = "<script>alert('修改失败');</script>";
                    Response.Write(strUrl);
                }
            }
        }
示例#2
0
 public static bool deleteMusicType(int id)
 {
     using (OLMSDBEntities oLMSDB = new OLMSDBEntities())
     {
         var gener = oLMSDB.Genres.FirstOrDefault(t => t.GenreId == id);
         oLMSDB.Genres.Remove(gener);
         return(oLMSDB.SaveChanges() > 0);
     }
 }
示例#3
0
 public static bool deleteMusicManager(int id)
 {
     using (OLMSDBEntities oLMSDB = new OLMSDBEntities())
     {
         var gener = oLMSDB.Albums.FirstOrDefault(t => t.AlbumId == id);
         oLMSDB.Albums.Remove(gener);
         return(oLMSDB.SaveChanges() > 0);
     }
 }
示例#4
0
 internal static bool changeRole(int userId, int roleId)
 {
     using (OLMSDBEntities oLMSDB = new OLMSDBEntities())
     {
         Users user = oLMSDB.Users.FirstOrDefault(u => u.UserId == userId);
         user.RoleId = roleId;
         return(oLMSDB.SaveChanges() > 0);
     }
 }
示例#5
0
 public static bool updateMusicType(int id, string name, string detail)
 {
     using (OLMSDBEntities oLMSDB = new OLMSDBEntities())
     {
         var genres = oLMSDB.Genres.FirstOrDefault(t => t.GenreId == id);
         genres.Name        = name;
         genres.Description = detail;
         return(oLMSDB.SaveChanges() > 0);
     }
 }
示例#6
0
 public static bool addMusicType(string name, string detail)
 {
     using (OLMSDBEntities oLMSDB = new OLMSDBEntities())
     {
         oLMSDB.Genres.Add(new Genres
         {
             Name        = name,
             Description = detail
         });
         if (oLMSDB.SaveChanges() > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
示例#7
0
 public static bool register(string Id, string Pwd, string name, string phone)
 {
     Pwd = PasswordEncryption(Pwd);
     using (OLMSDBEntities db = new OLMSDBEntities())
     {
         Users users = db.Users.Add(new Users
         {
             LoginId     = Id,
             LoginPwd    = Pwd,
             UserName    = name,
             RoleId      = 2,
             Phone       = phone,
             DateCreated = DateTime.Now,
             UserStatus  = 1
         });
         if (db.SaveChanges() > 0)
         {
             return(true);
         }
         return(false);
     }
 }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                string fileName = FileUpload1.FileName;
                string endName  = Path.GetExtension(fileName).ToLower();
                if (endName != ".jpg")
                {
                    string strUrl = "<script>alert('图片格式必须是.JPG格式');</script>";
                    Response.Write(strUrl);
                }
                else
                {
                    FileUpload1.SaveAs(Server.MapPath("..\\Content\\Images\\" + fileName));
                    this.Image1.ImageUrl = "~/Content/Images/" + fileName;

                    using (OLMSDBEntities oLMSDB = new OLMSDBEntities())
                    {
                        string name = MusicCreate.Text;

                        var MusicCreaterName = oLMSDB.Artists.FirstOrDefault(s => s.Name == name);
                        if (MusicCreaterName == null)
                        {
                            Artists artists = new Artists
                            {
                                Name = name
                            };
                            oLMSDB.Artists.Add(artists);
                            if (oLMSDB.SaveChanges() == 0)
                            {
                                string strUrl = "<script>alert('歌手添加失败');</script>";
                                Response.Write(strUrl);
                            }
                        }
                        //else
                        //{
                        //    Albums albums = new Albums
                        //    {
                        //        GenreId = Convert.ToInt32(DropDownList1.SelectedValue),
                        //        ArtistId = MusicCreaterName.ArtistId,
                        //        Title = MusicName.Text,
                        //        Price = Convert.ToDecimal(MusicPrice.Text),
                        //        AlbumArtUrl = FileUpload1.FileName

                        //    };
                        //    oLMSDB.Albums.Add(albums);
                        //    if (oLMSDB.SaveChanges() > 0)
                        //    {
                        //        string strUrl = "<script>alert('添加成功');window.location.href='../HoTaiYingYYM.aspx'</script>";
                        //        Response.Write(strUrl);
                        //    }
                        //    else
                        //    {
                        //        string strUrl = "<script>alert('添加失败');</script>";
                        //        Response.Write(strUrl);
                        //    }
                        //}
                        var    artistId = oLMSDB.Artists.FirstOrDefault(s => s.Name == name);
                        Albums albums   = new Albums
                        {
                            GenreId     = Convert.ToInt32(DropDownList1.SelectedValue),
                            ArtistId    = artistId.ArtistId,
                            Title       = MusicName.Text,
                            Price       = Convert.ToDecimal(MusicPrice.Text),
                            AlbumArtUrl = "/Content/Images/" + FileUpload1.FileName.ToString()
                        };
                        oLMSDB.Albums.Add(albums);
                        if (oLMSDB.SaveChanges() > 0)
                        {
                            string strUrl = "<script>alert('添加成功');window.location.href='MusicManager.aspx'</script>";
                            Response.Write(strUrl);
                        }
                        else
                        {
                            string strUrl = "<script>alert('添加失败');</script>";
                            Response.Write(strUrl);
                        }
                    }
                }
            }
        }