示例#1
0
        private void btnBrowseFileContact_Click(object sender, EventArgs e)
        {
            try
            {
                // browse excel import file
                OpenFileDialog objOpenFile = new OpenFileDialog();
                objOpenFile.Title = "Select an import excel file";
                objOpenFile.InitialDirectory = @"c:\";
                objOpenFile.Filter = "Excel files (*.xls;*.xlsx)|*.xls;*.xlsx";
                objOpenFile.FilterIndex = 2;
                objOpenFile.RestoreDirectory = true;

                if (objOpenFile.ShowDialog() == DialogResult.OK)
                    tbxImportFileContact.Text = objOpenFile.FileName;
                else
                    return;

                m_objFileHandlerContact = null;
                m_objFileHandlerContact = new ObjectFileHandler();
                List<string> ExcelSheetNames = new List<string>();

                gcMatchedColumnContact.DataSource = null;
                cboSheetNameContact.Properties.Items.Clear();
                lblRecordStatisticContact.Text = "          Number of Records: 0";
                WaitDialog.Show("Pulling import file...");

                // create temporary copy for importing
                if (File.Exists(m_sFileNameContact) && m_sFileNameContact.Length > 0)
                    File.Delete(m_sFileNameContact);

                string _TempFileName = Path.GetFileName(tbxImportFileContact.Text);
                string _TempFilePath = tbxImportFileContact.Text.Replace(_TempFileName, "");
                m_sFileNameContact = _TempFilePath + "tmp_" + _TempFileName;
                if (File.Exists(m_sFileNameContact))
                    File.Delete(m_sFileNameContact);

                File.Copy(tbxImportFileContact.Text, m_sFileNameContact);

                // populate sheet name combo box
                if (m_objFileHandlerContact.OpenExcelFile(m_sFileNameContact))
                {
                    ExcelSheetNames = m_objFileHandlerContact.GetImportFileSheetNames(m_sFileNameContact);
                    m_objFileHandlerContact.CloseExcelFile();
                }
                else
                {
                    tbxImportFileContact.Text = "";
                    WaitDialog.Close();
                    MessageBox.Show("Not a valid excel file", "Bright Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                foreach (string SheetName in ExcelSheetNames)
                    cboSheetNameContact.Properties.Items.Add(SheetName.Replace("$", ""));

                cboSheetNameContact.SelectedIndex = 0;
                WaitDialog.Close();
                gcMatchedColumnContact.DataSource = null;
                gcImportFileDataContact.DataSource = null;
                btnUpdateToGridContact.Enabled = false;
                btnUpdateToMasterDataTableContact.Enabled = false;
            }
            catch { }
        }
示例#2
0
        /// <summary>
        /// Get import file sheet names
        /// </summary>
        private void GetImportFileSheetNames()
        {
            WaitDialog.Show("Reading file information ...");
            List<string> ExcelSheetNames = new List<string>();
            m_objFileHandler = new ObjectFileHandler();

            // create a temporary copy of the import file
            try {
                // delete existing temporary file
                if (File.Exists(m_FileName))
                    File.Delete(m_FileName);

                string _TempFileName = Path.GetFileName(txtImportFile.Text);
                string _TempFilePath = txtImportFile.Text.Replace(_TempFileName, "");

                m_FileName = string.Empty;
                m_FileName = String.Format("{0}tmp_{1}", _TempFilePath, _TempFileName);
                if (File.Exists(m_FileName))
                    File.Delete(m_FileName);

                File.Copy(txtImportFile.Text, m_FileName);
            }
            catch (Exception Ex) {
                m_FileName = string.Empty;
                MessageBox.Show("Was not able to create / delete the temporary file. Please check your path access rights to that file / folder.", "Import File", MessageBoxButtons.OK, MessageBoxIcon.Information);
                WaitDialog.Close();
                return;
            }

            if (m_objFileHandler.OpenExcelFile(m_FileName)) {
                ExcelSheetNames = m_objFileHandler.GetImportFileSheetNames(m_FileName);
                m_objFileHandler.CloseExcelFile();
            }
            else {
                MessageBox.Show("Not a valid excel file", m_MessageBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                WaitDialog.Close();
                return;
            }

            cboSheetName.Items.Clear();
            foreach (string SheetName in ExcelSheetNames)
                cboSheetName.Items.Add(SheetName);

            WaitDialog.Close();
        }
示例#3
0
        private void m_bwColumnMatching_DoWork(object sender, DoWorkEventArgs e)
        {
            m_objFileHandler = new ObjectFileHandler();
            m_dtColumnMatches = new DataTable();
            m_dtColumnMatches = DataImportUtility.CreateLargeCompanyImportColumnMatching();

            this.Invoke(new MethodInvoker(delegate  {
                WaitDialog.Show(ParentForm, "Matching import file...");
                cmdUpdateToGrid.Enabled = false;
                cmdUpdateToMasterDataTable.Enabled = false;

                gcMatchedColumn.DataSource = null;
                if (!m_objFileHandler.OpenExcelFile(m_sFileName)) {
                    cmdUpdateToGrid.Enabled = true;
                    WaitDialog.Close();
                    e.Cancel = true;
                    return;
                }

                List<string> _lstImportFileColumns = m_objFileHandler.GetImportFileColumnNames(m_sFileName, cboSheetName.Text);
                if (_lstImportFileColumns.Count < 1) {
                    cmdUpdateToGrid.Enabled = true;
                    MessageBox.Show("Selected import file has no columns.", "Bright Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    WaitDialog.Close();
                    e.Cancel = true;
                    return;
                }

                m_NoOfColumnsMatched = 0;
                int _iMatchedColumnIndex = 0;
                string _sMasterDataFieldName = string.Empty;
                layoutControlItem3.Text = "Identical Column Matching         now processing import file column matching ...";

                m_lstAccountColumnNames = null;
                m_lstAccountColumnNames = new List<CTAccountColumnName>();
                m_lstAccountColumnNames = ObjectCompany.GetAccountColumnNames();
                for (int i = 0; i < m_lstAccountColumnNames.Count; i++) {
                    _sMasterDataFieldName = m_lstAccountColumnNames[i].master_data_field;
                    _iMatchedColumnIndex = _lstImportFileColumns.IndexOf(_sMasterDataFieldName);
                    if (_iMatchedColumnIndex >= 0) {
                        m_lstAccountColumnNames[i].matched_column_no = _iMatchedColumnIndex.ToString();
                        m_lstAccountColumnNames[i].matched_column_name = _sMasterDataFieldName;
                        m_NoOfColumnsMatched ++;
                    }
                }

                gcMatchedColumn.DataSource = m_lstAccountColumnNames;
                gvMatchedColumn.BestFitColumns();
                layoutControlItem3.Text = "Identical Column Matching";
                m_objFileHandler.CloseExcelFile();
                cmdUpdateToGrid.Enabled = true;
                WaitDialog.Close();

            }));

            e.Cancel = true;
        }
示例#4
0
        /// <summary>
        /// Open the import file and read contents
        /// </summary>
        public void GetFileContents()
        {
            if (InvokeRequired)
            {
                this.Invoke(new MethodInvoker(delegate { this.WriteLog("Opening file: " + m_FileName); }));
                this.Invoke(new MethodInvoker(delegate { this.WriteLog("Reading and getting file contents ..."); }));

                m_objFileDataTable = null;
                m_objFileDataTable = new DataTable();
                m_objFileHandler = new ObjectFileHandler();

                if (m_objFileHandler.OpenExcelFile(m_FileName))
                {
                    this.Invoke(new MethodInvoker(delegate { m_objFileDataTable = m_objFileHandler.GetFileContents(cboSheetName.Text); }));
                    this.Invoke(new MethodInvoker(delegate { m_objFileHandler.CloseExcelFile(); }));
                }
                else
                    MessageBox.Show("Not a valid excel file", m_MessageBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);

                this.Invoke(new MethodInvoker(delegate { this.WriteLog("Done ..."); }));
                this.Invoke(new MethodInvoker(delegate { this.WriteLog("Getting total number of records on file ..."); }));
                this.Invoke(new MethodInvoker(delegate { this.WriteLog("Records found: " + m_objFileDataTable.Rows.Count.ToString()); }));
                this.Invoke(new MethodInvoker(delegate { this.WriteLog("Done ..."); }));
            }
        }