private void test() { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.CheckFileExists = true; openFileDialog.InitialDirectory = ""; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { ImportType it = ImportManager.FileImportType(openFileDialog.FileName); MessageBox.Show(it.ToString()); } }
void import() { bool result = true; string fileName = ""; if (_NeedFileDialog) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.CheckFileExists = true; openFileDialog.InitialDirectory = ""; openFileDialog.RestoreDirectory = true; result = openFileDialog.ShowDialog() == DialogResult.OK; fileName = openFileDialog.FileName; } if (result) { object[] services = null; ImportType importType; try { if (_NeedFileDialog) { importType = ImportManager.FileImportType(fileName); if (_ImportFormType != ImportType.All) { if (importType != _ImportFormType) { ShowMessageError(string.Format(GetLocalized("ImportFileNotContainData"), ImportManager.ImportName(_ImportFormType))); return; } } } else { importType = _ImportFormType; } ImportManager importManager = createImportManager(); switch (importType) { case ImportType.Country: case ImportType.Absence: case ImportType.Feast: case ImportType.WorkingDays: services = new object[] { _CountryService }; break; case ImportType.Region: services = new object[] { _CountryService, _RegionService }; break; case ImportType.Store: services = new object[] { _CountryService, _RegionService, _StoreService }; break; case ImportType.World: case ImportType.HWGR: case ImportType.WGR: case ImportType.ActualBusinessVolume: case ImportType.TargetBusinessVolume: case ImportType.CashRegisterReceipt: services = new object[] { _StoreService }; break; case ImportType.Employee: case ImportType.LongTimeAbsence: case ImportType.TimePlanning: case ImportType.TimeRecording: services = new object[] { _EmployeeService }; break; default: ShowMessage(string.Format(GetLocalized("msgImportTypeNotRealized"), importType.ToString())); break; } if (services != null) { _CanClose = false; enableControls(false); importManager.Import(fileName, importType, services); } } catch (SameColumnsInImportFile) { ShowMessageError(GetLocalized("msgSameColumns")); } catch (UnknownImportFile) { ShowMessageError(GetLocalized("msgImportFileUnknown")); } } }