void descButton_Click(object sender, EventArgs e) { try { Button b = (Button)sender; Form form = b.FindForm(); Control grid = (Control)form.Controls.Find("grid", true)[0]; System.Reflection.BindingFlags getflags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance; object selectionMgr = grid.GetType().BaseType.BaseType.InvokeMember("m_selMgr", getflags, null, grid, new object[] { }); long currentRow = (long)selectionMgr.GetType().InvokeMember("m_curRowIndex", getflags, null, selectionMgr, new object[] { }); getflags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance; bool singleRowSelected = (bool)selectionMgr.GetType().InvokeMember("SingleRowOrColumnSelectedInMultiSelectionMode", getflags, null, selectionMgr, new object[] { }); if (!singleRowSelected) { MessageBox.Show("Only one description can be edited at a time."); return; } getflags = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance; CalculationPropertyCollection calcs = (CalculationPropertyCollection)form.GetType().InvokeMember("GetResultProperties", getflags, null, form, new object[] { }); if (currentRow >= 0 && currentRow < calcs.Count) { string sDesc = calcs[(int)currentRow].Description; if (sDesc != null) { //normalize line breaks so they display well in the textbox sDesc = sDesc.Replace("\r\n", "\r").Replace("\n", "\r").Replace("\r", "\r\n"); } Form descForm = new Form(); descForm.Icon = BIDSHelper.Resources.Common.BIDSHelper; descForm.Text = "BIDS Helper Description Editor"; descForm.MaximizeBox = true; descForm.MinimizeBox = false; descForm.Width = 350; descForm.Height = 300; descForm.SizeGripStyle = SizeGripStyle.Show; descForm.MinimumSize = new System.Drawing.Size(descForm.Width, descForm.Height); TextBox textValue = new TextBox(); textValue.Text = sDesc; textValue.Top = 10; textValue.Left = 10; textValue.Width = descForm.Width - 30; textValue.ScrollBars = ScrollBars.Vertical; textValue.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom; textValue.Multiline = true; textValue.Height = descForm.Height - 95; descForm.Controls.Add(textValue); Button okButton = new Button(); okButton.Text = "OK"; okButton.Anchor = AnchorStyles.Right | AnchorStyles.Bottom; okButton.Left = descForm.Right - okButton.Width * 2 - 40; okButton.Top = descForm.Bottom - okButton.Height * 2 - 20; //descForm.AcceptButton = okButton; //don't want enter to cause this window to close because of multiline value textbox okButton.Click += new EventHandler(okButton_Click); descForm.Controls.Add(okButton); Button cancelButton = new Button(); cancelButton.Text = "Cancel"; cancelButton.Anchor = AnchorStyles.Right | AnchorStyles.Bottom; cancelButton.Left = okButton.Right + 10; cancelButton.Top = okButton.Top; descForm.CancelButton = cancelButton; descForm.Controls.Add(cancelButton); DialogResult result = descForm.ShowDialog(form); if (result == DialogResult.OK) { calcs[(int)currentRow].Description = textValue.Text; } descForm.Dispose(); } else { MessageBox.Show("You have selected an invalid row."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
void OpenCalcPropertiesDialog() { Form form1 = null; //should be a CalcPropertiesEditorForm which is private Cube cube = (Cube)this.ApplicationObject.ActiveWindow.ProjectItem.Object; System.IServiceProvider provider = (System.IServiceProvider) this.ApplicationObject.ActiveWindow.ProjectItem.ContainingProject; using (WaitCursor cursor1 = new WaitCursor()) { IUserPromptService oService = (IUserPromptService)provider.GetService(typeof(IUserPromptService)); foreach (Type t in System.Reflection.Assembly.GetAssembly(typeof(Microsoft.AnalysisServices.Design.Scripts)).GetTypes()) { if (t.FullName == "Microsoft.AnalysisServices.Design.Calculations.CalcPropertiesEditorForm") { form1 = (Form)t.GetConstructor(new Type[] { typeof(IUserPromptService) }).Invoke(new object[] { oService }); break; } } if (form1 == null) { throw new Exception("Couldn't create instance of CalcPropertiesEditorForm"); } object script1 = null; //should be a Microsoft.AnalysisServices.MdxCodeDom.MdxCodeScript object try { //validate the script because deploying an invalid script makes cube unusable Microsoft.AnalysisServices.Design.Scripts scripts = new Microsoft.AnalysisServices.Design.Scripts(cube); System.Reflection.BindingFlags getflags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance; script1 = scripts.GetType().InvokeMember("mdxCodeScript", getflags, null, scripts, null); } catch (Microsoft.AnalysisServices.Design.ScriptParsingFailed ex) { string throwaway = ex.Message; //prevents a warning during compile MessageBox.Show("MDX Script in " + cube.Name + " is not valid.", "Problem Deploying MDX Script"); return; } if (cube.MdxScripts.Count == 0) { MessageBox.Show("There is no MDX script defined in this cube yet."); return; } System.Reflection.BindingFlags getmethodflags = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance; form1.GetType().InvokeMember("Initialize", getmethodflags, null, form1, new object[] { cube.MdxScripts[0], script1, cube, null }); //now make custom changes to the form Button okButton = (Button)form1.Controls.Find("okButton", true)[0]; Panel panel = (Panel)form1.Controls.Find("gridPanel", true)[0]; Button descButton = new Button(); descButton.Text = "Edit Description"; descButton.Anchor = AnchorStyles.Left | AnchorStyles.Bottom; descButton.Left = panel.Left; descButton.Top = okButton.Top; descButton.Width += 40; descButton.Click += new EventHandler(descButton_Click); form1.Controls.Add(descButton); } if (Microsoft.DataWarehouse.DataWarehouseUtilities.ShowDialog(form1, provider) == DialogResult.OK) { using (WaitCursor cursor2 = new WaitCursor()) { System.Reflection.BindingFlags getflags = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance; CalculationPropertyCollection collection1 = (CalculationPropertyCollection)form1.GetType().InvokeMember("GetResultProperties", getflags, null, form1, new object[] { }); DesignerTransaction transaction1 = null; try { IDesignerHost host1 = (IDesignerHost)ApplicationObject.ActiveWindow.Object; transaction1 = host1.CreateTransaction("BidsHelperCalcPropertiesUndoBatchDesc"); IComponentChangeService service1 = (IComponentChangeService)ApplicationObject.ActiveWindow.Object; service1.OnComponentChanging(cube.MdxScripts[0].CalculationProperties, null); cube.MdxScripts[0].CalculationProperties.Clear(); for (int num1 = collection1.Count - 1; num1 >= 0; num1--) { CalculationProperty property1 = collection1[num1]; collection1.RemoveAt(num1); cube.MdxScripts[0].CalculationProperties.Insert(0, property1); } service1.OnComponentChanged(cube.MdxScripts[0].CalculationProperties, null, null, null); } catch (CheckoutException exception1) { if (transaction1 != null) { transaction1.Cancel(); } if (exception1 != CheckoutException.Canceled) { throw exception1; } } finally { if (transaction1 != null) { transaction1.Commit(); } } } } }