public static AddMechResult AddMechToFile(MechModel mech)
        {
            AddMechResult result   = AddMechResult.CHASSIS_AND_VARIANT_EXIST;
            FileInfo      fileInfo = new FileInfo(Constants.StaticValues.OwnedMechsFile);
            XDocument     doc      = XDocument.Load(fileInfo.FullName);
            XElement      model    = (from el in doc.Root.Elements(mech.MechClass.ToString().ToLower())
                                      .Elements(StaticValues.XMLMechTag)
                                      where (string)el.Attribute(StaticValues.XMLModelNameTag) == mech.MechModelName
                                      select el)
                                     .FirstOrDefault();

            if (CheckEntryExists(model, mech) == false)
            {
                if (model == null)
                {
                    XElement weightClass = doc.Root.Element(mech.MechClass.ToString().ToLower());

                    weightClass.Add(
                        new XElement(StaticValues.XMLMechTag, new object[] {
                        new XAttribute(StaticValues.XMLMechfactionTag, mech.MechFaction),
                        new XAttribute(StaticValues.XMLWeightIncrementTag, mech.GetMechWeight()),
                        new XAttribute(StaticValues.XMLModelNameTag, mech.MechModelName),
                        new XElement(StaticValues.XMLModelVariantTag, mech.ModelVariantName)
                    }));
                    result = AddMechResult.SUCCESSFULLY_ADDED_NEW_CHASSIS_AND_VARIANT;
                }
                else
                {
                    model.Add(
                        new XElement(StaticValues.XMLModelVariantTag, mech.ModelVariantName));
                    result = AddMechResult.SUCCESSFULLY_ADDED_NEW_VARIANT;
                }

                doc.Save(fileInfo.FullName);
            }
            else
            {
                result = AddMechResult.CHASSIS_AND_VARIANT_EXIST;
            }

            return(result);
        }
Example #2
0
        private void ExistingMechs_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = this.ExistingMechs.SelectedIndex;

            if (index == 0)
            {
                this.NewChassisLabel.Visible = true;
                this.NewChassisName.Visible  = true;
                this.FactionSelector.Enabled = true;

                UpdateWeightClassDropdown(MechClasses.LIGHT);
                this.WeightClassSelector.Enabled = true;
                UpdateWeightIncrement(LightMechWeightIncrements.TWENTY.ToString());
                this.WeightIncrement.Enabled = true;
            }
            else
            {
                this.NewChassisLabel.Visible = false;
                this.NewChassisName.Visible  = false;

                DropDownItem item  = (DropDownItem)ExistingMechs.Items[index];
                MechModel    model = XMLRetriever.PerformChassisLookup(item.DisplayValue, item.Value);

                if (model.MechFaction == Factions.INNER_SPHERE)
                {
                    this.FactionSelector.SelectedIndex = 0;
                    this.FactionSelector.Enabled       = false;
                }
                else
                {
                    this.FactionSelector.SelectedIndex = 1;
                    this.FactionSelector.Enabled       = false;
                }

                UpdateWeightClassDropdown(model.MechClass);
                this.WeightClassSelector.Enabled = false;
                UpdateWeightIncrement(model.GetMechWeight());
                this.WeightIncrement.Enabled = false;
            }
        }