private void btnConfirm_Click(object sender, EventArgs e) { if (m_DiscountItem != null) { m_CurrentDiscount = m_DiscountItem; this.Close(); } }
private void btnCustomDiscountTo_Click(object sender, EventArgs e) { //权限验证 bool hasRights = false; if (RightsItemCode.FindRights(RightsItemCode.CUSTOMDISCOUNT)) { hasRights = true; } else { FormRightsCode form = new FormRightsCode(); form.ShowDialog(); if (form.ReturnValue) { IList<string> rightsCodeList = form.RightsCodeList; if (RightsItemCode.FindRights(rightsCodeList, RightsItemCode.CUSTOMDISCOUNT)) { hasRights = true; } } } if (!hasRights) { return; } FormNumericKeypad keyForm = new FormNumericKeypad(); keyForm.DisplayText = "请输入打折之后整单的金额"; keyForm.ShowDialog(); if (!string.IsNullOrEmpty(keyForm.KeypadValue)) { if (decimal.Parse(keyForm.KeypadValue) < 0 || decimal.Parse(keyForm.KeypadValue) > m_ActualSellPrice) { MessageBox.Show("折扣的金额不能小于零或者超过原始金额!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { decimal discountRate = (m_ActualSellPrice - decimal.Parse(keyForm.KeypadValue)) / m_ActualSellPrice; if (discountRate > ConstantValuePool.CurrentEmployee.MinDiscount) { MessageBox.Show("当前已超过您的最低折扣!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } this.txtDiscount.Text = string.Format("打折后整单金额({0}元)", keyForm.KeypadValue); Discount discount = new Discount(); discount.DiscountID = new Guid("88888888-8888-8888-8888-888888888888"); discount.DiscountName = "自定义折扣"; discount.DiscountName2nd = "自定义折扣"; discount.DiscountType = (int)DiscountItemType.OffFixPay; discount.OffFixPay = m_ActualSellPrice - decimal.Parse(keyForm.KeypadValue); m_DiscountItem = discount; } } }
private void btnDiscount_Click(object sender, EventArgs e) { Button btn = sender as Button; m_DiscountItem = btn.Tag as Discount; this.txtDiscount.Text = m_DiscountItem.DiscountName; }
private void btnItem_Click(object sender, EventArgs e) { CrystalButton btnItem = sender as CrystalButton; if (btnItem == null) return; if (btnItem.Tag is Goods) { Goods goods = btnItem.Tag as Goods; decimal goodsDiscount = 0; Discount _discount = null; bool isContainsSalePrice = false; //是否包含特价 decimal goodsPrice = goods.SellPrice; decimal goodsNum = 1M; if (goods.IsCustomQty || goods.IsCustomPrice) { decimal sellPrice = OrderDetailsService.GetInstance().GetLastCustomPrice(goods.GoodsID); if (sellPrice > 0) { goodsPrice = sellPrice; } if (goods.IsCustomQty || sellPrice == 0) { FormCustomQty form = new FormCustomQty(goods.IsCustomQty, goodsNum, goods.IsCustomPrice, goodsPrice); form.ShowDialog(); if (form.CustomPrice > 0) { goodsPrice = form.CustomPrice; } if (form.CustomQty > 0) { goodsNum = form.CustomQty; } } goods.SellPrice = goodsPrice; btnItem.Tag = goods; } else { #region 判断是否限时特价 //所属组特价 bool isInGroup = false; foreach (GoodsLimitedTimeSale item in ConstantValuePool.GroupLimitedTimeSaleList) { if (item.ItemID == _currentGoodsGroup.GoodsGroupID) { if (!IsValidDate(item.BeginDate, item.EndDate, item.Week, item.Day, item.Hour, item.Minute)) { continue; } _discount = new Discount(); _discount.DiscountID = new Guid("66666666-6666-6666-6666-666666666666"); _discount.DiscountName = "促销折扣"; if (item.DiscountType == (int)DiscountItemType.DiscountRate) { goodsDiscount = goods.SellPrice * item.DiscountRate; _discount.DiscountType = (int)DiscountItemType.DiscountRate; _discount.DiscountRate = item.DiscountRate; _discount.OffFixPay = 0; } if (item.DiscountType == (int)DiscountItemType.OffFixPay) { goodsDiscount = item.OffFixPay; _discount.DiscountType = (int)DiscountItemType.OffFixPay; _discount.DiscountRate = 0; _discount.OffFixPay = item.OffFixPay; } if (item.DiscountType == (int)DiscountItemType.OffSaleTo) { goodsDiscount = goods.SellPrice - item.OffSaleTo; _discount.DiscountType = (int)DiscountItemType.OffFixPay; _discount.DiscountRate = 0; _discount.OffFixPay = goods.SellPrice - item.OffSaleTo; } isInGroup = true; isContainsSalePrice = true; break; } } //品项特价 if (!isInGroup) { foreach (GoodsLimitedTimeSale item in ConstantValuePool.GoodsLimitedTimeSaleList) { if (item.ItemID == goods.GoodsID) { if (!IsValidDate(item.BeginDate, item.EndDate, item.Week, item.Day, item.Hour, item.Minute)) { continue; } _discount = new Discount(); _discount.DiscountID = new Guid("66666666-6666-6666-6666-666666666666"); _discount.DiscountName = "促销折扣"; if (item.DiscountType == (int)DiscountItemType.DiscountRate) { goodsDiscount = goods.SellPrice * item.DiscountRate; _discount.DiscountType = (int)DiscountItemType.DiscountRate; _discount.DiscountRate = item.DiscountRate; _discount.OffFixPay = 0; } if (item.DiscountType == (int)DiscountItemType.OffFixPay) { goodsDiscount = item.OffFixPay; _discount.DiscountType = (int)DiscountItemType.OffFixPay; _discount.DiscountRate = 0; _discount.OffFixPay = item.OffFixPay; } if (item.DiscountType == (int)DiscountItemType.OffSaleTo) { goodsDiscount = goods.SellPrice - item.OffSaleTo; _discount.DiscountType = (int)DiscountItemType.OffFixPay; _discount.DiscountRate = 0; _discount.OffFixPay = goods.SellPrice - item.OffSaleTo; } isContainsSalePrice = true; break; } } } #endregion } int index, selectedIndex; index = selectedIndex = dgvGoodsOrder.Rows.Add(new DataGridViewRow()); dgvGoodsOrder.Rows[index].Cells["ItemID"].Value = goods.GoodsID; dgvGoodsOrder.Rows[index].Cells["ItemID"].Tag = goods; dgvGoodsOrder.Rows[index].Cells["GoodsNum"].Value = goodsNum; dgvGoodsOrder.Rows[index].Cells["GoodsName"].Value = goods.GoodsName; dgvGoodsOrder.Rows[index].Cells["GoodsPrice"].Value = goodsPrice * goodsNum; dgvGoodsOrder.Rows[index].Cells["GoodsDiscount"].Value = (-goodsDiscount).ToString("f2"); if (_discount != null) { dgvGoodsOrder.Rows[index].Cells["GoodsDiscount"].Tag = _discount; } dgvGoodsOrder.Rows[index].Cells["ItemType"].Value = OrderItemType.Goods; dgvGoodsOrder.Rows[index].Cells["CanDiscount"].Value = goods.CanDiscount; dgvGoodsOrder.Rows[index].Cells["ItemUnit"].Value = goods.Unit; #region 判断是否套餐 if (!isContainsSalePrice) { bool haveCirculate = false; IList<GoodsSetMeal> goodsSetMealList = new List<GoodsSetMeal>(); foreach (GoodsSetMeal item in ConstantValuePool.GoodsSetMealList) { if (item.ParentGoodsID.Equals(goods.GoodsID)) { goodsSetMealList.Add(item); haveCirculate = true; } else { if (haveCirculate) break; } } if (goodsSetMealList.Count > 0) { Dictionary<int, List<GoodsSetMeal>> dicGoodsSetMealByGroup = new Dictionary<int, List<GoodsSetMeal>>(); foreach (GoodsSetMeal item in goodsSetMealList) { if (dicGoodsSetMealByGroup.ContainsKey(item.GroupNo)) { dicGoodsSetMealByGroup[item.GroupNo].Add(item); } else { List<GoodsSetMeal> temp = new List<GoodsSetMeal>(); temp.Add(item); dicGoodsSetMealByGroup.Add(item.GroupNo, temp); } } bool isSingleGoodsSetMeal = false; foreach (KeyValuePair<int, List<GoodsSetMeal>> item in dicGoodsSetMealByGroup) { if (item.Value[0].IsRequired && item.Value[0].LimitedQty == item.Value.Count) { isSingleGoodsSetMeal = true; } else { isSingleGoodsSetMeal = false; break; } } if (isSingleGoodsSetMeal) { foreach (GoodsSetMeal item in goodsSetMealList) { Goods temp = new Goods(); temp.GoodsID = item.GoodsID; temp.GoodsNo = item.GoodsNo; temp.GoodsName = item.GoodsName; temp.GoodsName2nd = item.GoodsName2nd; temp.Unit = item.Unit; temp.SellPrice = item.SellPrice; temp.CanDiscount = false; temp.AutoShowDetails = false; temp.PrintSolutionName = item.PrintSolutionName; temp.DepartID = item.DepartID; //更新列表 index = dgvGoodsOrder.Rows.Add(new DataGridViewRow()); dgvGoodsOrder.Rows[index].Cells["ItemID"].Value = item.GoodsID; dgvGoodsOrder.Rows[index].Cells["ItemID"].Tag = temp; dgvGoodsOrder.Rows[index].Cells["GoodsNum"].Value = item.ItemQty; dgvGoodsOrder.Rows[index].Cells["GoodsName"].Value = "--" + item.GoodsName; dgvGoodsOrder.Rows[index].Cells["GoodsPrice"].Value = item.SellPrice; decimal discount; if (item.DiscountRate > 0) { discount = item.SellPrice * item.ItemQty * item.DiscountRate; } else { discount = item.OffFixPay; } dgvGoodsOrder.Rows[index].Cells["GoodsDiscount"].Value = (-discount).ToString("f2"); dgvGoodsOrder.Rows[index].Cells["ItemType"].Value = OrderItemType.SetMeal; dgvGoodsOrder.Rows[index].Cells["CanDiscount"].Value = false; dgvGoodsOrder.Rows[index].Cells["ItemUnit"].Value = item.Unit; } } else { //需要人工选择 if (dicGoodsSetMealByGroup.Count > 0) { FormGoodsSetMeal form = new FormGoodsSetMeal(dicGoodsSetMealByGroup); form.ShowDialog(); if (form.DicResultGoodsSetMeal.Count > 0) { foreach (KeyValuePair<int, List<GoodsSetMeal>> dicItem in form.DicResultGoodsSetMeal) { foreach (GoodsSetMeal item in dicItem.Value) { Goods temp = new Goods(); temp.GoodsID = item.GoodsID; temp.GoodsNo = item.GoodsNo; temp.GoodsName = item.GoodsName; temp.GoodsName2nd = item.GoodsName2nd; temp.Unit = item.Unit; temp.SellPrice = item.SellPrice; temp.CanDiscount = false; temp.AutoShowDetails = false; temp.PrintSolutionName = item.PrintSolutionName; temp.DepartID = item.DepartID; //更新列表 index = dgvGoodsOrder.Rows.Add(new DataGridViewRow()); dgvGoodsOrder.Rows[index].Cells["ItemID"].Value = item.GoodsID; dgvGoodsOrder.Rows[index].Cells["ItemID"].Tag = temp; dgvGoodsOrder.Rows[index].Cells["GoodsNum"].Value = item.ItemQty; dgvGoodsOrder.Rows[index].Cells["GoodsName"].Value = "--" + item.GoodsName; dgvGoodsOrder.Rows[index].Cells["GoodsPrice"].Value = item.SellPrice; decimal discount; if (item.DiscountRate > 0) { discount = item.SellPrice * item.ItemQty * item.DiscountRate; } else { discount = item.OffFixPay; } dgvGoodsOrder.Rows[index].Cells["GoodsDiscount"].Value = (-discount).ToString("f2"); dgvGoodsOrder.Rows[index].Cells["ItemType"].Value = OrderItemType.SetMeal; dgvGoodsOrder.Rows[index].Cells["CanDiscount"].Value = false; dgvGoodsOrder.Rows[index].Cells["ItemUnit"].Value = item.Unit; } } } else { dgvGoodsOrder.Rows.RemoveAt(dgvGoodsOrder.Rows.Count - 1); return; } } } } } #endregion #region 判断是否自动显示细项组 if (goods.AutoShowDetails) { _groupPageIndex = 0; _itemPageIndex = 0; if (goods.DetailsGroupIDList != null && goods.DetailsGroupIDList.Count > 0) { _goodsOrDetails = false; //状态为细项 _currentDetailsGroupIdList = goods.DetailsGroupIDList; DisplayDetailGroupButton(); HideItemButton(); _detailsPrefix = "--"; } } #endregion //datagridview滚动条定位 dgvGoodsOrder.Rows[selectedIndex].Selected = true; dgvGoodsOrder.CurrentCell = dgvGoodsOrder.Rows[selectedIndex].Cells["GoodsNum"]; //统计 BindOrderInfoSum(); //清空 txtSearch.Text = string.Empty; } if (btnItem.Tag is Details) { Details details = btnItem.Tag as Details; if (dgvGoodsOrder.CurrentRow != null) { int selectIndex = dgvGoodsOrder.CurrentRow.Index; if (_currentDetailsGroup.LimitedNumbers > 0) { object objGroupLimitNum = dgvGoodsOrder.Rows[selectIndex].Cells["ItemType"].Tag; if (objGroupLimitNum == null) { Dictionary<Guid, int> dicGroupLimitNum = new Dictionary<Guid, int>(); dicGroupLimitNum.Add(_currentDetailsGroup.DetailsGroupID, 1); dgvGoodsOrder.Rows[selectIndex].Cells["ItemType"].Tag = dicGroupLimitNum; } else { Dictionary<Guid, int> dicGroupLimitNum = objGroupLimitNum as Dictionary<Guid, int>; if (dicGroupLimitNum != null) { if (dicGroupLimitNum.ContainsKey(_currentDetailsGroup.DetailsGroupID)) { int selectedNum = dicGroupLimitNum[_currentDetailsGroup.DetailsGroupID]; if (selectedNum >= _currentDetailsGroup.LimitedNumbers) { MessageBox.Show("超出细项的数量限制!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { selectedNum++; dicGroupLimitNum[_currentDetailsGroup.DetailsGroupID] = selectedNum; dgvGoodsOrder.Rows[selectIndex].Cells["ItemType"].Tag = dicGroupLimitNum; } } else { dicGroupLimitNum.Add(_currentDetailsGroup.DetailsGroupID, 1); dgvGoodsOrder.Rows[selectIndex].Cells["ItemType"].Tag = dicGroupLimitNum; } } } } //数量 decimal itemNum = Convert.ToDecimal(dgvGoodsOrder.Rows[selectIndex].Cells["GoodsNum"].Value); DataGridViewRow dgr = dgvGoodsOrder.Rows[0].Clone() as DataGridViewRow; if (dgr != null) { dgr.Cells[0].Value = details.DetailsID; dgr.Cells[0].Tag = details; dgr.Cells[1].Value = itemNum; dgr.Cells[2].Value = _detailsPrefix + details.DetailsName; dgr.Cells[3].Value = details.SellPrice; dgr.Cells[4].Value = 0; dgr.Cells[5].Value = OrderItemType.Details; dgr.Cells[6].Value = details.CanDiscount; int rowIndex = selectIndex + 1; if (rowIndex == dgvGoodsOrder.Rows.Count) { dgvGoodsOrder.Rows.Add(dgr); } else { if (Convert.ToInt32(dgvGoodsOrder.Rows[selectIndex].Cells["ItemType"].Value) == (int) OrderItemType.Goods) { for (int i = selectIndex + 1; i < dgvGoodsOrder.RowCount; i++) { int itemType = Convert.ToInt32(dgvGoodsOrder.Rows[i].Cells["ItemType"].Value); if (itemType == (int) OrderItemType.Goods) { break; } else { rowIndex++; } } } dgvGoodsOrder.Rows.Insert(rowIndex, dgr); } } //统计 BindOrderInfoSum(); } } //更新第二屏信息 if (Screen.AllScreens.Length > 1 && ConstantValuePool.BizSettingConfig.SecondScreenEnabled) { if (ConstantValuePool.SecondScreenForm != null && ConstantValuePool.SecondScreenForm is FormSecondScreen) { ((FormSecondScreen)ConstantValuePool.SecondScreenForm).BindGoodsOrderInfo(dgvGoodsOrder); } } }
/// <summary> /// 判断是否存在限时组合销售 /// </summary> /// <param name="goodsOrderGridView"></param> private void JoinGoodsCombinedSale(DataGridView goodsOrderGridView) { //获取符合时间条件的品项组组合销售 if (ConstantValuePool.GroupCombinedSaleList == null || ConstantValuePool.GroupCombinedSaleList.Count <= 0) return; var groupCombinedSaleList = ConstantValuePool.GroupCombinedSaleList.Where(item => IsValidDate(item.BeginDate, item.EndDate, item.Week, item.Day, item.Hour, item.Minute)).ToList(); //获取符合时间条件的品项组合销售 if (ConstantValuePool.GoodsCombinedSaleList == null || ConstantValuePool.GoodsCombinedSaleList.Count <= 0) return; var goodsCombinedSaleList = ConstantValuePool.GoodsCombinedSaleList.Where(item => IsValidDate(item.BeginDate, item.EndDate, item.Week, item.Day, item.Hour, item.Minute)).ToList(); List<Guid> hasExistGoodsId = new List<Guid>(); for (int index = 0; index < goodsOrderGridView.Rows.Count; index++) { DataGridViewRow dr = goodsOrderGridView.Rows[index]; int itemType = Convert.ToInt32(dr.Cells["ItemType"].Value); //限时组合销售只针对主品项 if (itemType == (int)OrderItemType.Goods) { Guid goodsId = new Guid(dr.Cells["ItemID"].Value.ToString()); decimal goodsQty = Convert.ToDecimal(dr.Cells["GoodsNum"].Value); decimal totalSellPrice = Convert.ToDecimal(dr.Cells["GoodsPrice"].Value); decimal totalDiscount = Convert.ToDecimal(dr.Cells["GoodsDiscount"].Value); if (hasExistGoodsId.Exists(p => p == goodsId) || hasExistGoodsId.Exists(p => GoodsUtil.IsGoodsInGroup(goodsId, p))) { continue; } //在品项中是否存在 bool isInItem = false; foreach (GoodsCombinedSale item in goodsCombinedSaleList) { if (item.ItemID == goodsId) { //组合优惠 decimal discountRate = Math.Abs(totalDiscount) / totalSellPrice; bool isFit = goodsQty >= item.Quantity; if (isFit) { if (item.MoreOrLess == 1) { isFit = totalSellPrice / goodsQty > item.SellPrice; } else if (item.MoreOrLess == 2) { isFit = totalSellPrice / goodsQty == item.SellPrice; } else if (item.MoreOrLess == 3) { isFit = totalSellPrice / goodsQty < item.SellPrice; } } if (isFit) { isFit = discountRate <= item.LeastDiscountRate; } if (isFit) { //优惠区间 第二杯半价 if (item.PreferentialInterval == 2) { int count = 0; for (int m = index + 1; m < goodsOrderGridView.Rows.Count; m++) { //限时组合销售只针对主品项 if (Convert.ToInt32(goodsOrderGridView.Rows[m].Cells["ItemType"].Value) == (int)OrderItemType.Goods) { Guid tempGoodsId = new Guid(goodsOrderGridView.Rows[m].Cells["ItemID"].Value.ToString()); decimal tempTotalPrice = Convert.ToDecimal(goodsOrderGridView.Rows[m].Cells["GoodsPrice"].Value); if (tempGoodsId == item.ItemID) { if (count % 2 == 1) { count++; continue; } Discount discount = new Discount(); discount.DiscountID = new Guid("66666666-6666-6666-6666-666666666666"); discount.DiscountName = "促销折扣"; decimal goodsDiscount = 0; if (item.DiscountType2 == (int)DiscountItemType.DiscountRate) { goodsDiscount = tempTotalPrice * item.DiscountRate2; discount.DiscountType = (int)DiscountItemType.DiscountRate; discount.DiscountRate = item.DiscountRate2; discount.OffFixPay = 0; } if (item.DiscountType2 == (int)DiscountItemType.OffFixPay) { goodsDiscount = item.OffFixPay2; discount.DiscountType = (int)DiscountItemType.OffFixPay; discount.DiscountRate = 0; discount.OffFixPay = item.OffFixPay2; } if (item.DiscountType2 == (int)DiscountItemType.OffSaleTo) { goodsDiscount = tempTotalPrice - item.OffSaleTo2; discount.DiscountType = (int)DiscountItemType.OffFixPay; discount.DiscountRate = 0; discount.OffFixPay = tempTotalPrice - item.OffSaleTo2; } goodsOrderGridView.Rows[m].Cells["GoodsDiscount"].Value = (-goodsDiscount).ToString("f2"); goodsOrderGridView.Rows[m].Cells["GoodsDiscount"].Tag = discount; if (item.IsMultiple) { count++; } else { break; } } } } } //优惠区间 第二件半价 第三件免费 if (item.PreferentialInterval == 3) { int count = 1; for (int m = index + 1; m < goodsOrderGridView.Rows.Count; m++) { //限时组合销售只针对主品项 if (Convert.ToInt32(goodsOrderGridView.Rows[m].Cells["ItemType"].Value) == (int)OrderItemType.Goods) { Guid tempGoodsId = new Guid(goodsOrderGridView.Rows[m].Cells["ItemID"].Value.ToString()); decimal tempTotalPrice = Convert.ToDecimal(goodsOrderGridView.Rows[m].Cells["GoodsPrice"].Value); if (tempGoodsId == item.ItemID) { if (count % 3 == 0) { count++; continue; } if (count % 3 == 1) { Discount discount = new Discount(); discount.DiscountID = new Guid("66666666-6666-6666-6666-666666666666"); discount.DiscountName = "促销折扣"; decimal goodsDiscount = 0; if (item.DiscountType2 == (int)DiscountItemType.DiscountRate) { goodsDiscount = tempTotalPrice * item.DiscountRate2; discount.DiscountType = (int)DiscountItemType.DiscountRate; discount.DiscountRate = item.DiscountRate2; discount.OffFixPay = 0; } if (item.DiscountType2 == (int)DiscountItemType.OffFixPay) { goodsDiscount = item.OffFixPay2; discount.DiscountType = (int)DiscountItemType.OffFixPay; discount.DiscountRate = 0; discount.OffFixPay = item.OffFixPay2; } if (item.DiscountType2 == (int)DiscountItemType.OffSaleTo) { goodsDiscount = tempTotalPrice - item.OffSaleTo2; discount.DiscountType = (int)DiscountItemType.OffFixPay; discount.DiscountRate = 0; discount.OffFixPay = tempTotalPrice - item.OffSaleTo2; } goodsOrderGridView.Rows[m].Cells["GoodsDiscount"].Value = (-goodsDiscount).ToString("f2"); goodsOrderGridView.Rows[m].Cells["GoodsDiscount"].Tag = discount; count++; continue; } if (count % 3 == 2) { Discount discount = new Discount(); discount.DiscountID = new Guid("66666666-6666-6666-6666-666666666666"); discount.DiscountName = "促销折扣"; decimal goodsDiscount = 0; if (item.DiscountType3 == (int)DiscountItemType.DiscountRate) { goodsDiscount = tempTotalPrice * item.DiscountRate3; discount.DiscountType = (int)DiscountItemType.DiscountRate; discount.DiscountRate = item.DiscountRate3; discount.OffFixPay = 0; } if (item.DiscountType3 == (int)DiscountItemType.OffFixPay) { goodsDiscount = item.OffFixPay3; discount.DiscountType = (int)DiscountItemType.OffFixPay; discount.DiscountRate = 0; discount.OffFixPay = item.OffFixPay3; } if (item.DiscountType3 == (int)DiscountItemType.OffSaleTo) { goodsDiscount = tempTotalPrice - item.OffSaleTo3; discount.DiscountType = (int)DiscountItemType.OffFixPay; discount.DiscountRate = 0; discount.OffFixPay = tempTotalPrice - item.OffSaleTo3; } goodsOrderGridView.Rows[m].Cells["GoodsDiscount"].Value = (-goodsDiscount).ToString("f2"); goodsOrderGridView.Rows[m].Cells["GoodsDiscount"].Tag = discount; if (item.IsMultiple) { count++; } else { break; } } } } } } } isInItem = true; hasExistGoodsId.Add(goodsId); break; } } if (!isInItem) { //在品项组中是否存在 foreach (GoodsCombinedSale item in groupCombinedSaleList) { if (GoodsUtil.IsGoodsInGroup(goodsId, item.ItemID)) { //组合优惠 decimal discountRate = Math.Abs(totalDiscount) / totalSellPrice; bool isFit = goodsQty >= item.Quantity; if (isFit) { if (item.MoreOrLess == 1) { isFit = totalSellPrice / goodsQty > item.SellPrice; } else if (item.MoreOrLess == 2) { isFit = totalSellPrice / goodsQty == item.SellPrice; } else if (item.MoreOrLess == 3) { isFit = totalSellPrice / goodsQty < item.SellPrice; } } if (isFit) { isFit = discountRate <= item.LeastDiscountRate; } if (isFit) { //优惠区间 第二杯半价 if (item.PreferentialInterval == 2) { int count = 0; for (int m = index + 1; m < goodsOrderGridView.Rows.Count; m++) { //限时组合销售只针对主品项 if (Convert.ToInt32(goodsOrderGridView.Rows[m].Cells["ItemType"].Value) == (int)OrderItemType.Goods) { Guid tempGoodsId = new Guid(goodsOrderGridView.Rows[m].Cells["ItemID"].Value.ToString()); decimal tempTotalPrice = Convert.ToDecimal(goodsOrderGridView.Rows[m].Cells["GoodsPrice"].Value); if (GoodsUtil.IsGoodsInGroup(tempGoodsId, item.ItemID)) { if (count % 2 == 1) { count++; continue; } Discount discount = new Discount(); discount.DiscountID = new Guid("66666666-6666-6666-6666-666666666666"); discount.DiscountName = "促销折扣"; decimal goodsDiscount = 0; if (item.DiscountType2 == (int)DiscountItemType.DiscountRate) { goodsDiscount = tempTotalPrice * item.DiscountRate2; discount.DiscountType = (int)DiscountItemType.DiscountRate; discount.DiscountRate = item.DiscountRate2; discount.OffFixPay = 0; } if (item.DiscountType2 == (int)DiscountItemType.OffFixPay) { goodsDiscount = item.OffFixPay2; discount.DiscountType = (int)DiscountItemType.OffFixPay; discount.DiscountRate = 0; discount.OffFixPay = item.OffFixPay2; } if (item.DiscountType2 == (int)DiscountItemType.OffSaleTo) { goodsDiscount = tempTotalPrice - item.OffSaleTo2; discount.DiscountType = (int)DiscountItemType.OffFixPay; discount.DiscountRate = 0; discount.OffFixPay = tempTotalPrice - item.OffSaleTo2; } goodsOrderGridView.Rows[m].Cells["GoodsDiscount"].Value = (-goodsDiscount).ToString("f2"); goodsOrderGridView.Rows[m].Cells["GoodsDiscount"].Tag = discount; if (item.IsMultiple) { count++; } else { break; } } } } } //优惠区间 第二件半价 第三件免费 if (item.PreferentialInterval == 3) { int count = 1; for (int m = index + 1; m < goodsOrderGridView.Rows.Count; m++) { //限时组合销售只针对主品项 if (Convert.ToInt32(goodsOrderGridView.Rows[m].Cells["ItemType"].Value) == (int)OrderItemType.Goods) { Guid tempGoodsId = new Guid(goodsOrderGridView.Rows[m].Cells["ItemID"].Value.ToString()); decimal tempTotalPrice = Convert.ToDecimal(goodsOrderGridView.Rows[m].Cells["GoodsPrice"].Value); if (GoodsUtil.IsGoodsInGroup(tempGoodsId, item.ItemID)) { if (count % 3 == 0) { count++; continue; } if (count % 3 == 1) { Discount discount = new Discount(); discount.DiscountID = new Guid("66666666-6666-6666-6666-666666666666"); discount.DiscountName = "促销折扣"; decimal goodsDiscount = 0; if (item.DiscountType2 == (int)DiscountItemType.DiscountRate) { goodsDiscount = tempTotalPrice * item.DiscountRate2; discount.DiscountType = (int)DiscountItemType.DiscountRate; discount.DiscountRate = item.DiscountRate2; discount.OffFixPay = 0; } if (item.DiscountType2 == (int)DiscountItemType.OffFixPay) { goodsDiscount = item.OffFixPay2; discount.DiscountType = (int)DiscountItemType.OffFixPay; discount.DiscountRate = 0; discount.OffFixPay = item.OffFixPay2; } if (item.DiscountType2 == (int)DiscountItemType.OffSaleTo) { goodsDiscount = tempTotalPrice - item.OffSaleTo2; discount.DiscountType = (int)DiscountItemType.OffFixPay; discount.DiscountRate = 0; discount.OffFixPay = tempTotalPrice - item.OffSaleTo2; } goodsOrderGridView.Rows[m].Cells["GoodsDiscount"].Value = (-goodsDiscount).ToString("f2"); goodsOrderGridView.Rows[m].Cells["GoodsDiscount"].Tag = discount; count++; continue; } if (count % 3 == 2) { Discount discount = new Discount(); discount.DiscountID = new Guid("66666666-6666-6666-6666-666666666666"); discount.DiscountName = "促销折扣"; decimal goodsDiscount = 0; if (item.DiscountType3 == (int)DiscountItemType.DiscountRate) { goodsDiscount = tempTotalPrice * item.DiscountRate3; discount.DiscountType = (int)DiscountItemType.DiscountRate; discount.DiscountRate = item.DiscountRate3; discount.OffFixPay = 0; } if (item.DiscountType3 == (int)DiscountItemType.OffFixPay) { goodsDiscount = item.OffFixPay3; discount.DiscountType = (int)DiscountItemType.OffFixPay; discount.DiscountRate = 0; discount.OffFixPay = item.OffFixPay3; } if (item.DiscountType3 == (int)DiscountItemType.OffSaleTo) { goodsDiscount = tempTotalPrice - item.OffSaleTo3; discount.DiscountType = (int)DiscountItemType.OffFixPay; discount.DiscountRate = 0; discount.OffFixPay = tempTotalPrice - item.OffSaleTo3; } goodsOrderGridView.Rows[m].Cells["GoodsDiscount"].Value = (-goodsDiscount).ToString("f2"); goodsOrderGridView.Rows[m].Cells["GoodsDiscount"].Tag = discount; if (item.IsMultiple) { count++; } else { break; } } } } } } hasExistGoodsId.Add(item.ItemID); } break; } } } } } }
public override void GetPromotionPresents(DataGridView dgvGoodsOrder) { if (m_ActivePromotionPresent.Classification == 1) { //赠品 decimal giftNum = 0; if (m_ActivePromotionPresent.IsMultiple) { giftNum = Math.Floor(m_TotalMoney / m_MaxAmount) * (decimal)m_ActivePromotionPresent.Quantity; } else { giftNum = (decimal)m_ActivePromotionPresent.Quantity; } Goods goods = new Goods(); goods.GoodsID = (Guid)m_ActivePromotionPresent.GoodsID; goods.GoodsNo = m_ActivePromotionPresent.GoodsNo; goods.GoodsName = goods.GoodsName2nd = m_ActivePromotionPresent.GoodsName; goods.Unit = m_ActivePromotionPresent.Unit; goods.SellPrice = (decimal)m_ActivePromotionPresent.SellPrice; goods.CanDiscount = false; goods.AutoShowDetails = false; goods.PrintSolutionName = m_ActivePromotionPresent.PrintSolutionName; goods.DepartID = (Guid)m_ActivePromotionPresent.DepartID; int index = dgvGoodsOrder.Rows.Add(new DataGridViewRow()); dgvGoodsOrder.Rows[index].Cells["ItemID"].Value = goods.GoodsID; dgvGoodsOrder.Rows[index].Cells["ItemID"].Tag = goods; dgvGoodsOrder.Rows[index].Cells["GoodsNum"].Value = giftNum; dgvGoodsOrder.Rows[index].Cells["GoodsName"].Value = goods.GoodsName; dgvGoodsOrder.Rows[index].Cells["GoodsPrice"].Value = goods.SellPrice; dgvGoodsOrder.Rows[index].Cells["GoodsDiscount"].Value = 0; dgvGoodsOrder.Rows[index].Cells["ItemType"].Value = OrderItemType.Goods; dgvGoodsOrder.Rows[index].Cells["CanDiscount"].Value = goods.CanDiscount; dgvGoodsOrder.Rows[index].Cells["ItemUnit"].Value = goods.Unit; } if (m_ActivePromotionPresent.Classification == 2) { //折扣率 Discount discount = new Discount(); discount.DiscountID = new Guid("66666666-6666-6666-6666-666666666666"); discount.DiscountName = "促销折扣"; discount.DiscountType = (int)DiscountItemType.DiscountRate; discount.DiscountRate = (decimal)m_ActivePromotionPresent.DiscountRate; discount.OffFixPay = 0; decimal limitCount = 0; foreach (DataGridViewRow dr in dgvGoodsOrder.Rows) { decimal goodsDiscount = Convert.ToDecimal(dr.Cells["GoodsDiscount"].Value); if (goodsDiscount == 0) { dr.Cells["GoodsDiscount"].Value = -Convert.ToDecimal(dr.Cells["GoodsPrice"].Value) * m_ActivePromotionPresent.DiscountRate; dr.Cells["GoodsDiscount"].Tag = discount; limitCount += Convert.ToDecimal(dr.Cells["GoodsNum"].Value); } if (limitCount >= m_ActivePromotionPresent.DiscountLimit) break; } } if (m_ActivePromotionPresent.Classification == 3) { //固定折扣 Discount discount = new Discount(); discount.DiscountID = new Guid("66666666-6666-6666-6666-666666666666"); discount.DiscountName = "促销折扣"; discount.DiscountType = (int)DiscountItemType.OffFixPay; discount.DiscountRate = 0; discount.OffFixPay = (decimal)m_ActivePromotionPresent.OffFixPay; decimal limitCount = 0; foreach (DataGridViewRow dr in dgvGoodsOrder.Rows) { decimal goodsDiscount = Convert.ToDecimal(dr.Cells["GoodsDiscount"].Value); if (goodsDiscount == 0) { dr.Cells["GoodsDiscount"].Value = -m_ActivePromotionPresent.OffFixPay; dr.Cells["GoodsDiscount"].Tag = discount; limitCount += Convert.ToDecimal(dr.Cells["GoodsNum"].Value); } if (limitCount >= m_ActivePromotionPresent.DiscountLimit) break; } } }
private void btnMember_Click(object sender, EventArgs e) { if (m_SalesOrder.order.Status == 3) { MessageBox.Show("当前处于预结状态,请先解锁!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (m_SalesOrder.order.Status == 0) { //权限验证 bool hasRights = false; if (RightsItemCode.FindRights(RightsItemCode.MEMBERDISCOUNT)) { hasRights = true; } else { FormRightsCode form = new FormRightsCode(); form.ShowDialog(); if (form.ReturnValue) { IList<string> rightsCodeList = form.RightsCodeList; if (RightsItemCode.FindRights(rightsCodeList, RightsItemCode.MEMBERDISCOUNT)) { hasRights = true; } } } if (!hasRights) { return; } Membership.FormVIPCardDiscount formCardDiscount = new Membership.FormVIPCardDiscount(); formCardDiscount.ShowDialog(); if (formCardDiscount.Result == 1) { m_MembershipCard = formCardDiscount.CardNo; m_MemberDiscountRate = formCardDiscount.DiscountRate; Discount discount = new Discount(); discount.DiscountID = new Guid("99999999-9999-9999-9999-999999999999"); discount.DiscountName = "会员折扣"; discount.DiscountName2nd = "会员折扣"; discount.DiscountType = (int)DiscountItemType.DiscountRate; discount.DiscountRate = formCardDiscount.DiscountRate; for (int index = 0; index < dgvGoodsOrder.Rows.Count; index++) { DataGridViewRow dr = dgvGoodsOrder.Rows[index]; 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 || itemDiscountPrice == 0)) { dr.Cells["GoodsDiscount"].Value = -Convert.ToDecimal(dr.Cells["GoodsPrice"].Value) * discount.DiscountRate; orderDetails.TotalDiscount = Convert.ToDecimal(dr.Cells["GoodsDiscount"].Value); dr.Cells["OrderDetailsID"].Tag = orderDetails; dr.Cells["GoodsDiscount"].Tag = discount; } } } //统计 BindOrderInfoSum(); this.lbUnpaidAmount.Text = (decimal.Parse(lbReceMoney.Text) + decimal.Parse(lbServiceFee.Text) - decimal.Parse(lbPaidInMoney.Text)).ToString("f2"); //更新第二屏信息 if (Screen.AllScreens.Length > 1 && ConstantValuePool.BizSettingConfig.SecondScreenEnabled) { if (ConstantValuePool.SecondScreenForm != null && ConstantValuePool.SecondScreenForm is FormSecondScreen) { ((FormSecondScreen)ConstantValuePool.SecondScreenForm).BindGoodsOrderInfo(dgvGoodsOrder); ((FormSecondScreen)ConstantValuePool.SecondScreenForm).ShowOrderServiceFee(m_ActualPayMoney + m_ServiceFee, m_ServiceFee); } } } } }