31 de agosto de 2015

Test

Expresiones regulares
DataTable dt = dal.PoblarCBX_DPTO();
 DataRow dr = dt.NewRow();
 dr["Departmento"] = Convert.ToInt32("0");
 dr["Departmento"] = "-- Seleccione Departamento --";
 dt.Rows.InsertAt(dr,0);
 cbxDpto.DataSource = dt;
 cbxDpto.DisplayMember = "Departmento";
 cbxDpto.ValueMember = "Departmento";
 cbxDpto.SelectedIndex = 0;
Expresiones regulares
string DUI = @"\A[0-9]{8}(-)[0-9]{1}\Z";

string NOMBRE = @"\A((\w+)(\s?)(\w+))*\Z";

string MONEY = @"\A$?(\d{1,3},?(\d{3},?)*\d{3}(.\d{0,3})?|\d{1,3}(.\d{2})?)\Z";

string CORREO = @"\A(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@" + 
                            @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\." + 
                            @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|" +
                            @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})\Z";

string telefono = @"\A[0-9]{8}\Z";

string telefonoGuion = @"\A[0-9]{4}(-)[0-9]{4}\Z";

string telefonoCodigo = @"\A(()[0-9]{3}())[0-9]{8}\Z";

string telefonoCodigoGuion = @"\A(()[0-9]{3}())[0-9]{4}(-)[0-9]{4}\Z";

Regex regAge = new Regex(@"^\d{2}$");

Regex regUrl = new Regex(@"^((https?|ftp)://|(www|ftp)\.)[a-z0-9-]+(\.[a-z0-9-]+)+([/?].*)?$");

Regex regCompany = new Regex(@"^[A-Z]([a-zA-Z0-9]|[- @\.#&!])*$");
Aceptar solo letras en un textbox
private void txtLetras_KeyPress(object sender, KeyPressEventArgs e){
 if (!(char.IsLetter(e.KeyChar)) && (e.KeyChar != (char)Keys.Back) && (e.KeyChar != (char)Keys.Space))
    {
    MessageBox.Show("Solo se permiten letras", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information);
    e.Handled = true;
    return;
    }
}
Aceptar solo numeros en textbox
private void txtNumeros_KeyPress(object sender, KeyPressEventArgs e){
 if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
    {
    MessageBox.Show("Solo se permiten numeros", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information);
    e.Handled = true;
    return;
    }
}
Aceptar numeros double
private void textBox1_KeyPress(object sender, KeyPressEventArgs e){
 if (textBox1.Text.Contains(‘.’)) {
  if(!char.IsDigit(e.KeyChar)){
   e.Handled = true;
   }

  if (e.KeyChar == ‘\b’){
   e.Handled = false;
   }
  }
 else {
  if(!char.IsDigit(e.KeyChar)){
   e.Handled = true;
   }

  if(e.KeyChar==‘.’ || e.KeyChar==‘\b’)
   {
   e.Handled = false;
   }}}
Crear tabla SQL DDL con llave primaria
IF EXISTS(SELECT * FROM SYSOBJECTS WHERE TYPE ='U' AND NAME ='TIPO_USUARIO')
DROP TABLE TIPO_USUARIO
GO

CREATE TABLE TIPO_USUARIO(
idTipoUsuario int Identity(1,1),
descTipoUsuario varchar(20) NOT NULL,
CONSTRAINT PK_TIPO_USUARIO PRIMARY KEY(idTipoUsuario)
)
GO
o bien se puede especificar la llave primaria fuera de la definicion de tabla
ALTER TABLE employee ADD CONSTRAINT PK_TIPO_USUARIO PRIMARY KEY(idTipoUsuario)
Crear tabla SQL DDL con llave primaria y llave foranea
IF EXISTS(SELECT * FROM SYSOBJECTS WHERE TYPE ='U' AND NAME ='USUARIO')
DROP TABLE USUARIO
GO

CREATE TABLE USUARIO(
idUsuario char(8)NOT NULL,
idTipoUsuario int NOT NULL,
nomUsuario varchar(35) NOT NULL,
habilitado bit NOT NULL,
fechaExpCarnet smalldatetime NOT NULL,
fechaVencCarnet smalldatetime NOT NULL,

CONSTRAINT PK_USUARIO_idUsuario PRIMARY KEY(idUsuario),

CONSTRAINT FK_USUARIO_idTipoUsuario FOREIGN KEY (idTipoUsuario) REFERENCES TIPO_USUARIO(idTipoUsuario)

)
GO
de nuevo puede alterarse la tabla fuera de la definicion de esta
alter table libros
  add constraint FK_libros_codigoeditorial
  foreign key (codigoeditorial)
  references editoriales(codigo)
  on update cascade
  on delete cascade;
lunes, agosto 31, 2015