Implications in using VB.NET method DateAndTime.DateDiff with C# - asp.net

I'm building a new ASP.NET web application based on a legacy one (Classic ASP). The people, who build this code 4, 5 years ago, used a lot of VBScript functions like DateDiff.
I'm currently working on a simulator that does a lot of calculations with dates. And I'm getting a annoying difference between these dates because I don't have a easily manner to get the difference between months in c# like they did in VB 6.
So, I choose the path of using the DateAndTime.DateDiff from Microsoft.VisualBasic namespace on my ASP.NET web application.
You guys know if there are some implications on that? I'm a little concerned with this approach.
Cheers,

The only implication is that you're adding another assembly to your deployment, and using functionality that many C# developers (other people that might need to maintain your code) are not aware of. But personally I don't think there's much wrong with it. The MSDN Library documentation is typically good, and you can also add a few comments if you want to explain why your using it.
Edit: I also want to note that Microsoft.VisualBasic was implemented from scratch for .NET. It does not contain ancient code.

One possibility is to use the TimeSpan as Itay indicated, but divide by 30.4375 (the average days per month), ignoring fractional months. This is close enough for things I'm currently working on, but may not be accurate enough based on your needs. For instance, The difference between February 1 and March 1 would be 0, which (based on a 30.4375 day month definition) is correct; it may not be correct for your particular purposes, however.

It's good thing you are concerned with that, because you should not use any of of the classed in the VisualBasic namespace.
The .net library offer a much better solution called TimeSpan, use it in the following way: (dt1, and dt2 are DateTimes)
TimeSpan ts = dt2 - dt1; //Or ts = dt1.Subtract(dt2)
As far as i would like to help, I really think a quick glance at the intellisence will tell you the rest (just write this in Visual Studio, and add ts.)
EDIT for real month counting: (y2 - y1) * 12 + m2 - m1, what the big deal?

Related

is it the right way to do the project with asp.net mvc 4 and stored procedures?

Can you please spend ur time 4 this and help me as it is a big project if we do mistakes noe we will repeat the same mistake in next 3 years.
we are starting a new big project in asp.net mvc4, Html5 and CSS3 (We preffer these Because our application should target tablet, desktop, mobile).
So I feel bec its new we can better start with code first approach(latest) like first creating classes and prepare db(sql express) and deploy well and also we have support of EF migrations, So I think that way the proj become more successful and maintainable easily.
But the small concern with the manager, I dont know whether he is correct or iam wrong bec he has good experience in working but he is also new to MVC. below is my query ive explained pls look into this,
-Database with tables are ready.
-Now we have to start the project. (I think we can do code first reverse engineering and start)
But, For that our manager asked our team to prefer and write stored procedures, and use asp.net mvc 4?
My question is, is it the right way to do the project with that combination? Why am asking you is I have been watching videos/tutorials through online they never said the samples with that combination and all are saying with out using stored procedures, is it any problem like performance we will not get as we are using storedprocedures through EF OR because we are using stored procedures in backend we will get performance and maintaing easily as our PM says,
Iam totally confused???? please help me in this if you have solution.
There is no any issue using stored procedure in MVC, you can go for it. There would be worth reading this about your performance question.
If controller is not depended on the implementation of data access layer then no matter what you use whether EF or Stored procedure, you are good to go.
Darin Dimitrov already explain it about here.
That videos doesn't represend examples of using stored procedures, because they doesn't need stored procedures! All of results from SPs can be achived by EF easily and with much less effort and waisting times.
However, you should consider 3 things:
1) It seems that you all are new to EF. So, using EF is a potentially thechnical risk for your project!
2) Keep in mind that EF will cause some overhead to your app and if you're creating an app which works with huge data or should handle many requests at once, maybe it's better for you to keep going through SPs.
3) From the other hand, if you get familar with EF, it will dramatically progress your project fast and easy because of its useful abstractions and conventions.
So, first know your project, then deside which way you should go...

Migrating from asp to asp.net - What are classic ado's recordset 'replacements'?

I've tried to do my homework on this...
I'm migrating a site from classic asp to asp.net 4.0
Before I rework all the code, I wanted to get clarification that the way i think my database code should be updated is fairly correct. (I'm using SQLClient objects)
First, when old code would use forward only recordsets or access single record/value, I'm fairly sure i'd use SqlCommand and SqlDataReader. That is pretty straightforward.
Now, when my old code navigates a recordset (movePrevious, find, etc.)... I believe the way to go is with SqlDataAdapter and DataTable to retrieve the data and DataView to filter/find/navigate the data.
I'n looking to do a quick migration... i don't want to get too bogged down in the new entity framework... so - just trying to stick with similar objects/logic.
I know this is one of those questions that doesn't really have a right/wrong answer... and I think that is part of my problem in finding an answer - there are so many.
Thanks,
bill g
I answered something similar here.
You only really need to know about the database bit here. For you it's a really good point to start as you mean to go on.
It terms of how deal with the data returned, it's up to you. I'd recommend custom class style dataset approach which will make life easier in the long run but of course in the short term, you'll have to generate them all which can be made easier by CodeSmith*. That in itself has an upfront cost but will, again, save time in the long run.
*Other code generation tools are available.
If your main issue is the database I propose to move and learn the Subsonic 2 (not subsonic 3, too slow) or any other DAL.
See here some examples:
http://subsonicproject.com/docs/Main_Page
Take some time to understand it, make some tests, see what really do, after wille you can't do with out it, but you need some time to understand the logic, and setup it to your project.
Get this project to play with and see some dal in action, ready to run.

A detailed explaination of what is "wrong" with date handling in GWT

I have seen countless forum posts complaining of issues in GWT when handling dates. I am still very unclear as to what is "wrong" with the date handling, what special considerations need to be made, and when/where/why methods like Date.setMinutes(int minutes) should not be used.
Does anybody have feedback?
Way back in the beginning of Java (i.e., Java 1.0), the date/time api largely (solely?) consisted of the Date class. The Java folks were aware that it lacked robustness, so they added the Calendar class in Java 1.1 and tried to change the Date class into a value object by deprecating most of it. Unfortunately, the Calendar class itself wasn't very well thought-out (see here) and we're stuck with what many consider to be a monstrosity.
Bringing us up to today, GWT supports Date because, well... how can you live without dates?, but doesn't support Calendar/GregorianCalendar/TimeZone because it's so ugly and surely there has to be a better answer. Sadly, no one's thought of it in over 3 years as Calendar support was requested way back in January of 2007 and marked as planned by April 2008.
In short, go ahead and use the the deprecated Date methods in your GWT code, if that will work for what you need to do.
EDIT: GWT's CalendarUtil class might also come in handy.

ASP.NET Scaffolding/Templating CRUD Solutions

I've been looking into ASP.NET Dynamic Data and how it does scaffolding and routing. I've only scratched the surface, but it's looking like I'd have to create a template for each table that I didn't want to display all columns the same way.
My first impression after looking at dynamic data is that it would seem like less time on the programmer to have to edit one-time generated user controls rather than build a template for each table that doesn't have a uniform display behavior.
What proven solutions are people currently using that help ease the laborious tasks of creating ASP.NET CRUD type user controls?
Thanks
In ASP.NET webforms we use CodeSmith. From a single entity we generate admin pages, codebehinds, service layers, data layers and db stored procedures. All in a matter of seconds. I'd recommend you check it our for quickly building the crud in your apps.
We're actually working on our own code generation tool. It has already proven to work perfectly on the lower layers and now we're on the way to extend it for the presentation layer, that is for generating user controls.
I've not looked into dynamic data (although I'd like to when I have some time) but my biggest fear is always to lose flexibility. The problem is that these front-ends are then maybe generated dynamically each time based on some template and editing, especially bringing in special customer wishes becomes quite difficult. For small standard apps it may work perfectly though.
What we're therefore doing is to "generate" these usercontrols based on a set of standard custom server controls we've developed, but we'll generate just the first time from some static information about the entities in our application. Then you can continue customizing.
Such systems should help the developer, improving his development speed, doing the initial awkward work but then they should give him the flexibility to modify till the maximum. They should not add additional complexity...
I used .netTiers CodeSmith templates long time ago (years) and it was proven so strong, so, it must be more than great now.
I know a (big) company who have built a customization engine (allowing GUI for internal company options) around those templates to use them in most of their applications and were so successful.
I've used http://www.ironspeed.com/ in the past which has been great. Saved us MONTHS of time on our last project which has a big DB, so the cost is worth it. But it looks a bit ugly and can be tricky to update the DB schema once you've generated.
Obviously not much widespread use out there other than whats provided in Visual Studio.
Have a look at Blinq.

DateTime Utility for ASP.net

I was wondering if anyone could suggest a utility library that has useful functions for handling dates in ASP.NET easily taking away some of the leg work you normally have to do when handling dates?
Subsonic Sugar has some really nice functions:
http://subsonichelp.com/html/1413bafa-b5aa-99aa-0478-10875abe82ec.htm
http://subsonicproject.googlecode.com/svn/trunk/SubSonic/Sugar/
Is there anything better out there?
I was wanting to work out the start(mon) and end(sun) dates of the last 5 weeks.
I was thinking something like this:
DateTime Now = DateTime.Now;
while(Now.DayOfWeek != DayOfWeek.Monday)
{
Now.AddDays(-1);
}
for(int i=0; i<5;i++)
{
AddToDatesList(Now, Now.AddDays(7));
Now.AddDays(-7);
}
but this seems crappy? Plus this is not exactly what i want because i need the time of that start date to be 00:00:00 and the time of the end date to be 23:59:59
Is there a specific problem you are trying to handle with dates? If the existing date API in .NET can handle your problem cleanly, I see no reason to consider a 3rd party library to do it. When I was in .NET, we had to deal with dates quite a bit, and the standard libraries provided a fair amount of functionality to us.
What exactly do you want to do that System.DateTime and System.Timespan can't handle?
CSLA has a useful helper class called SmartDate that addresses quite a lot of the problems when using dates in real applications. As far as I can recall it's coupled to the rest of the framework.

Resources