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

📄 productform.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 DaFanRongMIS.Model.Product;
namespace DaFanRongMIS.ViewController.Product
{
    public partial class ProductForm : Form
    {
        //定义产品实体类对象
        ProductEntity product = new ProductEntity();

        //定义产品操作类对象
        ProductDAOImpl productdao = new ProductDAOImpl();
        public ProductForm()
        {
            InitializeComponent();
        }

        
        #region 窗体加载方法
        private void ProductForm_Load(object sender, EventArgs e)
        {
            //填充ListView控件
           // FillLV();
        }
        #endregion

        #region 查询按钮,可按指定条件查询
        private void btnSelect_Click(object sender, EventArgs e)
        {
            //调用填充ListView方法
            FillLV();
        }//end method btnSelect_Click
        #endregion

        #region 填充ListView方法
        private void FillLV()
        {


            //声明数据表对象接收查询结果
            DataTable dt = productdao.SelectProduct(txtProductName.Text, txtPinName.Text, txtUnitName.Text, txtCateName.Text);

            //判断是否有返回记录
            if (dt != null)
            {
                //清除ListView上的所有项
                ProductLV.Items.Clear();

                //有返回值,将其填充到ListView中
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    //定义ListView项
                    ListViewItem item = new ListViewItem(dt.Rows[i][6].ToString());     //产品编号
                    //定义ListView子项
                    item.SubItems.Add(dt.Rows[i][7].ToString());            //计量单位编号
                    item.SubItems.Add(dt.Rows[i][8].ToString());            //类别编号
                    item.SubItems.Add((i + 1).ToString());                  //序号
                    item.SubItems.Add(dt.Rows[i][0].ToString());            //产品名称
                    item.SubItems.Add(dt.Rows[i][1].ToString());            //拼音码
                    item.SubItems.Add(dt.Rows[i][2].ToString());               //图片
                    item.SubItems.Add(dt.Rows[i][3].ToString());            //价格
                    item.SubItems.Add(dt.Rows[i][4].ToString());            //计量单位名
                    item.SubItems.Add(dt.Rows[i][5].ToString());            //类别名
                    item.SubItems.Add(dt.Rows[i][9].ToString());            //备注
                    //将此项添加到ListView中

                    ProductLV.Items.Add(item);

                }
            }

        }//end method FillLV
        #endregion

        #region 工具栏上的退出按钮
        private void TbExit_Click(object sender, EventArgs e)
        {
            //关闭当前窗口
            this.Close();
        }
        #endregion

        #region 工具栏的添加按钮
        private void TbAdd_Click(object sender, EventArgs e)
        {
            //显示产品模块增加操作窗体
            new ProductOperForm("Add", ProductLV).ShowDialog();
        }
        #endregion

        #region 工具栏的修改按钮
        private void TbUpdate_Click(object sender, EventArgs e)
        {
            if (ProductLV.SelectedItems.Count == 0)
            {
                MessageBox.Show("您没有选择要修改的记录,请选择", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            //显示产品模块修改操作窗体
            new ProductOperForm("Update", ProductLV).ShowDialog();
        }
        #endregion

        #region 工具栏上的删除按钮
        private void TbDelete_Click(object sender, EventArgs e)
        {
            if (ProductLV.SelectedItems.Count == 0)
            {
                MessageBox.Show("您没有选择要删除的记录,请选择", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }


            if (ProductLV.SelectedItems.Count > 0)  //有要删除的项
            {
                //此部分查询要删除的编号在其他表中是否被引用

                
                //此处需判断产品编号在销售明细中是否存在
              

                //定义销售明细操作类对象

                //按产品编号查询


                //if (i > 0 || j > 0)    //判断记录行数
                //{
                //    MessageBox.Show("此产品已经在使用中,不能删除!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //    return;
                //}

                //提示用户是否删除
                if (MessageBox.Show("你确认删除么?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    //定义字符串变量str,接收删除的返回值
                    string str = "";

                    //调用删除方法,并取返回值
                    str = productdao.DeleteProduct(ProductLV.SelectedItems[0].Text);

                    //得到返回值,判断是否添加成功
                    if (str == "OK")
                    {
                        //成功
                        //调用填充ListView方法
                        FillLV();

                    }
                }
            }
        }
        #endregion

        #region 状态栏
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.toolStripStatusLabel1.Text = "当前系统时间" + DateTime.Now.ToString();
        }
        #endregion
    }
}

⌨️ 快捷键说明

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