Exemplo n.º 1
0
 public void AddItem(SalesClothes sc)
 {
     m_clothesList.Add(sc);
 }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //检查是否输入已符合规范

            if (dataGridView.Rows.Count <= 1)
            {
                MessageBox.Show("没有需要付款的项,请检查!");
                return;
            }
            foreach (DataGridViewRow item in dataGridView.Rows)
            {
                if (null != item.Cells[1].Value &&
                    !string.IsNullOrEmpty(item.Cells[1].Value.ToString()))
                {
                    //有商品标签代码

                    if (null == item.Cells[2].Value ||
                        string.IsNullOrEmpty(item.Cells[2].Value.ToString()))
                    {
                        //但是没有找到相应的商品名称

                        MessageBox.Show("商品填写不正确,请检查标签代码!");
                        return;
                    }

                    if (null == item.Cells[3].Value ||
                        string.IsNullOrEmpty(item.Cells[3].Value.ToString()) ||
                        !ValueMarked.CheckMoney(item.Cells[3].Value.ToString()))
                    {
                        //原价没有填

                        MessageBox.Show("原价填写不正确,请检查!");
                        return;
                    }

                    if (null == item.Cells[5].Value ||
                        string.IsNullOrEmpty(item.Cells[5].Value.ToString()) ||
                        !ValueMarked.CheckMoney(item.Cells[5].Value.ToString()))
                    {
                        //结算价没有填

                        MessageBox.Show("结算价填写不正确,请检查!");
                        return;
                    }

                    if (null == item.Cells[7].Value ||
                        string.IsNullOrEmpty(item.Cells[7].Value.ToString()) ||
                        !ValueMarked.CheckMoney(item.Cells[7].Value.ToString()))
                    {
                        //金额价没有填

                        MessageBox.Show("金额填写不正确,请检查!");
                        return;
                    }
                }
            }

            if (string.IsNullOrEmpty(saleRecvTextBox.Text) ||
                !ValueMarked.CheckMoney(saleRecvTextBox.Text))
            {
                MessageBox.Show("应付金额填写不正确,请检查!");
                return;
            }

            //检查是否有付款页面已经打开
            if (null == m_sc)
            {
                m_sc = new SaleConfirm();
                m_sc.SetSalesRecv(saleRecvTextBox.Text);
                DialogResult dr = m_sc.ShowDialog();

                if (dr == DialogResult.OK)
                {
                    //打印发票

                    TicketPrinter tp = new TicketPrinter();


                    foreach (DataGridViewRow item in dataGridView.Rows)
                    {
                        if (item.Cells[1].Value != null &&
                            item.Cells[2].Value != null &&
                            item.Cells[3].Value != null &&
                            item.Cells[4].Value != null &&
                            item.Cells[5].Value != null &&
                            item.Cells[6].Value != null &&
                            item.Cells[7].Value != null &&
                            !string.IsNullOrEmpty(item.Cells[1].Value.ToString()) &&
                            !string.IsNullOrEmpty(item.Cells[2].Value.ToString()) &&
                            !string.IsNullOrEmpty(item.Cells[3].Value.ToString()) &&
                            !string.IsNullOrEmpty(item.Cells[4].Value.ToString()) &&
                            !string.IsNullOrEmpty(item.Cells[5].Value.ToString()) &&
                            !string.IsNullOrEmpty(item.Cells[6].Value.ToString()) &&
                            !string.IsNullOrEmpty(item.Cells[7].Value.ToString()))
                        {
                            SalesClothes sc = new SalesClothes();
                            sc.TagCode   = item.Cells[1].Value.ToString();
                            sc.Name      = item.Cells[2].Value.ToString();
                            sc.Price     = item.Cells[3].Value.ToString();
                            sc.Count     = item.Cells[6].Value.ToString();
                            sc.SalePrice = item.Cells[7].Value.ToString();

                            tp.AddItem(sc);
                        }
                    }

                    if (!string.IsNullOrEmpty(upOffTextBox.Text) &&
                        !string.IsNullOrEmpty(saleRecvTextBox.Text))
                    {
                        tp.SetPrices(upOffTextBox.Text, saleRecvTextBox.Text);
                    }

                    PrinterErr perr = tp.Print();
                    switch (perr)
                    {
                    case PrinterErr.NoLPTPrinter:
                        MessageBox.Show("找不到LPT打印机,请检查打印机的连接!");
                        break;

                    case PrinterErr.CanNotOpenPrinter:
                        MessageBox.Show("无法打开LPT1打印机,请检查打印机的端口是否正确!");
                        break;

                    case PrinterErr.Success:
                    default:
                        MessageBox.Show("发票打印成功!");
                        dataGridView.Rows.Clear();
                        upOffTextBox.Text    = "";
                        saleRecvTextBox.Text = "";
                        break;
                    }
                }

                m_sc = null;
            }
        }