Example #1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            Transfers transferencia = new Transfers();

            using (transferencia)
            {
                transferencia.Folio        = Convert.ToInt16(txtFolios.Text);
                transferencia.Tipo_trapaso = "E";
                transferencia.Sucursal     = cbOficinas.SelectedValue.ToString();
                transferencia.Subtotal     = Convert.ToDouble(txtSubtotal.Text);
                transferencia.Iva          = 0;
                transferencia.Total        = 0;
                transferencia.Facturado    = Convert.ToInt16(false);
                transferencia.CreateTransfer();
                List <Transfers> ultimo = transferencia.getTransferbyfolio(Convert.ToInt16(txtFolios.Text), "E");

                Det_transfers detalles = new Det_transfers();
                using (detalles)
                {
                    detalles.Folio = Convert.ToInt16(txtFolios.Text);
                    detalles.Tipo  = "E";

                    Product poductos = new Product();
                    foreach (DataGridViewRow row in dtProductos.Rows)
                    {
                        detalles.Cantidad    = Convert.ToDouble(row.Cells["cantidad"].Value.ToString());
                        detalles.Id_producto = Convert.ToInt16(row.Cells["id"].Value.ToString());
                        detalles.Precio      = Convert.ToDouble(row.Cells["p_u"].Value.ToString());
                        detalles.CreateDet();
                        using (poductos)
                        {
                            List <Product> producto = poductos.getProductById(Convert.ToInt16(row.Cells["id"].Value.ToString()));
                            Kardex         kardex   = new Kardex();
                            using (kardex)
                            {
                                kardex.Id_producto  = Convert.ToInt16(row.Cells["id"].Value.ToString());
                                kardex.Tipo         = "T";
                                kardex.Id_documento = ultimo[0].Id;
                                kardex.Cantidad     = Convert.ToDouble(row.Cells["cantidad"].Value.ToString());
                                kardex.Antes        = producto[0].Existencia;
                                kardex.CreateKardex();

                                List <Kardex> ultimo_kardez = kardex.getidKardex(Convert.ToInt16(row.Cells["id"].Value.ToString()), ultimo[0].Id, "T");
                                Afecta_inv    afecta        = new Afecta_inv();
                                using (afecta)
                                {
                                    afecta.Disminuye(ultimo_kardez[0].Id);
                                }
                            }
                        }
                    }
                }
            }


            //crea_xml();



            Folios folio = new Folios();

            using (folio)
            {
                folio.Transferencia = (Convert.ToInt16(txtFolios.Text) + 1);
                folio.savenewTransfer();
            }

            PrinterSettings ps = new PrinterSettings();

            printDocument1.PrintController = new StandardPrintController();
            printDocument1.PrinterSettings = ps;
            Configuration configuracion = new Configuration();

            using (configuracion)
            {
                List <Configuration> config = configuracion.getConfiguration();
                printDocument1.PrinterSettings.PrinterName = config[0].Impresora;
                printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
                printDocument1.Print();
            }
            this.Close();
        }
Example #2
0
        private void carga_xml(string archivo)
        {
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(archivo);
            XmlNodeList transferencia = xDoc.GetElementsByTagName("transferencia");

            string nfolio   = "";
            string fecha    = "";
            string emisor   = "";
            string receptor = "";
            double monto    = 0;

            string nCantidad   = "";
            string codigo1     = "";
            string codigo2     = "";
            string codigo3     = "";
            string codigo4     = "";
            string codigo5     = "";
            string descripcion = "";
            double pu          = 0;

            foreach (XmlElement nodo in transferencia)
            {
                nfolio   = nodo.GetElementsByTagName("Folio")[0].InnerText;
                fecha    = nodo.GetElementsByTagName("Fecha")[0].InnerText;
                emisor   = nodo.GetElementsByTagName("Emisor")[0].InnerText;
                receptor = nodo.GetElementsByTagName("Receptor")[0].InnerText;
                monto    = Convert.ToDouble(nodo.GetElementsByTagName("Monto")[0].InnerText);
            }
            XmlNodeList productos = ((XmlElement)transferencia[0]).GetElementsByTagName("Productos");
            XmlNodeList producto  = ((XmlElement)productos[0]).GetElementsByTagName("Producto");

            foreach (XmlElement any in producto)
            {
                nCantidad   = any.GetElementsByTagName("Cantidad")[0].InnerText;
                codigo1     = any.GetElementsByTagName("Codigo1")[0].InnerText;
                codigo2     = any.GetElementsByTagName("Codigo2")[0].InnerText;
                codigo3     = any.GetElementsByTagName("Codigo3")[0].InnerText;
                codigo4     = any.GetElementsByTagName("Codigo4")[0].InnerText;
                codigo5     = any.GetElementsByTagName("Codigo5")[0].InnerText;
                descripcion = any.GetElementsByTagName("Descripcion")[0].InnerText;
                pu          = Convert.ToDouble(any.GetElementsByTagName("Pu")[0].InnerText);
            }



            Transfers transferencias = new Transfers();

            using (transferencias)
            {
                transferencias.Fecha        = DateTime.ParseExact(fecha, "yyyy-MM-dd HH:mm:ss", null);
                transferencias.Folio        = Convert.ToInt16(nfolio);
                transferencias.Tipo_trapaso = "R";
                Offices oficinas = new Offices();
                using (oficinas)
                {
                    List <Offices> oficina = oficinas.GetOfficesbyrfc(emisor);
                    transferencias.Sucursal = oficina[0].Id.ToString();
                }

                transferencias.Subtotal  = (monto / 1.16);
                transferencias.Iva       = (monto / 1.16) * 0.16;
                transferencias.Total     = monto;
                transferencias.Facturado = Convert.ToInt16(false);
                transferencias.CreateTransfer();
                List <Transfers> ultimo   = transferencias.getTransferbyfolio(Convert.ToInt16(nfolio), "R");
                Det_transfers    detalles = new Det_transfers();

                using (detalles)
                {
                    detalles.Folio = Convert.ToInt16(ultimo[0].Id);
                    detalles.Tipo  = "R";
                    double  antes = 0;
                    Product prod  = new Product();
                    foreach (XmlElement any in producto)
                    {
                        using (prod)
                        {
                            nCantidad   = any.GetElementsByTagName("Cantidad")[0].InnerText;
                            codigo1     = any.GetElementsByTagName("Codigo1")[0].InnerText;
                            codigo2     = any.GetElementsByTagName("Codigo2")[0].InnerText;
                            codigo3     = any.GetElementsByTagName("Codigo3")[0].InnerText;
                            codigo4     = any.GetElementsByTagName("Codigo4")[0].InnerText;
                            codigo5     = any.GetElementsByTagName("Codigo5")[0].InnerText;
                            descripcion = any.GetElementsByTagName("Descripcion")[0].InnerText;
                            pu          = Convert.ToDouble(any.GetElementsByTagName("Pu")[0].InnerText);


                            detalles.Cantidad = Convert.ToInt16(any.GetElementsByTagName("Cantidad")[0].InnerText);

                            string codigo   = "";
                            int    numerico = 1;

                            int id_produto = 0;
                            while (id_produto == 0 || numerico < 6)
                            {
                                codigo = any.GetElementsByTagName("Codigo" + numerico)[0].InnerText;;

                                List <Product> list_producto = prod.getProductByCodeAbsolute(codigo);
                                if (list_producto.Count > 0)
                                {
                                    id_produto = list_producto[0].Id;
                                    antes      = list_producto[0].Existencia;
                                }
                                else
                                {
                                    numerico = numerico + 1;
                                }
                            }
                            if (id_produto == 0)
                            {
                                DialogResult resultado = MessageBox.Show("El producto " + descripcion + ", no se encuentra en la base de datos ¿Desea agregarlo?", "Producto", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                                if (resultado == DialogResult.Yes)
                                {
                                    prod.Code1       = codigo1;
                                    prod.Code2       = codigo2;
                                    prod.Code3       = codigo3;
                                    prod.Code4       = codigo4;
                                    prod.Code5       = codigo5;
                                    prod.Description = descripcion;
                                    prod.Parent      = "0";
                                    prod.Price1      = pu;
                                    prod.createProduct();

                                    List <Product> list_producto = prod.getProductByCodeAbsolute(codigo1);
                                    id_produto = list_producto[0].Id;
                                    antes      = 0;
                                }
                            }

                            detalles.Id_producto = id_produto;
                            detalles.Precio      = pu;
                            detalles.CreateDet();

                            Kardex kardex = new Kardex();
                            using (kardex)
                            {
                                kardex.Id_producto  = id_produto;
                                kardex.Tipo         = "I";
                                kardex.Id_documento = ultimo[0].Id;
                                kardex.Cantidad     = Convert.ToDouble(nCantidad);
                                kardex.Antes        = antes;
                                kardex.CreateKardex();
                                List <Kardex> ultimo_kardez = kardex.getidKardex(id_produto, ultimo[0].Id, "I");



                                Afecta_inv afecta = new Afecta_inv();
                                using (afecta)
                                {
                                    afecta.Agrega(ultimo_kardez[0].Id);
                                }
                            }
                        }
                    }
                }
            }
        }