public Vehicle() { _myLicensePlate = ""; _myHiddenLicensePlate = ""; _myType = VehicleType.Car; _myVehicleId = "0"; WebData = new VehicleWebData(); _isFromWebsite = false; }
private Vehicle(HtmlAgilityPack.HtmlNode htmlData) { // parse the html node to get the info out string licensePlate = htmlData.SelectSingleNode(".//input[@type='text']/@value")?.GetAttributeValue("value", ""); string vehicleTypeVal = htmlData.SelectSingleNode(".//select/option[@selected='selected']/@value")?.GetAttributeValue("value", ""); var hiddenData = htmlData.SelectNodes(".//input[@type='hidden']"); var hiddenId = hiddenData.Where(input => input.Attributes["name"]?.Value.Contains("VehicleUid") == true)?.First()?.GetAttributeValue("value", ""); var hiddenLicPlate = hiddenData.Where(input => input.Attributes["name"]?.Value.Contains("LicensePlateHiddenField") == true)?.First()?.GetAttributeValue("value", ""); _myType = (VehicleType)int.Parse(vehicleTypeVal); _myLicensePlate = licensePlate; _myHiddenLicensePlate = hiddenLicPlate; _myVehicleId = hiddenId; WebData = new VehicleWebData(htmlData); _isFromWebsite = true; }
public static VehicleWebData NextIncrement(VehicleWebData previous) { var oldInfo = previous.LicensePlateTextBox; Regex matcher = new Regex(@"(\S+)(\$ctl)(\d+)(\S+)"); var matches = matcher.Match(oldInfo); var editVal = (matches.Groups.Count == 5) ? matches.Groups[3]?.Value : ""; int number = int.Parse(editVal); number++; MatchEvaluator incrementer = m => m.Groups[1].Value + m.Groups[2].Value + number.ToString("00") + m.Groups[4].Value; VehicleWebData newData = new VehicleWebData(); newData.LicensePlateTextBox = matcher.Replace(previous.LicensePlateTextBox, incrementer); newData.LicensePlateHiddenField = matcher.Replace(previous.LicensePlateHiddenField, incrementer); newData.VehicleUidHiddenField = matcher.Replace(previous.VehicleUidHiddenField, incrementer); newData.VehicleTypeHiddenField = matcher.Replace(previous.VehicleTypeHiddenField, incrementer); newData.VehicleTypeDropDown= matcher.Replace(previous.VehicleTypeDropDown, incrementer); return newData; }