Beispiel #1
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);
        }
Beispiel #2
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);
                }
            }
        }
Beispiel #3
0
 public DataRaw(DataBase par) : base(par)
 {
     this.BeginUpdate();
     this.Name = "Новая компонента";
     this.EndUpdate(false);
 }
Beispiel #4
0
        public static DataRawStruct LoadFromXml(XmlNode root, DataBase par, DataBaseType curType)
        {
            DataRawStruct curRaw = new DataRawStruct(par);

            curRaw.BeginUpdate();
            curRaw.Id = int.Parse(root.Attributes["id"].Value, CultureInfo.CurrentCulture);
            foreach (XmlNode curRawNode in root.ChildNodes)
            {
                switch (curRawNode.Name)
                {
                case "brutto":
                    curRaw.pBrutto = Convert.ToDecimal(curRawNode.InnerText, CultureInfo.CurrentCulture);
                    break;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                case "normativDoc": curRaw.m_normativDoc = curRawNode.InnerText.ToString(); break;

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

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

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

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

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

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

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

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

                case "name": curRaw.Name = curRawNode.InnerText; break;

                case "inRecept": curRaw.pInRecept = Convert.ToBoolean(curRawNode.InnerText, CultureInfo.CurrentCulture); break;

                case "inSostav": curRaw.pInSostav = Convert.ToBoolean(curRawNode.InnerText, CultureInfo.CurrentCulture); break;
                    //case "quantity": curRaw._quantity = Convert.ToDecimal(curRawNode.InnerText); break;
                }
            }
            curRaw.EndUpdate(false);
            curRaw.IsChanged = false;

            // ищем эту или похожую компоненту в БД
            DataRawStruct ret;

            switch (curType)
            {
            case DataBaseType.RawType:
                ret = Config.DP.FindRaw(curRaw);
                if (ret == null)
                {
                    FormCompare frm = new FormCompare(curRaw, Config.DP.FindSimilarRaw(curRaw), curType);
                    frm.ShowDialog();
                    ret = (DataRawStruct)frm.UserRec;
                }
                break;

            case DataBaseType.ProcessLossType:
                ret = Config.DP.FindProcessLoss(curRaw);
                if (ret == null)
                {
                    FormCompare frm = new FormCompare(curRaw, Config.DP.FindSimilarProcessLoss(curRaw), curType);
                    frm.ShowDialog();
                    ret = (DataRawStruct)frm.UserRec;
                }
                break;

            default:
                throw new NotImplementedException("Не реализовано");
            }

            //ret.Add(curRaw);
            return(ret);
        }
Beispiel #5
0
 public DataRawStruct(DataBase par) : base(par)
 {
 }
 public static DataMicroBiologyIndicator LoadFromXml(XmlNode root, DataBase parent, ReceptVersion ver)
 {
     throw new NotImplementedException();
 }