public override void GetPromotionPresents(DataGridView dgvGoodsOrder) { foreach (PromotionPresent item in m_PromotionPresentList) { if (item.TotalMoney <= m_TotalMoney && item.TotalQuantity <= m_TotalQuantity) { if (item.Classification == 1) { //赠品 decimal giftNum = 0; if (item.IsMultiple) { giftNum = Math.Floor(m_TotalMoney / item.TotalMoney) * (decimal)item.Quantity; } else { giftNum = (decimal)item.Quantity; } Goods goods = new Goods(); goods.GoodsID = (Guid)item.GoodsID; goods.GoodsNo = item.GoodsNo; goods.GoodsName = goods.GoodsName2nd = item.GoodsName; goods.Unit = item.Unit; goods.SellPrice = (decimal)item.SellPrice; goods.CanDiscount = false; goods.AutoShowDetails = false; goods.PrintSolutionName = item.PrintSolutionName; goods.DepartID = (Guid)item.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; } //单选和多选只能是赠品 } } }
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); } } }
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; } } }