private void btnDeleteMailing_Click(object sender, RoutedEventArgs e)
        {
            RadButton _button = (RadButton)sender;

            Mouse.OverrideCursor = Cursors.Wait;
            int ID = ((DealerMailingList)_button.DataContext).ID;

            DealerMailingList _selectedDealerMailingList = DealerMailingListService.GetByID(ID);

            if (MessageBox.Show("Delete the mailing?", "Delete Mailing?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                if (File.Exists(_selectedDealerMailingList.CsvFilePath))
                {
                    File.Delete(_selectedDealerMailingList.CsvFilePath);
                }
                if (File.Exists(_selectedDealerMailingList.MailMergeFilePath))
                {
                    File.Delete(_selectedDealerMailingList.MailMergeFilePath);
                }

                DealerMailingListService.Delete(_selectedDealerMailingList);

                LoadPreviousMailings();
            }


            Mouse.OverrideCursor = Cursors.Arrow;
        }
        private void btnOpenCsvFile_Click(object sender, RoutedEventArgs e)
        {
            RadButton _button = (RadButton)sender;

            Mouse.OverrideCursor = Cursors.Wait;

            int ID = ((DealerMailingList)_button.DataContext).ID;

            DealerMailingList _selectedDealerMailingList = DealerMailingListService.GetByID(ID);

            //CREATING OBJECTS OF WORD AND DOCUMENT
            //Microsoft.Office.Interop.Word.Application oWordApp = new Microsoft.Office.Interop.Word.Application();

            ////close any open documents
            //foreach (Microsoft.Office.Interop.Word.Document _doc in oWordApp.Documents)
            //{
            //    _doc.Close(oFalse, oMissing, oMissing);
            //}
            try
            {
                Utils.OpenExcel(_selectedDealerMailingList.CsvFilePath);

                //oWordApp.Visible = true;
                //Microsoft.Office.Interop.Word.Document oWordDoc = oWordApp.Documents.Open(_selectedDealerMailingList.MailMergeFilePath);
                //oWordDoc.Activate();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            Mouse.OverrideCursor = Cursors.Arrow;
        }
        private void btnmarkTrackback_Click(object sender, RoutedEventArgs e)
        {
            RadButton         _button = (RadButton)sender;
            int               ID      = ((DealerMailingList)_button.DataContext).ID;
            DealerMailingList _selectedDealerMailingList = DealerMailingListService.GetByID(ID);

            _selectedDealerMailingList.TrackingLetterRecieved = true;
            DealerMailingListService.Save(_selectedDealerMailingList);
            MessageBox.Show("Dealer Mailing List Updated!");
            LoadPreviousMailings();
        }
        private void btnDeleteMailing_Click(object sender, RoutedEventArgs e)
        {
            RadButton _button = (RadButton)sender;

            Mouse.OverrideCursor = Cursors.Wait;
            int ID = ((DealerMailingList)_button.DataContext).ID;

            DealerMailingList _selectedDealerMailingList = DealerMailingListService.GetByID(ID);

            //there is the possibility that more than one mailing list has been created from this CSV file.

            try
            {
                List <DealerMailingList> _mailingLists = DealerMailingListService.GetByCsvFilePath(_selectedDealerMailingList.CsvFilePath);

                if (_mailingLists.Count > 1)
                {
                    MessageBox.Show("There are multiple mailing lists generated from this set of cases! The CSV file will not be deleted and the cases will show as SOLD until the other mailing lists generated against this data set are deleted.");
                }

                if (MessageBox.Show("Delete the mailing?", "Delete Mailing?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    if (File.Exists(_selectedDealerMailingList.CsvFilePath) && _mailingLists.Count == 1)
                    {
                        File.Delete(_selectedDealerMailingList.CsvFilePath);
                    }

                    if (File.Exists(_selectedDealerMailingList.MailMergeFilePath))
                    {
                        File.Delete(_selectedDealerMailingList.MailMergeFilePath);
                    }

                    DealerMailingListService.Delete(_selectedDealerMailingList);

                    LoadPreviousMailings();
                    LoadMailingTotals();
                }
            }
            catch (IOException ioex)
            {
                if (ioex.ToString().Contains("The process cannot access the file"))
                {
                    MessageBox.Show("One of the required files (.csv or doc) is open in Word or Excel.  Please clsoe Word and Excel completely and try again.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("The delete failed: " + ex.ToString());
            }

            Mouse.OverrideCursor = Cursors.Arrow;
        }
Exemplo n.º 5
0
 public override Style SelectStyle(object item, DependencyObject container)
 {
     if (item is BRGCaseMailServer.DealerMailingList)
     {
         DealerMailingList _dealerMailingList = item as DealerMailingList;
         if (_dealerMailingList.FiledCasesOnly == true)
         {
             return(HighlightedStyle);
         }
         else
         {
             return(RegularStyle);
         }
     }
     return(null);
 }
        private void btnRemerge_Click(object sender, RoutedEventArgs e)
        {
            RadButton         _button = (RadButton)sender;
            int               ID      = ((DealerMailingList)_button.DataContext).ID;
            DealerMailingList _selectedDealerMailingList = DealerMailingListService.GetByID(ID);

            try
            {
                if (txtReprintTemplateFilePath.Text != _selectedDealerMailingList.TemplateFilePath && txtReprintTemplateFilePath.Text.Length != 0)
                {
                    if (MessageBox.Show("You are selecting a different template than was originally used for this Mailing.  A New Mailing record and Mail Merge will be created using the original CSV file.", "Create New Mail Merge Record?", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                    {
                        _selectedDealerMailingList.TemplateFilePath = txtReprintTemplateFilePath.Text;
                        _selectedDealerMailingList.CreationDate     = DateTime.Parse(DateTime.Now.ToShortDateString());
                        _selectedDealerMailingList.ID = 0;
                        //get the New ID as it is used in the mail merge
                        DealerMailingListService.Save(_selectedDealerMailingList);
                        MailMergeHelper _helper = new MailMergeHelper(_selectedDealer, _selectedDealerMailingList);
                        //process but don't merge
                        _helper.ProcessWordMailMerge(true);
                        LoadPreviousMailings();
                        MessageBox.Show("Mail Merge Created!");
                    }
                }
                else
                {
                    MailMergeHelper _helper = new MailMergeHelper(_selectedDealer, _selectedDealerMailingList);
                    //process but don't merge
                    _helper.ProcessWordMailMerge(true);
                    LoadPreviousMailings();
                    MessageBox.Show("Mail Merge Created!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("The mail merge failed: " + ex.ToString());
            }
        }
        private void btnRemerge_Click(object sender, RoutedEventArgs e)
        {
            RadButton         _button = (RadButton)sender;
            int               ID      = ((DealerMailingList)_button.DataContext).ID;
            DealerMailingList _selectedDealerMailingList = DealerMailingListService.GetByID(ID);

            try
            {
                if (txtReprintTemplateFilePath.Text != _selectedDealerMailingList.TemplateFilePath && txtReprintTemplateFilePath.Text.Length != 0)
                {
                    if (MessageBox.Show("You are selecting a different template than was originally used for this Mailing.  This will replace the mailinglist record but will leave the old word document in the docs folder." + ConfigurationManager.AppSettings["MailMergeDocFilePath"], "Create New Mail Merge Record?", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                    {
                        _selectedDealerMailingList.TemplateFilePath = txtReprintTemplateFilePath.Text;
                        //don't allow cloning of a mailing list on the same day
                        _selectedDealerMailingList.CreationDate = DateTime.Now;
                        //_selectedDealerMailingList.ID = 0;

                        //get the New ID as it is used in the mail merge
                        //DealerMailingListService.Save(_selectedDealerMailingList);
                        MailMergeHelper _helper = new MailMergeHelper(_dealer, _selectedDealerMailingList);
                        //process and merge
                        try
                        {
                            _helper.ProcessMailingList(true);
                            MessageBox.Show("Mail Merge Created!");
                        }
                        catch (IOException ioex)
                        {
                            if (ioex.ToString().Contains("The process cannot access the file"))
                            {
                                MessageBox.Show("The mail merge failed becuase one of the required files (.csv or doc) is already open in Word or Excel.  Please clsoe Word and Excel completely and try again.");
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error Processing Mail merge: " + ex.ToString(), "Error");
                        }

                        LoadPreviousMailings();
                    }
                }
                else if (_selectedDealerMailingList.TemplateFileName == null)
                {
                    MessageBox.Show("Please Select a template!");
                }
                else
                {
                    MailMergeHelper _helper = new MailMergeHelper(_dealer, _selectedDealerMailingList);
                    //process and merge
                    try
                    {
                        _helper.ProcessMailingList(true);
                        MessageBox.Show("Mail Merge Created!");
                    }
                    catch (IOException ioex)
                    {
                        if (ioex.ToString().Contains("The process cannot access the file"))
                        {
                            MessageBox.Show("The mail merge failed becuase one of the required files (.csv or doc) is already open in Word or Excel.  Please clsoe Word and Excel completely and try again.");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error Processing Mail merge: " + ex.ToString(), "Error");
                    }

                    LoadPreviousMailings();
                }
            }
            catch (IOException ioex)
            {
                if (ioex.ToString().Contains("The process cannot access the file"))
                {
                    MessageBox.Show("The mail merge failed becuase one of the required files (.csv or doc) is already open in Word or Excel.  Please clsoe Word and Excel completely and try again.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("The mail merge failed: " + ex.ToString());
            }
        }
        private void btn2StepProcessCreateCSV_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtNumberMailings.Text.Length > 0)
                {
                    try
                    {
                        _dealer.DefaultNumberMailings = Int32.Parse(txtNumberMailings.Text);
                    }
                    catch
                    {
                        MessageBox.Show("A numeric number or mailings is required!");
                        return;
                    }
                }
                else
                {
                    return;
                }

                //save the dealer...
                DealerService.Save(_dealer);

                if (Int32.Parse(txtTotalUnsoldCases.Text) >= Int32.Parse(txtNumberMailings.Text))
                {
                    _dealerMailingList = new DealerMailingList()
                    {
                        DealerID = _dealer.ID, FiledCasesOnly = (bool)rdoFiledOnly.IsChecked, CreationDate = DateTime.Now, MarkedAsSold = (bool)chkMarkAsSold.IsChecked, StartFilterDate = (DateTime)rdpStartSelectDate.SelectedDate, EndFilterDate = (DateTime)rdpEndSelectDate.SelectedDate, TemplateFilePath = txtFilePath.Text, NumberCases = Int32.Parse(txtNumberMailings.Text)
                    };
                }
                else
                {
                    MessageBox.Show("The number of available unsold cases is less that the Selected Number of Mailings");
                    return;
                }

                Mouse.OverrideCursor = Cursors.Wait;

                MailMergeHelper _helper = new MailMergeHelper(_dealer, _dealerMailingList);
                //process but don't merge
                try
                {
                    _helper.ProcessMailingList(false);
                    MessageBox.Show("Mail Merge Created!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error Processing Mail merge: " + ex.ToString(), "Error");
                }

                Mouse.OverrideCursor = Cursors.Arrow;
                LoadPreviousMailings();
                LoadMailingTotals();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                Mouse.OverrideCursor = Cursors.Arrow;
            }
        }