private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { Controles.CNDCTextBoxDateTime tb = (Controles.CNDCTextBoxDateTime)sender; if (tb.Text.Length == tb.MaxLength && tb.SelectedText == "") { tb.SelectionLength = 1; } }
public static void Validating_DateTime(object sender, System.ComponentModel.CancelEventArgs e) { Controles.CNDCTextBoxDateTime tb = (Controles.CNDCTextBoxDateTime)sender; string errorMsg; System.Text.RegularExpressions.Regex rTime = new System.Text.RegularExpressions.Regex(@"[0-2][0-9]\:[0-6][0-9]\:[0-6][0-9]"); if (tb.Text.Length > 0) { if (!rTime.IsMatch(tb.Text)) { MessageBox.Show("Please provide the time in hh:mm:ss format", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void SetAtributesFromDb(string tableName, string columnName, System.Windows.Forms.Control control) { OracleCommand cmd = Sesion.Instancia.Conexion.CrearCommand(); cmd.CommandText = @"SELECT DATA_TYPE, DATA_LENGTH, DATA_PRECISION , NULLABLE, DATA_SCALE FROM all_tab_columns WHERE owner IN (SELECT DB_SCHEMA FROM P_QUANTUM) AND table_name = :pTableName AND column_name = :pColumnName "; cmd.Parameters.Add("pTableName", tableName); cmd.Parameters.Add("pColumnName", columnName); OracleDataReader odr = cmd.ExecuteReader(); if (odr.Read()) { string dataType = odr.GetString(0); decimal dataLength = odr.GetDecimal(1); decimal dataPrecision = -1; decimal dataScale = -1; string nullable = odr.GetString(3); if (odr[2] != DBNull.Value) { dataPrecision = odr.GetDecimal(2); } if (odr[4] != DBNull.Value) { dataScale = odr.GetDecimal(4); } if (control is TextBox) { TextBox tb = (TextBox)control; tb.MaxLength = (int)dataLength; switch (dataType) { case "CLOB": tb.MaxLength = int.MaxValue; break; case "NUMBER": tb.MaxLength = 32767; if (tb is CNDCTextBoxNumerico) { CNDCTextBoxNumerico txtNum = (CNDCTextBoxNumerico)tb; if (dataScale == -1) { txtNum.MaxDigitosEnteros = (int)dataPrecision; } else { txtNum.MaxDigitosEnteros = (int)dataPrecision - (int)dataScale; } txtNum.MaxDigitosDecimales = (int)dataScale; } break; case "DATE": case "TIMESTAMP(6)": tb.Tag = "dd/mm/yyyy hh:mi:ss"; if (tb.Text.Length == 0) { tb.Text = "__/__/____ __:__:__"; } tb.MaxLength = tb.Text.Length; break; } } if (control is Controles.CNDCTextBoxDateTime) { Controles.CNDCTextBoxDateTime tb = (Controles.CNDCTextBoxDateTime)control; tb.ValidadorFormatoFecha = new Controles.ValidadorControlFecha((string)(tb.Tag)); tb.ValidadorIngresoOnline = new Controles.ValidadorControlFechaParte((string)(tb.Tag)); tb.KeyPress += new KeyPressEventHandler(tb_KeyPress); tb.KeyDown += new KeyEventHandler(tb_KeyDown); } //control.Visible = (visible == 1); //control.Enabled = (enabled == 1); } else { //control.Visible = false; //control.Enabled = false; } if (odr != null) { odr.Close(); odr.Dispose(); } Sesion.Instancia.Conexion.DisposeCommand(cmd); }