public static void AddBook(int catId, string Title, string Genre, string Author, string Publication, int PagesCount, int Year, EnumFileFormat fileFormat, List<string> Tags) { Book book = new Book(); book.parentId = catId; book.Title = Title; book.Author = Author; book.parentId = catId; book.Publication = Publication; book.PagesCount = PagesCount; book.Year = Year; book.FileFormat = fileFormat; book.Genre = Genre; book.Tags = Tags; Catalog catalog = new Catalog(); catalog.Books.InsertOnSubmit(book); catalog.SubmitChanges(); int bookId = book.Id; foreach (string tag in book.Tags) { BookTag bookTag = new BookTag(); bookTag.Name = tag; bookTag.Book_Id = bookId; catalog.Tags.InsertOnSubmit(bookTag); } catalog.SubmitChanges(); }
private EnumAccountType GetAccountType(string type, EnumFileFormat enumFileFormat) { EnumAccountType result; switch (enumFileFormat) { case EnumFileFormat.Standard: result = (EnumAccountType)int.Parse(type); break; case EnumFileFormat.Custom: Enum.TryParse(type, out result); break; default: throw new ArgumentOutOfRangeException(nameof(enumFileFormat), enumFileFormat, null); } return(result); }
/// <summary> /// Crea un documento dependiendo del fileformat que se requiera /// </summary> /// <param name="enumFileFormat">enumerdo con el formato para crear el documento</param> /// <history> /// [emoguel] 02/09/2016 created /// </history> private void CreateFile(EnumFileFormat enumFileFormat) { Workbook wb = null; Microsoft.Office.Interop.Excel.Application excel = null; string defaultPrinter = ""; bool blnChagePrinter = false; try { if (_excelFile.Exists) { #region Printer defaultPrinter = PrinterHelper.GetDefaultPrinter(); if (!string.IsNullOrWhiteSpace(defaultPrinter) && defaultPrinter.Contains("pdf", StringComparison.OrdinalIgnoreCase)) //Ver si hay impresora predeterminada y que no sea pdf { var lstPrinters = PrinterHelper.getAllPrinters().Where(printer => !printer.Contains("pdf", StringComparison.OrdinalIgnoreCase)).ToList(); //Obtener la lista de impresoras que no sean pdf //Verificar si hay una impresora xps string xpsPrinter = lstPrinters.FirstOrDefault(printer => printer.Contains("xps", StringComparison.OrdinalIgnoreCase)); //Buscar impresora XPS if (!string.IsNullOrWhiteSpace(xpsPrinter)) //Verficar si existe una impresora XPS { PrinterHelper.SetDefaultPrinter(xpsPrinter); //Predefinir la impresora XPS blnChagePrinter = true; } else { PrinterHelper.SetDefaultPrinter(lstPrinters[0]);//Predefinir la primera impresora blnChagePrinter = true; } } #endregion //Obtenemos la orientacion seleccionada XlPageOrientation pageOrientation = (XlPageOrientation)cmbOrientation.SelectedValue; //Obtenemos el tamaño de papel seleccionado XlPaperSize paperSize = (XlPaperSize)cmbPageSize.SelectedValue; //Obtenemos el margen seleccionado Margin margin = cmbMargin.SelectedValue as Margin; //Obtenemos la escala seleccionada EnumScale enumScale = (EnumScale)cmbScale.SelectedValue; excel = new Microsoft.Office.Interop.Excel.Application(); excel.Visible = false; excel.ScreenUpdating = false; excel.DisplayAlerts = false; wb = excel.Workbooks.Open(_excelFile.FullName, 0, false, Missing.Value, Missing.Value, Missing.Value, true, XlPlatform.xlWindows, Missing.Value, false, false, Missing.Value, false, true, false);//Cargamos el excel _Worksheet ws = ((_Worksheet)wb.ActiveSheet); #region Page Configuration ws.PageSetup.PaperSize = paperSize; //asignamos el tamaño de hoja ws.PageSetup.Orientation = pageOrientation; //asignamos orientación de la pagina ws.PageSetup.LeftMargin = excel.CentimetersToPoints(margin.left); //asignamos Margen Izquierdo ws.PageSetup.RightMargin = excel.CentimetersToPoints(margin.right); //asignamos Margen Derecho ws.PageSetup.TopMargin = excel.CentimetersToPoints(margin.top); //asignamos Margen de arriba ws.PageSetup.BottomMargin = excel.CentimetersToPoints(margin.bottom); //asignamos Margen de abajo ws.PageSetup.Zoom = false; #endregion #region Scale //Asignamos la escala seleccionada switch (enumScale) { case EnumScale.Noscaling: { ws.PageSetup.FitToPagesTall = false; ws.PageSetup.FitToPagesWide = false; break; } case EnumScale.FitSheetOnOnePage: { ws.PageSetup.FitToPagesTall = 1; ws.PageSetup.FitToPagesWide = 1; break; } case EnumScale.FitAllColumnsOnOnePage: { ws.PageSetup.FitToPagesWide = 1; ws.PageSetup.FitToPagesTall = false; break; } case EnumScale.FitAllRowsOnOnePage: { ws.PageSetup.FitToPagesTall = 1; ws.PageSetup.FitToPagesWide = false; break; } } #endregion ws.PageSetup.Order = XlOrder.xlOverThenDown;//Poner el orden de la paginas #region Export switch (enumFileFormat) { case EnumFileFormat.Pdf: { SaveFileDialog dialog = new SaveFileDialog();//Cargamos el saveFileDialog dialog.FileName = Uid; dialog.Filter = "PDF files(*.pdf) | *.pdf;"; if (dialog.ShowDialog() == true) { wb.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, dialog.FileName, XlFixedFormatQuality.xlQualityStandard, false, true, Missing.Value, Missing.Value, false, Missing.Value);//Guardamos como PDF if (File.Exists(dialog.FileName)) { UIHelper.ShowMessage("Document sufesfully saved."); Process.Start(dialog.FileName); } else { UIHelper.ShowMessage("Document not saved."); } } break; } case EnumFileFormat.Xps: { wb.ExportAsFixedFormat(XlFixedFormatType.xlTypeXPS, $"{_fullPathAndName}.xps", XlFixedFormatQuality.xlQualityStandard, false, true, Missing.Value, Missing.Value, false, Missing.Value);//Guardamos como XPS break; } } #endregion } } catch (Exception ex) { UIHelper.ShowMessage(ex); } finally { if (wb != null) { wb.Close(); } if (excel != null) { excel.Quit(); } if (blnChagePrinter) { PrinterHelper.SetDefaultPrinter(defaultPrinter); } } }
public static void UpdateBook(int bookId, int catId, string Title, string Genre, string Author, string Publication, int PagesCount, int Year, EnumFileFormat fileFormat, List<string> Tags) { Catalog catalog = new Catalog(); var q = from ord in catalog.Books where ord.Id == bookId select ord; Book book = q.First(); book.Title = Title; book.Author = Author; book.parentId = catId; book.Publication = Publication; book.PagesCount = PagesCount; book.Year = Year; book.FileFormat = fileFormat; book.Genre = Genre; book.Tags = Tags; var tagQuery = from tag in catalog.Tags where tag.Book_Id == bookId select tag; foreach (BookTag bookTag in tagQuery) { catalog.Tags.DeleteOnSubmit(bookTag); } foreach(string tag in book.Tags) { BookTag bookTag = new BookTag(); bookTag.Name = tag; bookTag.Book_Id = bookId; catalog.Tags.InsertOnSubmit(bookTag); } catalog.SubmitChanges(); }