- 1
BuyTickets[i].session.listOfTickets.Add(BuyTickets[i]);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+118
BuyTickets[i].session.listOfTickets.Add(BuyTickets[i]);
Веселая объектная модель.
+121
private void txtModel_KeyPress(object sender, KeyPressEventArgs e)
{
if (getTag() == 3)
{
if (e.KeyChar != 8 && (e.KeyChar < 97 || e.KeyChar > 122) && (e.KeyChar < 65 || e.KeyChar > 90) && e.KeyChar < 192 && e.KeyChar != 37 && e.KeyChar != 63 && e.KeyChar != 42 && e.KeyChar != 91 && (e.KeyChar < 93 || e.KeyChar > 95) && e.KeyChar != 94 && e.KeyChar != 33)
{ e.Handled = true; }
}
else
{
if (e.KeyChar != 8 && (e.KeyChar < 97 || e.KeyChar > 122) && (e.KeyChar < 65 || e.KeyChar > 90) && e.KeyChar < 192)
{
e.Handled = true;
}
}
}
Очередной говнокод: проверка на ввод в текстовом поле, проверяется если форма вызвана для поиска, то допускаются символы шаблона, если нет, то только буквы в любом регистре, и так далее по всем полям формы проверяется
+135
for(int i =0; i<1;i++)
{
if (reader["Brand"].ToString() == addForm.txtBrand.Text) { flag = false; } else { flag = true; break; }
if (reader["Model"].ToString() == addForm.txtModel.Text) { flag = false; } else { flag = true; break; }
if (reader["Year"].ToString() == addForm.numYear.Value.ToString()) { flag = false; } else { flag = true; break; }
if (reader["Capacity"].ToString() == addForm.cboCapacity.Text) { flag = false; } else { flag = true; break; }
string k;
if (addForm.optAuto.Checked) { k = "Auto"; } else { k = "Mech"; }
if (reader["Control Box"].ToString() == k) { flag = false; } else { flag = true; break; }
if (reader["Country"].ToString() == addForm.txtCountry.Text) { flag = false; } else { flag = true; break; }
if (reader["Max speed"].ToString() == addForm.txtSpeed.Text) { flag = false; } else { flag = true; break; }
if (reader["Acceleration to 100 km/h"].ToString() == addForm.txtRacing.Text) { flag = false; } else { flag = true; break; }
if (reader["Engine type"].ToString() == addForm.txtEngine.Text) { flag = false; } else { flag = true; break; }
if (reader["Body"].ToString() == addForm.cboBody.Text) { flag = false; } else { flag = true; break; }
if (reader["Seats"].ToString() == addForm.numSeats.Value.ToString()) { flag = false; } else { flag = true; break; }
if (reader["Doors"].ToString() == addForm.numDoors.Value.ToString()) { flag = false; } else { flag = true; break; }
if (reader["Length"].ToString() == addForm.txtLength.Text) { flag = false; } else { flag = true; break; }
if (reader["Width"].ToString() == addForm.txtWidth.Text) { flag = false; } else { flag = true; break; }
if (reader["Power"].ToString() == addForm.txtPower.Text) { flag = false; } else { flag = true; break; }
if (reader["Drive Gear"].ToString() == addForm.cboTrans.Text) { flag = false; } else { flag = true; break; }
}
Проверка на то, были изменения в форме при вызове редактирования по сравнению с записью в базе
+112
result = result += (od.UnitPrice * od.Quantity);
Источник:
http://msdn.microsoft.com/ru-ru/library/ff852066.aspx#Y0
+120
/// <summary>
/// Calculates and returns a hashcode based on this user's
/// MarketName and default units. The hashcode should be
/// unique for each different combination of MarketName and
/// units.
/// </summary>
/// <returns>An int that may be positive or negative.</returns>
public override int GetHashCode()
{
// A function like this raises innumerable questions. Why did they over ride the
// hash code function? Why did they use an attribute that is not certain to be unique?
// why did they not use the one that is going to be unique? Why did they not cvheck to
// see if the thing they were hasing was not null? When did my life go so far off the rails
// that I have to deal with code like this? How many places call this code? Why did they not
// include any meaningful comments? Why does it suddenly start breaking after the 3.5 upgrade?
// in an effort to avoid thinking about those questions, I've justy changed the has to use the
// unique user id instead of the retarded defaultuserunits hash.
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(this.MarketName);
if (this.DefaultUserUnits != null)
{
sb.Append(Utility.StringUtility.GetJSObjectLiteral(this.DefaultUserUnits));
}
else
{
sb.Append(Utility.StringUtility.GetJSObjectLiteral(this.ID));
}
return sb.ToString().GetHashCode();
}
+124
_videoNum = (byte) (videoNum==0?videoNum:0);
попалось сегодня в исходниках рабочего проекта
+121
public class MainSetting
{
// ...
public void Load(out MainSetting objectToDeserialise) {...}
// ...
}
Использвоание: _mainSetting.Load(out _mainSetting);
+123
static public int MeasureDisplayStringWidth(Graphics graphics, string text,
Font font)
{
const int width = 32;
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap (width, 1,
graphics);
System.Drawing.SizeF size = graphics.MeasureString (text, font);
System.Drawing.Graphics anagra = System.Drawing.Graphics.FromImage(bitmap);
int measured_width = (int) size.Width;
if (anagra != null)
{
anagra.Clear (Color.White);
anagra.DrawString (text+"|", font, Brushes.Black,
width - measured_width, -font.Height / 2);
for (int i = width-1; i >= 0; i--)
{
measured_width--;
if (bitmap.GetPixel (i, 0).R != 255) // found a non-white pixel ?
break;
}
}
return measured_width;
}
Ищем размер нарисованной строки. Не моё. Нашел на codeproject.
(Вместо MeasureCharacterRanges)
+131
string[] strArray1 = new string[6];
string[] strArray2 = strArray1;
int index1 = 0;
DateTime now = DateTime.Now;
string str1 = now.Month.ToString();
strArray2[index1] = str1;
string[] strArray3 = strArray1;
int index2 = 1;
now = DateTime.Now;
string str2 = now.Day.ToString();
strArray3[index2] = str2;
string[] strArray4 = strArray1;
int index3 = 2;
now = DateTime.Now;
string str3 = now.Year.ToString();
strArray4[index3] = str3;
string[] strArray5 = strArray1;
int index4 = 3;
now = DateTime.Now;
string str4 = now.Hour.ToString();
strArray5[index4] = str4;
string[] strArray6 = strArray1;
int index5 = 4;
now = DateTime.Now;
string str5 = now.Minute.ToString();
strArray6[index5] = str5;
string[] strArray7 = strArray1;
int index6 = 5;
now = DateTime.Now;
string str6 = now.Second.ToString();
strArray7[index6] = str6;
Program.zipName = string.Concat(strArray1);
+133
public static string FristChar(this string input)
{
if (!string.IsNullOrEmpty(input))
{
if (input.Length >= 1)
{
return input.Substring(0, 1);
}
else
{
return input;
}
}
else
{
return null;
}
}
http://www.extensionmethod.net/Details.aspx?ID=170
Author: Mehrdad Ghasemi