1. C# / Говнокод #9469

    +116

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    bool IsAdd = false;
    
    
                if (EditAnalysisTable.Rows.Count == 1)
                {
                    if (EditAnalysisTable.Rows[0][4].ToString() == string.Empty)
                    {
                        drow = EditAnalysisTable.Rows[0];
                    }
                    else
                    {
                        IsAdd = true;
                    }
                }
                else
                {
                    IsAdd = true;
                }
                if (IsAdd)
                {
                    drow = EditAnalysisTable.NewRow();
                    EditAnalysisTable.Rows.Add(drow);
                }

    Indian style: у них свои законы логики

    Nataly, 17 Февраля 2012

    Комментарии (2)
  2. C# / Говнокод #9467

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    if ((ddlProbType.Text != "" && ddlProbType.Text != "Select") && (txtDesc.Text != ""))
                {
                    if ((txtDesc.Text.Trim() == string.Empty))
                    {

    Indian style: чем больше скобок, тем лучше!

    Nataly, 17 Февраля 2012

    Комментарии (8)
  3. C# / Говнокод #9445

    +120

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    //запись в журнал расчетов
    try
    {
        ompDataSet.OMP_History.AddOMP_HistoryRow(DateTime.Now, row["N"].ToString(), Convert.ToInt32(row["M"]), PS1I??0, PS1U??0, PS2I??0, PS2U??0, I1 / 1000, U1 / 1000, I2 / 1000, U2 / 1000, KZ, (Zone1.EditValue != null) ? Convert.ToDouble(Zone1.EditValue) : 0, (Zone2.EditValue != null) ? Convert.ToDouble(Zone2.EditValue) : 0, "", PS1_DeviceA.SelectedIndex, PS2_DeviceA.SelectedIndex, (Branch.Count > 0) ? true : false, "", "", "Время откл.: " + OffDT.DateTime.ToString("dd.MM.yyyy HH:mm") + "\n" + Lkz.ToolTip.Replace("\n", ";"));
        omp_HistoryTableAdapter.Update(ompDataSet);
        ompDataSet.OMP_History.AcceptChanges();
    }
    catch
    {
        XtraMessageBox.Show("Не удалось сохранить данные в журнал расчётов!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
    
    try
    {
        ompDataSet.Result.Clear();
        ompDataSet.Result.AddResultRow(((KeyValuePair<string, int>)NumberVL.EditValue).Key, ((KeyValuePair<string, int>)NumberVL.EditValue).Value, PS1I ?? 0, PS1U ?? 0, PS1I ?? 0, PS2U ?? 0, Convert.ToDouble(I0_A.EditValue), Convert.ToDouble(U0_A.EditValue), Convert.ToDouble(I0_B.EditValue), Convert.ToDouble(U0_B.EditValue), Convert.ToDouble(I0_A_Eval.EditValue), Convert.ToDouble(U0_A_Eval.EditValue), Convert.ToDouble(I0_B_Eval.EditValue), Convert.ToDouble(U0_B_Eval.EditValue), Convert.ToDouble(Lkz.EditValue), Convert.ToDouble(Zone1.EditValue), Convert.ToDouble(Zone2.EditValue), (PS1_DeviceA.SelectedIndex == 0) ? "ЛИФП" : "ИМФ", (PS2_DeviceA.SelectedIndex == 0) ? "ЛИФП" : "ИМФ", GetCurrentUserName(), DateTime.Now, Branch.Count, PS1.Text, PS2.Text, Convert.ToDouble(LengthVL.EditValue), UsingForEval[0], UsingForEval[1], UsingForEval[2], UsingForEval[3], OffDT.DateTime);
        ompDataSet.Result.AcceptChanges();
    }
    catch
    {}

    ZOMG! Что это!?

    invi, 16 Февраля 2012

    Комментарии (5)
  4. C# / Говнокод #9444

    +962

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    for (int i = 0; i < 4; i++)
    {
        if (!UseParam[i])
        {
            switch (i)
            {
                case 0:
                    if (AutoCalc || XtraMessageBox.Show("Неверные показания амперметра " + PS1_DeviceName_A.Text + " " + PS1.Text + "\nИслючить из расчета?", "Проверка показаний", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        if (CorrectKm[i] == 0 || CorrectKm[i] == L)
                            I1 = (CorrectValue[i] ?? 0) * 1000;
                        else
                            I1 = GetCorrectElectricValue(CorrectKm[1] ?? 0, "I0_A", row["N"], row["M"]) * 1000;
                        I0_A.ErrorText = PS1_A.ErrorText = "Показание " + PS1_DeviceName_A.Text + " исключено из расчета";
                    }
                    break;
                case 1:
                    if (AutoCalc || XtraMessageBox.Show("Неверные показания вольтметра" + PS1_DeviceName_B.Text + " " + PS1.Text + "\nИслючить из расчета?", "Проверка показаний", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        if (CorrectKm[i] == 0 || CorrectKm[i] == L)
                            U1 = (CorrectValue[i] ?? 0) * 1000;
                        else
                            U1 = GetCorrectElectricValue(CorrectKm[0] ?? 0, "U0_A", row["N"], row["M"]) * 1000;
                        U0_A.ErrorText = PS1_B.ErrorText = "Показание " + PS1_DeviceName_B.Text + " исключено из расчета";
                    }
                    break;
                case 2:
                    if (AutoCalc || XtraMessageBox.Show("Неверные показания амперметра" + PS2_DeviceName_A.Text + " " + PS2.Text + "\nИслючить из расчета?", "Проверка показаний", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        if (CorrectKm[i] == 0 || CorrectKm[i] == L)
                            I2 = (CorrectValue[i] ?? 0) * 1000;
                        else
                            I2 = GetCorrectElectricValue(CorrectKm[3] ?? 0, "I0_B", row["N"], row["M"]) * 1000;
                        I0_B.ErrorText = PS2_A.ErrorText = "Показание " + PS2_DeviceName_A.Text + " исключено из расчета";
                    }
                    break;
                case 3:
                    if (AutoCalc || XtraMessageBox.Show("Неверные показания вольтметра" + PS2_DeviceName_B.Text + " " + PS2.Text + "\nИслючить из расчета?", "Проверка показаний", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        if (CorrectKm[i] == 0 || CorrectKm[i] == L)
                            U2 = (CorrectValue[i] ?? 0) * 1000;
                        else
                            U2 = GetCorrectElectricValue(CorrectKm[2] ?? 0, "U0_B", row["N"], row["M"]) * 1000;
                        U0_B.ErrorText = PS2_B.ErrorText = "Показание " + PS2_DeviceName_B.Text + " исключено из расчета";
                    }
                    break;
            }
        }
    }

    Красота

    invi, 16 Февраля 2012

    Комментарии (13)
  5. C# / Говнокод #9443

    +960

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    private static void WriteErrLog(string FileName, string errors)
    {
        try
        {
            string name = Environment.CurrentDirectory + "\\log\\" + FileName.Replace("80020_", "");
            name = name.Replace(".xml", ".txt");
            if (File.Exists(name))
                name = name.Replace(".txt", "_" + DateTime.Now.ToString("yyyy-MM-dd hh_mm_ss") + ".txt");                
            using (StreamWriter f = new StreamWriter(name, true, Encoding.GetEncoding(1251)))
            {
                f.Write(errors);
            }
        }
        catch { }
    }

    Продолжаем...

    invi, 16 Февраля 2012

    Комментарии (16)
  6. C# / Говнокод #9442

    +113

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    private static string GetStringParam(ref string str, string param)
    {
        string result = "";
        if (str.Contains(param))
        {
            result = str.Substring(str.IndexOf(param) + 1);
            str = str.Remove(str.IndexOf(param));
        }
        return result;
    }

    И еще

    invi, 16 Февраля 2012

    Комментарии (0)
  7. C# / Говнокод #9441

    +113

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    public static string GetShortName(string name, int length)
    {
        StringBuilder shortname = new StringBuilder(name);
        string[] str = new string[] { "ПС", "ОАО" };
        for (int i = 0; i < str.Length; i++)
            if (shortname.ToString().Length > str[i].Length && shortname.ToString().Substring(0, str[i].Length).ToUpper() == str[i])
                shortname.Remove(0, str[i].Length);
    
        str = new string[] { "ТЭЦ", "ГЭС", "ГРЭС" };
        for (int i = 0; i < str.Length; i++)
            if (shortname.ToString().IndexOf(str[i], StringComparison.CurrentCultureIgnoreCase) > 0)
                shortname.Remove(1, shortname.ToString().IndexOf(str[i]) - 1);
        return (shortname.Length > length) ? shortname.ToString().Substring(0, length).Trim() : shortname.ToString().Trim();
    }

    Опять же, из того, что досталось в наследство)

    invi, 16 Февраля 2012

    Комментарии (0)
  8. C# / Говнокод #9415

    +115

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    try
    {
    	foreach (MapObjectBase item in objects)
    	{
    		GisTrack track = item as GisTrack;
    
    		if (track != null)
    		{
    			//ToolTipContent - наследник TextContent
    			ToolTipContent oToolTip = (ToolTipContent)track.ContentList.FirstOrDefault<IContent>(a => a is TextContent);
    			if (oToolTip != null)
    			{
    				track.ContentList.Remove(oToolTip);
    			}
    		}
    	}
    
    	this.map.Redraw(false);
    }
    catch (Exception ex)
    {
    	MonitoringManager.Instance.WriteLog(ex.ToString());
    }

    Linq - как граната. Смотря в чьих руках.

    ICELedyanoj, 14 Февраля 2012

    Комментарии (4)
  9. C# / Говнокод #9413

    +120

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public class BillingService : Handles<NewDayHasComeInMoscow>
    {
            public void When(NewDayHasComeInMoscow ev)
            {
                // ...
            }
    }

    pavelhritonenko, 14 Февраля 2012

    Комментарии (4)
  10. C# / Говнокод #9382

    +141

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    private void tlistObject_SelectedIndexChanged(object sender, EventArgs e)
    {
    	IMapObject oTarget = this.tlistObjects.SelectedItem as IMapObject;
    
    	if (oTarget != null)
    	{
    		if (this.SelectedObject != null)
    		{
    			this.SelectedObject.ObjectMode = ObjectModeElements.None;
    		}
    		this.SelectedObject = this.tlistObjects.SelectedItem as IMapObject;
    		this.SelectedObject.ObjectMode = ObjectModeElements.Selected;
    	}
    }

    (Is + Explicit приведение) или (As + проверка на Null)?
    Ход конём.
    ОБЯЗАТЕЛЬНОЕ использование this при обращении к полям, свойствам и методам текущего класса - отдельная тема. Это одна из особенностей неповторимого стиля, присущего аффтару. Весь код забит thisами под завязку.

    ICELedyanoj, 10 Февраля 2012

    Комментарии (31)