using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 上机_下午
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//string stu = "Data Source=.;Initial Catalog=assetsDB;Integrated Security=True";
private void 新增固定资产ToolStripMenuItem1_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
f.MdiParent = this;
f.Show();
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void 查询固定资产ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form3 q = new Form3();
q.MdiParent = this;
q.Show();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 上机_下午
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
sr();
}
public void sr()
{
this.comboBox1.SelectedIndex = 0;
}
MySchool.DBHelper a = new MySchool.DBHelper();
public bool ss() {
bool success = false;
string assetId = this.textBox1.Text.Trim();
string assetName = this.textBox2.Text.Trim();
string assetType = this.comboBox1.Text.Trim();
string intpDate= this.textBox3.Text.Trim();
try
{
string sql = string.Format("select * from assets");
a.OpenConnection();
SqlCommand comm = new SqlCommand(sql,a.Connection);
StringBuilder sb = new StringBuilder();
sb.AppendLine("insert into assets(assetId,assetName,assetType,intoData)");
sb.AppendFormat("values ('{0}','{1}','{2}','{3}')", assetId, assetName, assetType, intpDate);
MessageBox.Show(sb.ToString());
comm = new SqlCommand(sb.ToString(),a.Connection);
int result = comm.ExecuteNonQuery();
if (result == 1) {
success = true;
return success;
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
return false;
}
private void button2_Click(object sender, EventArgs e)
{
this.textBox1.Text = "";
this.textBox2.Text = "";
this.textBox3.Text = "";
this.comboBox1.Text = "";
}
private void button1_Click(object sender, EventArgs e)
{
ss();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 上机_下午
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void Form3_Load(object sender, EventArgs e)
{
st();
sr();
}
public void sr() {
this.comboBox1.SelectedIndex = 0;
}
MySchool.DBHelper a= new MySchool.DBHelper();
DataSet ds = new DataSet();
public void st() {
try
{
string sql = "select * from assets";
MessageBox.Show(sql);
SqlDataAdapter da = new SqlDataAdapter(sql,a.Connection);
da.Fill(ds, "r");
dataGridView1.DataSource = ds.Tables["r"];
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
if (this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString().Equals(null))
{
MessageBox.Show("没有查询到结果", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else {
se();
}
}
public void se() {
try
{
if (ds.Tables["assets"] != null)
{
ds.Tables["assets"].Clear();
}
StringBuilder sb = new StringBuilder();
sb.Append("select * from assets");
sb.AppendFormat(" where assetId='{0}' OR assetType='{1}' ", this.textBox1.Text, this.comboBox1.Text.Trim());
SqlDataAdapter da = new SqlDataAdapter(sb.ToString(), a.Connection);
da.Fill(ds, "assets");
dataGridView1.DataSource = ds.Tables["assets"];
}
catch (Exception w)
{
MessageBox.Show(w.Message);
}
finally {
a.CloseConnection();
}
}
}
}