示例#1
0
        private void AddColorImage(CategoryModel category)
        {
            // initialize picturebox
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();

            

            //create image from colour
            Bitmap img = new Bitmap(WidthHeight, WidthHeight);
            Graphics g = Graphics.FromImage(img);
            SolidBrush brush = new SolidBrush(Color.FromArgb(128, category.Colour.R, category.Colour.G, category.Colour.B));
            g.FillRectangle(brush, 0, 0, WidthHeight, WidthHeight);

            // add category and color to dictionary
            this.CategoryColors.Add(category.Name, brush);

            //add image to picturebox
            this.pictureBox1.Image = img;

            // picture specifications
            this.pictureBox1.Location = new System.Drawing.Point(horizontally, vertically+20);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(WidthHeight,30);
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;

            // add picturebox
            this.Controls.Add(this.pictureBox1);

            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();

            //
            horizontally += 80;
        }
示例#2
0
        private void AddLabel(CategoryModel category)
        {
            // initialize label
            this.categoryLabel = new System.Windows.Forms.Label();

            // label specifications
            this.categoryLabel.AutoSize = true;
            this.categoryLabel.Location = new Point(horizontally,vertically);
            this.categoryLabel.Name = "categoryLabel";
            this.categoryLabel.Size = new System.Drawing.Size(WidthHeight, 15);
            this.categoryLabel.TabIndex = 0;
            this.categoryLabel.Text = category.Name;

            //add label
            this.Controls.Add(this.categoryLabel);
        }
 public void GetCategories_FromDatabase()
 {
     foreach (var category in this.DataSet.category)
     {
         var c1 = new CategoryModel(category.category_id, category.name, category.subcategory_of, category.color);
     }
 }
        public void AddCategory(string text, string color)
        {
            
            //Fill the TableAdapter with data from the dataset, select MAX category_ID, Create an in with MAX category_ID + 1
            var maxCategoryId = Dbc.DataSet.category.Select("category_id = MAX(category_id)");

            var newCategoryId = (int)maxCategoryId[0]["category_id"] + 1;

            // add the object
            var category = new CategoryModel(newCategoryId, text, -1, color);
            Console.WriteLine(newCategoryId);

            //add in the database

            //Create a newProductrow and fill the row for each corresponding column
            var newCategory = Dbc.DataSet.category.NewcategoryRow();
            newCategory.name =category.Name;
            newCategory.category_id = category.CatId;
            newCategory.removed = false;
            newCategory.subcategory_of = (int)category.IsSubcategoryFrom;
            newCategory.color = color;

            //Try to add the new product row in the database
            try
            {
                Dbc.DataSet.category.Rows.Add(newCategory);
                Dbc.CategoryTableAdapter.Update(Dbc.DataSet.category);
                MessageBox.Show("Update successful");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Update failed" + ex);
                category = null;
            }

        }
示例#5
0
 public void AddItemToScreen(CategoryModel category)
 {
     AddLabel(category);
     AddColorImage(category);
 }