C#可视化 户外俱乐部活动管理系统(具体做法及全部代码)

题目:

 

 

 效果图:

 

 数据库:

 

 

做法:

该题显示的列是五个列,但是需要通过id来进行删除所以我们需要添加id列但是需要设置为不可见,取消打勾,这样子能够按照id进行删除操作,但是不显示

 

新增活动

 

新增活动窗口关闭时立即刷新表中的内容

 private void button1_Click(object sender, EventArgs e)
        {
            Form2 f = new Form2();
            f.ShowDialog();
            //这三行代码意思为查找数据库中所有数据并显示
            string sql = "select * from Activities ";
            DataSet ds = DBHelper.ds(sql);
            this.dataGridView1.DataSource = ds.Tables[0];
        }

提交活动

需要用datetimepicker.value.toshortdatestring()方法把时间转为字符串然后才能进行过数据库添加操作

  private void button1_Click(object sender, EventArgs e)
        {
            string a = dateTimePicker1.Value.ToShortDateString();
            string b = dateTimePicker2.Value.ToShortDateString();
            if (textBox1.Text==""||textBox4.Text==""||textBox5.Text==""||a.Length<1||b.Length<1)
            {
                MessageBox.Show("所有信息均不为空,请重新填写!","失败提示",MessageBoxButtons.OK,MessageBoxIcon.Information);//分别对应提示信息,左上角提示,选项,图标
                return;
            }


            string sql = string.Format("insert Activities values('{0}','{1}','{2}','{3}','{4}')", textBox1.Text, textBox4.Text, textBox5.Text, a, b);
            if (DBHelper.noquery(sql))
            {
                //分别对应提示信息,左上角提示,选项,图标
                MessageBox.Show("添加成功","成功提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            } 


        }

右键删除操作

需要先要拿到隐藏列id的单元格值,再用该隐藏格的值进行删除
                string str = this.dataGridView1.CurrentRow.Cells["id"].Value.ToString();//获取列名为id的单元格名字,调用方法进行删除

private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                string str = this.dataGridView1.CurrentRow.Cells["id"].Value.ToString();//获取列名为id的单元格名字,调用方法进行删除
                string sql = string.Format("delete Activities where id='{0}'", str);
                DBHelper.noquery(sql);
            }
            catch (Exception eee )
            {

                MessageBox.Show(eee.ToString());
            }
          

            string sqlstr = "select * from Activities ";
            DataSet ds = DBHelper.ds(sqlstr);
            this.dataGridView1.DataSource = ds.Tables[0];

        }

datagirdview设置

 

首先设置datagridview的这三个属性

    1. AutoSizeColumsMode = Fill 设置每列单元格宽度平铺

    1. RowHeadersVisible = False 取消列表最左侧列显示

    1. SelectionMode = FullRowSelect 设置单元格选中模式为整行选中

 

全部代码: 

 DBHelper类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace a
{
    class DBHelper
    {
        public static string connstr = "server=.;database=Club;uid=sa;pwd=123456";
        public static SqlConnection conn = null;
        public static void init() {
            if (conn==null)
            {
                conn = new SqlConnection(connstr);
            }
            conn.Close();
            conn.Open();
        }
        public static bool noquery(string sql) {
            init();
            SqlCommand cod = new SqlCommand(sql,conn);
          int ret=  cod.ExecuteNonQuery();
          conn.Close();
          if (ret>0)
          {
              return true;
          }
          else
          {
              return false;
          }
        }
        public static DataSet ds(string sql) {
            init();
            DataSet ds=new DataSet();
            SqlDataAdapter t = new SqlDataAdapter(sql,conn);
            t.Fill(ds);
            conn.Close();
            return ds;
        
        }


    }
}

 From1主窗体代码

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

namespace a
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.dataGridView1.AutoGenerateColumns=false;//自动取消列
            string sql = "select * from Activities ";
          DataSet ds=  DBHelper.ds(sql);
          this.dataGridView1.DataSource = ds.Tables[0];

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f = new Form2();
            f.ShowDialog();
            //这三行代码意思为查找数据库中所有数据并显示
            string sql = "select * from Activities ";
            DataSet ds = DBHelper.ds(sql);
            this.dataGridView1.DataSource = ds.Tables[0];
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                string str = this.dataGridView1.CurrentRow.Cells["id"].Value.ToString();//获取列名为id的单元格名字,调用方法进行删除
                string sql = string.Format("delete Activities where id='{0}'", str);
                DBHelper.noquery(sql);
            }
            catch (Exception eee )
            {

                MessageBox.Show(eee.ToString());
            }
          

            string sqlstr = "select * from Activities ";
            DataSet ds = DBHelper.ds(sqlstr);
            this.dataGridView1.DataSource = ds.Tables[0];

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}

添加代码:

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

namespace a
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string a = dateTimePicker1.Value.ToShortDateString();
            string b = dateTimePicker2.Value.ToShortDateString();
            if (textBox1.Text==""||textBox4.Text==""||textBox5.Text==""||a.Length<1||b.Length<1)
            {
                MessageBox.Show("所有信息均不为空,请重新填写!","失败提示",MessageBoxButtons.OK,MessageBoxIcon.Information);//分别对应提示信息,左上角提示,选项,图标
                return;
            }


            string sql = string.Format("insert Activities values('{0}','{1}','{2}','{3}','{4}')", textBox1.Text, textBox4.Text, textBox5.Text, a, b);
            if (DBHelper.noquery(sql))
            {
                //分别对应提示信息,左上角提示,选项,图标
                MessageBox.Show("添加成功","成功提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            } 


        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }
    }
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
很抱歉,由于酒店管理系统是一个比较大的项目,需要根据具体需求进行开发,所以无法提供完整的代码。不过,我可以给你一些参考: 1. 数据库设计 酒店管理系统需要使用数据库来存储数据,一般需要设计以下表: - 客房信息表(Room):包含房间编号、房间类型、房间价格等字段。 - 客户信息表(Customer):包含客户编号、客户姓名、联系方式等字段。 - 预订信息表(Reservation):包含预订编号、客户编号、房间编号、入住日期、离店日期等字段。 - 入住信息表(CheckIn):包含入住编号、客户编号、房间编号、入住日期、离店日期、入住人数等字段。 2. 用户界面设计 可以使用 Windows Form 或者 WPF 来进行界面设计,主要包括以下模块: - 登录模块:用户需要输入用户名和密码才能登录系统。 - 房间管理模块:可以对客房信息进行添加、修改、删除、查询等操作。 - 客户管理模块:可以对客户信息进行添加、修改、删除、查询等操作。 - 预订管理模块:可以对预订信息进行添加、修改、删除、查询等操作。 - 入住管理模块:可以对入住信息进行添加、修改、删除、查询等操作。 3. 代码实现 在代码实现方面,需要使用 C# 的面向对象编程思想,将不同的功能模块封装成类。以下是一些示例代码: - 客房信息类(Room): ```csharp public class Room { public int RoomId { get; set; } public string RoomType { get; set; } public double RoomPrice { get; set; } } ``` - 客户信息类(Customer): ```csharp public class Customer { public int CustomerId { get; set; } public string CustomerName { get; set; } public string Contact { get; set; } } ``` - 预订信息类(Reservation): ```csharp public class Reservation { public int ReservationId { get; set; } public int CustomerId { get; set; } public int RoomId { get; set; } public DateTime CheckInDate { get; set; } public DateTime CheckOutDate { get; set; } } ``` - 入住信息类(CheckIn): ```csharp public class CheckIn { public int CheckInId { get; set; } public int CustomerId { get; set; } public int RoomId { get; set; } public DateTime CheckInDate { get; set; } public DateTime CheckOutDate { get; set; } public int NumberOfPeople { get; set; } } ``` 以上是一个简单的酒店管理系统的示例代码具体实现还需要根据实际需求进行调整。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

W少年没有乌托邦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值