void ReplaceStrings() { WordWorker.FindReplace("{mount}", cBMount.SelectedItem.ToString()); WordWorker.FindReplace("{year}", cBYear.SelectedItem.ToString()); WordWorker.FindReplace("{nameCompanyCustomer}", (cBCustomer.SelectedItem as CustomerDTO).NameCompany); WordWorker.FindReplace("{nameCustomer}", (cBCustomer.SelectedItem as CustomerDTO).NameCustomer); }
void ReplaceStrings() { WordWorker.FindReplace("{vrachName}", tBVrach.Text); WordWorker.FindReplace("{kladName}", tBKlad.Text); WordWorker.FindReplace("{otdelenie}", tBOtdelenie.Text); WordWorker.FindReplace("{uchregdenie}", tBUchregdenie.Text); WordWorker.FindReplace("{povarName}", tBPovar.Text); WordWorker.FindReplace("{rukovoditelName}", tBRukov.Text); WordWorker.FindReplace("{date}", dTPDate.Value.ToShortDateString()); WordWorker.FindReplace("{kids}", (int.Parse(tBKids.Text) + int.Parse(tBKidsB.Text)).ToString()); WordWorker.FindReplace("{total}", (float.Parse(lSumm.Text) + float.Parse(lSummB.Text)).ToString()); }
void ReplaceStrings() { ContractDTO contract = MainForm.DB.Contracts.Get(MainForm.DB.Invoices.Get((lBDeliveryNotes.SelectedItem as DeliveryNoteDTO).InvoiceId).ContractId); InvoiceDTO invoice = MainForm.DB.Invoices.Get((lBDeliveryNotes.SelectedItem as DeliveryNoteDTO).InvoiceId); WordWorker.FindReplace("{dateNakl}", dTPData.Value.ToShortDateString()); WordWorker.FindReplace("{contractName}", contract.ToString()); WordWorker.FindReplace("{invoiceName}", invoice.ToString()); WordWorker.FindReplace("{numberNakl}", tBNumber.Text.ToString()); WordWorker.FindReplace("{nameCompanySeller}", MainForm.DB.Sellers.Get(contract.SellerId).NameCompany); WordWorker.FindReplace("{nameCompanyCustomer}", MainForm.DB.Customers.Get(contract.CustomerId).NameCompany); WordWorker.FindReplace("{fullNameCompanySeller}", MainForm.DB.Sellers.Get(contract.SellerId).FullNameCompany); WordWorker.FindReplace("{fullNameCompanyCustomer}", MainForm.DB.Customers.Get(contract.CustomerId).FullNameCompany); WordWorker.FindReplace("{nameSeller}", MainForm.DB.Sellers.Get(contract.SellerId).NameSeller); WordWorker.FindReplace("{addressCustomer}", MainForm.DB.Customers.Get(contract.CustomerId).AddressCompany); WordWorker.FindReplace("{addressSeller}", MainForm.DB.Sellers.Get(contract.SellerId).AddressCompany); WordWorker.FindReplace("{innCustomer}", MainForm.DB.Customers.Get(contract.CustomerId).INN.ToString()); WordWorker.FindReplace("{innSeller}", MainForm.DB.Sellers.Get(contract.SellerId).INN.ToString()); WordWorker.FindReplace("{kppCustomer}", MainForm.DB.Customers.Get(contract.CustomerId).KPP.ToString()); WordWorker.FindReplace("{kppSeller}", MainForm.DB.Sellers.Get(contract.SellerId).KPP.ToString()); WordWorker.FindReplace("{personalAccountCustomer}", MainForm.DB.Customers.Get(contract.CustomerId).PersonalAccount); WordWorker.FindReplace("{corespAccountSeller}", MainForm.DB.Sellers.Get(contract.SellerId).CorrespondentAccount); WordWorker.FindReplace("{bikCustomer}", MainForm.DB.Customers.Get(contract.CustomerId).BIK.ToString()); WordWorker.FindReplace("{bikSeller}", MainForm.DB.Sellers.Get(contract.SellerId).BIK.ToString()); WordWorker.FindReplace("{bikCustomer}", MainForm.DB.Customers.Get(contract.CustomerId).BIK.ToString()); WordWorker.FindReplace("{bankCustomer}", MainForm.DB.Customers.Get(contract.CustomerId).Bank); WordWorker.FindReplace("{bankSeller}", MainForm.DB.Sellers.Get(contract.SellerId).Bank); WordWorker.FindReplace("{bankAccountCustomer}", MainForm.DB.Customers.Get(contract.CustomerId).BankAccount); WordWorker.FindReplace("{bankAccountSeller}", MainForm.DB.Sellers.Get(contract.SellerId).BankAccount); WordWorker.FindReplace("{priemName}", tBPriemName.Text); WordWorker.FindReplace("{gruzName}", tBGruzName.Text); string replacedOfWord = WordWorker.ReplaceOfWord(float.Parse(lSumm.Text)); if (lSumm.Text.Contains(',')) { if (lSumm.Text.Substring(lSumm.Text.IndexOf(',')).Length - 1 == 2) { WordWorker.FindReplace("{total}", replacedOfWord.Remove(replacedOfWord.Length - 1)); WordWorker.FindReplace("{kopeiki}", lSumm.Text.Substring(lSumm.Text.IndexOf(',') + 1)); } else { WordWorker.FindReplace("{total}", replacedOfWord.Remove(replacedOfWord.Length - 1)); WordWorker.FindReplace("{kopeiki}", lSumm.Text.Substring(lSumm.Text.IndexOf(',') + 1) + "0"); } } else { WordWorker.FindReplace("{total}", replacedOfWord.Remove(replacedOfWord.Length - 1)); WordWorker.FindReplace("{kopeiki}", "00"); } }
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(); }
void ReplaceStrings() { WordWorker.FindReplace("{date}", dTPData.Value.ToShortDateString()); WordWorker.FindReplace("{contractDate}", (cBContracts.SelectedItem as ContractDTO).ConclusionDate.ToLongDateString()); WordWorker.FindReplace("{contractNumber}", (cBContracts.SelectedItem as ContractDTO).Number.ToString()); WordWorker.FindReplace("{number}", tBNumber.Text.ToString()); WordWorker.FindReplace("{NameCompanySeller}", MainForm.DB.Sellers.Get((cBContracts.SelectedItem as ContractDTO).SellerId).NameCompany); WordWorker.FindReplace("{nameCompanyCustomer}", MainForm.DB.Customers.Get((cBContracts.SelectedItem as ContractDTO).CustomerId).NameCompany); WordWorker.FindReplace("{nameSeller}", MainForm.DB.Sellers.Get((cBContracts.SelectedItem as ContractDTO).SellerId).NameSeller); WordWorker.FindReplace("{addressCustomer}", MainForm.DB.Customers.Get((cBContracts.SelectedItem as ContractDTO).CustomerId).AddressCompany); WordWorker.FindReplace("{addressSeller}", MainForm.DB.Sellers.Get((cBContracts.SelectedItem as ContractDTO).SellerId).AddressCompany); WordWorker.FindReplace("{innCustomer}", MainForm.DB.Customers.Get((cBContracts.SelectedItem as ContractDTO).CustomerId).INN.ToString()); WordWorker.FindReplace("{innSeller}", MainForm.DB.Sellers.Get((cBContracts.SelectedItem as ContractDTO).SellerId).INN.ToString()); WordWorker.FindReplace("{kppCustomer}", MainForm.DB.Customers.Get((cBContracts.SelectedItem as ContractDTO).CustomerId).KPP.ToString()); WordWorker.FindReplace("{kppSeller}", MainForm.DB.Sellers.Get((cBContracts.SelectedItem as ContractDTO).SellerId).KPP.ToString()); string replacedOfWord = WordWorker.ReplaceOfWord(Math.Round(float.Parse(lSumm.Text), 2)); if (lSumm.Text.Contains(',')) { if (lSumm.Text.Substring(lSumm.Text.IndexOf(',')).Length - 1 == 2) { WordWorker.FindReplace("{total}", replacedOfWord.Remove(replacedOfWord.Length - 1)); WordWorker.FindReplace("{kopeiki}", lSumm.Text.Substring(lSumm.Text.IndexOf(',') + 1)); } else { WordWorker.FindReplace("{total}", replacedOfWord.Remove(replacedOfWord.Length - 1)); WordWorker.FindReplace("{kopeiki}", lSumm.Text.Substring(lSumm.Text.IndexOf(',') + 1) + "0"); } } else { WordWorker.FindReplace("{total}", replacedOfWord.Remove(replacedOfWord.Length - 1)); WordWorker.FindReplace("{kopeiki}", "00"); } }
void ReplaceStrings() { WordWorker.FindReplace("{date}", dTPData.Value.ToShortDateString()); WordWorker.FindReplace("{dateEnd}", dTPOkonch.Value.ToShortDateString()); WordWorker.FindReplace("{typeSpec}", cBTypeProducts.Text); WordWorker.FindReplace("{number}", tBNumber.Text.ToString()); WordWorker.FindReplace("{address}", "п.Советский"); WordWorker.FindReplace("{fullNameCompanyCustomer}", (cBCustomer.SelectedItem as CustomerDTO).FullNameCompany); WordWorker.FindReplace("{fullNameCompanySeller}", (cBSeller.SelectedItem as SellerDTO).FullNameCompany); WordWorker.FindReplace("{nameCustomerSpec}", (cBCustomer.SelectedItem as CustomerDTO).NameCustomerSpec); WordWorker.FindReplace("{nameCustomer}", (cBCustomer.SelectedItem as CustomerDTO).NameCustomer); WordWorker.FindReplace("{nameSeller}", (cBSeller.SelectedItem as SellerDTO).NameSeller); WordWorker.FindReplace("{nameSellerSpec}", (cBSeller.SelectedItem as SellerDTO).NameSellerSpec); WordWorker.FindReplace("{addressCustomer}", (cBCustomer.SelectedItem as CustomerDTO).AddressCompany); WordWorker.FindReplace("{addressSeller}", "Адрес: " + (cBSeller.SelectedItem as SellerDTO).AddressCompany); if (!(cBSeller.SelectedItem as SellerDTO).Email.Equals("")) { WordWorker.FindReplace("{emailSeller}", "Email:" + (cBSeller.SelectedItem as SellerDTO).Email); } else { WordWorker.FindReplace("{emailSeller}", "" + (cBSeller.SelectedItem as SellerDTO).Email); } WordWorker.FindReplace("{personalAccountCustomer}", (cBCustomer.SelectedItem as CustomerDTO).PersonalAccount); if (!(cBSeller.SelectedItem as SellerDTO).PersonalAccount.Equals("")) { WordWorker.FindReplace("{corespAccountSeller}", "к/с: " + (cBSeller.SelectedItem as SellerDTO).CorrespondentAccount); } else { WordWorker.FindReplace("{corespAccountSeller}", "" + (cBSeller.SelectedItem as SellerDTO).CorrespondentAccount); } WordWorker.FindReplace("{bikCustomer}", (cBCustomer.SelectedItem as CustomerDTO).BIK.ToString()); if (!(cBSeller.SelectedItem as SellerDTO).BIK.Equals("")) { WordWorker.FindReplace("{bikSeller}", "БИК: " + (cBSeller.SelectedItem as SellerDTO).BIK.ToString()); } else { WordWorker.FindReplace("{bikSeller}", "" + (cBSeller.SelectedItem as SellerDTO).BIK.ToString()); } if (!(cBSeller.SelectedItem as SellerDTO).OGRN.Equals("")) { WordWorker.FindReplace("{ogrnSeller}", "ОГРН: " + (cBSeller.SelectedItem as SellerDTO).OGRN.ToString()); } else { WordWorker.FindReplace("{ogrnSeller}", "" + (cBSeller.SelectedItem as SellerDTO).OGRN.ToString()); } WordWorker.FindReplace("{bikCustomer}", (cBCustomer.SelectedItem as CustomerDTO).BIK.ToString()); WordWorker.FindReplace("{innCustomer}", (cBCustomer.SelectedItem as CustomerDTO).INN.ToString()); if (!(cBSeller.SelectedItem as SellerDTO).INN.Equals("")) { WordWorker.FindReplace("{innSeller}", "ИНН: " + (cBSeller.SelectedItem as SellerDTO).INN.ToString()); } else { WordWorker.FindReplace("{innSeller}", "" + (cBSeller.SelectedItem as SellerDTO).INN.ToString()); } WordWorker.FindReplace("{kppCustomer}", (cBCustomer.SelectedItem as CustomerDTO).KPP.ToString()); if (!(cBSeller.SelectedItem as SellerDTO).KPP.Equals("")) { WordWorker.FindReplace("{kppSeller}", "КПП: " + (cBSeller.SelectedItem as SellerDTO).KPP.ToString()); } else { WordWorker.FindReplace("{kppSeller}", "" + (cBSeller.SelectedItem as SellerDTO).KPP.ToString()); } WordWorker.FindReplace("{bankCustomer}", (cBCustomer.SelectedItem as CustomerDTO).Bank); if (!(cBSeller.SelectedItem as SellerDTO).Bank.Equals("")) { WordWorker.FindReplace("{bankSeller}", "Банк: " + (cBSeller.SelectedItem as SellerDTO).Bank); } else { WordWorker.FindReplace("{bankSeller}", "" + (cBSeller.SelectedItem as SellerDTO).Bank); } WordWorker.FindReplace("{bankAccountCustomer}", (cBCustomer.SelectedItem as CustomerDTO).BankAccount); if (!(cBSeller.SelectedItem as SellerDTO).BankAccount.Equals("")) { WordWorker.FindReplace("{bankAccountSeller}", "р/с: " + (cBSeller.SelectedItem as SellerDTO).BankAccount); } else { WordWorker.FindReplace("{bankAccountSeller}", "" + (cBSeller.SelectedItem as SellerDTO).BankAccount); } if (!(cBSeller.SelectedItem as SellerDTO).PhoneNumber.Equals("")) { WordWorker.FindReplace("{phoneSeller}", "Телефон: " + (cBSeller.SelectedItem as SellerDTO).PhoneNumber); } else { WordWorker.FindReplace("{phoneSeller}", "" + (cBSeller.SelectedItem as SellerDTO).PhoneNumber); } WordWorker.FindReplace("{rangSeller}", (cBSeller.SelectedItem as SellerDTO).RangSeller); WordWorker.FindReplace("{nameResponssable}", tBOtv.Text.ToString()); WordWorker.FindReplace("{year}", dTPData.Value.Year.ToString()); WordWorker.FindReplace("{total}", Math.Round(float.Parse(lSumm.Text)).ToString()); string replacedOfWord = WordWorker.ReplaceOfWord(float.Parse(lSumm.Text)); if (lSumm.Text.Contains(',')) { if (lSumm.Text.Substring(lSumm.Text.IndexOf(',')).Length - 1 == 2) { WordWorker.FindReplace("{totalRub}", replacedOfWord.Remove(replacedOfWord.Length - 1)); WordWorker.FindReplace("{kopeiki}", lSumm.Text.Substring(lSumm.Text.IndexOf(',') + 1)); } else { WordWorker.FindReplace("{totalRub}", replacedOfWord.Remove(replacedOfWord.Length - 1)); WordWorker.FindReplace("{kopeiki}", lSumm.Text.Substring(lSumm.Text.IndexOf(',') + 1) + "0"); } } else { WordWorker.FindReplace("{totalRub}", replacedOfWord.Remove(replacedOfWord.Length - 1)); WordWorker.FindReplace("{kopeiki}", "00"); } }