Ejemplo n.º 1
0
        internal void CreateExcelFile()
        {
            try
            {
                xclFile = new Excel.Application();

                xclWBook      = xclFile.Workbooks.Add(missingValue);
                xclSheet      = xclWBook.Worksheets.get_Item(1);
                xclSheet.Name = "Spoils_Audit";

                xclSheet.Cells[1, 1] = "Starting Number";
                xclSheet.Cells[1, 2] = "Ending Number";
                xclSheet.Cells[1, 3] = "Quantity";
                firstFileCreated     = true;

                xclWBook.SaveAs(GetNewPathName(), Excel.XlFileFormat.xlWorkbookNormal, missingValue, missingValue, missingValue, missingValue,
                                Excel.XlSaveAsAccessMode.xlExclusive, missingValue, missingValue, missingValue, missingValue, missingValue);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                fileExists = FileSave.AddSuffix(path, ".txt", true);
                CloseExcelFile();
            }
        }
Ejemplo n.º 2
0
        private string GetNewPathName()
        {
            if (excelFileName == string.Empty)
            {
                excelFileName = FileSave.AddSuffix(path, ".xls", firstFileCreated);
            }

            FileInfo fi = new FileInfo(excelFileName);

            return(fi.Directory.ToString() + "\\" + fi.Name);
        }
Ejemplo n.º 3
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            string     path       = lblPath.Content.ToString();
            string     header     = lblHeader.Content.ToString();
            DataTable  dtAsc      = dt2.Clone();
            SpoilsData spoilsData = null;

            try
            {
                if (dtAsc.Columns[0].ColumnName == "KEY")
                {
                    FileSave.RemoveDuplicateRows(dt2, "KEY");
                    dtAsc = FileSave.SortAscending("KEY", dt2);
                }
                else if (dtAsc.Columns[0].ColumnName == "Count")
                {
                    FileSave.RemoveDuplicateRows(dt2, "Count");
                    dtAsc = FileSave.SortAscending("Count", dt2);
                }
                else if (dtAsc.Columns[1].ColumnName == "Sequence")
                {
                    FileSave.RemoveDuplicateRows(dt2, "Sequence");
                    dtAsc = FileSave.SortAscending("Sequence", dt2);
                }
                else
                {
                    FileSave.RemoveDuplicateRows(dt2, "Seq");
                    dtAsc = FileSave.SortAscending("Seq", dt2);
                }

                string newFilename = FileSave.SaveSpoilsFile(path, dtAsc, header);

                var lines = File.ReadAllLines(newFilename);
                File.WriteAllLines(newFilename, lines.Take(lines.Length - 1).ToArray());
                int  recordCount  = dtAsc.Rows.Count;
                bool isNewMailing = false;
                spoilsData = new SpoilsData(dtAsc);

                MessageBoxResult processQuestion = MessageBox.Show("Are you processing as new mailing?", "??? IS THIS A NEW MAILING ???", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);

                if (processQuestion != MessageBoxResult.Cancel)
                {
                    if (processQuestion == MessageBoxResult.Yes)
                    {
                        isNewMailing = true;
                        isNewMailing = spoilsData.NewMailing;
                    }

                    FileInfo emailFile = new FileInfo(newFilename);
                    FileSave.SendEmail_Outlook(emailFile, isNewMailing, recordCount);
                    MessageBox.Show(recordCount + " records have been saved!  \n\nEmail has been sent.", "'" + recordCount + "'" + " - RECORD(s) EXPORTED", MessageBoxButton.OK);
                }
                else
                {
                    MessageBox.Show(recordCount + " records have been saved!", "'" + recordCount + "'" + " - RECORD(s) EXPORTED", MessageBoxButton.OK);
                }
                //spoilsData.PopulateReportDataTable();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                ClearAllData();
                ChangeVisibility(true);
            }
        }