/// <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); }
private void GetHosts() { ips.Clear(); //Clear Hosts List if (IpHelpers.isValidIP(tbIPStart.Text) == true && IpHelpers.isValidIP(tbIPEnd.Text) && cbUseSubnet.Checked == false) { string ipStart = tbIPStart.Text; string ipEnd = tbIPEnd.Text; string ipNet = IPFirstPart(ipStart); int ipStartSub = Convert.ToInt32(IPLastPart(ipStart)); int ipEndSub = Convert.ToInt32(ipEnd); if (ipStartSub <= ipEndSub) { for (int i = ipStartSub; i <= ipEndSub; i++) { IPAddress newIP = IPAddress.Parse(ipNet + i.ToString()); Host newHost = new Host(); newHost.IP_Address = newIP; newHost.CountChecks = 0; newHost.RunningCheck = false; ips.Add(newHost); } } } if (IpHelpers.isValidIP(tbIPStart.Text) == true && cbUseSubnet.Checked == true) { foreach (var host in ipSeg.Hosts()) { if (host >= IpHelpers.ParseIp(firstIP) && host <= IpHelpers.ParseIp(lastIP)) { //Prevent ip .0 and .255 in List if (Convert.ToInt32(IPLastPart(host.ToIpString())) > 0 && Convert.ToInt32(IPLastPart(host.ToIpString())) < 255) { IPAddress newIP = IPAddress.Parse(host.ToIpString()); Host newHost = new Host(); newHost.IP_Address = newIP; newHost.CountChecks = 0; newHost.RunningCheck = false; ips.Add(newHost); } } } } }
private Data[] AddData(SortedBindingList <Data> list, int length) { var datas = CreateData(length); foreach (var data in datas) { list.Add(data); } return(datas); }
public void Contains() { var cut = new SortedBindingList <Data>(); var data = new Data(); cut.Add(data); var rc = cut.Contains(data); Assert.IsTrue(rc); }
public void SetAt() { var cut = new SortedBindingList <Data>(); var datas = CreateData(2); cut.Add(datas[0]); cut[0] = datas[1]; Assert.AreEqual(1, cut.Count); Assert.AreEqual(datas[1], cut[0]); }
private void btnSerarch_Click(object sender, EventArgs e) { String name = txtName.Text; Student student = null; foreach (Student item in students) { if (item.Name.Equals(name)) { student = item; } } SortedBindingList <Student> searchList = new SortedBindingList <Student>(); searchList.Add(student); dataGridView1.DataSource = searchList; }
public void Add() { var cut = new SortedBindingList <Data>(); var raisedEvents = new List <ListChangedEventArgs>(); cut.ListChanged += (s, e) => raisedEvents.Add(e); var data = new Data(); cut.Add(data); Assert.AreEqual(1, cut.Count); Assert.AreEqual(data, cut[0]); Assert.AreEqual(1, raisedEvents.Count); Assert.AreEqual(ListChangedType.ItemAdded, raisedEvents[0].ListChangedType); Assert.AreEqual(0, raisedEvents[0].NewIndex); }
public void Clear() { var cut = new SortedBindingList <Data>(); var raisedEvents = new List <ListChangedEventArgs>(); cut.ListChanged += (s, e) => raisedEvents.Add(e); var data = new Data(); cut.Add(data); cut.Clear(); var last = raisedEvents.Last(); Assert.AreEqual(0, cut.Count); Assert.AreEqual(ListChangedType.Reset, last.ListChangedType); }
public void Remove() { var cut = new SortedBindingList <Data>(); var raisedEvents = new List <ListChangedEventArgs>(); cut.ListChanged += (s, e) => raisedEvents.Add(e); var data = new Data(); cut.Add(data); cut.Remove(data); var last = raisedEvents.Last(); Assert.AreEqual(0, cut.Count); Assert.AreEqual(ListChangedType.ItemDeleted, last.ListChangedType); Assert.AreEqual(0, last.NewIndex); }
/// <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); }
private void BtnGetUrl_Click(object sender, EventArgs e) { SortedBindingList <GitInfoPath> gitPaths = new SortedBindingList <GitInfoPath>(); GitInfoPath gitInfoPath; if (!String.IsNullOrWhiteSpace(txtGitPath.Text)) { var directories = Directory.GetDirectories(txtGitPath.Text); foreach (string directory in directories) { gitInfoPath = new GitInfoPath(); using (var repo = new Repository(directory)) { var remote = repo.Network.Remotes["origin"]; gitInfoPath.DirName = directory.Substring(directory.LastIndexOf('\\') + 1); gitInfoPath.GitPath = remote.PushUrl; gitPaths.Add(gitInfoPath); } } } dgGitView.DataSource = gitPaths; }
public void RaisedItemEvents() { var cut = new SortedBindingList <Data>(); var raisedEvents = new List <ListChangedEventArgs>(); cut.ListChanged += (s, e) => raisedEvents.Add(e); var data = new Data(); const string NewName = "NewName"; cut.Add(data); data.Name = NewName; Assert.AreEqual(1, cut.Count); Assert.AreEqual(data.Name, cut[0].Name); Assert.AreEqual(2, raisedEvents.Count); Assert.AreEqual(ListChangedType.ItemAdded, raisedEvents[0].ListChangedType); Assert.AreEqual(0, raisedEvents[0].NewIndex); Assert.AreEqual(ListChangedType.ItemChanged, raisedEvents[1].ListChangedType); Assert.AreEqual(0, raisedEvents[1].NewIndex); Assert.AreEqual(nameof(Data.Name), raisedEvents[1].PropertyDescriptor.Name); }
/// <summary> /// Devuelve una lista a partir de los datos de la lista actual /// </summary> /// <param name="criteria">Filtro (Insensitive)</param> /// <returns>Lista</returns> public SortedBindingList <IAgenteHipatia> GetSortedSubList(FCriteria criteria, List <string> properties_list) { List <IAgenteHipatia> list = new List <IAgenteHipatia>(); SortedBindingList <IAgenteHipatia> sortedList = new SortedBindingList <IAgenteHipatia>(list); if (this.Count == 0) { return(sortedList); } PropertyDescriptor property = null; if (criteria.GetProperty() != null) { property = TypeDescriptor.GetProperties(this[0]).Find(criteria.GetProperty(), false); } else { property = null; } Type type = typeof(IAgenteHipatia); System.Reflection.PropertyInfo prop = null; switch (criteria.Operation) { case Operation.Equal: { foreach (IAgenteHipatia item in this) { foreach (string propName in properties_list) { prop = type.GetProperty(propName); if (prop == null) { continue; } //Buscamos en una propiedad en concreto if (property != null) { if (prop.Name == property.Name) { object value = prop.GetValue(item, null); if (value == null) { break; } if (value.ToString().ToLower().Equals(criteria.GetValue().ToString().ToLower())) { sortedList.Add(item); } break; } } //Buscamos en todas las propiedades de la lista else { object value = prop.GetValue(item, null); if (value == null) { continue; } if (value.ToString().ToLower().Equals(criteria.GetValue().ToString().ToLower())) { sortedList.Add(item); break; } } } } } break; case Operation.StartsWith: { foreach (IAgenteHipatia item in this) { foreach (string propName in properties_list) { prop = type.GetProperty(propName); if (prop == null) { continue; } //Buscamos en una propiedad en concreto if (property != null) { if (prop.Name == property.Name) { object value = prop.GetValue(item, null); if (value == null) { break; } if (value.ToString().ToLower().StartsWith(criteria.GetValue().ToString().ToLower())) { sortedList.Add(item); } break; } } //Buscamos en todas las propiedades de la lista else { object value = prop.GetValue(item, null); if (value == null) { continue; } if (value.ToString().ToLower().StartsWith(criteria.GetValue().ToString().ToLower())) { sortedList.Add(item); break; } } } } } break; case Operation.Less: { foreach (IAgenteHipatia item in this) { foreach (string propName in properties_list) { prop = type.GetProperty(propName); if (prop == null) { continue; } //Buscamos en una propiedad en concreto if (property != null) { if (prop.Name == property.Name) { object value = prop.GetValue(item, null); if (value == null) { break; } if (criteria.Less(value)) { sortedList.Add(item); } break; } } //Buscamos en todas las propiedades de la lista else { object value = prop.GetValue(item, null); if (value == null) { continue; } if (criteria.Less(value)) { sortedList.Add(item); break; } } } } } break; case Operation.LessOrEqual: { foreach (IAgenteHipatia item in this) { foreach (string propName in properties_list) { prop = type.GetProperty(propName); if (prop == null) { continue; } //Buscamos en una propiedad en concreto if (property != null) { if (prop.Name == property.Name) { object value = prop.GetValue(item, null); if (value == null) { break; } if (criteria.LessOrEqual(value)) { sortedList.Add(item); } break; } } //Buscamos en todas las propiedades de la lista else { object value = prop.GetValue(item, null); if (value == null) { continue; } if (criteria.LessOrEqual(value)) { sortedList.Add(item); break; } } } } } break; case Operation.Greater: { foreach (IAgenteHipatia item in this) { foreach (string propName in properties_list) { prop = type.GetProperty(propName); if (prop == null) { continue; } //Buscamos en una propiedad en concreto if (property != null) { if (prop.Name == property.Name) { object value = prop.GetValue(item, null); if (value == null) { break; } if (criteria.Greater(value)) { sortedList.Add(item); } break; } } //Buscamos en todas las propiedades de la lista else { object value = prop.GetValue(item, null); if (value == null) { continue; } if (criteria.Greater(value)) { sortedList.Add(item); break; } } } } } break; case Operation.GreaterOrEqual: { foreach (IAgenteHipatia item in this) { foreach (string propName in properties_list) { prop = type.GetProperty(propName); if (prop == null) { continue; } //Buscamos en una propiedad en concreto if (property != null) { if (prop.Name == property.Name) { object value = prop.GetValue(item, null); if (value == null) { break; } if (criteria.GreaterOrEqual(value)) { sortedList.Add(item); } break; } } //Buscamos en todas las propiedades de la lista else { object value = prop.GetValue(item, null); if (value == null) { continue; } if (criteria.GreaterOrEqual(value)) { sortedList.Add(item); break; } } } } } break; case Operation.Contains: default: { foreach (IAgenteHipatia item in this) { foreach (string propName in properties_list) { prop = type.GetProperty(propName); if (prop == null) { continue; } //Buscamos en una propiedad en concreto if (property != null) { if (prop.Name == property.Name) { object value = prop.GetValue(item, null); if (value == null) { break; } if (value.ToString().ToLower().Contains(criteria.GetValue().ToString().ToLower())) { sortedList.Add(item); } break; } } //Buscamos en todas las propiedades de la lista else { object value = prop.GetValue(item, null); if (value == null) { continue; } if (value.ToString().ToLower().Contains(criteria.GetValue().ToString().ToLower())) { sortedList.Add(item); break; } } } } } break; } return(sortedList); }
/// <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); }
public SortedBindingList <C> GetSortedSubList(FCriteria criteria) { 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.StartsWith: { 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().StartsWith(criteria.GetValue().ToString().ToLower())) { 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) { object value = prop.GetValue(item); if (criteria.Equal(value)) { sortedList.Add(item); } break; } } } } break; case Operation.Less: { foreach (C item in Items) { foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item)) { if (prop.Name == property.Name) { object value = prop.GetValue(item); if (criteria.Less(value)) { 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) { object value = prop.GetValue(item); if (criteria.LessOrEqual(value)) { 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) { object value = prop.GetValue(item); if (criteria.Greater(value)) { 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) { object value = prop.GetValue(item); if (criteria.GreaterOrEqual(value)) { sortedList.Add(item); } break; } } } } break; default: { 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; } } } } break; } return(sortedList); }