下午上机

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();
            }
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值