Example #1
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            #region validaciones
            if (txtRazon.Text.Equals(""))
            {
                XtraMessageBox.Show("Por favor, ingrese Razon Social", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                empresaPago.RazonSocial = txtRazon.Text;
            }

            if (txtRFC.Text.Equals(""))
            {
                XtraMessageBox.Show("Por favor, ingrese RFC", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                empresaPago.RFC = txtRFC.Text;
            }
            if (txtLogo.Text.Equals(""))
            {
                mensaje = "Por favor, cargue un archivo.";
                XtraMessageBox.Show(mensaje, "Cargar Archivo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            #endregion
            empresaPago.IDEmpresa = txtID.Text;

            if (controlador.InsertaEmpresaPago(empresaPago).Equals(true))
            {
                NombreArchivo = txtLogo.Text;

                byte[] file = null;
                //Stream stream = openFileDialog1.OpenFile();
                Stream stream = OpenFile(Archivo);
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    stream.CopyTo(memoryStream);
                    file = memoryStream.ToArray();
                }
                using (Models.AsimiladosEntitiesLogos lg = new Models.AsimiladosEntitiesLogos())
                {
                    Models.LogosEmpresas logo = new Models.LogosEmpresas();
                    logo.logoNombre = nombreArchivoOriginal;
                    string path         = AppDomain.CurrentDomain.BaseDirectory;
                    string folder       = path + "/Logos/";
                    string fullFilePath = folder + Archivo;
                    logo.logoPath                = nombreArchivoOriginal;
                    logo.logoArchivo             = file;
                    logo.logoFechaCarga          = DateTime.Now;
                    logo.logousuarioArchivoCarga = usuarioSistema;
                    logo.logoIDEmpresa           = txtID.Text;
                    logo.logoEmpresa             = txtRazon.Text;
                    lg.LogosEmpresas.Add(logo);
                    lg.SaveChanges();
                }
                this.LlenaTabla();
                this.GetNextID();
                txtRazon.Text = "";
                txtRFC.Text   = "";
            }
            else
            {
                XtraMessageBox.Show("Error al dar de alta Empresa.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
 private void btnActualizaLogo_Click(object sender, EventArgs e)
 {
     try
     {
         byte[] file = null;
         if (txtLogo.Text.Equals(""))
         {
             mensaje = "Por favor, cargue un archivo.";
             XtraMessageBox.Show(mensaje, "Cargar Archivo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         else
         {
             //Stream stream = openFileDialog1.OpenFile();
             Stream stream = OpenFile(Archivo);
             using (MemoryStream memoryStream = new MemoryStream())
             {
                 stream.CopyTo(memoryStream);
                 file = memoryStream.ToArray();
             }
         }
         for (int i = 0; i < gridViewEmpr.RowCount; i++)
         {
             if (gridViewEmpr.IsRowSelected(i))
             {
                 IDE     = Convert.ToInt32(gridViewEmpr.GetRowCellValue(i, gridViewEmpr.Columns[0]).ToString());
                 IDEmp   = gridViewEmpr.GetRowCellValue(i, gridViewEmpr.Columns[1]).ToString();
                 RFC     = gridViewEmpr.GetRowCellValue(i, gridViewEmpr.Columns[2]).ToString();
                 RS      = gridViewEmpr.GetRowCellValue(i, gridViewEmpr.Columns[3]).ToString();
                 Estatus = gridViewEmpr.GetRowCellValue(i, gridViewEmpr.Columns[4]).ToString();
             }
         }
         using (Models.AsimiladosEntitiesLogos lg = new Models.AsimiladosEntitiesLogos())
         {
             var logo = lg.LogosEmpresas.SingleOrDefault(b => b.logoIDEmpresa == IDEmp);
             if (logo != null)
             {
                 string path     = AppDomain.CurrentDomain.BaseDirectory;
                 string folder   = path + @"Logos\";
                 string fullPath = folder + logo.logoPath;
                 if (File.Exists(fullPath))
                 {
                     File.Delete(fullPath);
                 }
                 logo.logoArchivo = file;
                 lg.SaveChanges();
             }
             else
             {
                 Models.LogosEmpresas logoNuevo = new Models.LogosEmpresas();
                 logoNuevo.logoNombre = nombreArchivoOriginal;
                 string path         = AppDomain.CurrentDomain.BaseDirectory;
                 string folder       = path + "/Logos/";
                 string fullFilePath = folder + Archivo;
                 logoNuevo.logoPath                = nombreArchivoOriginal;
                 logoNuevo.logoArchivo             = file;
                 logoNuevo.logoFechaCarga          = DateTime.Now;
                 logoNuevo.logousuarioArchivoCarga = usuarioSistema;
                 logoNuevo.logoIDEmpresa           = IDEmp;
                 logoNuevo.logoEmpresa             = RS;
                 lg.LogosEmpresas.Add(logoNuevo);
                 lg.SaveChanges();
             }
         }
         mensaje = "¡Logo Actualizado con éxito!";
         XtraMessageBox.Show(mensaje, "Actualizar Logo", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }catch (Exception btnActLogo)
     {
         mensaje = string.Concat("Error al intentar actualizar logo:", "\n", btnActLogo.Message);
         XtraMessageBox.Show(mensaje, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }