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

📄 sellsform.cs

📁 一个超市管理系统,没有错误,非常好,里面什么都有!很使用,很有用
💻 CS
📖 第 1 页 / 共 2 页
字号:
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.Sell;
using DaFanRongMIS.Model.Login;
namespace DaFanRongMIS.ViewController.Sell
{
    public partial class SellsForm : Form
    {
        public SellsForm()
        {
            InitializeComponent();
        }
        string s;
        public SellsForm(string n)
        {
            InitializeComponent();
            s = n;
        }
        //标记变量 用来限制用户输入的字符格式的判断
        private bool flag = false;
        //记录每次入库的主表编号
        private string SellMainID;
        LoginEntity login = new LoginEntity();
        private void SellForm_Load(object sender, EventArgs e)
        {
            //读取数据库填充商品信息
            Model.Sell.SellMainDAOImpl dao = new SellMainDAOImpl();
            dao.FillData();
          //  Model.Login.LoginEntity ldao = new DaFanRongMIS.Model.Login.LoginEntity();
            //t1.Text = ldao.UserID;
            TxtName.Focus();

           this.t5.Text= this.t5.Text+dao.GetShopID(login.UserID);
           this.t1.Text = this.t1.Text+s;
           

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.t4.Text = DateTime.Now.ToString();
        }

        private void TxtName_KeyDown(object sender, KeyEventArgs e)
        {
            //如果输入上下箭头按钮则让表格控件获取焦点
            if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
            {
                this.DGShowGood.Focus();
            }
            //验证输入的信息是否是字母,数字和退格键
            if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) || (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) || (e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9) || e.KeyCode == Keys.Back)
            {
                flag = false;
            }
            else
            {
                flag = true;
            }     
        }

        #region 验证当前输入的食品信息是否准确

        /// 验证当前输入的食品信息是否准确
    
        public bool JudgeGood()
        {
            bool result = false;
            int j = 0;
            if (this.TxtName.Text != "")
            {
                if (this.TxtName.Text[0] == '【')
                {
                    for (int i = 0; i < this.TxtName.Text.Length; i++)
                    {
                        if (this.TxtName.Text[i] == '】')
                        {
                            j++;
                        }
                        if (this.TxtName.Text[i] == '(')
                        {
                            j++;
                        }
                        if (this.TxtName.Text[i] == ')')
                        {
                            j++;
                        }
                    }
                }
            }
            if (j == 3)
            {
                result = true;
            }
            return result;
        }
        #endregion

        #region 验证输入的信息是否是数字
        public bool JudgeTxtIsNumber()
        {
            bool result = true;
            if (this.TxtName.Text != "")
            {
                for (int i = 0; i < this.TxtName.Text.Length; i++)
                {
                    if (!Char.IsNumber(this.TxtName.Text[i]))
                    {
                        result = false;
                    }
                }
            }
            else
            {
                result = false;
            }
            return result;
        }
        #endregion

        private void TxtName_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                //创建操作类的对象
                SellMainDAOImpl dao = new SellMainDAOImpl();

                #region 判断是否按了回车键并验证输入信息判断是拼音码还是编号,无论那个都有相关的验证,来检验其信息有效性
                if (e.KeyCode == Keys.Enter)
                {
                    //判断输入的内容是否准确 此处是拼音码的操作
                    if (JudgeGood())
                    {
                        //根据输入的产品信息查询价格
                        this.TxtPrice.Text = dao.GetProductPrice(this.TxtName.Text.Substring(this.TxtName.Text.LastIndexOf('(')+1, 6)).ToString();
                        this.TxtCount.Focus();
                    }
                    //判断输入的信息是否 准确 此处是产品编号的操作
                    else if (JudgeTxtIsNumber())
                    {
                        //根据输入的编号 来获取此编号所对应的产品信息 并将获取到的信息添加到文本框中 如果无此编号则提示信息
                        DataRow dr = dao.GetDataByID(this.TxtName.Text);
                        if (!dr.Equals(null))
                        {
                            this.TxtName.Text = "【1】(" + dr["ID"] + ")" + dr["Name"].ToString();
                            this.TxtPrice.Text = dr["price"].ToString();
                        }
                        else
                        {
                            MessageBox.Show("无此编号信息!", " 系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        this.TxtCount.Focus();
                        return;
                    }
                    //此处为个数输入错误
                    else
                    {
                        MessageBox.Show("输入格式有误,请重新输入!", " 系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.TxtName.Text = "";
                        this.TxtName.Focus();
                        return;
                    }
                }
                #endregion

                #region 判断当前输入的字符是否是字符,或者是退格键
                if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
                {
                    if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
                    {
                        //如果是字符则开始根据输入的信息进行查询
                        string WhereStr = "";
                        if (this.TxtName.Text == "")
                        {
                            WhereStr = "!!";
                        }
                        else
                        {
                            WhereStr = this.TxtName.Text;
                        }
                        dao.FillListBoxByPin(WhereStr, this.LbGoodsList);
                    }//end block if 判断小键盘数字
                }//end block if 判断大键盘数字
                else
                {
                    //如果是数字则根据数字将数字所对应的列表项填入到文本框当中
                    if (Convert.ToInt32(e.KeyValue) - 48 <= this.LbGoodsList.Items.Count && e.KeyCode != Keys.D0)
                    {
                        this.TxtName.Text = this.LbGoodsList.Items[Convert.ToInt32(e.KeyValue) - 49].ToString();
                        this.LbGoodsList.Items.Clear();
                    }
                }//end block else 是数字
                #endregion

                #region 如果输入空格,则开始输入付款金额
                if (e.KeyValue == 32)
                {
                    this.textBox3.Focus();

                }
                #endregion
                //#region 如果输入+,则开始打印,商品交易信息入库,并准备下一次的交易
                //if (e.KeyCode == Keys.Oemplus)
                //{
                //    //判断是否按了完成交易按键
                //    if (this.DGShowGood.Rows.Count > 0)
                //    {
                //        //创建销售主表的对象
                //        SellMainEntity main = new SellMainEntity();
                //        //给销售主表的属性付值
                //        main.Id = dao.CreateMainSellID();
                //        SellMainID = main.Id;
                //        main.Shopid = this.t5.Text.Substring(this.t5.Text.LastIndexOf('(') + 1, 2);
                //        main.Cashid = this.t2.Text.Substring(this.t2.Text.LastIndexOf(':') + 1, 2);
                //        main.Casher = this.t3.Text.Substring(this.t3.Text.LastIndexOf(':') + 1).Trim();
                //        main.Selltime = System.DateTime.Today.ToShortDateString();
                //        main.Memo = "nothing";
                //        //创建销售明细对象数组,数组的个数根据DataGridView中的记录行数添加
                //        SellDetailEntity[] details = new SellDetailEntity[DGShowGood.Rows.Count - 1];
                //        //循环DataGridView中的所有存在记录的行并将每行记录信息添加入明细对象数组中
                //        for (int i = 0; i < DGShowGood.Rows.Count - 1; i++)
                //        {
                //            //创建明细表对象
                //            SellDetailEntity detail = new SellDetailEntity();
                //            //给明细表对象属性付值
                //            detail.MainID = main.Id;
                //            detail.ProductID = DGShowGood.Rows[i].Cells[2].Value.ToString();
                //            detail.SoldCount = Convert.ToInt32(DGShowGood.Rows[i].Cells[3].Value);
                //            //detail.Diccount = 0;
                //            //detail.MemberPrice = 0;
                //            details[i] = detail;
                //        }
                //        //判断执行是否成功
                //        if (dao.SellProduct(main, details) == "ok")
                //        {
                //            MessageBox.Show("正在打印");

⌨️ 快捷键说明

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