⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jl_baoche.cs

📁 此系统开发了一个公交车管理系统。系统根据权限的不同
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace CarManage
{
    public partial class JL_Baoche : Form
    {
        public JL_Baoche()
        {
            InitializeComponent();
        }

        private void label19_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #region  创建gridviewcar()方法调用所有库中信息
        private void gridviewcar()
        {
            //调用config配置文件对象dl连接对象
            string dl = ConfigurationManager.AppSettings["sqlString"];
            //创建connection对象con进行连接
            SqlConnection con = new SqlConnection(dl);
            //打开连接
            con.Open();
            //创建sql语句将信息从库中调出
            string sql = "select rent_id as 序号,rent_carnumber as 车牌号码,rent_starttime as 起始时间,rent_endtime as 截止时间,rent_money as 包车费用,rent_startpalce as 起始地址,rent_endplace as 结束地址,rent_distance as 包车距离,rent_remark as 备注 from db_rent";
            //创建执行对象cmd
            SqlCommand cmd = new SqlCommand(sql, con);
            //创建读取器对象sdr
            SqlDataAdapter sdr = new SqlDataAdapter();
            //sdr的查询方法为cmd
            sdr.SelectCommand = cmd;
            //创建一个dataset容器
            DataSet ds = new DataSet();
            //填充数据ds
            sdr.Fill(ds);
            //绑定datagriview数据源为ds
            this.GridView_Car.DataSource = ds.Tables[0].DefaultView;
            //关闭连接
            con.Close();
            this.textCarNumber.Clear();
            this.textMoney.Clear();
            this.textAddressFrist.Clear();
            this.textAddressLast.Clear();
            this.textLoadTotal.Clear();
            this.textCarRemark.Clear();
            GridView_Car.Columns[0].Width = 80;
            GridView_Car.Columns[1].Width = 80;
            GridView_Car.Columns[2].Width = 80;
            GridView_Car.Columns[3].Width = 80;
            GridView_Car.Columns[4].Width = 80;
            GridView_Car.Columns[5].Width = 80;
            GridView_Car.Columns[6].Width = 80;
            GridView_Car.Columns[7].Width = 80;
            GridView_Car.Columns[8].Width = 80;
        }
        #endregion
        #region 修改按钮
        private void btnCarUpdate_Click(object sender, EventArgs e)
        {
            string CarNumber = this.textCarNumber.Text.ToString().Trim();
            DateTime FristTime = Convert.ToDateTime(this.dateTime_FristTime.Value.ToShortDateString());
            DateTime LastTime = Convert.ToDateTime(this.dateTime_LastTime.Value.ToShortDateString());
            string Money = this.textMoney.Text.ToString().Trim();
            string AddressFrist = this.textAddressFrist.Text.ToString().Trim();
            string AddressLast = this.textAddressLast.Text.ToString().Trim();
            string LoadTotal = this.textLoadTotal.Text.ToString().Trim();
            string CarRemark = this.textCarRemark.Text.ToString().Trim();
            DialogResult drm = MessageBox.Show("确定要修改吗?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (LoadTotal != "")
            {
                if (CarNumber != "")
                {
                    if (Money != "")
                    {
                        if (AddressFrist != "")
                        {
                            if (AddressLast != "")
                            {
                                if (CarRemark != "")
                                {
                                    if (drm == DialogResult.OK)
                                    {
                                        //获取选中的行的信息
                                        object row = (object)this.GridView_Car.CurrentRow.Cells[0].Value.ToString().Trim();
                                        //创建sql语句将信息从库中调出
                                        string sql = "update db_rent set rent_carnumber ='" + CarNumber + "', rent_starttime ='" + FristTime + "' , rent_endtime='" + LastTime + "',rent_money = '" + Money + "',rent_startpalce = '" + AddressFrist + "',rent_endplace ='" + AddressLast + "',rent_distance = '" + LoadTotal + "',rent_remark ='" + CarRemark + "' where rent_id ='" + row + "'";
                                        Car.ADU(sql);
                                        this.gridviewcar();
                                        MessageBox.Show("修改成功");
                                    }
                                    else
                                    {
                                        MessageBox.Show("请选择要修改的选项 ");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("请选择要修改的选项 ");
                                }
                            }
                            else
                            {

                                MessageBox.Show("请选择要修改的选项 ");

                            }

                        }
                        else
                        {
                            MessageBox.Show("请选择要修改的选项 ");
                        }

                    }
                    else
                    {
                        MessageBox.Show("请选择要修改的选项");
                    }

                }
                else
                {
                    MessageBox.Show("请选择要修改的选项");
                }
            }
            else
            {
                MessageBox.Show("请选择要修改的选项");
            }
        }
        #endregion
        #region 添加按钮
        private void btnCarAdd_Click(object sender, EventArgs e)
        {
            string CarNumber = this.textCarNumber.Text.ToString().Trim();
            DateTime FristTime = Convert.ToDateTime(this.dateTime_FristTime.Value.ToShortDateString());
            DateTime LastTime = Convert.ToDateTime(this.dateTime_LastTime.Value.ToShortDateString());
            string Money = this.textMoney.Text.ToString().Trim();
            string AddressFrist = this.textAddressFrist.Text.ToString().Trim();
            string AddressLast = this.textAddressLast.Text.ToString().Trim();
            string LoadTotal = this.textLoadTotal.Text.ToString().Trim();
            string CarRemark = this.textCarRemark.Text.ToString().Trim();         
            if (LoadTotal != "")
            {
                if (CarNumber != "")
                {
                    if (Money != "")
                    {
                        if (AddressFrist != "")
                        {
                            if (AddressLast != "")
                            {
                                if (CarRemark != "")
                                {
                                    string sql = "insert into db_rent(rent_carnumber,rent_starttime,rent_endtime,rent_money,rent_startpalce,rent_endplace,rent_distance,rent_remark)values( '" + CarNumber + "','" + FristTime + "','" + LastTime + "','" + Money + "','" + AddressFrist + "','" + AddressLast + "','" + LoadTotal + "','" + CarRemark + "')";
                                    Car.ADU(sql);
                                    //调用gridviewcar方法
                                    this.gridviewcar();
                                    MessageBox.Show("添加成功");
                                }
                                else
                                {
                                    MessageBox.Show("请将信息添加完整 ");
                                }
                            }
                            else
                            {

                                MessageBox.Show("请将信息添加完整 ");

                            }

                        }
                        else
                        {
                            MessageBox.Show("请将信息添加完整 ");
                        }

                    }
                    else
                    {
                        MessageBox.Show("请将信息添加完整");
                    }

                }
                else
                {
                    MessageBox.Show("请将信息添加完整");
                }
            }
            else
            {
                MessageBox.Show("请将信息添加完整");
            }

            
        }
        #endregion
        #region 显示选中行信息
        private void GridView_Car_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //获取选中的行的信息
            this.textCarNumber.Text = GridView_Car.CurrentRow.Cells[1].Value.ToString();
            this.dateTime_FristTime.Value = Convert.ToDateTime(GridView_Car.CurrentRow.Cells[2].Value.ToString());
            this.dateTime_LastTime.Value = Convert.ToDateTime(GridView_Car.CurrentRow.Cells[3].Value.ToString());
            this.textMoney.Text = GridView_Car.CurrentRow.Cells[4].Value.ToString();
            this.textAddressFrist.Text = GridView_Car.CurrentRow.Cells[5].Value.ToString();
            this.textAddressLast.Text = GridView_Car.CurrentRow.Cells[6].Value.ToString();
            this.textLoadTotal.Text = GridView_Car.CurrentRow.Cells[7].Value.ToString();
            this.textCarRemark.Text = GridView_Car.CurrentRow.Cells[8].Value.ToString();
        }
        #endregion
        #region 删除按钮
        private void btnCarDelete_Click(object sender, EventArgs e)
        {
            string CarNumber = this.textCarNumber.Text.ToString().Trim();
            DateTime FristTime = Convert.ToDateTime(this.dateTime_FristTime.Value.ToShortDateString());
            DateTime LastTime = Convert.ToDateTime(this.dateTime_LastTime.Value.ToShortDateString());
            string Money = this.textMoney.Text.ToString().Trim();
            string AddressFrist = this.textAddressFrist.Text.ToString().Trim();
            string AddressLast = this.textAddressLast.Text.ToString().Trim();
            string LoadTotal = this.textLoadTotal.Text.ToString().Trim();
            string CarRemark = this.textCarRemark.Text.ToString().Trim();
            DialogResult drm = MessageBox.Show("确定要删除吗?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (LoadTotal != "")
            {
                if (CarNumber != "")
                {
                    if (Money != "")
                    {
                        if (AddressFrist != "")
                        {
                            if (AddressLast != "")
                            {
                                if (CarRemark != "")
                                {
                                    if (drm == DialogResult.OK)
                                    {
                                        //获取选中的行的信息
                                        object row = (object)this.GridView_Car.CurrentRow.Cells[0].Value.ToString().Trim();
                                        //创建sql语句将信息从库中调出
                                        string sql = "delete db_rent where rent_id = '" + row + "'";
                                        Car.ADU(sql);
                                        this.gridviewcar();
                                        MessageBox.Show("删除成功");
                                    }
                                    else
                                    {
                                        MessageBox.Show("请选择要删除的选项 ");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("请选择要删除的选项 ");
                                }
                            }
                            else
                            {

                                MessageBox.Show("请选择要删除的选项 ");

                            }

                        }
                        else
                        {
                            MessageBox.Show("请选择要删除的选项 ");
                        }

                    }
                    else
                    {
                        MessageBox.Show("请选择要删除的选项");
                    }

                }
                else
                {
                    MessageBox.Show("请选择要删除的选项");
                }
            }
            else
            {
                MessageBox.Show("请选择要删除的选项");
            }
        }
        #endregion

        private void JL_Baoche_Load(object sender, EventArgs e)
        {
            this.gridviewcar();
        }
        #region 查询按钮
        private void btnCarCheck_Click(object sender, EventArgs e)
        {
            string CheckCarNumber = this.textCheckCarNumber.Text.ToString().Trim();
            string sqlstr ="select rent_id as 序号,rent_carnumber as 车牌号码,rent_starttime as 起始时间,rent_endtime as 截止时间,rent_money as 包车费用,rent_startpalce as 起始地址,rent_endplace as 结束地址,rent_distance as 包车距离,rent_remark as 备注 from db_rent where 1 = 1";
            //调用config配置文件对象dl连接对象
            string dl = ConfigurationManager.AppSettings["sqlString"];
            //创建connection对象con进行连接
            SqlConnection con = new SqlConnection(dl);
            //打开连接
            con.Open();
            if (CheckCarNumber != "")
            {
                sqlstr = sqlstr + "and rent_carnumber = '" + CheckCarNumber + "'";

            }
            SqlCommand cmd = new SqlCommand(sqlstr, con);
            //创建读取器对象sdr
            SqlDataAdapter sdr = new SqlDataAdapter();
            //sdr的查询方法为cmd
            sdr.SelectCommand = cmd;
            //创建一个dataset容器
            DataSet ds = new DataSet();
            //填充数据ds
            sdr.Fill(ds);
            //绑定datagriview数据源为ds
            this.GridViewCarCheckResult.DataSource = ds.Tables[0].DefaultView;
            //关闭连接
            con.Close();
        }
        #endregion
        #region 清空按钮
        private void btnCarClear_Click(object sender, EventArgs e)
        {
            this.textCheckCarNumber.Clear();
        }
        #endregion
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -