public BindingSource AddNewTemplateToBindingSourceFromFile(DataGridView dgv, BindingSource bs, string filePath) { var fileInfo = new FileInfo(filePath); string regexp = @"[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}"; var id = Guid.Empty; if (Regex.IsMatch(filePath, regexp)) { id = new Guid(Regex.Match(filePath, regexp).Value); } if (!CheckMethods.DoesGridviewContainGuid(dgv, "idDataGridViewTextBoxColumn", id)) { var entityType = string.Empty; if (filePath.Contains(settings.PrefixDocumentTemplate)) { entityType = "documenttemplate"; } if (filePath.Contains(settings.PrefixPersonalDocumentTemplate)) { entityType = "personaldocumenttemplate"; } var template = new DocumentTemplateModel { Id = id, DocumentType = fileInfo.Extension, Name = fileInfo.Name.Replace(fileInfo.Extension, string.Empty), FilePath = filePath, EntityType = entityType, CreatedNew = true }; bs.Add(template); } else { var ex = new DuplicateException("Duplicate detected! A dataset with the given id " + id.ToString() + " was already added to this list!"); throw ex; } return(bs); }
private void btnDlDisk_Click(object sender, EventArgs e) { if (DgvDocumentTemplates.SelectedRows.Count > 0) { if (!string.IsNullOrEmpty(TxtDirectoryPath.Text) && Directory.Exists(TxtDirectoryPath.Text)) { if (!CheckMethods.DoesGridviewContainString(DgvDocumentTemplates, "NameDataGridViewTextBoxColumn3")) { var dialog = new ConfirmImportDialog(); DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { var stepSize = Convert.ToInt32((100 / DgvDocumentTemplates.SelectedRows.Count)); TsprgbLoadUpdate.Value = 0; var selectedRows = DgvDocumentTemplates.SelectedRows; var errors = new List <string>(); for (int i = 0; i < selectedRows.Count; i++) { var template = (DocumentTemplateModel)DgvDocumentTemplates.SelectedRows[i].DataBoundItem; if (File.Exists(template.FilePath)) { if (template.CreatedNew) { _documentTemplateService.CreateFile(template); } else // Template already exists { _documentTemplateService.UpdateFile(template); } TsprgbLoadUpdate.Value += stepSize; } else // FilePath does not exist { errors.Add(template.FilePath); } } TsprgbLoadUpdate.Value = TsprgbLoadUpdate.Maximum; ResetProgressBar(3500); ShowInfoNote("Update complete!"); //tabCtrlDocumentTemplate.SelectTab(tabCrmDocumentTemplates); BsCrmTemplates = _bindingSourceService.LoadCrmTemplatesToBindingSource(BsCrmTemplates); if (errors.Count > 0) { var message = "The Following files could not be found:\n\n"; foreach (var s in errors) { message += s + "\n\n"; } MessageBox.Show(message); } } } else //EntityType is empty { ShowErrorNote("The field 'Entity Type' must not be empty!"); } } } else // No rows selected { ShowInfoNote("No templates selected!"); } #region delete if (DgvDocumentTemplates.SelectedRows.Count > 0) { foreach (DataGridViewRow row in DgvDocumentTemplates.SelectedRows) { BsDocumentTemplateObject.Remove(row.DataBoundItem); } } else // No rows selected { ShowInfoNote("No templates selected!"); } #endregion }