- 1
private string[] months = new string[12] {"Январь","Февраль","Март", "Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь","Декабрь"};
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+135.1
private string[] months = new string[12] {"Январь","Февраль","Март", "Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь","Декабрь"};
безусловно сильный ход. особенно для .NET
+135.1
if ((Owner as Form1).ZakazdataGrid.Columns.Count == 0)
{
(Owner as Form1).ZakazdataGrid.Columns.Add("KodTov", "");
(Owner as Form1).ZakazdataGrid.Columns.Add("NazvaTov", "Товар");
(Owner as Form1).ZakazdataGrid.Columns.Add("Kolvo", "Кол-во");
(Owner as Form1).ZakazdataGrid.Columns.Add("NazvaEd", "Ед.");
(Owner as Form1).ZakazdataGrid.Columns.Add("Suma", "Сумма");
(Owner as Form1).ZakazdataGrid.Columns.Add("KolEd", "");
(Owner as Form1).ZakazdataGrid.Columns.Add("Sostavnoy", "");
(Owner as Form1).ZakazdataGrid.Columns.Add("Sostav", "");
(Owner as Form1).ZakazdataGrid.Columns["Sostavnoy"].Visible = false;
(Owner as Form1).ZakazdataGrid.Columns["Sostav"].Visible = false;
(Owner as Form1).ZakazdataGrid.Columns["KodTov"].Visible = false;
(Owner as Form1).ZakazdataGrid.Columns["KolEd"].Visible = false;
(Owner as Form1).ZakazdataGrid.Columns["NazvaTov"].Width = (int)((Owner as Form1).ZakazdataGrid.Width * 0.5);
(Owner as Form1).ZakazdataGrid.Columns["NazvaTov"].SortMode = DataGridViewColumnSortMode.NotSortable;
(Owner as Form1).ZakazdataGrid.Columns["Kolvo"].Width = (int)((Owner as Form1).ZakazdataGrid.Width * 0.15);
(Owner as Form1).ZakazdataGrid.Columns["Kolvo"].SortMode = DataGridViewColumnSortMode.NotSortable;
(Owner as Form1).ZakazdataGrid.Columns["NazvaEd"].Width = (int)((Owner as Form1).ZakazdataGrid.Width * 0.15);
(Owner as Form1).ZakazdataGrid.Columns["NazvaEd"].SortMode = DataGridViewColumnSortMode.NotSortable;
(Owner as Form1).ZakazdataGrid.Columns["Suma"].Width = (int)((Owner as Form1).ZakazdataGrid.Width * 0.2);
(Owner as Form1).ZakazdataGrid.Columns["Suma"].SortMode = DataGridViewColumnSortMode.NotSortable;
(Owner as Form1).ZakazdataGrid.RowsDefaultCellStyle.Font = new Font("Times New Roman", FontSize - 5);
(Owner as Form1).ZakazdataGrid.ColumnHeadersDefaultCellStyle.Font = new Font("Times New Roman", FontSize - 5);
(Owner as Form1).ZakazdataGrid.AlternatingRowsDefaultCellStyle.BackColor = Color.PowderBlue;
(Owner as Form1).ZakazdataGrid.RowsDefaultCellStyle.BackColor = Color.LightSkyBlue;
}
Отсюда: http://sql.ru/forum/actualthread.aspx?tid=688754
:-)
+129.7
[StructLayout(LayoutKind.Explicit, Size=264)]
public struct STRRET
{
[FieldOffset(0)]
public UInt32 uType; // One of the STRRET_* values
[FieldOffset(4)]
public IntPtr pOleStr; // must be freed by caller of GetDisplayNameOf
[FieldOffset(4)]
public IntPtr pStr; // NOT USED
[FieldOffset(4)]
public UInt32 uOffset; // Offset into SHITEMID
[FieldOffset(4)]
public IntPtr cStr; // Buffer to fill in (ANSI)
}
Обертка над структурой STRRET. Доставляет тут http://www.pinvoke.net/default.aspx/Structures/STRRET.html
+135.1
this.txtGroupSubject.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
Виетнамский кастинг :)
+135.2
Continue = (Continue) ? true : false;
+139
dgridPFF1.Rows[1].Cells[1].Value = UtilHelper.Number2String(Convert.ToDouble(UtilHelper.StringToInvariantCulture(dgridPFF1.Rows[0].Cells[1].Value), UtilHelper.getCultureInfo()) / Convert.ToDouble(UtilHelper.StringToInvariantCulture(dgridPFF2.Rows[0].Cells[0].Value),UtilHelper.getCultureInfo()), 2); // String.Format(UtilHelper.getCultureInfo(),UtilHelper.NUMBERIC_FORMAT_2,Convert.ToDouble(dgridPFF1.Rows[0].Cells[1].Value) / Convert.ToDouble(dgridPFF2.Rows[0].Cells[0].Value, UtilHelper.getCultureInfo()));
Виетнамский jungle code :)
+138.9
public static void loadDataToDataGridView(DataGridView objDataGridView, List<object> objResultSet, IList objects)
{
if (objDataGridView == null || objResultSet == null) return;
objDataGridView.Rows.Clear();
for (int i = 0; i < objResultSet.Count; i++)
{
for (int columnIndex = 0; columnIndex < ((List<object>)objResultSet[i]).Count; columnIndex++)
{
if (columnIndex == 0)
{
objDataGridView.Rows.Add();
}
objDataGridView.Rows[i].Cells[columnIndex].Value = ((List<object>)objResultSet[i])[columnIndex];
}
if (objects != null)
{
objDataGridView.Rows[i].Tag = objects[i];
}
}
}
public static void loadDataToDataGridView(DataGridView objDataGridView, List<object> objResultSet)
{
loadDataToDataGridView(objDataGridView, objResultSet, null);
}
...
use of this code:
...
List<object> values = new List<object>();
List<object> value = new List<object>();
if (_objPriceFormationFormula.RateVsEuro == 0)
{
value.Add(UtilHelper.Number2String(1.00,2));// String.Format(UtilHelper.getCultureInfo(),UtilHelper.NUMBERIC_FORMAT_2,1.00));//1.00
}
else
{
value.Add(UtilHelper.Number2String(_objPriceFormationFormula.RateVsEuro,2));// String.Format(UtilHelper.getCultureInfo(),UtilHelper.NUMBERIC_FORMAT_2,_objPriceFormationFormula.RateVsEuro));
}
values.Add(value);
UtilHelper.loadDataToDataGridView(this.dgridPFF2, values);
Instead of databind :)
+139
public bool IsEmpty()
{
int x = 0;
x += EntityType.Length == 0 ? 1 : 0;
x += EntityTypeName.Length == 0 ? 1 : 0;
x += EntityDisplayName.Length == 0 ? 1 : 0;
x += EntityId == Guid.Empty ? 1 : 0;
return x == 0 ? false : true;
}
Аритметичный if :)
+137
if (messages[i].description != "")
if (messages[i].description.StartsWith("<![CDATA["))
{
messages[i].description = messages[i].description.Substring(9);
messages[i].description = messages[i].description.Substring(0, messages[i].description.Length - 3);
}
для строк типа <![CDATA[******]!>
Возникает устойчивое ощущение говнокода. Как нормально написать? :)
+133.8
public static XmlNode FindNodeXPath(XmlNode root, string xPath)
{
string[] paths = xPath.Split(new char[] { '/' });
XmlNode node = root;
for (int i = 0; i < paths.Length; i++)
{
XmlNode childNode = null;
for (int j = 0; j < node.ChildNodes.Count; j++)
{
if (node.ChildNodes[j].Name == paths[i])
{
childNode = node.ChildNodes[j];
node = childNode;
break;
}
}
if (childNode == null)
{
return null;
}
}
return node;
}
public static XmlNode FindNodeXPath(XmlNode root, string nodeName, string xPath)
{
XmlNode node = FindNodeXPath(root, xPath);
if (node != null)
{
for (int i = 0; i < node.ChildNodes.Count; i++)
{
if (node.ChildNodes[i].Name == nodeName)
{
node = node.ChildNodes[i];
}
}
}
return node;
}
public static void UpdateBaseAddress(string url, string fileConfig)
{
// Create config file to create
XmlDocument xmlDom = new XmlDocument();
xmlDom.Load(fileConfig);
XmlNode root = xmlDom.DocumentElement;
// Get XML node
XmlNode xmlNode = FindNodeXPath(root, "endpoint", "system.serviceModel/services/service");
xmlNode.Attributes["address"].Value = url;
xmlNode = FindNodeXPath(root, "add", "system.serviceModel/services/service/host/baseAddresses");
xmlNode.Attributes["baseAddress"].Value = url;
xmlDom.Save(fileConfig);
}
Виетнамский XPath эквивалент :)