Пример #1
0
        private void AddSelectedComponent()
        {
            if (!(treAvailableComponents.SelectedNode?.Tag is clsNodeData objNodeData) || objNodeData.Level == -1)
            {
                return;
            }

            string   strCategory     = objNodeData.DrugComponent.Category;
            TreeNode nodCategoryNode = treChosenComponents.FindNode("Node_" + strCategory);

            if (nodCategoryNode == null)
            {
                Log.Warn("Unknown category " + strCategory + " in component " + objNodeData.DrugComponent.Name);
                return;
            }

            //prevent adding same component multiple times.
            if (_lstSelectedDrugComponents.Count(c => c.DrugComponent.Name == objNodeData.DrugComponent.Name) >=
                objNodeData.DrugComponent.Limit && objNodeData.DrugComponent.Limit != 0)
            {
                Program.MainForm.ShowMessageBox(this,
                                                LanguageManager.GetString("Message_DuplicateDrugComponentWarning")
                                                .Replace("{0}", objNodeData.DrugComponent.Limit.ToString(GlobalOptions.CultureInfo)));
                return;
            }

            //drug can have only one foundation
            if (objNodeData.DrugComponent.Category == "Foundation")
            {
                if (_lstSelectedDrugComponents.Any(c => c.DrugComponent.Category == "Foundation"))
                {
                    Program.MainForm.ShowMessageBox(this, LanguageManager.GetString("Message_DuplicateDrugFoundationWarning"));
                    return;
                }
            }

            string strSpaceString = LanguageManager.GetString("String_Space");
            string strColonString = LanguageManager.GetString("String_Colon");

            //restriction for maximum level of block (CF 191)
            if (objNodeData.Level + 1 > 2)
            {
                foreach (clsNodeData objFoundationNodeData in _lstSelectedDrugComponents)
                {
                    if (objFoundationNodeData.DrugComponent.Category != "Foundation")
                    {
                        continue;
                    }
                    Dictionary <string, int> dctFoundationAttributes = objFoundationNodeData.DrugComponent.DrugEffects[0].Attributes;
                    Dictionary <string, int> dctBlockAttributes      = objNodeData.DrugComponent.DrugEffects[objNodeData.Level].Attributes;
                    foreach (KeyValuePair <string, int> objItem in dctFoundationAttributes)
                    {
                        if (objItem.Value < 0 &&
                            dctBlockAttributes.TryGetValue(objItem.Key, out int intBlockAttrValue) &&
                            intBlockAttrValue > 0)
                        {
                            string message = new StringBuilder(LanguageManager.GetString("String_MaximumDrugBlockLevel")).
                                             AppendLine().
                                             Append(objFoundationNodeData.DrugComponent.CurrentDisplayName).Append(strColonString).Append(strSpaceString).Append(objItem.Key).Append(objItem.Value.ToString("+#;-#;", GlobalOptions.CultureInfo)).AppendLine().
                                             Append(objNodeData.DrugComponent.CurrentDisplayName).Append(strColonString).Append(strSpaceString).Append(objItem.Key).Append(intBlockAttrValue.ToString("+#;-#;", GlobalOptions.CultureInfo)).
                                             ToString();
                            Program.MainForm.ShowMessageBox(this, message);
                            return;
                        }
                    }
                }
            }


            string strNodeText = objNodeData.DrugComponent.CurrentDisplayName;

            if (objNodeData.DrugComponent.Level <= 0 && objNodeData.DrugComponent.DrugEffects.Count > 1)
            {
                strNodeText += strSpaceString + '(' + LanguageManager.GetString("String_Level") + strSpaceString + (objNodeData.Level + 1).ToString(GlobalOptions.CultureInfo) + ")";
            }
            TreeNode objNewNode = nodCategoryNode.Nodes.Add(strNodeText);

            objNewNode.Tag = objNodeData;
            objNewNode.EnsureVisible();

            _lstSelectedDrugComponents.Add(objNodeData);
            UpdateCustomDrugStats();
            lblDrugDescription.Text = _objDrug.GenerateDescription(0);
        }
Пример #2
0
        private void AddSelectedComponent()
        {
            clsNodeData objNodeData;

            if (treAvailableComponents.SelectedNode?.Tag != null)
            {
                objNodeData = (clsNodeData)treAvailableComponents.SelectedNode.Tag;
            }
            else
            {
                return;
            }

            if (objNodeData.level == -1)
            {
                return;
            }

            int categoryIndex = FindRootNodeIndexForCategory(objNodeData.objDrugComponent.Category);

            if (categoryIndex == -1)
            {
                Log.Warning(string.Format("Uknown category %s in component %s", objNodeData.objDrugComponent.Category, objNodeData.objDrugComponent.Name));
                return;
            }

            //prevent adding same component twice
            if (lstSelectedDrugComponents.Any(c => c.objDrugComponent.Name == objNodeData.objDrugComponent.Name))
            {
                MessageBox.Show(this, LanguageManager.GetString("Message_DuplicateDrugComponentWarning"));
                return;
            }

            //drug can have only one foundation
            if (objNodeData.objDrugComponent.Category == "Foundation")
            {
                if (lstSelectedDrugComponents.Any(c => c.objDrugComponent.Category == "Foundation"))
                {
                    MessageBox.Show(this, LanguageManager.GetString("Message_DuplicateDrugFoundationWarning"));
                    return;
                }
            }

            //restriction for maximum level of block (CF 191)
            if (objNodeData.level + 1 > 2)
            {
                foreach (clsNodeData objFoundationNodeData in lstSelectedDrugComponents)
                {
                    if (objFoundationNodeData.objDrugComponent.Category != "Foundation")
                    {
                        continue;
                    }
                    var dctFoundationAttributes = objFoundationNodeData.objDrugComponent.DrugEffects[0].Attributes;
                    var dctBlockAttributes      = objNodeData.objDrugComponent.DrugEffects[objNodeData.level].Attributes;
                    foreach (var item in dctFoundationAttributes)
                    {
                        if (item.Value < 0 &&
                            dctBlockAttributes.TryGetValue(item.Key, out var blockAttrValue) &&
                            blockAttrValue > 0)
                        {
                            string message = new StringBuilder("The maximum level of a block that positively modifies an Attribute that the chosen foundation negatively modifies is Level 2. (CF 191)").
                                             AppendLine().
                                             Append(objFoundationNodeData.objDrugComponent.Name).Append(": ").Append(item.Key).Append(item.Value.ToString("+#;-#;")).AppendLine().
                                             Append(objNodeData.objDrugComponent.Name).Append(": ").Append(item.Key).Append(blockAttrValue.ToString("+#;-#;")).
                                             ToString();
                            MessageBox.Show(this, message);
                            return;
                        }
                    }
                }
            }


            string nodeText = objNodeData.objDrugComponent.Name;

            if (objNodeData.objDrugComponent.DrugEffects.Count > 1)
            {
                nodeText += " (level " + (objNodeData.level + 1).ToString() + ")";
            }
            TreeNode node = treChoosenComponents.Nodes[categoryIndex].Nodes.Add(nodeText);

            node.Tag = objNodeData;
            node.EnsureVisible();

            lstSelectedDrugComponents.Add(objNodeData);
            UpdateCustomDrugStats();
            lblDrugDescription.Text = _objDrug.GenerateDescription(0);
        }