Example #1
0
        //private int[] getAddress(String s)
        //{
        //    if (s == Rabbit.NULL_ADDRESS)
        //        return new int[] { 0, 0, 0 };
        //    for (int i = 0; i < _buildings.Count; i++)
        //        for (int j = 0; j < _buildings[i].Sections; j++)
        //            if (_buildings[i].MedName(j) == s)
        //            {
        //                return new int[] { (int)_buildings[i].Farm, _buildings[i].TierID, j };
        //            }
        //    return null;
        //}

        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex < 0)
            {
                DialogResult = DialogResult.Cancel;
                Close();
                return;
            }
            Address adr = _buildings.SearchByMedName(comboBox1.Text);

            if (adr.Farm == 0)
            {
                DialogResult = DialogResult.Cancel;
                Close();
                return;
            }
            girlOut = r.Clone(1, adr.Farm, adr.Floor, adr.Section);
        }
Example #2
0
        /// <summary>
        /// Добавляет все данные в базу
        /// </summary>
        private void importToBase()
        {
            ///Добавляем породы в базу и переопределяем ID породы у кроликов, относительно текущей базы
            List <KeyValuePair <int, int> > wasBecome = new List <KeyValuePair <int, int> >();

            foreach (ListViewItem lviBreed in lvBreeds.Items)
            {
                if (lviBreed.ForeColor == EXISTS)
                {
                    continue;
                }

                Breed b   = lviBreed.Tag as Breed;
                int   bID = 0;
                if (lviBreed.ForeColor == NOT_EXISTS)
                {
                    if (lviBreed.SubItems[1].Text == "")
                    {
                        bID = Engine.db().AddBreed(b.Name, b.ShortName, "");
                    }
                    else
                    {
                        bID = _breeds.Search(lviBreed.SubItems[1].Text).ID;
                    }
                }
                else if (lviBreed.ForeColor == EXISTS_NOT_ID_MATCH)
                {
                    bID = _breeds.Search(lviBreed.SubItems[0].Text).ID;
                }
                wasBecome.Add(new KeyValuePair <int, int>(b.ID, bID));
            }
            adaptBreed(wasBecome);

            ///добавляем имена и переопределяем ID имен и фамилий относительно текущей базы
            wasBecome = new List <KeyValuePair <int, int> >();
            foreach (ListViewItem lviName in lvNames.Items)
            {
                if (lviName.ForeColor == EXISTS)
                {
                    continue;
                }

                RabName rn  = lviName.Tag as RabName;
                int     nId = 0;
                if (lviName.ForeColor == EXISTS_NOT_ID_MATCH)
                {
                    nId = _names.Search(rn.Name, rn.Sex).ID;
                }
                else if (lviName.ForeColor == NOT_EXISTS)
                {
                    nId = Engine.db().AddName(rn.Sex, rn.Name, rn.Surname);
                }
                wasBecome.Add(new KeyValuePair <int, int>(rn.ID, nId));
            }
            adaptName(wasBecome);

            ///импортируем кроликов
            sortExpRabById();
            foreach (ListViewItem lviRab in lvExportRabbits.Items)
            {
                if (lviRab.ForeColor == IMPORTED_RAB_RAB /*|| lviRab.ForeColor == IMPORTED_RAB_ASC*/)
                {
                    continue;
                }

                OneRabbit r = lviRab.Tag as OneRabbit;
                if (lviRab.SubItems[IMP_NEW_NAME].Text != "")
                {
                    r.NameID = _names.Search(lviRab.SubItems[IMP_NEW_NAME].Text, r.Sex).ID;
                }
                int oldRid = r.ID;
                Engine.db().NewRabbit(r, r.ParentID, r.BirthPlace, _importFileGuid);
                ///селим по назначенный адрес
                Address a = _freeBuildings.SearchByMedName(lviRab.SubItems[IMP_ADDRESS].Text);
                Engine.db().replaceRabbit(r.ID, a.Farm, a.Floor, a.Section);
                Engine.get().logs().log(LogType.REPLACE, r.ID, 0, lviRab.SubItems[IMP_ADDRESS].Text);
                lviRab.ForeColor = IMPORTED_RAB_RAB;
                adaptParent(r, oldRid);
            }

            foreach (ListViewItem lviAsc in lvAscendants.Items)
            {
                if (/*lviAsc.ForeColor == IMPORTED_ASC_RAB ||*/ lviAsc.ForeColor == IMPORTED_ASC_ASC)
                {
                    continue;
                }

                OneRabbit r = lviAsc.Tag as OneRabbit;
                if (lviAsc.ForeColor == IMPORTED_ASC_RAB)
                {
                }
                else
                {
                    Engine.db().ImportAscendant(r);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Сохраняет операции, по пересадке кролика
        /// warning full vachanaliation and analizing troubles
        /// </summary>
        /// <param name="r">Строка кролика</param>
        /// <param name="id"></param>
        /// <param name="allowReplace">Уже перемещен</param>
        private void commitRabbit(RP rp, int id, bool allowReplace)
        {
            if (rp.Saved)
            {
                return;
            }

            if (rp.ID == 0)
            {
                //int[] a = getAddress(rp);
                Address a = _freeBuildings.SearchByMedName(rp.CurAddress);
                _rabERs[_replaceList.IndexOf(rp)].ReplaceRabbit(a.Farm, a.Floor, a.Section, rp.CurAddress);
                rp.Saved = true;
                return;
            }

            RabNetEngRabbit rb  = Engine.get().getRabbit(id == 0 ? rp.ID : id);
            RabNetEngRabbit par = null;

            if (rp.Younger)
            {
                par = Engine.get().getRabbit(rp.Parent);
            }
            if (rp.PlaceTo != null || rp.PlaceWith != null)
            {
                if (!allowReplace)
                {
                    return;
                }

                if (rp.PlaceWith != null)
                {
                    rb.CombineWidth(rp.PlaceWith.ID);
                    rp.Saved = true;
                    return;
                }
                if (rp.PlaceTo != null)
                {
                    rb.PlaceSuckerTo(rp.PlaceTo.ID);
                }
            }

            if (rp.Replaced && !allowReplace)
            {
                //int[] a = getAddress(rp);
                Address a = _freeBuildings.SearchByMedName(rp.CurAddress);
                //if (rp.Younger)
                //par.ReplaceYounger(rb.ID, a.Farm, a.Tier, a.Section, rp.CurAddress);
                //else
                rb.ReplaceRabbit(a.Farm, a.Floor, a.Section, rp.CurAddress);
            }

            if (rp.CanHaveNest)
            {
                if (!rp.Younger || (rp.Younger && rp.Replaced && rp.PlaceTo == null))
                {
                    RabNetEngRabbit   rr  = Engine.get().getRabbit(rb.ID);
                    RabNetEngBuilding rbe = Engine.get().getBuilding(rr.RawAddress);

                    string[] vals = rr.RawAddress.Split(','); ///todo ГОВНОКОД нужно переделывать движок построек
                    //BuildingType tp = Building.ParseType(vals[3]);
                    if (rbe.Type == BuildingType.Jurta || rbe.Type == BuildingType.Female)
                    {
                        rbe.setNest(rp.SetNest, 0);
                    }
                    else if (rbe.Type == BuildingType.DualFemale)
                    {
                        rbe.setNest(rp.SetNest, Int32.Parse(vals[2]));
                    }
                }
            }

            if (rp.NewSex != rp.Sex)
            {
                rb.SetSex(rp.NewSex);
            }

            /// рассаживаем отделеных
            while (rp.Clones.Count > 0)
            {
                RP      c   = rp.Clones[0];
                Address a   = _freeBuildings.SearchByMedName(c.CurAddress);
                int     cid = rb.Clone(c.Count, a.Farm, a.Floor, a.Section);
                c.ID = cid;
                commitRabbit(c, cid, allowReplace);
                if (_action == Action.ONE_GIRL_OUT && _girlout == 0 && c.Sex == Rabbit.SexType.FEMALE && c.Count == 1)
                {
                    _girlout = cid;
                }
                rp.Clones.RemoveAt(0);
            }
            rp.Saved = true;
        }