// check if the data is in a specific range public static bool IsWithinRange(DateTimePicker dtp, DateTime min, DateTime max) { bool accept = true; DateTime time = Convert.ToDateTime(dtp.Value); TimeSpan tsMin = time.Subtract(min); int minDays = tsMin.Days; TimeSpan tsMax = time.Subtract(max); int maxDays = tsMax.Days; if (minDays < 0) { MessageBox.Show("The shipped date should be after than the order date."); accept = false; dtp.Focus(); } if (maxDays > 0) { MessageBox.Show("The shipped date should be before the required date."); accept = false; dtp.Focus(); } return(accept); }
private void dtp_TextChange(object sender, EventArgs e) { ////////////////// ///usar a variavel ePubl que pega o endereço da celula ativa e atualiar manualmente a data; try { var col = GridCarrinho.Rows[GridCarrinho.CurrentCell.RowIndex].Cells[GridCarrinho.CurrentCell.RowIndex].OwningColumn.Name; //Debug.WriteLine("GridCarrinho.CurrentCell.RowIndex : " + GridCarrinho.CurrentCell.RowIndex + " |ePubl RowIndex: " + ePubl.RowIndex + " ColIndex: " + ePubl.ColumnIndex + "| dtp: " + dtp.Text.ToString() + "| colanme: " + col); if (ePubl.ColumnIndex != null) { //GridCarrinho.CurrentCell.Value = dtp.Text.ToString(); // Debug.WriteLine("GridCarrinho.CurrentCell.RowIndex : " + GridCarrinho.CurrentCell.RowIndex + "| dtp.txt: " + dtp.Text.ToString() + " | dt grid before" + GridCarrinho.Rows[ePubl.RowIndex].Cells["Disp_DataAceite"].Value.ToString()); GridCarrinho.Rows[ePubl.RowIndex].Cells["Disp_DataAceite"].Value = dtp.Text.ToString(); TabEmissaoPedidoEdit(GridCarrinho.Rows[GridCarrinho.CurrentCell.RowIndex].Cells["Iditem"].Value.ToString(), dtp.Text.ToString(), 0); GridCarrinho.Rows[GridCarrinho.CurrentCell.RowIndex].Cells["Disp_Decendio"].Selected = true; //Debug.WriteLine("GridCarrinho.CurrentCell.RowIndex : " + GridCarrinho.CurrentCell.RowIndex + "| dtp.txt: " + dtp.Text.ToString() + " | dt grid after" + GridCarrinho.Rows[ePubl.RowIndex].Cells["Disp_DataAceite"].Value.ToString()); dtp.Visible = false; dtp.Hide(); dtp.Focus(); } } catch (Exception) { } }
private void JkDataGridView_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex > -1 && e.RowIndex > -1 && this.EditMode != DataGridViewEditMode.EditProgrammatically && this.Columns[e.ColumnIndex].ValueType == Type.GetType("System.DateTime")) { this.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true; Rectangle Rectangle = this.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); this.Controls.Add(datePicker); datePicker.Format = DateTimePickerFormat.Custom; datePicker.CustomFormat = "MM'/'dd'/'yyyy"; if (this.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null && this.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != DBNull.Value) { datePicker.Value = DateTime.Parse(this.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()); } datePicker.Size = new Size(Rectangle.Width, Rectangle.Height); datePicker.Location = new Point(Rectangle.X, Rectangle.Y); datePicker.CloseUp += datePicker_CloseUp; datePicker.ValueChanged += datePicker_ValueChanged; datePicker.Visible = true; datePicker.Focus(); } }
private static DateTime _lastTimeValue; // to avoid infinite loops public static bool Valid(string label, TimeSpan limit, DateTimePicker pickDate, DateTimePicker pickTime) { bool valid = true; if (pickDate != null && pickTime != null) { if (_lastTimeValue == null || pickTime.Value.Ticks != _lastTimeValue.Ticks) { DateTime threshold = DateTime.Now + limit; if (pickDate != null && pickTime != null && pickDate.Value.Date == threshold.Date && pickTime.Value.TimeOfDay > threshold.TimeOfDay) { _lastTimeValue = pickTime.Value; Complain(label, limit); pickTime.Value = DateTime.Now; pickTime.Focus(); valid = false; } _lastTimeValue = pickTime.Value; } } return(valid); }
private void dtpDateReturned_ValueChanged(object sender, EventArgs e) { DateTimePicker oDtp = sender as DateTimePicker; if (oDtp != null) { var Contract = (TLADM_CottonContracts)cmbContractNo.SelectedItem; if (Contract != null) { var result = (from u in MandatoryFields where u[0] == oDtp.Name select u).FirstOrDefault(); if (result != null) { int nbr = Convert.ToInt32(result[2].ToString()); MandSelected[nbr] = true; if (oDtp.Value < Contract.CottonCon_StartDate) { MessageBox.Show("Cotton return date cannot be before contract start date", "Contract Start Date " + Contract.CottonCon_StartDate.ToShortDateString()); MandSelected[nbr] = false; oDtp.Focus(); return; } } } } }
private void ShowDateTimePicker(DateTimePicker dtp, ListViewItem.ListViewSubItem subItem) { Rectangle rect = subItem.Bounds; dtp.Bounds = new Rectangle(rect.Left + 1, rect.Top, rect.Width - 1, rect.Height - 1); dtp.Tag = subItem; DateTime time; if (DateTime.TryParse(subItem.Text, out time)) { dtp.Value = time; } else { dtp.Value = DateTime.Now; } dtp.Visible = true; dtp.BringToFront(); dtp.Focus(); _curEditCtrl = dtp; }
private bool KiemTra(LabelX maktx, DateTimePicker ngay, ComboBoxEx hoatdong, TextBoxX ghichu) { if (maktx.Text == "") { MessageBox.Show("Mã KTX không hợp lệ", "ky Luat"); return(false); } if (ngay.Value > DateTime.Now) { MessageBox.Show("Ngày không hợp lệ", "ky Luat"); ngay.Value = DateTime.Now; ngay.Focus(); return(false); } if (hoatdong.SelectedIndex < 0) { MessageBox.Show("Chưa chọn Hoạt động", "ky Luat"); hoatdong.Focus(); return(false); } if (ghichu.Text == "") { MessageBox.Show("Chưa nhập Lý do kỹ luật", "ky Luat"); ghichu.Focus(); return(false); } return(true); }
public void setDateInCheckedPicker(Window window, DateTimePicker picker, string date) { picker.Focus(); window.Keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.SPACE); window.Keyboard.Enter(date); }
public static bool DataNascCliente(DateTimePicker dtpicker) { if (dtpicker.Value > DateTime.Now.AddYears(-16)) { Util.MensagemErro("Data de Nascimento inválida (menor de 16 anos)"); dtpicker.Focus(); return(false); } if (dtpicker.Value < DateTime.Now.AddYears(-90)) { Util.MensagemErro("Data de Nascimento inválida (maior de 90 anos)"); dtpicker.Focus(); return(false); } return(true); }
public static bool inputError <T>(object obj, string errorMessage) { hasMessage(errorMessage); if (typeof(T) == typeof(TextBox)) { TextBox control = (TextBox)obj; control.SelectAll(); control.Focus(); } else if (typeof(T) == typeof(ComboBox)) { ComboBox control = (ComboBox)obj; control.Focus(); } else if (typeof(T) == typeof(DateTimePicker)) { DateTimePicker control = (DateTimePicker)obj; control.Focus(); } else if (typeof(T) == typeof(CheckedListBox)) { CheckedListBox control = (CheckedListBox)obj; control.Focus(); } return(false); }
/// <summary> /// datagridview单元格进入事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgrdvWorkTime_CellEnter(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 1 || e.ColumnIndex == 2) { //获取当前单元格区域 Rectangle rect = dgrdvWorkTime.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false); _dtp.Visible = true; _dtp.Top = rect.Top; _dtp.Left = rect.Left; _dtp.Height = rect.Height; _dtp.Width = rect.Width; //datetimepicker获取焦点 _dtp.Focus(); //datetimepicker显示值设置 if (dgrdvWorkTime[e.ColumnIndex, e.RowIndex].Value != null) { _dtp.Value = Convert.ToDateTime(dgrdvWorkTime[e.ColumnIndex, e.RowIndex].Value.ToString()); } else { _dtp.Value = DateTime.Now; dgrdvWorkTime[e.ColumnIndex, e.RowIndex].Value = _dtp.Text; } } }
public void CambiarTxt(ComboBox Actual, DateTimePicker Nuevo) { Actual.Enabled = false; Actual.BackColor = System.Drawing.Color.White; Nuevo.Enabled = true; Nuevo.BackColor = System.Drawing.Color.Turquoise; Nuevo.Focus(); }
private void Datetime_Leave(object sender, EventArgs e) { DateTimePicker date = (DateTimePicker)sender; if (!date.Value.Year.ToString().Equals(this.anio)) { MessageBox.Show("DIGITE EL AÑO:" + anio, "ERROR", MessageBoxButtons.OK); date.Focus(); } }
public static bool IsPresentDateTimePicker(DateTimePicker dateTimePicker, string name) { if (dateTimePicker.Text == "") { MessageBox.Show(name + " is a required field.", "Entry Error"); dateTimePicker.Focus(); return(false); } return(true); }
/// <summary> /// checks if user entered a end date that is past the start date /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <returns>returns a true or false answer, false if start date is bigger than end date stopping it from being entered into the database</returns> public static bool EndAfterStart(DateTimePicker startDate, DateTimePicker endDate) { if (startDate.Value > endDate.Value) { MessageBox.Show("Package end date must be after package start date.", Title); endDate.Focus(); return(false); } return(true); }
// rejects date if end date is younger than start date private bool IsValidEndDate(DateTimePicker endDate) { if (endDate.Value < dtpStart.Value) { MessageBox.Show("End Date must be on or after the Start Date", "Entry Error"); endDate.Focus(); return(false); } return(true); }
//Date Required Validation private bool IsDateNull(DateTimePicker box, bool ok, int tabIndex) { if (box.Text == " ") { ok = false; box.Focus(); tabControl1.SelectedIndex = tabIndex; errorProvider1.SetError(box, "Please select a Date"); } return(ok); }
public static bool StartAndEndDateIsValid(DateTimePicker startDate, DateTimePicker endDate, out string msg) { if (DateTime.Compare(endDate.Value, startDate.Value) > 0) { msg = ""; return(true); } msg = "Start Date is Later than End Date"; startDate.Focus(); return(false); }
public static bool DateTimePickersError(DateTimePicker picker1, DateTimePicker picker2, ErrorProvider errorProvider) { if (picker1.Value > picker2.Value) { picker2.Focus(); errorProvider.SetError(picker2, "Greska. Ponovite unos."); return(false); } errorProvider.Clear(); return(true); }
public bool ErrorProviderDate(DateTimePicker date1, DateTimePicker date2, ErrorProvider errorProvider) { if (date1.Value > date2.Value) { date2.Focus(); errorProvider.SetError(date2, "Error! Enter data again."); return(false); } errorProvider.Clear(); return(true); }
private void DateTimePicker_FontChanged(object sender, EventArgs e) { // <Snippet3> // <Snippet4> if (!myDateTimePicker.Focused) { // Set focus on 'DateTimePicker' control. myDateTimePicker.Focus(); } // </Snippet4> // </Snippet3> }
public static bool checkToFromDates(DateTimePicker startDate, DateTimePicker endDate) { bool result = true; if (Convert.ToDateTime(startDate.Value) > Convert.ToDateTime(endDate.Value)) { result = false; MessageBox.Show("Start date CANNOT be greater than the end date"); endDate.Focus(); } return(result); }
// Method checks if start date less than end date public static bool checkDates(DateTimePicker startDate, DateTimePicker endDate) { bool result = true; if (Convert.ToDateTime(startDate.Text) > Convert.ToDateTime(endDate.Text)) { result = false; MessageBox.Show("A travel package's start date CANNOT be later than its end date"); endDate.Focus(); } return(result); }
private bool CampoPreenchido(DateTimePicker obj, string campo) { //Se o campo está preenchido, retorna verdadeiro if (!string.IsNullOrEmpty(obj.Value.ToString())) { return(true); } MessageBox.Show($"Campo {campo} não preenchido!"); obj.Focus(); return(false); }
/// <summary> /// Checks if a package duration is correct. End date should be after start date /// </summary> /// <param name="dtp1"> Package start date</param> /// <param name="dtp2"> Package End date</param> /// <returns></returns> internal static bool IsValidDuration(DateTimePicker dtp1, DateTimePicker dtp2) { bool isValid = true; // "innocent until proven guilty" if (dtp2.Value <= dtp1.Value) //not a valid duration { isValid = false; MessageBox.Show(" End date must be after Start date", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error); dtp2.Focus(); } return(isValid); }
public static bool ValidateDate(DateTimePicker dateTimePicker) { if (string.IsNullOrWhiteSpace(dateTimePicker.Text)) { MessageBox.Show("Please select " + dateTimePicker.Tag); dateTimePicker.Focus(); return(false); } else { return(true); } }
public static bool DateIsValid(DateTimePicker dtpBox, out string msg) { DateTime date = dtpBox.Value; if (DateTime.Compare(date, DateTime.Now) > 0) { msg = ""; return(true); } msg = "Please use dates after today"; dtpBox.Focus(); return(false); }
/// <summary> /// Checks if a chosen date is in the past. Packages should only be added if their date /// is to occur in the future /// </summary> /// <param name="dtp"></param> /// <param name="name"></param> /// <returns></returns> internal static bool IsValidDate(DateTimePicker dtp, string name) { bool isValid = true; // "innocent until proven guilty" if (dtp.Value <= DateTime.Today) //not a valid date { isValid = false; MessageBox.Show(name + " must be a future date", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error); dtp.Focus(); } return(isValid); }
// Validar edad. public void ValidarEdad(DateTimePicker dtPicker) { int diferencia = DateTime.Now.Year - dtPicker.Value.Year; if (diferencia < 18) { this.FalloValidacion = true; MessageBox.Show("El cliente debe tener al menos 18 años de edad.", "Aviso.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); dtPicker.Focus(); return; } this.FalloValidacion = false; }
private bool CheckDate(DateTimePicker dtp, string name) { bool isError = false; if (DateTime.Today > dtp.Value) { isError = true; MessageBox.Show(name + "不能小于当前时间!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); dtp.Focus(); } return(isError); }