Пример #1
0
        private void buttonLoadEx_Click(object sender, RoutedEventArgs e)
        {
            button1_Click(null, null);


            ProgressWnd pw = new ProgressWnd("Загрузка данных из Excel...");

            pw.Show();
            var ad = LoadDataFromExcel(textBoxExcelPath.Text);

            pw.Stop();



            ad.Our      = (DataContext as AllData).Our;
            DataContext = ad;

            dataGridExtra1.ItemsSource   = ad.e1;
            dataGridExtraSod.ItemsSource = ad.e2;
            dataGridContacts.ItemsSource = ad.Contacts;
        }
Пример #2
0
        private void buttonPDF_Click(object sender, RoutedEventArgs e)
        {
            var wrd_name = Convert.ToString(comboBox.SelectedValue);
            var xls_name = textBoxExcelPath.Text;

            if (string.IsNullOrEmpty(wrd_name))
            {
                MessageBox.Show("Выберите шаблон КП");
                return;
            }

            ProgressWnd pw = new ProgressWnd("Создаем КП по шаблону...");
            pw.Show();

            string fn = "";
            try
            {

                WordApp = new Wd.Application() { Visible = false };
                WordDoc = WordApp.Documents.Open(wrd_name);
                fn=SaveW(WordApp, WordDoc);

                var ad = DataContext as AllData;

                ReplaceAll(WordDoc,"[OurCompany]", ad.Our.OurCompany);
                ReplaceAll(WordDoc, "[ForWho]", ad.ForWho);
                ReplaceAll(WordDoc, "[ContractPeriodYears]", ad.HowLongYears);
                ReplaceAll(WordDoc, "[ServiceType]", ad.ServiceType);
                ReplaceAll(WordDoc, "[DaysToStart]", ad.DaysToStart);
                ReplaceAll(WordDoc, "[DateStart]", ad.DateStart);
                ReplaceAll(WordDoc, "[CostMonthString]", ad.CostMonthString);
                ReplaceAll(WordDoc, "[CostMonth]", ad.CostMonth);
                ReplaceAll(WordDoc, "[CostYear]", (o2d(ad.CostMonth) * 12).ToString());
                ReplaceAll(WordDoc, "[Address]", ad.Address);
                ReplaceAll(WordDoc, "[Date]", ad.Date);
                ReplaceAll(WordDoc, "[Area]", ad.Area.ToString());
                ReplaceAll(WordDoc, "[NameObject]", ad.ForWho);

                int kk = 1;
                foreach(var ee in ad.e1)
                {
                    var trg="[Extra" + kk + "]";
                    if (ee.IsSelected==true)
                    {
                        ReplaceAll(WordDoc, trg, ee.Text);
                    }
                    else
                    {
                        WordDoc.Bookmarks["bExtra" + kk].Range.Delete();
                        ReplaceAll(WordDoc, trg, "");
                    }
                    ++kk;
                }

                kk = 1;
                foreach (var ee in ad.e2)
                {
                    var trg = "[Sod" + kk + "]";
                    if (ee.IsSelected == true)
                    {
                        ReplaceAll(WordDoc, trg, ee.Text);
                    }
                    else
                    {
                        WordDoc.Bookmarks["bSod" + kk].Range.Delete();
                        ReplaceAll(WordDoc, trg, "");
                    }
                    ++kk;
                }

                if(radioButton.IsChecked==true)
                {
                    ReplaceAll(WordDoc, "[NaOsnovanii]", ad.NaOsn1);
                }
                else
                {
                    ReplaceAll(WordDoc, "[NaOsnovanii]", ad.NaOsn2);
                }

                if(checkBoxServicePlan.IsChecked==false)
                {
                    Wd.Range delRange = WordDoc.Range();
                    delRange.Start=WordDoc.Bookmarks["b0"].Range.Start;
                    delRange.End = WordDoc.Bookmarks["b1"].Range.End;
                    delRange.Delete();

                }
                ReplaceAll(WordDoc, "[ServicePlanStart]", "");
                ReplaceAll(WordDoc, "[ServicePlanEnd]", "");
                //ReplaceAll(WordDoc, "[NameCost]", ad.ForWho);

                //Sebestoimost
                Wd.Table tt=FindTable(WordDoc, WordDoc.Bookmarks["tab6"]);

                double total = 0;
                foreach (var s in ad.Sebestimost)
                {
                    tt.Rows.Add();

                    tt.Cell(tt.Rows.Count, 1).Range.Text = s.Name;
                    tt.Cell(tt.Rows.Count, 2).Range.Text = s.CostMonth.ToString();
                    total += s.CostMonth;
                }
                tt.Rows.Add();
                tt.Cell(tt.Rows.Count, 1).Range.Text = "Итого";
                tt.Cell(tt.Rows.Count, 2).Range.Text = total.ToString();
                ///

                //FOT
                Wd.Table ttFOT = FindTable(WordDoc, WordDoc.Bookmarks["tab7"]);

                total = 0;
                foreach (var s in ad.ShtatRasstanovka)
                {
                    ttFOT.Rows.Add();

                    ttFOT.Cell(tt.Rows.Count, 1).Range.Text = s.Num.ToString();
                    ttFOT.Cell(tt.Rows.Count, 2).Range.Text = s.Name;
                    ttFOT.Cell(tt.Rows.Count, 3).Range.Text = s.Quant.ToString();
                    ttFOT.Cell(tt.Rows.Count, 4).Range.Text = s.Smena.ToString();
                }
                ////

                //os sredstv
                Wd.Table ttOS = FindTable(WordDoc, WordDoc.Bookmarks["tab8"]);

                total = 0;
                foreach (var s in ad.OsnSredstva)
                {
                    ttOS.Rows.Add();

                    ttOS.Cell(tt.Rows.Count, 1).Range.Text = s.Num.ToString()+".";
                    ttOS.Cell(tt.Rows.Count, 2).Range.Text = s.Name;
                    ttOS.Cell(tt.Rows.Count, 3).Range.Text = s.Quant.ToString();
                    ttOS.Cell(tt.Rows.Count, 4).Range.Text = s.CostMonth.ToString();

                    total += s.CostMonth;
                }
                ttOS.Rows.Add();
                ttOS.Cell(tt.Rows.Count, 1).Range.Text = "Итого";
                ttOS.Cell(tt.Rows.Count, 4).Range.Text = total.ToString();

                //rash san
                Wd.Table ttSAN = FindTable(WordDoc, WordDoc.Bookmarks["tab9"]);

                total = 0;
                foreach (var s in ad.RashMaterials)
                {
                    ttSAN.Rows.Add();

                    ttSAN.Cell(tt.Rows.Count, 1).Range.Text = s.Name;
                    ttSAN.Cell(tt.Rows.Count, 2).Range.Text = s.Quant.ToString();
                    ttSAN.Cell(tt.Rows.Count, 3).Range.Text = s.Price.ToString();
                    ttSAN.Cell(tt.Rows.Count, 4).Range.Text = s.CostMonth.ToString();

                    total += s.CostMonth;
                }
                ttSAN.Rows.Add();
                ttSAN.Cell(tt.Rows.Count, 1).Range.Text = "Итого в месяц";
                ttSAN.Cell(tt.Rows.Count, 4).Range.Text = total.ToString();

                StringBuilder sb = new StringBuilder();
                foreach(var c in ad.Contacts)
                {
                    if(c.IsSelected)
                    {
                        sb.AppendLine(c.Dolj);
                        sb.AppendLine(c.Name);
                        sb.AppendLine(c.Tel);
                        sb.AppendLine(c.MobTel);
                        sb.AppendLine(c.Email);
                        sb.AppendLine();
                    }
                }
                ReplaceAll(WordDoc, "[Contacts]", sb.ToString());

                WordDoc.TablesOfContents[1].Update();

                foreach (Wd.Range docRange in WordDoc.Words)
                {
                    docRange.HighlightColorIndex = Wd.WdColorIndex.wdNoHighlight;
                }

            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
            finally
            {
                WordDoc.Save();
                WordApp.Documents.Close();
                WordApp.Quit(Wd.WdSaveOptions.wdDoNotSaveChanges);

                string convertedXpsDoc = string.Concat(System.IO.Path.GetTempPath(), "\\", Guid.NewGuid().ToString(), ".xps");
                XpsDocument xpsDocument = ConvertWordToXps(fn, convertedXpsDoc);
                if (xpsDocument != null)
                {
                    documentViewer.Document = xpsDocument.GetFixedDocumentSequence();
                }

                pw.Stop();

            }

            // doc.Content.Find.Execute("[ND]", ReplaceWith: Doc.No);

            //   SaveW(app, doc, TemplateFilePath);
        }
Пример #3
0
        private void buttonPDF_Click(object sender, RoutedEventArgs e)
        {
            var wrd_name = Convert.ToString(comboBox.SelectedValue);
            var xls_name = textBoxExcelPath.Text;



            if (string.IsNullOrEmpty(wrd_name))
            {
                MessageBox.Show("Выберите шаблон КП");
                return;
            }

            ProgressWnd pw = new ProgressWnd("Создаем КП по шаблону...");

            pw.Show();

            string fn = "";

            try
            {
                WordApp = new Wd.Application()
                {
                    Visible = false
                };
                WordDoc = WordApp.Documents.Open(wrd_name);
                fn      = SaveW(WordApp, WordDoc);



                var ad = DataContext as AllData;


                ReplaceAll(WordDoc, "[OurCompany]", ad.Our.OurCompany);
                ReplaceAll(WordDoc, "[ForWho]", ad.ForWho);
                ReplaceAll(WordDoc, "[ContractPeriodYears]", ad.HowLongYears);
                ReplaceAll(WordDoc, "[ServiceType]", ad.ServiceType);
                ReplaceAll(WordDoc, "[DaysToStart]", ad.DaysToStart);
                ReplaceAll(WordDoc, "[DateStart]", ad.DateStart);
                ReplaceAll(WordDoc, "[CostMonthString]", ad.CostMonthString);
                ReplaceAll(WordDoc, "[CostMonth]", ad.CostMonth);
                ReplaceAll(WordDoc, "[CostYear]", (o2d(ad.CostMonth) * 12).ToString());
                ReplaceAll(WordDoc, "[Address]", ad.Address);
                ReplaceAll(WordDoc, "[Date]", ad.Date);
                ReplaceAll(WordDoc, "[Area]", ad.Area.ToString());
                ReplaceAll(WordDoc, "[NameObject]", ad.ForWho);

                int kk = 1;
                foreach (var ee in ad.e1)
                {
                    var trg = "[Extra" + kk + "]";
                    if (ee.IsSelected == true)
                    {
                        ReplaceAll(WordDoc, trg, ee.Text);
                    }
                    else
                    {
                        WordDoc.Bookmarks["bExtra" + kk].Range.Delete();
                        ReplaceAll(WordDoc, trg, "");
                    }
                    ++kk;
                }

                kk = 1;
                foreach (var ee in ad.e2)
                {
                    var trg = "[Sod" + kk + "]";
                    if (ee.IsSelected == true)
                    {
                        ReplaceAll(WordDoc, trg, ee.Text);
                    }
                    else
                    {
                        WordDoc.Bookmarks["bSod" + kk].Range.Delete();
                        ReplaceAll(WordDoc, trg, "");
                    }
                    ++kk;
                }

                if (radioButton.IsChecked == true)
                {
                    ReplaceAll(WordDoc, "[NaOsnovanii]", ad.NaOsn1);
                }
                else
                {
                    ReplaceAll(WordDoc, "[NaOsnovanii]", ad.NaOsn2);
                }

                if (checkBoxServicePlan.IsChecked == false)
                {
                    Wd.Range delRange = WordDoc.Range();
                    delRange.Start = WordDoc.Bookmarks["b0"].Range.Start;
                    delRange.End   = WordDoc.Bookmarks["b1"].Range.End;
                    delRange.Delete();
                }
                ReplaceAll(WordDoc, "[ServicePlanStart]", "");
                ReplaceAll(WordDoc, "[ServicePlanEnd]", "");
                //ReplaceAll(WordDoc, "[NameCost]", ad.ForWho);


                //Sebestoimost
                Wd.Table tt = FindTable(WordDoc, WordDoc.Bookmarks["tab6"]);

                double total = 0;
                foreach (var s in ad.Sebestimost)
                {
                    tt.Rows.Add();

                    tt.Cell(tt.Rows.Count, 1).Range.Text = s.Name;
                    tt.Cell(tt.Rows.Count, 2).Range.Text = s.CostMonth.ToString();
                    total += s.CostMonth;
                }
                tt.Rows.Add();
                tt.Cell(tt.Rows.Count, 1).Range.Text = "Итого";
                tt.Cell(tt.Rows.Count, 2).Range.Text = total.ToString();
                ///

                //FOT
                Wd.Table ttFOT = FindTable(WordDoc, WordDoc.Bookmarks["tab7"]);

                total = 0;
                foreach (var s in ad.ShtatRasstanovka)
                {
                    ttFOT.Rows.Add();

                    ttFOT.Cell(tt.Rows.Count, 1).Range.Text = s.Num.ToString();
                    ttFOT.Cell(tt.Rows.Count, 2).Range.Text = s.Name;
                    ttFOT.Cell(tt.Rows.Count, 3).Range.Text = s.Quant.ToString();
                    ttFOT.Cell(tt.Rows.Count, 4).Range.Text = s.Smena.ToString();
                }
                ////

                //os sredstv
                Wd.Table ttOS = FindTable(WordDoc, WordDoc.Bookmarks["tab8"]);

                total = 0;
                foreach (var s in ad.OsnSredstva)
                {
                    ttOS.Rows.Add();

                    ttOS.Cell(tt.Rows.Count, 1).Range.Text = s.Num.ToString() + ".";
                    ttOS.Cell(tt.Rows.Count, 2).Range.Text = s.Name;
                    ttOS.Cell(tt.Rows.Count, 3).Range.Text = s.Quant.ToString();
                    ttOS.Cell(tt.Rows.Count, 4).Range.Text = s.CostMonth.ToString();

                    total += s.CostMonth;
                }
                ttOS.Rows.Add();
                ttOS.Cell(tt.Rows.Count, 1).Range.Text = "Итого";
                ttOS.Cell(tt.Rows.Count, 4).Range.Text = total.ToString();


                //rash san
                Wd.Table ttSAN = FindTable(WordDoc, WordDoc.Bookmarks["tab9"]);

                total = 0;
                foreach (var s in ad.RashMaterials)
                {
                    ttSAN.Rows.Add();

                    ttSAN.Cell(tt.Rows.Count, 1).Range.Text = s.Name;
                    ttSAN.Cell(tt.Rows.Count, 2).Range.Text = s.Quant.ToString();
                    ttSAN.Cell(tt.Rows.Count, 3).Range.Text = s.Price.ToString();
                    ttSAN.Cell(tt.Rows.Count, 4).Range.Text = s.CostMonth.ToString();

                    total += s.CostMonth;
                }
                ttSAN.Rows.Add();
                ttSAN.Cell(tt.Rows.Count, 1).Range.Text = "Итого в месяц";
                ttSAN.Cell(tt.Rows.Count, 4).Range.Text = total.ToString();


                StringBuilder sb = new StringBuilder();
                foreach (var c in ad.Contacts)
                {
                    if (c.IsSelected)
                    {
                        sb.AppendLine(c.Dolj);
                        sb.AppendLine(c.Name);
                        sb.AppendLine(c.Tel);
                        sb.AppendLine(c.MobTel);
                        sb.AppendLine(c.Email);
                        sb.AppendLine();
                    }
                }
                ReplaceAll(WordDoc, "[Contacts]", sb.ToString());


                WordDoc.TablesOfContents[1].Update();


                foreach (Wd.Range docRange in WordDoc.Words)
                {
                    docRange.HighlightColorIndex = Wd.WdColorIndex.wdNoHighlight;
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
            finally
            {
                WordDoc.Save();
                WordApp.Documents.Close();
                WordApp.Quit(Wd.WdSaveOptions.wdDoNotSaveChanges);

                string      convertedXpsDoc = string.Concat(System.IO.Path.GetTempPath(), "\\", Guid.NewGuid().ToString(), ".xps");
                XpsDocument xpsDocument     = ConvertWordToXps(fn, convertedXpsDoc);
                if (xpsDocument != null)
                {
                    documentViewer.Document = xpsDocument.GetFixedDocumentSequence();
                }


                pw.Stop();
            }


            // doc.Content.Find.Execute("[ND]", ReplaceWith: Doc.No);

            //   SaveW(app, doc, TemplateFilePath);
        }
Пример #4
0
        private void buttonLoadEx_Click(object sender, RoutedEventArgs e)
        {
            button1_Click(null, null);

            ProgressWnd pw = new ProgressWnd("Загрузка данных из Excel...");
            pw.Show();
            var ad = LoadDataFromExcel(textBoxExcelPath.Text);
            pw.Stop();

            ad.Our = (DataContext as AllData).Our;
            DataContext = ad;

            dataGridExtra1.ItemsSource = ad.e1;
            dataGridExtraSod.ItemsSource = ad.e2;
            dataGridContacts.ItemsSource = ad.Contacts;
        }