Changing the Default Option for Column Filters - acumatica

Is it possible to change the default option all column filters? I'm pretty sure I can accomplish this with some JavaScript, but I'd like to know if there's any way within the Acumatica framework to change this.

The answer will be no. The filter is inside the PX.Web.UI.dll in the PXGridFilter class which is an internal class. The property that you are interested in is the Condition.
The value is set inside one of the private methods of the PXGrid class. The code of the method is below:
private IEnumerable<PXGridFilter> ab()
{
List<PXGridFilter> list = new List<PXGridFilter>();
if (this.FilterID != null)
{
Guid? filterID = this.FilterID;
Guid guid = PXGrid.k;
if (filterID == null || (filterID != null && filterID.GetValueOrDefault() != guid))
{
using (IEnumerator<PXResult<FilterRow>> enumerator = PXSelectBase<FilterRow, PXSelect<FilterRow, Where<FilterRow.filterID, Equal<Required<FilterRow.filterID>>, And<FilterRow.isUsed, Equal<True>>>>.Config>.Select(this.DataGraph, new object[]
{
this.FilterID.Value
}).GetEnumerator())
{
while (enumerator.MoveNext())
{
FilterRow row = enumerator.Current;
string dataField = row.DataField;
PXCache pxcache = PXFilterDetailView.TargetCache(this.DataGraph, new Guid?(this.FilterID.Value), ref dataField);
if (this.Columns[row.DataField] != null)
{
List<PXGridFilter> list2 = list;
int valueOrDefault = row.OpenBrackets.GetValueOrDefault();
string dataField2 = row.DataField;
string dataField3 = row.DataField;
int value = (int)row.Condition.Value;
object value2 = pxcache.ValueFromString(dataField, row.ValueSt);
string valueText = row.ValueSt.With((string _) => this.Columns[row.DataField].FormatValue(_));
object value3 = pxcache.ValueFromString(dataField, row.ValueSt2);
string value2Text = row.ValueSt2.With((string _) => this.Columns[row.DataField].FormatValue(_));
int valueOrDefault2 = row.CloseBrackets.GetValueOrDefault();
int? #operator = row.Operator;
int num = 1;
list2.Add(new PXGridFilter(valueOrDefault, dataField2, dataField3, value, value2, valueText, value3, value2Text, valueOrDefault2, #operator.GetValueOrDefault() == num & #operator != null));
}
}
return list;
}
}
}
if (this.FilterRows != null && this.FilterRows.Count > 0)
{
for (int i = 0; i < this.FilterRows.Count; i++)
{
PXFilterRow row = this.FilterRows[i];
list.Add(new PXGridFilter(row.OpenBrackets, row.DataField, row.DataField, (int)row.Condition, row.Value, row.Value.With(delegate(object _)
{
if (this.Columns[row.DataField] == null)
{
return _.ToString();
}
return this.Columns[row.DataField].FormatValue(_);
}), row.Value2, row.Value2.With(delegate(object _)
{
if (this.Columns[row.DataField] == null)
{
return _.ToString();
}
return this.Columns[row.DataField].FormatValue(_);
}), row.CloseBrackets, row.OrOperator));
}
}
return list;
}
UPDATE
The below JS code allows you to change the condition of the last set filter:
px_all.ctl00_phG_grid_fd.show();
px_all.ctl00_phG_grid_fd_cond.items.items[7].setChecked(true);
px_all.ctl00_phG_grid_fd_ok.element.click();
px_all.ctl00_phG_grid_fd_cond.items.items[7].value "EQ"
px_all.ctl00_phG_grid_fd_cond.items.items[8].value "NE"
px_all.ctl00_phG_grid_fd_cond.items.items[9].value "GT"
px_all.ctl00_phG_grid_fd_cond.items.items[13].value "LIKE"
px_all.ctl00_phG_grid_fd_cond.items.items[14].value "LLIKE"
px_all.ctl00_phG_grid_fd_cond.items.items[15].value "RLIKE"
px_all.ctl00_phG_grid_fd_cond.items.items[16].value "NOTLIKE"
px_all.ctl00_phG_grid_fd_cond.items.items[18].value "ISNULL"
px_all.ctl00_phG_grid_fd_cond.items.items[19].value "ISNOTNULL"

Related

Acumatica Pagination Implementation for Processing Screen does not returns all applicable values

I have tried to implement pagination for my custom processing screen but not getting all the required values in the grid.
If I am using below code, where I did not implemented pagination and directly using BQL in the foreach() loop for getting the records, I am getting all the applicable values.
public PXCancel<KNPIPaymentFilter> cancel;
public PXFilter<KNPIPaymentFilter> KNPIFilter;
[PXFilterable]
public PXFilteredProcessing<SOOrder, KNPIPaymentFilter> KNPIProcessOrders;
protected bool _PayMethodChanged = false;
protected bool _PayActionChanged = false;
public virtual void KNPIPaymentFilter_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
_PayMethodChanged = !sender.ObjectsEqual<KNPIPaymentFilter.paymentMethodID>(e.Row, e.OldRow);
_PayActionChanged = !sender.ObjectsEqual<KNPIPaymentFilter.payPalInvAction>(e.Row, e.OldRow);
}
public IEnumerable kNPIProcessOrders()
{
if (_PayMethodChanged || _PayActionChanged)
KNPIProcessOrders.Cache.Clear();
KNPIPaymentFilter filter = PXCache<KNPIPaymentFilter>.CreateCopy(KNPIFilter.Current);
if (filter.PayPalInvAction == KNPIConstants.SL)
yield break;
foreach (SOOrder order in PXSelect<SOOrder, Where<SOOrder.orderType, Equal<SOOrderTypeConstants.salesOrder>, And<SOOrder.paymentMethodID, Equal<Required<KNPIPaymentFilter.paymentMethodID>>,
And<SOOrder.status, NotEqual<SOOrderStatus.completed>>>>>.Select(this, this.KNPIFilter.Current.PaymentMethodID))
{
KNPIPayments PayPalPayment = new PXSelect<KNPIPayments, Where<KNPIPayments.acmOrderNbr, Equal<Required<KNPIPayments.acmOrderNbr>>,
And<KNPIPayments.acmOrderType, Equal<Required<KNPIPayments.acmOrderType>>>>, OrderBy<Desc<KNPIPayments.lineNbr>>>
(this).SelectWindowed(0, 1, order.OrderNbr, order.OrderType);
if (filter.PayPalInvAction == KNPIConstants.RE)
{
if (PayPalPayment == null || (PayPalPayment != null && PayPalPayment.PayPalInvoiceStatus == KNPIConstants.CANCELLED))
yield return order;
}
else if (filter.PayPalInvAction == KNPIConstants.CH)
{
if (PayPalPayment != null && PayPalPayment.PayPalInvoiceStatus == KNPIConstants.SENT)
yield return order;
}
}
KNPIProcessOrders.Cache.IsDirty = false;
}
But when I am implementing pagination logic like below, I am not getting any of the record in the grid. I have debugged the code and found out in the list object it is loading only 19 records initially but after that other records are not at all loading in the object.
public PXCancel<KNPIPaymentFilter> cancel;
public PXFilter<KNPIPaymentFilter> KNPIFilter;
[PXFilterable]
public PXFilteredProcessing<SOOrder, KNPIPaymentFilter> KNPIProcessOrders;
protected bool _PayMethodChanged = false;
protected bool _PayActionChanged = false;
public virtual void KNPIPaymentFilter_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
_PayMethodChanged = !sender.ObjectsEqual<KNPIPaymentFilter.paymentMethodID>(e.Row, e.OldRow);
_PayActionChanged = !sender.ObjectsEqual<KNPIPaymentFilter.payPalInvAction>(e.Row, e.OldRow);
}
public IEnumerable kNPIProcessOrders()
{
if (_PayMethodChanged || _PayActionChanged)
KNPIProcessOrders.Cache.Clear();
KNPIPaymentFilter filter = PXCache<KNPIPaymentFilter>.CreateCopy(KNPIFilter.Current);
if (filter.PayPalInvAction == KNPIConstants.SL)
yield break;
PXSelectBase<SOOrder> cmd = new PXSelect<SOOrder, Where<SOOrder.orderType, Equal<SOOrderTypeConstants.salesOrder>, And<SOOrder.status, NotEqual<SOOrderStatus.completed>,
And<SOOrder.paymentMethodID, Equal<Optional<KNPIPaymentFilter.paymentMethodID>>>>>>(this);
int startRow = PXView.StartRow;
int totalRows = 0;
List<object> list = cmd.View.Select(new[] { KNPIFilter.Current }, null, PXView.Searches,
PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRows);
foreach (SOOrder order in list)
{
KNPIPayments PayPalPayment = new PXSelect<KNPIPayments, Where<KNPIPayments.acmOrderNbr, Equal<Required<KNPIPayments.acmOrderNbr>>,
And<KNPIPayments.acmOrderType, Equal<Required<KNPIPayments.acmOrderType>>>>, OrderBy<Desc<KNPIPayments.lineNbr>>>
(this).SelectWindowed(0, 1, order.OrderNbr, order.OrderType);
if (this.KNPIFilter.Current.PayPalInvAction == KNPIConstants.RE)
{
if (PayPalPayment == null || (PayPalPayment != null && PayPalPayment.PayPalInvoiceStatus == KNPIConstants.CANCELLED))
yield return order;
}
else if (this.KNPIFilter.Current.PayPalInvAction == KNPIConstants.CH)
{
if (PayPalPayment != null && PayPalPayment.PayPalInvoiceStatus == KNPIConstants.SENT)
yield return order;
}
}
PXView.StartRow = 0;
KNPIProcessOrders.Cache.IsDirty = false;
}
Can someone please help me out, as what I am doing wrong or what I am missing here.

Provide data lookup for PXSelector

I need advice either to convert the SQL to BQL or set the Resultset manipulated by C# code to the PXSelector.
I need to customize the AR Invoice and add 2 custom fields to record the COGS GL account and sub account for the inter company client when the inter company enter this invoice line as a bill. This custom field need to look up all sub accounts that is restricted to this Client's Branch ID and GL account. Basically all system's sub account lookup take care of the restriction group but for the custom fields; a custom PXSelector need to be written for this. Below is the SQL that supplies the require sub accounts but I need to know how to make the SQL query works in Acumatica
-- SQL for the required data
DECLARE #GLAccountCD nvarchar(10) = 'COGS'
DECLARE #BranchCD nvarchar(30) = 'PurchaseBranch'
SELECT *
FROM Sub
where (((CAST(Sub.groupmask as int) & CAST((SELECT GroupMask FROM Account WHERE AccountCD = #GLAccountCD AND CompanyID = 3 AND DeletedDatabaseRecord = 0) AS int)) > 1
AND (CAST(Sub.groupmask as int) & CAST((SELECT GroupMask FROM Branch WHERE BranchCD = #BranchCD AND CompanyID = 3 AND DeletedDatabaseRecord = 0) AS int)) > 1)
OR (Sub.GroupMask = 0 AND Sub.DeletedDatabaseRecord = 0))
AND CompanyID = 3
ORDER BY SubCD
--The below PXSelector provide all sub accounts regard of restriction group,
--I need the PXSelector to use the above SQL Query result
#region UsrAPBIllGLSubAccID
[PXDBInt]
[PXUIField(DisplayName="Bill COGS SubAccount")]
[PXSelector(typeof(Search<Sub.subID, Where<Sub.active, Equal<True>>, OrderBy<Desc<Sub.subCD>>>),
new Type[] {typeof(Sub.subCD),
typeof(Sub.description)},
SubstituteKey = typeof(Sub.subCD)
)]
public virtual int? UsrAPBIllGLSubAccID { get; set; }
public abstract class usrAPBIllGLSubAccID : IBqlField { }
#endregion
I think that would be achievable using the Match BQL clause.
GLAccess.cs file has BQL queries to restrict accounts based on Sub and Branch group mask using Match clause, this would be a good place to investigate:
public PXSelect<Sub> Sub;
protected virtual IEnumerable sub(
)
{
if (Group.Current != null && !String.IsNullOrEmpty(Group.Current.GroupName))
{
bool inserted = (Group.Cache.GetStatus(Group.Current) == PXEntryStatus.Inserted);
foreach (Sub item in PXSelect<Sub,
Where2<Match<Current<PX.SM.RelationGroup.groupName>>,
Or2<Match<Required<Sub.groupMask>>, Or<Sub.groupMask, IsNull>>>>
.Select(this, new byte[0]))
{
if (!inserted || item.Included == true)
{
Sub.Current = item;
yield return item;
}
else if (item.GroupMask != null)
{
PX.SM.RelationGroup group = Group.Current;
bool anyGroup = false;
for (int i = 0; i < item.GroupMask.Length && i < group.GroupMask.Length; i++)
{
if (group.GroupMask[i] != 0x00 && (item.GroupMask[i] & group.GroupMask[i]) == group.GroupMask[i])
{
Sub.Current = item;
yield return item;
}
anyGroup |= item.GroupMask[i] != 0x00;
}
if (!anyGroup)
{
Sub.Current = item;
yield return item;
}
}
}
}
else
{
yield break;
}
}
public PXSelect<Branch> Branch;
protected virtual IEnumerable branch(
)
{
if (Group.Current != null && !String.IsNullOrEmpty(Group.Current.GroupName))
{
bool inserted = (Group.Cache.GetStatus(Group.Current) == PXEntryStatus.Inserted);
foreach (Branch item in PXSelect<Branch,
Where2<Match<Current<PX.SM.RelationGroup.groupName>>,
Or<Match<Required<Branch.groupMask>>>>>
.Select(this, new byte[0]))
{
if (!inserted)
{
Branch.Current = item;
yield return item;
}
else if (item.GroupMask != null)
{
PX.SM.RelationGroup group = Group.Current;
bool anyGroup = false;
for (int i = 0; i < item.GroupMask.Length && i < group.GroupMask.Length; i++)
{
if (group.GroupMask[i] != 0x00 && (item.GroupMask[i] & group.GroupMask[i]) == group.GroupMask[i])
{
Branch.Current = item;
yield return item;
}
anyGroup |= item.GroupMask[i] != 0x00;
}
if (!anyGroup)
{
Branch.Current = item;
yield return item;
}
}
}
}
else
{
yield break;
}
}

How to print all object fields dynamicly even if on of the fields is object

I want want to print all the fields in object and if one of the field is object i want to print it fields and on and on (with recursion).
I wrote function but i get this error once i've entering to recursion.
Field '_str1' defined on type 'ConsoleApplication1.StringTest' is not
a field on the target object which is of type
'System.Reflection.RtFieldInfo'.
This is the Code:
static void OutPutObject(dynamic dyn,Type pType)
{
List<string> lFieldsList = new List<string>();
// Get the type of MyClass.
Type lType = pType;
// Get the FieldInfo of MyClass.
FieldInfo[] myFields = lType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
// Display the values of the fields.
for (int i = 0; i < myFields.Length; i++)
{
if (myFields[i].FieldType.IsClass && myFields[i].FieldType.Name != "String")
{
Type tType = myFields[i].FieldType.GetType();
OutPutObject(myFields[i], pType);
}
else
{
Console.WriteLine(string.Format("{0}: {1}", myFields[i].Name, myFields[i].GetValue(dyn)));
}
}
}
public class IntTest
{
private int a = 1;
private int b = 2;
}
public class StringTest
{
private string _str1;
private string _str2;
private IntTest intl;
public StringTest()
{
_str1 = "str1";
_str2 = "str2";
}
}
I've change your code and now it works!
Please notice that the inner classes must have default constructor.
static void OutPutObject(object obj, Type pType, bool isFirst)
{
// Get the FieldInfo of MyClass.
FieldInfo[] myFields = pType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
// Display the values of the fields.
for (int i = 0; i < myFields.Length; i++)
{
if (myFields[i].FieldType.IsPrimitive || myFields[i].FieldType == typeof(Decimal) || myFields[i].FieldType == typeof(String))
{
if (!isFirst)
{
object temp = Activator.CreateInstance(pType);
obj = temp;
}
Console.WriteLine(string.Format("{0}: {1}", myFields[i].Name, myFields[i].GetValue(obj)));
}
else if (myFields[i].FieldType.IsClass)
{
Type tType = myFields[i].FieldType;
OutPutObject(myFields[i], tType, false);
}
}
}
You can use following lines to write object public fields. I tested on .NET 4.0
Type type = obj.GetType();
foreach (var f in type.GetFields().Where(f => f.IsPublic)) {
Console.WriteLine("Name: "+f.Name+" Value: "+ f.GetValue(obj) );
}

Getting a random UserProfile In SharePoint 2010

I am trying to retrieve a random number of users from the UserProfileManager.
But I am encountering errors when deploying to the live servers. I can't seem to see what is causing the error. My code is below:
for (int i = 0; i < NumberOfUserLimit; i++)
{
UserProfile up = profileManager.GetUserProfile(random.Next(1, NumberOfUserLimit));
if (up["FirstName"] != null && up["FirstName"].Value != null && !String.IsNullOrEmpty(up["FirstName"].Value.ToString()))
{
DataRow drUserProfile;
drUserProfile = dtUserProfile.NewRow();
drUserProfile["DisplayName"] = up.DisplayName;
drUserProfile["FirstName"] = up["FirstName"].Value;
drUserProfile["LastName"] = up["LastName"].Value;
drUserProfile["Department"] = up["Department"].Value;
drUserProfile["Location"] = up["SPS-Location"].Value;
drUserProfile["HireDate"] = up["SPS-HireDate"].Value;
drUserProfile["ContactNumber"] = up["Office"].Value;
if (up["PictureURL"] != null && up["PictureURL"].Value != null && !String.IsNullOrEmpty(up["PictureURL"].Value.ToString()))
{
string cleanAccountName = up["AccountName"].Value.ToString().Replace(#"\", "_");
string pictureUrl = String.Format("https://my.someintranet.com/User Photos/Profile Pictures/{0}_MThumb.jpg", cleanAccountName);
drUserProfile["Image"] = pictureUrl;
}
else
{
drUserProfile["Image"] = "~/_layouts/images/O14_person_placeHolder_96.png";
}
drUserProfile["MySiteUrl"] = up.PublicUrl;
dtUserProfile.Rows.Add(drUserProfile);
}
}
My code works when I apply a simple foreach to my code above instead of the "for loop":
foreach (UserProfile up in profileManager)
Which proves I can return userprofiles.
Any help is appreciated.
profileManager.GetUserProfile(long recordId)
expects a recordId from userprofile table. It is not an index, so you cannot use "random".
If you want to check RecordId, you can take a look at SQL tables of ProfileDB. Table "UserProfile_Full" has MasterRecordId column. Your parameter in GetUserProfile has to match of the user profile's MasterRecordId.
you can use the following code to get your random profiles:
IEnumerator profiles = profileManager.GetEnumerator();
int index = new Random().Next(1, 100);
while (index >= 0 && profiles.MoveNext())
index--;
UserProfile currentProfile = (UserProfile)profiles.Current
Code that handles Random better
public class TestClass
{
private random = new Random();
private long totalNumberOfProfiles; //ProfileManager.Count not always returns count correctly
public TestClass()
{
//this does not have to be in constructor but point is to have it cached (reasonably)
IEnumerator profiles = profileManager.GetEnumerator();
long counter = 0;
while (profiles.MoveNext())
counter++;
this.totalNumberOfProfiles = counter;
}
public fillInDataSet()
{
//something is here...
IEnumerator profiles = profileManager.GetEnumerator();
int index = random.Next(1, totalNumberOfProfiles);
while (index >= 0 && profiles.MoveNext())
index--;
UserProfile currentProfile = (UserProfile)profiles.Current
//something is here...
}
}

Easy way to search a string for strings

I'm trying to find the easiest way to search a string for an array of possible strings. I know the easy way to do this for characters is to use myString.IndexOfAny(charArray). But how what if I'd like to search my string for strings and not just characters? Are there any .net tricks or methods that make this easier?
Basically, I'd like to do something like this:
string myName = "rahkim";
string[] names = new string[] {"joe","bob","chris"};
if(myName.IndexOfAny(names) >= 0)
{
//success code//
}
I know there are ways to do this with loops, etc. But I was hoping for something inherent in the framework.
You should define if you want to to find equal strings or search for a matching substring. Both ways are easy pre-LINQ and with LINQ.
string myName = "rahkim";
string[] names = new string[] { "joe", "bob", "chris" };
Equal Strings, LINQ
bool contains = names.Contains(myName);
Equal Strings, Pre-LINQ
bool contains = new List<string>(name).Contains(myName);
Substrings, LINQ
bool contains = names.Any(name => name.Contains(myName));
Substring, Pre-LINQ
bool contains = false;
foreach(string name in names)
if (name.Contains(myName))
contains = true;
If anyone else found this while trying to search for a .Net method like String.IndexOfAny(String[]), this is my solution:
C#
public int IndexOfAny(string test, string[] values)
{
int first = -1;
foreach (string item in values) {
int i = test.IndexOf(item);
if (i >= 0) {
if (first > 0) {
if (i < first) {
first = i;
}
} else {
first = i;
}
}
}
return first;
}
VB
Public Function IndexOfAny(test As String, values As String()) As Integer
Dim first As Integer = -1
For Each item As String In values
Dim i As Integer = test.IndexOf(item)
If i >= 0 Then
If first > 0 Then
If i < first Then
first = i
End If
Else
first = i
End If
End If
Next
Return first
End Function
You can do a LastIndexOfAny(String[]) by just switching the
i < first
to
i > first
You can (also) use the static IndexOf method of the Array class:
bool hasName = Array.IndexOf(names, myName) > -1;
int IndexOfAny(String[] rgs) would indeed be nice but it's nominally an O(n^2) operation. If, in your application, the set of strings rgs is large and always the same, the most efficient approach is to load them into a trie data structure once, and then use the trie repeatedly to search for them within the unknown strings given at runtime.
Here is the relevant code, adapted from a C# trie source I found on the web, attributed to "Kerry D. Wong." In my version, each string in the trie has a "payload" of generic type TValue. To use this trie to simply search for substrings, the payload could always be set to true, as illustrated with simple_trie.
The other thing I changed here is that this trie automatically adapts allow for storage of arbitrary Unicode strings. The array at each node—which characterizes a trie—adjusts its base and length to accomodate the range of Unicode characters which need to be stored at that node. This allows for case-sensitive matching, for example.
The C# 3.0 initialization syntax is handy for this trie, but enabling it requires a dummy implementation of IEnumerable in order to compile. The CLR doesn't seem to call GetEnumerator() and I suggest that you don't try to enumerate with its result either.
using System;
using System.Collections.Generic;
using System.Linq; // only used in Main()
class Program
{
// trie with payload of type <String>
static Trie<String> value_trie = new Trie<String>
{
{ "rabbit", "cute" },
{ "giraffe", "tall" },
{ "ape", "smart" },
{ "hippo", "large" },
};
// degenerate case of a trie without payload
static Trie<bool> simple_trie = new Trie<bool>
{
{ "rabbit", true },
{ "giraffe", true },
{ "ape", true },
{ "hippo", true },
};
static void Main(String[] args)
{
String s = "Once upon a time, a rabbit met an ape in the woods.";
// Retrieve payloads for words in the string.
//
// output:
// cute
// smart
foreach (String word in value_trie.AllSubstringValues(s))
Console.WriteLine(word);
// Simply test a string for any of the words in the trie.
// Note that the Any() operator ensures that the input is no longer
// traversed once a single result is found.
//
// output:
// True
Console.WriteLine(simple_trie.AllSubstringValues(s).Any(e=>e));
s = "Four score and seven years ago.";
// output:
// False
Console.WriteLine(simple_trie.AllSubstringValues(s).Any(e => e));
}
}
class TrieNode<TValue>
{
private TrieNode<TValue>[] nodes = null;
private TValue m_value = default(TValue);
private Char m_base;
public Char Base { get { return m_base; } }
public bool IsEnd { get { return !m_value.Equals(default(TValue)); } }
public TValue Value
{
get { return m_value; }
set { m_value = value; }
}
public IEnumerable<TrieNode<TValue>> Nodes { get { return nodes; } }
public TrieNode<TValue> this[char c]
{
get
{
if (nodes != null && m_base <= c && c < m_base + nodes.Length)
return nodes[c - m_base];
return null;
}
}
public TrieNode<TValue> AddChild(char c)
{
if (nodes == null)
{
m_base = c;
nodes = new TrieNode<TValue>[1];
}
else if (c >= m_base + nodes.Length)
{
Array.Resize(ref nodes, c - m_base + 1);
}
else if (c < m_base)
{
Char c_new = (Char)(m_base - c);
TrieNode<TValue>[] tmp = new TrieNode<TValue>[nodes.Length + c_new];
nodes.CopyTo(tmp, c_new);
m_base = c;
nodes = tmp;
}
TrieNode<TValue> node = nodes[c - m_base];
if (node == null)
{
node = new TrieNode<TValue>();
nodes[c - m_base] = node;
}
return node;
}
};
class Trie<TValue> : System.Collections.IEnumerable
{
private TrieNode<TValue> _root = new TrieNode<TValue>();
// This dummy enables C# 3.0 initialization syntax
public System.Collections.IEnumerator GetEnumerator()
{
return null;
}
public void Add(String s, TValue v)
{
TrieNode<TValue> node = _root;
foreach (Char c in s)
node = node.AddChild(c);
node.Value = v;
}
public bool Contains(String s)
{
TrieNode<TValue> node = _root;
foreach (Char c in s)
{
node = node[c];
if (node == null)
return false;
}
return node.IsEnd;
}
public TValue Find(String s_in)
{
TrieNode<TValue> node = _root;
foreach (Char c in s_in)
{
node = node[c];
if (node == null)
return default(TValue);
}
return node.Value;
}
public IEnumerable<TValue> FindAll(String s_in)
{
TrieNode<TValue> node = _root;
foreach (Char c in s_in)
{
node = node[c];
if (node == null)
break;
if (node.Value != null)
yield return node.Value;
}
}
public IEnumerable<TValue> AllSubstringValues(String s)
{
int i_cur = 0;
while (i_cur < s.Length)
{
TrieNode<TValue> node = _root;
int i = i_cur;
while (i < s.Length)
{
node = node[s[i]];
if (node == null)
break;
if (node.Value != null)
yield return node.Value;
i++;
}
i_cur++;
}
}
};
Here's the right syntax:
if(names.Contains(myName))
{
//success code//
}
if (names.Contains(myName))
{
//success code//
}

Resources