Пример #1
0
        private void BtnEnHoja_Click(object sender, EventArgs e)
        {
            //generar los vales y despues impromir pero en hoja
            try
            {
                dtVales2.Rows.Clear();
                Cursor = Cursors.WaitCursor;

                if (ds.Tables[0].Rows.Count != 0 & TxtDesde.Text != "")
                {
                    Encrypt objCrypto = new Encrypt(Encrypt.CryptoProvider.Rijndael);
                    objCrypto.Key = AppSettings.Key;
                    objCrypto.IV  = AppSettings.IV;

                    dtDetalle = new DataTable();
                    dtDetalle = new CL_Vales().getdetalleVales(NumComprobrante, Convert.ToInt32(CboTipoComprobante.SelectedValue));



                    string cadena;
                    if (dtDetalle.Rows.Count == 0)
                    {
                        int UltimoNumVale = new CL_Vales().getUltimoVale();

                        foreach (DataRow fila in ds.Tables[1].Rows)
                        {
                            int cant = Convert.ToInt32(fila["Cantidad"]);

                            for (int x = 0; x < cant; x++)
                            {
                                UltimoNumVale++;
                                DataRow row = dtVales2.NewRow();
                                row["ID"]          = x + 1;
                                row["Comprobante"] = NumComprobrante;
                                row["Cliente"]     = lblCliente.Text;
                                row["Codigo"]      = fila["ProductoID"].ToString();
                                row["Producto"]    = fila["NomProducto"].ToString().Remove(fila["NomProducto"].ToString().IndexOf("X"));
                                row["Peso"]        = string.Concat(string.Format("{0:0.##}", fila["Unidades"]), " KG");
                                row["NumVale"]     = UltimoNumVale;
                                cadena             = objCrypto.CifrarCadena(UltimoNumVale.ToString());

                                row["CodBar"]    = string.Concat("*", UltimoNumVale.ToString().PadLeft(4, '/'), cadena.Substring(0, 7), "*");
                                row["Numeros"]   = UltimoNumVale.ToString().PadLeft(4, '0');
                                row["Direccion"] = direccion;
                                row["Foto"]      = ImageToByteArray((Image)Halley.Presentacion.Properties.Resources.ResourceManager.GetObject(fila["Imagen"].ToString() + "2"));
                                dtVales2.Rows.Add(row);
                            }
                        }

                        new CL_Vales().Insert(AppSettings.UserID, lblSedeID.Text, dtVales2, Convert.ToInt32(CboTipoComprobante.SelectedValue));
                    }
                    else
                    {
                        int X = 1;
                        foreach (DataRow fila in dtDetalle.Rows)
                        {
                            DataRow row = dtVales2.NewRow();
                            row["ID"]          = X;
                            row["Comprobante"] = NumComprobrante;
                            row["Cliente"]     = fila["RazonSocial"].ToString();
                            row["Producto"]    = fila["NomProducto"].ToString().Remove(fila["NomProducto"].ToString().IndexOf("X"));
                            row["Peso"]        = string.Concat(string.Format("{0:0.##}", fila["Unidades"]), " KG");
                            row["NumVale"]     = fila["NumVale"];
                            cadena             = objCrypto.CifrarCadena(fila["NumVale"].ToString());

                            row["CodBar"]    = string.Concat("*", fila["NumVale"].ToString().PadLeft(4, '/'), cadena.Substring(0, 7), "*");
                            row["Numeros"]   = fila["NumVale"].ToString().PadLeft(4, '0');
                            row["Direccion"] = direccion;
                            row["Foto"]      = ImageToByteArray((Image)Halley.Presentacion.Properties.Resources.ResourceManager.GetObject(fila["Imagen"].ToString() + "2"));
                            dtVales2.Rows.Add(row);
                            ++X;
                        }
                    }

                    printDialog1.ShowDialog();
                    if (printDialog1.PrinterSettings.PrinterName != "")
                    {
                        Pd.Print();
                    }
                }
                else
                {
                    Cursor = Cursors.Default;
                    MessageBox.Show("No existen vales o no se ha ingresado el inicio del vale", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;
                MessageBox.Show(ex.Message, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }