- 1
- 2
- 3
- 4
- 5
- 6
if ( check < 50000 ) {
primaryAnimation = primaryAnimation;
} else {
int ani = (check - 50000) / 100;
primaryAnimation = _OptionalAnimations["Run"][ani];
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+116
if ( check < 50000 ) {
primaryAnimation = primaryAnimation;
} else {
int ani = (check - 50000) / 100;
primaryAnimation = _OptionalAnimations["Run"][ani];
}
Найдено в недрах загрузчика MD2-моделек для XNA.
+115
public void chkStatus_OnCheckedChanged(object sender, EventArgs e)
{
CheckBox chkStatus = (CheckBox)sender;
GridViewRow row = (GridViewRow)chkStatus.NamingContainer;
string cid = row.Cells[1].Text;
bool status = chkStatus.Checked;
string constr = @"Server=.\SQLEXPRESS;Database=TestDB;uid=waqas;pwd=sql;";
string query = "UPDATE Categories SET Approved = @Approved WHERE CategoryID = @CategoryID";
SqlConnection con = new SqlConnection(constr);
SqlCommand com = new SqlCommand(query, con);
com.Parameters.Add("@Approved", SqlDbType.Bit).Value = status;
com.Parameters.Add("@CategoryID", SqlDbType.Int).Value = cid;
con.Open();
com.ExecuteNonQuery();
con.Close();
LoadData();
}
Полезный говнокод
+119
// создаём источник для репитера
private DataTable EventsDataTable
{
get
{
DataTable dt = new DataTable();
dt.Columns.Add(
new DataColumn("ID", typeof(string)));
dt.Columns.Add(
new DataColumn("day", typeof(string)));
dt.Columns.Add(
new DataColumn("date", typeof(DateTime)));
dt.Columns.Add(
new DataColumn("title", typeof(string)));
dt.Columns.Add(
new DataColumn("url", typeof(string)));
dt.Columns.Add(
new DataColumn("description", typeof(string)));
dt.Columns.Add(
new DataColumn("location", typeof(string)));
dt.Columns.Add(
new DataColumn("place", typeof(string)));
dt.Columns.Add(
new DataColumn("FileDirRef", typeof(string)));
// Добавляем строчки
foreach (EventInfo ei in CalendarEvents)
{
DataRow dr = dt.NewRow();
dr["day"] = ei.EventDate.Date.ToString("ddMMyyyy");
dr["date"] = ei.EventDate;
dr["title"] = ei.Title;
dr["location"] = ei.Location;
dr["ID"] = ei.ID;
dr["FileDirRef"] = ei.FileDirRef;
dt.Rows.Add(dr);
}
return dt;
}
}
protected void repeaterItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e != null
&& e.Item != null
&& e.Item.DataItem != null
&& e.Item.DataItem is DataRow)
{
DataRow dataItem = (DataRow)e.Item.DataItem;
Label date = (Label)(e.Item.FindControl("date"));
date.Text =
dataItem["date"] != null
? Convert.ToDateTime(dataItem["date"].ToString()).ToString()
: Convert.ToDateTime(dataItem["Created"].ToString()).ToString();
date.Text = date.Text.Substring(0, date.Text.Length - 3);
HyperLink title = (HyperLink)(e.Item.FindControl("title"));
title.Text = dataItem["title"].ToString();
Label location = (Label)(e.Item.FindControl("location"));
location.Text = "Расположение: " + dataItem["location"].ToString();
}
}
Современный способ привязки данных в asp.net Repeater
+120
var trimmedKey = Regex.Split(key, @"\.").Last();
if (_options.Any(o => o == ModelBinderOptions.ExpectUnderLineSymbolAsPrefixDelimiter))
trimmedKey = Regex.Split(trimmedKey, "_").Last();
if (_allRequiredParameters.Any(p => p.Key.ToLower() == trimmedKey.ToLower()))
{
var param = _allRequiredParameters.Single(p => p.Key.ToLower() == trimmedKey.ToLower());
try
{
if (param.Value != typeof(string))
{
if (Nullable.GetUnderlyingType(param.Value) != null)
{
try
{
var parseMethod = Nullable.GetUnderlyingType(param.Value).GetMethods().Where(m => m.Name == "Parse").First(m => m.GetParameters().Count() == 1 && m.GetParameters().First().ParameterType == typeof(string));
var value = parseMethod.Invoke(null, new object[] { form[key] });
formValues.Add(param.Key, value);
}
catch(Exception)
{
formValues.Add(param.Key, null);
}
}
else
{
var parseMethod = param.Value.GetMethods().Where(m => m.Name == "Parse").First(m => m.GetParameters().Count() == 1 && m.GetParameters().First().ParameterType == typeof(string));
var value = parseMethod.Invoke(null, new object[] { form[key] });
formValues.Add(param.Key, value);
}
}
else
{
formValues.Add(param.Key, form[key]);
}
}
catch (Exception)
{
// Если произошла ошибка парсинга - печально, но ничего не поделать
}
}
Фееричный парсер
+130
private static bool? GetBoolFromObject(object o)
{
return string.IsNullOrEmpty(o.ToString()) ? (bool?)null : (bool)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" !!!)){}
}