📄 jl_gongzi.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_gongzi : Form
{
public JL_gongzi()
{
InitializeComponent();
}
private void label19_Click(object sender, EventArgs e)
{
this.Close();
}
private void gridviewcar()
{
//调用config配置文件对象dl连接对象
string dl = ConfigurationManager.AppSettings["sqlString"];
//创建connection对象con进行连接
SqlConnection con = new SqlConnection(dl);
//打开连接
con.Open();
//创建sql语句将信息从库中调出
string sql = "select pay_id as 序号,pay_account as 工人帐号,pay_kinds as 工种,pay_money as 工人工资,pay_ticket as 票款提成,pay_subsidy as 补助,pay_remark as 备注 from db_pay";
//创建执行对象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.textName.Clear();
this.textMoney.Clear();
this.textticheng.Clear();
this.textbuzhu.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;
}
private void btnCarAdd_Click(object sender, EventArgs e)
{
string Name = this.textName.Text.ToString().Trim();
string Kinds = this.textKinds.SelectedItem.ToString();
string Money = this.textMoney.Text.ToString().Trim();
string ticheng = this.textticheng.Text.ToString().Trim();
string buzhu = this.textbuzhu.Text.ToString().Trim();
string CarRemark = this.textCarRemark.Text.ToString().Trim();
if (Name != "")
{
if (ticheng != "")
{
if (Money != "")
{
if (buzhu != "")
{
if (CarRemark != "")
{
string sql = "insert into db_pay(pay_account,pay_kinds,pay_money,pay_ticket,pay_subsidy,pay_remark)values('" + Name + "','" + Kinds + "','" + Money + "','" + ticheng + "','" + buzhu + "','" + CarRemark + "')";
Car.ADU(sql);
//调用gridviewcar方法
this.gridviewcar();
MessageBox.Show("添加成功");
}
else
{
MessageBox.Show("请将信息添加完整 ");
}
}
else
{
MessageBox.Show("请将信息添加完整 ");
}
}
else
{
MessageBox.Show("请将信息添加完整 ");
}
}
else
{
MessageBox.Show("请将信息添加完整");
}
}
else
{
MessageBox.Show("请将信息添加完整");
}
}
private void btnCarCheck_Click(object sender, EventArgs e)
{
string CheckName = this.textCheckName.Text.ToString().Trim();
string sqlstr = "select pay_id as 序号,pay_account as 工人帐号,pay_kinds as 工种,pay_money as 工人工资,pay_ticket as 票款提成,pay_subsidy as 补助,pay_remark as 备注 from db_pay where 1 = 1";
//调用config配置文件对象dl连接对象
string dl = ConfigurationManager.AppSettings["sqlString"];
//创建connection对象con进行连接
SqlConnection con = new SqlConnection(dl);
//打开连接
con.Open();
if (CheckName != "")
{
sqlstr = sqlstr + "and pay_account = '" + CheckName + "'";
}
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 btnCarClear_Click(object sender, EventArgs e)
{
this.textCheckName.Clear();
}
private void JL_gongzi_Load(object sender, EventArgs e)
{
this.gridviewcar();
this.textKinds.SelectedItem = "经理";
}
private void btnDelete_Click(object sender, EventArgs e)
{
string Name = this.textName.Text.ToString().Trim();
string Kinds = this.textKinds.SelectedItem.ToString();
string Money = this.textMoney.Text.ToString().Trim();
string ticheng = this.textticheng.Text.ToString().Trim();
string buzhu = this.textbuzhu.Text.ToString().Trim();
string CarRemark = this.textCarRemark.Text.ToString().Trim();
if (Name != "")
{
if (ticheng != "")
{
if (Money != "")
{
if (buzhu != "")
{
if (CarRemark != "")
{
DialogResult drm = MessageBox.Show("确定要删除吗?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (drm == DialogResult.OK)
{
//获取选中的行的信息
object row = (object)this.GridView_Car.CurrentRow.Cells[0].Value.ToString().Trim();
//创建sql语句将信息从库中调出
string sql = "delete db_pay where pay_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("请将信息添加完整");
}
}
private void GridView_Car_CellClick(object sender, DataGridViewCellEventArgs e)
{
string Name = this.textName.Text.ToString().Trim();
string Kinds = this.textKinds.SelectedItem.ToString();
string Money = this.textMoney.Text.ToString().Trim();
string ticheng = this.textticheng.Text.ToString().Trim();
string buzhu = this.textbuzhu.Text.ToString().Trim();
string CarRemark = this.textCarRemark.Text.ToString().Trim();
//获取选中的行的信息
this.textName.Text = GridView_Car.CurrentRow.Cells[1].Value.ToString();
this.textKinds.SelectedItem = GridView_Car.CurrentRow.Cells[2].Value.ToString();
this.textMoney.Text = GridView_Car.CurrentRow.Cells[3].Value.ToString();
this.textticheng.Text = GridView_Car.CurrentRow.Cells[4].Value.ToString();
this.textbuzhu.Text = GridView_Car.CurrentRow.Cells[5].Value.ToString();
this.textCarRemark.Text = GridView_Car.CurrentRow.Cells[6].Value.ToString();
}
private void butUpdate_Click(object sender, EventArgs e)
{
string Name = this.textName.Text.ToString().Trim();
string Kinds = this.textKinds.SelectedItem.ToString();
string Money = this.textMoney.Text.ToString().Trim();
string ticheng = this.textticheng.Text.ToString().Trim();
string buzhu = this.textbuzhu.Text.ToString().Trim();
string CarRemark = this.textCarRemark.Text.ToString().Trim();
if (Name != "")
{
if (ticheng != "")
{
if (Money != "")
{
if (buzhu != "")
{
if (CarRemark != "")
{
DialogResult drm = MessageBox.Show("确定要修改吗?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (drm == DialogResult.OK)
{
//获取选中的行的信息
object row = (object)this.GridView_Car.CurrentRow.Cells[0].Value.ToString().Trim();
//创建sql语句将信息从库中调出
string sql = "update db_pay set pay_account ='" + Name + "', pay_kinds ='" + Kinds + "' , pay_money='" + Money + "',pay_ticket = '" + ticheng + "',pay_subsidy = '" + buzhu + "',pay_remark ='" + CarRemark + "' where pay_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("请选择要修改的选项");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -