/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Music DataRowToModel(DataRow row) { Maticsoft.Model.Music model=new Maticsoft.Model.Music(); if (row != null) { if(row["ID"]!=null && row["ID"].ToString()!="") { model.ID=int.Parse(row["ID"].ToString()); } if(row["MusicName"]!=null) { model.MusicName=row["MusicName"].ToString(); } if(row["Player"]!=null) { model.Player=row["Player"].ToString(); } if(row["Album"]!=null) { model.Album=row["Album"].ToString(); } if(row["Lyc"]!=null) { model.Lyc=row["Lyc"].ToString(); } if(row["MicUrl"]!=null) { model.MicUrl=row["MicUrl"].ToString(); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Music GetModel(int ID) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 ID,MusicName,Player,Album,Lyc,MicUrl from Music "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4) }; parameters[0].Value = ID; Maticsoft.Model.Music model=new Maticsoft.Model.Music(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }
private void btnSave_Click(object sender, EventArgs e) { SetControlEnabled(false); try { if (common.musicmode == "update") { Maticsoft.Model.Music model = music.GetModel(int.Parse(common.musicid)); model.Album = txtAlbum.Text; //if (lyc) //{ // string lycpath; // common.UploadFile(txtLyc.Text, progressBar1, label1, out lycpath,true); model.Lyc = lycpath; //} //if (mp3) //{ // string musicpath; // common.UploadFile(txtMusic.Text, progressBar2, label2, out musicpath,true); model.MicUrl = musicpath; //} model.MusicName = txtMusicName.Text; model.Player = txtPlayer.Text; music.Update(model); MessageBox.Show("保存成功"); this.Close(); } else { Maticsoft.Model.Music model = new Maticsoft.Model.Music(); model.Album = txtAlbum.Text; //if (lyc) //{ // progressBar1.Visible = true; // string lycpath; // common.UploadFile(txtLyc.Text, progressBar1, label1, out lycpath,true); // progressBar1.Visible = false; model.Lyc = lycpath; //} //if (mp3) //{ // string musicpath; // progressBar2.Visible = true; // if (common.UploadFile(txtMusic.Text, progressBar2, label2, out musicpath,true)) // { model.MicUrl = musicpath; // } // progressBar2.Visible = false; //} model.MusicName = txtMusicName.Text; model.Player = txtPlayer.Text; music.Add(model); MessageBox.Show("保存成功"); this.Close(); } SetControlEnabled(true); } catch { SetControlEnabled(true); MessageBox.Show("保存失败"); } }