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

📄 shopform.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 DaFanRongMIS.Model.Common;
using DaFanRongMIS.Model.Shop;
using DaFanRongMIS.ViewController.Shop;

namespace DaFanRongMIS
{
    public partial class ShopForm : Form
    {
        public ShopForm()
        {
            InitializeComponent();
        }

        ShopEntity shop;
        ShopDAO shopdao;
        SqlDataReader dr;//接收查询饭店信息返回结果的SqlDataReader对象
        
        private void tbAdd_Click(object sender, EventArgs e)
        {
            //新店注册
            ShopOperForm sop = new ShopOperForm(1,LVShop);
            sop.ShowDialog();
        }

        private void tbUpdate_Click(object sender, EventArgs e)
        {
            //饭店信息修改
            ShopOperForm shopupdate = new ShopOperForm(2,LVShop);
            shopupdate.ShowDialog();
            
        }
        public void FillLVShop(SqlDataReader dr)
        {
            this.LVShop.Items.Clear();//清空
            if (dr == null)
                MessageBox.Show("未查到信息!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            else
                //this.FillLVShop(dr);//用查询结果填充ListView
            {
                
                while (dr.Read())
                {
                    ListViewItem item = new ListViewItem(dr["ID"].ToString());
                    item.SubItems.Add(dr["Name"].ToString());
                    item.SubItems.Add(dr["Address"].ToString());
                    item.SubItems.Add(dr["Memo"].ToString());
                    this.LVShop.Items.Insert(this.LVShop.Items.Count, item);
                }
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            //饭店信息查询
            shop = new ShopEntity();
            shop.ShopName = this.txtName.Text;
            shop.ShopAddress = this.txtAddress.Text;
            shopdao = new ShopDAOImpl();
            dr = shopdao.SelectShop(shop);
            this.FillLVShop(dr);//用查询结果填充ListView
        }

        private void ShopForm_Load(object sender, EventArgs e)
        {
            this.tbUpdate.Enabled = false;
            this.tbDelete.Enabled = false;
        }

        private void LVShop_Click(object sender, EventArgs e)
        {
            shop = new ShopEntity();
            
            this.tbUpdate.Enabled = true;
            this.tbDelete.Enabled = true;
        }
 #region 工具栏上的删除按钮
        private void tbDelete_Click(object sender, EventArgs e)
        {
            //删除
            if (LVShop.SelectedItems.Count == 0)
            {
                MessageBox.Show("您没有选择要删除的记录,请选择", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (LVShop.SelectedItems.Count > 0)  //有要删除的项
            {
                //提示用户是否删除

                if (MessageBox.Show("真的要删除信息吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    shopdao = new ShopDAOImpl();
                    if (shopdao.DeleteShop(shop) == "OK")
                    {
                        LVShop.SelectedItems[0].Remove();
                        MessageBox.Show("删除信息成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.None);
                        shop.ShopName = "";
                        shop.ShopAddress = "";
                        dr = shopdao.SelectShop(shop);
                        //this.FillLVShop(dr);//用查询结果填充ListView
                    }
                }
            }
        }
#endregion
        private void tbExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

⌨️ 快捷键说明

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