Exemple #1
0
        private void LoadForms()
        {
            // Clear listviews
            lvForms.Items.Clear();
            lvParameters.Items.Clear();

            SetState(true);

            WorkAsync(new WorkAsyncInfo
            {
                Message = "Loading forms...",
                Work    = (bw, e) =>
                {
                    IEnumerable <CrmForm> forms = CrmForm.GetForms(Service, bw);
                    var items = new List <ListViewItem>();

                    foreach (var form in forms)
                    {
                        var item = new ListViewItem(form.Name);
                        item.SubItems.Add(form.EntityLogicalName);
                        item.SubItems.Add((form.Parameters.Count > 0).ToString());
                        item.Tag = form;

                        items.Add(item);
                    }

                    e.Result = items;
                },
                PostWorkCallBack = e =>
                {
                    if (e.Error != null)
                    {
                        MessageBox.Show(this, e.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        lvForms.Items.AddRange(((List <ListViewItem>)e.Result).ToArray());
                    }

                    SetState(false);
                },
                ProgressChanged = e => { SetWorkingMessage(e.UserState.ToString()); }
            });
        }
Exemple #2
0
        private void tsbDeleteParameters_Click(object sender, EventArgs e)
        {
            if (lvParameters.SelectedItems.Count == 0)
            {
                MessageBox.Show(this, "Please select a parameter", "Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            SetState(true);

            WorkAsync("Deleting attribute(s)...",
                      (bw, evt) =>
            {
                var lvItems      = (ListView.SelectedListViewItemCollection)((object[])evt.Argument)[0];
                var formsUpdated = new List <CrmForm>();


                foreach (ListViewItem item in lvItems)
                {
                    var parameter = (FormParameter)item.Tag;

                    // Deleting attribute on form
                    parameter.ParentForm.RemoveParameter(parameter);

                    if (!formsUpdated.Contains(parameter.ParentForm))
                    {
                        formsUpdated.Add(parameter.ParentForm);
                    }
                }

                // Updating form
                foreach (var form in formsUpdated)
                {
                    form.UpdateForm(Service);
                }

                bw.ReportProgress(0, "Publishing form(s)...");

                // Publishing form
                CrmForm.PublishForms(Service, formsUpdated.Select(f => f.EntityLogicalName));

                evt.Result = formsUpdated;
            },
                      evt =>
            {
                if (evt.Error != null)
                {
                    MessageBox.Show(this, evt.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    foreach (var form in (List <CrmForm>)evt.Result)
                    {
                        foreach (ListViewItem item in lvForms.Items)
                        {
                            if (((CrmForm)item.Tag).Id == form.Id)
                            {
                                item.SubItems[2].Text = (form.Parameters.Count > 0).ToString();
                            }
                        }
                    }

                    lvForms_ItemChecked(null, null);
                }

                SetState(false);
            },
                      evt => SetWorkingMessage(evt.UserState.ToString()),
                      new object[] { lvParameters.SelectedItems });
        }
Exemple #3
0
        private void tsbCreateNewParameter_Click(object sender, EventArgs e)
        {
            if (lvForms.CheckedItems.Count == 0)
            {
                MessageBox.Show(this, "Please select a form before creating a parameter", "Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var pForm = new ParameterForm(Service);

            if (pForm.ShowDialog(this) == DialogResult.OK)
            {
                SetState(true);

                WorkAsync("Creating attribute...",
                          (bw, evt) =>
                {
                    var parameter    = (FormParameter)((object[])evt.Argument)[0];
                    var lvItems      = (ListView.CheckedListViewItemCollection)((object[])evt.Argument)[1];
                    var formsUpdated = new List <CrmForm>();

                    foreach (ListViewItem item in lvItems)
                    {
                        var crmForm = (CrmForm)item.Tag;

                        // Creating attribute on form
                        crmForm.AddParameter(parameter);

                        // Updating form
                        crmForm.UpdateForm(Service);

                        item.Tag = crmForm;

                        formsUpdated.Add(crmForm);
                    }

                    // Publishing form
                    bw.ReportProgress(0, "Publishing form(s) ...");
                    CrmForm.PublishForms(Service, formsUpdated.Select(f => f.EntityLogicalName));

                    evt.Result = lvItems;
                },
                          evt =>
                {
                    if (evt.Error != null)
                    {
                        MessageBox.Show(this, evt.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        var lvItems = (ListView.CheckedListViewItemCollection)evt.Result;
                        foreach (ListViewItem item in lvItems)
                        {
                            item.SubItems[2].Text = (((CrmForm)item.Tag).Parameters.Count > 0).ToString();
                        }

                        lvForms_ItemChecked(null, null);
                    }

                    SetState(false);
                },
                          evt => SetWorkingMessage(evt.UserState.ToString()),
                          new object[] { pForm.Parameter, lvForms.CheckedItems });
            }
        }