void BuildContract() { List <string> types = new List <string>(); foreach (var item in addedProducts) { var type = MainForm.DB.Types.Get(item.TypeId).Name; if (!types.Contains(type)) { types.Add(type); } } DialogResult dialogResult = MessageBox.Show("Все запущенные документы будут закрыты без сохранения! Сохраните используемые в данный момент документы и нажмите 'Ок'", "ВНИМАНИЕ!!!", MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.OK) { lLoad.Visible = true; WordWorker.Load(); ReplaceStrings(); Word.Range range = WordWorker.doc.Paragraphs[WordWorker.doc.Paragraphs.Count].Range; int i = 1; List <int> mergesRows = new List <int>(); foreach (string item in types) { WordWorker.doc.Tables[4].Rows.Add(); i++; mergesRows.Add(i); WordWorker.doc.Tables[4].Rows[i].Range.Bold = 0; WordWorker.doc.Tables[4].Rows[i].Height = float.Parse("0,3"); WordWorker.doc.Tables[4].Rows[i].Cells[1].Range.Text = item; foreach (ProductArrival product in addedProducts.Where(x => MainForm.DB.Types.Get(x.TypeId).Name == item)) { WordWorker.doc.Tables[4].Rows.Add(); i++; WordWorker.doc.Tables[4].Cell(i, 1).Range.Text = product.Name; WordWorker.doc.Tables[4].Cell(i, 2).Range.Text = MainForm.DB.Units.Get(product.UnitId).Name; WordWorker.doc.Tables[4].Cell(i, 3).Range.Text = Math.Round(product.Price, 2).ToString(); WordWorker.doc.Tables[4].Cell(i, 4).Range.Text = "-"; WordWorker.doc.Tables[4].Cell(i, 5).Range.Text = Math.Round(product.Balance, 2).ToString(); WordWorker.doc.Tables[4].Cell(i, 6).Range.Text = product.getSumRound().ToString(); WordWorker.doc.Tables[4].Cell(i, 7).Range.Text = "0"; } } foreach (var item in mergesRows) { WordWorker.doc.Tables[4].Rows[item].Cells[1].Merge(WordWorker.doc.Tables[4].Rows[item].Cells[7]); } WordWorker.doc.Tables[4].Rows.Add(); i++; WordWorker.doc.Tables[4].Rows[i].Range.Bold = 0; WordWorker.doc.Tables[4].Rows[i].Height = float.Parse("0,3"); WordWorker.doc.Tables[4].Cell(i, 1).Range.Text = "Итого"; WordWorker.doc.Tables[4].Cell(i, 6).Range.Text = Math.Round(float.Parse(lSumm.Text)).ToString(); WordWorker.Save(MainForm.DataPath + "\\Документы\\" + (lBContracts.SelectedItem as ContractDTO).ToString() + "\\" + (lBContracts.SelectedItem as ContractDTO).ToString() + ".docx"); WordWorker.Close(); lLoad.Visible = false; } WordWorker.Close(); }
private void ButBuild_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Все запущенные документы будут закрыты без сохранения! Сохраните используемые в данный момент документы и нажмите 'Ок'", "ВНИМАНИЕ!!!", MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.OK) { lLoad.Visible = true; BuildDocument(); lLoad.Visible = false; } WordWorker.Close(); }
private void BuildDocument() { DialogResult dialogResult = MessageBox.Show("Все запущенные документы будут закрыты без сохранения! Сохраните используемые в данный момент документы и нажмите 'Ок'", "ВНИМАНИЕ!!!", MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.OK) { lLoad.Visible = true; WordWorker.Load(); ReplaceStrings(); Word.Range range = WordWorker.doc.Paragraphs[WordWorker.doc.Paragraphs.Count].Range; int i = 3; foreach (ProductArrival product in addedProducts) { WordWorker.doc.Tables[2].Rows.Add(); i++; WordWorker.doc.Tables[2].Cell(i, 1).Range.Text = (i - 3).ToString(); WordWorker.doc.Tables[2].Cell(i, 2).Range.Text = product.Name; WordWorker.doc.Tables[2].Cell(i, 4).Range.Text = MainForm.DB.Units.Get(product.UnitId).Name; WordWorker.doc.Tables[2].Cell(i, 10).Range.Text = Math.Round(product.Balance, 2).ToString(); WordWorker.doc.Tables[2].Cell(i, 11).Range.Text = Math.Round(product.Price, 2).ToString(); WordWorker.doc.Tables[2].Cell(i, 12).Range.Text = product.getSumRound().ToString(); WordWorker.doc.Tables[2].Cell(i, 13).Range.Text = "БЕЗ НДС"; WordWorker.doc.Tables[2].Cell(i, 15).Range.Text = product.getSumRound().ToString(); } WordWorker.doc.Tables[2].Rows.Add(); i++; WordWorker.doc.Tables[2].Cell(i, 1).Range.Text = "Итого"; WordWorker.doc.Tables[2].Cell(i, 11).Range.Text = "X"; WordWorker.doc.Tables[2].Cell(i, 12).Range.Text = Math.Round(float.Parse(lSumm.Text)).ToString(); WordWorker.doc.Tables[2].Cell(i, 13).Range.Text = "X"; WordWorker.doc.Tables[2].Cell(i, 15).Range.Text = Math.Round(float.Parse(lSumm.Text)).ToString(); WordWorker.Save(MainForm.DataPath + "\\Документы\\" + MainForm.DB.Contracts.Get(MainForm.DB.Invoices.Get((lBDeliveryNotes.SelectedItem as DeliveryNoteDTO).InvoiceId).ContractId).ToString() + "\\" + (lBDeliveryNotes.SelectedItem as DeliveryNoteDTO).ToString() + ".docx"); WordWorker.Close(); lLoad.Visible = false; } WordWorker.Close(); }
private void BuildContract() { DialogResult dialogResult = MessageBox.Show("Все запущенные документы будут закрыты без сохранения! Сохраните используемые в данный момент документы и нажмите 'Ок'", "ВНИМАНИЕ!!!", MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.OK) { lLoad.Visible = true; WordWorker.Load(); ReplaceStrings(); int i = 1; foreach (ProductArrival product in addedProducts) { WordWorker.doc.Tables[1].Rows.Add(); i++; WordWorker.doc.Tables[1].Rows[i].Height = (float)12; WordWorker.doc.Tables[1].Cell(i, 1).Range.Text = product.Name; WordWorker.doc.Tables[1].Cell(i, 2).Range.Text = MainForm.DB.Units.Get(product.UnitId).Name; WordWorker.doc.Tables[1].Cell(i, 3).Range.Text = Math.Round(product.Balance, 2).ToString(); WordWorker.doc.Tables[1].Cell(i, 4).Range.Text = Math.Round(product.Price, 2).ToString(); WordWorker.doc.Tables[1].Cell(i, 5).Range.Text = Math.Round(product.getSum(), 2).ToString(); WordWorker.doc.Tables[1].Cell(i, 9).Range.Text = Math.Round(product.getSum(), 2).ToString(); } WordWorker.doc.Tables[1].Rows.Add(); i++; WordWorker.doc.Tables[1].Rows[i].Range.Bold = 1; WordWorker.doc.Tables[1].Cell(i, 1).Range.Text = "Итого"; WordWorker.doc.Tables[1].Cell(i, 5).Range.Text = Math.Round(float.Parse(lSumm.Text), 2).ToString(); WordWorker.doc.Tables[1].Cell(i, 9).Range.Text = Math.Round(float.Parse(lSumm.Text), 2).ToString(); WordWorker.Save(MainForm.DataPath + "\\Документы\\" + (cBContracts.SelectedItem as ContractDTO).ToString() + "\\" + (lBInvoices.SelectedItem as InvoiceDTO).ToString() + ".docx"); WordWorker.Close(); lLoad.Visible = false; } WordWorker.Close(); }
public void BuildDocument() { DialogResult dialogResult = MessageBox.Show("Все запущенные документы будут закрыты без сохранения! Сохраните используемые в данный момент документы и нажмите 'Ок'", "ВНИМАНИЕ!!!", MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.OK) { lLoad.Visible = true; WordWorker.Load(); Word.Range range = WordWorker.doc.Paragraphs[WordWorker.doc.Paragraphs.Count].Range; int productIndex = 4; int productIndexB = 4; int menuIndex = 3; double TotalAll = 0; double TotalAllB = 0; int totalKids = 0; int totalKidsB = 0; ProductInMenu productB = new ProductInMenu(1, "r", 0, 1, 0, 1, 1, true); productB.SumNorms = 0; productB.TotalOfKids = 0; List <ProductInMenu> allProducts = new List <ProductInMenu>(); List <MenuDTO> menus = new List <MenuDTO>(); foreach (MenuDTO menu in clBMenus.CheckedItems) { totalKids += menu.Kids; totalKidsB += menu.KidsB; Stream stream = new FileStream(Application.StartupPath + "\\Local Data\\" + menu.FileName, FileMode.Open); Models.Menu menuInFile = new BinaryFormatter().Deserialize(stream) as Models.Menu; stream.Close(); WordWorker.doc.Tables[1].Cell(1, menuIndex).Range.Text = menu.Date.Day.ToString(); WordWorker.doc.Tables[1].Cell(2, menuIndex).Range.Text = (menu.Kids + menu.KidsB).ToString(); WordWorker.doc.Tables[2].Cell(1, menuIndex).Range.Text = menu.Date.Day.ToString(); WordWorker.doc.Tables[2].Cell(2, menuIndex).Range.Text = menu.KidsB.ToString(); foreach (ProductInMenu product in menuInFile.Products) { if (product.Id != menu.ProductBId) { if (allProducts.Where(x => x.Id == product.Id).Count() == 0) { allProducts.Add(product); allProducts.Single(x => x.Id == product.Id).SumNorms = product.TotalOfKids; WordWorker.doc.Tables[1].Cell(productIndex, 1).Range.Text = product.Name; WordWorker.doc.Tables[1].Cell(productIndex, 3).Range.Text = Math.Round(product.Price, 2).ToString(); WordWorker.doc.Tables[1].Cell(productIndex, menuIndex + 2).Range.Text = product.TotalOfKids.ToString(); productIndex++; } else { int index = allProducts.IndexOf(allProducts.Single(x => x.Id == product.Id)) + 4; WordWorker.doc.Tables[1].Cell(index, menuIndex + 2).Range.Text = product.TotalOfKids.ToString(); allProducts.Single(x => x.Id == product.Id).SumNorms += product.TotalOfKids; } } else { productB.Id = menu.ProductBId; WordWorker.doc.Tables[2].Cell(productIndexB, 1).Range.Text = product.Name; WordWorker.doc.Tables[2].Cell(productIndexB, 3).Range.Text = Math.Round(product.Price, 2).ToString(); WordWorker.doc.Tables[2].Cell(productIndexB, menuIndex + 2).Range.Text = product.TotalOfKids.ToString(); productB.SumNorms += product.TotalOfKids; productB.Price = product.Price; } } double summ = 0; double summB = 0; foreach (ProductInMenu productInMenu in menuInFile.Products) { if (productInMenu.Id != menu.ProductBId) { summ = Math.Round(summ + Math.Round((productInMenu.TotalOfKids * productInMenu.Price), 2), 2); } else { summB += Math.Round(summB + Math.Round((productInMenu.TotalOfKids * productInMenu.Price), 2), 2); } } WordWorker.doc.Tables[1].Cell(54, menuIndex + 2).Range.Text = Math.Round(summ, 2).ToString(); WordWorker.doc.Tables[2].Cell(6, menuIndex + 2).Range.Text = Math.Round(summB, 2).ToString(); TotalAllB = Math.Round(TotalAllB + summB, 2); TotalAll = Math.Round(TotalAll + summ, 2); menuIndex++; } WordWorker.doc.Tables[1].Cell(54, 1).Range.Text = "ИТОГО"; WordWorker.doc.Tables[2].Cell(6, 1).Range.Text = "ИТОГО"; double sumSumm = 0; foreach (ProductInMenu product in allProducts) { int index = allProducts.IndexOf(product) + 4; WordWorker.doc.Tables[1].Cell(index, 2).Range.Text = allProducts.Single(x => x.Id == product.Id).SumNorms.ToString(); WordWorker.doc.Tables[1].Cell(index, 4).Range.Text = Math.Round(Math.Round(allProducts.Single(x => x.Id == product.Id).SumNorms, 2) * product.Price, 2).ToString(); sumSumm = Math.Round(sumSumm + Math.Round(Math.Round(allProducts.Single(x => x.Id == product.Id).SumNorms, 2) * product.Price, 2), 2); } WordWorker.doc.Tables[1].Cell(54, 4).Range.Text = Math.Round(sumSumm, 2).ToString(); WordWorker.doc.Tables[2].Cell(4, 2).Range.Text = productB.SumNorms.ToString(); WordWorker.doc.Tables[2].Cell(4, 4).Range.Text = Math.Round(productB.SumNorms * productB.Price, 2).ToString(); WordWorker.doc.Tables[2].Cell(6, 4).Range.Text = Math.Round(productB.SumNorms * productB.Price, 2).ToString(); ReplaceStrings(); WordWorker.FindReplace("{totalKids}", (totalKids + totalKidsB).ToString()); WordWorker.FindReplace("{totalKidsB}", totalKidsB.ToString()); WordWorker.FindReplace("{countMenu}", (menuIndex - 3).ToString()); WordWorker.Save(MainForm.DataPath + "\\Документы\\Накопительные по расходу\\Накопительная по расходу за " + cBMount.SelectedItem.ToString() + " " + cBYear.SelectedItem.ToString() + ".docx"); WordWorker.app.Visible = true; WordWorker.doc = null; lLoad.Visible = false; } WordWorker.Close(); }
public void BuildDocument() { DialogResult dialogResult = MessageBox.Show("Все запущенные документы будут закрыты без сохранения! Сохраните используемые в данный момент документы и нажмите 'Ок'", "ВНИМАНИЕ!!!", MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.OK) { lLoad.Visible = true; WordWorker.Load(); ReplaceStrings(); Word.Range range = WordWorker.doc.Paragraphs[WordWorker.doc.Paragraphs.Count].Range; int contractIndex = 3; int naklIndex = 1; float TotalAll = 0; float TotalContract = 0; List <ProductDTO> allProducts = new List <ProductDTO>(); List <DeliveryNoteDTO> deliveryNotes = new List <DeliveryNoteDTO>(); foreach (DeliveryNoteDTO deliveryNote in cLBDeliveryNotes.CheckedItems) { deliveryNotes.Add(deliveryNote); } foreach (ContractDTO contract in cLBContracts.CheckedItems) { TotalContract = 0; WordWorker.doc.Tables[1].Cell(contractIndex, 2).Range.Text = MainForm.DB.Sellers.Get(contract.SellerId).NameCompany; foreach (DeliveryNoteDTO nakl in deliveryNotes.Where(x => MainForm.DB.Invoices.Get(x.InvoiceId).ContractId == contract.Id)) { Stream stream = new FileStream(Application.StartupPath + "\\Local Data\\" + contract.ToString() + "\\" + nakl.ToString() + ".nakl", FileMode.Open); List <ProductDTO> productList = new BinaryFormatter().Deserialize(stream) as List <ProductDTO>; stream.Close(); float Total = 0; foreach (var item in productList) { Total += item.Sum; if (allProducts.Where(x => x.Id == item.Id).Count() == 0) { allProducts.Add(item); WordWorker.doc.Tables[2].Rows.Add(); WordWorker.doc.Tables[2].Cell((allProducts.FindIndex(x => x.Id == item.Id) + 2), 1).Range.Text = item.Name; WordWorker.doc.Tables[2].Cell((allProducts.FindIndex(x => x.Id == item.Id) + 2), 2).Range.Text = MainForm.DB.Units.Get(item.UnitId).Name; WordWorker.doc.Tables[2].Cell((allProducts.FindIndex(x => x.Id == item.Id) + 2), naklIndex * 2 + 1).Range.Text = Math.Round(item.Balance, 2).ToString(); WordWorker.doc.Tables[2].Cell((allProducts.FindIndex(x => x.Id == item.Id) + 2), naklIndex * 2 + 2).Range.Text = Math.Round(item.Sum, 2).ToString(); } else { WordWorker.doc.Tables[2].Cell((allProducts.FindIndex(x => x.Id == item.Id) + 2), naklIndex * 2 + 1).Range.Text = Math.Round(item.Balance, 2).ToString(); WordWorker.doc.Tables[2].Cell((allProducts.FindIndex(x => x.Id == item.Id) + 2), naklIndex * 2 + 2).Range.Text = Math.Round(item.Sum, 2).ToString(); } } TotalContract += Total; WordWorker.doc.Tables[1].Cell(1, naklIndex + 2).Range.Text = "От " + (nakl as DeliveryNoteDTO).Date.ToLongDateString(); WordWorker.doc.Tables[1].Cell(2, naklIndex + 2).Range.Text = "Накл. №" + (nakl as DeliveryNoteDTO).Number.ToString(); WordWorker.doc.Tables[1].Cell(contractIndex, naklIndex + 2).Range.Text = Math.Round(Total, 2).ToString(); naklIndex++; } WordWorker.doc.Tables[1].Cell(contractIndex, 12).Range.Text = Math.Round(TotalContract, 2).ToString(); WordWorker.doc.Tables[1].Cell(contractIndex, 2).Range.Text = MainForm.DB.Sellers.Get(contract.SellerId).NameCompany; TotalAll += TotalContract; contractIndex++; } WordWorker.doc.Tables[1].Cell(13, 12).Range.Text = Math.Round(TotalAll, 2).ToString(); WordWorker.Save(MainForm.DataPath + "\\Документы\\Накопительные по приходу\\Накопительная по приходу за " + cBMount.SelectedItem.ToString() + " " + cBYear.SelectedItem.ToString() + ".docx"); WordWorker.app.Visible = true; WordWorker.doc = null; lLoad.Visible = false; } WordWorker.Close(); }
private void BuildDocument() { DialogResult dialogResult = MessageBox.Show("Все запущенные документы будут закрыты без сохранения! Сохраните используемые в данный момент документы и нажмите 'Ок'", "ВНИМАНИЕ!!!", MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.OK) { lLoad.Visible = true; WordWorker.Load(); ReplaceStrings(); Word.Range range = WordWorker.doc.Paragraphs[WordWorker.doc.Paragraphs.Count].Range; int i = 4; int y = 3; Dictionary <int, int> productsId = new Dictionary <int, int>(); foreach (DishDTO dishZ in menuInFile.DishesZ) { WordWorker.doc.Tables[1].Cell(i, 2).Range.Text = dishZ.Name; foreach (ProductDishDTO productDish in MainForm.DB.ProductDishes.GetAll().Where(x => x.DishId == dishZ.Id)) { if (!productsId.Keys.Contains(productDish.ProductId)) { productsId.Add(productDish.ProductId, y); WordWorker.doc.Tables[1].Cell(2, y - 1).Range.Text = MainForm.DB.Products.Get(productDish.ProductId).PsevdoName; WordWorker.doc.Tables[1].Cell(i, y).Range.Text = productDish.Norm.ToString(); y++; } else { int s; productsId.TryGetValue(productDish.ProductId, out s); WordWorker.doc.Tables[1].Cell(i, s).Range.Text = productDish.Norm.ToString(); } } i++; } i = 9; foreach (DishDTO dishO in menuInFile.DishesO) { WordWorker.doc.Tables[1].Cell(i, 2).Range.Text = dishO.Name; foreach (ProductDishDTO productDish in MainForm.DB.ProductDishes.GetAll().Where(x => x.DishId == dishO.Id)) { if (!productsId.Keys.Contains(productDish.ProductId)) { productsId.Add(productDish.ProductId, y); WordWorker.doc.Tables[1].Cell(2, y - 1).Range.Text = MainForm.DB.Products.Get(productDish.ProductId).PsevdoName; WordWorker.doc.Tables[1].Cell(i, y).Range.Text = productDish.Norm.ToString(); y++; } else { int s; productsId.TryGetValue(productDish.ProductId, out s); WordWorker.doc.Tables[1].Cell(i, s).Range.Text = productDish.Norm.ToString(); } } i++; } i = 15; foreach (DishDTO dishP in menuInFile.DishesP) { WordWorker.doc.Tables[1].Cell(i, 2).Range.Text = dishP.Name; foreach (ProductDishDTO productDish in MainForm.DB.ProductDishes.GetAll().Where(x => x.DishId == dishP.Id)) { if (!productsId.Keys.Contains(productDish.ProductId)) { productsId.Add(productDish.ProductId, y); WordWorker.doc.Tables[1].Cell(2, y - 1).Range.Text = MainForm.DB.Products.Get(productDish.ProductId).PsevdoName; WordWorker.doc.Tables[1].Cell(i, y).Range.Text = productDish.Norm.ToString(); y++; } else { int s; productsId.TryGetValue(productDish.ProductId, out s); WordWorker.doc.Tables[1].Cell(i, s).Range.Text = productDish.Norm.ToString(); } } i++; } foreach (ProductInMenu product in menuInFile.Products) { int s; productsId.TryGetValue(product.Id, out s); WordWorker.doc.Tables[1].Cell(20, s - 1).Range.Text = Math.Round(product.SumNorms, 2).ToString(); WordWorker.doc.Tables[1].Cell(21, s - 1).Range.Text = Math.Round(product.TotalOfKids, 2).ToString(); WordWorker.doc.Tables[1].Cell(22, s - 1).Range.Text = Math.Round(product.Price, 2).ToString(); if (product.Id != (cBProductB.SelectedItem as ProductDTO).Id) { WordWorker.doc.Tables[1].Cell(23, s).Range.Text = Math.Round(product.TotalOfKids * product.Price, 2).ToString(); } else { WordWorker.doc.Tables[1].Cell(24, s).Range.Text = Math.Round(product.TotalOfKids * product.Price, 2).ToString(); } } WordWorker.doc.Tables[1].Cell(23, 2).Range.Text = Math.Round(float.Parse(lSumm.Text), 2).ToString(); WordWorker.doc.Tables[1].Cell(24, 2).Range.Text = Math.Round(float.Parse(lSummB.Text), 2).ToString(); WordWorker.Save(MainForm.DataPath + "\\Документы\\Меню\\Меню на " + dTPDate.Value.ToLongDateString() + ".docx"); WordWorker.Close(); lLoad.Visible = false; } WordWorker.Close(); }