Example #1
0
        private void BtnMapClick(object sender, EventArgs e)
        {
            if (listViewEntities.SelectedItems.Count > 0 &&
                (listViewWebRessources16.SelectedItems.Count > 0 || listViewWebRessources32.SelectedItems.Count > 0 ||
                 listViewWebRessourcesOther.SelectedItems.Count > 0))
            {
                var selectedEntity = (EntityMetadata)listViewEntities.SelectedItems[0].Tag;

                var mapping = new EntityImageMap {
                    Entity = selectedEntity
                };

                if (listViewWebRessources16.SelectedItems.Count > 0)
                {
                    mapping.WebResourceName = ((Entity)listViewWebRessources16.SelectedItems[0].Tag)["name"].ToString();
                    mapping.ImageSize       = 16;
                }
                else if (listViewWebRessources32.SelectedItems.Count > 0)
                {
                    mapping.WebResourceName = ((Entity)listViewWebRessources32.SelectedItems[0].Tag)["name"].ToString();
                    mapping.ImageSize       = 32;
                }
                else
                {
                    mapping.WebResourceName =
                        ((WebResourcesManager.WebResourceAndImage)listViewWebRessourcesOther.SelectedItems[0].Tag)
                        .Webresource["name"].ToString();

                    var issDialog = new ImageSizeSelectionDialog {
                        StartPosition = FormStartPosition.CenterParent
                    };
                    if (issDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        mapping.ImageSize = issDialog.ImageSizeSelected;
                    }
                    else
                    {
                        return;
                    }
                }

                var item = new ListViewItem(
                    ((EntityMetadata)listViewEntities.SelectedItems[0].Tag).DisplayName.UserLocalizedLabel.Label)
                {
                    Tag = mapping
                };
                item.SubItems.Add(mapping.ImageSize + "x" + mapping.ImageSize);
                item.SubItems.Add(mapping.WebResourceName);

                foreach (ListViewItem existingItem in lvMappings.Items)
                {
                    if (existingItem.Text == item.Text &&
                        existingItem.SubItems[1].Text == item.SubItems[1].Text)
                    {
                        MessageBox.Show(this, "There is already a mapping for this entity and this size", "Warning",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }


                lvMappings.Items.Add(item);
            }
            else
            {
                MessageBox.Show(this, "Please select at least one entity and one image", "Warning", MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
            }
        }
Example #2
0
        private void BtnMapClick(object sender, EventArgs e)
        {
            if (listViewEntities.SelectedItems.Count > 0 &&
                (listViewWebRessources16.SelectedItems.Count > 0 || listViewWebRessources32.SelectedItems.Count > 0 ||
                 listViewWebRessourcesOther.SelectedItems.Count > 0))
            {
                var selectedEntity = (EntityMetadata) listViewEntities.SelectedItems[0].Tag;

                var mapping = new EntityImageMap {Entity = selectedEntity};

                if (listViewWebRessources16.SelectedItems.Count > 0)
                {
                    mapping.WebResourceName = ((Entity) listViewWebRessources16.SelectedItems[0].Tag)["name"].ToString();
                    mapping.ImageSize = 16;
                }
                else if (listViewWebRessources32.SelectedItems.Count > 0)
                {
                    mapping.WebResourceName = ((Entity) listViewWebRessources32.SelectedItems[0].Tag)["name"].ToString();
                    mapping.ImageSize = 32;
                }
                else
                {
                    mapping.WebResourceName =
                        ((WebResourcesManager.WebResourceAndImage) listViewWebRessourcesOther.SelectedItems[0].Tag)
                            .Webresource["name"].ToString();

                    var issDialog = new ImageSizeSelectionDialog {StartPosition = FormStartPosition.CenterParent};
                    if (issDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        mapping.ImageSize = issDialog.ImageSizeSelected;
                    }
                    else
                    {
                        return;
                    }
                }

                var item = new ListViewItem(
                    ((EntityMetadata) listViewEntities.SelectedItems[0].Tag).DisplayName.UserLocalizedLabel.Label)
                {
                    Tag = mapping
                };
                item.SubItems.Add(mapping.ImageSize + "x" + mapping.ImageSize);
                item.SubItems.Add(mapping.WebResourceName);

                foreach (ListViewItem existingItem in lvMappings.Items)
                {
                    if (existingItem.Text == item.Text
                        && existingItem.SubItems[1].Text == item.SubItems[1].Text)
                    {
                        MessageBox.Show(this, "There is already a mapping for this entity and this size", "Warning",
                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                }

                lvMappings.Items.Add(item);
            }
            else
            {
                MessageBox.Show(this, "Please select at least one entity and one image", "Warning", MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
            }
        }