第一天写的WINFORM的项目
来源:互联网 发布:欧美彩妆品牌知乎 编辑:程序博客网 时间:2024/05/18 00:25
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.OleDb;
using System.Text.RegularExpressions;
using System.IO;
namespace WindowsApplication15
{
public partial class zhichu : Form
{
public zhichu()
{
InitializeComponent();
}
private void zhichu_Load(object sender, EventArgs e)
{
du();
}
public void du()
{
string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=access/wajueji.mdb";
OleDbConnection myconnection = new OleDbConnection(strConnection);
OleDbDataAdapter da = new OleDbDataAdapter("select id,联系人,FORMAT(工作日期,'yyyy-mm-dd') as 工作日期 ,工作地点,工作时间,台班单价,加油金额,拖车司机,保养总表时间,其他费用,合计金额 from 大宇挖掘机", myconnection);
DataSet ds = new DataSet();
da.Fill(ds, "dsTable");
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
private void button2_Click(object sender, EventArgs e)
{
try
{
OleDbConnection myconnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=access/wajueji.mdb");
myconnection.Open();
string s = "delete from 大宇挖掘机 where ID=" + dataGridView1[dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex].Value;
OleDbCommand mycommnad = new OleDbCommand(s, myconnection);
mycommnad.ExecuteNonQuery();
myconnection.Close();
MessageBox.Show("删除成功");
du();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
}
}
private void textBox4_Validating(object sender, CancelEventArgs e)
{
string a = @"^[0-9]*[1-9][0-9]*$";
Regex r = new Regex(a, RegexOptions.IgnoreCase);
Match m = r.Match(textBox4.Text); //进行正则匹配
if (m.Success)
{
}
else
{
MessageBox.Show("只能输入正整数");
textBox4.Text = null;
textBox4.Focus();
}
}
private void textBox5_Validating(object sender, CancelEventArgs e)
{
string a = @"^[0-9]*[1-9][0-9]*$";
Regex r = new Regex(a, RegexOptions.IgnoreCase);
Match m = r.Match(textBox5.Text); //进行正则匹配
if (m.Success)
{
}
else
{
MessageBox.Show("只能输入正整数");
textBox5.Text = null;
textBox5.Focus();
}
}
private void textBox7_Validating(object sender, CancelEventArgs e)
{
string a = @"^/d+(/./d+)?$";
Regex r = new Regex(a, RegexOptions.IgnoreCase);
Match m = r.Match(textBox7.Text); //进行正则匹配
if (m.Success)
{
}
else
{
MessageBox.Show("只能输入符点数");
textBox7.Text = null;
textBox7.Focus();
}
}
private void textBox9_Validating(object sender, CancelEventArgs e)
{
string a = @"^[0-9]*[1-9][0-9]*$";
Regex r = new Regex(a, RegexOptions.IgnoreCase);
Match m = r.Match(textBox9.Text); //进行正则匹配
if (m.Success)
{
}
else
{
MessageBox.Show("只能输入正整数");
textBox9.Text = null;
textBox9.Focus();
}
}
private void textBox2_Validating(object sender, CancelEventArgs e)
{
string a = @"^[1-9]/d{3}-(1[0-2]|0?[1-9])-(0?[1-9]|[1-2]/d|3[0-1])$";
Regex r = new Regex(a, RegexOptions.IgnoreCase);
Match m = r.Match(textBox2.Text); //进行正则匹配
if (m.Success)
{
}
else
{
MessageBox.Show("请输入正确的格式例如2008-01-01");
textBox2.Text = null;
textBox2.Focus();
}
}
private void textBox3_Validating(object sender, CancelEventArgs e)
{
string a = @"^([0-1]{1}[0-9]{1}|[2]{1}[0-3]{1}):[0-5]{1}[0-9]{1}(:[0-5]{1}[0-9]{1})*$";
Regex r = new Regex(a, RegexOptions.IgnoreCase);
Match m = r.Match(textBox3.Text); //进行正则匹配
if (m.Success)
{
}
else
{
MessageBox.Show("请输入正确的格式例如20:22");
textBox3.Text = null;
textBox3.Focus();
}
}
private void button5_Click(object sender, EventArgs e)
{
try
{
OleDbConnection myconnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=access/wajueji.mdb");
myconnection.Open();
string s = "insert into 大宇挖掘机(联系人,工作日期,工作时间,台班单价,加油金额,拖车司机,保养总表时间,其他费用,合计金额,工作地点)values('" + textBox1.Text.Trim() + "','" + textBox2.Text.Trim() + "','" + textBox3.Text.Trim() + "','" + textBox4.Text.Trim() + "','" + textBox5.Text.Trim() + "','" + textBox6.Text.Trim() + "','" + textBox7.Text.Trim() + "','" + textBox8.Text.Trim() + "','" + textBox9.Text.Trim() + "','" + textBox10.Text + "')";
OleDbCommand mycommnad = new OleDbCommand(s, myconnection);
mycommnad.ExecuteNonQuery();
myconnection.Close();
MessageBox.Show("添加成功");
du();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void button3_Click(object sender, EventArgs e)
{
panel1.Visible = false;
panel2.Visible = true;
try
{
string s = "select 联系人,FORMAT(工作日期,'yyyy-mm-dd') as 工作日期,工作地点,FORMAT(工作时间,'HH:mm:ss') as 工作时间,台班单价,加油金额,拖车司机,保养总表时间,其他费用,合计金额,id from 大宇挖掘机 where ID=" + dataGridView1[dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex].Value;
OleDbConnection myconnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=access/wajueji.mdb");
myconnection.Open();
OleDbDataAdapter mycommand = new OleDbDataAdapter(s, myconnection);
DataSet ds = new DataSet();
mycommand.Fill(ds, "dsTable");
textBox11.Text = ds.Tables["dsTable"].Rows[0][0].ToString();
textBox12.Text = ds.Tables["dsTable"].Rows[0][1].ToString();
textBox13.Text = ds.Tables["dsTable"].Rows[0][2].ToString();
textBox14.Text = ds.Tables["dsTable"].Rows[0][3].ToString();
textBox15.Text = ds.Tables["dsTable"].Rows[0][4].ToString();
textBox16.Text = ds.Tables["dsTable"].Rows[0][5].ToString();
textBox17.Text = ds.Tables["dsTable"].Rows[0][6].ToString();
textBox18.Text = ds.Tables["dsTable"].Rows[0][7].ToString();
textBox19.Text = ds.Tables["dsTable"].Rows[0][8].ToString();
textBox20.Text = ds.Tables["dsTable"].Rows[0][9].ToString();
label21.Text = ds.Tables["dsTable"].Rows[0][10].ToString();
myconnection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
panel1.Visible = true;
panel2.Visible = false;
}
private void textBox15_Validating(object sender, CancelEventArgs e)
{
string a = @"^[0-9]*[1-9][0-9]*$";
Regex r = new Regex(a, RegexOptions.IgnoreCase);
Match m = r.Match(textBox15.Text); //进行正则匹配
if (m.Success)
{
}
else
{
MessageBox.Show("只能输入正整数");
textBox15.Text = null;
textBox15.Focus();
}
}
private void textBox16_Validating(object sender, CancelEventArgs e)
{
string a = @"^[0-9]*[1-9][0-9]*$";
Regex r = new Regex(a, RegexOptions.IgnoreCase);
Match m = r.Match(textBox16.Text); //进行正则匹配
if (m.Success)
{
}
else
{
MessageBox.Show("只能输入正整数");
textBox16.Text = null;
textBox16.Focus();
}
}
private void textBox12_Validating(object sender, CancelEventArgs e)
{
string a = @"^[1-9]/d{3}-(1[0-2]|0?[1-9])-(0?[1-9]|[1-2]/d|3[0-1])$";
Regex r = new Regex(a, RegexOptions.IgnoreCase);
Match m = r.Match(textBox12.Text); //进行正则匹配
if (m.Success)
{
}
else
{
MessageBox.Show("请输入正确的格式例如2008-01-01");
textBox12.Text = null;
textBox12.Focus();
}
}
private void textBox14_Validating(object sender, CancelEventArgs e)
{
string a = @"^([0-1]{1}[0-9]{1}|[2]{1}[0-3]{1}):[0-5]{1}[0-9]{1}(:[0-5]{1}[0-9]{1})*$";
Regex r = new Regex(a, RegexOptions.IgnoreCase);
Match m = r.Match(textBox14.Text); //进行正则匹配
if (m.Success)
{
}
else
{
MessageBox.Show("请输入正确的格式例如20:22");
textBox14.Text = null;
textBox14.Focus();
}
}
private void textBox18_Validating(object sender, CancelEventArgs e)
{
string a = @"^/d+(/./d+)?$";
Regex r = new Regex(a, RegexOptions.IgnoreCase);
Match m = r.Match(textBox18.Text); //进行正则匹配
if (m.Success)
{
}
else
{
MessageBox.Show("只能输入符点数");
textBox18.Text = null;
textBox18.Focus();
}
}
private void button6_Click(object sender, EventArgs e)
{
try
{
OleDbConnection myconnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=access/wajueji.mdb");
myconnection.Open();
string s = "update 大宇挖掘机 set 联系人='" + textBox11.Text.Trim() + "',工作日期='" + textBox12.Text.Trim() + "',工作地点='" + textBox13.Text + "',工作时间='" + textBox14.Text.Trim() + "',台班单价='" + textBox15.Text.Trim() + "',加油金额='" + textBox16.Text.Trim() + "',拖车司机='" + textBox17.Text.Trim() + "',保养总表时间='" + textBox18.Text.Trim() + "',其他费用='" + textBox19.Text.Trim() + "',合计金额='" + textBox20.Text.Trim() + "' where id=" + Convert.ToInt32(label21.Text);
OleDbCommand mycommnad = new OleDbCommand(s, myconnection);
mycommnad.ExecuteNonQuery();
myconnection.Close();
MessageBox.Show("修改成功");
du();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
- 第一天写的WINFORM的项目
- 写博客的第一天
- 写博客的第一天
- 写博客的第一天
- 今天第一天写CSDN的BLOG
- 第一天写博客的想法
- 开始写博客的第一天
- 今天是写博客的第一天
- 写博客的第一天..开始了
- 开始正式写博客的第一天
- 开始写博客的第一天
- 自己动手写博客的第一天!!
- 记录开始写博客的第一天
- 今天是写博客的第一天
- 想要认真写博客的第一天
- 写博客的第一天之我为什么写博客
- 第一天 悲催的遗留项目
- 项目中涉及的知识第一天
- C#静态方法
- 静态方法和实例化方法的区别
- 2008新的开始
- 字符串的多方式预处理
- sql 2005 所有连接字符串
- 第一天写的WINFORM的项目
- 论企业生存发展与革命战争
- 解析企业的“核”战争
- UML2时序图组合片段简要说明
- 网络营销的含义
- 长尾理论在网络营销中的应用
- ASP.NET中,客户端利用 ASP.NET AJAX(Atlas)调用服务端方法的代码
- 假期总结——设计臭味
- (转)如何手工在 SQL Server 2005 中为安装程序增加计数器注册表项值