|
Nah, my Message classes are DataContract objects... Don't want anything but basic accessors and mutators in there. And besides, all of those OnXMessage functions ARE virtual... This is the base class for different types of automated clients... The individual jobs just override the handler for the messages they want to react to.
|
|
|
|
|
Some years ago, I worked at the German office of a big international hospital information system manufacturer. The server was written in MUMPS (that's really a disease...), and lots of the code were developed at the US head quarters.
Some day, we had problems in the communication between computers. Eventually we found out that our American colleagues stored IP addresses in two floating point numbers and then concatenated them with a ".", something like address=float1+"."+float2
It worked fine in the US, but in Germany we use a decimal comma instead of a decimal point, and "192,168.109,47" is not a correctly formed IP address...
|
|
|
|
|
Easy to fix. You can use the code we use at our company to convert floats between european/american decimals notation:
Function CAMBIADECIMAL(ByVal NUMERO As String, ByVal TIPO As Integer) As String
Dim I As Integer
Dim J As Integer
Dim ss As String
Dim ss1 As String
Dim PARTE1 As String
Dim PARTE2 As String
Select Case TIPO
Case 1
ss = NUMERO
I = ss.IndexOf(".")
If I > 0 Then
J = ss.Length - I - 1
PARTE1 = ss.Substring(0, I)
PARTE2 = ss.Substring(I + 1, J)
ss1 = PARTE1 + "," + PARTE2
Return (ss1)
End If
Return ss
Case 2
ss = NUMERO
I = ss.IndexOf(",")
If I > 0 Then
J = ss.Length - I - 1
PARTE1 = ss.Substring(0, I)
PARTE2 = ss.Substring(I + 1, J)
ss1 = PARTE1 + "." + PARTE2
Return (ss1)
End If
Return ss
End Select
End Function
|
|
|
|
|
Here in Argentina we also use comma as floating point separator, and the correct code that always works is:
a) to retrieve the current decimal separator:
System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator
b) to output ANY float using "." as its decimal separator
[a float].ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
c) to parse using an invariant culture, with "." as decimal separator.
System.Convert.ToSingle("3.1415926", System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
|
|
|
|
|
Hey, take it easy! I was just posting another horror
|
|
|
|
|
Is there any requirement that any particular octet of an IP address always be non-zero? I would think that if e.g. using a subnet mask of 255.255.254.0, an IP address of 192.168.1.0 or 192.168.0.3 would be perfectly valid.
|
|
|
|
|
public class DateTimeExtended
{
protected static readonly Logger Log = NLog.LogManager.GetCurrentClassLogger();
public enum Days { Sun=0, Mon, Tue, Wed, Thu, Fri, Sat };
public static string[] FerialDays = {"0101",
"0501",
"0508",
"0714",
"0815",
"1101",
"1111",
"1225",
};
public static DateTime GetDate()
{
return DateTime.Now;
}
public static string GetDate(string format)
{
try
{
if(String.IsNullOrEmpty(format))
return GetDate().ToString();
else
return GetDate().ToString(format);
}
catch
{
return DateTime.Now.ToString();
}
}
public static string GetHour()
{
return DateTime.Now.Hour.ToString("00") + ":" + DateTime.Now.Minute.ToString("00") + ":" + DateTime.Now.Second.ToString("00");
}
public static int GetDay()
{
return (int) DateTime.Now.Day;
}
public static int GetMonth()
{
return (int) DateTime.Now.Month;
}
public static int GetYear()
{
return (int) DateTime.Now.Year;
}
public static int GetDayOfWeek()
{
return (int) DateTime.Now.DayOfWeek;
}
public static string GetNextMonthStart(DateTime date, int NbMois)
{
DateTime _date = date.AddMonths(NbMois);
return _date.Year.ToString("0000") + "-" + _date.Month.ToString("00") + "-" + "01";
}
public static bool IsDate(DateTime date)
{
try
{
int day = date.Day;
int month = date.Month;
int year = date.Year;
if(month == 2)
{
if(day == 30 || day == 31)
return false;
if(day == 29)
return ((year%4 == 0 && year%100 != 0) || year%400 == 0);
}
if (day == 31)
return !(month == 4 || month == 6 || month == 9 || month == 11);
return true;
}
catch { return false; }
}
public static string GetGuid()
{
return Guid.NewGuid().ToString();
}
public static DateTime GetDateValue(string sVal)
{
DateTime dtRet;
sVal = sVal.Replace("-", "").Replace("/", "");
try
{
int nAdd = 0;
if (Convert.ToInt32(sVal.Substring(0, 2)) < 80)
{
nAdd = 2000;
}
else
{
nAdd = 1980;
}
if (sVal.Length == 6)
{
dtRet = new DateTime(nAdd + Convert.ToInt32(sVal.Substring(0, 2)), Convert.ToInt32(sVal.Substring(2, 2)), Convert.ToInt32(sVal.Substring(4, 2)), 0, 0, 0);
return dtRet;
}
if (sVal.Length == 8)
{
if (sVal.IndexOf("-") > 0)
{
dtRet = new DateTime(nAdd + Convert.ToInt32(sVal.Substring(0, 2)), Convert.ToInt32(sVal.Substring(3, 2)), Convert.ToInt32(sVal.Substring(6, 2)), 0, 0, 0);
return dtRet;
}
dtRet = new DateTime(Convert.ToInt32(sVal.Substring(0, 4)), Convert.ToInt32(sVal.Substring(4, 2)), Convert.ToInt32(sVal.Substring(6, 2)), 0, 0, 0);
return dtRet;
}
if (sVal.Length == 10)
{
dtRet = new DateTime(Convert.ToInt32(sVal.Substring(0, 4)), Convert.ToInt32(sVal.Substring(5, 2)), Convert.ToInt32(sVal.Substring(8, 2)), 0, 0, 0);
return dtRet;
}
return Convert.ToDateTime(sVal);
}
catch (Exception)
{
}
dtRet = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
return dtRet;
}
}
This code has been in use for years, even if it's totaly uselless.
|
|
|
|
|
My favs are:
public static string GetHour() - very confusing if you take a look at functions like GetDay/GetMonth...
public static bool IsDate(DateTime date) - how is this function able not to return true?
Greetings
Covean
|
|
|
|
|
Some developers don't mind multiple returns in one function, but for me, that's a wtf in itself. Not to mention returning a complete statement instead of a value.
V.
|
|
|
|
|
I agree that it is a useless class.
Usually such classes are very useful for future scaling and I do use such classes to make sure that all references are taken from these classes only. It is like creating your own custom controls derived from base controls. Any future modifications are resembled uniformly.
But even after thinking a lot, I couldn't understand what this guy was trying to achieve here. It can't be used for scaling also
|
|
|
|
|
Thanks, that made standing up early on sunday worth it!
|
|
|
|
|
This is the best part of the class
doud wrote: public static string GetGuid()
{
return Guid.NewGuid().ToString();
}
Maybe rename the class to DateTimeExtendedGetNewGuidAsString
10 PRINT "Software is hard. - D. Knuth"
20 GOTO 10
|
|
|
|
|
We all know Math.Round() basically rounds a particular decimal value. But if we look into this method closely it rounds the value to the nearest even value.
For example if we do Math.Round(2.5,0) it will return 2. But we may expect 3 intead of 2. In that case we can use MidPointRounding parameter of
Math.Round() method.
Math.Round can also take a parameter known as MidPointRounding which helps us to select the Rounding option. That means whether we want to round towards even number or to the number away from zero.
For example, when someone do the rounding of 8.5 . MidpointRounding will help to specify whether rounding will be towards the even number (8) or it will be away from zero (9).
http://www.mindfiresolutions.com/MidPointRounding-for-MathRound-method-in-Net-Application-293.php[^]
Cheers,
Eliza
|
|
|
|
|
Wrong forum, this forum is for code that is soo ugly, its own momma vomits when she looks at it.
Your post would be better in "Tips and Tricks".
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
|
Not really relevant to this forum, but it has caught my attention.
Are these really the only two options for rounding in .NET? What if I want (for example) to always round up (i.e. 1.5 becomes 2, but -1.5 becomes -1). That sounds a bit odd at first, but in some banking applications I have worked on that was how it worked because you rounded in the bank's favour. (Banks never miss a trick when it comes to money.)
|
|
|
|
|
Use the Math.Ceiling(1.5) = 2, Math.Ceiling(1.0001) = 2
Math.Ceiling(-1.5) = -1, Math.Ceiling(-1.99999) = -1
...
Is what you are looking for?
PS: If it is, I'll start hiding my savings under my bed
|
|
|
|
|
Well I was thinking more in terms of being able to say something like MidPointRounding.Up, or something like that. I'm basically lazy and prefer to rely on other people to do the grunt work and write the boring little stuff.
It comes into things like currency trading for example. If the bank is calculating the rate at which they want to sell you something (dollars, for example) and they need to round it to a certain number of decimals, they will round it in such a way that is favourable to them. It may be a small thing on each trade, but it adds up.
When they are doing things like calculating interest payments, they use "traditional" rounding.
|
|
|
|
|
Please tell which banks these were for so I can bank elsewhere!
|
|
|
|
|
Not a horror by any means.
(unless you have roundophobia, I guess)
|
|
|
|
|
This is the structure for a MySQL table some anonymous guys from 6ib at the Koninklijk Atheneum Sint-Niklaas[^] created. It's in Dutch, but I'm guessing you'll get the point anyway. The table is supposed to store answers from an enquite.
CREATE TABLE IF NOT EXISTS `antwoorden` (
`id` int(11) NOT NULL auto_increment,
`geslacht` text NOT NULL,
`studeren` text NOT NULL,
`geboorteJaar` int(4) NOT NULL default '0',
`gsm` text NOT NULL,
`prijsGsmToestel` text,
`herlaadmanier` text,
`provider` text,
`bedragPerMaan` text,
`smsPerDag` text,
`belPerDag` text,
`mp3` text NOT NULL,
`prijsMp3` text,
`gebruikMp3` text,
`pc` text NOT NULL,
`aantalPc1` text,
`aantalPc2` text,
`aantalPc3` text,
`aantalPc4` text,
`aantalPc5` text,
`aantalPc6` text,
`aantalPc7` text,
`aantalPc8` text,
`aantalPc9` text,
`aantalPc10` text,
`prijsPc` text,
`pcWerk` text,
`pcSchool` text,
`pcGamen` text,
`pcFilm` text,
`pcComm` text,
`pcSociaal` text,
`pcMuziek` text,
`pcAndere` text,
`pcGebruik` text,
`pcProvider` text,
`pc2000` text,
`pcXp` text,
`pcVista` text,
`pc7` text,
`pcLeo` text,
`pcSnowLeo` text,
`pcLinux` text,
`pcUnix` text,
`pcAndereBest` text,
`pda` text NOT NULL,
`prijsPda` text,
`pdaWerk` text,
`pdaSchool` text,
`pdaGamen` text,
`pdaAndere` text,
`pdaGebruik` text,
`pdaProvider` text,
`tv` text NOT NULL,
`tvGebruik` text,
`tvProvider` text,
`gamen` text NOT NULL,
`play1` text,
`play2` text,
`play3` text,
`xbox` text,
`xbox360` text,
`psp` text,
`pspGo` text,
`gameCube` text,
`wii` text,
`ds` text,
`gameAndere` text,
`consoleAantal` text,
`prijsGames` text,
`digiFoto` text,
`filmCamera` text,
`extHD` text,
`memStick` text,
`videoRec` text,
`dvdSpelRec` text,
`bluRay` text,
`dlToetsMuis` text,
`gameToeb` text,
`surround` text,
`printer` text,
`webcam` text,
`scanner` text,
`enqueteLeuk` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
I think this is just brilliant and the authors should be nominated form the Nobel prize.
EDIT: Check out my blog post[^] about this
Jeroen De Dauw
---
Forums ; Blog ; Wiki
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
modified on Monday, March 22, 2010 8:35 PM
|
|
|
|
|
I do not know the Dutch for "What a load of Crap", but I think you get the gist.
Seriously, we should have a whip round and send them a Databases For Dummies right away.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
I was in Sint-Niklaas only yesterday, as a tourist. Little did I know they actually have software professionals there, I could have set up a meeting and learn something new.
|
|
|
|
|
Tss, I wouldn't nominate them for the Nobel prize... If they can type all of this but forget the last 'd' in the field bedragPerMaan they're not worth it
|
|
|
|
|
Very nice! With "AUTO_INCREMENT=3" they leave even some "empty" lines in between - what will they do with them?
Another guess is that they want to do some data mining, because there you normally remove all normalization. Maybe these guys were a bit smarter than we'd expect from the first view of their table design.
|
|
|
|
|