zoukankan      html  css  js  c++  java
  • 超市购物打印小票的简单程序 记录下来

    做了2个版本的超市购物小票打印程序,做过记录
    一、C/S样图如下:
       
     其中 输入商品的编码 回车 将会调用该商品的信息,显示在下面的DataGridView中 ,DataGridView中数量是可以修改的,修改数量,下面的合计 将会自动计算 ,然后打印
      其中 打印购物小票的程序如下:
          #region 结帐以及打印函数
            private void jzPrint()
            {
                if (dataGridView1.Rows.Count == 0)
                {
                    MessageBox.Show("没有购物数据,无法收银和打印!");
                    return;
                }
                if (textBox3.Text.Trim() == "")
                {
                    MessageBox.Show("没有输入付款金额,无法收银打印!");
                    return;
                }
                //收银打印

                string operuser = "露天其";//收银员的名称,实际修改时,应该成登录者的名字即可

                #region 第一步,首先把这项订单写入数据库的表中
                 //写入数据库比较简单,
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    string name = dataGridView1.Rows[i].Cells["ProName"].Value.ToString().Trim();//获取该行的物品名称
                    string num = dataGridView1.Rows[i].Cells["ProNum"].Value.ToString().Trim();//数量
                    string price = dataGridView1.Rows[i].Cells["ProPrice"].Value.ToString().Trim();//单价
                    string bm = dataGridView1.Rows[i].Cells["bianma"].Value.ToString();
                    //string SQL = "insert into T_Order()";
                    //SqlHelper.ExecuteNonQuery(

                }
                #endregion
                string path = Application.StartupPath.ToString() + "\\ticket.txt";//exe程序所在的路径

                #region 第二步,把这位顾客的购物单,按格式生成一个txt文件,方便第三步打印
                StreamWriter sw = new StreamWriter(path, true);
                string day = DateTime.Now.ToString("yyyyMMdd");
                string time = DateTime.Now.ToString();
                #region 小票 基本格式图
                //***************小票的格式如下************************  //
                //                   新一佳超市                         //
                //                欢迎光临新一佳超市                   //
                //                                                     //
                //                                                     //  
                // 物品                        数量       单价(¥)    //
                //---------------------------------------------------//
                //系列红山茶硬盒                 3         45.8      //
                //哆啦A梦相架小礼包              5         25.8      //
                //哆啦A梦相架小礼包              5         25.8      //
                //哆啦A梦相架小礼包              5         25.8      //
                //哆啦A梦相架小礼包              5         25.8      //
                //哆啦A梦相架小礼包              5         25.8      //
                //哆啦A梦相架小礼包              5         25.8      //
                //哆啦A梦相架小礼包              5         25.8      //
                //--------------------------------------------------//
                //           总数:              35                 //
                //           合计:              350                //
                //           现金:              355.9              //
                //           找赎:              15                 //
                //                                                  //
                //                                                  //
                //                                                 //
                //  日期/时间       2009/10/25 14:25:15           //
                //          服务热线:0755-25145252               //
                //**************************************************//
                #endregion
                #region 拼出小票格式
                sw.WriteLine("                 新一佳超市            \t\t");
                sw.WriteLine("                                           \t\t");
                sw.WriteLine("               欢迎光临新一佳超市      \t\t");
                sw.WriteLine("                                                ");
                sw.WriteLine("                                                ");
                sw.WriteLine("                                                ");
                sw.WriteLine("   物品               数量                  单价(¥)");
                sw.WriteLine("-----------------------------------------------------");
                int nums = 20;
                int prices = 12;

                #region 获取DataGridView中的数据
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    string name = dataGridView1.Rows[i].Cells["ProName"].Value.ToString().Trim();//获取该行的物品名称
                    string num = dataGridView1.Rows[i].Cells["ProNum"].Value.ToString().Trim();//数量
                    string price = dataGridView1.Rows[i].Cells["ProPrice"].Value.ToString().Trim();//单价

                    int numlength = System.Text.Encoding.Default.GetBytes(num).Length;
                    if (numlength < nums)
                    {
                        num = AddSpace(num, nums - numlength);
                    }

                    int pricelength = System.Text.Encoding.Default.GetBytes(price).Length;
                    if (pricelength < prices)
                    {
                        price = AddSpace(price, prices - pricelength);
                    }
                    sw.WriteLine(name);
                    sw.WriteLine("                         " + num + "        " + price);

                }
                #endregion
                sw.WriteLine("-----------------------------------------------------");
                sw.WriteLine("           总数:                  " + lbnum.Text.ToString());
                //计算合计金额:
                decimal oldmoney = Convert.ToDecimal(textBox1.Text);
                decimal newmoney = 0;

                newmoney = oldmoney;


                sw.WriteLine("           合计:                  " + newmoney.ToString());//合计金额
                sw.WriteLine("           现金:                  " + textBox3.Text.Trim());//实收现金
                sw.WriteLine("           找赎:                  " + textBox4.Text.Trim());//实收现金
                sw.WriteLine("                                         \t\t");
                sw.WriteLine("                                         \t\t");
                sw.WriteLine("日期/时间 " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                sw.WriteLine("                                                ");
                sw.WriteLine("服务热线:0755-12435682");
                sw.Close();
                #endregion
                #endregion
                #region 第三部,进行打印
                System.Windows.Forms.PrintDialog PrintDialog1 = new PrintDialog();
                PrintDialog1.AllowSomePages = true;
                PrintDialog1.ShowHelp = true;

                // 把PrintDialog的Document属性设为上面配置好的PrintDocument的实例
                PrintDialog1.Document = docToPrint;//这是工具箱中打印的一个 组件名称
                this.docToPrint.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(docToPrint_PrintPage);

                // 调用PrintDialog的ShowDialog函数显示打印对话框
                DialogResult result = PrintDialog1.ShowDialog();

                if (result == DialogResult.OK)// 弹出设置打印机,如果不需要设置,第三部可简写为   docToPrint.Print(); 则开始进行打印了
                {
                    // 开始打印
                    docToPrint.Print();

                }
                #endregion
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
            #endregion
    二、B/S的样图如下:
       
     B/S的和C/S的类似
    完整的程序如下:/Files/ggbbeyou/超市购物小票.rar
  • 相关阅读:
    电话线路使用的带通虑波器的宽带为3KHz (300~3300Hz),根据奈奎斯特采样定理,最小采样频率应为(16)。
    总线宽度为32bit,时钟频率为200MHz,若总线上每5个时钟周期传送一个32bit的字,则该总线的带宽为 (4) MB/S。
    安全需求可划分为物理安全、网络安全、系统安全和应用安全,下面的安全需求中属于系统安全的是(67),属于应用安全的是(68)。
    IP地址202.117.17.254/22是什么地址?
    公司的到一个B类地址块,需要划分成若干个包含1000台主机的子网,则可以划分成几个?
    PGP(Pretty Good Privacy)是一种电子邮件加密软件包,它提供数据加密和数字签名两种服务,采用(42)进行身份认证,使用(43) (128位密钥)进行数据加密,使用(44)进行数据完整性验证。 A.RSA公钥证书 B.RSA私钥证书 C.Kerboros证书 D.DES私钥证书
    comet反向Ajax模型原理与模型(笔记一)
    EasyARM-iMX257_U-Boot源代码移植分析
    linux移植u-boot(一)——U-Boot详解+自定义命令实战
    Ajax实现大文件切割上传
  • 原文地址:https://www.cnblogs.com/ggbbeyou/p/1571442.html
Copyright © 2011-2022 走看看