public void guardarEmpresaArchivo(Empresa e) { List<Empresa> lst = (List<Empresa>)Session["empresas"]; string archivo_usuarios = "~/App_Data/empresas.csv"; string archivo_en_disco = Server.MapPath(archivo_usuarios); if (System.IO.File.Exists(archivo_en_disco)) { try { System.IO.File.Delete(archivo_en_disco); } catch (System.IO.IOException ex) { this.error.InnerText = "Error al borrar archivo de empresas"; } } //File.Create(archivo_usuarios); TextWriter tw = new StreamWriter(archivo_usuarios); for (int i = 0; i < lst.Count; i++) { tw.WriteLine(lst[i].ToString()); } tw.Close(); }
public void add(Empresa e) { if (e != null) { List<Empresa> lst = (List<Empresa>)Session["empresas"]; lst.Add(e); } else throw new Exception("Empresa null"); }
/// <summary> /// /// </summary> /// <param name="e"></param> public Empresa(Empresa e) { NIF = e.NIF.ToUpper(); Nombre = e.Nombre; Email = e.Email; if (e.Fnac != null) { Fnac = new DateTime(e.Fnac.Ticks); } else Fnac = new DateTime(); Direccion = e.Direccion; Poblacion = e.Poblacion; Representante = e.Representante; Pyme = e.Pyme; Telefono = e.Telefono; Foto = e.foto; Carpeta = e.Carpeta; }
protected void Page_Load(object sender, EventArgs e) { List<Empresa> lst = (List<Empresa>)Session["empresas"]; if (this.IsPostBack) { this.Validate(); if (this.IsValid) { DateTime f; string[] fecha = this.txtFnac.Text.Split('/'); if (fecha.Length == 3) { int dia = Int32.Parse(fecha[0]); int mes = Int32.Parse(fecha[1]); int anio = Int32.Parse(fecha[2]); f = new DateTime(anio, mes, dia); } else f = DateTime.Now; if (!Directory.Exists(Server.MapPath("~/Private/" + this.txtNombre.Text))) { try { Empresa empresa = new Empresa("", "", this.txtDni.Text, this.txtNombre.Text, this.txtEmail.Text, f, this.txtDireccion.Text, this.txtPoblacion.Text, this.txtRepresentate.Text, this.txtPyme.Checked, this.txtTlf.Text); //add(empresa); //si es solo un archivo if (this.file_u.HasFile) { Directory.CreateDirectory(Server.MapPath("~/Private/" + this.txtNombre.Text + "/Logo")); //cogemos el nombre del archivo dada la ruta string archivo = Path.GetFileName(this.file_u.FileName); //guardamos en el servidor, en la ruta completa this.file_u.SaveAs(Server.MapPath("~/Private/" + this.txtNombre.Text + "/Logo/" + archivo)); empresa.Foto = "~/Private/" + this.txtNombre.Text + "/Logo/" + archivo; } //si tenemos varios archivos if (this.fu_archivos.HasFiles) { Directory.CreateDirectory(Server.MapPath("~/Private/" + this.txtNombre.Text + "/Archivos")); for (int i = 0; i < this.fu_archivos.PostedFiles.Count; i++) { string archivo = Path.GetFileName(this.fu_archivos.PostedFiles[i].FileName); this.fu_archivos.PostedFiles[i].SaveAs(Server.MapPath("~/Private/" + this.txtNombre.Text + "/Archivos/" + archivo)); } empresa.Carpeta = "~/Private/" + this.txtNombre.Text + "/Archivos"; } guardarEmpresaArchivo(empresa); List<string> acc = (List<string>)Session["acciones"]; //guardamos la accion en la variable de sesion acc.Add("Empresa guardada"); } catch (Exception ex) { this.error.InnerText = "Error al crear la empresa"; //Response.Write("<script>alert('Error al crear empresa: '"+ex+")</script>"); } } Response.Redirect("Default.aspx"); } } else { } MostrarAcciones(); }