protected void Button_Imprimir_Click(object sender, EventArgs e) { if (!(String.IsNullOrEmpty(HiddenField_ID_CONTRATO.Value))) { registroContrato _registroContrato = new registroContrato(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString()); DataTable tablaInfoContrato = _registroContrato.ObtenerInfoParaImprimirContrato(Convert.ToDecimal(HiddenField_ID_CONTRATO.Value)); NumToLetra numToLetra = new NumToLetra(); string salario_en_letras = numToLetra.Convertir(Convert.ToDecimal(TextBox_Salario.Text).ToString(), true); if(tablaInfoContrato.Rows.Count <= 0) { if(_registroContrato.MensajeError != null) { Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, "No se encontró información para generar el contrato.", Proceso.Error); } else { Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, _registroContrato.MensajeError, Proceso.Error); } } else { String uspReporte = ""; String nombreReporte = ""; string nombre_empresa = null; string nit_empresa = null; string telefono_empresa = null; string direccion_empresa = null; if (Session["idEmpresa"].ToString() == "1") { nombre_empresa = tabla.VAR_NOMBRE_SERTEMPO; nit_empresa = tabla.VAR_NIT_SERTEMPO; telefono_empresa = tabla.VAR_TELEFONO_SERTEMPO; direccion_empresa = tabla.VAR_DOMICILIO_SERTEMPO; } else { if (Session["idEmpresa"].ToString() == "3") { nombre_empresa = tabla.VAR_NOMBRE_EYS; nit_empresa = tabla.VAR_NIT_EYS; telefono_empresa = tabla.VAR_TELEFONO_EYS; direccion_empresa = tabla.VAR_DOMICILIO_EYS; } } DataRow filaInfoContrato = tablaInfoContrato.Rows[0]; if (RadioButton_PRACTICANTE_UNI.Checked) { uspReporte = "RPT_CONTRATACION_CONTRATO_APRENDIZ_UNIVERSITARIO"; nombreReporte = "RPT_CONTRATACION_CONTRATO_APRENDIZ_UNIVERSITARIO.rpt"; uspReporte += " '" + Session["idEmpresa"].ToString() + "'" + ", '" + nombre_empresa + "'" + ", '" + nit_empresa + "'" + ", '" + telefono_empresa + "'" + ", '" + direccion_empresa + "'" + ", '" + TextBox_contrato_aprendiz_universitario_representante_legal.Text + "'" + ", '" + TextBox_contrato_aprendiz_universitario_numero_identificacion.Text + "'" + ", '" + TextBox_contrato_aprendiz_universitario_nombre_institucion.Text + "'" + ", '" + TextBox_contrato_aprendiz_universitario_nit_institucion.Text + "'" + ", '" + TextBox_contrato_aprendiz_universitario_especialidad_aprendiz.Text + "'" + ", '" + filaInfoContrato["ID_EMPLEADO"].ToString() + "'" ; } else if ((RadioButton_SENA_ELECTIVO.Checked) || (RadioButton_SENA_PRODUCTIVO.Checked)) { uspReporte = "RPT_CONTRATACION_CONTRATO_APRENDIZ_SENA"; nombreReporte = "RPT_CONTRATACION_CONTRATO_APRENDIZ_SENA.rpt"; uspReporte += " '" + Session["idEmpresa"].ToString() + "'" + ", '" + nombre_empresa + "'" + ", '" + nit_empresa + "'" + ", '" + telefono_empresa + "'" + ", '" + direccion_empresa + "'" + ", '" + TextBox_contrato_aprendiz_sena_representante_legal.Text + "'" + ", '" + TextBox_contrato_aprendiz_sena_cargo_r_l.Text + "'" + ", '" + TextBox_contrato_aprendiz_sena_numero_documento_r_l.Text + "'" + ", '" + TextBox_contrato_aprendiz_sena_especialidad_aprendiz.Text + "'" + ", '" + TextBox_contrato_aprendiz_sena_curso_aprendiz.Text + "'" + ", '" + TextBox_contrato_aprendiz_nombre_institucion.Text + "'" + ", '" + TextBox_contrato_aprendiz_nit_institucion.Text + "'" + ", '" + TextBox_contrato_aprendiz_centro_formacion.Text + "'" + ", '" + TextBox_contrato_aprendiz_meses_duracion.Text + "'" + ", '" + TextBox_contrato_aprendiz_fecha_inicio.Text + "'" + ", '" + TextBox_contrato_aprendiz_fecha_final.Text + "'" + ", '" + filaInfoContrato["ID_EMPLEADO"].ToString() + "'" ; } else if (DropDownList_Clase_contrato.SelectedValue == ClaseContrato.I.ToString()) { uspReporte = "RPT_CONTRATACION_CONTRATO_INDEFINIDO"; nombreReporte = "RPT_CONTRATACION_CONTRATO_INDEFINIDO.rpt"; uspReporte += " '" + Session["idEmpresa"].ToString() + "'" + ", '" + nombre_empresa + "'" + ", '" + nit_empresa + "'" + ", '" + TextBox_contrato_indefinido_identificacion_empleador.Text + "'" + ", '" + TextBox_contrato_indefinido_nombre_empleador.Text + "'" + ", '" + TextBox_contrato_indefinido_ciudad_domicilio_empleador.Text + "'" + ", '" + telefono_empresa + "'" + ", '" + direccion_empresa + "'" + ", '" + salario_en_letras + "'" + ", '" + filaInfoContrato["ID_EMPLEADO"].ToString() + "'" ; } else { if (DropDownList_Clase_contrato.SelectedValue == ClaseContrato.L_C_C_D_A.ToString()) { } else { if (DropDownList_Clase_contrato.SelectedValue == ClaseContrato.L_S_C_D_A.ToString()) { } else { if (DropDownList_Clase_contrato.SelectedValue == ClaseContrato.O_L.ToString()) { if (DropDownList_FORMA_IMPRESION_CONTRATO.SelectedValue == "COMPLETO") { ImprimirContratoO_L_COMPLETO(filaInfoContrato); } else { if (DropDownList_FORMA_IMPRESION_CONTRATO.SelectedValue == "PREIMPRESO") { uspReporte = "usp_con_reg_contratos_ObtenerInfo_para_imprimir_contrato " + filaInfoContrato["REGISTRO_CONTRATO"].ToString(); nombreReporte = "RPT_CONTRATACION_OBRA_LABOR_PREIMPRESO.rpt "; } } } else { if (DropDownList_Clase_contrato.SelectedValue == ClaseContrato.T_F.ToString()) { } else { if (DropDownList_Clase_contrato.SelectedValue == ClaseContrato.IN.ToString()) { uspReporte = "RPT_CONTRATACION_CONTRATO_INTEGRAL"; nombreReporte = "RPT_CONTRATACION_CONTRATO_INTEGRAL.rpt"; uspReporte += " '" + Session["idEmpresa"].ToString() + "'" + ", '" + nombre_empresa + "'" + ", '" + direccion_empresa + "'" + ", '" + TextBox_contrato_integral_porcentaje_parafiscales.Text + "'" + ", '" + TextBox_contrato_integral_porcentaje_prestacional.Text + "'" + ", '" + filaInfoContrato["ID_EMPLEADO"].ToString() + "'"; } } } } } } String cadenaDeConeccion = ""; if (Session["idEmpresa"].ToString() == "1") { cadenaDeConeccion = ConfigurationManager.ConnectionStrings["siser"].ConnectionString; } else { cadenaDeConeccion = ConfigurationManager.ConnectionStrings["sister"].ConnectionString; } SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(cadenaDeConeccion); String user = builder.UserID; string pass = builder.Password; String server = builder.DataSource; String db = builder.InitialCatalog; SqlConnection conn = new SqlConnection(cadenaDeConeccion); try { using (SqlCommand comando = new SqlCommand(uspReporte, conn)) { using (SqlDataAdapter adaptador = new SqlDataAdapter(comando)) { DataSet ds = new DataSet(); adaptador.Fill(ds); reporte = new ReportDocument(); reporte.Load(Server.MapPath("~/Reportes/Contratacion/" + nombreReporte)); reporte.SetDataSource(ds.Tables[0]); reporte.DataSourceConnections[0].SetConnection(server, db, user, pass); using (var mStream = (MemoryStream)reporte.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)) { Response.AddHeader("Content-Disposition", "attachment;FileName=RPT_PDF.pdf"); Response.Clear(); Response.Buffer = true; Response.ContentType = "application/pdf"; Response.BinaryWrite(mStream.ToArray()); } Response.End(); } } } catch (Exception ex) { Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, ex.Message, Proceso.Error); } finally { if (conn.State != ConnectionState.Closed) conn.Close(); conn.Dispose(); } } } else { Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, "El contrato no ha sido guardado. Debe diligenciar todos los datos de contrato y luego Guardarlos, para poder imprimir el correspondiente documento.", Proceso.Advertencia); } }
protected void Button_ImprimrContrato1_Click(object sender, EventArgs e) { if (!(String.IsNullOrEmpty(HiddenField_ID_CONTRATO.Value))) { registroContrato _registroContrato = new registroContrato(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString()); DataTable tablaInfoContrato = _registroContrato.ObtenerInfoParaImprimirContrato(Convert.ToDecimal(HiddenField_ID_CONTRATO.Value)); NumToLetra numToLetra = new NumToLetra(); string salario_en_letras = ""; if (tablaInfoContrato.Rows.Count <= 0) { if (_registroContrato.MensajeError != null) { Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, "No se encontró información para generar el contrato.", Proceso.Error); } else { Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, _registroContrato.MensajeError, Proceso.Error); } } else { String uspReporte = ""; String nombreReporte = ""; string nombre_empresa = null; string nit_empresa = null; string telefono_empresa = null; string direccion_empresa = null; if (Session["idEmpresa"].ToString() == "1") { nombre_empresa = tabla.VAR_NOMBRE_SERTEMPO; nit_empresa = tabla.VAR_NIT_SERTEMPO; telefono_empresa = tabla.VAR_TELEFONO_SERTEMPO; direccion_empresa = tabla.VAR_DOMICILIO_SERTEMPO; } else { if (Session["idEmpresa"].ToString() == "3") { nombre_empresa = tabla.VAR_NOMBRE_EYS; nit_empresa = tabla.VAR_NIT_EYS; telefono_empresa = tabla.VAR_TELEFONO_EYS; direccion_empresa = tabla.VAR_DOMICILIO_EYS; } } DataRow filaInfoContrato = tablaInfoContrato.Rows[0]; salario_en_letras = numToLetra.Convertir(Convert.ToDecimal(filaInfoContrato["SALARIO"]).ToString(), true); if (filaInfoContrato["PRACTICANTE_UNIVERSITARIO"].ToString().ToUpper() == "S") { Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, "No se puede reimprimir el contrato de aprendizaje.", Proceso.Advertencia); } else if ((filaInfoContrato["SENA_ELECTIVO"].ToString().ToUpper() == "S") || (filaInfoContrato["SENA_LEC"].ToString().ToUpper() == "S") || (filaInfoContrato["SENA_PRO"].ToString().ToUpper() == "S") || (filaInfoContrato["SENA_PRODUCTIVO"].ToString().ToUpper() == "S")) { Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, "No se puede reimprimir el contrato de aprendizaje.", Proceso.Advertencia); } else if (filaInfoContrato["CLASE_CONTRATO"].ToString().ToUpper().Trim() == ClaseContrato.I.ToString()) { Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, "No se puede reimprimir el contrato integral.", Proceso.Advertencia); } else { if (filaInfoContrato["CLASE_CONTRATO"].ToString().ToUpper().Trim() == ClaseContrato.L_C_C_D_A.ToString()) { Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, "No se puede reimprimir el contrato.", Proceso.Advertencia); } else { if (filaInfoContrato["CLASE_CONTRATO"].ToString().ToUpper().Trim() == ClaseContrato.L_S_C_D_A.ToString()) { } else { if (filaInfoContrato["CLASE_CONTRATO"].ToString().ToUpper().Trim() == ClaseContrato.O_L.ToString()) { if (RadioButtonList_impresion_contrato.SelectedValue == "COMPLETO") { ImprimirContratoO_L_COMPLETO(filaInfoContrato); } else { if (RadioButtonList_impresion_contrato.SelectedValue == "PREIMPRESO") { uspReporte = "usp_con_reg_contratos_ObtenerInfo_para_imprimir_contrato " + filaInfoContrato["REGISTRO_CONTRATO"].ToString(); nombreReporte = "RPT_CONTRATACION_OBRA_LABOR_PREIMPRESO.rpt "; } } } else { if (filaInfoContrato["CLASE_CONTRATO"].ToString().ToUpper().Trim() == ClaseContrato.T_F.ToString()) { Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, "No se puede reimprimir el contrato.", Proceso.Advertencia); } else { if (filaInfoContrato["CLASE_CONTRATO"].ToString().ToUpper().Trim() == ClaseContrato.IN.ToString()) { Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, "No se puede reimprimir el contrato integral.", Proceso.Advertencia); } } } } } } String cadenaDeConeccion = ""; if (Session["idEmpresa"].ToString() == "1") { cadenaDeConeccion = ConfigurationManager.ConnectionStrings["siser"].ConnectionString; } else { cadenaDeConeccion = ConfigurationManager.ConnectionStrings["sister"].ConnectionString; } SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(cadenaDeConeccion); String user = builder.UserID; string pass = builder.Password; String server = builder.DataSource; String db = builder.InitialCatalog; SqlConnection conn = new SqlConnection(cadenaDeConeccion); try { using (SqlCommand comando = new SqlCommand(uspReporte, conn)) { using (SqlDataAdapter adaptador = new SqlDataAdapter(comando)) { DataSet ds = new DataSet(); adaptador.Fill(ds); reporte = new ReportDocument(); reporte.Load(Server.MapPath("~/Reportes/Contratacion/" + nombreReporte)); reporte.SetDataSource(ds.Tables[0]); reporte.DataSourceConnections[0].SetConnection(server, db, user, pass); using (var mStream = (MemoryStream)reporte.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)) { Response.AddHeader("Content-Disposition", "attachment;FileName=RPT_PDF.pdf"); Response.Clear(); Response.Buffer = true; Response.ContentType = "application/pdf"; Response.BinaryWrite(mStream.ToArray()); } Response.End(); } } } catch (Exception ex) { Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, ex.Message, Proceso.Error); } finally { if (conn.State != ConnectionState.Closed) conn.Close(); conn.Dispose(); } } } else { Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, "El contrato no ha sido guardado. Debe diligenciar todos los datos de contrato y luego Guardarlos, para poder imprimir el correspondiente documento.", Proceso.Advertencia); } }