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;
namespace Car
{
public partial class frmCheck : Form
{
DataSet dataset;
SqlDataAdapter dataAdapter;
public frmCheck()
{
InitializeComponent();
}
private void frmCheck_Load(object sender, EventArgs e)
{
string sql = "SELECT CarsID,Brand,Type,Discharge,GearBox,OilUser,Price from CarsInfo";
dataAdapter = new SqlDataAdapter(sql, DBHelper.connection);
dataset = new DataSet("CarsManager");
dataAdapter.Fill(dataset, "CarsInfo");
dgvCheck.DataSource=dataset.Tables["CarsInfo"];
}
private void btnCheck_Click(object sender, EventArgs e)
{
if (cboType.Text.Trim()=="全部")
{
txtTrem.ReadOnly = true;
dataset.Tables["CarsInfo"].Clear();
string sql = "SELECT * FROM CarsInfo";
try
{
dataAdapter = new SqlDataAdapter(sql,DBHelper.connection);
DBHelper.connection.Open();
dataAdapter.Fill(dataset, "CarsInfo");
dgvCheck.DataSource=dataset.Tables["CarsInfo"];
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
DBHelper.connection.Close();
}
}
if (cboType.Text.Trim() == "品牌")
{
txtTrem.ReadOnly=false;
dataset.Tables["CarsInfo"].Clear();
string sql = string.Format("SELECT * from CarsInfo where brand='{0}'",txtTrem.Text);
try
{
dataAdapter=new SqlDataAdapter(sql,DBHelper.connection);
DBHelper.connection.Open();
dataAdapter.Fill(dataset,"CarsInfo");
dgvCheck.DataSource=dataset.Tables["CarsInfo"];
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
DBHelper.connection.Close();
}
}
if (cboType.Text.Trim()=="排量")
{
txtTrem.ReadOnly = false;
dataset.Tables["CarsInfo"].Clear();
string sql = string.Format("SELECT CarsID,Brand,Type,Discharge,GearBox,OilUser,Price from CarsInfo where Discharge='{0}'", txtTrem.Text);
try
{
dataAdapter=new SqlDataAdapter(sql,DBHelper.connection);
DBHelper.connection.Open();
dataAdapter.Fill(dataset,"CarsInfo");
dgvCheck.DataSource=dataset.Tables["CarsInfo"];
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
DBHelper.connection.Close();
}
}
else if (cboType.Text.Trim() == " ")
{
MessageBox.Show("请输入查询条件!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void btnRest_Click(object sender, EventArgs e)
{
dataset.Tables["CarsInfo"].Clear();
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}