📄 cw_baoche.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 CW_Baoche : Form
{
public CW_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
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("请将信息添加完整");
}
}
private void button2_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();
}
private void button3_Click(object sender, EventArgs e)
{
this.textCheckCarNumber.Clear();
}
private void CW_Baoche_Load(object sender, EventArgs e)
{
this.gridviewcar();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -