Esempio n. 1
0
        private void BtnAddItem_Click(object sender, EventArgs e)
        {
            ListMap listMap = (ListMap)((Control)sender).Tag;
            Panel   s       = new Panel();

            s.Tag = new object[] { Activator.CreateInstance(listMap.type), listMap };
            Item_Click(s, new EventArgs());
        }
Esempio n. 2
0
        public void LoadData()
        {
            listMap.Clear();
            List <object>   result = new List <object>();
            BinaryFormatter bf     = new BinaryFormatter();

            if (File.Exists(dbPath))
            {
                FileStream fsin = new FileStream(dbPath, FileMode.Open, FileAccess.Read, FileShare.None);
                try
                {
                    using (fsin)
                    {
                        object o = bf.Deserialize(fsin);
                        result = (List <object>)o;
                    }
                    foreach (object obj in result)
                    {
                        foreach (object o in (IEnumerable <object>)obj)
                        {
                            ListMap map = listMap.Find(s => s.type == o.GetType());
                            if (map != null)
                            {
                                map.list.Add(o);
                            }
                            else
                            {
                                map = new ListMap(new List <object>(), o);
                                map.list.Add(o);
                                listMap.Add(map);
                            }
                        }
                    }
                    MessageBox.Show("File loaded successfully!", "Success");
                }
                catch (Exception e)
                {
                    MessageBox.Show("An error has occured: " + e.Message, "Error");
                }
                if (dbPath.EndsWith(".dodb"))
                {
                    foreach (object o in typeList)
                    {
                        ListMap map = listMap.Find(s => s.type == o.GetType());
                        if (map == null)
                        {
                            map = new ListMap(new List <object>(), o);
                            listMap.Add(map);
                        }
                    }
                }
            }
            refreshDataSource();
        }
Esempio n. 3
0
        private void lbxListTypes_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListBox lbx = (ListBox)sender;

            if (lbx.Items.Count < 1 || lbx.SelectedItem == null || lbx.SelectedItem.ToString() == "")
            {
                return;
            }
            selectedList = (ListMap)lbxListTypes.SelectedItem;
            DisplayItems(selectedList);
        }
Esempio n. 4
0
        private void Item_Click(object sender, EventArgs e)
        {
            foreach (Control cntrl in flpItems.Controls)
            {
                if (cntrl is Panel)
                {
                    cntrl.BackColor = Color.FromArgb(25, 0, 0, 0);
                }
            }
            Control c = (Control)sender;

            object[] tag = (object[])c.Tag;
            c.BackColor = Color.FromArgb(25, Color.Gold);
            object  obj        = tag[0];
            ListMap mappedList = (ListMap)tag[1];

            flpDetails.Controls.Clear();
            foreach (var field in mappedList.fields)
            {
                Panel pnl = new Panel();
                pnl.Size        = new Size(flpDetails.Width - 25, 100);
                pnl.BorderStyle = BorderStyle.FixedSingle;
                pnl.AutoScroll  = true;
                Label labName = new Label();
                labName.Text      = field.Name;
                labName.AutoSize  = false;
                labName.Width     = pnl.Width - 6;
                labName.Left      = 3;
                labName.Top       = 1;
                labName.TextAlign = ContentAlignment.MiddleCenter;
                pnl.Controls.Add(labName);

                object[] pnlTag = new object[] { obj, field, new object() };

                object value;
                if (field.FieldType.IsEnum)
                {
                    ComboBox cbx = new ComboBox();
                    cbx.DropDownStyle = ComboBoxStyle.DropDownList;
                    int i = 0;
                    foreach (FieldInfo f in field.FieldType.GetFields())
                    {
                        if (i > 0)
                        {
                            cbx.Items.Add(f.Name);
                            if ((value = field.GetValue(obj)) != null)
                            {
                                if (f.Name == field.GetValue(obj).ToString())
                                {
                                    cbx.SelectedIndex = i - 1;
                                }
                            }
                        }
                        i++;
                    }
                    if (cbx.SelectedIndex == -1 && cbx.Items.Count > 0)
                    {
                        cbx.SelectedIndex = 0;
                    }
                    cbx.Width = pnl.Width - 6;
                    cbx.Top   = labName.Bottom + 5;
                    cbx.Left  = 3;
                    pnl.Controls.Add(cbx);
                    flpDetails.Controls.Add(pnl);
                    pnlTag[2] = Enum.Parse(field.FieldType, cbx.SelectedItem.ToString());
                    cbx.SelectedValueChanged += detailsField_ValueChanged;
                }
                else
                {
                    switch (field.FieldType.Name)
                    {
                    case "String":
                        TextBox txbString = new TextBox();
                        if ((value = field.GetValue(obj)) != null)
                        {
                            txbString.Text = value.ToString();
                        }
                        txbString.AutoSize  = false;
                        txbString.Width     = pnl.Width - 6;
                        txbString.Left      = 3;
                        txbString.Top       = labName.Bottom + 5;
                        txbString.TextAlign = HorizontalAlignment.Center;
                        pnl.Controls.Add(txbString);
                        flpDetails.Controls.Add(pnl);

                        pnlTag[2]              = txbString.Text;
                        txbString.TextChanged += detailsField_ValueChanged;
                        break;

                    case "Int32":
                        NumericUpDown nudInt = new NumericUpDown();
                        nudInt.Name    = "32";
                        nudInt.Maximum = Int32.MaxValue;
                        nudInt.Minimum = Int32.MinValue;
                        if ((value = field.GetValue(obj)) != null)
                        {
                            nudInt.Value = (Int32)field.GetValue(obj);
                        }
                        nudInt.AutoSize  = false;
                        nudInt.Width     = pnl.Width - 6;
                        nudInt.Left      = 3;
                        nudInt.Top       = labName.Bottom + 5;
                        nudInt.TextAlign = HorizontalAlignment.Center;
                        pnl.Controls.Add(nudInt);
                        flpDetails.Controls.Add(pnl);

                        pnlTag[2]            = Int32.Parse(nudInt.Value.ToString());
                        nudInt.ValueChanged += detailsField_ValueChanged;
                        break;

                    case "Int64":
                        NumericUpDown nudLong = new NumericUpDown();
                        nudLong.Name    = "64";
                        nudLong.Maximum = Int64.MaxValue;
                        nudLong.Minimum = Int64.MinValue;
                        if ((value = field.GetValue(obj)) != null)
                        {
                            nudLong.Value = (Int64)field.GetValue(obj);
                        }
                        nudLong.AutoSize  = false;
                        nudLong.Width     = pnl.Width - 6;
                        nudLong.Left      = 3;
                        nudLong.Top       = labName.Bottom + 5;
                        nudLong.TextAlign = HorizontalAlignment.Center;
                        pnl.Controls.Add(nudLong);
                        flpDetails.Controls.Add(pnl);

                        pnlTag[2]             = Int32.Parse(nudLong.Value.ToString());
                        nudLong.ValueChanged += detailsField_ValueChanged;
                        break;

                    case "Image":
                        PictureBox pbx = new PictureBox();
                        if ((value = field.GetValue(obj)) != null)
                        {
                            pbx.BackgroundImage = (Image)field.GetValue(obj);
                        }
                        pbx.BackColor             = Color.White;
                        pbx.BackgroundImageLayout = ImageLayout.Zoom;
                        pbx.Height = pbx.Width = pnl.Width - 6;
                        pbx.Top    = labName.Bottom + 5;
                        pbx.Left   = 3;
                        pbx.Click += detailsImagePbx_Click;

                        pnl.Controls.Add(pbx);
                        flpDetails.Controls.Add(pnl);

                        pnlTag[2] = pbx.BackgroundImage;
                        pbx.BackgroundImageChanged += detailsField_ValueChanged;
                        break;

                    case "List`1":
                        switch (field.FieldType.GenericTypeArguments.First().Name)
                        {
                        case "Image":
                            Button btnListImage = new Button();
                            btnListImage.Text   = "Edit List of " + field.FieldType.GenericTypeArguments.First().Name + "...";
                            btnListImage.Top    = labName.Bottom + 5;
                            btnListImage.Left   = 3;
                            btnListImage.Width  = pnl.Width - 6;
                            btnListImage.Click += BtnListImage_Click;
                            pnlTag[2]           = btnListImage;
                            pnl.Controls.Add(btnListImage);
                            flpDetails.Controls.Add(pnl);
                            break;

                        default:
                            Console.WriteLine(field.FieldType.GenericTypeArguments.First().Name + " type of List is not supported in flpDetails!");
                            break;
                        }
                        break;

                    default:
                        Console.WriteLine(field.FieldType.Name + " type is not supported in flpDetails!");
                        break;
                    }
                }
                pnl.Tag    = pnlTag;
                pnl.Height = pnl.PreferredSize.Height;
            }
            Button applyBtn = new Button();

            applyBtn.Text   = "Apply";
            applyBtn.Size   = new Size(flpDetails.Width - 25, 35);
            applyBtn.Tag    = tag;
            applyBtn.Click += ApplyBtn_Click;
            flpDetails.Controls.Add(applyBtn);

            Button removeBtn = new Button();

            removeBtn.Text   = "Remove";
            removeBtn.Size   = new Size(flpDetails.Width - 25, 35);
            removeBtn.Tag    = tag;
            removeBtn.Click += RemoveBtn_Click;
            flpDetails.Controls.Add(removeBtn);
        }
Esempio n. 5
0
        private void DisplayItems(ListMap mappedList)
        {
            int size = 160;

            flpItems.Controls.Clear();
            foreach (object obj in mappedList.list)
            {
                Panel pnl = new Panel();
                pnl.Width     = pnl.Height = size;
                pnl.BackColor = Color.FromArgb(25, 0, 0, 0);
                pnl.Tag       = new object[] { obj, mappedList };
                foreach (var field in mappedList.fields)
                {
                    try
                    {
                        switch (field.FieldType.Name)
                        {
                        case "String":
                            if (field.Name == "name")
                            {
                                Label labName = new Label();
                                labName.Text      = field.GetValue(obj).ToString();
                                labName.AutoSize  = false;
                                labName.Width     = pnl.Width - 2;
                                labName.Left      = 1;
                                labName.Top       = 1;
                                labName.TextAlign = ContentAlignment.MiddleCenter;
                                labName.BackColor = Color.FromArgb(175, Color.Black);
                                labName.ForeColor = Color.White;
                                pnl.Controls.Add(labName);
                            }
                            break;

                        case "Image":
                            pnl.BackgroundImage       = (Image)field.GetValue(obj);
                            pnl.BackgroundImageLayout = ImageLayout.Zoom;
                            break;

                        default:
                            Console.WriteLine(field.FieldType.Name + " type is not supported in flpItems!");
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                foreach (Control c in pnl.Controls)
                {
                    c.Tag    = new object[] { obj, mappedList };
                    c.Click += Item_Click;
                }
                pnl.Click += Item_Click;
                flpItems.Controls.Add(pnl);
            }

            Button btnAddItem = new Button();

            btnAddItem.Text      = "+";
            btnAddItem.Font      = new Font(btnAddItem.Font.FontFamily, 30);
            btnAddItem.TextAlign = ContentAlignment.MiddleCenter;
            btnAddItem.Anchor    = AnchorStyles.None;
            btnAddItem.Size      = new Size(size / 2, size / 2);
            btnAddItem.Margin    = new Padding(size / 4);
            btnAddItem.Click    += BtnAddItem_Click;
            btnAddItem.Tag       = mappedList;

            flpItems.Controls.Add(btnAddItem);
        }