Esempio n. 1
0
        /// <summary>
        /// загрузка из файла старого формата
        /// </summary>
        /// <param name="curnode"></param>
        /// <param name="par"></param>
        /// <param name="curVer"></param>
        /// <returns></returns>
        private static DataRecept LoadFromXmlVer0(XmlNode curnode, DataBase par, ReceptVersion curVer)
        {
            DataRecept curRec = new DataRecept(par);

            curRec.BeginUpdate();
            XmlNode rootNode = curnode.SelectSingleNode("recept");

            foreach (XmlNode props in rootNode.ChildNodes)
            {
                switch (props.Name)
                {
                case "name": curRec.Name = props.InnerText; break;

                case "number": curRec.Id = int.Parse(props.InnerText, CultureInfo.CurrentCulture); break;

                case "water": curRec._water = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break;

                case "deflect": { curRec._waterPlus  = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture);
                                  curRec._waterMinus = curRec._waterPlus; break; }

                case "description": curRec._design = props.InnerText; break;

                case "poteri": curRec._totalLoss = DataTotalLoss.LoadFromXml(props, curRec, curVer); break;

                case "component": curRec.Components.Add(DataRaw.LoadOneFromXml(props, curRec, curVer)); break;
                }
            }
            curRec.IsChanged = false;
            curRec.EndUpdate(false);
            return(curRec);
        }
Esempio n. 2
0
        /// <summary>
        /// окончание работы со списком
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbName_Leave(object sender, EventArgs e)
        {
            //cbName.Visible = false;

            TreeGridNode  curNode = cbName.Tag as TreeGridNode;
            DataRawStruct curSel  = cbName.SelectedItem as DataRawStruct;

            if (curNode == null || curSel == null)
            {
                return;
            }

            DataRaw curRaw = curNode.Tag as DataRaw;

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

            // определение родительского объекта
            if (curRaw == null && curNode.Parent != null && curNode.Parent.Index >= 0 && curNode.Parent.Tag != null)
            {
                par = curNode.Parent.Tag as DataBase;
            }

            // если
            if (curRaw == null)
            {
                curRaw = new DataRaw(par);
                //curNode.Tag = curRaw;
                //if (curNode.Parent == null)
                //    dgvRawList.Nodes.Add(null, null, null, null, null, null);
                //else
                //    curNode.Parent.Nodes.Add(null, null, null, null, null, null);
            }

            if (curSel != null)
            {
                curRaw.RawStruct = curSel;
            }
            else
            {
                if (curRaw.RawStruct != null)
                {
                    curRaw.RawStruct = null;
                }
            }
            if (curNode.Tag == null)
            {
                par.Components.Add(curRaw);
            }
            //curNode.Selected = true;

            //dgvRawList.EndEdit();
            //dgvRawList.Focus();
        }
Esempio n. 3
0
        /// <summary>
        /// группировка сырья с суммированием количества
        /// </summary>
        /// <returns>ключ=DataRawStruct, значение=DataRaw (заполнено quantity и brutto)</returns>
        internal Hashtable GroupRaws(bool isRecursive)
        {
            Hashtable ret = new Hashtable();

            foreach (DataBase dr in this.Components)
            {
                // если это рецептура полуфабриката
                if (dr is DataRecept)
                {
                    if (isRecursive)
                    {
                        Hashtable curRec = (dr as DataRecept).GroupRaws(isRecursive);
                        foreach (DataRawStruct curRaw in curRec.Keys)
                        {
                            if (!ret.ContainsKey(curRaw))
                            {
                                ret[curRaw] = new DataRaw(null);
                            }
                            (ret[curRaw] as DataRaw).Quantity += (curRec[curRaw] as DataRaw).Quantity;
                            (ret[curRaw] as DataRaw).Brutto   += (curRec[curRaw] as DataRaw).Brutto;
                        }
                    }
                    continue;
                }

                DataRawStruct rawStr = (dr as DataRaw).RawStruct;

                if (rawStr == null)
                {
                    continue;
                }

                Decimal brutto = (dr as DataRaw).Brutto;
                Decimal netto  = (dr as DataRaw).Quantity;
                if (brutto != 0 && netto == 0 && rawStr.Brutto != 0)
                {
                    netto = brutto / rawStr.Brutto;
                }
                if (brutto == 0 && netto != 0 && rawStr.Brutto != 0)
                {
                    brutto = netto * rawStr.Brutto;
                }

                if (!ret.ContainsKey(rawStr))
                {
                    ret[rawStr] = new DataRaw(null);
                }
                (ret[rawStr] as DataRaw).Quantity += netto;
                (ret[rawStr] as DataRaw).Brutto   += brutto;
            }
            return(ret);
        }
Esempio n. 4
0
 /// <summary>
 /// Обработка таблицы после добавления пользователем новых строк
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvRawList_UserAddedRow(object sender, DataGridViewRowEventArgs e)
 {
     foreach (DataGridViewRow dr in dgvRawList.Rows)
     {
         if (dr.IsNewRow || dr.Tag != null)
         {
             continue;
         }
         DataRaw raw = new DataRaw(myData);
         dr.Tag = raw;
         myData.Components.Add(raw);
     }
 }
Esempio n. 5
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());
        }
Esempio n. 6
0
        private void PrintReceptBody(StringBuilder ret, DataRecept rec, int cols)
        {
            foreach (DataBase curRaw in rec.Components)
            {
                if (curRaw is DataRecept)
                {
                    ret.Append("<tr><td colspan=" + cols + " align=\"center\">" + curRaw.Name + "</tr>");
                    PrintReceptBody(ret, (DataRecept)curRaw, cols);
                    //ret.Append("<tr><td> Итого:</tr>");
                    continue;
                }
                DataRaw craw = (DataRaw)curRaw;
                ret.Append("<tr><td>" + craw.Name);
                if (!String.IsNullOrEmpty(craw.Comment))
                {
                    ret.Append(" (" + craw.Comment + ")");
                }
                if (Config.Cfg.ReportIsShowOriginal)
                {
                    ret.Append("<td>" + Math.Round(craw.Brutto, Config.Cfg.Precision));
                    if (craw.Brutto != craw.Quantity)
                    {
                        ret.Append(" / " + Math.Round(craw.Quantity, Config.Cfg.Precision));
                    }
                }

                for (int i = 0; i < Config.Cfg.ReportUseCounts.Count; i++)
                {
                    ret.Append("<td>" + Math.Round(craw.Brutto / rec.CountExit * Config.Cfg.ReportUseCounts[i], Config.Cfg.Precision));
                    if (craw.Brutto != craw.Quantity)
                    {
                        ret.Append(" / " +
                                   Math.Round(craw.Quantity / rec.CountExit * Config.Cfg.ReportUseCounts[i], Config.Cfg.Precision));
                    }
                }

                for (int i = 0; i < Config.Cfg.ReportUseExits.Count; i++)
                {
                    ret.Append("<td>" + Math.Round(craw.Brutto / rec.CalcExitNetto * Config.Cfg.ReportUseExits[i], Config.Cfg.Precision));
                    if (craw.Brutto != craw.Quantity)
                    {
                        ret.Append(" / " +
                                   Math.Round(craw.Quantity / rec.CalcExitNetto * Config.Cfg.ReportUseExits[i], Config.Cfg.Precision));
                    }
                }
                ret.Append("</tr>");
            }
        }
Esempio n. 7
0
        /// <summary>
        /// загрузка данных по сырью из xml файла
        /// </summary>
        /// <param name="root">узел со списком компонент</param>
        /// <param name="par">родительская структура</param>
        /// <returns></returns>
        public static BindingList <DataBase> LoadManyFromXml(XmlNode root, DataBase par, ReceptVersion curVer)
        {
            BindingList <DataBase> ret = new BindingList <DataBase>();

            switch (curVer)
            {
            case ReceptVersion.Version0:
                throw new NotImplementedException("not implemented");

            case ReceptVersion.Version1:
                foreach (XmlNode curNode in root.ChildNodes)
                {
                    if (curNode.Name.Equals("recept"))
                    {
                        ret.Add(DataRecept.LoadFromXml(curNode, par, curVer));
                    }
                    else     // это лист с сырьем
                    {
                        DataRaw curRaw = new DataRaw(par);
                        curRaw.BeginUpdate();
                        foreach (XmlNode curRawNode in curNode.ChildNodes)
                        {
                            switch (curRawNode.Name)
                            {
                            case "quantity": curRaw.Quantity = Convert.ToDecimal(curRawNode.InnerText, CultureInfo.CurrentCulture); break;

                            case "comment": curRaw.Comment = curRawNode.InnerText; break;

                            case "brutto": curRaw.myBrutto = Convert.ToDecimal(curRawNode.InnerText, CultureInfo.CurrentCulture); break;

                            case "rawStruct": curRaw.myRawStruct = DataRawStruct.LoadFromXml(curRawNode, curRaw, DataBaseType.RawType); break;

                            case "processLoss": curRaw.myProcessLoss = DataRawStruct.LoadFromXml(curRawNode, curRaw, DataBaseType.ProcessLossType); break;
                            }
                        }
                        curRaw.EndUpdate(false);
                        curRaw.IsChanged = false;
                        ret.Add(curRaw);
                    }
                }
                break;

            default:
                throw new NotImplementedException("not implemented");
            }
            return(ret);
        }
Esempio n. 8
0
        //public override bool Contains(DataBase child)
        //{
        //    return false;
        //    //throw new Exception("The method or operation is not implemented.");
        //}

        public static DataRaw LoadOneFromXml(XmlNode root, DataBase par, ReceptVersion curVer)
        {
            DataRaw ret = new DataRaw(par);

            ret.BeginUpdate();
            switch (curVer)
            {
            case ReceptVersion.Version0:
                foreach (XmlNode props in root.ChildNodes)
                {
                    switch (props.Name)
                    {
                    case "name": ret.Name = props.InnerText; break;

                    case "number": ret.RawStruct.Id = int.Parse(props.InnerText, CultureInfo.CurrentCulture); break;

                    case "water": ret.RawStruct.Water = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break;

                    case "gir": ret.RawStruct.fat = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break;

                    case "belki": ret.RawStruct.protein = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break;

                    case "sahar": ret.RawStruct.saccharides = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break;

                    case "kkal": ret.RawStruct.Caloric = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break;

                    case "comment": ret.Comment = props.InnerText; break;

                    case "value": ret.Quantity = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break;
                    }
                }
                break;

            case ReceptVersion.Version1:
                throw new NotImplementedException("not implemented");

            default:
                throw new NotImplementedException("not implemented");
            }
            ret.EndUpdate(false);
            ret.IsChanged = false;
            return(ret);
        }
Esempio n. 9
0
        /// <summary>
        /// расчет рецептуры
        /// </summary>
        /// <returns>результаты расчета</returns>
        internal void CalcRecept()
        {
            // инициализация
            this.myCalcProperty = new DataRawStruct(null);
            this.myCalcSumNetto = 0;
            this.myCalcSumSuhie = 0;

            // Потери текущего элемента.
            DataRawStruct prLoss;

            // расчет закладки по количеству и сухим веществам
            foreach (DataBase curRec in Components)
            {
                Decimal       netto  = 0;
                DataRawStruct curRaw = null;

                if (curRec is DataRecept)
                {
                    // расчет вложенной рецептуры
                    DataRecept introRec = (DataRecept)curRec;
                    introRec.CalcRecept();
                    netto  = introRec.CalcSumNetto;
                    curRaw = introRec.CalcProperty;
                    prLoss = new DataRawStruct(null);
                    this.myCalcSumSuhie += introRec.CalcSumSuhie;
                }
                else
                {
                    // Расчет компоненты
                    DataRaw dr = (DataRaw)curRec;
                    netto  = dr.Quantity;
                    curRaw = dr.RawStruct;
                    // если элемент пустой, то пропускаем его
                    if (curRaw == null)
                    {
                        continue;
                    }

                    if (dr.Brutto == 0 && netto != 0 && curRaw.Brutto != 0)
                    {
                        dr.Brutto = netto * curRaw.Brutto;
                    }

                    if (dr.Brutto != 0 && netto == 0 && curRaw.Brutto != 0)
                    {
                        netto = dr.Brutto / curRaw.Brutto;
                    }

                    // если не заданы потери, то создаем пустые (без потерь)
                    if (dr.ProcessLoss != null)
                    {
                        prLoss = dr.ProcessLoss;
                    }
                    else
                    {
                        prLoss = new DataRawStruct(null);
                    }

                    // добавление сухих веществ
                    this.myCalcSumSuhie += netto * (100 - curRaw.Water) * (100 - prLoss.Brutto) / 10000;
                }

                // расчет = сумма (количество, уменьшенное на потерю при термической обработке и умноженное на присутствие
                // исходные данные указаны в % (кроме веса и калорийности)
                this.myCalcSumNetto             += netto * (100 - prLoss.Brutto) / 100;
                this.myCalcProperty.Water       += curRaw.Water * netto * (100 - prLoss.Water) / 10000;
                this.myCalcProperty.Caloric     += curRaw.Caloric * netto * (100 - prLoss.Caloric) / 10000; // калории на 100г., поэтому еще делим и на 100
                this.myCalcProperty.starch      += curRaw.starch * netto * (100 - prLoss.starch) / 10000;
                this.myCalcProperty.saccharides += curRaw.saccharides * netto * (100 - prLoss.saccharides) / 10000;
                this.myCalcProperty.cellulose   += curRaw.cellulose * netto * (100 - prLoss.cellulose) / 10000;
                this.myCalcProperty.cholesterol += curRaw.cholesterol * netto * (100 - prLoss.cholesterol) / 10000;
                this.myCalcProperty.fat         += curRaw.fat * netto * (100 - prLoss.fat) / 10000;
                this.myCalcProperty.acid        += curRaw.acid * netto * (100 - prLoss.acid) / 10000;
                this.myCalcProperty.ash         += curRaw.ash * netto * (100 - prLoss.ash) / 10000;
                this.myCalcProperty.MineralCA   += curRaw.MineralCA * netto * (100 - prLoss.MineralCA) / 10000;
                this.myCalcProperty.MineralFE   += curRaw.MineralFE * netto * (100 - prLoss.MineralFE) / 10000;
                this.myCalcProperty.MineralK    += curRaw.MineralK * netto * (100 - prLoss.MineralK) / 10000;
                this.myCalcProperty.MineralMG   += curRaw.MineralMG * netto * (100 - prLoss.MineralMG) / 10000;
                this.myCalcProperty.MineralNA   += curRaw.MineralNA * netto * (100 - prLoss.MineralNA) / 10000;
                this.myCalcProperty.MineralP    += curRaw.MineralP * netto * (100 - prLoss.MineralP) / 10000;
                this.myCalcProperty.protein     += curRaw.protein * netto * (100 - prLoss.protein) / 10000;
                this.myCalcProperty.vitaminA    += curRaw.vitaminA * netto * (100 - prLoss.vitaminA) / 10000;
                this.myCalcProperty.VitaminB    += curRaw.VitaminB * netto * (100 - prLoss.VitaminB) / 10000;
                this.myCalcProperty.VitaminB1   += curRaw.VitaminB1 * netto * (100 - prLoss.VitaminB1) / 10000;
                this.myCalcProperty.VitaminB2   += curRaw.VitaminB2 * netto * (100 - prLoss.VitaminB2) / 10000;
                this.myCalcProperty.VitaminC    += curRaw.VitaminC * netto * (100 - prLoss.VitaminC) / 10000;
                this.myCalcProperty.VitaminPP   += curRaw.VitaminPP * netto * (100 - prLoss.VitaminPP) / 10000;
            }

            // Расчет по выходу
            if (myIsCalcExit && this.myTotalExit > 0)
            {
                if (this._totalLoss != null)
                {
                    this.myCalcExitSuhie = this.myCalcSumSuhie * (100 - this._totalLoss.Quantity) / 100;
                }
                else
                {
                    this.myCalcExitSuhie = this.myCalcSumSuhie;
                }

                this.myCalcExitNetto = this.myTotalExit;
            }
            else

            // расчет по воде
            if (myIsCalcWater && this.water > 0)
            {
                if (this._totalLoss != null)
                {
                    this.myCalcExitSuhie = this.myCalcSumSuhie * (100 - this._totalLoss.Quantity) / 100;
                }
                else
                {
                    this.myCalcExitSuhie = this.myCalcSumSuhie;
                }

                this.myCalcExitNetto = this.myCalcExitSuhie / (100 - this._water) * 100;
            }
            else

            // расчет воды по выходу и влажности
            if (myIsSetWater && this._water > 0 && this.myTotalExit > 0)
            {
                DataRawStruct waterRaw = Config.DP.GetRawByNum(Config.Cfg.WaterId);
                if (waterRaw == null)
                {
                    throw new InvalidDataException("Не задана вода для расчета в рецептуре");
                }

                if (this._totalLoss != null)
                {
                    this.myCalcExitSuhie = this.myCalcSumSuhie * (100 - this._totalLoss.Quantity) / 100;
                }
                else
                {
                    this.myCalcExitSuhie = this.myCalcSumSuhie;
                }

                this.myCalcExitNetto = this.myTotalExit;
                //decimal waterVal = this.myCalcExitSuhie / (100 - this._water) * 100 - this.myCalcExitNetto;
                throw new NotImplementedException("Дописать расчет воды по выходу и влажности");
            }
            else
            { // Просто без расчета
                this.myCalcExitNetto = this.myCalcSumNetto;
                this.myCalcExitSuhie = this.myCalcSumSuhie;
            }
            if (this.myCalcExitNetto <= 0)
            {
                throw new OverflowException("Выход у рецептуры меньше или равен нулю");
            }

            // пересчет значений в процентах
            this.myCalcProperty.Water       /= this.myCalcExitNetto / 100;
            this.myCalcProperty.Caloric     /= this.myCalcExitNetto / 100;
            this.myCalcProperty.starch      /= this.myCalcExitNetto / 100;
            this.myCalcProperty.saccharides /= this.myCalcExitNetto / 100;
            this.myCalcProperty.cellulose   /= this.myCalcExitNetto / 100;
            this.myCalcProperty.cholesterol /= this.myCalcExitNetto / 100;
            this.myCalcProperty.fat         /= this.myCalcExitNetto / 100;
            this.myCalcProperty.acid        /= this.myCalcExitNetto / 100;
            this.myCalcProperty.ash         /= this.myCalcExitNetto / 100;
            this.myCalcProperty.MineralCA   /= this.myCalcExitNetto / 100;
            this.myCalcProperty.MineralFE   /= this.myCalcExitNetto / 100;
            this.myCalcProperty.MineralK    /= this.myCalcExitNetto / 100;
            this.myCalcProperty.MineralMG   /= this.myCalcExitNetto / 100;
            this.myCalcProperty.MineralNA   /= this.myCalcExitNetto / 100;
            this.myCalcProperty.MineralP    /= this.myCalcExitNetto / 100;
            this.myCalcProperty.protein     /= this.myCalcExitNetto / 100;
            this.myCalcProperty.vitaminA    /= this.myCalcExitNetto / 100;
            this.myCalcProperty.VitaminB    /= this.myCalcExitNetto / 100;
            this.myCalcProperty.VitaminB1   /= this.myCalcExitNetto / 100;
            this.myCalcProperty.VitaminB2   /= this.myCalcExitNetto / 100;
            this.myCalcProperty.VitaminC    /= this.myCalcExitNetto / 100;
            this.myCalcProperty.VitaminPP   /= this.myCalcExitNetto / 100;
        }
Esempio n. 10
0
        /// <summary>
        /// загрузка файла версии программы "2"
        /// </summary>
        /// <param name="curnode">узел дерева XML</param>
        /// <param name="par">родительский объект</param>
        /// <returns>структуру данных рецептуры</returns>
        private static DataRecept LoadFromXmlVer1(XmlNode curnode, DataBase par, ReceptVersion curVer)
        {
            DataRecept curRec = new DataRecept(par);

            curRec.BeginUpdate();
            curRec.Id = int.Parse(curnode.Attributes["id"].Value, CultureInfo.CurrentCulture);
            foreach (XmlNode props in curnode.ChildNodes)
            {
                switch (props.Name)
                {
                case "color": curRec._color = props.InnerText; break;

                case "components": curRec.Components.AddRange(DataRaw.LoadManyFromXml(props, curRec, curVer)); break;

                case "consistence": curRec._consistence = props.InnerText; break;

                case "delivery": curRec._delivery = props.InnerText; break;

                case "design": curRec._design = props.InnerText; break;

                case "extView": curRec._extView = props.InnerText; break;

                case "totalLoss": curRec._totalLoss = DataTotalLoss.LoadFromXml(props, curRec, curVer); break;

                case "process": curRec._process = props.InnerText; break;

                case "sale": curRec._sale = props.InnerText; break;

                case "storage": curRec._storage = props.InnerText; break;

                case "taste": curRec._taste = props.InnerText; break;

                case "water": curRec._water = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break;

                case "waterPlus": curRec._waterPlus = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break;

                case "waterMinus": curRec._waterMinus = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break;

                case "acidity": curRec.myAcidity = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break;

                case "name": curRec.Name = props.InnerText; break;

                case "source": curRec._source = props.InnerText; break;

                case "normativDoc": curRec._normativDoc = props.InnerText; break;

                case "preview": curRec._preview = props.InnerText; break;

                case "quantity": curRec.Quantity = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break;

                case "totalExit": curRec.myTotalExit = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break;

                case "countExit": curRec.myCountExit = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break;

                case "microbiology": curRec.myMicroBiology = DataMicroBiology.LoadFromXml(props, curRec, curVer); break;

                case "isCalcExit": curRec.myIsCalcExit = Convert.ToBoolean(props.InnerText, CultureInfo.CurrentCulture); break;

                case "isCalcWater": curRec.myIsCalcWater = Convert.ToBoolean(props.InnerText, CultureInfo.CurrentCulture); break;

                case "isSetWater": curRec.myIsSetWater = Convert.ToBoolean(props.InnerText, CultureInfo.CurrentCulture); break;
                }
            }
            curRec.IsChanged = false;
            curRec.EndUpdate(false);
            return(curRec);
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
                }
            }
        }