Exemple #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //非空验证
            if (txtName.Text == "" || Convert.ToInt32(cmbSingerType.SelectedValue) == -1)
            {
                HintMessageBox.Warning_hint("请填写完整带*项的信息!!");
                return;
            }
            //获取性别
            string sex;

            if (rdoMale.Checked == true)
            {
                sex = rdoMale.Text;
            }
            else if (rdoFemale.Checked == true)
            {
                sex = rdoFemale.Text;
            }
            else
            {
                sex = rdoCom.Text;
            }
            //获取用户输入的值
            string name       = txtName.Text.Trim();                                           //获取歌手姓名
            int    singerType = Convert.ToInt32(cmbSingerType.SelectedValue);                  //歌手类型

            photoPath = photoPath == "" ? System.IO.Path.GetFullPath(ofd.FileName): photoPath; //歌手写真的路径
            string describe = txtDescribe.Text.Trim();                                         //歌手简介
            //sql语句
            string sql = string.Empty;

            switch (btnAdd.Text.Trim())
            {
            case "添加":
                //执行数据库插入操作的sql语句
                sql = string.Format("insert singer_info values('{0}','{1}','{2}','{3}','{4}')", name, singerType, sex, photoPath, describe);
                break;

            case "修改":
                sql = string.Format("update dbo.singer_info set singer_name = '{0}',singertype_id = '{1}',singer_sex = '{2}',singer_photo_url = '{3}',singer_Describe = '{4}' where singer_id = '{5}'", name, singerType, sex, photoPath, describe, singer_id);
                break;
            }
            if (db.ExecuteNonQuery(sql) > 0)
            {
                HintMessageBox.Information_hint(btnAdd.Text.Trim() + "歌手信息成功!!");
            }
            else
            {
                HintMessageBox.Warning_hint(btnAdd.Text.Trim() + "失败!!");
            }
        }
Exemple #2
0
        /// <summary>
        /// 保存修改按钮单击事件
        /// </summary>
        /// <param name="sender">事件源</param>
        /// <param name="e">事件参数</param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            ////如果歌曲路径字符串为空则更改歌手写真路径
            //sql = song_path == string.Empty ? string.Format("update singer_info set singer_photo_url = '{0}'", txtNewPath.Text) : string.Format("update song_info set song_url = '{0}'", txtNewPath.Text);
            //if (db.ExecuteNonQuery(sql)>0)
            //{
            //    HintMessageBox.Information_hint("修改路径成功!!");
            //    this.Close();
            //}
            //else
            //{
            //    HintMessageBox.Information_hint("修改路径失败!!");
            //}
            //需要将数据库中所有的记录查询出来,然后截取路径到文件名。
            //显示修改进度条
            pnlJinDu.Visible = true;
            //清空listview视图
            lvInfo.Items.Clear();
            //sql语句-->查询
            string sql = string.Empty;

            sql = song_path == null?string.Format("select singer_id,singer_photo_url from singer_info", txtNewPath.Text) : string.Format("select song_id,song_url from song_info", txtNewPath.Text);

            DataSet ds = db.GetDataSet(sql);//获得DataSet对象

            //修改每条记录的绝对路径
            for (int i = 0; i < ds.Tables["temp"].Rows.Count; i++)
            {
                string path     = ds.Tables["temp"].Rows[i][1].ToString();                                                                                                                                                                                                                       //获取记录的路径
                string fileName = path.Substring(path.LastIndexOf("\\") + 1);                                                                                                                                                                                                                    //获取文件名
                int    id       = Convert.ToInt32(ds.Tables["temp"].Rows[i][0]);                                                                                                                                                                                                                 //记录的id
                //sql语句 -->更新数据
                string sql_ = singer_photo_path == null?string.Format("update song_info set song_url = '{0}' where song_id = '{1}'", txtNewPath.Text + fileName, id) : string.Format("update singer_info set singer_photo_url = '{0}' where singer_id = '{1}'", txtNewPath.Text + fileName, id); //更新进行更新操作的sql语句

                //修改数据到数据库
                ListViewItem item = new ListViewItem();
                item.Text = path;                              //修改前的路径
                item.SubItems.Add("-->");
                item.SubItems.Add(txtNewPath.Text + fileName); //修改后的路径
                int result = db.ExecuteNonQuery(sql_);
                item.SubItems.Add(result > 0 ? "修改成功!": "修改失败!!");
                lvInfo.Items.Add(item);
            }
        }
Exemple #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //非空验证
            if (txtSongName.Text == "" || txtPinYin.Text == "" || Convert.ToInt32(cmbSongType.SelectedValue) == -1 || txtSongFileName.Text == "")
            {
                HintMessageBox.Information_hint("请填写完整带 * 的项!!");
                return;
            }
            //获取用户输入的值
            string songName     = txtSongName.Text;
            string pinYin       = txtPinYin.Text;
            string songFileName = txtSongFileName.Text;
            int    singer       = Convert.ToInt32(db.ExecuteScalar(string.Format("select singer_id from dbo.singer_info where singer_Name = '{0}'", txtSinger.Text)));
            int    songtype     = Convert.ToInt32(cmbSongType.SelectedValue);
            int    wordNum      = Convert.ToInt32(nudWordCount.Value);
            string sql          = "";

            switch (btnSave.Text)
            {
            case "保存":
                sql = string.Format("insert dbo.song_info values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", songName, pinYin, wordNum, songtype, singer, songFileName, 0);
                break;

            case "保存修改":
                sql = string.Format("UPDATE [MyKTV].[dbo].[song_info]  SET [song_name] = '{0}',[song_ab] ='{1}',[song_word_count] = '{2}',[songtype_id] = '{3}',[singer_id] = '{4}',[song_url] = '{5}' WHERE song_id='{6}'", songName, pinYin, wordNum, songtype, singer, songFileName, song_id);
                break;
            }
            if (db.ExecuteNonQuery(sql) > 0)
            {
                HintMessageBox.Information_hint(btnSave.Text + "歌曲成功!!");
            }
            else
            {
                HintMessageBox.Warning_hint(btnSave.Text + "歌曲失败!!");
            }
        }