Vous êtes sur la page 1sur 6

using using using using using using using using

System; System.Collections.Generic; System.Linq; System.Web; System.Web.UI; System.Web.UI.WebControls; System.IO; System.Web.UI.HtmlControls;

public partial class Operaciones_Certificado_subir : System.Web.UI.Page { Button btns = new Button(); protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { Session["noDocumentos"] = "1|1|1|1|5"; string s = Convert.ToString(Session["noDocumentos"]); int cont = s.Count(); string[] separador = s.Split('|'); CrearFileDinamico(Convert.ToInt32(separador[0]), 1); } else if (Page.IsPostBack == true) { Session["certificadoCompletado"] = false; } } public void CrearFileDinamico(int no_paginas,int no_div) { //for (int ndiv = 1; ndiv <= no_div; ndiv++) { #region "DivResultado" string cadena = "variable" + Convert.ToString(Session["Tramit"]); if (Session[cadena] == null) { } else { HtmlGenericControl DivResultado = new HtmlGenericControl("div"); DivResultado.ID = "Resultado"; DivResultado.Style.Add(HtmlTextWriterStyle.Height, "auto"); DivResultado.Style.Add(HtmlTextWriterStyle.Width, "600px"); DivResultado.Style.Add(HtmlTextWriterStyle.BackgroundColor, "SpringG reen"); Panel res1 = new Panel(); //DivResultado.InnerHtml = "<center>Tramite " + no_div + "</center>" ; string cad = Convert.ToString(Session[cadena]); int cont = cad.Count(); string[] separador2 = cad.Split('|'); string cad2 = Convert.ToString(Session["variable3"]); string[] separador3 = cad2.Split('|'); //separador3 = cad2.Split(' '); res1.Controls.Add(new LiteralControl("<table width='auto'>")); int cont2 = cad2.Count(); foreach (string x2 in separador3) { if (x2 == "") { }

else { res1.Controls.Add(new LiteralControl("<tr><td COLSPAN=2>Tram ite " + x2 + "</td></tr><tr>")); foreach (string x1 in separador2) { Label label2 = new Label(); label2.Text = x1; res1.Controls.Add(new LiteralControl("<td>")); res1.Controls.Add(label2); res1.Controls.Add(new LiteralControl("</td>")); //if (x1.Count() % 2 == 0) { // res1.Controls.Add(new LiteralControl("<br />")); //} else { //} if (x1.Count() % 2 == 0) { res1.Controls.Add(new LiteralControl("<tr></tr>")); //p1.Controls.Add(new LiteralControl("<br />")); } } res1.Controls.Add(new LiteralControl("</td></tr>")); } } res1.Controls.Add(new LiteralControl("</table>")); DivResultado.Controls.Add(res1); form1.Controls.Add(DivResultado); } #endregion #region "DivDinamico" HtmlGenericControl dynDiv = new HtmlGenericControl("div"); dynDiv.ID = "div"+ no_div; dynDiv.Style.Add(HtmlTextWriterStyle.Height, "auto"); dynDiv.Style.Add(HtmlTextWriterStyle.Width, "600px"); if (no_div % 2 == 0) { dynDiv.Style.Add(HtmlTextWriterStyle.BackgroundColor, "SlateGray"); } else { dynDiv.Style.Add(HtmlTextWriterStyle.BackgroundColor, "DarkGray"); } dynDiv.InnerHtml = "<center>Tramite " + no_div+"</center>"; Panel p1 = new Panel(); p1.Controls.Add(new LiteralControl("<table width='auto'><tr>")); for (int i = 1; i <= no_paginas; i++) { Label label = new Label(); FileUpload file = new FileUpload(); RequiredFieldValidator control = new RequiredFieldValidator(); file.ID = "FileUpload" + i; //file.Width = 200; control.ID = "validador" + i; control.ControlToValidate = file.ID;

control.ErrorMessage = "* Falta introducir el archivo <br />"; control.Display = ValidatorDisplay.Dynamic; control.Style.Add("Font-Size", "Small"); //control.CssClass = "MyClass"; control.ForeColor = System.Drawing.Color.Red; control.SetFocusOnError=true; control.EnableClientScript=true; if (i % 2 == 0) { label.Text = "Reverso: "; } else { label.Text = "Adverso: "; } p1.Controls.Add(new LiteralControl("<td>")); p1.Controls.Add(control); p1.Controls.Add(label); p1.Controls.Add(file); p1.Controls.Add(new LiteralControl("</td>")); if (i % 2 == 0) { p1.Controls.Add(new LiteralControl("<tr></tr>")); //p1.Controls.Add(new LiteralControl("<br />")); } } p1.Controls.Add(new LiteralControl("</td></tr></table>")); //p1.Controls.Add(btns); dynDiv.Controls.Add(p1); form1.Controls.Add(dynDiv); //} //System.Text.StringBuilder sb = new System.Text.StringBuilder(); ////sb.Append(@"<script src='../css/jqueryui/jquery-1.8.0.js' type='text /javascript'></script>"); //sb.Append(@"<script language='javascript'>"); //sb.Append(@"$(document).ready(function () {"); ////sb.Append(@"alert('hola');"); //sb.Append(@"for (var x = 2; x <= " + Session["v"] + ";x++) {"); //sb.Append(@"$('#div' + x).hide();"); //sb.Append(@"}});"); //sb.Append(@"</script>"); //if (!ClientScript.IsStartupScriptRegistered("JSScript")) //{ // ClientScript.RegisterStartupScript(this.GetType(), "JSScript", sb. ToString()); // //ClientScript.RegisterStartupScript(this.GetType(), "JSScript", " <script>alert('prueba');</script>",true); //} #endregion //} } protected void subir(object sender, EventArgs e)

{ try { SubirArchivosEnDocumentos(); Session["Tramite"] =Convert.ToInt32(Session["Tramite"])+ 1; string s = Convert.ToString(Session["noDocumentos"]); int cont = s.Count(); string[] separador = s.Split('|'); int numero = Convert.ToInt32(Session["Tramite"]); CrearFileDinamico(Convert.ToInt32(separador[numero]), numero + 1); //foreach (string x in separador) //{ // int nu = Convert.ToInt32(x); // // CrearFileDinamico(nu, contador); contador++;

} catch (Exception ee) { lblError.Text = ee.Message; } } //protected void subir2_Click(object sender, EventArgs e) //{ // try // { // SubirArchivosEnDocumentos(); // } // catch (Exception ee) // { // //lblError.Text = ee.Message; // } //} private void SubirArchivosEnDocumentos() { Panel p1 = new Panel(); Session["Tramit"]=Convert.ToUInt32(Session["Tramit"])+1; string cadena = "variable" + Convert.ToString(Session["Tramit"]); // check if file has been selected HttpFileCollection files = Request.Files; for (int i = 0; i < files.Count; i++) { Label etiqueta = new Label(); HttpPostedFile file = files[i]; if (file.ContentLength > 0) { string path = Server.MapPath("~/Documentos/"); string fileName = Path.GetFileName(file.FileName); //now save the file to the disk file.SaveAs(path + fileName); Session[cadena] = Session[cadena] + fileName + "|"; etiqueta.ID = "label" + i;

etiqueta.Text= fileName ; //p1.Controls.Add(etiqueta); p1.Controls.Add(new LiteralControl("<br />")); form1.Controls.Add(p1); //lblMessage.Text += "File : <b>" + fileName + "</b> uploaded su ccessfully !<br />"; } } Session["variable2"] = Convert.ToInt32(Session["variable2"]) + 1 ; Session["variable3"] =Session["variable3"]+ Convert.ToString(Session["va riable2"]) + "|"; } //public void crearDiv(){ // HtmlGenericControl dynDiv =new HtmlGenericControl("DIV"); //dynDiv.ID = "div1"; //dynDiv.Style.Add(HtmlTextWriterStyle.BackgroundColor, "Gray"); //dynDiv.Style.Add(HtmlTextWriterStyle.Height, "auto"); //dynDiv.Style.Add(HtmlTextWriterStyle.Width, "auto"); //dynDiv.InnerHtml = "I was created using Code Behind"; //Panel p1 = new Panel(); //for (int i = 1; i <= 2; i++) //{ // Label label = new Label(); // FileUpload file = new FileUpload(); // // // // // // // // // // // // // // // //} ////btns.Text = "Guardar"; ////btns.Load += new System.EventHandler(this.Page_Load); ////btns.Click += new System.EventHandler(this.subir); ////form1.Controls.Add(btns); ////btns.Text = "Guardar"; ////Button1.Click += new EventHandler(this.GreetingBtn_Click); ////InitializeComponent(); ////btns.Click += new EventHandler(subir2_Click); if (i % 2 == 0) { label.Text = "Reverso"; } else { label.Text = "Adverso "; } p1.Controls.Add(label); file.ID = "FileUpload" + i; p1.Controls.Add(file); if (i % 2 == 0) { p1.Controls.Add(new LiteralControl("<br />")); }

//form1.Controls.Add(btns); //dynDiv.Controls.Add(p1); //form1.Controls.Add(dynDiv); //} }

Vous aimerez peut-être aussi