public object Render(T obj, EditorField <T> editorField, Action preview) { object _value = editorField.GetValue(obj); DateTime?value; if (_value == null) { value = null; } else if (_value is DateTimeOffset dto) { value = dto.DateTime; } else if (_value is DateTime dt) { value = dt; } else { throw new ArgumentException("Not a DateTime or DateTimeOffset."); } _dateBox = new DateBox(value) { }; //_dateBox.HtmlElement.SetAttribute("placeholder", "YYYY-MM-DD"); _dateBox.TextInput += (sender, args) => preview(); _dateBox.Enabled = editorField.Enabled; return(_field = new Field(editorField.Label, _dateBox, editorField.Description, editorField.Helper, editorField.Required)); }
private void SubmitPaymentButton_Click(object sender, RoutedEventArgs e) { string connectionString; connectionString = "Data Source=(local);Initial Catalog=ML635064021;" + "Integrated Security=true"; SqlConnection connection = new SqlConnection(connectionString); SqlCommand payments = connection.CreateCommand(); payments.CommandText = "INSERT INTO PAYMENTS (Lease_Terms_ID, Date, Amount)" + " VALUES (@LeaseId, @DateEntry, @AmountEntry)"; payments.Parameters.AddWithValue("@LeaseId", LeaseIDBox.Text); payments.Parameters.AddWithValue("@DateEntry", DateBox.Text); payments.Parameters.AddWithValue("@AmountEntry", AmountBox.Text); try { connection.Open(); payments.ExecuteNonQuery(); MessageBox.Show("Payment Successfuly Added!"); } catch { MessageBox.Show("Something went wrong!"); } finally { connection.Close(); DateBox.Clear(); AmountBox.Clear(); LeaseIDBox.Clear(); } }
private void InitialiseTextBoxes() { DateBox.Clear(); DateBox.Enabled = false; CostBox.Clear(); CostBox.Enabled = false; NameBox.Clear(); NameBox.Enabled = false; }
private void AddBtn_Click(object sender, RoutedEventArgs e) { string ItemName = ItemBox.Text; string DateOfSale = DateBox.Text; string Country = CountryBox.Text; string Currency = CurrencyBox.Text; if (!float.TryParse(PriceBox.Text, out float NetPrice) & float.TryParse(VATbox.Text, out float VAT)) { MessageBox.Show("Net Price and VAT fields can only contain numbers!"); } con.InsertSales(ItemName, Country, Currency, DateOfSale, NetPrice, VAT); MessageBox.Show("Sale has been added."); ItemBox.Clear(); DateBox.Clear(); CountryBox.Clear(); CurrencyBox.Clear(); PriceBox.Clear(); VATbox.Clear(); }
public string GetUrlDateToString([FromUrl] DateBox dateBox) { var dt = dateBox.Date; return(dt == null ? string.Empty : dt.Value.ToString("u")); }
// 해당 달의 캘린더를 그림 private void RenderMonthCalendar(PaintEventArgs e) { _calendarDays.Clear(); _cEvents.Clear(); dateBoxes.Clear(); // e.Graphics.draw var bmp = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics g = Graphics.FromImage(bmp); e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; SizeF sunSize = g.MeasureString("Sun", _dayOfWeekFont); SizeF monSize = g.MeasureString("Mon", _dayOfWeekFont); SizeF tueSize = g.MeasureString("Tue", _dayOfWeekFont); SizeF wedSize = g.MeasureString("Wed", _dayOfWeekFont); SizeF thuSize = g.MeasureString("Thu", _dayOfWeekFont); SizeF friSize = g.MeasureString("Fri", _dayOfWeekFont); SizeF satSize = g.MeasureString("Sat", _dayOfWeekFont); SizeF dateHeaderSize = g.MeasureString( _calendarDate.ToString("MMMM") + " " + _calendarDate.Year.ToString(CultureInfo.InvariantCulture), _dateHeaderFont); int headerSpacing = Max(sunSize.Height, monSize.Height, tueSize.Height, wedSize.Height, thuSize.Height, friSize.Height, satSize.Height) + 5; int controlsSpacing = ((!_showTodayButton) && (!_showDateInHeader) && (!_showArrowControls)) ? 0 : 30; int cellWidth = (ClientSize.Width - MarginSize * 2) / 7; int numWeeks = NumberOfWeeks(_calendarDate.Year, _calendarDate.Month); int cellHeight = (ClientSize.Height - MarginSize * 2 - headerSpacing - controlsSpacing) / numWeeks; int xStart = MarginSize; int yStart = MarginSize; DayOfWeek startWeekEnum = new DateTime(_calendarDate.Year, _calendarDate.Month, 1).DayOfWeek; int startWeek = ((int)startWeekEnum) + 1; int rogueDays = startWeek - 1; yStart += headerSpacing + controlsSpacing; int counter = 1; int counter2 = 1; bool first = false; bool first2 = false; _todayBtn.Location = new Point(MarginSize, MarginSize); // 달력 그리는 부분 for (int y = 0; y < numWeeks; y++) { for (int x = 0; x < 7; x++) { if (rogueDays == 0 && counter <= DateTime.DaysInMonth(_calendarDate.Year, _calendarDate.Month)) { if (!_calendarDays.ContainsKey(counter)) _calendarDays.Add(counter, new Point(xStart, (int)(yStart + 2f + g.MeasureString(counter.ToString(CultureInfo.InvariantCulture), _daysFont).Height))); // Today if (_calendarDate.Year == DateTime.Now.Year && _calendarDate.Month == DateTime.Now.Month && counter == DateTime.Now.Day && _highlightCurrentDay) { g.FillRectangle(new SolidBrush(Color.FromArgb(234, 234, 234)), xStart, yStart, cellWidth, cellHeight); } if(counter == selectedDay) { g.FillRectangle(new SolidBrush(Color.AliceBlue), xStart, yStart, cellWidth, cellHeight); } // Date 이벤트 부여를 위한 날짜 + Rectangle 구조 저장 DateBox dateInfo = new DateBox(); dateInfo.month = _calendarDate.Month; dateInfo.date = counter; dateInfo.size = new Rectangle(xStart, yStart, cellWidth, cellHeight); dateBoxes.Add(dateInfo); // 날짜 그리기 if (first == false) { first = true; if (_calendarDate.Year == DateTime.Now.Year && _calendarDate.Month == DateTime.Now.Month && counter == DateTime.Now.Day) { g.DrawString(counter.ToString(CultureInfo.InvariantCulture), _todayFont, Brushes.Black, xStart + 5, yStart + 2); } else { g.DrawString(counter.ToString(CultureInfo.InvariantCulture), _daysFont, Brushes.Black, xStart + 5, yStart + 2); } } else { if (_calendarDate.Year == DateTime.Now.Year && _calendarDate.Month == DateTime.Now.Month && counter == DateTime.Now.Day) { g.DrawString(counter.ToString(CultureInfo.InvariantCulture), _todayFont, Brushes.Black, xStart + 5, yStart + 2); } else { g.DrawString(counter.ToString(CultureInfo.InvariantCulture), _daysFont, Brushes.Black, xStart + 5, yStart + 2); } } counter++; } else if (rogueDays > 0) { int dm = DateTime.DaysInMonth(_calendarDate.AddMonths(-1).Year, _calendarDate.AddMonths(-1).Month) - rogueDays + 1; g.DrawString(dm.ToString(CultureInfo.InvariantCulture), _daysFont, new SolidBrush(Color.FromArgb(170, 170, 170)), xStart + 5, yStart + 2); rogueDays--; } // 달력 선 그리기 g.DrawRectangle(Pens.DarkGray, xStart, yStart, cellWidth, cellHeight); if (rogueDays == 0 && counter > DateTime.DaysInMonth(_calendarDate.Year, _calendarDate.Month)) { if (first2 == false) first2 = true; else { if (counter2 == 1) { g.DrawString(_calendarDate.AddMonths(1).ToString("MMM") + " " + counter2.ToString(CultureInfo.InvariantCulture), _daysFont, new SolidBrush(Color.FromArgb(170, 170, 170)), xStart + 5, yStart + 2); } else { g.DrawString(counter2.ToString(CultureInfo.InvariantCulture), _daysFont, new SolidBrush(Color.FromArgb(170, 170, 170)), xStart + 5, yStart + 2); } counter2++; counter++; } } xStart += cellWidth; } xStart = MarginSize; yStart += cellHeight; } xStart = MarginSize + ((cellWidth - (int)sunSize.Width) / 2); yStart = MarginSize + controlsSpacing; g.DrawString("Sun", _dayOfWeekFont, Brushes.Red, xStart, yStart); xStart = MarginSize + ((cellWidth - (int)monSize.Width) / 2) + cellWidth; g.DrawString("Mon", _dayOfWeekFont, Brushes.Black, xStart, yStart); xStart = MarginSize + ((cellWidth - (int)tueSize.Width) / 2) + cellWidth * 2; g.DrawString("Tue", _dayOfWeekFont, Brushes.Black, xStart, yStart); xStart = MarginSize + ((cellWidth - (int)wedSize.Width) / 2) + cellWidth * 3; g.DrawString("Wed", _dayOfWeekFont, Brushes.Black, xStart, yStart); xStart = MarginSize + ((cellWidth - (int)thuSize.Width) / 2) + cellWidth * 4; g.DrawString("Thu", _dayOfWeekFont, Brushes.Black, xStart, yStart); xStart = MarginSize + ((cellWidth - (int)friSize.Width) / 2) + cellWidth * 5; g.DrawString("Fri", _dayOfWeekFont, Brushes.Black, xStart, yStart); xStart = MarginSize + ((cellWidth - (int)satSize.Width) / 2) + cellWidth * 6; g.DrawString("Sat", _dayOfWeekFont, Brushes.Red, xStart, yStart); // 년도 쓰는 부분 if (_showDateInHeader) { g.DrawString( _calendarDate.Year.ToString(CultureInfo.InvariantCulture) + "년 " + _calendarDate.ToString("MMMM"), _dateHeaderFont, Brushes.Black, ClientSize.Width / 2, MarginSize); // 범례 부분 Font ImageInfoFont = new Font("Arial", 8, FontStyle.Regular); g.DrawRectangle(Pens.Black, new Rectangle(ClientSize.Width - 105, MarginSize - 16, 80, 46)); Bitmap start = new Bitmap(Application.StartupPath + @"\image\start.png"); Rectangle startSize = new Rectangle(ClientSize.Width - 100, MarginSize - 12, 10, 12); g.DrawImage(start, startSize); g.DrawString("근무 시작", ImageInfoFont, Brushes.Black, ClientSize.Width - 100 + 12, MarginSize - 12); Bitmap end = new Bitmap(Application.StartupPath + @"\image\end.png"); Rectangle endSize = new Rectangle(ClientSize.Width - 100, MarginSize + 2, 10, 12); g.DrawImage(end, endSize); g.DrawString("근무 종료", ImageInfoFont, Brushes.Black, ClientSize.Width - 100 + 12, MarginSize + 2); Bitmap etc = new Bitmap(Application.StartupPath + @"\image\etc.png"); Rectangle etcSize = new Rectangle(ClientSize.Width - 100, MarginSize + 16, 10, 12); g.DrawImage(etc, etcSize); g.DrawString("비고", ImageInfoFont, Brushes.Black, ClientSize.Width - 100 + 12, MarginSize + 16); } // 해당 년과 달의 이벤트를 찾아서 그리는 부분 for (int i = 1; i <= DateTime.DaysInMonth(_calendarDate.Year, _calendarDate.Month); i++) { int renderOffsetY = 0; foreach (IEvent v in _events) { var dt = new DateTime(_calendarDate.Year, _calendarDate.Month, i, 23, 59, _calendarDate.Second); // 해당 Date에 이벤트가 존재하면 if (NeedsRendering(v, dt)) { int alpha = 255; if (!v.Enabled && _dimDisabledEvents) alpha = 64; Color alphaColor = Color.FromArgb(alpha, v.EventColor.R, v.EventColor.G, v.EventColor.B); int offsetY = renderOffsetY; Region r = g.Clip; Point point = _calendarDays[i]; SizeF sz = g.MeasureString(v.startTime, v.EventFont); int yy = point.Y - 1; int xx = ((cellWidth - (int)sz.Width) / 2) + point.X; if (sz.Width > cellWidth) xx = point.X; if (renderOffsetY + sz.Height > cellHeight - 10) continue; g.Clip = new Region(new Rectangle(point.X + 1, point.Y + offsetY, cellWidth - 1, (int)(sz.Height * 4))); //g.FillRectangle(new SolidBrush(alphaColor), point.X + 1, point.Y + offsetY, cellWidth - 1, sz.Height); if (!v.Enabled && _showDashedBorderOnDisabledEvents) { var p = new Pen(new SolidBrush(Color.FromArgb(255, 0, 0, 0))) { DashStyle = DashStyle.Dash }; g.DrawRectangle(p, point.X + 1, point.Y + offsetY, cellWidth - 2, sz.Height - 1); } // 근무 시작 이미지와 글씨 입력 Bitmap start = new Bitmap(Application.StartupPath + @"\image\start.png"); Rectangle startSize = new Rectangle(xx, yy + offsetY, 10, (int)(sz.Height + 1)); g.DrawImage(start, startSize); g.DrawString(v.startTime, v.EventFont, new SolidBrush(v.EventTextColor), xx + 10, yy + offsetY); // 근무 마침 이미지와 글씨 입력 Bitmap end = new Bitmap(Application.StartupPath + @"\image\end.png"); Rectangle endSize = new Rectangle(xx, yy + (int)(sz.Height + 1), 10, (int)(sz.Height + 1)); g.DrawImage(end, endSize); g.DrawString(v.endTime, v.EventFont, new SolidBrush(v.EventTextColor), xx + 10, yy + (int)(sz.Height + 1)); // 비고란 이미지와 글씨 입력 Bitmap etc = new Bitmap(Application.StartupPath + @"\image\etc.png"); Rectangle etcSize = new Rectangle(xx, yy + (int)((sz.Height + 1) * 2), 10, (int)(sz.Height + 1)); g.DrawImage(etc, etcSize); g.DrawString(v.etc, v.EventFont, new SolidBrush(v.EventTextColor), xx + 10, yy + (int)((sz.Height + 1) * 2)); g.Clip = r; var evs = new cEvent { EventArea = new Rectangle(point.X + 1, point.Y + offsetY, cellWidth - 1, (int)sz.Height), Event = v, Date = dt }; _cEvents.Add(evs); renderOffsetY += (int)sz.Height + 1; } } } _rectangles.Clear(); g.Dispose(); e.Graphics.DrawImage(bmp, 0, 0, ClientSize.Width, ClientSize.Height); bmp.Dispose(); }