C#可视化完成电影售票管理系统

前言

现在中国大部分的家庭都喜欢在家里置办属于自己风格的家庭影院。但是,仍有很多人喜欢到电影院去看电影。因为家里的气氛毕竟不如影院好。所以,现代家庭影院的出现并不会让电影院没有生路。

为了提高劳动的效率、节约成本、提高服务质量,特此开发这一管理系统。

界面一(查询/添加修改)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace Demo1
{
    public partial class FormAdd : Form
    {
        int MovieInfoId;
        DataSet ds = new DataSet();
        static string connstring = "server=.;database=MovieDb;Integrated Security=true";
        SqlConnection conn = new SqlConnection(connstring);

        public FormAdd()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //查询所有
            string sql = "select * from MovieInfo";
            SqlDataAdapter dap = new SqlDataAdapter(sql, connstring);
            dap.Fill(ds);
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = ds.Tables[0];
            conn.Close();
            conn.Dispose();
        }
        private void SelectAll()
        {
            //查询所有
            string sql = "select * from MovieInfo";
            SqlDataAdapter dap = new SqlDataAdapter(sql, connstring);

            dap.Fill(ds);
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = ds.Tables[0];
            conn.Close();
            conn.Dispose();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //添加事件
            string str = "server=.;database=MovieDB;Integrated Security=true";
            SqlConnection sqlConnection = new SqlConnection(str);
            sqlConnection.Open();
            string Sql = string.Format("insert into MovieInfo values('{0}','{1}','{2}','{3}','{4}')", textName.Text, TypeBox.Text, AreaBox.Text, textTime.Text, textAddTime.Text);
            if (textName.Text.Trim() == "" || TypeBox.Text.Trim() == "" || AreaBox.Text.Trim() == "" || textTime.Text.Trim() == "" || textAddTime.Text.Trim() == "")
            {
                MessageBox.Show("数据添加不完整!");
            }
            else
            {
                SqlCommand sqlCommand = new SqlCommand(Sql, sqlConnection);
                sqlCommand.ExecuteNonQuery();
                sqlConnection.Close();
                DataTable dt = (DataTable)dataGridView1.DataSource;
                dt.Rows.Clear();
                dataGridView1.DataSource = dt;
                string sql = "select * from MovieInfo";
                SqlDataAdapter dap = new SqlDataAdapter(sql, connstring);

                dap.Fill(ds);
                dataGridView1.AutoGenerateColumns = false;
                dataGridView1.DataSource = ds.Tables[0];
                conn.Close();
                conn.Dispose();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //修改
            string connStr = "server=.;database=MovieDB;Integrated Security=true";
            SqlConnection conn = new SqlConnection(connStr);
            conn.Open();
            string sql = string.Format("update dbo.MovieInfo set Name = '{0}',Type = '{1}',Area = '{2}',Duration ={3},ReleaseTime = '{4}' where ID ={5}", 
                textName.Text, TypeBox.Text, AreaBox.Text, textTime.Text, textAddTime.Text, MovieInfoId);
            SqlCommand sqlCommand = new SqlCommand(sql,conn);
            int i = sqlCommand.ExecuteNonQuery();
            if (i ==1)
            {
                MessageBox.Show("成功修改了" + textName.Text + "的信息");
                DataTable dt = (DataTable)dataGridView1.DataSource;
                dt.Rows.Clear();
                dataGridView1.DataSource = dt;
                SelectAll();
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }

        private void dataGridView1_Click(object sender, EventArgs e)
        {

           
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int i = dataGridView1.CurrentRow.Index;
            MovieInfoId = Convert.ToInt32(dataGridView1.Rows[i].Cells["MovieID"].Value);
            textName.Text = this.dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
            TypeBox.Text = this.dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
            AreaBox.Text = this.dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
            textTime.Text = this.dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
            textAddTime.Text = this.dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
        }
    }
}

界面二(模糊查询)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Demo1
{
    public partial class FormSelect : Form
    {
        DataSet ds = new DataSet();
        public FormSelect()
        {
            InitializeComponent();
        }

        private void FormSelect_Load(object sender, EventArgs e)
        {
            Connection();
        }

        private void Connection()
        {
            //数据库连接
            string connstring = "server=.;database=MovieDb;Integrated Security=true";
            SqlConnection conn = new SqlConnection(connstring);
            string sql = "select * from MovieInfo";
            SqlDataAdapter dap = new SqlDataAdapter(sql, connstring);
            dap.Fill(ds);
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = ds.Tables[0];
            conn.Close();
            conn.Dispose();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //模糊查询
            string Name = textBox1.Text;
            DataView dv = ds.Tables[0].DefaultView;
            dv.RowFilter = string.Format("Name like '%{0}%'", Name);
            this.dataGridView1.DataSource = dv;
            int result=dataGridView1.RowCount;
            //判断是否找到相关信息
            if (result==1)
            {
                MessageBox.Show(string.Format("没有找到和{0}相关的电影",Name));
            }
        }
    }
}

  • 2
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值