Ejemplo n.º 1
0
        private void lvEntities_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvEntities.SelectedItems.Count > 0)
            {
                string entityLogicalName = lvEntities.SelectedItems[0].Tag.ToString();

                Cursor = Cursors.WaitCursor;
                lvEmailTemplates.Items.Clear();

                WorkAsync(new WorkAsyncInfo
                {
                    Message       = "Loading emailTemplates...",
                    AsyncArgument = entityLogicalName,
                    Work          = (bw, evt) =>
                    {
                        evt.Result = EmailTemplateHelper.GetTemplatessByEntity(evt.Argument.ToString(), Service);
                    },
                    PostWorkCallBack = evt =>
                    {
                        if (evt.Error != null)
                        {
                            MessageBox.Show(this, "An error occured: " + evt.Error.Message, "Error",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                        }
                        else
                        {
                            Cursor        = Cursors.Default;
                            var templates = (EntityCollection)evt.Result;
                            foreach (var entity in templates.Entities)
                            {
                                string isPersonalStr = "False";
                                if (entity.Attributes.Contains("IsPersonal"))
                                {
                                    var ispersonal = (bool)entity.Attributes["IsPersonal"];
                                    isPersonalStr  = (ispersonal) ? "True" : "False";
                                }
                                ListViewItem lvi = new ListViewItem( );
                                lvi.Tag          = entity;
                                lvi.SubItems.Add(entity.GetAttributeValue <string>("title"));
                                lvi.SubItems.Add(isPersonalStr);
                                lvi.SubItems.Add(entity.GetAttributeValue <string>("description"));
                                lvEmailTemplates.Items.Add(lvi);
                            }
                        }
                    }
                });
            }
        }