/// <summary> /// 0:提交失败 1:成功 2:没有可提交的数据 3:沽清失败 /// </summary> private Int32 SubmitSalesOrder(string deskName, EatWayType eatType) { int result = 0; Guid orderId; if (_salesOrder == null) //新增的菜单 { orderId = Guid.NewGuid(); } else { orderId = _salesOrder.order.OrderID; } IList<GoodsCheckStock> temp = new List<GoodsCheckStock>(); IList<OrderDetails> newOrderDetailsList = new List<OrderDetails>(); IList<OrderDiscount> newOrderDiscountList = new List<OrderDiscount>(); foreach (DataGridViewRow dr in dgvGoodsOrder.Rows) { if (dr.Cells["OrderDetailsID"].Value == null) { Guid orderDetailsId = Guid.NewGuid(); int itemType = Convert.ToInt32(dr.Cells["ItemType"].Value); string goodsName = dr.Cells["GoodsName"].Value.ToString(); //填充OrderDetails OrderDetails orderDetails = new OrderDetails(); orderDetails.OrderDetailsID = orderDetailsId; orderDetails.OrderID = orderId; orderDetails.DeviceNo = ConstantValuePool.BizSettingConfig.DeviceNo; orderDetails.TotalSellPrice = Convert.ToDecimal(dr.Cells["GoodsPrice"].Value); orderDetails.TotalDiscount = Convert.ToDecimal(dr.Cells["GoodsDiscount"].Value); orderDetails.ItemQty = Convert.ToDecimal(dr.Cells["GoodsNum"].Value); orderDetails.EmployeeID = ConstantValuePool.CurrentEmployee.EmployeeID; if (dr.Cells["Wait"].Value != null) { orderDetails.Wait = Convert.ToInt32(dr.Cells["Wait"].Value); } if (itemType == (int)OrderItemType.Goods) { orderDetails.ItemType = (int)OrderItemType.Goods; Goods goods = dr.Cells["ItemID"].Tag as Goods; if (goods != null) { orderDetails.GoodsID = goods.GoodsID; orderDetails.GoodsNo = goods.GoodsNo; orderDetails.GoodsName = goods.GoodsName; orderDetails.Unit = goods.Unit; orderDetails.CanDiscount = goods.CanDiscount; orderDetails.SellPrice = goods.SellPrice; orderDetails.PrintSolutionName = goods.PrintSolutionName; orderDetails.DepartID = goods.DepartID; if (goods.IsCheckStock) { GoodsCheckStock goodsCheckStock = new GoodsCheckStock(); goodsCheckStock.GoodsID = goods.GoodsID; goodsCheckStock.GoodsName = goods.GoodsName; goodsCheckStock.ReducedQuantity = orderDetails.ItemQty; temp.Add(goodsCheckStock); } } } else if (itemType == (int)OrderItemType.Details) { orderDetails.ItemType = (int)OrderItemType.Details; Details details = dr.Cells["ItemID"].Tag as Details; if (details != null) { orderDetails.GoodsID = details.DetailsID; orderDetails.GoodsNo = details.DetailsNo; orderDetails.GoodsName = details.DetailsName; orderDetails.CanDiscount = details.CanDiscount; orderDetails.Unit = ""; // orderDetails.SellPrice = details.SellPrice; orderDetails.PrintSolutionName = details.PrintSolutionName; orderDetails.DepartID = details.DepartID; } int index = goodsName.LastIndexOf('-'); string itemPrefix = goodsName.Substring(0, index + 1); orderDetails.ItemLevel = itemPrefix.Length / 2; } else if (itemType == (int)OrderItemType.SetMeal) { orderDetails.ItemType = (int)OrderItemType.SetMeal; int index = goodsName.LastIndexOf('-'); string itemPrefix = goodsName.Substring(0, index + 1); orderDetails.ItemLevel = itemPrefix.Length / 2; object item = dr.Cells["ItemID"].Tag; if (item is Goods) { Goods goods = item as Goods; orderDetails.GoodsID = goods.GoodsID; orderDetails.GoodsNo = goods.GoodsNo; orderDetails.GoodsName = goods.GoodsName; orderDetails.CanDiscount = goods.CanDiscount; orderDetails.Unit = goods.Unit; orderDetails.SellPrice = goods.SellPrice; orderDetails.PrintSolutionName = goods.PrintSolutionName; orderDetails.DepartID = goods.DepartID; } else if (item is Details) { Details details = item as Details; orderDetails.GoodsID = details.DetailsID; orderDetails.GoodsNo = details.DetailsNo; orderDetails.GoodsName = details.DetailsName; orderDetails.CanDiscount = details.CanDiscount; orderDetails.Unit = ""; // orderDetails.SellPrice = details.SellPrice; orderDetails.PrintSolutionName = details.PrintSolutionName; orderDetails.DepartID = details.DepartID; } } newOrderDetailsList.Add(orderDetails); //填充OrderDiscount Discount discount = dr.Cells["GoodsDiscount"].Tag as Discount; if (discount != null) { decimal offPay = Math.Abs(Convert.ToDecimal(dr.Cells["GoodsDiscount"].Value)); if (offPay > 0) { OrderDiscount orderDiscount = new OrderDiscount(); orderDiscount.OrderDiscountID = Guid.NewGuid(); orderDiscount.OrderID = orderId; orderDiscount.OrderDetailsID = orderDetailsId; orderDiscount.DiscountID = discount.DiscountID; orderDiscount.DiscountName = discount.DiscountName; orderDiscount.DiscountType = discount.DiscountType; orderDiscount.DiscountRate = discount.DiscountRate; orderDiscount.OffFixPay = discount.OffFixPay; orderDiscount.OffPay = offPay; orderDiscount.EmployeeID = ConstantValuePool.CurrentEmployee.EmployeeID; newOrderDiscountList.Add(orderDiscount); } } } else { //修改过折扣的账单 Discount discount = dr.Cells["GoodsDiscount"].Tag as Discount; if (discount != null) { Guid orderDetailsId = new Guid(dr.Cells["OrderDetailsID"].Value.ToString()); //填充OrderDetails OrderDetails orderDetails = new OrderDetails(); orderDetails.OrderDetailsID = orderDetailsId; orderDetails.OrderID = orderId; orderDetails.DeviceNo = ConstantValuePool.BizSettingConfig.DeviceNo; orderDetails.ItemQty = Convert.ToDecimal(dr.Cells["GoodsNum"].Value); orderDetails.ItemType = Convert.ToInt32(dr.Cells["ItemType"].Value); orderDetails.GoodsName = dr.Cells["GoodsName"].Value.ToString(); orderDetails.TotalSellPrice = Convert.ToDecimal(dr.Cells["GoodsPrice"].Value); orderDetails.TotalDiscount = Convert.ToDecimal(dr.Cells["GoodsDiscount"].Value); orderDetails.Unit = dr.Cells["ItemUnit"].Value.ToString(); orderDetails.EmployeeID = ConstantValuePool.CurrentEmployee.EmployeeID; if (dr.Cells["Wait"].Value != null) { orderDetails.Wait = Convert.ToInt32(dr.Cells["Wait"].Value); } newOrderDetailsList.Add(orderDetails); //填充OrderDiscount decimal offPay = Math.Abs(Convert.ToDecimal(dr.Cells["GoodsDiscount"].Value)); if (offPay > 0) { OrderDiscount orderDiscount = new OrderDiscount(); orderDiscount.OrderDiscountID = Guid.NewGuid(); orderDiscount.OrderID = orderId; orderDiscount.OrderDetailsID = orderDetailsId; orderDiscount.DiscountID = discount.DiscountID; orderDiscount.DiscountName = discount.DiscountName; orderDiscount.DiscountType = discount.DiscountType; orderDiscount.DiscountRate = discount.DiscountRate; orderDiscount.OffFixPay = discount.OffFixPay; orderDiscount.OffPay = offPay; orderDiscount.EmployeeID = ConstantValuePool.CurrentEmployee.EmployeeID; newOrderDiscountList.Add(orderDiscount); } } } } //品项沽清 IList<GoodsCheckStock> tempGoodsStockList = GoodsService.GetInstance().GetGoodsCheckStock(); if (tempGoodsStockList != null && tempGoodsStockList.Count > 0 && temp.Count > 0) { IList<GoodsCheckStock> goodsCheckStockList = new List<GoodsCheckStock>(); foreach (GoodsCheckStock item in temp) { bool isContains = tempGoodsStockList.Any(tempGoodsStock => item.GoodsID.Equals(tempGoodsStock.GoodsID)); if (isContains) { goodsCheckStockList.Add(item); } } if (goodsCheckStockList.Count > 0) { string goodsName = GoodsService.GetInstance().UpdateReducedGoodsQty(goodsCheckStockList); if (!string.IsNullOrEmpty(goodsName)) { MessageBox.Show(string.Format("<{0}> 的剩余数量不足!", goodsName), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return 3; } } } if (_salesOrder == null) //新增的菜单 { Order order = new Order(); order.OrderID = orderId; order.TotalSellPrice = _totalPrice; order.ActualSellPrice = _actualPayMoney; order.DiscountPrice = _discount; order.CutOffPrice = _cutOff; order.ServiceFee = 0; order.DeviceNo = ConstantValuePool.BizSettingConfig.DeviceNo; order.DeskName = deskName; order.EatType = (int)eatType; order.Status = 0; order.PeopleNum = 1; order.EmployeeID = ConstantValuePool.CurrentEmployee.EmployeeID; order.EmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo; SalesOrder salesOrder = new SalesOrder(); salesOrder.order = order; salesOrder.orderDetailsList = newOrderDetailsList; salesOrder.orderDiscountList = newOrderDiscountList; int tranSequence = SalesOrderService.GetInstance().CreateSalesOrder(salesOrder); if (tranSequence > 0) { //重新加载 _salesOrder = SalesOrderService.GetInstance().GetSalesOrder(orderId); BindGoodsOrderInfo(); //绑定订单信息 BindOrderInfoSum(); result = 1; } } else { if (newOrderDetailsList.Count > 0) { Order order = new Order(); order.OrderID = orderId; order.TotalSellPrice = _totalPrice; order.ActualSellPrice = _actualPayMoney; order.DiscountPrice = _discount; order.CutOffPrice = _cutOff; order.ServiceFee = 0; order.DeviceNo = ConstantValuePool.BizSettingConfig.DeviceNo; order.DeskName = deskName; order.PeopleNum = 1; order.EmployeeID = ConstantValuePool.CurrentEmployee.EmployeeID; order.EmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo; SalesOrder salesOrder = new SalesOrder(); salesOrder.order = order; salesOrder.orderDetailsList = newOrderDetailsList; salesOrder.orderDiscountList = newOrderDiscountList; if (SalesOrderService.GetInstance().UpdateSalesOrder(salesOrder) == 1) { //重新加载 _salesOrder = SalesOrderService.GetInstance().GetSalesOrder(orderId); BindGoodsOrderInfo(); //绑定订单信息 BindOrderInfoSum(); result = 1; } } else { result = 2; } } if (eatType == EatWayType.OutsideOrder) { if (result == 1 || result == 2) { //添加外送信息 CustomerOrder customerOrder = new CustomerOrder { OrderID = orderId, Telephone = txtTelephone.Text.Trim(), CustomerName = txtName.Text.Trim(), Address = txtAddress.Text.Trim() }; if (!string.IsNullOrEmpty(customerOrder.Telephone) && !string.IsNullOrEmpty(customerOrder.CustomerName)) { if (CustomersService.GetInstance().CreateOrUpdateCustomerOrder(customerOrder)) { result = 1; } else { MessageBox.Show("添加外送信息失败!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } if (eatType == EatWayType.Takeout) { if (result == 1) { if (ConstantValuePool.BizSettingConfig.TakeoutPrint && ConstantValuePool.BizSettingConfig.printConfig.Enabled) { //打印 PrintData printData = new PrintData(); printData.ShopName = ConstantValuePool.CurrentShop.ShopName; printData.DeskName = deskName; printData.PersonNum = "1"; printData.PrintTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); printData.EmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo; printData.TranSequence = _salesOrder.order.TranSequence.ToString(); printData.ShopAddress = ConstantValuePool.CurrentShop.RunAddress; printData.Telephone = ConstantValuePool.CurrentShop.Telephone; printData.GoodsOrderList = new List<GoodsOrder>(); foreach (OrderDetails item in newOrderDetailsList) { string strLevelFlag = string.Empty; if (item.ItemLevel > 0) { int levelCount = item.ItemLevel * 2; for (int i = 0; i < levelCount; i++) { strLevelFlag += "-"; } } GoodsOrder goodsOrder = new GoodsOrder(); goodsOrder.GoodsName = strLevelFlag + item.GoodsName; goodsOrder.GoodsNum = item.ItemQty.ToString("f1"); goodsOrder.SellPrice = (item.TotalSellPrice / item.ItemQty).ToString("f2"); goodsOrder.TotalSellPrice = item.TotalSellPrice.ToString("f2"); goodsOrder.TotalDiscount = item.TotalDiscount.ToString("f2"); goodsOrder.Unit = item.Unit; printData.GoodsOrderList.Add(goodsOrder); } int copies = ConstantValuePool.BizSettingConfig.printConfig.Copies; string paperWidth = ConstantValuePool.BizSettingConfig.printConfig.PaperWidth; if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.DRIVER) { string printerName = ConstantValuePool.BizSettingConfig.printConfig.Name; string paperName = ConstantValuePool.BizSettingConfig.printConfig.PaperName; DriverOrderPrint printer = DriverOrderPrint.GetInstance(printerName, paperName, paperWidth); for (int i = 0; i < copies; i++) { printer.DoPrintOrder(printData); } } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.COM) { string port = ConstantValuePool.BizSettingConfig.printConfig.Name; if (port.Length > 3) { if (port.Substring(0, 3).ToUpper() == "COM") { string portName = port.Substring(0, 4).ToUpper(); InstructionOrderPrint printer = new InstructionOrderPrint(portName, 9600, Parity.None, 8, StopBits.One, paperWidth); for (int i = 0; i < copies; i++) { printer.DoPrintOrder(printData); } } } } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.ETHERNET) { string ipAddress = ConstantValuePool.BizSettingConfig.printConfig.Name; InstructionOrderPrint printer = new InstructionOrderPrint(ipAddress, 9100, paperWidth); for (int i = 0; i < copies; i++) { printer.DoPrintOrder(printData); } } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.USB) { string vid = ConstantValuePool.BizSettingConfig.printConfig.VID; string pid = ConstantValuePool.BizSettingConfig.printConfig.PID; string endpointId = ConstantValuePool.BizSettingConfig.printConfig.EndpointID; InstructionOrderPrint printer = new InstructionOrderPrint(vid, pid, endpointId, paperWidth); for (int i = 0; i < copies; i++) { printer.DoPrintOrder(printData); } } } } } return result; }
private void btnCheckOut_Click(object sender, EventArgs e) { if (m_ActualPayMoney > m_PaidInAmount) { // 支付的金额不足 MessageBox.Show("支付的金额不足,请确认后重新付款!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (m_PaidInAmount > m_ActualPayMoney) { decimal cash = 0, noCash = 0; List<OrderPayoff> noCashPayoff = new List<OrderPayoff>(); foreach (KeyValuePair<string, OrderPayoff> item in dic) { if (item.Value.PayoffType == (int)PayoffWayMode.Cash) { cash += item.Value.AsPay * item.Value.Quantity; } else { noCash += item.Value.AsPay * item.Value.Quantity; noCashPayoff.Add(item.Value); } } if (noCash > m_ActualPayMoney) { //非现金支付方式按单位价值从高到低排序 OrderPayoff[] noCashPayoffArr = noCashPayoff.ToArray(); for (int j = 0; j < noCashPayoffArr.Length; j++) { for (int i = noCashPayoffArr.Length - 1; i > j; i--) { if (noCashPayoffArr[j].AsPay < noCashPayoffArr[i].AsPay) { OrderPayoff temp = noCashPayoffArr[j]; noCashPayoffArr[j] = noCashPayoffArr[i]; noCashPayoffArr[i] = temp; } } } if (noCash - noCashPayoffArr[noCashPayoffArr.Length - 1].AsPay < m_ActualPayMoney) { if (cash > 0) { MessageBox.Show("现金支付方式多余!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { MessageBox.Show("非现金支付方式金额过多,请重新支付!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { //由全部非现金及部分现金来支付 decimal changePay = m_PaidInAmount - m_ActualPayMoney; foreach (KeyValuePair<string, OrderPayoff> item in dic) { if (item.Value.PayoffType == (int)PayoffWayMode.Cash) { item.Value.NeedChangePay = changePay; break; } } } } //计算支付的金额并填充OrderPayoff bool isContainsCash = false; bool isContainsVipCard = false; decimal paymentMoney = 0; decimal needChangePay = 0; List<OrderPayoff> orderPayoffList = new List<OrderPayoff>(); foreach (KeyValuePair<string, OrderPayoff> item in dic) { if (item.Value.Quantity > 0) { if (item.Value.PayoffType == (int)PayoffWayMode.Cash) { isContainsCash = true; } if (item.Value.PayoffType == (int)PayoffWayMode.MembershipCard) { isContainsVipCard = true; } OrderPayoff orderPayoff = item.Value; paymentMoney += orderPayoff.AsPay * orderPayoff.Quantity; needChangePay += orderPayoff.NeedChangePay; orderPayoffList.Add(orderPayoff); } } if (isContainsCash) { //支付方式中包含现金,需要打开钱箱 OpenCashBox(); } bool paySuccess = false; if (isContainsVipCard) { Dictionary<string, VIPCardPayment> dicCardPayment; Dictionary<string, string> dicCardTradePayNo; if (IsVipCardPaySuccess(out dicCardPayment, out dicCardTradePayNo)) { //组合交易流水号,因为需要支持多张会员卡 string strTradePayNo = string.Empty; foreach (KeyValuePair<string, string> item in dicCardTradePayNo) { strTradePayNo += "," + item.Value; } strTradePayNo = strTradePayNo.Substring(1); //将支付方式中的卡号密码去掉 foreach (var orderPayoff in orderPayoffList) { if (orderPayoff.PayoffType == (int) PayoffWayMode.MembershipCard) { if (!string.IsNullOrEmpty(orderPayoff.CardNo)) { orderPayoff.CardNo = orderPayoff.CardNo.Split('#')[0]; } } } // 支付服务尝试三次 int times = 0; while (times < 3 && !paySuccess) { paySuccess = PayForOrder(orderPayoffList, paymentMoney, needChangePay, strTradePayNo); times++; Thread.Sleep(500); } if (!paySuccess) { //取消会员卡支付 foreach (KeyValuePair<string, VIPCardPayment> item in dicCardPayment) { string cardNo = item.Value.CardNo; //将支付成功的会员卡取消支付 int returnValue = VIPCardTradeService.GetInstance().RefundVipCardPayment(cardNo, item.Value.CardPassword, dicCardTradePayNo[cardNo]); if (returnValue == 1) continue; if (returnValue == 2) { MessageBox.Show(string.Format("交易流水号'{0}'不存在或者已作废", dicCardTradePayNo[cardNo]), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (returnValue == 99) { MessageBox.Show(string.Format("'{0}'的会员卡号或者密码错误!", cardNo), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("服务器出现错误,请重新操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } //保存到本地Sqlite CardRefundPay cardRefundPay = new CardRefundPay(); cardRefundPay.CardNo = cardNo; cardRefundPay.ShopID = ConstantValuePool.CurrentShop.ShopID.ToString(); cardRefundPay.TradePayNo = dicCardTradePayNo[cardNo]; cardRefundPay.PayAmount = item.Value.PayAmount; cardRefundPay.EmployeeNo = item.Value.EmployeeNo; cardRefundPay.DeviceNo = item.Value.DeviceNo; CardRefundPayService refundPayService = new CardRefundPayService(); refundPayService.AddRefundPayInfo(cardRefundPay); } } } else { MessageBox.Show("会员卡支付操作失败,请稍后再试!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { paySuccess = PayForOrder(orderPayoffList, paymentMoney, needChangePay, string.Empty); } if (paySuccess) { //打印小票 PrintData printData = new PrintData(); printData.ShopName = ConstantValuePool.CurrentShop.ShopName; printData.DeskName = m_SalesOrder.order.DeskName; printData.PersonNum = m_SalesOrder.order.PeopleNum.ToString(); printData.PrintTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); printData.EmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo; printData.TranSequence = m_SalesOrder.order.TranSequence.ToString(); printData.ShopAddress = ConstantValuePool.CurrentShop.RunAddress; printData.Telephone = ConstantValuePool.CurrentShop.Telephone; printData.ReceivableMoney = m_ActualPayMoney.ToString("f2"); printData.ServiceFee = "0.00"; printData.PaidInMoney = paymentMoney.ToString("f2"); printData.NeedChangePay = needChangePay.ToString("f2"); printData.GoodsOrderList = new List<GoodsOrder>(); printData.PayingOrderList = new List<PayingGoodsOrder>(); foreach (OrderDetails item in m_SalesOrder.orderDetailsList) { string strLevelFlag = string.Empty; int levelCount = item.ItemLevel * 2; for (int i = 0; i < levelCount; i++) { strLevelFlag += "-"; } GoodsOrder goodsOrder = new GoodsOrder(); goodsOrder.GoodsName = strLevelFlag + item.GoodsName; goodsOrder.GoodsNum = item.ItemQty.ToString("f1"); goodsOrder.SellPrice = item.SellPrice.ToString("f2"); goodsOrder.TotalSellPrice = item.TotalSellPrice.ToString("f2"); goodsOrder.TotalDiscount = item.TotalDiscount.ToString("f2"); goodsOrder.Unit = item.Unit; printData.GoodsOrderList.Add(goodsOrder); } foreach (OrderPayoff orderPayoff in orderPayoffList) { PayingGoodsOrder payingOrder = new PayingGoodsOrder(); payingOrder.PayoffName = orderPayoff.PayoffName; payingOrder.PayoffMoney = (orderPayoff.AsPay * orderPayoff.Quantity).ToString("f2"); payingOrder.NeedChangePay = orderPayoff.NeedChangePay.ToString("f2"); printData.PayingOrderList.Add(payingOrder); } string paperWidth = ConstantValuePool.BizSettingConfig.printConfig.PaperWidth; if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.DRIVER) { string printerName = ConstantValuePool.BizSettingConfig.printConfig.Name; string paperName = ConstantValuePool.BizSettingConfig.printConfig.PaperName; DriverOrderPrint printer = DriverOrderPrint.GetInstance(printerName, paperName, paperWidth); printer.DoPrintPaidOrder(printData); } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.COM) { string port = ConstantValuePool.BizSettingConfig.printConfig.Name; if (port.Length > 3) { if (port.Substring(0, 3).ToUpper() == "COM") { string portName = port.Substring(0, 4).ToUpper(); InstructionOrderPrint printer = new InstructionOrderPrint(portName, 9600, Parity.None, 8, StopBits.One, paperWidth); printer.DoPrintPaidOrder(printData); } } } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.ETHERNET) { string ipAddress = ConstantValuePool.BizSettingConfig.printConfig.Name; InstructionOrderPrint printer = new InstructionOrderPrint(ipAddress, 9100, paperWidth); printer.DoPrintPaidOrder(printData); } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.USB) { string vid = ConstantValuePool.BizSettingConfig.printConfig.VID; string pid = ConstantValuePool.BizSettingConfig.printConfig.PID; string endpointId = ConstantValuePool.BizSettingConfig.printConfig.EndpointID; InstructionOrderPrint printer = new InstructionOrderPrint(vid, pid, endpointId, paperWidth); printer.DoPrintPaidOrder(printData); } //判断单据类型,如果是外带并且是直接出货 if (m_SalesOrder.order.EatType == (int)EatWayType.Takeout && ConstantValuePool.BizSettingConfig.DirectShipping) { CustomerOrder customerOrder = new CustomerOrder { OrderID = m_SalesOrder.order.OrderID, DeliveryEmployeeNo = string.Empty }; CustomersService.GetInstance().UpdateTakeoutOrderStatus(customerOrder); } m_IsPaidOrder = true; this.Close(); } else { MessageBox.Show("账单支付失败!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnPrintBill_Click(object sender, EventArgs e) { if (dgvGoodsOrder.Rows.Count > 0) { foreach (DataGridViewRow dr in dgvGoodsOrder.Rows) { if (dr.Cells["OrderDetailsID"].Value == null) { MessageBox.Show("存在新单,不能印单!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (ConstantValuePool.BizSettingConfig.printConfig.Enabled) { //打印 PrintData printData = new PrintData(); printData.ShopName = ConstantValuePool.CurrentShop.ShopName; printData.DeskName = _salesOrder.order.DeskName; printData.PersonNum = "1"; printData.PrintTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); printData.EmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo; printData.TranSequence = _salesOrder.order.TranSequence.ToString(); printData.ShopAddress = ConstantValuePool.CurrentShop.RunAddress; printData.Telephone = ConstantValuePool.CurrentShop.Telephone; printData.GoodsOrderList = new List<GoodsOrder>(); foreach (DataGridViewRow dr in dgvGoodsOrder.Rows) { GoodsOrder goodsOrder = new GoodsOrder(); goodsOrder.GoodsName = dr.Cells["GoodsName"].Value.ToString(); decimal itemQty = Convert.ToDecimal(dr.Cells["GoodsNum"].Value); decimal totalSellPrice = Convert.ToDecimal(dr.Cells["GoodsPrice"].Value); goodsOrder.GoodsNum = itemQty.ToString("f1"); goodsOrder.SellPrice = (totalSellPrice/itemQty).ToString("f2"); goodsOrder.TotalSellPrice = totalSellPrice.ToString("f2"); goodsOrder.TotalDiscount = Convert.ToDecimal(dr.Cells["GoodsDiscount"].Value).ToString("f2"); goodsOrder.Unit = dr.Cells["ItemUnit"].Value.ToString(); printData.GoodsOrderList.Add(goodsOrder); } printData.CustomerPhone = this.txtTelephone.Text.Trim(); printData.CustomerName = this.txtName.Text.Trim(); printData.DeliveryAddress = this.txtAddress.Text.Trim(); printData.Remark = string.Empty; printData.DeliveryEmployeeName = string.Empty; string paperWidth = ConstantValuePool.BizSettingConfig.printConfig.PaperWidth; if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.DRIVER) { string printerName = ConstantValuePool.BizSettingConfig.printConfig.Name; string paperName = ConstantValuePool.BizSettingConfig.printConfig.PaperName; DriverOrderPrint printer = DriverOrderPrint.GetInstance(printerName, paperName, paperWidth); if (_salesOrder.order.EatType == (int) EatWayType.Takeout) { printer.DoPrintOrder(printData); } else { printer.DoPrintDeliveryOrder(printData); } } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.COM) { string port = ConstantValuePool.BizSettingConfig.printConfig.Name; if (port.Length > 3) { if (port.Substring(0, 3).ToUpper() == "COM") { string portName = port.Substring(0, 4).ToUpper(); InstructionOrderPrint printer = new InstructionOrderPrint(portName, 9600, Parity.None, 8, StopBits.One, paperWidth); if (_salesOrder.order.EatType == (int) EatWayType.Takeout) { printer.DoPrintOrder(printData); } else { printer.DoPrintDeliveryOrder(printData); } } } } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.ETHERNET) { string ipAddress = ConstantValuePool.BizSettingConfig.printConfig.Name; InstructionOrderPrint printer = new InstructionOrderPrint(ipAddress, 9100, paperWidth); if (_salesOrder.order.EatType == (int) EatWayType.Takeout) { printer.DoPrintOrder(printData); } else { printer.DoPrintDeliveryOrder(printData); } } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.USB) { string vid = ConstantValuePool.BizSettingConfig.printConfig.VID; string pid = ConstantValuePool.BizSettingConfig.printConfig.PID; string endpointId = ConstantValuePool.BizSettingConfig.printConfig.EndpointID; InstructionOrderPrint printer = new InstructionOrderPrint(vid, pid, endpointId, paperWidth); if (_salesOrder.order.EatType == (int) EatWayType.Takeout) { printer.DoPrintOrder(printData); } else { printer.DoPrintDeliveryOrder(printData); } } } } }
private void btnDelivery_Click(object sender, EventArgs e) { CustomerOrder customerOrder = new CustomerOrder(); customerOrder.OrderID = _salesOrder.order.OrderID; customerOrder.Telephone = this.txtTelephone.Text.Trim(); customerOrder.CustomerName = this.txtName.Text.Trim(); customerOrder.Address = this.txtAddress.Text.Trim(); customerOrder.Remark = this.txtRemark.Text.Trim(); customerOrder.DeliveryEmployeeNo = this.txtEmployeeNo.Text.Trim(); if (CustomersService.GetInstance().UpdateTakeoutOrderStatus(customerOrder)) { //打印 _printData.CustomerPhone = this.txtTelephone.Text.Trim(); _printData.CustomerName = this.txtName.Text.Trim(); _printData.DeliveryAddress = this.txtAddress.Text.Trim(); _printData.Remark = this.txtRemark.Text.Trim(); _printData.DeliveryEmployeeName = this.txtEmployeeName.Text.Trim(); if (ConstantValuePool.BizSettingConfig.printConfig.Enabled) { int copies = ConstantValuePool.BizSettingConfig.printConfig.Copies; string paperWidth = ConstantValuePool.BizSettingConfig.printConfig.PaperWidth; if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.DRIVER) { string printerName = ConstantValuePool.BizSettingConfig.printConfig.Name; string paperName = ConstantValuePool.BizSettingConfig.printConfig.PaperName; DriverOrderPrint printer = DriverOrderPrint.GetInstance(printerName, paperName, paperWidth); for (int i = 0; i < copies; i++) { printer.DoPrintDeliveryOrder(_printData); } } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.COM) { string port = ConstantValuePool.BizSettingConfig.printConfig.Name; if (port.Length > 3) { if (port.Substring(0, 3).ToUpper() == "COM") { string portName = port.Substring(0, 4).ToUpper(); InstructionOrderPrint printer = new InstructionOrderPrint(portName, 9600, Parity.None, 8, StopBits.One, paperWidth); for (int i = 0; i < copies; i++) { printer.DoPrintDeliveryOrder(_printData); } } } } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.ETHERNET) { string ipAddress = ConstantValuePool.BizSettingConfig.printConfig.Name; InstructionOrderPrint printer = new InstructionOrderPrint(ipAddress, 9100, paperWidth); for (int i = 0; i < copies; i++) { printer.DoPrintDeliveryOrder(_printData); } } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.USB) { string vid = ConstantValuePool.BizSettingConfig.printConfig.VID; string pid = ConstantValuePool.BizSettingConfig.printConfig.PID; string endpointId = ConstantValuePool.BizSettingConfig.printConfig.EndpointID; InstructionOrderPrint printer = new InstructionOrderPrint(vid, pid, endpointId, paperWidth); for (int i = 0; i < copies; i++) { printer.DoPrintDeliveryOrder(_printData); } } } _hasDeliveried = true; this.Close(); } else { MessageBox.Show("出货失败,请重新操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void btnConfirm_Click(object sender, EventArgs e) { decimal needChangePay = 0; //找零 decimal receMoney = decimal.Parse(lbReceMoney.Text); //应收 decimal paidInMoney = decimal.Parse(lbPaidInMoney.Text); //实收 if (paidInMoney == 0) { //判断是否直接支付 if (DialogResult.No == MessageBox.Show("警告,当前未选择任何支付方式,是否以现金继续结账?", "信息提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) return; } if (receMoney + m_ServiceFee < paidInMoney) { decimal cash = 0, noCash = 0; List<OrderPayoff> noCashPayoff = new List<OrderPayoff>(); foreach (KeyValuePair<string, OrderPayoff> item in dic) { if (item.Value.PayoffType == (int)PayoffWayMode.Cash) { cash += item.Value.AsPay * item.Value.Quantity; } else { noCash += item.Value.AsPay * item.Value.Quantity; noCashPayoff.Add(item.Value); } } if (noCash > receMoney + m_ServiceFee) { //非现金支付方式按单位价值从高到低排序 OrderPayoff[] noCashPayoffArr = noCashPayoff.ToArray(); for (int j = 0; j < noCashPayoffArr.Length; j++) { for (int i = noCashPayoffArr.Length - 1; i > j; i--) { if (noCashPayoffArr[j].AsPay < noCashPayoffArr[i].AsPay) { OrderPayoff temp = noCashPayoffArr[j]; noCashPayoffArr[j] = noCashPayoffArr[i]; noCashPayoffArr[i] = temp; } } } if (noCash - noCashPayoffArr[noCashPayoffArr.Length - 1].AsPay < receMoney + m_ServiceFee) { if (cash > 0) { MessageBox.Show("现金支付方式多余!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { MessageBox.Show("非现金支付方式金额过多,请重新支付!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { //由全部非现金及部分现金来支付 needChangePay = paidInMoney - (receMoney + m_ServiceFee); foreach (KeyValuePair<string, OrderPayoff> item in dic) { if (item.Value.PayoffType == (int)PayoffWayMode.Cash) { item.Value.NeedChangePay = needChangePay; break; } } } } if (receMoney + m_ServiceFee > paidInMoney) { // 支付的金额不足, 现金补足 foreach (PayoffWay temp in ConstantValuePool.PayoffWayList) { if (temp.PayoffType == (int)PayoffWayMode.Cash) { if (dic.ContainsKey(temp.PayoffID.ToString())) { OrderPayoff orderPayoff = dic[temp.PayoffID.ToString()]; orderPayoff.Quantity += (receMoney + m_ServiceFee - paidInMoney) / temp.AsPay; } else { OrderPayoff orderPayoff = new OrderPayoff(); orderPayoff.OrderPayoffID = Guid.NewGuid(); orderPayoff.OrderID = m_SalesOrder.order.OrderID; orderPayoff.PayoffID = temp.PayoffID; orderPayoff.PayoffName = temp.PayoffName; orderPayoff.PayoffType = temp.PayoffType; orderPayoff.AsPay = temp.AsPay; orderPayoff.Quantity = (receMoney + m_ServiceFee - paidInMoney) / temp.AsPay; orderPayoff.CardNo = ""; orderPayoff.EmployeeID = ConstantValuePool.CurrentEmployee.EmployeeID; dic.Add(temp.PayoffID.ToString(), orderPayoff); } break; } } } //计算支付的金额并填充OrderPayoff bool isContainsCash = false; bool isContainsVipCard = false; decimal paymentMoney = 0; List<OrderPayoff> orderPayoffList = new List<OrderPayoff>(); foreach (KeyValuePair<string, OrderPayoff> item in dic) { if (item.Value.Quantity > 0) { if (item.Value.PayoffType == (int)PayoffWayMode.Cash) { isContainsCash = true; } if (item.Value.PayoffType == (int)PayoffWayMode.MembershipCard) { isContainsVipCard = true; } OrderPayoff orderPayoff = item.Value; paymentMoney += orderPayoff.AsPay * orderPayoff.Quantity; orderPayoffList.Add(orderPayoff); } } if (isContainsCash) { //支付方式中包含现金,需要打开钱箱 OpenCashBox(); } bool paySuccess = false; if (isContainsVipCard) { Dictionary<string, VIPCardPayment> dicCardPayment; Dictionary<string, string> dicCardTradePayNo; if (IsVipCardPaySuccess(out dicCardPayment, out dicCardTradePayNo)) { //组合交易流水号,因为需要支持多张会员卡 string strTradePayNo = string.Empty; foreach (KeyValuePair<string, string> item in dicCardTradePayNo) { strTradePayNo += "," + item.Value; } strTradePayNo = strTradePayNo.Substring(1); //将支付方式中的卡号密码去掉 foreach (var orderPayoff in orderPayoffList) { if (orderPayoff.PayoffType == (int)PayoffWayMode.MembershipCard) { if (!string.IsNullOrEmpty(orderPayoff.CardNo)) { orderPayoff.CardNo = orderPayoff.CardNo.Split('#')[0]; } } } // 支付服务尝试三次 int times = 0; while (times < 3 && !paySuccess) { paySuccess = PayForOrder(orderPayoffList, paymentMoney, needChangePay, strTradePayNo); times++; Thread.Sleep(500); } if (!paySuccess) { //取消会员卡支付 foreach (KeyValuePair<string, VIPCardPayment> item in dicCardPayment) { string cardNo = item.Value.CardNo; //将支付成功的会员卡取消支付 int returnValue = VIPCardTradeService.GetInstance().RefundVipCardPayment(cardNo, item.Value.CardPassword, dicCardTradePayNo[cardNo]); if (returnValue == 1) continue; if (returnValue == 2) { MessageBox.Show(string.Format("交易流水号'{0}'不存在或者已作废", dicCardTradePayNo[cardNo]), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (returnValue == 99) { MessageBox.Show(string.Format("'{0}'的会员卡号或者密码错误!", cardNo), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("服务器出现错误,请重新操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } //保存到本地Sqlite CardRefundPay cardRefundPay = new CardRefundPay { CardNo = cardNo, ShopID = ConstantValuePool.CurrentShop.ShopID.ToString(), TradePayNo = dicCardTradePayNo[cardNo], PayAmount = item.Value.PayAmount, EmployeeNo = item.Value.EmployeeNo, DeviceNo = item.Value.DeviceNo }; CardRefundPayService refundPayService = new CardRefundPayService(); refundPayService.AddRefundPayInfo(cardRefundPay); } } } else { MessageBox.Show("会员卡支付操作失败,请稍后再试!"); return; } } else { paySuccess = PayForOrder(orderPayoffList, paymentMoney, needChangePay, string.Empty); } if (paySuccess) { //打印小票 PrintData printData = new PrintData(); printData.ShopName = ConstantValuePool.CurrentShop.ShopName; printData.DeskName = m_CurrentDeskName; printData.PersonNum = m_SalesOrder.order.PeopleNum.ToString(); printData.PrintTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); printData.EmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo; printData.TranSequence = m_SalesOrder.order.TranSequence.ToString(); printData.ShopAddress = ConstantValuePool.CurrentShop.RunAddress; printData.Telephone = ConstantValuePool.CurrentShop.Telephone; printData.ReceivableMoney = this.lbReceMoney.Text; printData.ServiceFee = m_ServiceFee.ToString("f2"); printData.PaidInMoney = paymentMoney.ToString("f2"); printData.NeedChangePay = needChangePay.ToString("f2"); printData.GoodsOrderList = new List<GoodsOrder>(); printData.PayingOrderList = new List<PayingGoodsOrder>(); foreach (OrderDetails item in m_SalesOrder.orderDetailsList) { string strLevelFlag = string.Empty; int levelCount = item.ItemLevel * 2; for (int i = 0; i < levelCount; i++) { strLevelFlag += "-"; } GoodsOrder goodsOrder = new GoodsOrder(); goodsOrder.GoodsName = strLevelFlag + item.GoodsName; goodsOrder.GoodsNum = item.ItemQty.ToString("f1"); goodsOrder.SellPrice = item.SellPrice.ToString("f2"); goodsOrder.TotalSellPrice = item.TotalSellPrice.ToString("f2"); goodsOrder.TotalDiscount = item.TotalDiscount.ToString("f2"); goodsOrder.Unit = item.Unit; printData.GoodsOrderList.Add(goodsOrder); } foreach (OrderPayoff orderPayoff in orderPayoffList) { PayingGoodsOrder payingOrder = new PayingGoodsOrder(); payingOrder.PayoffName = orderPayoff.PayoffName; payingOrder.PayoffMoney = (orderPayoff.AsPay * orderPayoff.Quantity).ToString("f2"); payingOrder.NeedChangePay = orderPayoff.NeedChangePay.ToString("f2"); printData.PayingOrderList.Add(payingOrder); } string paperWidth = ConstantValuePool.BizSettingConfig.printConfig.PaperWidth; if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.DRIVER) { string printerName = ConstantValuePool.BizSettingConfig.printConfig.Name; string paperName = ConstantValuePool.BizSettingConfig.printConfig.PaperName; DriverOrderPrint printer = DriverOrderPrint.GetInstance(printerName, paperName, paperWidth); printer.DoPrintPaidOrder(printData); } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.COM) { string port = ConstantValuePool.BizSettingConfig.printConfig.Name; if (port.Length > 3) { if (port.Substring(0, 3).ToUpper() == "COM") { string portName = port.Substring(0, 4).ToUpper(); InstructionOrderPrint printer = new InstructionOrderPrint(portName, 9600, Parity.None, 8, StopBits.One, paperWidth); printer.DoPrintPaidOrder(printData); } } } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.ETHERNET) { string ipAddress = ConstantValuePool.BizSettingConfig.printConfig.Name; InstructionOrderPrint printer = new InstructionOrderPrint(ipAddress, 9100, paperWidth); printer.DoPrintPaidOrder(printData); } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.USB) { string vid = ConstantValuePool.BizSettingConfig.printConfig.VID; string pid = ConstantValuePool.BizSettingConfig.printConfig.PID; string endpointId = ConstantValuePool.BizSettingConfig.printConfig.EndpointID; InstructionOrderPrint printer = new InstructionOrderPrint(vid, pid, endpointId, paperWidth); printer.DoPrintPaidOrder(printData); } m_IsPaidOrder = true; //更新桌况为空闲状态 int status = (int)DeskButtonStatus.IDLE_MODE; if (!DeskService.GetInstance().UpdateDeskStatus(m_CurrentDeskName, string.Empty, status)) { DeskService.GetInstance().UpdateDeskStatus(m_CurrentDeskName, string.Empty, status); } //更新第二屏信息 if (Screen.AllScreens.Length > 1 && ConstantValuePool.BizSettingConfig.SecondScreenEnabled) { if (ConstantValuePool.SecondScreenForm != null && ConstantValuePool.SecondScreenForm is FormSecondScreen) { ((FormSecondScreen)ConstantValuePool.SecondScreenForm).DisplayOrderInfoSum(receMoney + m_ServiceFee, needChangePay, orderPayoffList); } } FormConfirm form = new FormConfirm(receMoney + m_ServiceFee, needChangePay, orderPayoffList); form.ShowDialog(); this.Close(); } else { MessageBox.Show("账单支付失败!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnPreCheck_Click(object sender, EventArgs e) { CrystalButton btn = sender as CrystalButton; Order order = m_SalesOrder.order; if (order.Status == 0) { //存在整单折扣则先提交 //填充Order Order submitOrder = new Order(); submitOrder.OrderID = order.OrderID; submitOrder.TotalSellPrice = m_TotalPrice; submitOrder.ActualSellPrice = m_ActualPayMoney; submitOrder.DiscountPrice = m_Discount; submitOrder.CutOffPrice = m_CutOff; submitOrder.ServiceFee = m_ServiceFee; submitOrder.MembershipCard = m_MembershipCard; submitOrder.MemberDiscount = m_MemberDiscountRate; //填充OrderDetails\OrderDiscount List<OrderDetails> orderDetailsList = new List<OrderDetails>(); List<OrderDiscount> newOrderDiscountList = new List<OrderDiscount>(); foreach (DataGridViewRow dr in dgvGoodsOrder.Rows) { OrderDetails orderDetails = dr.Cells["OrderDetailsID"].Tag as OrderDetails; if (orderDetails != null) { Discount itemDiscount = dr.Cells["GoodsDiscount"].Tag as Discount; decimal itemDiscountPrice = Convert.ToDecimal(dr.Cells["GoodsDiscount"].Value); if (orderDetails.CanDiscount && itemDiscount != null && Math.Abs(itemDiscountPrice) > 0) { orderDetailsList.Add(orderDetails); //OrderDiscount OrderDiscount orderDiscount = new OrderDiscount(); orderDiscount.OrderDiscountID = Guid.NewGuid(); orderDiscount.OrderID = order.OrderID; orderDiscount.OrderDetailsID = orderDetails.OrderDetailsID; orderDiscount.DiscountID = itemDiscount.DiscountID; orderDiscount.DiscountName = itemDiscount.DiscountName; orderDiscount.DiscountType = itemDiscount.DiscountType; orderDiscount.DiscountRate = itemDiscount.DiscountRate; orderDiscount.OffFixPay = itemDiscount.OffFixPay; orderDiscount.OffPay = Math.Abs(Convert.ToDecimal(dr.Cells["GoodsDiscount"].Value)); orderDiscount.EmployeeID = ConstantValuePool.CurrentEmployee.EmployeeID; newOrderDiscountList.Add(orderDiscount); } } } if (orderDetailsList.Count > 0 && newOrderDiscountList.Count > 0) { PayingOrder payingOrder = new PayingOrder(); payingOrder.order = submitOrder; payingOrder.orderDetailsList = orderDetailsList; payingOrder.orderDiscountList = newOrderDiscountList; bool result = PayingOrderService.GetInstance().CreatePrePayOrder(payingOrder); if (result) { btn.Text = "解锁"; order.Status = 3; //预结 m_IsPreCheckOut = true; } else { MessageBox.Show("预结账单失败,请重新操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { int status = 3; //预结 if (OrderService.GetInstance().UpdateOrderStatus(order.OrderID, status)) { btn.Text = "解锁"; order.Status = status; m_IsPreCheckOut = true; } else { MessageBox.Show("预结账单失败,请重新操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } //打印预结小票 PrintData printData = new PrintData(); printData.ShopName = ConstantValuePool.CurrentShop.ShopName; printData.DeskName = m_CurrentDeskName; printData.PersonNum = m_SalesOrder.order.PeopleNum.ToString(); printData.PrintTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); printData.EmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo; printData.TranSequence = m_SalesOrder.order.TranSequence.ToString(); printData.ShopAddress = ConstantValuePool.CurrentShop.RunAddress; printData.Telephone = ConstantValuePool.CurrentShop.Telephone; printData.ReceivableMoney = this.lbReceMoney.Text; printData.ServiceFee = m_ServiceFee.ToString("f2"); printData.TotalAmount = (m_ActualPayMoney + m_ServiceFee).ToString("f2"); printData.GoodsOrderList = new List<GoodsOrder>(); foreach (OrderDetails item in m_SalesOrder.orderDetailsList) { string strLevelFlag = string.Empty; int levelCount = item.ItemLevel * 2; for (int i = 0; i < levelCount; i++) { strLevelFlag += "-"; } GoodsOrder goodsOrder = new GoodsOrder(); goodsOrder.GoodsName = strLevelFlag + item.GoodsName; goodsOrder.GoodsNum = item.ItemQty.ToString("f1"); goodsOrder.SellPrice = item.SellPrice.ToString("f2"); goodsOrder.TotalSellPrice = item.TotalSellPrice.ToString("f2"); goodsOrder.TotalDiscount = item.TotalDiscount.ToString("f2"); goodsOrder.Unit = item.Unit; printData.GoodsOrderList.Add(goodsOrder); } string paperWidth = ConstantValuePool.BizSettingConfig.printConfig.PaperWidth; if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.DRIVER) { string printerName = ConstantValuePool.BizSettingConfig.printConfig.Name; string paperName = ConstantValuePool.BizSettingConfig.printConfig.PaperName; DriverOrderPrint printer = DriverOrderPrint.GetInstance(printerName, paperName, paperWidth); printer.DoPrintPrePayOrder(printData); } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.COM) { string port = ConstantValuePool.BizSettingConfig.printConfig.Name; if (port.Length > 3) { if (port.Substring(0, 3).ToUpper() == "COM") { string portName = port.Substring(0, 4).ToUpper(); InstructionOrderPrint printer = new InstructionOrderPrint(portName, 9600, Parity.None, 8, StopBits.One, paperWidth); printer.DoPrintPrePayOrder(printData); } } } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.ETHERNET) { string ipAddress = ConstantValuePool.BizSettingConfig.printConfig.Name; InstructionOrderPrint printer = new InstructionOrderPrint(ipAddress, 9100, paperWidth); printer.DoPrintPrePayOrder(printData); } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.USB) { string vid = ConstantValuePool.BizSettingConfig.printConfig.VID; string pid = ConstantValuePool.BizSettingConfig.printConfig.PID; string endpointId = ConstantValuePool.BizSettingConfig.printConfig.EndpointID; InstructionOrderPrint printer = new InstructionOrderPrint(vid, pid, endpointId, paperWidth); printer.DoPrintPrePayOrder(printData); } } else if (order.Status == 3) { //权限验证 bool hasRights = false; if (RightsItemCode.FindRights(RightsItemCode.PRECHECKOUT)) { hasRights = true; } else { FormRightsCode form = new FormRightsCode(); form.ShowDialog(); if (form.ReturnValue) { IList<string> rightsCodeList = form.RightsCodeList; if (RightsItemCode.FindRights(rightsCodeList, RightsItemCode.PRECHECKOUT)) { hasRights = true; } } } if (!hasRights) { return; } int status = 0; if (OrderService.GetInstance().UpdateOrderStatus(order.OrderID, status)) { btn.Text = "预结"; order.Status = status; m_IsPreCheckOut = false; } else { MessageBox.Show("预结状态解锁失败,请重新操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } }
private void btnPrint_Click(object sender, EventArgs e) { if (dataGridView1.CurrentRow != null && _salesOrder != null && _salesOrder.order != null) { if (_salesOrder.order.Status == 1) { int selectedIndex = dataGridView1.CurrentRow.Index; if (dataGridView1.Rows[selectedIndex].Cells["OrderID"].Value != null) { Order order = _salesOrder.order; //打印小票 PrintData printData = new PrintData(); printData.ShopName = ConstantValuePool.CurrentShop.ShopName; printData.DeskName = order.DeskName; printData.PersonNum = order.PeopleNum.ToString(); printData.PrintTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); printData.EmployeeNo = order.EmployeeNo; printData.TranSequence = order.TranSequence.ToString(); printData.ShopAddress = ConstantValuePool.CurrentShop.RunAddress; printData.Telephone = ConstantValuePool.CurrentShop.Telephone; printData.ReceivableMoney = order.ActualSellPrice.ToString("f2"); printData.ServiceFee = order.ServiceFee.ToString("f2"); printData.PaidInMoney = order.PaymentMoney.ToString("f2"); printData.NeedChangePay = order.NeedChangePay.ToString("f2"); printData.GoodsOrderList = new List<GoodsOrder>(); printData.PayingOrderList = new List<PayingGoodsOrder>(); foreach (OrderDetails item in _salesOrder.orderDetailsList) { string strLevelFlag = string.Empty; int levelCount = item.ItemLevel * 2; for (int i = 0; i < levelCount; i++) { strLevelFlag += "-"; } GoodsOrder goodsOrder = new GoodsOrder(); goodsOrder.GoodsName = strLevelFlag + item.GoodsName; goodsOrder.GoodsNum = item.ItemQty.ToString("f1"); goodsOrder.SellPrice = item.SellPrice.ToString("f2"); goodsOrder.TotalSellPrice = item.TotalSellPrice.ToString("f2"); goodsOrder.TotalDiscount = item.TotalDiscount.ToString("f2"); goodsOrder.Unit = item.Unit; printData.GoodsOrderList.Add(goodsOrder); } foreach (OrderPayoff orderPayoff in _salesOrder.orderPayoffList) { PayingGoodsOrder payingOrder = new PayingGoodsOrder(); payingOrder.PayoffName = orderPayoff.PayoffName; payingOrder.PayoffMoney = (orderPayoff.AsPay * orderPayoff.Quantity).ToString("f2"); payingOrder.NeedChangePay = orderPayoff.NeedChangePay.ToString("f2"); printData.PayingOrderList.Add(payingOrder); } string paperWidth = ConstantValuePool.BizSettingConfig.printConfig.PaperWidth; if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.DRIVER) { string printerName = ConstantValuePool.BizSettingConfig.printConfig.Name; string paperName = ConstantValuePool.BizSettingConfig.printConfig.PaperName; DriverOrderPrint printer = DriverOrderPrint.GetInstance(printerName, paperName, paperWidth); printer.DoPrintPaidOrder(printData); } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.COM) { string port = ConstantValuePool.BizSettingConfig.printConfig.Name; if (port.Length > 3) { if (port.Substring(0, 3).ToUpper() == "COM") { string portName = port.Substring(0, 4).ToUpper(); InstructionOrderPrint printer = new InstructionOrderPrint(portName, 9600, Parity.None, 8, StopBits.One, paperWidth); printer.DoPrintPaidOrder(printData); } } } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.ETHERNET) { string ipAddress = ConstantValuePool.BizSettingConfig.printConfig.Name; InstructionOrderPrint printer = new InstructionOrderPrint(ipAddress, 9100, paperWidth); printer.DoPrintPaidOrder(printData); } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.USB) { string vid = ConstantValuePool.BizSettingConfig.printConfig.VID; string pid = ConstantValuePool.BizSettingConfig.printConfig.PID; string endpointId = ConstantValuePool.BizSettingConfig.printConfig.EndpointID; InstructionOrderPrint printer = new InstructionOrderPrint(vid, pid, endpointId, paperWidth); printer.DoPrintPaidOrder(printData); } } } } }