Пример #1
0
        static void Main(string[] args)
        {
            //var abc = MappingLogic.GetAll();

            string abcc = ExcelConversion.UploadSalesOrder();

            //DateTime adab = DateTime.ParseExact("12022009", "ddMMyyyy", CultureInfo.InvariantCulture);



            //int a = CommonHelper.ColumnExcelToNumber("J");

            //var balikan = CommonHelper.ConvertToDateTime("ddMMyyyy", "10021989");

            //string filename = @"D:\New Text Document.txt";

            //using (var md5 = MD5.Create())
            //{
            //    using (var stream = File.OpenRead(filename))
            //    {
            //        //return md5.ComputeHash(stream);
            //        //string abc = Encoding.Default.GetString(md5.ComputeHash(stream));
            //        byte[] checksum = md5.ComputeHash(stream);
            //        string abc = BitConverter.ToString(checksum).Replace("-", string.Empty);
            //    }
            //}

            //using (var stream = File.OpenRead(filename))
            //{

            //    MD5 md5x = new MD5CryptoServiceProvider();
            //    try
            //    {
            //        byte[] result = md5x.ComputeHash(stream);

            //        // Build the final string by converting each byte
            //        // into hex and appending it to a StringBuilder
            //        StringBuilder sb = new StringBuilder();
            //        for (int i = 0; i < result.Length; i++)
            //        {
            //            sb.Append(result[i].ToString("X4"));
            //        }

            //        // And return it
            //        string abc = sb.ToString();
            //    }
            //    catch (ArgumentNullException ane)
            //    {
            //        //If something occurred during serialization,
            //        //this method is called with a null argument.


            //    }
            //}
        }
        private void ExcelFileCreation(IQueryable <History> histories, string excelFilePathAndName)
        {
            ExcelConversion historyExcelConversion = new ExcelConversion();

            historyExcelConversion.OpenExcelApp();
            historyExcelConversion.InitializeColumnNumbers();
            historyExcelConversion.InitializeHeader();
            historyExcelConversion.BoldColumn(1);
            historyExcelConversion.WriteToExcelFile(histories);
            historyExcelConversion.SaveAsAndQuit(excelFilePathAndName);
            historyExcelConversion.Dispose();
        }
Пример #3
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            statusUpdate("Processing queue...");

            #region Validate and check information prior to conversion

            // Check that the queue is not empty
            if (lvFiles.Items.Count == 0)
            {
                MessageBox.Show("Please add files to the queue.");
                return;
            }

            // Check that an output format has been selected
            if (cbConvertOption.SelectedIndex == -1)
            {
                MessageBox.Show("Please select an output format.");
                return;
            }

            // Check that an output location has been selected
            if (string.IsNullOrWhiteSpace(tbPath.Text) || string.IsNullOrEmpty(tbPath.Text))
            {
                MessageBox.Show("Please select an output location.");
                return;
            }

            #endregion

            // Show wait cursor and block interaction
            this.Cursor  = Cursors.WaitCursor;
            this.Enabled = false;

            string conversionFormat = null;
            if (cbConvertOption.SelectedIndex == 0)
            {
                conversionFormat = "quotewin_single";
            }
            else if (cbConvertOption.SelectedIndex == 1)
            {
                conversionFormat = "quotewin_multi";
            }
            else if (cbConvertOption.SelectedIndex == 2)
            {
                conversionFormat = "sap";
            }

            foreach (ListViewItem item in lvFiles.Items)
            {
                // Trigger the preview
                item.Selected         = true;
                item.SubItems[3].Text = "Processing";
                // Get file type and process accordingly
                if (String.Equals(item.SubItems[1].Text, ".doc", StringComparison.OrdinalIgnoreCase) == true || String.Equals(item.SubItems[1].Text, ".docx", StringComparison.OrdinalIgnoreCase) == true)
                {
                    // Give the user a status update
                    statusUpdate(String.Format("Processing file: {0}", item.SubItems[0].Text + item.SubItems[1].Text));
                    // It's a Word document - convert to Excel first
                    var    wordEx  = new WordExtraction();
                    string inFile  = item.SubItems[2].Text;
                    string outFile = this.tbPath.Text + "\\" + item.SubItems[0].Text + "_extract.xls";
                    wordEx.convertWordToExcel(this, inFile, outFile);
                    wordEx = null;
                    // Reset progress bar for file
                    pbUpdate(0, pbModeReset);
                    // Next step: process as Excel
                    statusUpdate(String.Format("Processing file: {0}", item.SubItems[0].Text + "_extract.xls"));
                    var    excelConvert = new ExcelConversion();
                    string inFile2      = outFile;
                    string outFile2     = this.tbPath.Text + "\\" + item.SubItems[0].Text + "_" + conversionFormat;
                    if (conversionFormat.Equals("sap"))
                    {
                        outFile2 = outFile2 + ".xls";
                    }
                    else
                    {
                        outFile2 = outFile2 + ".csv";
                    }
                    // Ask user for row header
                    int headerRow = askRowHeader(item.SubItems[0].Text);
                    // Call Excel conversion function
                    excelConvert.transformExcel(this, inFile2, outFile2, headerRow, conversionFormat);
                    // Reset progress bar for file
                    pbUpdate(0, pbModeReset);
                }
                else if (String.Equals(item.SubItems[1].Text, ".pdf", StringComparison.OrdinalIgnoreCase) == true)
                {
                    statusUpdate(String.Format("Processing file: {0}", item.SubItems[0].Text + item.SubItems[1].Text));
                    // It's a PDF - convert to Word first
                    string inFile  = item.SubItems[2].Text;
                    string outFile = this.tbPath.Text + "\\" + item.SubItems[0].Text + "_extract.doc";
                    var    pdfEX   = new PDFExtraction();
                    pdfEX.convertPDFToWord(this, inFile, outFile);
                    pdfEX = null;
                    // Reset progress bar for file
                    pbUpdate(0, pbModeReset);
                    // Next step: convert from Word to Excel
                    statusUpdate(String.Format("Processing file: {0}", item.SubItems[0].Text + "_extract.doc"));
                    var    wordEx   = new WordExtraction();
                    string inFile2  = outFile;
                    string outFile2 = this.tbPath.Text + "\\" + item.SubItems[0].Text + "_extract.xls";
                    wordEx.convertWordToExcel(this, inFile2, outFile2);
                    wordEx = null;
                    // Reset progress bar for file
                    pbUpdate(0, pbModeReset);
                    // Next step: process as Excel
                    statusUpdate(String.Format("Processing file: {0}", item.SubItems[0].Text + "_extract.xls"));
                    var    excelConvert = new ExcelConversion();
                    string inFile3      = outFile2;
                    string outFile3     = this.tbPath.Text + "\\" + item.SubItems[0].Text + "_" + conversionFormat;
                    if (conversionFormat.Equals("sap"))
                    {
                        outFile3 = outFile3 + ".xls";
                    }
                    else
                    {
                        outFile3 = outFile3 + ".csv";
                    }
                    // Ask user for row header
                    int headerRow = askRowHeader(item.SubItems[0].Text);
                    // Call Excel conversion function
                    excelConvert.transformExcel(this, inFile3, outFile3, headerRow, conversionFormat);
                    // Reset progress bar for file
                    pbUpdate(0, pbModeReset);
                }
                else if (String.Equals(item.SubItems[1].Text, ".xls", StringComparison.OrdinalIgnoreCase) == true || String.Equals(item.SubItems[1].Text, ".xlsx", StringComparison.OrdinalIgnoreCase) == true)
                {
                    statusUpdate(String.Format("Processing file: {0}", item.SubItems[0].Text + item.SubItems[1].Text));
                    // It's a native Excel spreadsheet
                    var    excelConvert = new ExcelConversion();
                    string inFile       = item.SubItems[2].Text;
                    string outFile      = this.tbPath.Text + "\\" + item.SubItems[0].Text + "_" + conversionFormat;
                    if (conversionFormat.Equals("sap"))
                    {
                        outFile = outFile + ".xls";
                    }
                    else
                    {
                        outFile = outFile + ".csv";
                    }
                    // Ask user for row header
                    int headerRow = askRowHeader(item.SubItems[0].Text);
                    excelConvert.transformExcel(this, inFile, outFile, headerRow, conversionFormat);
                    // Reset progress bar for file
                    pbUpdate(0, pbModeReset);
                }
                else
                {
                    // File extension unrecognised
                    Debug.WriteLine("File type unrecognised.");
                    statusUpdate(String.Format("Unrecognised file skipped: {0}", item.SubItems[0].Text + item.SubItems[1].Text));
                }
                // Update status in list
                item.SubItems[3].Text = "Complete";
            }
            // Queue has been completely processed
            statusUpdate("Ready");
            statusUpdate2(" ");
            this.Enabled = true;
            this.Cursor  = Cursors.Default;
        }