Exemplo n.º 1
0
        protected void btnProcesar_Click(object sender, EventArgs e)
        {
            List <Data2.Class.Struct_Unidades> t_unidades = Data2.Class.Struct_Unidades.GetAll();
            int UnidadPorDefecto = 0;

            if (t_unidades.Count > 0)
            {
                UnidadPorDefecto = t_unidades[0].Id;
            }

            if (CmbFileList.Items.Count > 0)
            {
                string FileName = CmbFileList.SelectedItem.Text;
                Data2.Statics.Log.ADD("Examinando:" + FileName, this);
                System.IO.StreamReader file = new System.IO.StreamReader(PortalSettings.HomeDirectoryMapPath + "\\" + "UsersUpdate\\" + UserId.ToString() + "\\" + FileName, System.Text.Encoding.Default);
                bool failure = false;


                string firstLine = "";
again:
                if (!file.EndOfStream)
                {
                    firstLine = file.ReadLine().ToLower();

                    /*firstLine = firstLine.Replace("\u001a", "");
                    *  firstLine = firstLine.Replace("\u0011", "");
                    *  firstLine = firstLine.Replace("\u0007", "");
                    *  firstLine = firstLine.Replace("\u0000", "");
                    *  firstLine = firstLine.Replace("\u0016", "");
                    *  firstLine = firstLine.Replace("\u001d", "");*/
                    if (!firstLine.Contains("codigo"))
                    {
                        goto again;
                    }
                    Data2.Statics.Log.ADD(firstLine, this);
                }



                //firstLine = firstLine.Replace("\u001a", "");
                //firstLine = firstLine.Replace("\u0007", "");
                //firstLine = firstLine.Replace("\u0000", "");



                if (!firstLine.Contains("codigo"))
                {
                    failure = true;
                }
                if (!firstLine.Contains("precioneto"))
                {
                    failure = true;
                }
                if (!firstLine.Contains("iva"))
                {
                    failure = true;
                }
                if (!firstLine.Contains("preciocompra"))
                {
                    failure = true;
                }
                if (!firstLine.Contains("porcentajeganancia"))
                {
                    failure = true;
                }
                if (!firstLine.Contains("preciofinal"))
                {
                    failure = true;
                }
                Data2.Statics.Log.ADD("Primera Linea:" + firstLine, this);
                if (failure == false)
                {
                    int      indexcodigo             = -1;
                    int      indexprecioneto         = -1;
                    int      indexiva                = -1;
                    int      indexpreciocompra       = -1;
                    int      indexporcentajeganancia = -1;
                    int      indexpreciofinal        = -1;
                    int      indexdescripcion        = -1;
                    int      indexcodigodebarra      = -1;
                    string[] splitter                = { "\t" };
                    string[] fields = firstLine.Split(splitter, StringSplitOptions.None);

                    for (int a = 0; a < fields.Length; a++)
                    {
                        if (fields[a] == "codigo")
                        {
                            indexcodigo = a;
                        }
                        if (fields[a] == "precioneto")
                        {
                            indexprecioneto = a;
                        }
                        if (fields[a] == "iva")
                        {
                            indexiva = a;
                        }
                        if (fields[a] == "preciocompra")
                        {
                            indexpreciocompra = a;
                        }
                        if (fields[a] == "porcentajeganancia")
                        {
                            indexporcentajeganancia = a;
                        }
                        if (fields[a] == "preciofinal")
                        {
                            indexpreciofinal = a;
                        }
                        if (fields[a] == "descripcion")
                        {
                            indexdescripcion = a;
                        }
                        if (fields[a] == "codigobarra")
                        {
                            indexcodigodebarra = a;
                        }
                    }


                    int UpdateSucces = 0;
                    int UpdateError  = 0;
                    int NewSucces    = 0;
                    int NewError     = 0;

                    string line;
                    while ((line = file.ReadLine()) != null)
                    {
                        Console.WriteLine(line);

                        string[] separatevalues = line.Split(splitter, StringSplitOptions.None);
                        if (separatevalues.Length >= 5)
                        {
                            string  artcod             = separatevalues[indexcodigo];
                            decimal precioneto         = Data2.Statics.Conversion.GetDecimal(separatevalues[indexprecioneto]);
                            decimal iva                = Data2.Statics.Conversion.GetDecimal(separatevalues[indexiva]);
                            decimal preciocompra       = Data2.Statics.Conversion.GetDecimal(separatevalues[indexpreciocompra]);
                            decimal porcentajeganancia = Data2.Statics.Conversion.GetDecimal(separatevalues[indexporcentajeganancia]);
                            decimal preciofinal        = Data2.Statics.Conversion.GetDecimal(separatevalues[indexpreciofinal]);
                            string  descripcion        = artcod;
                            string  codigobarra        = artcod;
                            if (indexdescripcion != -1)
                            {
                                descripcion = separatevalues[indexdescripcion];
                                descripcion = descripcion.Replace("\"\"", "*");
                                descripcion = descripcion.Replace("\"", "");
                                descripcion = descripcion.Replace("*", "\"");
                            }
                            if (indexcodigodebarra != -1)
                            {
                                codigobarra = separatevalues[indexcodigodebarra];
                            }
                            int IdProveddor    = int.Parse(CmbUpdateProviders.SelectedValue);
                            int IdMateriaPrima = int.Parse(cmbMateriaPrima.SelectedValue);
                            Data2.Class.Struct_Producto MyProduct = Data2.Class.Struct_Producto.SelectSingleArticle(UserId, IdProveddor, artcod);
                            if (MyProduct != null)
                            {
                                MyProduct.PrecioNeto         = precioneto;
                                MyProduct.IVA                = iva;
                                MyProduct.PorcentajeGanancia = porcentajeganancia;
                                MyProduct.PrecioFinal        = preciofinal;

                                if (MyProduct.ActualizarPrecios() == true)
                                {
                                    UpdateSucces++;
                                }
                                else
                                {
                                    UpdateError++;
                                }
                            }
                            else
                            {
                                bool esmateriaprima = false;
                                if (ChkMateriaPrima.Checked == true)
                                {
                                    esmateriaprima = true;
                                }
                                MyProduct = new Data2.Class.Struct_Producto(UserId, IdProveddor, artcod, codigobarra, descripcion, precioneto, iva, preciocompra, porcentajeganancia, preciofinal, UnidadPorDefecto, esmateriaprima, IdMateriaPrima);
                                if (MyProduct.Guardar() == true)
                                {
                                    NewSucces++;
                                }
                                else
                                {
                                    NewError++;
                                }
                            }
                        }
                    }

                    string RESVALUE = NewSucces.ToString() + "-" + NewError.ToString() + "-" + UpdateSucces.ToString() + "-" + UpdateError.ToString();
                    Data2.Statics.Log.ADD("NUEVOS EXITOSOS:" + NewSucces.ToString() + "NUEVOS ERROR:" + NewError.ToString() + "UPDATES EXITOSOS:" + UpdateSucces.ToString() + "NUEVOS EXITOSOS:" + UpdateError.ToString(), this);
                    file.Close();
                    //Fin de recorrido...
                    Response.Redirect("~/MyManager/Articulos?Message=Success3&Res=" + RESVALUE);
                }
                else
                {
                    Data2.Statics.Log.ADD("Campos Incorrectos", this);
                    file.Close();
                    Response.Redirect("~/MyManager/Articulos?Message=Error3");
                }
            }
        }
Exemplo n.º 2
0
        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            CheckFields();
            if (isOk == true)
            {
                if (Mode.Value.ToLower() == "none")
                {
                    bool materiaprima = false;
                    if (ChkMateriaPrima.Checked == true)
                    {
                        materiaprima = true;
                    }
                    Data2.Class.Struct_Producto t_PRD = new Data2.Class.Struct_Producto(
                        UserId,
                        int.Parse(cmbProveedor.SelectedValue),
                        txtCodigo.Text,
                        txtCodigoDeBarra.Text,
                        txtNombre.Text,
                        Data2.Statics.Conversion.GetDecimal(txtPrecioNeto.Text),
                        Data2.Statics.Conversion.GetDecimal(txtPorcentajeIVA.Text),
                        Data2.Statics.Conversion.GetDecimal(txtPrecioCompra.Text),
                        Data2.Statics.Conversion.GetDecimal(txtPorcentajeGanancia.Text),
                        Data2.Statics.Conversion.GetDecimal(txtPrecioFinal.Text),
                        int.Parse(cmbUnidades.SelectedValue),
                        materiaprima,
                        int.Parse(cmbMateriaPrima.SelectedValue));
                    if (t_PRD.Guardar() == true)
                    {
                        Response.Redirect("~/MyManager/Articulos?Message=Success1");
                    }
                    else
                    {
                        Response.Redirect("~/MyManager/Articulos?Message=Error1");
                    };
                }
                else if (Mode.Value.ToLower() == "fedt")
                {
                    if (IdArt.Value != "0")
                    {
                        int IDART = int.Parse(IdArt.Value);

                        Data2.Class.Struct_Producto PRD = Data2.Class.Struct_Producto.Get_SingleArticle(UserId, IDART);
                        if (PRD != null)
                        {
                            PRD.IdProveedor        = int.Parse(cmbProveedor.SelectedValue);
                            PRD.CodigoInterno      = txtCodigo.Text;
                            PRD.CodigoBarra        = txtCodigoDeBarra.Text;
                            PRD.Descripcion        = txtNombre.Text;
                            PRD.PrecioNeto         = Data2.Statics.Conversion.GetDecimal(txtPrecioNeto.Text);
                            PRD.IVA                = Data2.Statics.Conversion.GetDecimal(txtPorcentajeIVA.Text);
                            PRD.PrecioCompra       = Data2.Statics.Conversion.GetDecimal(txtPrecioCompra.Text);
                            PRD.PorcentajeGanancia = Data2.Statics.Conversion.GetDecimal(txtPorcentajeGanancia.Text);
                            PRD.PrecioFinal        = Data2.Statics.Conversion.GetDecimal(txtPrecioFinal.Text);
                            PRD.IdUnidad           = int.Parse(cmbUnidades.SelectedValue);
                            PRD.EsMateriaPrima     = ChkMateriaPrima.Checked;

                            if (PRD.Actualizar(UserId))
                            {
                                Response.Redirect("~/MyManager/Articulos?Message=Success1");
                            }
                            else
                            {
                                Response.Redirect("~/MyManager/Articulos?Message=Error1");
                            }
                        }
                    }
                }
            }
        }