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

📄 crmanageform.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.Common;
using System.Data.SqlClient;
using DaFanRongMIS.Model.CashRegister;

namespace DaFanRongMIS.ViewController.CashRegister
{
    public partial class CRManageForm : Form
    {
        string flag = "";
        ListView lv = null;
        CashRegisterEntity crEntity;
        CashRegisterDAO crDAO;

        public CRManageForm()
        {
            InitializeComponent();
        }
        public CRManageForm(string Flag,ListView CRLV)
        {
            InitializeComponent();
            this.flag = Flag;
            this.lv = CRLV;
        }

        private void FillLV()
        {
            this.lv.Items.Clear();
            crDAO= new CashRegisterDAOImpl();
            SqlDataReader dr = crDAO.SelectAll(); 
            while (dr.Read())
            {
                ListViewItem item = new ListViewItem();
                item.Text = dr.GetString(0);
                item.SubItems.Add(dr.GetString(1));
                item.SubItems.Add(dr.GetString(2));
                item.SubItems.Add(dr.GetString(3));
                item.SubItems.Add(dr.GetString(4));
                item.SubItems.Add(dr.GetString(5));
                item.SubItems.Add(dr.GetString(6));
                item.SubItems.Add(dr.GetString(7));
                lv.Items.Add(item);

            }
            dr.Close();
            ConnectionDataBase.getConClose();
           
            
        }

        private void CRManageForm_Load(object sender, EventArgs e)
        {
            this.lv.View = View.Details;
            this.lv.AllowColumnReorder = true;
            this.lv.FullRowSelect = true;
            this.lv.GridLines = true;
            this.lv.Columns.Add("店名",100,HorizontalAlignment.Left);
            this.lv.Columns.Add("编号",50,HorizontalAlignment.Left);
            this.lv.Columns.Add("收银机名称", 90, HorizontalAlignment.Left);
            this.lv.Columns.Add("IP地址", 80, HorizontalAlignment.Left);
            this.lv.Columns.Add("主机名称", 100, HorizontalAlignment.Left);
            this.lv.Columns.Add("网卡地址", 120, HorizontalAlignment.Left);
            this.lv.Columns.Add("硬盘号", 120, HorizontalAlignment.Left);
            this.lv.Columns.Add("备注", 100, HorizontalAlignment.Left);
            if (flag == "Add")
            {
                this.cbxShopID.Visible = true;
                this.GBManage.Text = "添加信息";
                
                crDAO = new CashRegisterDAOImpl();

                SqlDataReader dr = crDAO.getShopName();

                while (dr.Read())
                {
                    this.cbxShopID.Items.Add(dr.GetString(0));
                }
                dr.Close();
               ConnectionDataBase.getConClose();
               this.txtCRID.ReadOnly = true; 
            }
            else if (flag == "Update")
            {
                this.txtShopID.Visible = true;
                this.GBManage.Text = "修改信息";
                this.txtShopID.ReadOnly = true;
                this.txtCRID.ReadOnly = true;
                if (lv.SelectedItems.Count > 0)
                {
                    this.txtShopID.Text = lv.SelectedItems[0].SubItems[0].Text;
                    this.txtCRID.Text = lv.SelectedItems[0].SubItems[1].Text;
                    this.txtCRName.Text = lv.SelectedItems[0].SubItems[2].Text;
                    this.txtIP.Text = lv.SelectedItems[0].SubItems[3].Text;
                    this.txtHostName.Text = lv.SelectedItems[0].SubItems[4].Text;
                    this.txtMAC.Text = lv.SelectedItems[0].SubItems[5].Text;
                    this.txtHard.Text = lv.SelectedItems[0].SubItems[6].Text;
                    this.txtMemo.Text = lv.SelectedItems[0].SubItems[7].Text;

                }
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (flag == "Add")
            {
                if (this.cbxShopID.Text != "" && this.txtCRID.Text != "" && this.txtCRName.Text != "" && this.txtIP.Text != "" && this.txtHostName.Text != "" && this.txtMAC.Text != "" || this.txtHard.Text != ""||this.txtMemo.Text!="")
                {

                    crDAO = new CashRegisterDAOImpl();
                    crEntity = new CashRegisterEntity();
                    string name = this.cbxShopID.Text;
                    crEntity.Shopid = crDAO.getID(name);
                    crEntity.Id=this.txtCRID.Text;
                    crEntity.Name=this.txtCRName.Text;
                    crEntity.Ip=this.txtIP.Text;
                    crEntity.Hostname=this.txtHostName.Text;
                    crEntity.Mac=this.txtMAC.Text;
                    crEntity.Hard=this.txtHard.Text;
                    crEntity.Memo=this.txtMemo.Text;
                    string str = crDAO.CrAdd(crEntity);
                    if (str == "OK")
                    {
                        MessageBox.Show("添加记录成功");
                    }
                    else
                    {
                       MessageBox.Show("Error");
                    }
                    this.FillLV();
                    this.txtCRID.Text = "";
                    this.txtCRName.Text = "";
                    this.txtIP.Text = "";
                    this.txtHostName.Text = "";
                    this.txtMAC.Text = "";
                    this.txtHard.Text = "";
                    this.txtMemo.Text = "";
                    this.txtCRName.Focus();
                }
                else
                {
                    MessageBox.Show("请输入数据!");
                }
            }
            else if (flag == "Update")
            {
                if (this.txtShopID.Text != "" && this.txtCRID.Text != "")
                {
                    crDAO = new CashRegisterDAOImpl();
                    crEntity =new CashRegisterEntity();
                    string name = this.txtShopID.Text;
                    crEntity.Shopid =crDAO.getID(name);
                    crEntity.Id=this.txtCRID.Text;
                    crEntity.Name=this.txtCRName.Text;
                    crEntity.Ip=this.txtIP.Text;
                    crEntity.Hostname=this.txtHostName.Text;
                    crEntity.Mac=this.txtMAC.Text;
                    crEntity.Hard=this.txtHard.Text;
                    crEntity.Memo=this.txtMemo.Text;
                    string str= crDAO.CrUpdate(crEntity);
                    if (str == "OK")
                    {
                        MessageBox.Show("修改记录成功");
                    }
                     
                    this.FillLV();
                }
                else
                {
                    MessageBox.Show("你没有选择记录,请选择!");
                }
            }
            
        }

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

        private void cbxShopID_SelectedValueChanged(object sender, EventArgs e)
        {
            string shopname = this.cbxShopID.Text;
            SqlDataReader dr = crDAO.AutoID(shopname);
            
            if (dr.Read())
            {

                int i = Convert.ToInt32(dr.GetValue(0)) + 1;
                this.txtCRID.Text = i.ToString("00");
                
            }
            else
            {
                
                this.txtCRID.Text ="00";
            }
            dr.Close();
            ConnectionDataBase.getConClose();
        }
    }
}

⌨️ 快捷键说明

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