C#固定资产查询

sing 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 zichanxitong
{
    public partial class FrmSystem : Form
    {
        DBHelper helper = new DBHelper();
        DataSet ds = null;
        SqlDataAdapter adapter = null;
        DataView dv;

        public FrmSystem()
        {
            InitializeComponent();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void FrmSystem_Load(object sender, EventArgs e)
        {
            this.cboassetType1.Text = "请选择类型";
//            string sql = @"SELECT [id]
//                          ,[assetType]
//                      FROM [assets]";

//            adapter = new SqlDataAdapter(sql, helper.Connection);
//            ds = new DataSet();
//            adapter.Fill(ds, "assets");

//            DataRow row = ds.Tables["assets"].NewRow();
//            row[0] = "-1";
//            row[1] = "请选择类型";
//            ds.Tables["assets"].Rows.InsertAt(row, 0);


//            dv = new DataView(ds.Tables["assets"]);

//            cboassetType1.DataSource = dv;
//            cboassetType1.DisplayMember = "assetType";
//            cboassetType1.ValueMember = "id";

            DgvBand();
        }

        private void DgvBand()
        {
            string sql = string.Format(@"SELECT [assetId]as '资产编号'
                                                  ,[assetName]as '资产名称'
                                                  ,[assetType]as '资产类型'
                                                  ,[intoData]as '入库日期'
                                              FROM [assets]");
            adapter = new SqlDataAdapter(sql, helper.Connection);
            ds = new DataSet();
            if (ds.Tables["assets"] != null)
            {
                ds.Tables["assets"].Clear();
            }
            adapter.Fill(ds, "assets");

            dv = new DataView(ds.Tables["assets"]);

            this.dgvassets.DataSource = dv;
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {

            if (this.txtassetId1.Text.Trim() != "")
            {
                assetId();
            }

            if (this.cboassetType1.Text.ToString().Equals("运输设备"))
            {
                assetType();
            }
            if (this.cboassetType1.Text.ToString().Equals("机械设备"))
            {
                assetType();
            }
            if (this.cboassetType1.Text.ToString().Equals("电子设备"))
            {
                assetType();
            }
            if (this.txtassetId1.Text.Trim()=="" && this.cboassetType1.Text.ToString().Equals("请选择类型"))
            {
                 DgvBand();
            }
        }
        #region 按编号
        private void assetId()
        {
            string sql = string.Format(@"SELECT [assetId]'资产编号'
                                              ,[assetName]as '资产名称'
                                              ,[assetType]as '资产类型'
                                              ,[intoData]as '入库日期'
                                          FROM [assets]
                                          where assetId ='{0}'", this.txtassetId1.Text.ToString());
            adapter = new SqlDataAdapter(sql, helper.Connection);
            ds = new DataSet();
            adapter.Fill(ds, "assets");
            dv = new DataView(ds.Tables["assets"]);
            this.dgvassets.DataSource = dv; 
 
        }
        #endregion
        #region 按类型
        private void assetType()
        {
            string sql = string.Format(@"SELECT [assetId]'资产编号'
                                              ,[assetName]as '资产名称'
                                              ,[assetType]as '资产类型'
                                              ,[intoData]as '入库日期'
                                          FROM [assets]
                                          where assetType='{0}'",this.cboassetType1.Text.ToString());
            adapter = new SqlDataAdapter(sql, helper.Connection);
            ds = new DataSet();
            adapter.Fill(ds, "assets");
            dv = new DataView(ds.Tables["assets"]);
            this.dgvassets.DataSource = dv; 
        }
        #endregion

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {    
            try
            {
                helper.OpenConnection();
                string sql = string.Format(@"DELETE FROM [assetsDB].[dbo].[assets]
      WHERE assetId='{0}'",this.dgvassets.CurrentRow.Cells[0].Value);
                 adapter=new SqlDataAdapter(sql,helper.Connection);
                SqlCommand comm = new SqlCommand(sql, helper.Connection);
                int iRet = comm.ExecuteNonQuery();
                if (iRet>0)
                {
                     MessageBox.Show("确定要删除?","系统提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
                }
                else
                {
                    MessageBox.Show("删除失败");
                }
                
                DgvBand();
                
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                helper.CloseConnection();
            }
        }





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 zichanxitong
{
    public partial class frmInsert : Form
    {
        DBHelper helper = new DBHelper();
        DataSet ds = null;
        SqlDataAdapter adapter=null;
        DataView dv = null;
        public frmInsert()
        {
            InitializeComponent();
        }
        #region 增加
        private void btnInsert_Click(object sender, EventArgs e)
        {
            if (insertClose()==true)
            {
                if (insert()==true)
	            {
                    this.Hide();
	            }
            }
        }
        #endregion

        #region 非空判断
        private bool insertClose()
        {
            if (this.txtassetId.Text.Trim().Equals(string.Empty))
            {
                MessageBox.Show("请输入编号", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return false;
            }
            if (this.txtassetName.Text.Trim().Equals(string.Empty))
            {
                MessageBox.Show("请输入名称", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return false;
            }
            if (this.txtDate.Text.Trim().Equals(string.Empty))
            {
                MessageBox.Show("请输入日期", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return false;
            }
            if (this.cboassetType.Text.Equals(string.Empty))
            {
                MessageBox.Show("请输入类型", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return false;
            }
            return true;
        }
        #endregion

        #region 增加
        private bool insert()
        {
            string lblassetId = this.txtassetId.Text.Trim();
            string lblassetName = this.txtassetName.Text.Trim();
            string lblassetType = this.cboassetType.Text.ToString();
            
            string datatime = this.txtDate.Text.ToString();
           
            try
            {
                helper.OpenConnection();
                string sql = string.Format(@"INSERT INTO [assets]
                                               ([assetId]
                                               ,[assetName]
                                               ,[assetType]
                                               ,[intoData])
                                         VALUES({0},'{1}','{2}','{3}')", lblassetId, lblassetName, lblassetType, datatime);
                SqlCommand comm = new SqlCommand(sql, helper.Connection);
                int iRet = comm.ExecuteNonQuery();
                if (iRet > 0)
                {
                    MessageBox.Show("添加成功");
                }
                else
                {
                    
                    MessageBox.Show("添加失败");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                helper.CloseConnection();
            }
            return true;
        }
       #endregion

        private void frmInsert_Load(object sender, EventArgs e)
        {
            BandCbo();
        }

        private void BandCbo()
        {
            this.cboassetType.Text = "请选择类型";
//            string sql = @"SELECT [id]
//                          ,[assetType]
//                      FROM [assets]";

//            adapter = new SqlDataAdapter(sql, helper.Connection);
//            ds = new DataSet();
//            adapter.Fill(ds, "assets");

//            DataRow row = ds.Tables["assets"].NewRow();
//            row[0] = "-1";
//            row[1] = "请选择类型";
//            ds.Tables["assets"].Rows.InsertAt(row, 0);

//            dv = new DataView(ds.Tables["assets"]);

//            cboassetType.DataSource = dv;
//            cboassetType.DisplayMember = "assetType";
//            cboassetType.ValueMember = "id";
        }


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;

namespace zichanxitong
{
    public partial class FrmMainForm : Form
    {
        public FrmMainForm()
        {
            InitializeComponent();
        }
        #region 退出
        private void TsClose_Click(object sender, EventArgs e)
        {
            DialogResult result=MessageBox.Show("确定要退出吗?","系统提示",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation);
            if (result==DialogResult.Yes)
            {
                Application.Exit();
            }
        }
        #endregion

        #region 新增
        private void TsInsret_Click(object sender, EventArgs e)
        {
            frmInsert insert = new frmInsert();
            insert.Show();//模式窗体
        }
        #endregion

        private void TsSelect_Click(object sender, EventArgs e)
        {
            FrmSystem system = new FrmSystem();
            system.ShowDialog();
        }

        private void TsDelete_Click(object sender, EventArgs e)
        {
            FrmSystem system = new FrmSystem();
            system.ShowDialog();
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值