public void ResetOrderPanelSize() { _sizeMeasure = new Size(_colWidth, double.MaxValue); _pageColsCount = Convert.ToInt32(WpfHelper.GetAppGlobalValue("OrdersColumnsCount")); _colWidth = Convert.ToDouble(WpfHelper.GetAppGlobalValue("OrdersColumnWidth")); _colMargin = Convert.ToDouble(WpfHelper.GetAppGlobalValue("OrdersColumnMargin")); _hdrTopMargin = Convert.ToDouble(WpfHelper.GetAppGlobalValue("OrderPanelTopMargin")); _colHeight = _canvas.ActualHeight; // высота столбца OrderPanel minHeaderPanel = new OrderPanel(null, 0, _colWidth, false); _canvas.Children.Add(minHeaderPanel); DishDelimeterPanel continuePanel = createContinuePanel(true); _canvas.Children.Add(continuePanel); // измерение высоты служебных панелей #if fromActualHeight _canvas.UpdateLayout(); _ordHeaderMinHeight = minHeaderPanel.ActualHeight; _continuePanelHeight = continuePanel.ActualHeight; #else _canvas.Measure(_sizeMeasure); _ordHeaderMinHeight = minHeaderPanel.DesiredSize.Height; _continuePanelHeight = continuePanel.DesiredSize.Height; #endif _canvas.Children.Clear(); minHeaderPanel = null; }
private DishDelimeterPanel createContinuePanel(bool isForward) { BrushesPair brPair = BrushHelper.AppBrushes["delimiterBreakPage"]; string text = (isForward) ? WpfHelper.GetAppGlobalValue("ContinueOrderNextPage", "see next page").ToString() : WpfHelper.GetAppGlobalValue("ContinueOrderPrevPage", "see prev page").ToString(); DishDelimeterPanel newDelimPanel = new DishDelimeterPanel(_colWidth, brPair.Foreground, brPair.Background, text); newDelimPanel.DelimeterType = (isForward) ? DishDelimeterPanelTypeEnum.OrderContinueNext : DishDelimeterPanelTypeEnum.OrderContinuePrev; return(newDelimPanel); }
private DishDelimeterPanel createFilingPanel(int filingNumber) { Brush foreground = (filingNumber == 1) ? Brushes.Red : Brushes.Blue; string supplyName = WpfHelper.GetAppGlobalValue("DishesSupplyName", "подача").ToString(); DishDelimeterPanel newDelimPanel = new DishDelimeterPanel(_colWidth, foreground, Brushes.AliceBlue, supplyName + " " + filingNumber.ToString()) { DontTearOffNext = true }; newDelimPanel.DelimeterType = DishDelimeterPanelTypeEnum.FilingNumber; return(newDelimPanel); }
private OrderPanel createOrderPanel(OrderViewModel orderModel, int dishIdxFrom, int dishIdxTo, bool isTailSplit) { if (dishIdxFrom > dishIdxTo) { return(null); } OrderPanel ordPanel = new OrderPanel(orderModel, 0, _colWidth, (dishIdxFrom == 0 ? true: false)); // не с первого блюда - добавляем разделитель продолжения на предыд.странице if (dishIdxFrom != 0) { ordPanel.AddDelimiter(createContinuePanel(false)); } OrderDishViewModel dishModel; int curFiling = 0; for (int i = dishIdxFrom; i <= dishIdxTo; i++) { dishModel = orderModel.Dishes[i]; // разделитель подач if (curFiling != dishModel.FilingNumber) { curFiling = dishModel.FilingNumber; DishDelimeterPanel newDelimPanel = createFilingPanel(curFiling); ordPanel.AddDelimiter(newDelimPanel); } // панель блюда DishPanel dishPanel = new DishPanel(dishModel, _colWidth); ordPanel.AddDish(dishPanel); } // оторванных хвост (dishIdxTo меньше кол-ва элементов) - добавляем разделитель продолжения на след.странице if (isTailSplit) { ordPanel.AddDelimiter(createContinuePanel(true)); } return(ordPanel); }
public void InsertDelimiter(int index, DishDelimeterPanel delimPanel) { this.stkDishes.Children.Insert(index, delimPanel); }
public void AddDelimiter(DishDelimeterPanel delimPanel) { this.stkDishes.Children.Add(delimPanel); }
} // DrawOrderPanelsOnPage // преобразование сплошной панели в коллекцию панелей по колонкам // панели записываются на канву временного размещения // входные параметры: // - OrderPanel ordPanel - сплошная панель, которую надо разбить по колонкам, эта панель уже измерена! private void splitOrderViewPanels(OrderPanel ordPanel, bool keepSplitOrderOnLastColumnByForward) { OrderPanel curPanel = null; double curPanelHeight = 0d; string orderLogInfo = string.Format("id: {0}, index: {1}, number: {2}, dishes: {3}", ordPanel.OrderViewModel.Id, ordPanel.OrderViewModel.Index, ordPanel.OrderViewModel.Number, ordPanel.OrderViewModel.Dishes.Count); // цикл по блокам заказа, смещая curDishIndex, пока curDishIndex не дойдет до граничного значения в соотв.напр-и double freeHeight = getFreeHeight(); double curBlockHeight; List <FrameworkElement> curBlock; while (true) { curBlock = getNextItemsBlock(ordPanel, true); // выбрали все блоки - установить координаты последней панели и выйти if (curBlock == null) { setLastPanelPosition(curPanel, curPanelHeight); break; // нормальный выход - выбраны все элементы панели } // создать панель без заголовка, в которую будем переносить панели блюд if (curPanel == null) { curPanel = new OrderPanel(ordPanel.OrderViewModel, 0, ordPanel.Width, false); if (_shiftForward) { _canvas.Children.Add(curPanel); } else { _canvas.Children.Insert(0, curPanel); } // измерить панель measurePanel(curPanel); curPanelHeight = curPanel.PanelHeight; } // добавить заголовок заказа в панель, если при прямом проходе блок самый первый // иначе - добавлять в панель на последнем блоке из ordPanel if (_shiftForward && (curPanel.HeaderPanel == null) && (ordPanel.HeaderPanel != null)) { OrderPanelHeader header = ordPanel.DetachHeader(); curPanel.HeaderPanel = header; curPanelHeight += header.PanelHeight; } curBlockHeight = getBlockHeight(curBlock); // при обратном проходе и отсутствии элементов в ordPanel, // к curBlockHeight прибавить высоту заголовка и шапки таблицы блюд if (!_shiftForward && ((ordPanel.ItemsCount == 0) && (curPanel.HeaderPanel == null) && (ordPanel.HeaderPanel != null)) ) { curBlockHeight += ordPanel.HeaderHeight; if (curPanel.ItemsCount == 0) { curBlockHeight += ordPanel.DishTableHeaderHeight; } } // анализ размещения блока в свободном месте if (curPanelHeight + curBlockHeight <= freeHeight) { // при прямом проходе, добавить текущий блок элементов в конец панели заказа if (_shiftForward) { curPanel.AddDishes(curBlock); curPanelHeight += curBlockHeight; } // при обратном проходе, вставить блок в начало коллекции else { curPanel.InsertDishes(0, curBlock); curPanelHeight += curBlockHeight; // и не забываем про заголовок заказа при обратном проходе if ((ordPanel.ItemsCount == 0) && (curPanel.HeaderPanel == null) && (ordPanel.HeaderPanel != null)) { OrderPanelHeader header = ordPanel.DetachHeader(); curPanel.HeaderPanel = header; // высота заголовка заказа уже есть в curBlockHeight } } } // переход в следующий/предыдущий столбец else { // движение вперед, переход в следующий столбец if (_shiftForward) { // из последнего столбца #region из последнего столбца if (curColIndex == _pageColsCount) { // если панель заказа в последней колонке является продолжением заказа, т.е. HeaderPanel==null, то обрываем заказ и добавляем разделитель продолжения if (((curPanel.HeaderPanel == null) || keepSplitOrderOnLastColumnByForward) && (curPanel.ItemsCount > 0)) { // добавляем в конце разделитель продолжения заказа DishDelimeterPanel delimPanel = createContinuePanel(true); // удалить последний блок if (curPanelHeight + _continuePanelHeight > freeHeight) { _shiftForward = false; // смещаясь назад curBlock = getNextItemsBlock(curPanel, true); // поиск блока и удаление его _shiftForward = true; // восстановить смещение // если текущая панель не пустая, то добавляем панель переноса if ((curBlock != null) && (curPanel.ItemsCount > 0)) { curPanel.AddDelimiter(delimPanel); setPanelLeftTop(curPanel); } // иначе полностью переносим панель заказа в след.страницу else { _canvas.Children.Remove(curPanel); } } else { curPanel.AddDelimiter(delimPanel); setPanelLeftTop(curPanel); } } // иначе полностью переносим панель заказа в след.страницу else { _canvas.Children.Remove(curPanel); } // перенос панели на следующую страницу _pageBreak = true; break; } // из последнего столбца #endregion // из НЕпоследнего столбца: создаем новую панель (Top=0) #region из НЕпоследнего столбца else { // в текущей панели нет элементов или только одна панель DishPanel - // переносим панель в следующую колонку //if ((curPanel.DishPanels.Count == 0) || (curPanel.DishPanelsCount() == 1)) if (curPanel.DishPanels.Count == 0) { curPanel.AddDishes(curBlock); // добавить текущий блок элементов curPanelHeight += curBlockHeight; curColIndex++; curTopValue = 0d; // следующая колонка setPanelLeftTop(curPanel); } // размещение предыдущей панели по текущим координатам и создание новой панели else { setPanelLeftTop(curPanel); // новая панель без заголовка заказа curPanel = new OrderPanel(ordPanel.OrderViewModel, 0, ordPanel.Width, false); curPanel.AddDishes(curBlock); // добавить текущий блок элементов _canvas.Children.Add(curPanel); measurePanel(curPanel); curPanelHeight = curPanel.PanelHeight; // координаты следующего столбца curColIndex++; curTopValue = 0d; } freeHeight = getFreeHeight(); } #endregion } // движение назад, переход в предыдущий столбец else { // из первого столбца #region из первого столбца if (curColIndex == 1) { // если в текущей панели еще нет строк, то переносим всю панель на предыдущий лист // удалив текущую пустую панель if (curPanel.ItemsCount == 0) { _canvas.Children.Remove(curPanel); } // если в текущей панели уже есть блюда, т.е. есть что оставлять на текущей странице, // то добавляем в начало разделитель продолжения заказа и разделитель подачи else { DishDelimeterPanel contPanel = createContinuePanel(false); double delimPanelsHeight = _continuePanelHeight; // поиск номера подачи в блоке тек.панели (та, что остается на тек.странице) DishDelimeterPanel filingPanel = null; curBlock = getNextItemsBlock(curPanel, false, true); // блок НЕ удаляем!! if (curBlock != null) { int filingNumber = getFilingNumber(curBlock); if (filingNumber != 0) { filingPanel = createFilingPanel(filingNumber); // измерить высоту панели номера подачи //measurePanel(filingPanel); //double pnlHeight = getBlockHeight(new FrameworkElement[] { filingPanel }); //delimPanelsHeight += pnlHeight; } } bool keepPanel = true; //bool keepPanel = false; //// если разделитель не помещается, то удалить следующий блок из текущей панели //if (curPanelHeight + delimPanelsHeight > freeHeight) //{ // curBlock = getNextItemsBlock(curPanel, true, true); // // после удаления первого блока из текущ.панели остались блюда - добавляем разделитель // if ((curBlock != null) && (curPanel.ItemsCount > 0)) // { // keepPanel = true; // } // // иначе удаляем весь заказ со страницы - будет отрисован на предыду.странице // else // { // _canvas.Children.Remove(curPanel); // } //} //else //{ // keepPanel = true; //} // вставить разделители if (keepPanel) { curPanel.InsertDelimiter(0, contPanel); if (filingPanel != null) { curPanel.InsertDelimiter(0, filingPanel); } curTopValue = 0d; setPanelLeftTop(curPanel); } } // перенос панели на предыдущую страницу _pageBreak = true; break; } #endregion // из НЕпервого столбца - создаем новую панель #region из НЕпервого столбца - создаем новую панель else { // в текущей панели нет элементов - возвращаем блок и переносим панель НЕ разбивая ее if (curPanel.ItemsCount == 0) { curPanel.InsertDishes(0, curBlock); curPanelHeight += curBlockHeight; } // размещение предыдущей панели по текущим координатам и создание новой панели else { curTopValue = 0d; setPanelLeftTop(curPanel); // новая панель curPanel = new OrderPanel(ordPanel.OrderViewModel, 0, ordPanel.Width, false); curPanel.InsertDishes(0, curBlock); // добавить текущий блок элементов _canvas.Children.Insert(0, curPanel); measurePanel(curPanel); curPanelHeight = curPanel.PanelHeight; } // еще раз проверить перенос заголовка панели заказа if ((ordPanel.ItemsCount == 0) && (curPanel.HeaderPanel == null) && (ordPanel.HeaderPanel != null)) { OrderPanelHeader header = ordPanel.DetachHeader(); curPanel.HeaderPanel = header; curPanelHeight += header.PanelHeight; } curColIndex--; curTopValue = _colHeight; freeHeight = getFreeHeight(); } #endregion } } } return; }
//******************************************* // РАЗМЕЩЕНИЕ ПАНЕЛЕЙ ЗАКАЗОВ //******************************************* public void AddOrderPanel(OrderViewModel orderModel) { OrderPanel ordPnl; DishPanel dshPnl; //, curDshPnl = null; // СОЗДАТЬ ПАНЕЛЬ ЗАКАЗА вместе с ЗАГОЛОВКОМ заказа и строкой заголовка таблицы блюд ordPnl = new OrderPanel(orderModel, _currentPageIndex, _colWidth, true); // поле между заказами по вертикали if (_curTopValue > 0d) { _curTopValue += _hdrTopMargin; } ordPnl.SetPosition(_curTopValue, getLeftOrdPnl()); CurrentPage.AddOrder(ordPnl); CurrentPage.UpdateLayout(); // перенос в новый столбец всего заказа if ((_curTopValue + ordPnl.PanelHeight) >= _uiPanelSize.Height) { moveToNewCol(ordPnl); CurrentPage.UpdateLayout(); } int curFiling = 0; // блюда foreach (OrderDishViewModel dishModel in orderModel.Dishes) { if (curFiling != dishModel.FilingNumber) { curFiling = dishModel.FilingNumber; Brush foreground = (curFiling == 1) ? Brushes.Red : Brushes.Blue; DishDelimeterPanel newDelimPanel = new DishDelimeterPanel(_colWidth, foreground, Brushes.AliceBlue, "Подача " + curFiling.ToString()) { DontTearOffNext = true }; ordPnl.AddDelimiter(newDelimPanel); // и добавить в стек } //if (dishModel.ParentUID.IsNull()) curDshPnl = null; // сохранить родительское блюдо dshPnl = new DishPanel(dishModel, _colWidth); // , curDshPnl //if (dishModel.ParentUID.IsNull()) curDshPnl = dshPnl; // сохранить родительское блюдо // добавить строку заказа в стек ordPnl.AddDish(dshPnl); CurrentPage.UpdateLayout(); if ((_curTopValue + Math.Ceiling(ordPnl.PanelHeight)) > _uiPanelSize.Height) // переход в новый столбец { // 1. удалить из ordPnl только что добавленное блюдо // и вернуть массив удаленных элементов, возможно с "висячим" разделителем номера подачи UIElement[] delItems = ordPnl.RemoveDish(dshPnl, _curTopValue, _uiPanelSize.Height); // разбиваем блюда заказа по колонкам на той же странице if ((ordPnl.ItemsCount > 2) && ((_curColIndex < _pageColsCount) || ((_curColIndex == _pageColsCount) && (Convert.ToDouble(ordPnl.GetValue(Canvas.TopProperty)) == 0d)))) { setNextColumn(); // 2. создать новый OrderPanel для текущего блюда с заголовком таблицы ordPnl = new OrderPanel(orderModel, _currentPageIndex, _colWidth, false); // 3. добавить только что удаленные блюда ordPnl.AddDishes(delItems); // 4. привязать к канве ordPnl.SetPosition(_curTopValue, getLeftOrdPnl()); CurrentPage.AddOrder(ordPnl); } // не разбиваем заказ, а полностью переносим в новую колонку else { // 2. изменить координаты панели заказа moveToNewCol(ordPnl); // 3. добавить только что удаленные блюда ordPnl.AddDishes(delItems); } CurrentPage.UpdateLayout(); } } // foreach dishes _curTopValue += ordPnl.PanelHeight; }