private void insertarCodigosDeBarraAPlantillaWord(Word.Document docPRUEBA, int i) { List<Word.Shape> lst = new List<Word.Shape>(); foreach (Word.Shape sh in docPRUEBA.Shapes) { while (sh.Name.Contains("\n")) sh.Name = sh.Name.Replace("\n", ""); if (sh.Type.ToString() == "msoPicture") lst.Add(sh); } List<Word.Range> ranges = new List<Microsoft.Office.Interop.Word.Range>(); float left, top, h, w; bool insertado = false; string tempname = ""; List<Word.Shape> removedShapes = new List<Word.Shape>(); try { foreach (string bcd in lista_camposCodBarr) { insertado = false; ranges.Clear(); foreach (Word.Shape sh in lst) { if (sh.Name == bcd) { left = sh.Left; top = sh.Top; h = sh.Height; w = sh.Width; sh.ConvertToInlineShape(); foreach (Word.InlineShape s in docPRUEBA.InlineShapes) { if (s.Type == Word.WdInlineShapeType.wdInlineShapePicture) { tempname = sh.Name; ranges.Add(s.Range); s.Delete(); removedShapes.Add(sh); } } foreach (Word.Range r in ranges) { r.InlineShapes.AddPicture(@rutasEnModAdmin.RutaDeTemp + "/" + i + bcd + ".jpg", Type.Missing, Type.Missing, Type.Missing); insertado = true; } Word.Shape pic; foreach (Word.InlineShape s in docPRUEBA.InlineShapes) { if (s.Type == Word.WdInlineShapeType.wdInlineShapePicture) { pic = s.ConvertToShape(); pic.Name = tempname; pic.Top = top; pic.Left = left; pic.Height = h; pic.Width = w; } } if (insertado) break; } } foreach (Word.Shape s in removedShapes) lst.Remove(s); } if (dgv_PesosLotes.InvokeRequired) { this.Invoke(new Action(() => dgv_PesosLotes.Rows[i].DefaultCellStyle.BackColor = Color.White)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[i].Cells[1].ReadOnly = false )); this.Invoke(new Action(() => dgv_PesosLotes.Rows[i].Cells[2].ReadOnly = false)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[i].Cells[4].ReadOnly = false)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[i].Cells[5].ReadOnly = false)); } else { dgv_PesosLotes.Rows[i].DefaultCellStyle.BackColor = Color.White; dgv_PesosLotes.Rows[i].Cells[1].ReadOnly = false; dgv_PesosLotes.Rows[i].Cells[2].ReadOnly = false; dgv_PesosLotes.Rows[i].Cells[4].ReadOnly = false; dgv_PesosLotes.Rows[i].Cells[5].ReadOnly = false; } } catch { if (dgv_PesosLotes.InvokeRequired) { this.Invoke(new Action(() => dgv_PesosLotes.Rows[i].DefaultCellStyle.BackColor = Color.Red)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[i].Cells[3].Value = null)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[i].Cells[1].ReadOnly = false)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[i].Cells[2].ReadOnly = false)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[i].Cells[4].ReadOnly = false)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[i].Cells[5].ReadOnly = false)); } else { dgv_PesosLotes.Rows[i].DefaultCellStyle.BackColor = Color.Red; dgv_PesosLotes.Rows[i].Cells[3].Value = null; dgv_PesosLotes.Rows[i].Cells[1].ReadOnly = false; dgv_PesosLotes.Rows[i].Cells[2].ReadOnly = false; dgv_PesosLotes.Rows[i].Cells[4].ReadOnly = false; dgv_PesosLotes.Rows[i].Cells[5].ReadOnly = false; } } }
private void insertarCodigosDeBarraAPlantillaWord_ParaCopiar(Word.Document docWord) { int i = 0; List<Word.Shape> lst = new List<Word.Shape>(); foreach (Word.Shape sh in docWord.Shapes) { while (sh.Name.Contains("\n")) sh.Name = sh.Name.Replace("\n", ""); if (sh.Type.ToString() == "msoPicture") lst.Add(sh); } List<Word.Range> ranges = new List<Microsoft.Office.Interop.Word.Range>(); float left, top, h, w; bool insertado = false; string tempname = ""; List<Word.Shape> removedShapes = new List<Word.Shape>(); try { foreach (string bcd in lista_camposCodBarr) { insertado = false; ranges.Clear(); foreach (Word.Shape sh in lst) { if (sh.Name == bcd) { left = sh.Left; top = sh.Top; h = sh.Height; w = sh.Width; sh.ConvertToInlineShape(); foreach (Word.InlineShape s in docWord.InlineShapes) { if (s.Type == Word.WdInlineShapeType.wdInlineShapePicture) { tempname = sh.Name; ranges.Add(s.Range); s.Delete(); removedShapes.Add(sh); } } foreach (Word.Range r in ranges) { r.InlineShapes.AddPicture(@rutasEnModAdmin.RutaDeTemp + "/" + i + bcd + ".jpg", Type.Missing, Type.Missing, Type.Missing); insertado = true; } Word.Shape pic; foreach (Word.InlineShape s in docWord.InlineShapes) { if (s.Type == Word.WdInlineShapeType.wdInlineShapePicture) { pic = s.ConvertToShape(); pic.Name = tempname; pic.Top = top; pic.Left = left; pic.Height = h; pic.Width = w; } } if (insertado) break; } } foreach (Word.Shape s in removedShapes) lst.Remove(s); } } catch(Exception ex) { MessageBox.Show(ex.Message); } }
private void insertarPrimerosCodigosDeBarra() { string path = @rutasEnModAdmin.RutaDePlantillas + "/temp_EtiquetaActual.docx"; appWord = new Word.Application(); appWord.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone; appWord.Visible = false; bool isOpen = false; FileStream stream = null; try { stream = File.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None); } catch (IOException) { isOpen = true; } finally { if (stream != null) stream.Close(); } if (isOpen) { Process[] proces = Process.GetProcessesByName("WINWORD"); foreach (Process proc in proces) { if (proc.MainWindowTitle == "") proc.Kill(); } MessageBox.Show("Existía un proceso abierto, y se ha cerrado correctamente. Favor de intentar nuevamente.", "Proceso Terminado", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //return -1; } doc = appWord.Documents.Open(path); List<Word.Shape> lst = new List<Word.Shape>(); foreach (Word.Shape sh in doc.Shapes) { if (sh.Type.ToString() == "msoPicture") { while (sh.Name.Contains("\n")) sh.Name = sh.Name.Replace("\n", ""); lst.Add(sh); } } this.generarPrimerosCodigosDeBarra(); List<string> bcdUsados = new List<string>(); foreach (string bcd in lista_camposCodBarr) { foreach (Control txt in gb_CamposAdicionales.Controls.OfType<TextBox>()) { if (!txt.Name.Contains(bcd.Replace("bcd", ""))) continue; try { bcdUsados.Add(bcd); float left, top, h, w; string tempname = ""; List<Word.Range> ranges = new List<Word.Range>(); Word.Shape removed = null; foreach (Word.Shape sh in lst) { if (sh.Name == bcd) { left = sh.Left; top = sh.Top; h = sh.Height; w = sh.Width; sh.ConvertToInlineShape(); foreach (Word.InlineShape s in doc.InlineShapes) { if (s.Type == Word.WdInlineShapeType.wdInlineShapePicture) { tempname = sh.Name; ranges.Add(s.Range); s.Delete(); removed = sh; } } foreach (Word.Range r in ranges) { r.InlineShapes.AddPicture(@rutasEnModAdmin.RutaDeTemp + "/" + bcd + ".jpg", Type.Missing, Type.Missing, Type.Missing); } Word.Shape pic; foreach (Word.InlineShape s in doc.InlineShapes) { if (s.Type == Word.WdInlineShapeType.wdInlineShapePicture) { pic = s.ConvertToShape(); pic.Name = tempname; pic.Top = top; pic.Left = left; pic.Height = h; pic.Width = w; } } } } lst.Remove(removed); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } doc.Save(); doc.Saved = true; ((Microsoft.Office.Interop.Word._Document)doc).Close(); foreach (string str in bcdUsados) lista_camposCodBarr.Remove(str); }
private void GenderManReportItem(List<ReportItemModel> rimList, Hashtable manItemTable) { foreach (ReportItemModel rim in rimList) { switch (rim.ItemNo) { case 90009288: manItemTable.Add("Item9288", rim.ItemResult); rimList.Remove(rim); break; case 90009289: manItemTable.Add("Item9289", rim.ItemResult); rimList.Remove(rim); break; case 90009290: manItemTable.Add("Item9290", rim.ItemResult); break; case 90009291: manItemTable.Add("Item9291", rim.ItemResult); rimList.Remove(rim); break; case 90009292: manItemTable.Add("Item9292", rim.ItemResult); rimList.Remove(rim); break; case 90009293: manItemTable.Add("Item9293", rim.ItemResult); rimList.Remove(rim); break; case 90009294: manItemTable.Add("Item9294", rim.ItemResult); rimList.Remove(rim); break; case 90009300: manItemTable.Add("Item9300", rim.ItemResult); rimList.Remove(rim); break; case 90009295: manItemTable.Add("Item9295", rim.ItemResult); rimList.Remove(rim); break; case 90009296: manItemTable.Add("Item9296", rim.ItemResult); rimList.Remove(rim); break; case 90009297: manItemTable.Add("Item9297", rim.ItemResult); rimList.Remove(rim); break; case 90009301: manItemTable.Add("Item9301", rim.ItemResult); rimList.Remove(rim); break; } } }
private void BuildPDF(Dictionary<string, ISPage> pageMap, string baseRoom, Dictionary<string, int> chapterPageMap, bool fakeRun) { if (fakeRun) { ISPageHtmlParser.BuildAllISPages(pageMap, baseRoom, filePath).Wait(); } //now that we have all the pages, we'll have to clean them up and decide on pages Dictionary<string, int> ISPageToPhysicalPageMap = new Dictionary<string, int>(); int currentPage = 1; int currentChapter = 1; Random r = new Random(123456); List<string> pagesLeft = new List<string>(pageMap.Count); foreach (string x in pageMap.Keys) { pagesLeft.Add(x); } using (MemoryStream memStream = new MemoryStream()) { Document pdfDoc = new Document(); iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, memStream); HeaderFooter evnt = new HeaderFooter(); if (fakeRun) { evnt.pageByTitle = chapterPageMap; } else { evnt.pageByTitle = new Dictionary<string, int>(); } if (!fakeRun) { writer.PageEvent = evnt; } pdfDoc.Open(); pdfDoc.AddAuthor("test"); pdfDoc.AddTitle("testTitle"); while (pagesLeft.Any()) { string pageToAdd = pagesLeft.First(); if (currentPage > 1) { pagesLeft.Skip(r.Next(pagesLeft.Count)).First(); } pagesLeft.Remove(pageToAdd); if (fakeRun) { chapterPageMap.Add(pageToAdd, writer.PageNumber + 1); } ISPageToPhysicalPageMap.Add(pageToAdd, currentPage); var chapter = GetPDFPage(pageMap[pageToAdd], int.Parse(pageToAdd), chapterPageMap); pdfDoc.Add(chapter); int actualPageLength = fakeRun ? 1 : chapterPageMap[pageToAdd]; currentPage += actualPageLength; currentChapter++; } pdfDoc.Close(); writer.Close(); if (!fakeRun) { File.WriteAllBytes(Path.Combine(filePath, fileName), memStream.GetBuffer()); } } }
private void insertarPrimerosCodigosDeBarra(bool EtiquetaMultiples) { this.generarPrimerosCodigosDeBarra(true); List<string> bcdUsados = new List<string>(); foreach (Etiqueta_C.Estructura_etqMultiple etqM in ListaEtiquetasMultiples) { string path = @rutasEnModAdmin.RutaDePlantillas + "/temp_EtiquetaActual" + ListaEtiquetasMultiples.IndexOf(etqM) + ".docx"; appWord.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone; appWord.Visible = false; doc = appWord.Documents.Open(path); List<Word.Shape> lst = new List<Word.Shape>(); foreach (Word.Shape sh in doc.Shapes) { if (sh.Type.ToString() == "msoPicture") { while (sh.Name.Contains("\n")) sh.Name = sh.Name.Replace("\n", ""); lst.Add(sh); } } foreach (string bcd in lista_camposCodBarr) { foreach (Control txt in gb_CamposAdicionales.Controls.OfType<TextBox>()) { if (!txt.Name.Contains(bcd.Replace("bcd", ""))) continue; try { bcdUsados.Add(bcd); float left, top, h, w; string tempname = ""; List<Word.Range> ranges = new List<Word.Range>(); Word.Shape removed = null; foreach (Word.Shape sh in lst) { if (sh.Name == bcd) { left = sh.Left; top = sh.Top; h = sh.Height; w = sh.Width; sh.ConvertToInlineShape(); foreach (Word.InlineShape s in doc.InlineShapes) { if (s.Type == Word.WdInlineShapeType.wdInlineShapePicture) { tempname = sh.Name; ranges.Add(s.Range); s.Delete(); removed = sh; } } foreach (Word.Range r in ranges) { if (File.Exists(@rutasEnModAdmin.RutaDeTemp + "/" + bcd + ".jpg")) r.InlineShapes.AddPicture(@rutasEnModAdmin.RutaDeTemp + "/" + bcd + ".jpg", Type.Missing, Type.Missing, Type.Missing); } ranges.Clear(); Word.Shape pic; foreach (Word.InlineShape s in doc.InlineShapes) { if (s.Type == Word.WdInlineShapeType.wdInlineShapePicture) { pic = s.ConvertToShape(); pic.Name = tempname; pic.Top = top; pic.Left = left; pic.Height = h; pic.Width = w; } } } } lst.Remove(removed); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n\n" + ex.ToString()); } } } doc.Save(); doc.Saved = true; ((Microsoft.Office.Interop.Word._Document)doc).Close(); } foreach (string str in bcdUsados) lista_camposCodBarr.Remove(str); }
private void insertarCodigosDeBarraAWordMasDeUnaEtq(Word.Document doc, int indice ,int etqActual, bool nuevaHoja) { bool continuar = false; while (!continuar) { if (indice == 0) continuar = true; else { if (dgv_PesosLotes.Rows[indice - 1].DefaultCellStyle.BackColor == Color.Orange && (indice % 2 != 0 || indice == 1)) continuar = false; else continuar = true; } } List<Word.Shape> lst = new List<Word.Shape>(); foreach (Word.Shape sh in doc.Shapes) { while (sh.Name.Contains("\n")) sh.Name = sh.Name.Replace("\n", ""); if (sh.Type.ToString() == "msoPicture") lst.Add(sh); } List<Word.Range> ranges = new List<Microsoft.Office.Interop.Word.Range>(); float left, top, h, w; bool insertado = false; string tempname = ""; List<Word.Shape> removedShapes = new List<Word.Shape>(); try { foreach (string bcd in lista_camposCodBarr) { insertado = false; ranges.Clear(); foreach (Word.Shape sh in lst) { if (sh.Name == bcd + etqActual) { left = sh.Left; top = sh.Top; h = sh.Height; w = sh.Width; sh.ConvertToInlineShape(); foreach (Word.InlineShape s in doc.InlineShapes) { if (s.Type == Word.WdInlineShapeType.wdInlineShapePicture) { tempname = sh.Name; ranges.Add(s.Range); s.Delete(); removedShapes.Add(sh); } } foreach (Word.Range r in ranges) { r.InlineShapes.AddPicture(@rutasEnModAdmin.RutaDeTemp + "/" + indice + bcd + ".jpg", Type.Missing, Type.Missing, Type.Missing); insertado = true; } Word.Shape pic; ranges.Clear(); foreach (Word.InlineShape s in doc.InlineShapes) { if (s.Type == Word.WdInlineShapeType.wdInlineShapePicture) { pic = s.ConvertToShape(); pic.Name = tempname; pic.Top = top; pic.Left = left; pic.Height = h; pic.Width = w; } } if (insertado) break; } } foreach (Word.Shape s in removedShapes) lst.Remove(s); } if (dgv_PesosLotes.InvokeRequired) { this.Invoke(new Action(() => dgv_PesosLotes.Rows[indice].DefaultCellStyle.BackColor = Color.White)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[indice].Cells[1].ReadOnly = false)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[indice].Cells[2].ReadOnly = false)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[indice].Cells[4].ReadOnly = false)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[indice].Cells[5].ReadOnly = false)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[indice].Cells[6].ReadOnly = false)); } else { dgv_PesosLotes.Rows[indice].DefaultCellStyle.BackColor = Color.White; dgv_PesosLotes.Rows[indice].Cells[1].ReadOnly = false; dgv_PesosLotes.Rows[indice].Cells[2].ReadOnly = false; dgv_PesosLotes.Rows[indice].Cells[4].ReadOnly = false; dgv_PesosLotes.Rows[indice].Cells[5].ReadOnly = false; dgv_PesosLotes.Rows[indice].Cells[6].ReadOnly = false; } } catch { this.Invoke(new Action(() => dgv_PesosLotes.Rows[indice].DefaultCellStyle.BackColor = Color.Red)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[indice].Cells[1].ReadOnly = false)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[indice].Cells[2].ReadOnly = false)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[indice].Cells[4].ReadOnly = false)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[indice].Cells[5].ReadOnly = false)); this.Invoke(new Action(() => dgv_PesosLotes.Rows[indice].Cells[6].ReadOnly = false)); foreach (DataGridViewCell cell in dgv_PesosLotes.Rows[indice].Cells) { this.Invoke(new Action(() => cell.Value = null)); } return; } }
/// <summary> /// Adds conflicts to the database depending upon the current state of the election. /// </summary> /// <param name="session">A valid session.</param> public virtual void ConflictLogic(ISession session) { List<ElectionConflict> conflicts = ElectionConflict.FindElectionConflicts(session, ID); foreach (ElectionConflict conflict in conflicts) NHibernateHelper.Delete(session, conflict); ITransaction transaction = session.BeginTransaction(); // Get the current committee Committee committee = Committee.FindCommittee(session, PertinentCommittee); // Get the users who won the election. Dictionary<string, int> winners = GetResults(session); List<User> winningUsers = new List<User>(); foreach (string email in winners.Keys) { winningUsers.Add(User.FindUser(session, email)); } // Get the users on the committee. List<User> members = User.FindUsers(session, committee.Name); // List all of the departments currently present on the committee. // and use a parallel list to store the ID of the other department // member so we can add it to the conflict later. List<DepartmentType> departments = new List<DepartmentType>(); List<int> secID = new List<int>(); foreach (User i in members) { departments.Add(i.Department); secID.Add(i.ID); } //List departments of nominees List<DepartmentType> departmentsWinning = new List<DepartmentType>(); List<int> secIDWinning = new List<int>(); foreach (User i in winningUsers) { departmentsWinning.Add(i.Department); secIDWinning.Add(i.ID); } // For each user who won, add a new conflict if their department // is already present on the list. Adding, departments as we go. // Also raise conflicts if the winning users hold officer positions, // or if they already serve on a committee. foreach (User i in winningUsers) { // check if they have a prior committment if (i.OfficerPosition != OfficerPositionType.None || i.CurrentCommittee != User.NoCommittee) { ElectionConflict conflict = new ElectionConflict(); conflict.Election = ID; conflict.FirstUser = i.ID; conflict.SecUser = ElectionConflict.SecondUserNotApplicable; conflict.Type = ConflictType.ElectedToMultipleCommittees; session.SaveOrUpdate(conflict); } // check for department-based conflicts if (departments.Contains(i.Department)) { ElectionConflict conflict = new ElectionConflict(); conflict.Election = ID; conflict.FirstUser = i.ID; conflict.SecUser = secID[departments.IndexOf(i.Department)]; conflict.Type = ConflictType.TooManyDeptMembers; session.SaveOrUpdate(conflict); } // check for department-based conflicts - nominees if (departmentsWinning.Contains(i.Department) && i.ID != secIDWinning[departmentsWinning.IndexOf(i.Department)]) { ElectionConflict conflict = new ElectionConflict(); conflict.Election = ID; conflict.FirstUser = i.ID; conflict.SecUser = secIDWinning[departmentsWinning.IndexOf(i.Department)]; secIDWinning.Remove(conflict.SecUser); departmentsWinning.Remove(i.Department); conflict.Type = ConflictType.TooManyDeptMembers; session.SaveOrUpdate(conflict); } } session.Flush(); NHibernateHelper.Finished(transaction); }
public static bool Merge(List<PDFFiles> InFiles, string OutFile) { try { for(int i=0; i<InFiles.Count; i++) { PdfReader reader = null; reader = new PdfReader(InFiles[i].filePath); if (!reader.IsOpenedWithFullPermissions) { string newUnlockedFile = unlockPDF(InFiles[i].filePath); //throw new System.IO.FileLoadException("Cannot merge because \"" + file.fileName + "\" is Locked for editing"); InFiles.Remove(InFiles[i]); InFiles.Insert(i, new PDFFiles(newUnlockedFile)); } } } catch (FileNotFoundException ex) { throw ex; } catch (System.IO.FileLoadException) { throw; } catch { return false; } try { using (FileStream stream = new FileStream(OutFile, FileMode.Create)) using (Document doc = new Document(PageSize.A4)) using (PdfCopy pdf = new PdfCopy(doc, stream)) { doc.Open(); PdfReader reader = null; PdfImportedPage page = null; //fixed typo InFiles.ForEach(file => { reader = new PdfReader(file.filePath); for (int i = 0; i < reader.NumberOfPages; i++) { page = pdf.GetImportedPage(reader, i + 1); //doc.SetPageSize(page.Width <= page.Height ? PageSize.A4 : PageSize.A4.Rotate()); pdf.AddPage(page); } pdf.FreeReader(reader); reader.Close(); }); } } catch { return false; } ScaleToA4(OutFile, OutFile); return true; }
protected void UpdateExplanationValidationField() { HealthStatements collection = (HealthStatements)(Session["HealthStatements"]); List<String> QuestionsToAnswer = new List<String>(); foreach (System.Web.UI.WebControls.ListItem li in cmbQuestion.Items) { if (!QuestionsToAnswer.Contains(li.Value)) { QuestionsToAnswer.Add(li.Value); } } foreach (HealthStatement hs in collection.MyHealthStatements) { if (QuestionsToAnswer.Contains(hs.QuestionNum)) { QuestionsToAnswer.Remove(hs.QuestionNum); } } //Update field used for validation. NumExplanationsRequired.Value = QuestionsToAnswer.Count.ToString(); }