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

📄 reportform.cs

📁 主要实现仓库的入库与出库的基本功能
💻 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.SqlClient;
using System.Drawing.Printing;

namespace Elysian
{
    public partial class reportForm : Form
    {
        public string str;
        private ListView lv;
        SqlConnection sqlconn = new SqlConnection(DataSource.GetConnectionString());
        SqlCommand sqlcomm ;
        //SqlDataAdapter adapter = null;
        SqlDataReader sqlreader ;
        public reportForm()
        {
            InitializeComponent();
        }

        //private void UpdataListView()
        //{

        //}

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
            //实现mainForm中groupBox1的再次出现
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //PrintDialog pd = new PrintDialog();
            //PrintDocument pdm = new PrintDocument();
            //pd.Document = pdm;
            //pd.AllowCurrentPage = true;
            //pd.AllowPrintToFile = true;
            //pd.PrinterSettings = null;
            //pd.ShowDialog();
            sqlcomm = new SqlCommand();
            listView3.Items.Clear();
            listView3.Refresh();
            lv = new ListView();
            lv.Visible = true;
            str = "select * from 库存表";
            sqlcomm.CommandText = str;
            sqlcomm.Connection = sqlconn;
            try
            {
                if (sqlconn.State == ConnectionState.Closed)
                    sqlconn.Open();
                this.sqlreader = this.sqlcomm.ExecuteReader();
                while (this.sqlreader.Read())
                {
                    ListViewItem ListVI = new ListViewItem();
                    ListVI.SubItems.Clear();
                    ListVI.SubItems[0].Text = sqlreader["商品编号"].ToString();
                    ListVI.SubItems.Add(sqlreader["商品名称"].ToString());
                    this.listView3.Items.Add(ListVI);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                this.sqlreader.Close();
                this.sqlconn.Close();
            }
            if (this.listView3.Items.Count == 0)
            {
                MessageBox.Show("没有记录存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                this.listView3.Items[0].Selected = true;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //ListViewExport.ExportToExcel(listView1, "F:\\课程设计\\Elysian\\Elysian\\dataDB\\", "商品入库信息", true);
            sqlcomm = new SqlCommand();
            lv = new ListView();
            lv.Visible = true;
            this.listView1.Items.Clear();
            this.listView1.Refresh();
            this.str = "select * from 商品入库信息";
            this.sqlcomm.CommandText = this.str;
            this.sqlcomm.Connection = this.sqlconn;
            try
            {
                if (this.sqlconn.State == ConnectionState.Closed)
                    this.sqlconn.Open();
                this.sqlreader = this.sqlcomm.ExecuteReader();
                
                while (this.sqlreader.Read())
                {
                    ListViewItem listVI = new ListViewItem();
                    listVI.SubItems.Clear();
                    listVI.SubItems[0].Text = sqlreader["供应商编号"].ToString();
                    listVI.SubItems.Add(sqlreader["供应商名称"].ToString());
                    listVI.SubItems.Add(sqlreader["入库编号"].ToString());
                    listVI.SubItems.Add(sqlreader["商品编号"].ToString());
                    listVI.SubItems.Add(sqlreader["商品名称"].ToString());
                    listVI.SubItems.Add(sqlreader["生产日期"].ToString());
                    listVI.SubItems.Add(sqlreader["保质期"].ToString());
                    listVI.SubItems.Add(sqlreader["商品数量"].ToString());
                    listVI.SubItems.Add(sqlreader["入库日期"].ToString());
                    listVI.SubItems.Add(sqlreader["经手人"].ToString());
                    listVI.SubItems.Add(sqlreader["备注"].ToString());
                    this.listView1.Items.Add(listVI);
                    listView1.Visible = true;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                this.sqlreader.Close();
                this.sqlconn.Close();
            }
            if (this.listView1.Items.Count == 0)
            {
                MessageBox.Show("没有记录存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                this.listView1.Items[0].Selected = true;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            sqlcomm = new SqlCommand();
            lv = new ListView();
            lv.Visible = true;
            listView2.Items.Clear();
            listView2.Refresh();
            str = "select * from 商品出库信息";
            sqlcomm.CommandText = str;
            sqlcomm.Connection = sqlconn;
            try
            {
                if (sqlconn.State == ConnectionState.Closed)
                    this.sqlconn.Open();
                this.sqlreader = this.sqlcomm.ExecuteReader();
                while (this.sqlreader.Read())
                {
                    ListViewItem ListVI = new ListViewItem();
                    ListVI.SubItems.Clear();
                    ListVI.SubItems[0].Text = sqlreader["出库编号"].ToString();
                    ListVI.SubItems.Add(sqlreader["商品编号"].ToString());
                    ListVI.SubItems.Add(sqlreader["商品名称"].ToString());
                    ListVI.SubItems.Add(sqlreader["出库日期"].ToString());
                    ListVI.SubItems.Add(sqlreader["经手人"].ToString());
                    ListVI.SubItems.Add(sqlreader["备注"].ToString());
                    this.listView2.Items.Add(ListVI);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                this.sqlreader.Close();
                this.sqlconn.Close();
            }
            if (this.listView2.Items.Count == 0)
            {
                MessageBox.Show("没有记录存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                this.listView2.Items[0].Selected = true;
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            //导出数据以Excel格式
            ListViewExport.ExportToExcel(listView1, "F:\\课程设计\\Elysian\\Elysian\\dataDB\\1.xls", "商品入库信息", true);
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            ListViewExport.ExportToExcel(listView2, "F:\\课程设计\\Elysian\\Elysian\\dataDB\\2.xls", "商品出库信息", true);
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            ListViewExport.ExportToExcel(listView3, "F:\\课程设计\\Elysian\\Elysian\\dataDB\\3.xls", "库存表", true);
        }
    }
}

⌨️ 快捷键说明

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