- 1
- 2
- 3
- 4
foreach (var list in Distances.ConvertToList())
{
dt.Rows.Add(ConvertToObject(list.ToArray()));
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+119
foreach (var list in Distances.ConvertToList())
{
dt.Rows.Add(ConvertToObject(list.ToArray()));
}
+122
var rl2 = _vf.AddNewRouteLine(BusStation.Instance.GetRoute(
BusStation.Instance.FindSettlement(БарановичиcheckBox6.Content.ToString()),
BusStation.Instance.FindSettlement(БобруйскcheckBox17.Content.ToString()))[0],
БарановичиcheckBox6, БобруйскcheckBox17, Upd);
canvas1.Children.Add(rl2.Line);
+116
IList<Hashtable> records = crit.List<Hashtable>();
Guid[] personsId = records.Select(item => (Guid)item["PersonID"]).Distinct().ToArray();
List<EmployeeData> empDatas = new List<EmployeeData>();
foreach(Guid personId in personsId) {
IEnumerable<Hashtable> employeeRecords = records.Where(item => (Guid)item["PersonID"] == personId);
Hashtable employeeRecord = employeeRecords.FirstOrDefault(item => !(bool)item["IsLoad"] || (DateTime)item["EventDate"] == employeeRecords.Max(unit => (DateTime)unit["EventDate"]));
Hashtable employeeRecordAddition = new GenericNHibernateDao<BaseDocument>().CreateCriteria()
.CreateAlias("Department", "department")
.CreateAlias("Employee", "employee")
.CreateAlias("WorkDescription.Schedule", "schedule", JoinType.LeftOuterJoin)
.CreateAlias("WorkDescription.EmployeeApperance", "employeeApperance", JoinType.LeftOuterJoin)
.Add(Restrictions.Eq("EmployeeStamp.TabNo", employeeRecord["TabNo"]))
.Add(Restrictions.Eq("IsHalf", false))
...
}
No comments %)
+120
private string GetConnectionString()
{
string connString = String.Empty;
string location = Assembly.GetExecutingAssembly().Location;
int pos = location.LastIndexOf('\\');
location = location.Remove(pos);
pos = location.LastIndexOf('\\');
location = location.Remove(pos);
pos = location.LastIndexOf('\\');
location = location.Remove(pos);
location += @"\server\conf\config.conf";
using (StreamReader sr = File.OpenText(location))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
connString += s;
}
}
connString += "database = ***; charset = utf8;";
return connString;
}
+115
----Something.cs
public partial class Something
{
// some implementation.
}
----Something.Bla.cs
partial class Something
{
private class Bla
{
}
}
----Something.Foo.cs
partial class Something
{
private class Foo
{
}
}
----Something.Bar.cs
partial class Something
{
private class Bar
{
}
}
Нормально ли использовать partial классы исключительно для хранения private nested классов? К примеру если количество таковых доходит до 5-15?
+116
mainDays = 0;
for (var d = emplDoc.EventDate.AddMonths(1).AddDays(-1).Date; d <= emplDoc.DateEndWork.Date; d = d.AddMonths(1)) {
mainDays += 2;
}
+125
/// <summary>
/// Return a DateTime version of the given Jabber date. Example date: 20020504T20:39:42
/// </summary>
/// <param name="dt">The pseudo-ISO-8601 formatted date (no milliseconds)</param>
/// <returns>A (usually UTC) DateTime</returns>
public static DateTime JabberDate(string dt)
{
if ((dt == null) || (dt == ""))
return DateTime.MinValue;
try
{
return new DateTime(int.Parse(dt.Substring(0, 4)),
int.Parse(dt.Substring(4, 2)),
int.Parse(dt.Substring(6, 2)),
int.Parse(dt.Substring(9,2)),
int.Parse(dt.Substring(12,2)),
int.Parse(dt.Substring(15,2)));
}
catch
{
return DateTime.MinValue;
}
}
/// <summary>
/// Get a jabber-formated date for the DateTime. Example date: 20020504T20:39:42
/// </summary>
/// <param name="dt">The (usually UTC) DateTime to format</param>
/// <returns>The pseudo-ISO-8601 formatted date (no milliseconds)</returns>
public static string JabberDate(DateTime dt)
{
return string.Format("{0:yyyy}{0:MM}{0:dd}T{0:HH}:{0:mm}:{0:ss}", dt);
}
Перевод DateTime в строку вида "20020504T20:39:42" и обратно. Из исходников библиотеки Jabber-net.
TryParseExact и ToString с форматом "yyyyMMddTHH:mm:ss" - это пусть лентяи используют.
+119
public static Bitmap DrawBarsChart(ChartType t, Size s)
{
double[] values = DataValues;
string[] names = DataNames;
Bitmap bmp = new Bitmap(s.Width, s.Height);
if (t != ChartType.bars || names.Length != values.Length || names.Length < 2)
return bmp;
else
{
Graphics g = Graphics.FromImage(bmp as Image);
g.Clear(Color.White);
g.DrawLines(new Pen(Brushes.Black), new Point[] { new Point(20, 20), new Point(20, s.Height - 20), new Point(s.Width - 200, s.Height - 20) });
int Columnwidth = (s.Width - 240) / values.Length;
if (Columnwidth > 150) Columnwidth = 150;
double maxvalue = values.Max();
int counter = 1;
int rangefirst;
int rangesecond;
while (true)
{
if (maxvalue / Math.Pow(10, counter) < 10)
{
rangefirst = (int)Math.Floor(maxvalue / Math.Pow(10, counter));
rangesecond = (int)(maxvalue - rangefirst * Math.Pow(10, counter));
break;
}
else
{
counter++;
}
}
int rangepix = (s.Height - 60) / (rangefirst + 1);
for (int i = 0; i < rangefirst + 1; i++)
{
g.DrawString((i * Math.Pow(10, counter)).ToString(), new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular),
Brushes.Black, new PointF(0, s.Height - 30 - rangepix * i));
g.DrawLine(new Pen(Brushes.Black), new Point(17, s.Height - 20 - rangepix * i), new Point(20, s.Height - 20 - rangepix * i));
}
Colors colors = new Colors(); //класс-контейнер цветов (99 штук)
int startcolor = new Random(DateTime.Now.Millisecond).Next(99);
int j = startcolor;
int startx = 21;
int ColumnNumber = 1;
foreach (var value in values)
{
int curfirstrange = (int)Math.Floor(value / Math.Pow(10, counter));
int cursecondrange = (int)(value - curfirstrange * Math.Pow(10, counter));
int rangesmallpix = (int)(cursecondrange * rangepix / Math.Pow(10, counter));
g.FillRectangle(new SolidBrush(colors.GetNextColor(j)), startx,
s.Height - 20 - curfirstrange * rangepix - rangesmallpix, Columnwidth, curfirstrange * rangepix + rangesmallpix);
g.DrawString(value.ToString(), new Font(FontFamily.GenericSerif, 10, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(startx + Columnwidth / 2 - 10,
s.Height - 20 - curfirstrange * rangepix - rangesmallpix - 20));
g.DrawString(ColumnNumber.ToString(), new Font(FontFamily.GenericSerif, 10, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(startx + Columnwidth / 2 - 10,
s.Height - 10));
ColumnNumber++;
j++; if (j > 99) j = 0;
startx += Columnwidth;
}
j = startcolor;
int TopMargin = 20;
foreach (string str in names)
{
string tmp = str;
if (str.Length > 15)
tmp = str.Substring(0, 15);
g.FillRectangle(new SolidBrush(colors.GetNextColor(j)), s.Width - 200, TopMargin, 10, 10); //pucyeM LIBeTHbIe kBagpaTuku
g.DrawString(tmp, new Font(FontFamily.GenericSerif, 12, FontStyle.Italic), Brushes.Black, new PointF(s.Width - 180, TopMargin - 6)); //pucyeM Hagnucu
TopMargin += 20;
j++; if (j > 99) j = 0;
}
return bmp;
}
}
+127
private void bbbut_Click(object sender, EventArgs e)
{
if (this.plugDescr.SelectedText.Length > 0)
{
ToolStripButton button = (ToolStripButton) sender;
if (button.Name == "bbB")
{
this.plugDescr.SelectedText = BB_HTMLwork.WriteBBToString(this.plugDescr.SelectedText, "", "b");
}
if (button.Name == "bbI")
{
this.plugDescr.SelectedText = BB_HTMLwork.WriteBBToString(this.plugDescr.SelectedText, "", "i");
}
if (button.Name == "bbU")
{
this.plugDescr.SelectedText = BB_HTMLwork.WriteBBToString(this.plugDescr.SelectedText, "", "u");
}
if (button.Name == "bbS")
{
this.plugDescr.SelectedText = BB_HTMLwork.WriteBBToString(this.plugDescr.SelectedText, "", "s");
}
if (button.Name == "bbURL")
{
this.plugDescr.SelectedText = BB_HTMLwork.WriteBBToString(this.plugDescr.SelectedText, this.bbAddInfoContent.Text, "url");
}
}
}
Обработчик кнопок ббкода в утилите для генерации ридми. Весь ее код выполнем в таком духе.
Утилита: http://fullrest.ru/forum/topic/34114-generator-readme/
Сорцы: http://depositfiles.com/files/kvi4gsajy
+124
litFreeMinets.Text = FreeMinutes.Count;