⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list.cs

📁 用c#和access编写的仓库管理系统源码
💻 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.OleDb;

using System.Configuration;
using System.Collections;
using System.Web;


namespace WindowsApplication2
{
    public partial class List : Form
    {
       
        public List()
        {
            InitializeComponent();
            Bind();
        }

        protected void Bind()
        {

            OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Windows.Forms.Application.StartupPath + "/huochaihe.mdb");

            string article = "select article_id as 编号,article_name as 标题,article_Comment as 内容,article_author as 作者  from [article] order by article_id desc";

            myConn.Open();

            OleDbDataAdapter myAdapter = new OleDbDataAdapter(article, myConn);

            DataTable table = new DataTable();

            table.Locale = System.Globalization.CultureInfo.InvariantCulture;

            myAdapter.Fill(table);

            //dataGridView1.ColumnHeadersVisible = true;

            //dataGridView1.AutoGenerateColumns = true;

            //DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();

            //columnHeaderStyle.BackColor = Color.Beige;
            //
            //columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold);

            //dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;

            //dataGridView1.Columns[0].Name = "学生编号";

            //this.dataGridView1.RowHeadersWidth = 20;//行头的宽度

            this.dataGridView1.DataSource = table;



            //dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
            ///dataGridView1.BorderStyle = BorderStyle.Fixed3D;
            //dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;

            myConn.Close();

            ////this.label1.Text = "欢迎你";
            //this.label2.Text = "欢迎你";
            //this.label3.Text = "欢迎你";
        }

        private void button1_Click(object sender, EventArgs e)
        {

            string article_id = this.dataGridView1[0, this.dataGridView1.CurrentCell.RowIndex].Value.ToString();

            OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Windows.Forms.Application.StartupPath + "/huochaihe.mdb");
            
            myConn.Open();//打开数据库
           
            string article = "delete from article where article_id=" + article_id;

            OleDbCommand cmd = new OleDbCommand(article, myConn);

            cmd.ExecuteNonQuery();

            myConn.Close();

            Bind();

            MessageBox.Show("成功删除", "登录提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

            this.label1.Text = this.dataGridView1[0, this.dataGridView1.CurrentCell.RowIndex].Value.ToString();
            this.label2.Text = this.dataGridView1[1, this.dataGridView1.CurrentCell.RowIndex].Value.ToString();
            this.label3.Text = this.dataGridView1[3, this.dataGridView1.CurrentCell.RowIndex].Value.ToString();

            textBox1.Text = this.dataGridView1[0, this.dataGridView1.CurrentCell.RowIndex].Value.ToString();
            textBox2.Text = this.dataGridView1[1, this.dataGridView1.CurrentCell.RowIndex].Value.ToString();
            textBox3.Text = this.dataGridView1[3, this.dataGridView1.CurrentCell.RowIndex].Value.ToString();
            richTextBox1.Text = this.dataGridView1[2, this.dataGridView1.CurrentCell.RowIndex].Value.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Add add = new Add();
            add.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
           
           string article_Comment = richTextBox1.Text;
           string article_author= textBox3.Text;
           string article_name = textBox2.Text;
           string article_id = textBox1.Text;

           OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Windows.Forms.Application.StartupPath + "/huochaihe.mdb");
 
           myConn.Open();//打开数据库


           string article = "update article set article_name='" + article_name + "',article_author='" + article_author + "',article_comment='" + article_Comment + "' where article_id=" + article_id;

           //SqlDataAdapter cmdarticle = new SqlDataAdapter(article,myConn);

           OleDbCommand cmd = new OleDbCommand(article, myConn);

           cmd.ExecuteNonQuery();

           myConn.Close();//关闭数据库
          
            Bind();

           MessageBox.Show("成功修改", "登录提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string article_id = this.dataGridView1[0, this.dataGridView1.CurrentCell.RowIndex].Value.ToString();
            View view = new View();
            view.Bind(article_id);
            //view.Show();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            string article_name = textBox4.Text;
           
            //MessageBox.Show(article_name, "登录提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

            OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Windows.Forms.Application.StartupPath + "/huochaihe.mdb");

            string article = "select article_id as 编号,article_name as 标题,article_Comment as 内容,article_author as 作者  from [article] where article_name like '%"+ article_name +"%' order by article_id desc";
            
            myConn.Open();

            OleDbDataAdapter myAdapter = new OleDbDataAdapter(article, myConn);

            DataTable table = new DataTable();

            table.Locale = System.Globalization.CultureInfo.InvariantCulture;

            myAdapter.Fill(table);

            this.dataGridView1.DataSource = table;

            myConn.Close();
        }

        //窗体的Click事件响应函数
        private void frmNotifyIcon_Load(object sender, EventArgs e)
        {
            notifyIcon1.Visible = true;
        }

        private void notifyIcon1_DoubleClick(object sender, EventArgs e)
        {

        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Application.Exit();
            this.Close();
        }

        /////////////////////////////////


    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -