Exemplo n.º 1
0
        /// <summary>
        /// Загрузка дерева рецептур в таблицу
        /// </summary>
        /// <param name="nodes">коллекция строк</param>
        /// <param name="data">рецептура</param>
        private void LoadReceptData(TreeGridNodeCollection nodes, DataRecept data)
        {
            TreeGridNode curNode = null;

            foreach (DataBase dr in data.Components)
            {
                //MessageBox.Show("Start Load: " + dr.name);

                // если компонента рецептуры есть сама рецептура, то делаем рекурсию
                if (dr is DataRecept)
                {
                    DataRecept rec = dr as DataRecept;
                    curNode = new TreeGridNode();
                    curNode.DefaultCellStyle.BackColor = Color.LightGray;
                    curNode.Tag = rec;
                    nodes.Add(curNode);
                    curNode.Cells[dgvRecName.Index].Value       = rec.Name;
                    curNode.Cells[dgvRecCountNetto.Index].Value = rec.TotalExit;
                    LoadReceptData(curNode.Nodes, rec);
                    continue;
                }

                // иначе это обычная компонента и мы ее загружаем в корень
                DataRaw curRaw = dr as DataRaw;
                curNode     = new TreeGridNode();
                curNode.Tag = curRaw;
                nodes.Add(curNode);
                curNode.Cells[dgvRecCountNetto.Index].Value  = (curRaw.Quantity != 0 ? curRaw.Quantity.ToString(CultureInfo.CurrentCulture) : string.Empty);
                curNode.Cells[dgvRecCountBrutto.Index].Value = (curRaw.Brutto != 0 ? curRaw.Brutto.ToString(CultureInfo.CurrentCulture) : string.Empty);
                curNode.Cells[dgvRecComment.Index].Value     = curRaw.Comment;
                if (curRaw.RawStruct != null)
                {
                    curNode.Cells[dgvRecName.Index].Value = curRaw.RawStruct.DisplayMember;
                    if (curRaw.Brutto == 0 && curRaw.Quantity != 0 && curRaw.RawStruct.Brutto != 0)
                    {
                        curNode.Cells[dgvRecCountBrutto.Index].Value = CommonFunctions.Round(curRaw.Quantity * curRaw.RawStruct.Brutto);
                    }
                    if (curRaw.Quantity == 0 && curRaw.RawStruct.Brutto != 0 && curRaw.Brutto != 0)
                    {
                        curNode.Cells[dgvRecCountNetto.Index].Value = CommonFunctions.Round(curRaw.Brutto / curRaw.RawStruct.Brutto);
                    }
                }
                if (curRaw.ProcessLoss != null)
                {
                    (curNode.Cells[dgvRecProcessLoss.Index] as DataGridViewComboBoxCell).Value = curRaw.ProcessLoss.ValueMember;
                }
            }

            // добавляем пустую новую строку для каждой рецептуры
            nodes.Add(new TreeGridNode());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Загрузка дерева рецептур
        /// </summary>
        /// <param name="root">текущие листья узла</param>
        /// <param name="curRec">рецептура</param>
        private void LoadRecepts(TreeNodeCollection root, DataRecept curRec)
        {
            TreeNode curnode = new TreeNode(curRec.Name + " (" + CommonFunctions.Round(curRec.PercentFilling()) + "%)");

            curnode.Tag = curRec;
            root.Add(curnode);
            foreach (DataBase rec in curRec.Components)
            {
                if (rec is DataRecept)
                {
                    LoadRecepts(curnode.Nodes, rec as DataRecept);
                }
            }
        }
Exemplo n.º 3
0
        private void UpdateTreeNode(TreeNode root, bool isMainDataChanged)
        {
            DataBase curData = (DataBase)root.Tag;

            // удаляем узел, если его нет у родителя
            if (curData.Parent != null && !curData.Parent.Contains(curData))
            {
                root.Remove();
                return;
            }

            string newName = curData.Name + " (" + CommonFunctions.Round(curData.PercentFilling()) + "%)";

            // обновляем имя узла если изменилось
            if (!root.Text.Equals(newName))
            {
                root.Text = newName;
            }

            if (isMainDataChanged)
            {
                // добавляем новые узлы для книги
                if (curData is DataBook)
                {
                    foreach (DataBase curChild in ((DataBook)curData).Components)
                    {
                        bool isFound = false;
                        foreach (TreeNode node in root.Nodes)
                        {
                            if (((DataBase)node.Tag).Equals(curChild))
                            {
                                isFound = true;
                                break;
                            }
                        }
                        if (!isFound)
                        {
                            TreeNode newNode = null;
                            if (curChild.Name == "")
                            {
                                newNode          = new TreeNode("(без названия)");
                                newNode.NodeFont = new Font(newNode.NodeFont, FontStyle.Italic);
                            }
                            else
                            {
                                newNode = new TreeNode(curChild.Name + " (" + CommonFunctions.Round(curChild.PercentFilling()) + "%)");
                            }
                            newNode.Tag = curChild;
                            root.Nodes.Add(newNode);
                        }
                    }
                }

                if (curData is DataRecept)
                {
                    foreach (DataBase curChild in ((DataRecept)curData).Components)
                    {
                        if (!(curChild is DataRecept || curChild is DataBook))
                        {
                            continue;
                        }
                        bool isFound = false;
                        foreach (TreeNode node in root.Nodes)
                        {
                            if (((DataBase)node.Tag).Equals(curChild))
                            {
                                isFound = true;
                                break;
                            }
                        }
                        if (!isFound)
                        {
                            TreeNode newNode = null;
                            if (curChild.Name == "")
                            {
                                newNode          = new TreeNode("(без названия)");
                                newNode.NodeFont = new Font(newNode.NodeFont, FontStyle.Italic);
                            }
                            else
                            {
                                newNode = new TreeNode(curChild.Name + " (" + CommonFunctions.Round(curChild.PercentFilling()) + "%)");
                            }
                            newNode.Tag = curChild;
                            root.Nodes.Add(newNode);
                        }
                    }
                }
            }

            // рекурсия по нижестоящим узлам
            if (root.Nodes != null)
            {
                foreach (TreeNode curNode in root.Nodes)
                {
                    UpdateTreeNode(curNode, isMainDataChanged);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Создание технико-технологической карты
        /// </summary>
        /// <returns></returns>
        internal string PrintTTK(DataRecept curRec)
        {
            Hashtable   groupRaws = curRec.GroupRaws(true);
            FormCounter cc        = new FormCounter();

            StringBuilder ret = new StringBuilder("<html><style>h3{text-align:center;}</style>");

            try{
                curRec.CalcRecept();
            }catch (OverflowException ex)
            {
                ret.Append("<p align=center>Невозможно сосчитать рецептуру:" + ex.Message + ". Проверьте правильность заполнения</p></html>");
                return(ret.ToString());
            }

            // шапка
            ret.Append(makeHeader(true, true));
            ret.Append("<p align=center><b><font size=4>ТЕХНИКО-ТЕХНОЛОГИЧЕСКАЯ КАРТА № " + curRec.Id.ToString(CultureInfo.CurrentCulture) +
                       "</font><br><font size=5> на " + curRec.Name + "</font></b>");
            if (!String.IsNullOrEmpty(curRec.normativDoc))
            {
                ret.Append("<br>Изготовлено по " + curRec.normativDoc);
            }
            ret.Append("</p>");

            // область применения
            ret.Append("<h3>" + cc.moveUp() + " Область применения</h3>" +
                       "<p align=justify>" + cc.next() + " Настоящая технико-технологическая карта распространяется на изделие \"" +
                       curRec.Name + "\", вырабатываемое " + DataBook.Book.company + ".");
            if (!String.IsNullOrEmpty(curRec.preview))
            {
                ret.Append("<br>" + cc.next() + " Описание изделия. " + curRec.preview);
            }
            ret.Append("</p>");

            // перечень сырья и гостов
            ret.Append("<h3>" + cc.moveUp() + " Перечень сырья</h3>");
            StringBuilder curElem = new StringBuilder();

            foreach (DataRawStruct curRaw in groupRaws.Keys)
            {
                if (String.IsNullOrEmpty(curRaw.NormativDoc) || !curRaw.InRecept)
                {
                    continue;
                }
                curElem.Append("<tr><td><span>" + curRaw.Name + "</span><td><span>" + curRaw.NormativDoc + "</span></tr>");
            }
            if (curElem.Length > 0)
            {
                ret.Append("<p align=justify>" + cc.next() + " Для приготовления \"" + curRec.Name + "\" используют следующее сырье: <table>");
                ret.Append(curElem);
                ret.Append("</table>или продукты зарубежных фирм, имеющие сертификаты и удостоверения качества РФ.</p>");
            }

            ret.Append("<p align=justify>" + cc.next() + " Сырье, используемое для приготовления \"" + curRec.Name + "\", должно соответствовать требованиям" +
                       " нормативной документации, иметь сертификаты и удостоверения качества.</p>");

            // рецептура
            ret.Append("<h3>" + cc.moveUp() + " Рецептура</h3><p align=justify>Рецептура изделия \"" + curRec.Name +
                       "\"<table width=\"100%\" border><tr><td align=center> Наименование сырья <td align=center>Масса брутто, г<td align=center> Масса нетто, г</tr>");
            decimal brSum = 0, ntSum = 0;

            // пробегаем по вложенным рецептурам
            foreach (DataBase dbase in curRec.Components)
            {
                if (dbase is DataRecept)
                {
                    groupRaws = (dbase as DataRecept).GroupRaws(false);
                    Decimal curbrSum = 0;
                    Decimal curntSum = 0;
                    foreach (DataRawStruct curRaw in groupRaws.Keys)
                    {
                        if (!curRaw.InRecept)
                        {
                            continue;
                        }

                        decimal brutto = (groupRaws[curRaw] as DataRaw).Brutto * Config.Cfg.TotalExit / curRec.CalcExitNetto;
                        decimal netto  = (groupRaws[curRaw] as DataRaw).Quantity * Config.Cfg.TotalExit / curRec.CalcExitNetto;
                        ret.Append("<tr><td>" + curRaw.Name + "<td align=center>" +
                                   CommonFunctions.Round(brutto) +
                                   "<td align=center>" + CommonFunctions.Round(netto) + "</tr>");
                        curbrSum += brutto;
                        curntSum += netto;
                    }
                    ret.Append("<tr style=\"background-color: #808080\"><td>Итого " + dbase.Name + "<td align=center>" + CommonFunctions.Round(curbrSum) + "<td align=center>" + CommonFunctions.Round(curntSum) + "</tr>");
                    brSum += curbrSum;
                    ntSum += curntSum;
                }
            }

            // отстатки основной рецептуры
            groupRaws = curRec.GroupRaws(false);

            foreach (DataRawStruct curRaw in groupRaws.Keys)
            {
                if (!curRaw.InRecept)
                {
                    continue;
                }

                decimal brutto = (groupRaws[curRaw] as DataRaw).Brutto * Config.Cfg.TotalExit / curRec.CalcExitNetto;
                decimal netto  = (groupRaws[curRaw] as DataRaw).Quantity * Config.Cfg.TotalExit / curRec.CalcExitNetto;
                ret.Append("<tr><td>" + curRaw.Name + "<td align=center>" +
                           CommonFunctions.Round(brutto) +
                           "<td align=center>" + CommonFunctions.Round(netto) + "</tr>");
                brSum += brutto;
                ntSum += netto;
            }
            ret.Append("<tr><td>Итого<td align=center>" + CommonFunctions.Round(brSum) + "<td align=center>" + CommonFunctions.Round(ntSum) + "</tr>");
            ret.Append("<tr><td>Выход<td>&nbsp;<td align=center>" + CommonFunctions.Round(Config.Cfg.TotalExit) + "</tr>");
            ret.Append("</table></p>");

            // технологический процесс
            ret.Append("<h3>" + cc.moveUp() + " Технологический процесс</h3>");
            ret.Append("<p align=justify> " + cc.next() + " Подготовка сырья к производству изделия \"" + curRec.Name + "\" производится в соответствии со \"Сборником рецептур блюд и кулинарных изделий для предприятий общественного питания\" (1996 г.).</p>");
            if (!String.IsNullOrEmpty(curRec.process))
            {
                ret.Append("<p align=justify> " + cc.next() + " " + curRec.process + "</p>");
            }

            // оформление подача и т.д.
            if (!String.IsNullOrEmpty(curRec.design) || !String.IsNullOrEmpty(curRec.delivery) ||
                !String.IsNullOrEmpty(curRec.sale) || !String.IsNullOrEmpty(curRec.storage))
            {
                ret.Append("<h3>" + cc.moveUp() + " Оформление, подача, реализация и хранение</h3>");
                if (!String.IsNullOrEmpty(curRec.design))
                {
                    ret.Append("<p align=justify> " + cc.next() + " " + curRec.design + "</p>");
                }
                if (!String.IsNullOrEmpty(curRec.delivery))
                {
                    ret.Append("<p align=justify> " + cc.next() + " " + curRec.delivery + "</p>");
                }
                if (!String.IsNullOrEmpty(curRec.sale))
                {
                    ret.Append("<p align=justify> " + cc.next() + " " + curRec.sale + "</p>");
                }
                if (!String.IsNullOrEmpty(curRec.storage))
                {
                    ret.Append("<p align=justify> " + cc.next() + " " + curRec.storage + "</p>");
                }
            }

            // физ-хим показатели
            ret.Append("<h3>" + cc.moveUp() + " Показатели качества и безопасности</h3>");
            curElem = makeReceptProperty(curRec);
            if (curElem.Length > 0)
            {
                ret.Append("<p align=justify>" + cc.next() + " Органолептические показатели изделия:<br>");
                ret.Append(curElem + "</p>");
            }

            ret.Append("<p align=justify>" + cc.next() + " Физико-химические показатели:<br>");
            if (curRec.CalcWater != 0)
            {
                string waterApp = "";
                if (curRec.waterPlus == curRec.waterMinus)
                {
                    if (curRec.waterPlus != 0)
                    {
                        waterApp = " &plusmn;" + curRec.waterPlus;
                    }
                }
                else
                {
                    waterApp = " +" + curRec.waterPlus + " -" + curRec.waterMinus;
                }
                ret.AppendLine("Влажность: " + CommonFunctions.Round(curRec.CalcWater) + "%" + waterApp + "<br>");
            }
            if (curRec.Acidity != 0)
            {
                ret.AppendLine("Кислотность: " + CommonFunctions.Round(curRec.Acidity) + "Ph<br>");
            }
            if (curRec.CalcProperty.starch != 0)
            {
                ret.AppendLine("Крахмал: " + CommonFunctions.Round(curRec.CalcProperty.starch) + "%<br>");
            }
            if (curRec.CalcProperty.saccharides != 0)
            {
                ret.Append("Моно и дисахариды: " + CommonFunctions.Round(curRec.CalcProperty.saccharides) + "%<br>");
            }
            if (curRec.CalcProperty.acid != 0)
            {
                ret.Append("Жирные кислоты: " + CommonFunctions.Round(curRec.CalcProperty.acid) + "%<br>");
            }
            if (curRec.CalcProperty.ash != 0)
            {
                ret.Append("Зола: " + CommonFunctions.Round(curRec.CalcProperty.ash) + "%<br>");
            }
            if (curRec.CalcProperty.cellulose != 0)
            {
                ret.Append("Целлюлоза: " + CommonFunctions.Round(curRec.CalcProperty.cellulose) + "%<br>");
            }
            if (curRec.CalcProperty.cholesterol != 0)
            {
                ret.Append("Холестерин: " + CommonFunctions.Round(curRec.CalcProperty.cholesterol) + "%<br>");
            }
            if (curRec.CalcProperty.protein != 0)
            {
                ret.Append("Протеины: " + CommonFunctions.Round(curRec.CalcProperty.protein) + "%<br>");
            }

            // макроэлементы
            curElem = new StringBuilder();
            if (curRec.CalcProperty.MineralK != 0)
            {
                curElem.Append("<li>Калий (K): " + CommonFunctions.Round(curRec.CalcProperty.MineralK));
            }
            if (curRec.CalcProperty.MineralCA != 0)
            {
                curElem.Append("<li>Кальций (Ca): " + CommonFunctions.Round(curRec.CalcProperty.MineralCA));
            }
            if (curRec.CalcProperty.MineralMG != 0)
            {
                curElem.Append("<li>Магний (Mg): " + CommonFunctions.Round(curRec.CalcProperty.MineralMG));
            }
            if (curRec.CalcProperty.MineralNA != 0)
            {
                curElem.Append("<li>Натрий (Na): " + CommonFunctions.Round(curRec.CalcProperty.MineralNA));
            }
            if (curRec.CalcProperty.MineralP != 0)
            {
                curElem.Append("<li>Фосфор (P): " + CommonFunctions.Round(curRec.CalcProperty.MineralP));
            }
            if (curElem.Length > 0)
            {
                ret.Append("<div>Макроэлементы, мг<ul>");
                ret.Append(curElem);
                ret.Append("</ul></div>");
            }

            // микроэлементы
            curElem = new StringBuilder();
            if (curRec.CalcProperty.MineralFE != 0)
            {
                curElem.Append("<li>Железо (Fe): " + CommonFunctions.Round(curRec.CalcProperty.MineralFE));
            }
            if (curElem.Length > 0)
            {
                ret.Append("<div>Микроэлементы, мкг<ul>");
                ret.Append(curElem);
                ret.Append("</ul></div>");
            }

            // витамины
            curElem = new StringBuilder();
            if (curRec.CalcProperty.vitaminA != 0)
            {
                curElem.Append("<li>Ретинол (А): " + CommonFunctions.Round(curRec.CalcProperty.vitaminA));
            }
            if (curRec.CalcProperty.VitaminB != 0)
            {
                curElem.Append("<li>Бета-каротин (B): " + CommonFunctions.Round(curRec.CalcProperty.VitaminB));
            }
            if (curRec.CalcProperty.VitaminB1 != 0)
            {
                curElem.Append("<li>Тиамин (B1): " + CommonFunctions.Round(curRec.CalcProperty.VitaminB1));
            }
            if (curRec.CalcProperty.VitaminB2 != 0)
            {
                curElem.Append("<li>Рибофлавин (B2): " + CommonFunctions.Round(curRec.CalcProperty.VitaminB2));
            }
            if (curRec.CalcProperty.VitaminC != 0)
            {
                curElem.Append("<li>Аскорбиновая кислота (C): " + CommonFunctions.Round(curRec.CalcProperty.VitaminC));
            }
            if (curRec.CalcProperty.VitaminPP != 0)
            {
                curElem.Append("<li>Ниацин (PP): " + CommonFunctions.Round(curRec.CalcProperty.VitaminPP));
            }
            if (curElem.Length > 0)
            {
                ret.Append("<div>Витамины<ul>");
                ret.Append(curElem);
                ret.Append("</ul></div>");
            }

            if (curRec.MicroBiology != null)
            {
                ret.Append("<p align=justify>" + cc.next() + " Микробиологические показатели:" + "</p>");
                throw new NotImplementedException("Нарисовать табличку с микробиологией");
            }
            ret.Append("<h3>" + cc.moveUp() + " Пищевая и энергетическая ценность</h3>");
            ret.Append("<p><table width=\"100%\"  border><tr><td align=\"center\"><span>Белки</span><td align=\"center\"><span>Жиры</span><td align=\"center\"><span>Углеводы</span><td align=\"center\"><span>Энергетическая ценность, ккал/кДж</span></tr>");
            ret.Append("<tr><td align=\"center\"><span>" + CommonFunctions.Round((Decimal)curRec.CalcProperty.protein) + "</span>" +
                       "<td align=\"center\"><span>" + CommonFunctions.Round((Decimal)curRec.CalcProperty.fat) + "</span>" +
                       "<td align=\"center\"><span>" + CommonFunctions.Round((Decimal)(curRec.CalcProperty.saccharides + curRec.CalcProperty.starch)) + "</span>" +
                       "<td align=\"center\"><span>" + CommonFunctions.Round((Decimal)curRec.CalcProperty.Caloric) + "/" +
                       CommonFunctions.Round((Decimal)curRec.CalcProperty.Caloric * (Decimal)4.184) + "</span>" + "</tr></table></p>");

            ret.Append(makeFooter());

            // автозамены
            ReplaceSymbols(ret);

            return(ret.ToString());
        }
Exemplo n.º 5
0
        private void dgvRawList_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }

            TreeGridNode curNode  = dgvRawList.GetNodeForRow(e.RowIndex);
            object       curValue = dgvRawList[e.ColumnIndex, e.RowIndex].Value;
            DataBase     curRec   = curNode.Tag as DataBase;
            bool         isNew    = curNode.Tag == null ? true : false;

            if (curValue == null && isNew)
            {
                return;
            }

            dgvRawList.CellValueChanged -= new DataGridViewCellEventHandler(dgvRawList_CellValueChanged);

            // родительский объект
            DataBase par = curRec == null ? myData : curRec.Parent;

            if (curRec == null && curNode.Parent != null && curNode.Parent.Index >= 0 && curNode.Parent.Tag != null)
            {
                par = curNode.Parent.Tag as DataBase;
            }

            // если это последняя строчка, то добавляем следующую пустую, а для этой делаем структуру
            if (isNew)
            {
                curRec = new DataRaw(par);
            }

            if (curRec is DataRecept)
            {
                DataRecept curRecept = (DataRecept)curRec;
                // изменение имени
                if (e.ColumnIndex == dgvRecName.Index && !curRecept.Name.Equals(curValue))
                {
                    if (curValue == null || curValue.ToString().Length == 0)
                    {
                        dgvRawList[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Yellow;
                    }
                    else
                    {
                        curRecept.Name = curValue.ToString();
                        dgvRawList[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.LightGray;
                    }
                }

                // изменение выхода
                if (e.ColumnIndex == dgvRecCountNetto.Index)
                {
                    try {
                        curRecept.TotalExit = Convert.ToDecimal(curValue, CultureInfo.CurrentCulture);
                        dgvRawList[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.LightGray;
                    } catch (System.Exception) {
                        dgvRawList[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Yellow;
                    }
                }
                // обработка компоненты
            }
            else
            {
                DataRaw curData = (DataRaw)curRec;

                // изменение потерь
                if (e.ColumnIndex == dgvRecProcessLoss.Index)
                {
                    curData.ProcessLoss = Config.DP.GetProcessLossByNum(Convert.ToInt32(curValue, CultureInfo.CurrentCulture));
                }

                decimal brutto = 0;
                if (curData.RawStruct != null && curData.RawStruct.Brutto != 0)
                {
                    brutto = curData.RawStruct.Brutto;
                }
                // изменение нетто
                if (e.ColumnIndex == dgvRecCountNetto.Index)
                {
                    try {
                        curData.Quantity = Convert.ToDecimal(curValue, CultureInfo.CurrentCulture);
                        if (curData.Brutto == 0 && curData.Quantity != 0 && brutto != 0)
                        {
                            dgvRawList[dgvRecCountBrutto.Index, e.RowIndex].Value = CommonFunctions.Round(curData.Quantity * brutto);
                        }
                        dgvRawList[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.White;
                    } catch (System.Exception) {
                        dgvRawList[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Yellow;
                    }
                }

                // изменение брутто
                if (e.ColumnIndex == dgvRecCountBrutto.Index)
                {
                    try {
                        ((DataRaw)curData).Brutto = Convert.ToDecimal(curValue, CultureInfo.CurrentCulture);
                        if (curData.Quantity == 0 && curData.Brutto != 0 && brutto != 0)
                        {
                            dgvRawList[dgvRecCountNetto.Index, e.RowIndex].Value = CommonFunctions.Round(((DataRaw)curData).Brutto / brutto);
                        }
                        dgvRawList[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.White;
                    } catch (System.Exception) {
                        dgvRawList[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Yellow;
                    }
                }

                // изменение коммента
                if (e.ColumnIndex == dgvRecComment.Index)
                {
                    curData.Comment = Convert.ToString(dgvRawList[e.ColumnIndex, e.RowIndex].Value, CultureInfo.CurrentCulture);
                }
            }

            if (isNew)
            {
                par.Components.Add(curRec);
            }

            dgvRawList.CellValueChanged += new DataGridViewCellEventHandler(dgvRawList_CellValueChanged);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Проверка данных формы и данных рецептуры
        /// </summary>
        /// <param name="root">дерево строк формы</param>
        /// <param name="curRec">рецептура</param>
        private void CheckReceptData(TreeGridNodeCollection root, DataRecept curRec)
        {
            ArrayList toDelete = new ArrayList();

            TreeGridNode lastNode = null;

            // собираем строчки для удаления
            if (dgvRawList.Nodes.Count > 0)
            {
                foreach (TreeGridNode dr in root)
                {
                    // если это пустая последняя строчка, то пропускаем
                    if (dr.Tag == null)
                    {
                        if (lastNode == null)
                        {
                            lastNode = dr;
                        }
                        else
                        {
                            toDelete.Add(dr);
                        }
                        continue;
                    }

                    DataBase curBase = (DataBase)dr.Tag;
                    if (!curRec.Components.Contains(curBase))
                    {
                        toDelete.Add(dr);
                        continue;
                    }

                    // если это рецептура, то рекурсия проверки
                    if (curBase is DataRecept)
                    {
                        CheckReceptData(dr.Nodes, curBase as DataRecept);
                        continue;
                    }

                    DataRaw curRaw = curBase as DataRaw;
                    if (curRaw.RawStruct != null)
                    {
                        if (!curRaw.RawStruct.DisplayMember.Equals(dr.Cells[dgvRecName.Index].Value))
                        {
                            dr.Cells[dgvRecName.Index].Value = curRaw.RawStruct.DisplayMember;
                        }
                    }
                    if (!((Decimal)curRaw.Brutto).Equals(dr.Cells[dgvRecCountBrutto.Index].Value))
                    {
                        dr.Cells[dgvRecCountBrutto.Index].Value = curRaw.Brutto;
                    }
                    if (curRaw.ProcessLoss != null)
                    {
                        if (!curRaw.ProcessLoss.ValueMember.Equals((dr.Cells[dgvRecProcessLoss.Index] as DataGridViewComboBoxCell).Value))
                        {
                            dr.Cells[dgvRecProcessLoss.Index].Value = curRaw.ProcessLoss.ValueMember;
                        }
                    }
                    if (!curRaw.Quantity.Equals(dr.Cells[dgvRecCountNetto.Index].Value))
                    {
                        dr.Cells[dgvRecCountNetto.Index].Value = curRaw.Quantity;
                    }
                    if (!curRaw.Comment.Equals(dr.Cells[dgvRecComment.Index].Value))
                    {
                        dr.Cells[dgvRecComment.Index].Value = curRaw.Comment;
                    }
                    if (curRaw.RawStruct != null)
                    {
                        if (curRaw.Brutto == 0 && curRaw.Quantity != 0)
                        {
                            dr.Cells[dgvRecCountBrutto.Index].Value = CommonFunctions.Round(curRaw.Quantity * curRaw.RawStruct.Brutto);
                        }
                        if (curRaw.Quantity == 0 && curRaw.Brutto != 0 && curRaw.RawStruct.Brutto != 0)
                        {
                            dr.Cells[dgvRecCountNetto.Index].Value = CommonFunctions.Round(curRaw.Brutto / curRaw.RawStruct.Brutto);
                        }
                    }
                }
            }
            if (toDelete.Count > 0)
            {
                foreach (TreeGridNode dr in toDelete)
                {
                    root.Remove(dr);
                }
            }

            // добавление новых
            if (curRec.Components.Count > 0)
            {
                foreach (DataBase newRec in curRec.Components)
                {
                    Boolean isExists = false;
                    foreach (TreeGridNode dr in root)
                    {
                        if (newRec.Equals(dr.Tag))
                        {
                            isExists = true;
                            break;
                        }
                    }
                    if (!isExists)
                    {
                        TreeGridNode node = new TreeGridNode();
                        node.Tag = newRec;
                        root.Add(node);

                        if (newRec is DataRecept)
                        {
                            //TreeGridNode curNode = root.Add(null, newRec.name, null, null, (newRec as DataRecept).totalExit, newRec.comment);
                            node.Cells[dgvRecName.Index].Value       = newRec.Name;
                            node.Cells[dgvRecCountNetto.Index].Value = (newRec as DataRecept).TotalExit;
                            node.DefaultCellStyle.BackColor          = Color.LightGray;
                            LoadReceptData(node.Nodes, newRec as DataRecept);
                            continue;
                        }

                        DataRaw curRaw = newRec as DataRaw;
                        //TreeGridNode newNode = root.Add(curRaw.id, null, null, curRaw.brutto, curRaw.quantity, curRaw.comment);
                        node.Cells[dgvRecCountBrutto.Index].Value = curRaw.Brutto;
                        node.Cells[dgvRecCountNetto.Index].Value  = curRaw.Quantity;
                        node.Cells[dgvRecComment.Index].Value     = curRaw.Comment;
                        if (curRaw.RawStruct != null)
                        {
                            node.Cells[dgvRecName.Index].Value = curRaw.RawStruct.DisplayMember;
                            if (curRaw.Brutto == 0 && curRaw.Quantity != 0 && curRaw.RawStruct.Brutto != 0)
                            {
                                node.Cells[dgvRecCountBrutto.Index].Value = CommonFunctions.Round(curRaw.Quantity * curRaw.RawStruct.Brutto);
                            }
                            if (curRaw.Brutto != 0 && curRaw.Quantity == 0 && curRaw.RawStruct.Brutto != 0)
                            {
                                node.Cells[dgvRecCountNetto.Index].Value = CommonFunctions.Round(curRaw.Brutto / curRaw.RawStruct.Brutto);
                            }
                        }
                        if (curRaw.ProcessLoss != null)
                        {
                            (node.Cells[dgvRecProcessLoss.Index] as DataGridViewComboBoxCell).Value = curRaw.ProcessLoss.ValueMember;
                        }
                    }
                }
            }

            // проверяем, чтобы последняя строчка была последней
            if (dgvRawList.Nodes.Count > 0 && (lastNode == null || !lastNode.IsLastSibling))
            {
                root.Add(new TreeGridNode());
                if (lastNode != null)
                {
                    root.Remove(lastNode);
                }
            }
        }