Using Visual Studios 2013 and VB.net, how to capitalize lets in a textfield mixed with numbers - vb.net

I am and entry level programmer and i have a task that is asking me to modify a page that takes and entry from a textfield that is mixed with letters and numbers. this field is called a "job#" and then the page will search a database for that in particular job. problem is that it only searches it if its in capital letters. need to have it accept caps and lower case letters. it is in VB.net. and i went to the controller and i have this code here
Try
res.success = True
res.message = ""
Dim r = New Objects.Business.Capital.CapitalRequest(jobNumber)
Dim req = New ViewModels.Business.Capital.CapitalRequest(r)
Models.Core.Approvals.AddIApprovableToCache(r)
res.data = req
Return New PCA.Core.Web.JSON.JSONPResult() With { _
.Data = res,
.Callback = callback
}
i tried to tack on "ToUpper() after the (jobnumber) because i thought that is where it takes the number entered and applies it to a variable to search the database for it. but it says that 'ToUpper()' is not a member of 'Trident.Objects.Business.Capital.CapitalRequest' im assuming the parent class doesnt have the package where ToUpper() is ?

i tried to tack on "ToUpper() after the (jobnumber) because i thought
that is where it takes the number entered and applies it to a variable
to search the database for it. but it says that 'ToUpper()' is not a
member of 'Trident.Objects.Business.Capital.CapitalRequest'
Instead of
Dim r = New Objects.Business.Capital.CapitalRequest(jobNumber).ToUpper()
use
Dim r = New Objects.Business.Capital.CapitalRequest(jobNumber.ToUpper())

Related

How to convert 'Integer' to 'Timestamps'?

**I did a effort but got error while testing
Error BC30311 Value of type 'Integer' cannot be converted to 'Timestamps'.**
I have tried this :
Public Sub test()
client = New DiscordRpcClient("test")
client.Logger = New ConsoleLogger
client.Initialize()
client.SetPresence(New RichPresence With {
.Details = "test",
.Assets = New Assets() With {
.LargeImageKey = "test",
.LargeImageText = "test",
.Timestamps = 0
})
Dim timer = New System.Timers.Timer(150)
AddHandler timer.Elapsed, Sub(sender, args)
client.Invoke()
End Sub
timer.Start()
client.Invoke()
End Sub
here the problem is "Timestamps = 0", So how can i solve.
im trying to use discord rich Presence elapsed timer.
This is actually more of an issue with this Discord-RPC-Csharp library than it is with C#. That being said, I looked into it anyway.
The example code given in the repository for this project shows this as an example
Timestamps = Timestamps.FromTimeSpan(10)
See the error you got is an error specific to C# for when trying to assign one value type to a complete different type. An Integer is not a Timestamp, and a Timestamp is not an Integer. So we need to figure out what Timestamps actually is. So the best way to do this is to right-click on Timestamps and go to "Go To Definition" or hit F12 on it.
Now in RichPresence.cs you can see the class definition for Timestamps. You will see four options
Timestamps.Now
Timestamps.FromTimeSpan(double seconds)
Timestamps.FromTimeSpan(Timespan timespan)
in addition to a constructor
new Timestamps(DateTime start, DateTime end)
Since you haven't told us what this timestamp is supposed to represent in your code, I'll leave it to you to figure out which one of these you want/need to use.

C# RavenDB delete

I have the following object:
WordOccurrence, which has two attributes:
- string word.
- int occurrences.
I would like to do the following, without getting an exeception (-:
WordOccurrence w1 = new WordOccurrence() {Word ="Hey", Occurrence = 1};
WordOccurrence w2 = new WordOccurrence() {Word ="Hey", Occurrence = 1};
now I would like to store the first one , w1, but with w2 to delete him.
session.store(w1);
session.delete(w2); -> gets exeception...
is it possible??
Please try formatting the code in your question, and rephrasing what you are trying to do. It isn't clear if you're expecting that saving w2 should refer to the same object as w1, but they aren't - even if the ID is the same that isn't how Raven will handle the delete. You need to either delete the object you just stored immediately after you call SaveChanges (which I don't understand why you would want to do), or in the more likely scenario Load it at some point later on and then call Delete:
var w1Id = string.empty;
using(session)
{
var w1 = new WordOccurrence { Word="Hey", Occurrence=1};
session.store(w1);
session.SaveChanges();
w1Id = w1.Id;
//if you aren't declaring the Id property for some reason...
w1Id = session.Advanced.GetDocumentId(w1);
}
//somewhere else in the code
using(session)
{
var w1 = session.Load<WordOccurrence>(w1Id);
session.Delete(w1);
session.SaveChanges();
}
Bottom line is that you can't delete something you just told the session to Store, before you even called SaveChanges. If you're trying to undo a Store operation, perhaps because the user hit an undo button, just don't call SaveChanges (if it's the only operation in the session), or use Session.Advanced.Evict(w1) to evit that object from the session.
If you are expecting the Word property to be the Id of the document you can make that happen by customizing the DocumentStore conventions

Getting "Editor" field value throws the value range exception under a non-System account

Below's the piece of legacy code of migration from 2007 to 2010. It gets the values of the author and the editor fields. The values are the same user, actually. When I login under the SPAdmin rights, both fields work okay. However, under a test account, the attempt to get the value of the Editor field fails with the following exception: "Value does not fall within the expected range", while the Author field still works fine. Let's see the code:
SPQuery sPQuery = new SPQuery();
sPQuery.Query = queryString;
sPQuery.ExpandRecurrence = true;
sPQuery.CalendarDate = startDateTime;
sPQuery.DatesInUtc = false;
SPListItemCollection items = list.GetItems(sPQuery);
SPListItem item = items[0];
object author = item["Author"]; //works always, under any account
object editor = item["Editor"]; // **doesn't work under non-system account**
Well, here is the line of code that always works for the Editor too:
object editor = item.ParentList.GetItemById(item.ID)["Editor"];
So I wonder what wrong with that and what should I check.
Thanks.
Well, the problem was in the the lookup threshold limitation.

Entity Model Not Being Updated on SaveChanges

I have a misunderstanding somewhere with the Entity Framework. This code is from my unit testing:
Public Sub UpdateRosterLinkTest()
Dim target As PlayerAdmin = New PlayerAdmin()
target.PlayerAdminManager = playerAdminTestManager
target.Team = playerAdminTestManager.GetAirForceMensBB()
playerAdminTestManager.resetRosterLink(target)
Assert.IsNull(target.Team.RosterLink)
Dim playerAdmin As PlayerAdmin = New PlayerAdmin()
playerAdmin.TeamId = 12434
playerAdmin.RosterLink = "Roster Link"
playerAdmin.UpdateRosterLink()
Dim team As DAL.Team = playerAdminTestManager.GetAirForceMensBB()
Assert.AreEqual("Roster Link", team.RosterLink)
End Sub
I'm creating a PlayerAdmin, which is a model class. target.Team is an Entity object. What I do is reset the RosterLink field in the Team just to make sure our test starts out at the same place. Then I call the UpdateRosterLink() function. That looks like:
Function UpdateRosterLink() As Integer
If (PlayerAdminManager Is Nothing) Then
PlayerAdminManager = New PlayerAdminManager()
End If
Team = PlayerAdminManager.GetTeamByTeamId(TeamId)
Team.RosterLink = RosterLink
Dim numberOfChanges As Integer = PlayerAdminManager.SaveChanges()
Return numberOfChanges
End Function
When I run this code, I can see the changes saved to the SQL Server this pulls from (RosterLink = Roster Link, like I set in the unit test).
However, my unit test is failing, because team.RosterLink is still Nothing. The function GetAirForceMensBB() returns the Team with TeamId = 12434:
Function GetAirForceMensBB() As DAL.Team
Return (From team In Container.Teams Where team.TeamId = 12434).SingleOrDefault
End Function
I'm sure I'm using the entity framework incorrectly and it probably has something to do with the fact that I am calling the PlayerAdminTestManager in different places, but I don't understand why. Although, I set the PlayerAdminManager to be the PlayerAdminTestManager. PlayerAdminTestManager extends PlayerAdminManager, fyi.
Why is team.RosterLink not showing the update from UpdateRosterLink?
Thanks
EDIT
Container is my ObjectContext. This is how I access the information stored in the database. Container.Teams represents my Teams table.
The problem was I was referencing different instantiations of the Container (each manager created its own). Thus, the entity items were not attached to anything.
Doh!

Is it possible to pass a variable's name along with the value, when passing through functions?

I want to know if it's possible to retrieve the variables name from when it was passed into a certain function. For example, if I call parseId(myId) to a function with the signature parseId(id), i can obviously retrieve the value of 'id'. However, is there any way I can retrieve 'myId' as a string (without passing it as another value)?
Specifically in vb.net, but I'm interested in how it would work in any given language.
This is all just random thoughts.. feel free to dismiss or not ;-p
Re your comment about use with stored procedures... if you want to go that route, I wouldn't mess around with the local variable names; that is an implementation detail. However, you could expose those details on an interface method and use the names from there, since that is more formalised - for example (C#):
interface ICustomerRepository {
Customer GetById(int id); // perhaps an attribute to name the sproc
}
You can use similar expression-tree parsing (as discussed here) to get the name and value of the parameter, for example:
var repoWrapper = new Repo<ICustomerRepository>();
int custId = 12345;
var cust = repoWrapper.Execute(r => r.GetById(custId));
Here we'd want to resolve the argument to GetById as "id" (not "custId"), with value 12345. This is actually exactly what my protobuf-net RPC code does ;-p (just don't ask me to translate it to VB - it is hard enough to write it in a language you know well...)
No, you can't do that in the normal sense. What are you really trying to accomplish with this?
You can do this in .NET 3.5 and above using expression trees; I'll knock up a C# example, and try to run it through reflector for VB...
C#:
static void Main()
{
int i = 17;
WriteLine(() => i);
}
static void WriteLine<T>(Expression<Func<T>> expression)
{
string name;
switch (expression.Body.NodeType)
{
case ExpressionType.MemberAccess:
name = ((MemberExpression)expression.Body).Member.Name;
break;
default:
throw new NotSupportedException("Give me a chance!");
}
T val = expression.Compile()();
Console.WriteLine(name + "=" + val);
}
The VB is below, but note that the VB compiler seems to use different names (like $VB$Local_i, not i):
Sub Main()
Dim i As Integer = 17
WriteLine(Function() i)
End Sub
Private Sub WriteLine(Of T)(ByVal expression As Expression(Of Func(Of T)))
If (expression.Body.NodeType <> ExpressionType.MemberAccess) Then
Throw New NotSupportedException("Give me a chance!")
End If
Console.WriteLine((DirectCast(expression.Body, MemberExpression).Member.Name
& "=" & Convert.ToString(expression.Compile.Invoke)))
End Sub