- 1
for(dynamic o=0; o!=237; o++){
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+132
for(dynamic o=0; o!=237; o++){
Ох, что мне досталось поддерживать... dynamic почти везде... :( Кто это написал??? Хочу этого человека взять и @#$%^&... :(
+128
public string GetUserCurrentStage(int stage)
{
string stageName = "";
if (stage == 1)
stageName += "Initial Certification";
else if (stage == 2)
{
stageName += "Maintenance *";
}
else if (stage == 3)
stageName += "Recertification";
else
return string.Empty;
return stageName;
}
Когда платят за строчки кода...
+123
this.Border1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(111)))), ((int)(((byte)(111)))), ((int)(((byte)(111)))));
Встретилось такое внутри сгенеренной системой InitializeComponent()
+127
try
{
this.DBConn.Open();
}
catch (Exception)
{
try
{
this.DBConn.Close();
this.DBConn.Open();
}
catch (Exception ex)
{
System.Diagnostics.EventLog.WriteEntry("Agent", "Ошибка подключения к базе данных: " + ex.ToString(),
System.Diagnostics.EventLogEntryType.Error);
return;
}
}
Поразительная настойчивость
+125
protected string getUpdateNotesDE(string fieldNameAlias, string fieldName, string fieldValue, ASPxDateEdit newValue)
{
if (isSaveField("fieldName"))
{
if (fieldValue != "")
return "Field " + locCom.getFieldAlias("payTFNDeclaredOn") + ", Old Value = " + Convert.ToDateTime(fieldValue).ToString("dd/MM/yyyy") + ", New Value = " + Convert.ToDateTime(newValue.Text).ToString("dd/MM/yyyy") + " ; ";
else
if (newValue.Text != "")
return "Field " + locCom.getFieldAlias("payTFNDeclaredOn") + ", Old Value = , New Value = " + Convert.ToDateTime(newValue.Text).ToString("dd/MM/yyyy") + " ; ";
}
return "";
}
protected Boolean isSaveField(string fieldName)
{
if (locCom.getVisible(fieldName))
return true;
return false;
}
public bool getVisible(string fldName)
{
Boolean showall = Convert.ToBoolean(System.Web.Configuration.WebConfigurationManager.AppSettings.Get("Show-all-fields"));
if (showall) return true;
if (fldAccess.Tables.Count == 0) return false;
foreach (System.Data.DataRow item in fldAccess.Tables[0].Rows)
{
if (item["fieldname"].ToString().Replace('@', 'a').Replace("%", "percent").Replace("$", "dollar").ToLower() == fldName.ToLower())
return Convert.ToBoolean(item["visible"]);
}
return false;
}
особенно доставляет
protected string getUpdateNotesDE(string fieldName){
if (isSaveField( !!! "fieldName" !!!)){}
}
+129
public void ReadFromFile()
{
LoadIntervals = new TimeIntervals(Color.Black);
StreamReader tReader = null;
tReader = File.OpenText("DefaultIntervals");
string income = null;
while ((income = tReader.ReadLine()) != null)
{
// string income = tReader.ReadLine();
string colorR = null; string colorG = null; string colorB = null; string colorA = null; string interval = null;
int i = 0;
for (i = 4; i < income.Length; i++)
{
if (income[i] != ',')
{
interval += income[i];
}
else { break; }
}
for (int a = i + 10; a < income.Length; a++)
{
if (income[a] != ',')
{
colorA += income[a];
}
else
{
for (int r = a + 4; r < income.Length; r++)
{
if (income[r] != ',')
{
colorR += income[r];
}
else
{
for (int g = r + 4; g < income.Length; g++)
if (income[g] != ',')
{
colorG += income[g];
}
else
{
for (int b = g + 4; b < income.Length; b++)
if (income[b] != ',')
{
if (income[b] != ']')
colorB += income[b];
}
else
{
break;
}
break;
}
break;
}
}
break;
}
}
TimePoint tp = new TimePoint(Convert.ToDouble(interval), Color.FromArgb(Convert.ToInt32(colorA), Color.FromArgb(Convert.ToInt32(colorR), Convert.ToInt32(colorG), Convert.ToInt32(colorB))));
LoadIntervals.Add(tp);
}
tReader.Close();
Intervals = LoadIntervals;
}
Так мы парсим файл конфигов вида. (Формат придуман автором кода)
Int=3,Color [A=223, R=253, G=4, B=38]
Int=10,Color [A=255, R=86, G=86, B=185]
Int=20,Color [A=200, R=255, G=215, B=0]
Int=50,Color [A=200, R=255, G=165, B=0]
+128
if (body.ToLower().Contains("pr") ||
subject.Contains("PM") ||
subject.Contains("pm") ||
subject.Contains("Pm") ||
subject.Contains("pM") ||
subject.Contains("PMR") ||
subject.Contains("prs") ||
subject.ToLower().Contains("prt") ||
subject.ToLower().Contains("prm") ||
subject.ToLower().Contains("pmt") ||
subject.ToLower().Contains("pmk") ||
subject.ToLower().Contains("pml") ||
subject.ToLower().Contains("pal"))
{
result = true;
}
Пишут друзья из Норвегии
+126
public static bool ValidateEmailAddress(string emailAddress)
{
try
{
string TextToValidate = emailAddress;
// test email address with expression
if (emailExpression.IsMatch(TextToValidate))
{
// is valid email address
return true;
}
else
{
// is not valid email address
return false;
}
}
catch (Exception)
{
throw;
}
}
public static bool ValidateEmailAddress(string emailAddress)
{
if(string.IsNullOrEmpty(emailAddress))
return false;
return emailExpression.IsMatch(TextToValidate);
}
+127
private string CalculateDecadeOrYear(string year)
{
string decade = year.Remove(3) + "0";
string currentYear = DateTime.Now.Year.ToString();
string currentDecade = currentYear.Remove(3) + "0";
string prevDecade = ((Convert.ToInt32(currentYear.Remove(3)) - 1)).ToString() + "0";
if (!(decade == currentDecade) && !(decade == prevDecade))
{
return decade;
}
return year;
}
stringly typed вычисление декады. нашел в исходниках индусов
+121
// первай варянт
string[] GetMonth =
{
"Январь", "Февраль", "Март", "Апрель",
"Май", "Июнь", "Июль", "Август", "Сентябрь",
"Октябрь", "Ноябрь", "Декабрь"
};
for (int i = 1; i <= 12; i++)
{
Console.WriteLine(GetMonth[i]);
}
// вторый варянт
System.Globalization.DateTimeFormatInfo mfi = new System.Globalization.DateTimeFormatInfo();
for(int i = 1; i <= 12; i++)
{
string strMonthName = mfi.GetMonthName(i).ToString();
Console.WriteLine(strMonthName);
}
Как в C# автоматически получить массив или список всех месяцев года (январь ... декабрь)?