private void lookUp_Click(object sender, EventArgs e) { if (null == onClickFunction) { return; } isProcessing = true; if (Start != null) { Start(this); } ClickFunction functions = new ClickFunction(); Type type = typeof(ClickFunction); MethodInfo method = type.GetMethod(onClickFunction); string[] lookUp = null; try { if (null == onClickFunctionParams && null == onClickGlobalDataParams) { lookUp = (string[])method.Invoke(functions, null); } else { string[] paramValues; if (null != onClickFunctionParams) { Control c = ((Button)sender).Parent.Parent.Parent.Parent.Parent; XmlDocument doc = ((XmlForm)c).GetShapeXml(); paramValues = new string[onClickFunctionParams.Length]; for (int i = 0; i < onClickFunctionParams.Length; ++i) { if (null != doc.DocumentElement[onClickFunctionParams[i]]) { paramValues[i] = doc.DocumentElement[onClickFunctionParams[i]].InnerText; } } } else { paramValues = new string[onClickGlobalDataParams.Length]; for (int i = 0; i < onClickGlobalDataParams.Length; ++i) { paramValues[i] = globalData[onClickGlobalDataParams[i]]; } } lookUp = (string[])method.Invoke(functions, paramValues); } } catch (Exception ex) { isProcessing = false; if (Stop != null) { Stop(this); } //_form.Hide(); if (null != ex.InnerException) { MessageBox.Show(null, ex.InnerException.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(null, "É necessário definir primeiro o produto composto.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } isProcessing = false; //_form.Hide(); if (Stop != null) { Stop(this); } string xml = WriteXml(lookUp); using (XmlForm form = new XmlForm()) { form.LoadDefinition("LookUp", null); form.Tag = this.FindForm().Tag; form.Design(""); form.SetShapeXml(xml); DialogResult result = form.ShowDialog(this); if (result == DialogResult.OK) { XmlDocument xdoc = form.GetShapeXml(); //valor selecionado na ListBox if (null != ((ListBox)form.Controls[1].Controls[0].Controls[0].Controls[0].Controls[5]).SelectedItem) { string text = ((ListBox)form.Controls[1].Controls[0].Controls[0].Controls[0].Controls[5]).SelectedItem.ToString(); if ("GetStates" != onClickFunction) { valueControl.Text = text; } else { string[] values = text.Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries); string temp = values[0].Substring(9); valueControl.Text = temp.Replace(" ", string.Empty); if (2 == values.Length) { ((Button)sender).Parent.Parent.Parent.Controls[0].Controls[0].Controls[1].Text = values[1].Substring(13); } } } } } }
private void lookUp_Click(object sender, EventArgs e) { if (null == onClickFunction) return; isProcessing = true; if (Start != null) Start(this); ClickFunction functions = new ClickFunction(); Type type = typeof(ClickFunction); MethodInfo method = type.GetMethod(onClickFunction); string[] lookUp = null; try { if (null == onClickFunctionParams && null == onClickGlobalDataParams) { lookUp = (string[])method.Invoke(functions, null); } else { string[] paramValues; if (null != onClickFunctionParams) { Control c = ((Button)sender).Parent.Parent.Parent.Parent.Parent; XmlDocument doc = ((XmlForm)c).GetShapeXml(); paramValues = new string[onClickFunctionParams.Length]; for (int i = 0; i < onClickFunctionParams.Length; ++i) { if (null != doc.DocumentElement[onClickFunctionParams[i]]) paramValues[i] = doc.DocumentElement[onClickFunctionParams[i]].InnerText; } } else { paramValues = new string[onClickGlobalDataParams.Length]; for (int i = 0; i < onClickGlobalDataParams.Length; ++i) { paramValues[i] = globalData[onClickGlobalDataParams[i]]; } } lookUp = (string[])method.Invoke(functions, paramValues); } } catch (Exception ex) { isProcessing = false; if (Stop != null) Stop(this); //_form.Hide(); if(null != ex.InnerException) MessageBox.Show(null, ex.InnerException.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); else MessageBox.Show(null, "É necessário definir primeiro o produto composto.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } isProcessing = false; //_form.Hide(); if (Stop != null) Stop(this); string xml = WriteXml(lookUp); using (XmlForm form = new XmlForm()) { form.LoadDefinition("LookUp", null); form.Tag = this.FindForm().Tag; form.Design(""); form.SetShapeXml(xml); DialogResult result = form.ShowDialog(this); if (result == DialogResult.OK) { XmlDocument xdoc = form.GetShapeXml(); //valor selecionado na ListBox if (null != ((ListBox)form.Controls[1].Controls[0].Controls[0].Controls[0].Controls[5]).SelectedItem) { string text = ((ListBox)form.Controls[1].Controls[0].Controls[0].Controls[0].Controls[5]).SelectedItem.ToString(); if ("GetStates" != onClickFunction) { valueControl.Text = text; } else { string[] values = text.Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries); string temp = values[0].Substring(9); valueControl.Text = temp.Replace(" ", string.Empty); if (2 == values.Length) { ((Button)sender).Parent.Parent.Parent.Controls[0].Controls[0].Controls[1].Text = values[1].Substring(13); } } } } } }