示例#1
0
        private void cmdConstancia_Click(object sender, EventArgs e)
        {
            WSLicitaciones.WSLicitaciones WSLic = new WSLicitaciones.WSLicitaciones();
            WSLic.Url = mdlGenerales.DireccionWS + "FazServices/WSLicitaciones.asmx";
            DataSet   DSDevuelveID         = new DataSet();
            DataTable DTDevuelveID         = new DataTable();
            DataSet   DSDevuelveValidacion = new DataSet();
            DataTable DTDevuelveValidacion = new DataTable();
            String    strResultado         = "";
            Int32     intResultado         = 0;
            String    strNDoc      = "";
            String    strApellidos = "";
            String    strNombres   = "";

            /*************************
            * Validación de  datos
            *************************/

            if (lblIDCargo.Text.ToString() == "")
            {
                MessageBoxAdv.Show("Debe de seleccionar un cargo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCargo.Focus();
                return;
            }

            DSDevuelveValidacion = WSLic.ValidaExperiencia(mdlGenerales.Conexion,
                                                           txtTipoDoc.Text.ToString(), txtNDoc.Text.ToString(), lblItem.Text,
                                                           lblIDCargo.Text.ToString(), txtCliente.Text.ToString(), txtComentario.Text.ToString(),
                                                           dtpInicio.Value.ToString("yyyy/MM/dd"), dtpFin.Value.ToString("yyyy/MM/dd"));
            DTDevuelveValidacion = DSDevuelveValidacion.Tables[0];

            foreach (DataRow Row in DTDevuelveValidacion.Rows)
            {
                intResultado = Convert.ToInt32(Row[0].ToString());
                strResultado = Row[1].ToString();
                strNDoc      = Row[2].ToString();
                strApellidos = Row[3].ToString();
                strNombres   = Row[4].ToString();
            }

            if (intResultado == -2)
            {
                if (MessageBoxAdv.Show("El objeto esta presente en otro personal: " + strNDoc + " " + strApellidos + " " + strNombres, "Información", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) != DialogResult.OK)
                {
                    MessageBoxAdv.Show("Se cancelo el ingreso de la experiencia", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            if (intResultado == -1)
            {
                if (MessageBoxAdv.Show("Existe un traslape de fechas en la experiencia, desea continuar", "Información", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) != DialogResult.OK)
                {
                    MessageBoxAdv.Show("Se cancelo el ingreso de la experiencia", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            if (dtpInicio.Value > dtpFin.Value)
            {
                MessageBoxAdv.Show("La fecha de Inicio no puede ser mayor que la fecha de fin de la experiencia", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                dtpInicio.Focus();
                return;
            }
            if (txtComentario.Text.ToString() == "")
            {
                MessageBoxAdv.Show("Debe de registrar el comentario de la experiencia", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtComentario.Focus();
                return;
            }
            if (txtRubro.Text.ToString() == "")
            {
                MessageBoxAdv.Show("Debe de registrar el rubro", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRubro.Focus();
                return;
            }
            if (txtCliente.Text.ToString() == "")
            {
                MessageBoxAdv.Show("Debe de registrar el cliente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCliente.Focus();
                return;
            }
            if (lblIDCargo.Text.ToString() == "")
            {
                MessageBoxAdv.Show("Debe de seleccionar un cargo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCargo.Focus();
                return;
            }

            /*try
            *  {
            *   if (txtArchivo.Text != "")
            *       DeleteFile(txtArchivo.Text);
            *  }
            *  catch
            *  { }*/
            string NombreArchivo = string.Concat(txtNDoc.Text.ToString(), "_", txtCliente.Text.ToString(), "_", txtCargo.Text.ToString(), "_", txtRubro.Text.ToString(), "_", dtpInicio.Value.ToString("yyyyMMdd"), "_", dtpFin.Value.ToString("yyyyMMdd"));

            NombreArchivo = NombreArchivo.Replace(" ", "");
            string extension = "";

            /*************************
            * Subiendo Constancia
            *************************/
            DialogResult result = openFileDialog1.ShowDialog();

            if (result == DialogResult.OK) // Test result.
            {
                FileInfo fi = new FileInfo(openFileDialog1.FileName);
                if (fi.Exists)
                {
                    extension = fi.Extension.ToString();
                    fi.CopyTo(openFileDialog1.FileName.Replace(openFileDialog1.SafeFileName, "") + NombreArchivo + extension);
                }
                Upload(openFileDialog1.FileName.Replace(openFileDialog1.SafeFileName, "") + NombreArchivo + extension, "");
                File.Delete(openFileDialog1.FileName.Replace(openFileDialog1.SafeFileName, "") + NombreArchivo + extension);
            }
            else
            {
                MessageBoxAdv.Show("Se cancelo el registro", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string Item = "";

            if (lblItem.Text.ToString() == ("0"))
            {
                Item = "0";
            }
            else
            {
                Item = lblItem.Text.ToString();
            }

            /************************************
            * Registrando experiencia en BD
            ************************************/
            DSDevuelveID = WSLic.ActualizaPersonalLicExperiencia(mdlGenerales.Conexion,
                                                                 txtTipoDoc.Text.ToString(), txtNDoc.Text.ToString(), lblItem.Text,
                                                                 lblIDCargo.Text.ToString(), txtRubro.Text.ToString(), txtCliente.Text.ToString(),
                                                                 txtComentario.Text.ToString(),
                                                                 dtpInicio.Value.ToString("yyyy/MM/dd"), dtpFin.Value.ToString("yyyy/MM/dd"),
                                                                 NombreArchivo + extension,
                                                                 mdlGenerales.STRUsuario);
            DTDevuelveID = DSDevuelveID.Tables[0];
            foreach (DataRow Row in DTDevuelveID.Rows)
            {
                intResultado = Convert.ToInt32(Row[0].ToString());
                strResultado = Row[1].ToString();
            }

            if (intResultado != 0)
            {
                MessageBoxAdv.Show(strResultado, "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Limpiar();
                CargaGrid(txtTipoDoc.Text.ToString(), txtNDoc.Text.ToString(), txtNombres.Text.ToString(),
                          txtApellidos.Text.ToString(), txtTelefono1.Text.ToString(), txtEmail.Text.ToString());
            }
            else
            {
                MessageBoxAdv.Show(strResultado, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }