public bool DeleteSingleOrderDetails(DeletedOrderDetails deletedOrderDetails)
 {
     int result = ExecuteUpdate("DeleteSingleOrderDetails", deletedOrderDetails);
     return result > 0;
 }
Пример #2
0
        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (dgvGoodsOrder.CurrentRow != null)
            {
                int selectIndex = dgvGoodsOrder.CurrentRow.Index;
                if (dgvGoodsOrder.Rows[selectIndex].Cells["OrderDetailsID"].Value != null)
                {
                    int itemType = Convert.ToInt32(dgvGoodsOrder.Rows[selectIndex].Cells["ItemType"].Value);
                    if (itemType == (int)OrderItemType.Details)
                    {
                        MessageBox.Show("细项不能单独删除!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    if (itemType == (int)OrderItemType.SetMeal)
                    {
                        MessageBox.Show("套餐项不能单独删除!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    Guid orderDetailsId = new Guid(dgvGoodsOrder.Rows[selectIndex].Cells["OrderDetailsID"].Value.ToString());
                    decimal goodsNum = Convert.ToDecimal(dgvGoodsOrder.Rows[selectIndex].Cells["GoodsNum"].Value);
                    string goodsName = dgvGoodsOrder.Rows[selectIndex].Cells["GoodsName"].Value.ToString();
                    decimal goodsPrice = Convert.ToDecimal(dgvGoodsOrder.Rows[selectIndex].Cells["GoodsPrice"].Value);
                    if (!RightsItemCode.FindRights(RightsItemCode.CANCELGOODS))
                    {
                        decimal singleItemPriceSum = goodsPrice / goodsNum;
                        if (itemType == (int)OrderItemType.Goods && selectIndex < dgvGoodsOrder.Rows.Count - 1)
                        {
                            for (int index = selectIndex + 1; index < dgvGoodsOrder.RowCount; index++)
                            {
                                if (Convert.ToInt32(dgvGoodsOrder.Rows[index].Cells["ItemType"].Value) == (int)OrderItemType.Goods)
                                {
                                    break;
                                }
                                singleItemPriceSum += Convert.ToDecimal(dgvGoodsOrder.Rows[index].Cells["GoodsPrice"].Value) / Convert.ToDecimal(dgvGoodsOrder.Rows[index].Cells["GoodsNum"].Value);
                            }
                            if (singleItemPriceSum > ConstantValuePool.CurrentEmployee.LimitMoney)
                            {
                                if (DialogResult.Yes == MessageBox.Show("当前用户不具备该权限,并且超过最高退菜限额,是否更换用户?", "信息提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                                {
                                    //权限验证
                                    bool hasRights = false;
                                    FormRightsCode formRightsCode = new FormRightsCode();
                                    formRightsCode.ShowDialog();
                                    if (formRightsCode.ReturnValue)
                                    {
                                        IList<string> rightsCodeList = formRightsCode.RightsCodeList;
                                        if (RightsItemCode.FindRights(rightsCodeList, RightsItemCode.CANCELGOODS))
                                        {
                                            hasRights = true;
                                        }
                                    }
                                    if (!hasRights)
                                    {
                                        return;
                                    }
                                }
                                else
                                {
                                    return;
                                }
                            }
                        }
                    }
                    FormCancelOrder form = new FormCancelOrder(goodsName, goodsNum);
                    form.ShowDialog();
                    if (form.DelItemNum > 0 && form.CurrentReason != null)
                    {
                        if (form.DelItemNum < goodsNum)
                        {
                            //Key:Index, Value:RemainNum
                            Dictionary<int, decimal> dicRemainNum = new Dictionary<int, decimal>();
                            List<DeletedOrderDetails> deletedOrderDetailsList = new List<DeletedOrderDetails>();
                            //主项
                            decimal remainNum = goodsNum - form.DelItemNum;
                            dicRemainNum.Add(selectIndex, remainNum);
                            decimal originalDetailsNum = Convert.ToDecimal(dgvGoodsOrder.Rows[selectIndex].Cells["GoodsNum"].Value);
                            decimal originalDetailsDiscount = Convert.ToDecimal(dgvGoodsOrder.Rows[selectIndex].Cells["GoodsDiscount"].Value);
                            DeletedOrderDetails orderDetails = new DeletedOrderDetails();
                            orderDetails.OrderDetailsID = orderDetailsId;
                            orderDetails.DeletedQuantity = -form.DelItemNum;
                            orderDetails.RemainQuantity = remainNum;
                            orderDetails.OffPay = Math.Round(-originalDetailsDiscount / originalDetailsNum * remainNum, 4);
                            orderDetails.AuthorisedManager = ConstantValuePool.CurrentEmployee.EmployeeID;
                            orderDetails.CancelEmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo;
                            orderDetails.CancelReasonName = form.CurrentReason.ReasonName;
                            deletedOrderDetailsList.Add(orderDetails);
                            //细项
                            if (selectIndex < dgvGoodsOrder.Rows.Count - 1)
                            {
                                for (int index = selectIndex + 1; index < dgvGoodsOrder.RowCount; index++)
                                {
                                    if (Convert.ToInt32(dgvGoodsOrder.Rows[index].Cells["ItemType"].Value) == (int)OrderItemType.Goods)
                                    {
                                        break;
                                    }
                                    orderDetailsId = new Guid(dgvGoodsOrder.Rows[index].Cells["OrderDetailsID"].Value.ToString());
                                    originalDetailsNum = Convert.ToDecimal(dgvGoodsOrder.Rows[index].Cells["GoodsNum"].Value);
                                    originalDetailsDiscount = Convert.ToDecimal(dgvGoodsOrder.Rows[index].Cells["GoodsDiscount"].Value);
                                    decimal delItemNum = originalDetailsNum / goodsNum * form.DelItemNum;
                                    remainNum = originalDetailsNum - delItemNum;
                                    dicRemainNum.Add(index, remainNum);
                                    DeletedOrderDetails item = new DeletedOrderDetails();
                                    item.OrderDetailsID = orderDetailsId;
                                    item.DeletedQuantity = -delItemNum;
                                    item.RemainQuantity = remainNum;
                                    item.OffPay = Math.Round(-originalDetailsDiscount / originalDetailsNum * remainNum, 4);
                                    item.AuthorisedManager = ConstantValuePool.CurrentEmployee.EmployeeID;
                                    item.CancelEmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo;
                                    item.CancelReasonName = form.CurrentReason.ReasonName;
                                    deletedOrderDetailsList.Add(item);
                                }
                            }
                            //计算价格信息
                            decimal totalPrice = 0, totalDiscount = 0;
                            for (int i = 0; i < dgvGoodsOrder.RowCount; i++)
                            {
                                if (dgvGoodsOrder.Rows[i].Cells["OrderDetailsID"].Value != null)
                                {
                                    if (dicRemainNum.ContainsKey(i))
                                    {
                                        decimal originalDetailsPrice = Convert.ToDecimal(dgvGoodsOrder.Rows[i].Cells["GoodsPrice"].Value);
                                        originalDetailsNum = Convert.ToDecimal(dgvGoodsOrder.Rows[i].Cells["GoodsNum"].Value);
                                        originalDetailsDiscount = Convert.ToDecimal(dgvGoodsOrder.Rows[i].Cells["GoodsDiscount"].Value);
                                        totalPrice += originalDetailsPrice / originalDetailsNum * dicRemainNum[i];
                                        totalDiscount += originalDetailsDiscount / originalDetailsNum * dicRemainNum[i];
                                    }
                                    else
                                    {
                                        totalPrice += Convert.ToDecimal(dgvGoodsOrder.Rows[i].Cells["GoodsPrice"].Value);
                                        totalDiscount += Convert.ToDecimal(dgvGoodsOrder.Rows[i].Cells["GoodsDiscount"].Value);
                                    }
                                }
                            }
                            decimal wholePayMoney = totalPrice + totalDiscount;
                            decimal actualPayMoney = CutOffDecimal.HandleCutOff(wholePayMoney, ConstantValuePool.SysConfig.IsCutTail, ConstantValuePool.SysConfig.CutTailType, ConstantValuePool.SysConfig.CutTailDigit);
                            //构造DeletedSingleOrder对象
                            DeletedSingleOrder deletedSingleOrder = new DeletedSingleOrder();
                            deletedSingleOrder.OrderID = _salesOrder.order.OrderID;
                            deletedSingleOrder.TotalSellPrice = totalPrice;
                            deletedSingleOrder.ActualSellPrice = actualPayMoney;
                            deletedSingleOrder.DiscountPrice = totalDiscount;
                            deletedSingleOrder.CutOffPrice = wholePayMoney - actualPayMoney;
                            deletedSingleOrder.deletedOrderDetailsList = deletedOrderDetailsList;

                            if (DeletedOrderService.GetInstance().DeleteSingleOrder(deletedSingleOrder))
                            {
                                foreach (KeyValuePair<int, decimal> item in dicRemainNum)
                                {
                                    int index = item.Key;
                                    decimal remainsNum = item.Value;
                                    decimal detailsNum = Convert.ToDecimal(dgvGoodsOrder.Rows[index].Cells["GoodsNum"].Value);
                                    decimal detailsPrice = Convert.ToDecimal(dgvGoodsOrder.Rows[index].Cells["GoodsPrice"].Value);
                                    decimal detailsDiscount = Convert.ToDecimal(dgvGoodsOrder.Rows[index].Cells["GoodsDiscount"].Value);
                                    dgvGoodsOrder.Rows[index].Cells["GoodsNum"].Value = remainsNum;
                                    dgvGoodsOrder.Rows[index].Cells["GoodsPrice"].Value = detailsPrice / detailsNum * remainsNum;
                                    dgvGoodsOrder.Rows[index].Cells["GoodsDiscount"].Value = detailsDiscount / detailsNum * remainsNum;
                                }
                            }
                            else
                            {
                                MessageBox.Show("删除品项失败!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                        }
                        else
                        {
                            List<int> deletedIndexList = new List<int>();
                            List<DeletedOrderDetails> deletedOrderDetailsList = new List<DeletedOrderDetails>();
                            //主项
                            deletedIndexList.Add(selectIndex);
                            DeletedOrderDetails orderDetails = new DeletedOrderDetails();
                            orderDetails.OrderDetailsID = orderDetailsId;
                            orderDetails.DeletedQuantity = -Convert.ToDecimal(dgvGoodsOrder.Rows[selectIndex].Cells["GoodsNum"].Value);
                            orderDetails.RemainQuantity = 0;
                            orderDetails.OffPay = 0;
                            orderDetails.AuthorisedManager = ConstantValuePool.CurrentEmployee.EmployeeID;
                            orderDetails.CancelEmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo;
                            orderDetails.CancelReasonName = form.CurrentReason.ReasonName;
                            deletedOrderDetailsList.Add(orderDetails);
                            //细项
                            if (selectIndex < dgvGoodsOrder.RowCount - 1)
                            {
                                for (int index = selectIndex + 1; index < dgvGoodsOrder.RowCount; index++)
                                {
                                    if (Convert.ToInt32(dgvGoodsOrder.Rows[index].Cells["ItemType"].Value) == (int)OrderItemType.Goods)
                                    {
                                        break;
                                    }
                                    deletedIndexList.Add(index);
                                    orderDetailsId = new Guid(dgvGoodsOrder.Rows[index].Cells["OrderDetailsID"].Value.ToString());
                                    DeletedOrderDetails item = new DeletedOrderDetails();
                                    item.OrderDetailsID = orderDetailsId;
                                    item.DeletedQuantity = -Convert.ToDecimal(dgvGoodsOrder.Rows[index].Cells["GoodsNum"].Value);
                                    item.RemainQuantity = 0;
                                    item.OffPay = 0;
                                    item.AuthorisedManager = ConstantValuePool.CurrentEmployee.EmployeeID;
                                    item.CancelEmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo;
                                    item.CancelReasonName = form.CurrentReason.ReasonName;
                                    deletedOrderDetailsList.Add(item);
                                }
                            }
                            //计算价格信息
                            decimal totalPrice = 0, totalDiscount = 0;
                            for (int i = 0; i < dgvGoodsOrder.RowCount; i++)
                            {
                                if (dgvGoodsOrder.Rows[i].Cells["OrderDetailsID"].Value != null)
                                {
                                    bool hasDeleted = false;
                                    foreach (int deletedIndex in deletedIndexList)
                                    {
                                        if (i == deletedIndex)
                                        {
                                            hasDeleted = true;
                                            break;
                                        }
                                    }
                                    if (hasDeleted) continue;
                                    totalPrice += Convert.ToDecimal(dgvGoodsOrder.Rows[i].Cells["GoodsPrice"].Value);
                                    totalDiscount += Convert.ToDecimal(dgvGoodsOrder.Rows[i].Cells["GoodsDiscount"].Value);
                                }
                            }
                            decimal wholePayMoney = totalPrice + totalDiscount;
                            decimal actualPayMoney = CutOffDecimal.HandleCutOff(wholePayMoney, ConstantValuePool.SysConfig.IsCutTail, ConstantValuePool.SysConfig.CutTailType, ConstantValuePool.SysConfig.CutTailDigit);
                            //构造DeletedSingleOrder对象
                            DeletedSingleOrder deletedSingleOrder = new DeletedSingleOrder();
                            deletedSingleOrder.OrderID = _salesOrder.order.OrderID;
                            deletedSingleOrder.TotalSellPrice = totalPrice;
                            deletedSingleOrder.ActualSellPrice = actualPayMoney;
                            deletedSingleOrder.DiscountPrice = totalDiscount;
                            deletedSingleOrder.CutOffPrice = wholePayMoney - actualPayMoney;
                            deletedSingleOrder.deletedOrderDetailsList = deletedOrderDetailsList;

                            if (DeletedOrderService.GetInstance().DeleteSingleOrder(deletedSingleOrder))
                            {
                                for (int i = deletedIndexList.Count - 1; i >= 0; i--)
                                {
                                    dgvGoodsOrder.Rows.RemoveAt(deletedIndexList[i]);
                                }
                            }
                            else
                            {
                                MessageBox.Show("删除品项失败!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                        }
                    }
                }
                else
                {
                    if (Convert.ToInt32(dgvGoodsOrder.Rows[selectIndex].Cells["ItemType"].Value) == (int)OrderItemType.Details)
                    {
                        dgvGoodsOrder.Rows.RemoveAt(selectIndex);
                    }
                    else if (Convert.ToInt32(dgvGoodsOrder.Rows[selectIndex].Cells["ItemType"].Value) == (int)OrderItemType.SetMeal)
                    {
                        MessageBox.Show("套餐项不能单独删除!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    else
                    {
                        dgvGoodsOrder.Rows.RemoveAt(selectIndex);
                        if (selectIndex < dgvGoodsOrder.RowCount - 1)
                        {
                            for (int i = selectIndex; i < dgvGoodsOrder.RowCount; i++)
                            {
                                if (Convert.ToInt32(dgvGoodsOrder.Rows[i].Cells["ItemType"].Value) == (int)OrderItemType.Goods)
                                {
                                    break;
                                }
                                dgvGoodsOrder.Rows.RemoveAt(i);
                                i--;
                            }
                        }
                    }
                }
                //统计
                BindOrderInfoSum();
                //更新第二屏信息
                if (Screen.AllScreens.Length > 1 && ConstantValuePool.BizSettingConfig.SecondScreenEnabled)
                {
                    if (ConstantValuePool.SecondScreenForm != null && ConstantValuePool.SecondScreenForm is FormSecondScreen)
                    {
                        ((FormSecondScreen)ConstantValuePool.SecondScreenForm).BindGoodsOrderInfo(dgvGoodsOrder);
                    }
                }
            }
        }
Пример #3
0
 private void btnCheckOut_Click(object sender, EventArgs e)
 {
     decimal refundAmount = decimal.Parse(txtRefundAmount.Text);
     decimal realReturnAmount = 0;
     if (!string.IsNullOrEmpty(txtRealReturnAmount.Text))
     {
         realReturnAmount = decimal.Parse(txtRealReturnAmount.Text);
     }
     if (refundAmount == realReturnAmount)
     {
         //判断支付方式是否正确
         bool IsPayoffWayRight = true;
         IList<OrderPayoff> _orderPayoffList = new List<OrderPayoff>();
         foreach (KeyValuePair<string, OrderPayoff> item in dic)
         {
             if (item.Value.Quantity > 0)
             {
                 _orderPayoffList.Add(item.Value);
             }
         }
         foreach (OrderPayoff orderPayoff in _orderPayoffList)
         {
             bool IsContains = false;
             OrderPayoff temp = null;
             foreach (OrderPayoff item in m_SalesOrder.orderPayoffList)
             {
                 if (item.PayoffID.Equals(orderPayoff.PayoffID))
                 {
                     IsContains = true;
                     temp = item;
                     break;
                 }
             }
             if (IsContains)
             {
                 decimal tempAmount = temp.AsPay * temp.Quantity - temp.NeedChangePay;
                 decimal payAmount = orderPayoff.AsPay * orderPayoff.Quantity - orderPayoff.NeedChangePay;
                 if (tempAmount < payAmount)
                 {
                     IsPayoffWayRight = false;
                     break;
                 }
             }
             else
             {
                 IsPayoffWayRight = false;
                 break;
             }
         }
         if (IsPayoffWayRight)
         {
             IList<OrderPayoff> orderPayoffList = new List<OrderPayoff>();
             foreach (OrderPayoff item in m_SalesOrder.orderPayoffList)
             {
                 bool IsContains = false;
                 foreach (OrderPayoff orderPayoff in _orderPayoffList)
                 {
                     if (item.PayoffID.Equals(orderPayoff.PayoffID))
                     {
                         decimal remainQty = ((item.AsPay * item.Quantity - item.NeedChangePay) - (orderPayoff.AsPay * orderPayoff.Quantity - orderPayoff.NeedChangePay)) / orderPayoff.AsPay;
                         if (remainQty > 0)
                         {
                             OrderPayoff temp = new OrderPayoff();
                             temp.OrderPayoffID = Guid.NewGuid();
                             temp.OrderID = m_SalesOrder.order.OrderID;
                             temp.PayoffID = item.PayoffID;
                             temp.PayoffName = item.PayoffName;
                             temp.PayoffType = item.PayoffType;
                             temp.AsPay = item.AsPay;
                             temp.Quantity = remainQty;
                             temp.NeedChangePay = 0;
                             temp.CardNo = item.CardNo;
                             temp.EmployeeID = ConstantValuePool.CurrentEmployee.EmployeeID;
                             orderPayoffList.Add(temp);
                         }
                         IsContains = true;
                         break;
                     }
                 }
                 if (!IsContains)
                 {
                     OrderPayoff temp = CopyExtension.Clone<OrderPayoff>(item);
                     temp.OrderID = m_SalesOrder.order.OrderID;
                     temp.OrderPayoffID = Guid.NewGuid();
                     temp.EmployeeID = ConstantValuePool.CurrentEmployee.EmployeeID;
                     orderPayoffList.Add(temp);
                 }
             }
             List<DeletedOrderDetails> deletedOrderDetailsList = new List<DeletedOrderDetails>();
             for (int i = 0; i < dgvGoodsOrder.RowCount; i++)
             {
                 OrderDetails tempOrderDetails = dgvGoodsOrder.Rows[i].Cells["OrderDetailsID"].Tag as OrderDetails;
                 decimal tempGoodsNum = Convert.ToDecimal(dgvGoodsOrder.Rows[i].Cells["GoodsNum"].Value);
                 decimal tempGoodsDiscount = Convert.ToDecimal(dgvGoodsOrder.Rows[i].Cells["GoodsDiscount"].Value);
                 decimal tempDeletedNum = Convert.ToDecimal(dgvGoodsOrder.Rows[i].Cells["DelFlag"].Value);
                 if (Math.Abs(tempDeletedNum) > 0)
                 {
                     decimal remainQty = tempGoodsNum - Math.Abs(tempDeletedNum);
                     DeletedOrderDetails orderDetails = new DeletedOrderDetails();
                     orderDetails.OrderDetailsID = tempOrderDetails.OrderDetailsID;
                     orderDetails.DeletedQuantity = tempDeletedNum;
                     orderDetails.RemainQuantity = remainQty;
                     orderDetails.OffPay = Math.Round(-tempGoodsDiscount / tempGoodsNum * remainQty, 4);
                     orderDetails.AuthorisedManager = ConstantValuePool.CurrentEmployee.EmployeeID;
                     orderDetails.CancelEmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo;
                     orderDetails.CancelReasonName = dgvGoodsOrder.Rows[i].Cells["DelReasonName"].Value.ToString(); ;
                     deletedOrderDetailsList.Add(orderDetails);
                 }
             }
             //构造DeletedPaidOrder对象
             decimal paymentMoney = 0;
             foreach (OrderPayoff item in orderPayoffList)
             {
                 paymentMoney += item.AsPay * item.Quantity;
             }
             Order order = new Order();
             order.OrderID = m_SalesOrder.order.OrderID;
             order.TotalSellPrice = m_TotalPrice;
             order.ActualSellPrice = m_ActualPayMoney;
             order.DiscountPrice = m_Discount;
             order.CutOffPrice = m_CutOff;
             order.ServiceFee = m_ServiceFee;
             order.PaymentMoney = paymentMoney;
             order.NeedChangePay = 0;
             order.EmployeeID = ConstantValuePool.CurrentEmployee.EmployeeID;
             DeletedPaidOrder deletedPaidOrder = new DeletedPaidOrder();
             deletedPaidOrder.order = order;
             deletedPaidOrder.deletedOrderDetailsList = deletedOrderDetailsList;
             deletedPaidOrder.orderPayoffList = orderPayoffList;
             if (DeletedOrderService.GetInstance().DeletePaidSingleOrder(deletedPaidOrder))
             {
                 m_IsChanged = true;
                 this.Close();
             }
             else
             {
                 MessageBox.Show("单品删除失败,请重新操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
         }
         else
         {
             MessageBox.Show("退款支付方式不属于原结账支付方式,请重新支付!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
     }
     else
     {
         MessageBox.Show("应退金额与实退金额不一致,请重新支付!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
 }