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

📄 jl_car_massage.cs

📁 此系统开发了一个公交车管理系统。系统根据权限的不同
💻 CS
📖 第 1 页 / 共 2 页
字号:
            con.Open();
            if (CheckCarNumber != "")
            {
                sqlstr = sqlstr + " and  car_number = '"+ CheckCarNumber+"'";
               
            }
            if (dateTimeCheckBuyTime.Checked)
            {
                sqlstr = sqlstr + " and  car_buytime= '" + CheckBuyTime + "'";
               
            }
            if (CheckCarKinds != "")
            {
                sqlstr = sqlstr + "and car_rank = '"+CheckCarKinds+"'";
            }
            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
        #region 窗体加载
        private void JL_Car_Massage_Load(object sender, EventArgs e)
        {
            //调用gridviewcar方法
            this.gridviewcar();
            this.gridviewcar1();
        }
        #endregion
        #region 删除按钮
        private void btnCarDelete_Click(object sender, EventArgs e)
        {
            string CarNumber = this.textCarNumber.Text.ToString().Trim();
             //获取选中的行的信息
            string row = this.GridView_Car.CurrentRow.Cells[0].Value.ToString().Trim();
           DialogResult drm=MessageBox.Show("确定要删除此人信息吗?","",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
           if (drm == DialogResult.OK)
           {
               //调用config配置文件对象dl连接对象
               string dl = ConfigurationManager.AppSettings["sqlString"];
               //创建connection对象con进行连接
               SqlConnection con = new SqlConnection(dl);
               //打开连接
               con.Open();
               //创建sql语句将信息从库中调出
               string sql = "delete db_car where car_number  = '" + row + "'";

               //创建执行对象cmd
               SqlCommand cmd = new SqlCommand(sql, con);
               cmd.ExecuteNonQuery();
               con.Close();
               this.textCarNumber.Clear();
               this.textCarRemark.Clear();
               this.textRank.Clear();
               this.domainLoadMoney.Clear();
               this.domainUpDown1.Clear();
               this.gridviewcar1();
               MessageBox.Show("删除成功");
           }
           else
           {
               MessageBox.Show("请选择要删除的车辆");
           }
        }
        #endregion
        #region 修改按钮
        private void btnCarUpdate_Click(object sender, EventArgs e)
        {
            string CarNumber = this.textCarNumber.Text.ToString().Trim();
            DateTime BuyTime = Convert.ToDateTime(this.dateTime_BuyTime.Value.ToShortDateString());
            string Rank = this.textRank.Text.ToString().Trim();
            string LoadMoney = this.domainLoadMoney.Text.ToString().Trim();
            DateTime LoadFrist = Convert.ToDateTime(this.dateTime_LoadFrist.Value.ToShortDateString());
            DateTime LoadLast = Convert.ToDateTime(this.dateTime_LoadLast.Value.ToShortDateString());
            string SafeMoney = this.domainUpDown1.Text.ToString().Trim();
            DateTime baoxianFirst = Convert.ToDateTime(this.dateTime_baoxianFirst.Value.ToShortDateString());
            DateTime baoxianLast = Convert.ToDateTime(this.dateTime_baoxianLast.Value.ToShortDateString());
            string Remark = this.textCarRemark.Text.ToString().Trim();
            if (CarNumber != "")
            {
                if (Rank != "")
                {
                    if (LoadMoney != "")
                    {
                        if (SafeMoney != "")
                        {
                            if (Remark != "")
                            {
                              
                                //调用config配置文件对象dl连接对象
                                string dl = ConfigurationManager.AppSettings["sqlString"];
                                //创建connection对象con进行连接
                                SqlConnection con = new SqlConnection(dl);
                                //打开连接
                                con.Open();
                                string sql = "update db_car set car_number ='" + CarNumber + "', car_rank ='" + Rank + "' , car_fee='" + LoadMoney + "',car_buytime = '" + BuyTime + "',car_insurance = '" + SafeMoney + "',car_remark= '" + Remark + "',car_feestart ='" + LoadFrist + "', car_feeend ='" + LoadLast + "' , car_instart='" + baoxianFirst + "',car_inend = '" + baoxianLast + "' where car_number = '" + CarNumber + "'";
                                //创建执行对象cmd1
                                SqlCommand cmd1 = new SqlCommand(sql, con);
                                //返回受影响的数据
                                cmd1.ExecuteNonQuery();
                                con.Close();
                                this.gridviewcar1();
                                MessageBox.Show("修改成功");
                            }
                            else
                            {
                               
                              MessageBox.Show("请选择要修改的车辆 ");

                            }

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

                }
                else
                {
                    MessageBox.Show("请选择要修改的车辆");
                }
               
            }
            else
            {
                MessageBox.Show("请选择要修改的车辆");
            }
           
        }
        #endregion
        #region 点击gridview后显示要修改的内容
        private void GridView_Car_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string CarNumber = this.textCarNumber.Text.ToString().Trim();
            DateTime BuyTime = Convert.ToDateTime(this.dateTime_BuyTime.Value.ToShortDateString());
            string Rank = this.textRank.Text.ToString().Trim();
            string LoadMoney = this.domainLoadMoney.Text.ToString().Trim();
            DateTime LoadFrist = Convert.ToDateTime(this.dateTime_LoadFrist.Value.ToShortDateString());
            DateTime LoadLast = Convert.ToDateTime(this.dateTime_LoadLast.Value.ToShortDateString());
            string SafeMoney = this.domainUpDown1.Text.ToString().Trim();
            DateTime baoxianFirst = Convert.ToDateTime(this.dateTime_baoxianFirst.Value.ToShortDateString());
            DateTime baoxianLast = Convert.ToDateTime(this.dateTime_baoxianLast.Value.ToShortDateString());
            string Remark = this.textCarRemark.Text.ToString().Trim();
            //获取选中的行的信息
            this.textCarNumber.Text = GridView_Car.CurrentRow.Cells[0].Value.ToString();
            this.dateTime_BuyTime.Value = Convert.ToDateTime(GridView_Car.CurrentRow.Cells[1].Value.ToString());
            this.textRank.Text = GridView_Car.CurrentRow.Cells[2].Value.ToString();
            this.domainLoadMoney.Text = GridView_Car.CurrentRow.Cells[3].Value.ToString();
            this.dateTime_LoadFrist.Value = Convert.ToDateTime(GridView_Car.CurrentRow.Cells[4].Value.ToString());
            this.dateTime_LoadLast.Value = Convert.ToDateTime(GridView_Car.CurrentRow.Cells[5].Value.ToString());
            this.domainUpDown1.Text = GridView_Car.CurrentRow.Cells[6].Value.ToString();
            this.dateTime_baoxianFirst.Value = Convert.ToDateTime(GridView_Car.CurrentRow.Cells[7].Value.ToString());
            this.dateTime_baoxianLast.Value = Convert.ToDateTime(GridView_Car.CurrentRow.Cells[8].Value.ToString());
            this.textCarRemark.Text = GridView_Car.CurrentRow.Cells[9].Value.ToString();
        }
        #endregion
        #region 验证控件格式 显示出相应的错误信息
        //private void textCarNumber_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
        //{
        //    textCarNumber.Mask = "00000000";
        //    toolTip1.ToolTipTitle = "车牌号输入格式";
        //    toolTip1.Show("车牌号只能录入8位数", textCarNumber, textCarNumber.Location, 5000);
        //    textCarNumber.SelectAll();
        //    textCarNumber.SelectionStart = 0;
        //    textCarNumber.Focus();
        //}
        #endregion

    }
}

⌨️ 快捷键说明

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