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

📄 sellsform.cs

📁 一个超市管理系统,没有错误,非常好,里面什么都有!很使用,很有用
💻 CS
📖 第 1 页 / 共 2 页
字号:
                //            //如果成功则开始打印
                //            //POSPrinter pos = new POSPrinter();
                //            //pos.PrintLine(SellMainID, this.DGShowGood, "01");
                //            //如果成功则准备下一次交易
                //            this.TxtName.Text = "";
                //            this.TxtName.Focus();
                //            this.DGShowGood.Rows.Clear();
                //            this.ClsTxt();
                //            this.LbGoodsList.Items.Clear();
                //            this.LblCount.Text = "0";
                //            this.LblMoney.Text = "0";
                //            this.textBox3.Text = "";
                //            this.textBox4.Text = "";
                //        }
                //        else
                //        {
                //            MessageBox.Show("产品销售有误或未添加任何产品,请咨询管理员!", " 系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //        }
                //    }
                //    else
                //    {
                //        MessageBox.Show("未添加商品信息,无法出售!", " 系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //    }
                //    return;
                //#endregion
              //  }
            }//end try
            catch (Exception ee)
            {
                if (ee.Message == "未将对象引用设置到对象的实例。")
                {
                    MessageBox.Show("无此编号产品!", " 系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("字符输入有误,请重新输入!", " 系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                this.TxtName.Text = "";
            }
        }

        private void TxtCount_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                //记录当前货品数量 
                string GoodsCount = "";
                if (e.KeyCode == Keys.Enter)
                {
                    if (this.TxtCount.Text.Length == 0)
                    {
                        GoodsCount = "1";
                    }

                    else
                    {
                        GoodsCount = this.TxtCount.Text;
                    }
                    int j = 0;
                    //计算当前列表中的记录数
                    int iCount = 1;
                    iCount=iCount+this.DGShowGood.Rows.Count;
                    //计算当前行记录中的总钱数
                    decimal money = Convert.ToInt32(GoodsCount) * Convert.ToDecimal(this.TxtPrice.Text);
                    for (int i = 0; i < DGShowGood.Rows.Count ; i++)
                    {
                        if(DGShowGood.Rows[i].Cells[1].Value.ToString()==TxtName.Text.Substring(11))
                        {
                            DGShowGood.Rows[i].Cells[3].Value=Convert.ToDecimal(DGShowGood.Rows[i].Cells[3].Value)+Convert.ToDecimal(TxtCount.Text);
                            DGShowGood.Rows[i].Cells[5].Value=Convert.ToDecimal(DGShowGood.Rows[i].Cells[5].Value)+money;
                        j=j+1;
                        }
                    }
                    if(j==0)

                        //将当前行添加到列表中
                        this.DGShowGood.Rows.Add(new string[] { iCount.ToString(), this.TxtName.Text.Substring(11), this.TxtName.Text.Substring(this.TxtName.Text.LastIndexOf('(') + 1, 6), GoodsCount, this.TxtPrice.Text, money.ToString() });
                    
                    
                    
                    
                    //汇总总钱数
                    this.LblMoney.Text = Convert.ToString(Convert.ToDecimal(this.LblMoney.Text) + money);
                    //汇总总货品数
                    this.LblCount.Text = Convert.ToString(Convert.ToInt32(this.LblCount.Text) + Convert.ToInt32(GoodsCount));
                    //清空文本框
                    this.ClsTxt();
                    //将当货品名称获取焦点,为下一次添加货品做准备
                    this.TxtName.Focus();
                }
            }//end try
            catch (Exception ee)
            {
                MessageBox.Show("字符输入有误,请重新输入!", " 系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.TxtCount.Text = "";
            }
        }

        private void TxtCount_KeyDown(object sender, KeyEventArgs e)
        {
            //验证数量文本框中输入的字符必须是数字
            if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
            {
                if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
                {
                    if (e.KeyCode != Keys.Back)
                    {
                        flag = true;
                    }
                }
            }
        }

        #region 清空文本框
       
        // 清空文本框
    
        public void ClsTxt()
        {
            foreach (Control c in this.groupBox2.Controls)
            {
                if (c.Name.ToString().Substring(0, 3).ToUpper() == "TXT")
                {
                    c.Text = "";
                }
            }
        }
        #endregion

        private void TxtCount_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = flag;
            flag = false;
        }

        private void TxtName_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = flag;
            flag = false;
        }

        private void DGShowGood_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.TxtName.Focus();
            }
        }

        private void DGShowGood_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
        {
            //删除某一行是减掉移除行的钱
            this.LblMoney.Text = Convert.ToString(Convert.ToDecimal(this.LblMoney.Text) - Convert.ToDecimal(e.Row.Cells[5].Value.ToString()));
            //删除某一行是减掉移除行的数量
            this.LblCount.Text = Convert.ToString(Convert.ToInt32(this.LblCount.Text) - Convert.ToInt32(e.Row.Cells[3].Value.ToString()));
            //产品信息文本框获焦点
            this.TxtName.Focus();

        }

        private void SellForm_Activated(object sender, EventArgs e)
        {
            this.TxtName.Focus();
        }

        private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                this.textBox4.Text = Convert.ToString(Convert.ToDecimal(this.textBox3.Text) - Convert.ToDecimal(this.LblMoney.Text));
            }
        }

        private void textBox3_KeyUp(object sender, KeyEventArgs e)
        {
            SellMainDAOImpl dao = new SellMainDAOImpl();
            #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.t1.Text.Substring(this.t1.Text.LastIndexOf(':') + 1).Trim();
                    main.Selltime = System.DateTime.Today.ToShortDateString();
                    main.Memo = "nothing";
                    //创建销售明细对象数组,数组的个数根据DataGridView中的记录行数添加
                    SellDetailEntity[] details = new SellDetailEntity[DGShowGood.Rows.Count ];
                    //循环DataGridView中的所有存在记录的行并将每行记录信息添加入明细对象数组中
                    for (int i = 0; i < DGShowGood.Rows.Count; 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("正在打印");
                        //如果成功则开始打印
                        //POSPrinter pos = new POSPrinter();
                        //pos.PrintLine(SellMainID, this.DGShowGood, "01");
                        //如果成功则准备下一次交易
                        this.TxtName.Text = "";
                        this.TxtName.Focus();
                        this.DGShowGood.Rows.Clear();
                        this.ClsTxt();
                        this.LbGoodsList.Items.Clear();
                        this.LblCount.Text = "0";
                        this.LblMoney.Text = "0";
                        this.textBox3.Text = "";
                        this.textBox4.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("产品销售有误或未添加任何产品,请咨询管理员!", " 系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("未添加商品信息,无法出售!", " 系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                return;
            #endregion
            }
        }
    }
}

⌨️ 快捷键说明

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