public static CarritoDeCompras_2012.CS.ProxyVentasWS.CarritoItem lccTolc(CarritoItem pf) { //CarritoItem cI = new CarritoItem(); CarritoDeCompras_2012.CS.ProxyVentasWS.CarritoItem cI = new CarritoDeCompras_2012.CS.ProxyVentasWS.CarritoItem(); cI.idProducto = pf.idProducto; cI.NombreProducto = pf.NombreProducto; cI.Cantidad = pf.Cantidad; cI.PrecioUnitario = pf.PrecioUnitario; cI.PrecioTotal = pf.PrecioTotal; return cI; }
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { List<CarritoItem> LCarrito = new List<CarritoItem>(); CarritoItem cI = new CarritoItem(); int id = this.GridView1.SelectedIndex; LCarrito = tc.ObtenerCookie(); LCarrito.RemoveAt(id); tc.GenerarNuevaCookie(LCarrito); //Vuelvo a llamar a la pagina para que relea la cookie Response.Redirect("Carrito.aspx"); }
public List<CarritoItem> ParsearCookieYGenerar(string s2, bool lista) { CarritoItem cI = new CarritoItem(); List<CarritoItem> ListCarrito = new List<CarritoItem>(); //Pruebo reemplazo caracteres primero... s2 = RemoveDiacritics(s2); int size = s2.Length; // DEBO AGREGAR IF SIZE >0... HACER TODO (ES CUANDO NO HAY MAS ITEMS -SE ELIMINA EL ULTIMO-) if (size > 0) { int finaldatos = size - 1; //asi quito el pipe (sin usar caracter de escape) //manejo el incremento para por los caracteres de identificacion (es decir C=&) int inc = 3; //& me separa las variables dentro de la cookie, hay 3 separaciones int indexofa = Contiene(s2, "&", 1); int indexofb = Contiene(s2, "&", 2); int indexofc = Contiene(s2, "&", 3); //aca agregamos solo los datos a cada valor de item string id = s2.Substring(inc, indexofa - inc); //OJO, Cuando elimino el ultimo aca no vale nada... string cantidad = s2.Substring(s2.IndexOf("C=", 1) + inc, indexofb - indexofa - inc - 1); string NombreProducto = s2.Substring(s2.IndexOf("N=", 1) + inc, indexofc - indexofb - inc - 1); string Precio = s2.Substring(s2.IndexOf("P=", 1) + inc, finaldatos - indexofc - inc - 1); //una vez obtenidas todas las variables separamos las comlumnas en arrays string[] array_id = id.Split('|'); string[] array_cantidad = cantidad.Split('|'); string[] array_NombreProducto = NombreProducto.Split('|'); string[] array_Precio = Precio.Split('|'); //ahora creo un vector con el par id=cantidadcolumnas int cantidadDeColumnas = 2; int[,] resultado_final ; if (lista) resultado_final = DevolverCuantasVecesEnLista(array_id, cantidadDeColumnas, array_cantidad); else resultado_final = DevolverCuantasVeces(array_id, cantidadDeColumnas); //valores dentro del array int da = 0; int db = 0; //recorro el array para obtener cada valor de item y luego guardo en el cookie for (int i = 0; i < resultado_final.GetLength(0); i++) for (int j = 0; j < cantidadDeColumnas; j++) { if (j == 0) da = resultado_final[i, j]; else { db = resultado_final[i, j]; string vi = da.ToString(); //me da el valor del item string cvqa = db.ToString(); //me da la cantidad de veces que aparece //opcion1, puedo obtener la posicion del valor en el array principal, //y moverme con esos valores en los otros arrays para recuperar los valores a guardar int posicion = CuantasVeces(vi, array_id, true); if (int.Parse(db.ToString()) > 0) { //le paso la id y la posicion de esa id dentro de cada array con valores cI = GuardarPosicion(posicion, vi, cvqa, array_NombreProducto, array_Precio); ListCarrito.Add(cI); } }//de if j } //de for } //de if size else //si no existen datos para parsear entonces es el ultimo eliminado ListCarrito = null; //devuelvo el carrito generado return ListCarrito; }
public CarritoItem GuardarPosicion(int posicion, string valor, string cantidad, string[] array_NombreProducto,string[] array_Precio) { CarritoItem cI = new CarritoItem(); int id = int.Parse(valor); if (id > 0) { cI.idProducto = id; int cant = int.Parse(cantidad); cI.Cantidad = cant; cI.NombreProducto = array_NombreProducto[posicion]; float conv = float.Parse(array_Precio[posicion].ToString()); //precio unitario cI.PrecioUnitario = Math.Round(conv, 2); //Obtengo el monto total conv = conv * cant; cI.PrecioTotal = Math.Round(conv, 2); } return cI; }
protected void GenerarCookie(object sender, EventArgs e) { /***************************** ****** EN ESTA SECCION ****** ***************************** * Vamos a guardar por cada clic un elemento mas a la cookie * para eso vamos a tomar la fila seleccionada y guardaremos los datos * en las variables correspondientes. Cada vez que haya uno * Nuevo se recuperara el dato actual e ingresara el siguiente. * */ GridViewRow fila = GridView1.SelectedRow; List<CarritoItem> LCarrito = new List<CarritoItem>(); CarritoItem cI = new CarritoItem(); //primero obtengo cookie actual LCarrito = tc.ObtenerCookie(); //verifico si es nula, la creo... if (LCarrito == null) LCarrito = new List<CarritoItem>(); // obtener id id_ = fila.Cells[1].Text.ToString(); //SIN DOBLE PIPE //if (id_.Length > 0) // id_ = "|" + fila.Cells[1].Text.ToString() + id_; //else // id_ = "|" + fila.Cells[1].Text.ToString() + "|" + id_; ////obtener producto producto_[0] = fila.Cells[2].Text.ToString(); ////SIN DOBLE PIPE //if (producto_.Length > 0) // producto_ = "|" + fila.Cells[2].Text.ToString() + producto_; //else // producto_ = "|" + fila.Cells[2].Text.ToString() + "|" + producto_; ////obtener precio precio_[0] = fila.Cells[3].Text.ToString(); ////SIN DOBLE PIPE //if (precio_.Length > 0) // precio_ = "|" + fila.Cells[3].Text.ToString() + precio_; //else // precio_ = "|" + fila.Cells[3].Text.ToString() + "|" + precio_; ////obtener cantidad (siempre sera 1) cantidad_ = cantidad.ToString(); ////SIN DOBLE PIPE //if (cantidad_.Length > 0) // cantidad_ = "|" + cantidad.ToString() + cantidad_; //else // cantidad_ = "|" + cantidad.ToString() + "|" + cantidad_; //guardo datos recolectados cI = pc.GuardarPosicion(0, id_, cantidad_, producto_, precio_); //Carrito.Values["I"] = id_; //Carrito.Values["C"] = cantidad_; //Carrito.Values["N"] = producto_; //Carrito.Values["P"] = precio_ ; ///luego agrego valores de un item LCarrito.Add(cI); //cI.idProducto = id_; //cI.NombreProducto = producto_; //cI.Cantidad = cantidad_; //cI.PrecioUnitario = precio_; //cI.PrecioTotal = pf.PrecioTotal; //string s2 = LCarrito.ToString(); string s2 = tc.ArmarStringDesdeLista(LCarrito); ///finalmente genero la nueva cookie //tc.GenerarNuevaCookie(LCarrito); //vieja forma //ESTO ESTA OK PERO FALTARIA VER XQ CORNO NO SUMA LA CANTIDAD.... tc.GenerarNuevaCookie(pc.ParsearCookieYGenerar(s2,true)); /* nueva forma*/ /*Agrego al carrito //Response.Cookies.Add(Carrito);*/ }