예제 #1
0
        /// <summary>
        ///  Convert Excel file to Xml format and view in Listbox control
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnConvert_Click(object sender, EventArgs e)
        {
            tbXmlView.Clear();
            string excelfileName = tbExcelName.Text;

            if (string.IsNullOrEmpty(excelfileName) || !File.Exists(excelfileName))
            {
                MessageBox.Show("The Excel file is invalid! Please select a valid file.");
                return;
            }

            try
            {
                string xmlFormatstring = new ConvertExcelToXml().GetXML(excelfileName);
                if (string.IsNullOrEmpty(xmlFormatstring))
                {
                    MessageBox.Show("The content of Excel file is Empty!");
                    return;
                }

                tbXmlView.Text = xmlFormatstring;

                // If txbXmlView has text, set btnSaveAs button to be enable
                btnSaveAs.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error occurs! The error message is: " + ex.Message);
            }
        }
예제 #2
0
        private void btnCreate_Click(object sender, RoutedEventArgs e)
        {
            if (txtDbName.Text != string.Empty && inputfiles.inputFilenames != null)
            {
                try
                {
                    string xmlFormatstring = new ConvertExcelToXml().StoreInDB(inputfiles.inputFilenames, txtDbName.Text);
                    if (xmlFormatstring == "") this.Close();

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error : " + ex.Message);
                    return;
                }
            }
        }
예제 #3
0
 private void DoProcess()
 {
     string filename = string.Empty;
     //read the inspection sheet and convert to xml
     foreach (string fileName in fileList)
     {
         XDocument conditionXML = XMLConvertHelper.ConvertExcelDataToXML(fileName, 1);
         XDocument inputXML = XMLConvertHelper.ConvertExcelDataToXML(txtInputFile.Text, 0);
         DataSet ds = FilterResults(conditionXML, inputXML, selectableCols, out filename);
         //conditionXML.Save("c:\\temp\\test.xml");
         if (ds != null || ds.Tables.Count > 0)
         {
             ConvertExcelToXml cex = new ConvertExcelToXml();
             cex.GenerateExcel(ds.Tables[0], fileName);
             if (filename == string.Empty)
             {
                 filename = string.Format("{0}_{1}.xlsx", System.IO.Path.GetFileNameWithoutExtension(txtInputFile.Text), DateTime.Now.ToFileTime().ToString());
             }
             filename = string.Format("{0}\\inspection\\{1}_{2}.xlsx", System.IO.Path.GetDirectoryName(txtInputFile.Text), System.IO.Path.GetFileNameWithoutExtension(txtInputFile.Text), DateTime.Now.ToFileTime().ToString());
             FileSaveHelper.ExportDataSet(ds, filename);
         }
         else
         {
             System.Windows.MessageBox.Show("No matching records found.");
         }
     }
     System.Windows.MessageBox.Show(string.Format("Operation completed. '{0}' created.", txtConditionFile.Text));
 }