Esempio n. 1
0
        /// <summary>
        /// Devuelve una lista ordenada de todos los elementos
        /// </summary>
        /// <param name="sortProperty">Campo de ordenación</param>
        /// <param name="sortDirection">Sentido de ordenación</param>
        /// <returns>Lista ordenada de elementos</returns>
        public static SortedBindingList <OutputDeliveryLineInfo> GetSortedList(string sortProperty, ListSortDirection sortDirection)
        {
            SortedBindingList <OutputDeliveryLineInfo> sortedList = new SortedBindingList <OutputDeliveryLineInfo>(GetList());

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 2
0
        public void AscendingSort()
        {
            int[] intArr = { 45, 23, 57, 56, 11, 87, 94, 44 };
            SortedBindingList <int> sortedList = new SortedBindingList <int>(intArr);

            sortedList.ListChanged += new ListChangedEventHandler(sortedList_ListChanged);

            Assert.AreEqual(false, sortedList.IsSorted);
            Assert.AreEqual(56, intArr[3]);
            sortedList.ApplySort("", ListSortDirection.Ascending);
            Assert.AreEqual(44, sortedList[2]);
            Assert.AreEqual(8, sortedList.Count);
            Assert.AreEqual(true, sortedList.Contains(56));
            Assert.AreEqual(4, sortedList.IndexOf(56));
            Assert.AreEqual(true, sortedList.IsReadOnly);
            Assert.AreEqual(true, sortedList.IsSorted);

            foreach (int item in sortedList)
            {
                Console.WriteLine(item.ToString());
            }

            sortedList.RemoveSort();
            Assert.AreEqual(false, sortedList.IsSorted);
            Assert.AreEqual(56, sortedList[3]);

            // This list dowes not support searching
            Assert.IsFalse(sortedList.SupportsSearching);
            // and Find should return -1 because underlying list dows not implement IBindingList
            Assert.AreEqual(-1, sortedList.Find("", 56));
        }
        /// <summary>
        /// Devuelve una lista ordenada de todos los elementos y sus hijos
        /// </summary>
        /// <param name="sortProperty">Campo de ordenación</param>
        /// <param name="sortDirection">Sentido de ordenación</param>
        /// <param name="childs">Traer hijos</param>
        /// <returns>Lista ordenada de elementos</returns>
        public static SortedBindingList <InformePlantillaInfo> GetSortedList(string sortProperty, ListSortDirection sortDirection, bool childs)
        {
            SortedBindingList <InformePlantillaInfo> sortedList = new SortedBindingList <InformePlantillaInfo>(GetList());

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 4
0
        public void ApplySort_ThrowException_WhenPropertyNameNotFound()
        {
            int[] intArray = { 5, 7, 1, 3, 5, 44, 32 };
            SortedBindingList <int> sortedList = new SortedBindingList <int>(intArray);

            sortedList.ApplySort("NotAProperty", ListSortDirection.Ascending);
        }
Esempio n. 5
0
        /// <summary>
        /// Devuelve una lista ordenada y filtrada a partir de los datos de la lista
        /// actual
        /// </summary>
        /// <param name="criteria">Filtro</param>
        /// <param name="sortProperty">Campo de ordenación</param>
        /// <param name="sortDirection">Sentido de ordenación</param>
        /// <returns>Lista ordenada</returns>
        public SortedBindingList <C> GetSortedSubList(FCriteria criteria,
                                                      string sortProperty,
                                                      ListSortDirection sortDirection)
        {
            List <C> list = new List <C>();

            SortedBindingList <C> sortedList = new SortedBindingList <C>(list);

            if (Items.Count == 0)
            {
                return(sortedList);
            }

            PropertyDescriptor property = TypeDescriptor.GetProperties(Items[0]).Find(criteria.GetProperty(), false);

            foreach (C item in Items)
            {
                foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item))
                {
                    if (prop.Name == property.Name)
                    {
                        object value = prop.GetValue(item);
                        if (value.ToString().ToLower().Contains(criteria.GetValue().ToString().ToLower()))
                        {
                            sortedList.Add(item);
                        }
                        break;
                    }
                }
            }

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 6
0
        public SortedBindingList <C> GetSortedSubList(FCriteria criteria, string sortProperty, ListSortDirection sortDirection)
        {
            SortedBindingList <C> sortedList = GetSortedSubList(criteria);

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 7
0
        public static SortedBindingList <OutputDeliveryInfo> GetSortedList(string sortProperty, ListSortDirection sortDirection, bool childs)
        {
            SortedBindingList <OutputDeliveryInfo> sortedList = new SortedBindingList <OutputDeliveryInfo>(GetList(childs, ETipoEntidad.Cliente));

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 8
0
        public void AddThenSort()
        {
            var cut          = new SortedBindingList <Data>();
            var raisedEvents = new List <ListChangedEventArgs>();

            cut.ListChanged += (s, e) => raisedEvents.Add(e);

            var datas = AddData(cut, 5);

            const string            propertyName = nameof(Data.Name);
            const ListSortDirection direction    = ListSortDirection.Ascending;

            cut.ApplySort(propertyName, direction);

            var sorted = datas.OrderBy(d => d.Name).ToArray();
            var last   = raisedEvents.Last();

            Assert.AreEqual(datas.Length, cut.Count);
            for (var i = 0; i < datas.Length; i++)
            {
                Assert.AreEqual(sorted[i], cut[i]);
            }
            Assert.IsTrue(cut.IsSorted);
            Assert.AreEqual(propertyName, cut.SortProperty.Name);
            Assert.AreEqual(direction, cut.SortDirection);
            Assert.AreEqual(ListChangedType.Reset, last.ListChangedType);
        }
Esempio n. 9
0
        public SortedBindingList <C> GetSortedList(string sortProperty, ListSortDirection sortDirection)
        {
            SortedBindingList <C> sorted_list = new SortedBindingList <C>(this);

            sorted_list.ApplySort(sortProperty, sortDirection);
            return(sorted_list);
        }
Esempio n. 10
0
        /// <summary>
        /// Devuelve una lista ordenada de todos los elementos y sus hijos
        /// </summary>
        /// <param name="sortProperty">Campo de ordenación</param>
        /// <param name="sortDirection">Sentido de ordenación</param>
        /// <param name="childs">Traer hijos</param>
        /// <returns>Lista ordenada de elementos</returns>
        public static SortedBindingList <AlumnoClienteInfo> GetSortedList(string sortProperty, ListSortDirection sortDirection, bool childs)
        {
            SortedBindingList <AlumnoClienteInfo> sortedList = new SortedBindingList <AlumnoClienteInfo>(GetList(childs));

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 11
0
        /// <summary>
        /// Devuelve una lista ordenada de todos los elementos
        /// </summary>
        /// <param name="sortProperty">Campo de ordenación</param>
        /// <param name="sortDirection">Sentido de ordenación</param>
        /// <returns>Lista ordenada de elementos</returns>
        public static SortedBindingList <ImpuestoInfo> GetSortedList(string sortProperty, ListSortDirection sortDirection)
        {
            SortedBindingList <ImpuestoInfo> sortedList = new SortedBindingList <ImpuestoInfo>(GetList());

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 12
0
        public void AscendingSort()
        {
            int[] intArr = { 45, 23, 57, 56, 11, 87, 94, 44 };
            SortedBindingList<int> sortedList = new SortedBindingList<int>(intArr);
            sortedList.ListChanged += new ListChangedEventHandler(sortedList_ListChanged);

            Assert.AreEqual(false, sortedList.IsSorted);
            Assert.AreEqual(56, intArr[3]);
            sortedList.ApplySort("", ListSortDirection.Ascending);
            Assert.AreEqual(44, sortedList[2]);
            Assert.AreEqual(8, sortedList.Count);
            Assert.AreEqual(true, sortedList.Contains(56));
            Assert.AreEqual(4, sortedList.IndexOf(56));
            Assert.AreEqual(true, sortedList.IsReadOnly);
            Assert.AreEqual(true, sortedList.IsSorted);

            foreach (int item in sortedList)
            {
                Console.WriteLine(item.ToString());
            }

            sortedList.RemoveSort();
            Assert.AreEqual(false, sortedList.IsSorted);
            Assert.AreEqual(56, sortedList[3]);

            // This list dowes not support searching
            Assert.IsFalse(sortedList.SupportsSearching);
            // and Find should return -1 because underlying list dows not implement IBindingList
            Assert.AreEqual(-1, sortedList.Find("", 56));
        }
Esempio n. 13
0
        /// <summary>
        /// Devuelve una lista ordenada de todos los elementos y sus hijos
        /// </summary>
        /// <param name="sortProperty">Campo de ordenación</param>
        /// <param name="sortDirection">Sentido de ordenación</param>
        /// <param name="childs">Traer hijos</param>
        /// <returns>Lista ordenada de elementos</returns>
        public static SortedBindingList <RegistroDisponibilidadInfo> GetSortedList(DateTime fecha_inicio, string sortProperty, ListSortDirection sortDirection, bool childs)
        {
            SortedBindingList <RegistroDisponibilidadInfo> sortedList = new SortedBindingList <RegistroDisponibilidadInfo>(GetList(fecha_inicio, childs));

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 14
0
        /// <summary>
        /// Devuelve una lista ordenada de todos los elementos
        /// </summary>
        /// <param name="sortProperty">Campo de ordenación</param>
        /// <param name="sortDirection">Sentido de ordenación</param>
        /// <returns>Lista ordenada de elementos</returns>
        public static SortedBindingList <PreguntaInfo> GetSortedList(string sortProperty,
                                                                     ListSortDirection sortDirection)
        {
            SortedBindingList <PreguntaInfo> sortedList =
                new SortedBindingList <PreguntaInfo>(GetList(false));

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 15
0
        /// <summary>
        /// Devuelve una lista ordenada de todos los elementos
        /// </summary>
        /// <param name="sortProperty">Campo de ordenación</param>
        /// <param name="sortDirection">Sentido de ordenación</param>
        /// <returns>Lista ordenada de elementos</returns>
        public static SortedBindingList <SchemaUserInfo> GetSortedList(string sortProperty,
                                                                       ListSortDirection sortDirection)
        {
            SortedBindingList <SchemaUserInfo> sortedList =
                new SortedBindingList <SchemaUserInfo>(GetChildList());

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
        /// <summary>
        /// Devuelve una lista ordenada de todos los elementos
        /// </summary>
        /// <param name="sortProperty">Campo de ordenación</param>
        /// <param name="sortDirection">Sentido de ordenación</param>
        /// <returns>Lista ordenada de elementos</returns>
        public static SortedBindingList <NotificacionInternaInfo> GetSortedList(string sortProperty,
                                                                                ListSortDirection sortDirection)
        {
            SortedBindingList <NotificacionInternaInfo> sortedList =
                new SortedBindingList <NotificacionInternaInfo>(GetList());

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 17
0
        /// <summary>
        /// Devuelve una lista ordenada de todos los elementos
        /// </summary>
        /// <param name="sortProperty">Campo de ordenación</param>
        /// <param name="sortDirection">Sentido de ordenación</param>
        /// <returns>Lista ordenada de elementos</returns>
        public static SortedBindingList <IncidenciaSesionCronogramaInfo> GetSortedList(string sortProperty,
                                                                                       ListSortDirection sortDirection)
        {
            SortedBindingList <IncidenciaSesionCronogramaInfo> sortedList =
                new SortedBindingList <IncidenciaSesionCronogramaInfo>(GetList());

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 18
0
        /// <summary>
        /// Ordena una lista
        /// </summary>
        /// <param name="list">Lista a ordenar</param>
        /// <param name="sortProperty">Campo de ordenación</param>
        /// <param name="sortDirection">Sentido de ordenación</param>
        /// <returns>Lista ordenada</returns>
        public static SortedBindingList <C> SortList(BusinessListBaseEx <T, C> list,
                                                     string sortProperty,
                                                     ListSortDirection sortDirection)
        {
            SortedBindingList <C> sortedList = new SortedBindingList <C>(list);

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 19
0
        /// <summary>
        /// Devuelve una lista ordenada de todos los elementos
        /// </summary>
        /// <param name="sortProperty">Campo de ordenación</param>
        /// <param name="sortDirection">Sentido de ordenación</param>
        /// <returns>Lista ordenada de elementos</returns>
        public static SortedBindingList <Submodulo_InstructorInfo> GetSortedList(string sortProperty,
                                                                                 ListSortDirection sortDirection)
        {
            SortedBindingList <Submodulo_InstructorInfo> sortedList =
                new SortedBindingList <Submodulo_InstructorInfo>(GetList());

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 20
0
        public void SimulateDataBindingAdd()
        {
            var source = Csla.DataPortal.Create <MyChildren>();

            source.BeginEdit();
            var sorted = new SortedBindingList <MyChild>(source);

            sorted.ApplySort(MyChild.NameProperty.Name, ListSortDirection.Ascending);
            var current = source.AddNew();

            current.BeginEdit();
            current.CancelEdit();
            source.CancelEdit();
        }
Esempio n. 21
0
        public SelectInputForm(List <Currency> list)
            : base(true)
        {
            InitializeComponent();

            _currencies = new SortedBindingList <Currency>(list);
            _currencies.ApplySort("Name", ListSortDirection.Ascending);

            _tipo = typeof(Currency);

            this.Text = Resources.Labels.SELECT_CURRENCY_TITLE;

            SetFormData();
        }
        public static SortedBindingList <ExpedientInfo> GetSortedListByYear(bool childs, ETipoExpediente t, int ano, string sortProperty, ListSortDirection sortDirection)
        {
            CriteriaEx criteria = Expedient.GetCriteria(Expedient.OpenSession());

            criteria.Childs = childs;

            criteria.Query = ExpedienteList.SELECT_BY_TYPE_AND_YEAR(t, ano);

            ExpedienteList list = DataPortal.Fetch <ExpedienteList>(criteria);

            CloseSession(criteria.SessionCode);

            SortedBindingList <ExpedientInfo> sortedList = new SortedBindingList <ExpedientInfo>(list);

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 23
0
        public void EnumerateSorted()
        {
            var cut = new SortedBindingList <Data>();

            var datas = AddData(cut, 6);

            cut.ApplySort(nameof(Data.Name), ListSortDirection.Ascending);
            var sorted = datas.OrderBy(d => d.Name).ToArray();

            Assert.AreEqual(sorted.Length, cut.Count);

            var i = 0;

            foreach (var item in cut)
            {
                Assert.AreEqual(sorted[i++], item);
            }
        }
Esempio n. 24
0
        public void IndexOf()
        {
            List <string> list = new List <string>();

            string barney  = "Barney";
            string charlie = "Charlie";
            string zeke    = "Zeke";

            list.AddRange(new string[] { charlie, barney, zeke });

            SortedBindingList <string> sortedList = new SortedBindingList <string>(list);

            Assert.AreEqual(1, sortedList.IndexOf(barney), "Unsorted index should be 1");

            sortedList.ApplySort(string.Empty, System.ComponentModel.ListSortDirection.Ascending);

            Assert.AreEqual(1, sortedList.IndexOf(charlie), "Sorted index should be 1");
        }
Esempio n. 25
0
        public void AddSorted()
        {
            var cut          = new SortedBindingList <Data>();
            var raisedEvents = new List <ListChangedEventArgs>();

            cut.ListChanged += (s, e) => raisedEvents.Add(e);

            cut.ApplySort(nameof(Data.Name), ListSortDirection.Ascending);

            var datas = AddData(cut, 3);

            var sorted = datas.OrderBy(d => d.Name).ToArray();

            Assert.AreEqual(datas.Length, cut.Count);
            for (var i = 0; i < datas.Length; i++)
            {
                Assert.AreEqual(sorted[i], cut[i]);
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Devuelve una lista ordenada a partir de los datos de la lista
        /// </summary>
        /// <param name="sortProperty"></param>
        /// <param name="sortDirection"></param>
        /// <returns></returns>
        public SortedBindingList <C> ToSortedList(string sortProperty,
                                                  ListSortDirection sortDirection)
        {
            List <C> list = new List <C>();

            SortedBindingList <C> sortedList = new SortedBindingList <C>(list);

            if (Items.Count == 0)
            {
                return(sortedList);
            }

            foreach (C item in Items)
            {
                sortedList.Add(item);
            }

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 27
0
        public void CopyTo()
        {
            int[] intArray = { 5, 7, 1, 3, 5, 44, 32 };
            SortedBindingList <int> sortedList = new SortedBindingList <int>(intArray);

            int[] intArray2 = { 3, 75, 1222, 3333, 511, 443, 332 };

            Assert.AreEqual(1222, intArray2[2]);

            sortedList.ApplySort("", ListSortDirection.Descending);
            Assert.AreEqual(44, sortedList[0], "Sorted values incorrect");

            sortedList.CopyTo(intArray2, 0);

            Assert.AreEqual(44, intArray2[0], "Copied values incorrect");
            Assert.AreEqual(7, intArray2[2], "Copied values incorrect");

            foreach (int item in intArray2)
            {
                Console.WriteLine(item.ToString());
            }
        }
Esempio n. 28
0
        public void DescendingSort()
        {
            string[] strArr = { "zandy", "alex", "Chris", "bert", "alfred", "Bert", "Jimmy", "chris", "chris", "mobbit", "myper", "Corey", "Monkey" };
            SortedBindingList <string> sortedList = new SortedBindingList <string>(strArr);

            Assert.AreEqual("Bert", sortedList[5]);

            sortedList.ApplySort("", ListSortDirection.Descending);

            foreach (string item in sortedList)
            {
                Console.WriteLine(item);
            }

            for (int i = 0; i < sortedList.Count; i++)
            {
                Console.WriteLine("regular loop: " + sortedList[i]);
            }

            Assert.AreEqual("Corey", sortedList[5]);

            Console.WriteLine();
            Console.WriteLine(sortedList.Count);
        }
Esempio n. 29
0
        public void DescendingSort()
        {
            string[] strArr = { "zandy", "alex", "Chris", "bert", "alfred", "Bert", "Jimmy", "chris", "chris", "mobbit", "myper", "Corey", "Monkey" };
            SortedBindingList<string> sortedList = new SortedBindingList<string>(strArr);

            Assert.AreEqual("Bert", sortedList[5]);

            sortedList.ApplySort("", ListSortDirection.Descending);

            foreach (string item in sortedList)
            {
                Console.WriteLine(item);
            }

            for (int i = 0; i < sortedList.Count; i++)
            {
                Console.WriteLine("regular loop: " + sortedList[i]);
            }

            Assert.AreEqual("Corey", sortedList[5]);

            Console.WriteLine();
            Console.WriteLine(sortedList.Count);
        }
        private void SaveAttack()
        {
            using (SqlConnection cn = new SqlConnection( Database.AphelionTriggerConnection ))
            {
                cn.Open();

                ATConfiguration config = ATConfiguration.Instance;

                #region 4. Save Casualties
                foreach (Unit unit in _defenderForces)
                {
                    if (unit.Casualties > 0)
                    {
                        using (SqlCommand cm = cn.CreateCommand())
                        {
                            cm.CommandType = CommandType.StoredProcedure;
                            cm.CommandText = "AddCasualties";
                            cm.Parameters.AddWithValue( "@HouseID", _defenderHouse.ID );
                            cm.Parameters.AddWithValue( "@UnitID", unit.ID );
                            cm.Parameters.AddWithValue( "@Casualties", unit.Casualties );
                            cm.ExecuteNonQuery();

                            _description.Add( "You killed " + unit.Casualties.ToString() + " " + (unit.Casualties > 1 ? Pluralize( unit.Name ) : unit.Name) + "." );
                        }
                    }
                }

                foreach (Unit unit in _attackerForces)
                {
                    if (unit.Casualties > 0)
                    {
                        using (SqlCommand cm = cn.CreateCommand())
                        {
                            cm.CommandType = CommandType.StoredProcedure;
                            cm.CommandText = "AddCasualties";
                            cm.Parameters.AddWithValue( "@HouseID", _attackerHouse.ID );
                            cm.Parameters.AddWithValue( "@UnitID", unit.ID );
                            cm.Parameters.AddWithValue( "@Casualties", unit.Casualties );
                            cm.ExecuteNonQuery();

                            _description.Add( "You lost " + unit.Casualties.ToString() + " " + (unit.Casualties > 1 ? Pluralize( unit.Name ) : unit.Name) + "." );
                        }
                    }
                }
                #endregion

                #region 5. Calculate plundered credits

                int totalPlunder = 0;
                int plunder = 0;

                foreach (Unit unit in _attackerForces)
                {
                    // subtract casualties to make sure only surviving units plunder
                    totalPlunder += ((unit.Plunder + unit.PlunderTech) * (unit.Count - unit.Casualties));
                }

                // only calculate plunder if necessary
                if ( totalPlunder > 0 )
                {
                    // if attacker is a faction leader, add appropirate bonus
                    if ( _attackerHouse.FactionLeaderHouseID == _attackerHouse.ID ) { totalPlunder += Convert.ToInt32( totalPlunder * config.FactionLeaderBonus ); }

                    // modify stat totals on the basis of house contingency characteristics
                    Random plunderRandom = new Random();
                    int attackerContingencyRange = (int)( config.ContingencyFactor * ( _attackerHouse.Contingency / 100 ) );
                    int attackerContingency = plunderRandom.Next( -attackerContingencyRange, attackerContingencyRange );
                    totalPlunder += ( totalPlunder * ( attackerContingency / 100 ) );

                    double percentPlundered = ( (double)totalPlunder / 40 ) * 0.01;

                    // modify total plunder total by the attacker house's ambition
                    percentPlundered = ( percentPlundered * ( ( _attackerHouse.Ambition * 0.0025 ) + 0.75 ) );

                    // cap the ammount of credits that can be plundered at 10%
                    if ( percentPlundered > 0.1 ) percentPlundered = 0.1;

                    using ( SqlCommand cm = cn.CreateCommand() )
                    {
                        cm.CommandType = CommandType.StoredProcedure;
                        cm.CommandText = "Plunder";
                        cm.Parameters.AddWithValue( "@PlundererHouseID", _attackerHouse.ID );
                        cm.Parameters.AddWithValue( "@PlunderedHouseID", _defenderHouse.ID );
                        cm.Parameters.AddWithValue( "@PlunderPercent", percentPlundered );
                        SqlParameter param = new SqlParameter( "@Plunder", SqlDbType.Int );
                        param.Direction = ParameterDirection.Output;
                        cm.Parameters.Add( param );
                        cm.ExecuteNonQuery();

                        plunder = (int)cm.Parameters["@Plunder"].Value;
                    }

                    _description.Add( "You seized " + plunder.ToString() + " credits." );
                }

                #endregion

                #region 6. Calculate captured militia

                int totalCapture = 0;
                int totalCaptured = 0;

                foreach (Unit unit in _attackerForces)
                {
                    // subtract casualties to make sure only surviving units capture
                    totalCapture += ((unit.Capture + unit.CaptureTech) * (unit.Count - unit.Casualties));
                }

                // only calculate capture if necessary
                if ( totalCapture > 0 )
                {
                    // if attacker is a faction leader, add appropirate bonus
                    totalCapture = (int)_attackerHouse.ApplyFactionLeaderBonus( totalCapture );

                    // modify stat totals on the basis of house contingency characteristics
                    Random captureRandom = new Random();
                    int attackerContingencyRange = (int)( config.ContingencyFactor * ( _attackerHouse.Contingency / 100 ) );
                    int attackerContingency = captureRandom.Next( -attackerContingencyRange, attackerContingencyRange );
                    totalCapture += ( totalCapture * ( attackerContingency / 100 ) );

                    double percentCaptured = ( (double)totalCapture / config.CaptureDivisor ) * config.CaptureFactor;

                    // finally, modify total capture total by the attacker house's ambition
                    percentCaptured = (int)( percentCaptured * ( ( _attackerHouse.Ambition * 0.0025 ) + 0.75 ) );

                    // cap the ammount of militia that can be captured at CaptureCap
                    if ( percentCaptured > config.CaptureCap ) percentCaptured = config.CaptureCap;

                    int totalCaptureableUnits = 0;
                    foreach ( Unit unit in _defenderForces )
                    {
                        // substract casualties to make sure only surviving units are capture
                        if ( unit.UnitClassID == 1 ) totalCaptureableUnits += ( unit.Count - unit.Casualties );
                    }

                    int captureCount = (int)( percentCaptured * totalCaptureableUnits );

                    // ensure that if any percentage of units is to be captured, at least one will always be captured
                    if ( percentCaptured > 0 && captureCount == 0 ) captureCount = 1;

                    SortedBindingList<Unit> sortedList = new SortedBindingList<Unit>( _defenderForces );
                    sortedList.ApplySort( "Cost", ListSortDirection.Ascending );

                    int cheapestMilitiaId = GetCheapestMilitiaID( _attackerForces );

                    // go through defender forces until all captures are made
                    foreach ( Unit unit in sortedList )
                    {
                        // skip non-militia
                        if ( unit.UnitClassID != 1 ) continue;

                        // capture as many units as possible each iteration of the loop
                        int captured = captureCount;
                        if ( captured > unit.Count - unit.Casualties ) captured = ( unit.Count - unit.Casualties );

                        using ( SqlCommand cm = cn.CreateCommand() )
                        {
                            cm.CommandType = CommandType.StoredProcedure;
                            cm.CommandText = "Capture";
                            cm.Parameters.AddWithValue( "@CapturerHouseID", _attackerHouse.ID );
                            cm.Parameters.AddWithValue( "@CapturedHouseID", _defenderHouse.ID );
                            cm.Parameters.AddWithValue( "@CapturedUnitID", unit.ID );
                            cm.Parameters.AddWithValue( "@Captured", captured );
                            cm.ExecuteNonQuery();

                            if ( captured > 0 ) _description.Add( "You captured " + captured.ToString() + " " + unit.Name + "." );
                            captureCount -= captured;
                            totalCaptured += captured;
                        }
                        if ( captureCount <= 0 ) break;
                    }
                }

                #endregion

                #region 7. Calculate Stun

                int totalStun = 0;
                int stun = 0;

                foreach ( Unit unit in _attackerForces )
                {
                    // subtract casualties to make sure only surviving units stun
                    totalStun += ( ( unit.Stun + unit.StunTech ) * ( unit.Count - unit.Casualties ) );
                }

                // only calculate stun if necessary
                if ( totalStun > 0 )
                {
                    // if attacker is a faction leader, add appropirate bonus
                    if ( _attackerHouse.FactionLeaderHouseID == _attackerHouse.ID ) { totalStun += Convert.ToInt32( totalStun * config.FactionLeaderBonus ); }

                    // modify stat totals on the basis of house contingency characteristics
                    Random stunRandom = new Random();
                    int attackerContingencyRange = (int)( config.ContingencyFactor * ( _attackerHouse.Contingency / 100 ) );
                    int attackerContingency = stunRandom.Next( -attackerContingencyRange, attackerContingencyRange );
                    totalStun += ( totalStun * ( attackerContingency / 100 ) );

                    double percentStunned = ( (double)totalStun / 40 ) * 0.001;

                    // cap the ammount of turns that can be stunned at 8%
                    if ( percentStunned > 0.08 ) percentStunned = 0.08;

                    using ( SqlCommand cm = cn.CreateCommand() )
                    {
                        cm.CommandType = CommandType.StoredProcedure;
                        cm.CommandText = "Stun";
                        cm.Parameters.AddWithValue( "@HouseID", _defenderHouse.ID );
                        cm.Parameters.AddWithValue( "@StunPercent", percentStunned );
                        SqlParameter param = new SqlParameter( "@Stun", SqlDbType.Int );
                        param.Direction = ParameterDirection.Output;
                        cm.Parameters.Add( param );
                        cm.ExecuteNonQuery();

                        stun = (int)cm.Parameters["@Stun"].Value;
                    }

                    _description.Add( "You stunned your enemy for " + stun.ToString() + " turns." );
                }
                #endregion

                #region 8. Update Ambition
                // the attacker gains or looses ambition based on how much of a percentage lower
                // or higher the defender is ranked vs. the attacker.
                int lowestRank = HouseList.GetHouseList().LowestRank;

                double attackerRankPercent = 100.0 - ( ( _attackerHouse.Rank / (double)lowestRank ) * 100.0 );
                double defenderRankPercent = 100.0 - ( ( _defenderHouse.Rank / (double)lowestRank ) * 100.0 );

                //// no attacker may gain or loose more than 25% ambition in one attack
                int ambitionChangeValue = (int)( defenderRankPercent - attackerRankPercent ) / 4;

                if ( _attackerHouse.Ambition + ambitionChangeValue > 100 ) ambitionChangeValue = 0;
                if ( _attackerHouse.Ambition + ambitionChangeValue < 1 ) ambitionChangeValue = 0;

                if (ambitionChangeValue != 0)
                {
                    using (SqlCommand cm = cn.CreateCommand())
                    {
                        cm.CommandType = CommandType.Text;
                        cm.CommandText = "UPDATE bbgHouses SET Ambition = Ambition + " + ambitionChangeValue.ToString() + " WHERE ID = " + _attackerHouse.ID.ToString();
                        cm.ExecuteNonQuery();
                    }

                    if (Math.Abs( ambitionChangeValue ) == ambitionChangeValue)
                    {
                        _description.Add( "Your ambition improved by " + ambitionChangeValue.ToString() + "." );
                    }
                    else
                    {
                        _description.Add( "Your ambition worsened by " + ambitionChangeValue.ToString() + "." );
                    }
                }
                #endregion

                #region 9. Update Experience
                int experience = 0;
                foreach (Unit unit in _defenderForces)
                {
                    if ( unit.Casualties > 0 ) experience += ( ( unit.Experience + unit.ExperienceTech ) * unit.Casualties );
                }

                // only advance if experience was gained AND user isn't already at level the level cap
                if (experience > 0 && _attackerHouse.Level.Rank < config.LevelCap)
                {
                    Level.UpdateExperience( _attackerHouse, experience );
                    _description.Add( "You gained " + experience + " experience." );

                    // TODO: right now this will cause weird problems if enough exp to advance more than one level is gained at once
                    if (_attackerHouse.Experience + experience >= _attackerHouse.NextLevel.Experience)
                    {
                        _description.Add( "You advanced to level " + _attackerHouse.NextLevel.Rank.ToString() + "." );

                        // add level advancement
                        Advancement advancement = Advancement.NewAdvancement();
                        advancement.HouseID = _attackerHouse.ID;
                        advancement.LevelID = _attackerHouse.NextLevel.ID;
                        advancement.Save();

                        // add leveling report
                        AphelionTrigger.Library.Report report = Report.NewReport();
                        report.FactionID = _attackerHouse.FactionID;
                        report.GuildID = _attackerHouse.GuildID;
                        report.HouseID = _attackerHouse.ID;
                        report.Message = "House " + _attackerHouse.Name + " gained a level.";
                        report.ReportLevelID = 1 + House.GetSecrecyBonus( _attackerHouse.Intelligence );
                        report.Save();
                    }
                }

                #endregion

                #region 10. Add Attack
                int totalAttackerCasualties = 0;
                foreach (Unit unit in _attackerForces)
                    totalAttackerCasualties += unit.Casualties;

                int totalDefenderCasualties = 0;
                foreach (Unit unit in _defenderForces)
                    totalDefenderCasualties += unit.Casualties;

                Attack attack = AphelionTrigger.Library.Attack.NewAttack();
                attack.AttackerHouseID = _attackerHouse.ID;
                attack.DefenderHouseID = _defenderHouse.ID;
                attack.Captured = totalCaptured;
                attack.Plundered = plunder;
                attack.Stunned = stun;
                attack.AttackerCasualties = totalAttackerCasualties;
                attack.DefenderCasualties = totalDefenderCasualties;

                StringBuilder description = new StringBuilder();
                foreach (string s in _description)
                    description.AppendFormat( "{0}<br/>", s );

                attack.Description = description.ToString();

                attack.Save();

                AttackID = attack.ID;

                // decrement the attacker's turns that were expended in the attack
                House.UpdateTurns( _attackerHouse.ID, -1 );
                #endregion
            }
        }
Esempio n. 31
0
        public void CopyTo()
        {
            int[] intArray = { 5, 7, 1, 3, 5, 44, 32 };
            SortedBindingList<int> sortedList = new SortedBindingList<int>(intArray);

            int[] intArray2 = { 3, 75, 1222, 3333, 511, 443, 332 };

            Assert.AreEqual(1222, intArray2[2]);

            sortedList.ApplySort("", ListSortDirection.Descending);
            Assert.AreEqual(44, sortedList[0], "Sorted values incorrect");

            sortedList.CopyTo(intArray2, 0);

            Assert.AreEqual(44, intArray2[0], "Copied values incorrect");
            Assert.AreEqual(7, intArray2[2], "Copied values incorrect");

            foreach (int item in intArray2)
            {
                Console.WriteLine(item.ToString());
            }
        }
    private Csla.SortedBindingList<Challenge> GetChallengeList()
    {
        object businessObject = Session["CurrentObject"];
        if ( businessObject == null || !( businessObject is ChallengeList ) )
        {
            businessObject = ChallengeList.GetChallengeList( ViewingGladiatorId, ChallengeList.ChallengeFilter.All );
            Session["CurrentObject"] = businessObject;
        }

        Master.SortExpression = "ChallengeDate";
        Master.SortDirection = System.ComponentModel.ListSortDirection.Descending;

        SortedBindingList<Challenge> list = new SortedBindingList<Challenge>( (ChallengeList)businessObject );
        list.ApplySort( Master.SortExpression, Master.SortDirection );
        return list;
    }
Esempio n. 33
0
        /// <summary>
        /// Devuelve una lista ordenada y filtrada a partir de los datos de la lista
        /// actual, usando un criterio para fechas.
        /// </summary>
        /// <param name="criteria">Criterio para DateTime</param>
        /// <param name="sortProperty">Campo de ordenación</param>
        /// <param name="sortDirection">Sentido de ordenación</param>
        /// <returns>Lista ordenada</returns>
        public SortedBindingList <C> GetSortedSubList(DCriteria criteria,
                                                      string sortProperty,
                                                      ListSortDirection sortDirection)
        {
            List <C> list = new List <C>();

            SortedBindingList <C> sortedList = new SortedBindingList <C>(list);

            if (Items.Count == 0)
            {
                return(sortedList);
            }

            PropertyDescriptor property = TypeDescriptor.GetProperties(Items[0]).Find(criteria.GetProperty(), false);

            switch (criteria.Operation)
            {
            case Operation.Less:
            {
                foreach (C item in Items)
                {
                    foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item))
                    {
                        if (prop.Name == property.Name)
                        {
                            DateTime value = (DateTime)prop.GetValue(item);
                            if (value < (DateTime)criteria.GetValue())
                            {
                                sortedList.Add(item);
                            }
                            break;
                        }
                    }
                }
            } break;

            case Operation.LessOrEqual:
            {
                foreach (C item in Items)
                {
                    foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item))
                    {
                        if (prop.Name == property.Name)
                        {
                            DateTime value = (DateTime)prop.GetValue(item);
                            if (value <= (DateTime)criteria.GetValue())
                            {
                                sortedList.Add(item);
                            }
                            break;
                        }
                    }
                }
            } break;

            case Operation.Equal:
            {
                foreach (C item in Items)
                {
                    foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item))
                    {
                        if (prop.Name == property.Name)
                        {
                            DateTime value = (DateTime)prop.GetValue(item);
                            if (value == (DateTime)criteria.GetValue())
                            {
                                sortedList.Add(item);
                            }
                            break;
                        }
                    }
                }
            } break;

            case Operation.GreaterOrEqual:
            {
                foreach (C item in Items)
                {
                    foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item))
                    {
                        if (prop.Name == property.Name)
                        {
                            DateTime value = (DateTime)prop.GetValue(item);
                            if (value >= (DateTime)criteria.GetValue())
                            {
                                sortedList.Add(item);
                            }
                            break;
                        }
                    }
                }
            } break;

            case Operation.Greater:
            {
                foreach (C item in Items)
                {
                    foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item))
                    {
                        if (prop.Name == property.Name)
                        {
                            DateTime value = (DateTime)prop.GetValue(item);
                            if (value > (DateTime)criteria.GetValue())
                            {
                                sortedList.Add(item);
                            }
                            break;
                        }
                    }
                }
            } break;

            default:
            {
                foreach (C item in Items)
                {
                    foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item))
                    {
                        if (prop.Name == property.Name)
                        {
                            DateTime value = (DateTime)prop.GetValue(item);
                            if (value == (DateTime)criteria.GetValue())
                            {
                                sortedList.Add(item);
                            }
                            break;
                        }
                    }
                }
            } break;
            }

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 34
0
 public void ApplySort_ThrowException_WhenPropertyNameNotFound()
 {
     int[] intArray = { 5, 7, 1, 3, 5, 44, 32 };
     SortedBindingList<int> sortedList = new SortedBindingList<int>(intArray);
     sortedList.ApplySort("NotAProperty", ListSortDirection.Ascending);
 }
        public static SortedBindingList <FestivoInfo> GetList(DateTime fecha_inicio, DateTime fecha_fin)
        {
            CriteriaEx criteria = Festivo.GetCriteria(Festivo.OpenSession());

            criteria.Childs = false;

            List <FestivoInfo> list     = new List <FestivoInfo>();
            List <FestivoInfo> festivos = new List <FestivoInfo>();

            string query = SELECT_BY_DATE(fecha_inicio, fecha_fin);

            try
            {
                IDataReader reader = nHManager.Instance.SQLNativeSelect(query, criteria.Session);

                while (reader.Read())
                {
                    list.Add(FestivoInfo.GetChild(criteria.SessionCode, reader, false));
                }
            }
            catch (Exception ex)
            {
                iQExceptionHandler.TreatException(ex);
            }

            CloseSession(criteria.SessionCode);

            foreach (FestivoInfo info in list)
            {
                if (!info.Anual)
                {
                    festivos.Add(info);
                }
                else
                {
                    TimeSpan span = info.FechaFin.Date.Subtract(info.FechaInicio.Date);

                    for (int i = Math.Max(fecha_inicio.Year, info.FechaInicio.Year); i <= fecha_fin.Year; i++)
                    {
                        DateTime date_inicio = new DateTime(i, info.FechaInicio.Month, info.FechaInicio.Day);

                        if (date_inicio.Date > info.FechaInicio.Date)
                        {
                            FestivoInfo nuevo = FestivoInfo.New();
                            nuevo.CopyFrom(info);

                            nuevo.FechaInicio = date_inicio;
                            nuevo.FechaFin    = date_inicio + span;
                            festivos.Add(nuevo);
                        }
                        else
                        {
                            festivos.Add(info);
                        }
                    }
                }
            }

            SortedBindingList <FestivoInfo> ordenada = new SortedBindingList <FestivoInfo>(festivos);

            ordenada.ApplySort("FechaInicio", ListSortDirection.Ascending);

            return(ordenada);
        }
Esempio n. 36
0
        public void IndexOf()
        {
            List<string> list = new List<string>();

            string barney = "Barney";
            string charlie = "Charlie";
            string zeke = "Zeke";

            list.AddRange(new string[] { charlie, barney, zeke });

            SortedBindingList<string> sortedList = new SortedBindingList<string>(list);

            Assert.AreEqual(1, sortedList.IndexOf(barney), "Unsorted index should be 1");

            sortedList.ApplySort(string.Empty, System.ComponentModel.ListSortDirection.Ascending);

            Assert.AreEqual(1, sortedList.IndexOf(charlie), "Sorted index should be 1");
        }