📄 jl_oil_ticket.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_Oil_Ticket : Form
{
public JL_Oil_Ticket()
{
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 oilticket_id as 序号,oilticket_number as 车牌号,oilticket_namer as 姓名 ,oilticket_person as 工人编号,oilticket_price as 车票单价,oilticket_count as 车票数量,oilticket_total as 车票钱数,oilticket_time as 车票输入时间,oilticket_aver as 耗油单价,oilticket_avercount as 总耗油量,oilticket_avertotal as 耗油总钱数,oilticket_avertime as 耗油输入时间 from db_oilticket";
//创建执行对象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.GridViewOil.DataSource = ds.Tables[0].DefaultView;
//关闭连接
con.Close();
this.text_CarNumber.Clear();
this.text_Name.Clear();
this.text_CarAver.Clear();
this.text_CarCount.Clear();
this.text_CarMoney.Clear();
this.text_OilAver.Clear();
this.text_OilCount.Clear();
this.text_OilMoney.Clear();
this.text_PersonNumber.Clear();
GridViewOil.Columns[0].Width = 80;
GridViewOil.Columns[1].Width = 80;
GridViewOil.Columns[2].Width = 80;
GridViewOil.Columns[3].Width = 80;
GridViewOil.Columns[4].Width = 80;
GridViewOil.Columns[5].Width = 80;
GridViewOil.Columns[6].Width = 80;
GridViewOil.Columns[7].Width = 110;
GridViewOil.Columns[8].Width = 80;
GridViewOil.Columns[9].Width = 80;
GridViewOil.Columns[10].Width = 100;
GridViewOil.Columns[11].Width = 110;
}
#endregion
#region 添加按钮
private void btnOiAdd_Click(object sender, EventArgs e)
{
string CarNumber = this.text_CarNumber.Text.ToString().Trim();
string PersonNumber = this.text_PersonNumber.Text.ToString().Trim();
string Name = this.text_Name.Text.ToString().Trim();
string CarAver = this.text_CarAver.Text.ToString().Trim();
string CarCount = this.text_CarCount.Text.ToString().Trim();
string CarMoney = this.text_CarMoney.Text.ToString().Trim();
DateTime TimeCarAdd = Convert.ToDateTime(this.dateTimeCarAdd.Value.ToShortDateString());
string OilAver = this.text_OilAver.Text.ToString().Trim();
string OilCount = this.text_OilCount.Text.ToString().Trim();
string OilMoney = this.text_OilMoney.Text.ToString().Trim();
DateTime TimeOilAdd = Convert.ToDateTime(this.dateTimeOilAdd.Value.ToShortDateString());
if (PersonNumber != "")
{
if (CarNumber != "")
{
if (Name != "")
{
if (CarAver != "")
{
if (CarCount != "")
{
if (CarMoney != "")
{
if (OilAver != "")
{
if (OilCount != "")
{
if (OilMoney != "")
{
if (OilMoney != "")
{
string sql = "insert into db_oilticket(oilticket_number,oilticket_person,oilticket_namer,oilticket_price,oilticket_count,oilticket_total,oilticket_time,oilticket_aver,oilticket_avercount,oilticket_avertotal,oilticket_avertime)values('" + CarNumber + "','" + PersonNumber + "','" + Name + "','" + CarAver + "','" + CarCount + "','" + CarMoney + "','" + TimeCarAdd + "','" + OilAver + "','" + OilCount + "','" + OilMoney + "','" + TimeOilAdd + "')";
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("请将信息添加完整 ");
}
}
else
{
MessageBox.Show("请将信息添加完整 ");
}
}
else
{
MessageBox.Show("请将信息添加完整");
}
}
else
{
MessageBox.Show("请将信息添加完整");
}
}
else
{
MessageBox.Show("请将信息添加完整");
}
}
#endregion
private void JL_Oil_Ticket_Load(object sender, EventArgs e)
{
this.gridviewcar();
}
#region 显示选中行信息
private void GridViewOil_CellClick(object sender, DataGridViewCellEventArgs e)
{
//获取选中的行的信息
this.text_CarNumber.Text = GridViewOil.CurrentRow.Cells[1].Value.ToString();
this.text_PersonNumber.Text = GridViewOil.CurrentRow.Cells[3].Value.ToString();
this.text_Name.Text = GridViewOil.CurrentRow.Cells[2].Value.ToString();
this.text_CarAver.Text = GridViewOil.CurrentRow.Cells[4].Value.ToString();
this.text_CarCount.Text = GridViewOil.CurrentRow.Cells[5].Value.ToString();
this.text_CarMoney.Text = GridViewOil.CurrentRow.Cells[6].Value.ToString();
this.dateTimeCarAdd.Value = Convert.ToDateTime(GridViewOil.CurrentRow.Cells[7].Value.ToString());
this.text_OilAver.Text = GridViewOil.CurrentRow.Cells[8].Value.ToString();
this.text_OilCount.Text = GridViewOil.CurrentRow.Cells[9].Value.ToString();
this.text_OilMoney.Text = GridViewOil.CurrentRow.Cells[10].Value.ToString();
this.dateTimeOilAdd.Value = Convert.ToDateTime(GridViewOil.CurrentRow.Cells[11].Value.ToString());
}
#endregion
#region 删除按钮
private void btnOilDelete_Click(object sender, EventArgs e)
{
string CarNumber = this.text_CarNumber.Text.ToString().Trim();
string Name = this.text_Name.Text.ToString().Trim();
string CarAver = this.text_CarAver.Text.ToString().Trim();
string CarCount = this.text_CarCount.Text.ToString().Trim();
string CarMoney = this.text_CarMoney.Text.ToString().Trim();
DateTime TimeCarAdd = Convert.ToDateTime(this.dateTimeCarAdd.Value.ToShortDateString());
string OilAver = this.text_OilAver.Text.ToString().Trim();
string OilCount = this.text_OilCount.Text.ToString().Trim();
string OilMoney = this.text_OilMoney.Text.ToString().Trim();
DateTime TimeOilAdd = Convert.ToDateTime(this.dateTimeOilAdd.Value.ToShortDateString());
if (CarNumber != "")
{
if (Name != "")
{
if (CarAver != "")
{
if (CarCount != "")
{
if (CarMoney != "")
{
if (OilAver != "")
{
if (OilCount != "")
{
if (OilMoney != "")
{
if (OilMoney != "")
{
DialogResult drm = MessageBox.Show("确定要删除吗?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (drm == DialogResult.OK)
{
//获取选中的行的信息
object row = (object)this.GridViewOil.CurrentRow.Cells[0].Value.ToString().Trim();
//创建sql语句将信息从库中调出
string sql = "delete db_oilticket where oilticket_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("请选择要删除的选项 ");
}
}
else
{
MessageBox.Show("请选择要删除的选项");
}
}
else
{
MessageBox.Show("请选择要删除的选项");
}
}
}
#endregion
#region 修改按钮
private void btnOilUpdate_Click(object sender, EventArgs e)
{
string CarNumber = this.text_CarNumber.Text.ToString().Trim();
string PersonNumber = this.text_PersonNumber.Text.ToString().Trim();
string Name = this.text_Name.Text.ToString().Trim();
string CarAver = this.text_CarAver.Text.ToString().Trim();
string CarCount = this.text_CarCount.Text.ToString().Trim();
string CarMoney = this.text_CarMoney.Text.ToString().Trim();
DateTime TimeCarAdd = Convert.ToDateTime(this.dateTimeCarAdd.Value.ToShortDateString());
string OilAver = this.text_OilAver.Text.ToString().Trim();
string OilCount = this.text_OilCount.Text.ToString().Trim();
string OilMoney = this.text_OilMoney.Text.ToString().Trim();
DateTime TimeOilAdd = Convert.ToDateTime(this.dateTimeOilAdd.Value.ToShortDateString());
if (PersonNumber != "")
{
if (CarNumber != "")
{
if (Name != "")
{
if (CarAver != "")
{
if (CarCount != "")
{
if (CarMoney != "")
{
if (OilAver != "")
{
if (OilCount != "")
{
if (OilMoney != "")
{
if (OilMoney != "")
{
DialogResult drm = MessageBox.Show("确定要修改吗?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (drm == DialogResult.OK)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -