// Basic constructor, not usually called without using TryParse(). public Filter(Argument argument, Modifyer modifyer, string value, string secondaryValue) { _argument = argument; _modifyer = modifyer; _value = value; _secondaryValue = secondaryValue; }
public void FromCustomObject(SqlConnection con, IntPtr pUdt) { if (ID != null) { SqlUdt.SetValue(con, pUdt, "ID", ID.ToSqlValue()); } if (CheckNo != null) { SqlUdt.SetValue(con, pUdt, "CheckNo", CheckNo.ToSqlValue()); } if (CheckType != null) { SqlUdt.SetValue(con, pUdt, "CheckType", CheckType.ToSqlValue()); } if (DutyUser != null) { SqlUdt.SetValue(con, pUdt, "DutyUser", DutyUser.ToSqlValue()); } if (CheckDesc != null) { SqlUdt.SetValue(con, pUdt, "CheckDesc", CheckDesc.ToSqlValue()); } if (CheckStatus != null) { SqlUdt.SetValue(con, pUdt, "CheckStatus", CheckStatus.ToSqlValue()); } if (BeginTime != null) { SqlUdt.SetValue(con, pUdt, "BeginTime", BeginTime.ToSqlValue()); } if (DoneTime != null) { SqlUdt.SetValue(con, pUdt, "DoneTime", DoneTime.ToSqlValue()); } if (Remarks != null) { SqlUdt.SetValue(con, pUdt, "Remarks", Remarks.ToSqlValue()); } if (IsDel != null) { SqlUdt.SetValue(con, pUdt, "IsDel", IsDel.ToSqlValue()); } if (Creater != null) { SqlUdt.SetValue(con, pUdt, "Creater", Creater.ToSqlValue()); } if (CreateTime != null) { SqlUdt.SetValue(con, pUdt, "CreateTime", CreateTime.ToSqlValue()); } if (Modifyer != null) { SqlUdt.SetValue(con, pUdt, "Modifyer", Modifyer.ToSqlValue()); } if (ModifyTime != null) { SqlUdt.SetValue(con, pUdt, "ModifyTime", ModifyTime.ToSqlValue()); } }
public void FromCustomObject(SqlConnection con, IntPtr pUdt) { SqlUdt.SetValue(con, pUdt, "ID", ID.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "CheckID", CheckID.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "WarehouseNo", WarehouseNo.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "HouseNo", HouseNo.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "AreaNo", AreaNo.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "MaterialNo", MaterialNo.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "MaterialDesc", MaterialDesc.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "AccountQty", AccountQty.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "ScanQty", ScanQty.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "Status", Status.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "StockTime", StockTime.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "Operator", Operator.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "OperationTime", OperationTime.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "ProfitLoss", ProfitLoss.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "DifferenceQty", DifferenceQty.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "IsDel", IsDel.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "Creater", Creater.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "CreateTime", CreateTime.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "Modifyer", Modifyer.ToSqlValue()); SqlUdt.SetValue(con, pUdt, "ModifyTime", ModifyTime.ToSqlValue()); }
public void AddModifyer(Modifyer modifyer) { Modifyers.Add(modifyer); }
// Used to ensure that a valid filter is constructed. static public bool TryParse(Argument argument, Modifyer modifyer, string value, out Filter filter) { // Set default value of filter incase parsing fails. filter = new Filter(Argument.NULL, Modifyer.NONE, string.Empty, string.Empty); // Create empty potential secondaryValue (may be used by some arguments). string secondaryValue = String.Empty; // Don't allow modifyers on arguments that don't use them. if (!(argument == Argument.HOST || argument == Argument.PORT) && modifyer != Modifyer.NONE) { return(false); } // Validate host argument. if (argument == Argument.HOST) { // Check for an IP range. if (value.Split('-').Length == 2) { // Split string based on '-' delimiter (represents a range). secondaryValue = value.Split('-')[1]; value = value.Split('-')[0]; // Check IP against regex before TryParse. if (Regex.Match(secondaryValue, Filter.nonNumericAndDotRegex).Length > 0) { return(false); } // Make sure secondary IP is valid. if (!IPAddress.TryParse(secondaryValue, out IPAddress _)) { return(false); } } // Check IP against regex before TryParse. if (Regex.Match(value, Filter.nonNumericAndDotRegex).Length > 0) { return(false); } // Make sure primary IP is valid. if (!IPAddress.TryParse(value, out IPAddress _)) { return(false); } // Make sure range is sane. if (secondaryValue != string.Empty && ConnectionAddress.IPV4ToUint32(IPAddress.Parse(value)) >= ConnectionAddress.IPV4ToUint32(IPAddress.Parse(secondaryValue))) { return(false); } } // Validate port argument. else if (argument == Argument.PORT) { // Check for a port range. if (value.Split('-').Length == 2) { // Split string based on '-' delimiter (represents a range). secondaryValue = value.Split('-')[1]; value = value.Split('-')[0]; // Check Port against regex before TryParse. if (Regex.Match(secondaryValue, Filter.nonNumericRegex).Length > 0) { return(false); } // Make sure we have a valid secondary port value. if (!UInt16.TryParse(secondaryValue, out _)) { return(false); } } // Check Port against regex before TryParse. if (Regex.Match(value, Filter.nonNumericRegex).Length > 0) { return(false); } // Make sure we have a valid primary port value. if (!UInt16.TryParse(value, out _)) { return(false); } // Make sure range is sane. if (secondaryValue != string.Empty && UInt16.Parse(value) >= UInt16.Parse(secondaryValue)) { return(false); } } else if (argument == Argument.ISO) { // ISO code should have at 2 or 5 chars. if (!(value.Length == 2 || value.Length == 5)) { return(false); } // Check string against regex before. if (Regex.Match(value, Filter.nonAlphaAndDashRegex).Length > 0) { return(false); } } else if (argument == Argument.ASN) { // Check string against regex before. if (Regex.Match(value, Filter.nonAlphaNumericAndSeparatorsRegex).Length > 0) { return(false); } } // Create new filter on successful parse. filter = new Filter(argument, modifyer, value, secondaryValue); return(true); }
// Attempts to create a valid filter from a string, and retunrs a success indicator. static public bool TryParse(string filter, out DisplayFilter displayFilter) { // Set default value of displayFilter incase parsing fails. displayFilter = new DisplayFilter(new List <Filter>()); // Create a temporary list of filters which will be used if parsing is successful. List <Filter> tmpFilters = new List <Filter>(); // Split string into tokens using a space separator. string[] tokens = filter.ToLower().Split(' '); // Argument being processed, acts as flag. Argument argument = Argument.NULL; // Possible modifyer. Modifyer modifyer = Modifyer.NONE; foreach (string token in tokens) { // Check if current token could be an argument modifyer. if (modifyer == Modifyer.NONE && argument == Argument.NULL) { // Attempt to match a modifyer to the token. for (uint i = 0; i < ModifyerTokens.Length; i++) { if (ModifyerTokens[i].Equals(token)) { modifyer = (Modifyer)i; break; } } // If a valid modifyer was found, continue to next token (should be an argument). if (modifyer != Modifyer.NONE) { continue; } } // Check if the current token should be an argument. if (argument == Argument.NULL) { // Attempt to match an argument to the token. for (uint i = 0; i < ArgumentTokens.Length; i++) { if (ArgumentTokens[i].Equals(token)) { argument = (Argument)i; break; } } // No argument found when one is needed means we have an invalid string. if (argument == Argument.NULL) { return(false); } // Arguments that require no follow up value must be immidiately added. if (argument == Argument.TCP || argument == Argument.UDP) { // Make sure regular argument value combo is valid. if (!Filter.TryParse(argument, modifyer, String.Empty, out Filter tmpFilter)) { return(false); } // Add valid filter to list. tmpFilters.Add(tmpFilter); // Reset modifyer and argument / flags. modifyer = Modifyer.NONE; argument = Argument.NULL; } // Contine to next loop so that arg value will be processed. continue; } // Make sure regular argument value combo is valid. if (!Filter.TryParse(argument, modifyer, token, out Filter tmpfilter)) { return(false); } // Add valid filter to list. tmpFilters.Add(tmpfilter); // Reset modifyer and argument / flags. modifyer = Modifyer.NONE; argument = Argument.NULL; } // If the last argument never recieved a value, then we have an invalid string. if (!(modifyer == Modifyer.NONE && argument == Argument.NULL)) { return(false); } // Create Display filter and indicate successful result. displayFilter = new DisplayFilter(tmpFilters); return(true); }