private void EditDataSource(TreeView treeView) { if ((ItemTypeEnum)(treeView.SelectedNode.Tag) != ItemTypeEnum.DataSource) { MessageBox.Show(@"Please choose a Datasource"); return; } ReportServerProperties reportServerProperties = new ReportServerProperties(((ReportServerProperties)(treeView.Tag)).ReportsServerInstance.Url); DataSourceDefinition dataSourceDefinition = reportServerProperties.GetDataSourceDefinition(treeView.SelectedNode.FullPath.Replace(treeView.Nodes[0].Text, string.Empty).Replace(@"\", "/")); using (var frmDataSourceDetail = new frmDataSourceDetail()) { string[] connectionString = dataSourceDefinition.ConnectString.Split(';'); foreach (string[] itemDict in connectionString.Select(item => item.Split('='))) { if (itemDict[0] == "Data Source") { frmDataSourceDetail.SQLServer = itemDict[1]; } if (itemDict[0] == "Initial Catalog") { frmDataSourceDetail.DBName = itemDict[1]; } } frmDataSourceDetail.DataSourceName = treeView.SelectedNode.Text; CatalogItem[] catalogItems = reportServerProperties.ReportsServerInstance.ListDependentItems(treeView.SelectedNode.FullPath.Replace(treeView.Nodes[0].Text, string.Empty).Replace(@"\", "/")); //frmDataSourceDetail.DependentItems = catalogItems.Select(catalogItem => string.Format("{0}{1}", catalogItem.Path, catalogItem.Name)).ToList(); if (frmDataSourceDetail.ShowDialog() == DialogResult.OK) { string folder = treeView.SelectedNode.FullPath.Replace(treeView.Nodes[0].Text, string.Empty).Replace(@"\", "/").Replace(treeView.SelectedNode.Text, string.Empty); if (ReportServerDestination.DeleteItem(ItemTypeEnum.DataSource, folder.Substring(0, folder.Length - 1), treeView.SelectedNode.Text) && ReportServerDestination.CreateDataSource(frmDataSourceDetail.DataSourceName, folder.Substring(0, folder.Length - 1), frmDataSourceDetail.SQLServer, frmDataSourceDetail.DBName)) { treeView.SelectedNode.Text = frmDataSourceDetail.DataSourceName; MessageBox.Show("DataSource modified succesfully"); } else { MessageBox.Show("DataSource WASN'T modified"); } } } }
private void CreateDatasource(object sender) { try { TreeView treeView = (TreeView)((ContextMenuStrip)((ToolStripMenuItem)sender).Owner).SourceControl; if ((ItemTypeEnum)(treeView.SelectedNode.Tag) == ItemTypeEnum.Folder) { using (var frmDataSourceDetail = new frmDataSourceDetail()) { if (frmDataSourceDetail.ShowDialog() == DialogResult.OK) { if (ReportServerDestination.CreateDataSource(frmDataSourceDetail.DataSourceName, treeView.SelectedNode.FullPath.Replace(treeView.Nodes[0].Text, string.Empty).Replace(@"\", "/"), frmDataSourceDetail.SQLServer, frmDataSourceDetail.DBName)) { MessageBox.Show(@"DataSource created succesfully"); treeView.SelectedNode.Nodes.Add(new TreeNode(treeView.SelectedNode.Text + @"/" + frmDataSourceDetail.DataSourceName, 1, 1) { Tag = ItemTypeEnum.DataSource }); treeView.SelectedNode.Expand(); } else { MessageBox.Show(@"DataSource WASN'T created"); } } } } else { MessageBox.Show(@"Please choose a folder"); } } catch (Exception exception) { MessageBox.Show(exception.Message); } }