コード例 #1
0
        protected void product_Click(object sender, EventArgs e)
        {
            Control myPanel = sender as Control;
            Control d       = Class_functions.FindControlByName("id", (Panel)myPanel);

            if (d != null)
            {
                try
                {
                    id_product_to_modify = int.Parse(d.Text);
                    change_product_selected();
                    //MessageBox.Show(id_product_to_modify.ToString());
                }catch (Exception ec)
                {
                    MessageBox.Show(ec.ToString());
                }
            }
        }
コード例 #2
0
        public void add_items_products()
        {
            Class_functions.empty_control(products);


            Database.connecter();
            String        query   = "select distinct id,name from Categories";
            SqlCommand    command = new SqlCommand(query, Database.Con);
            SqlDataReader reader  = command.ExecuteReader();

            while (reader.Read())
            {
                int     id_cat   = (int)reader[0];
                String  cat_name = (string)reader[1];
                TabPage x        = new TabPage(cat_name);
                products.TabPages.Add(x);
                FlowLayoutPanel f             = new FlowLayoutPanel();
                string          query_items   = "select id,name,img,barcode,price from products where cat_id = @c";
                SqlCommand      command_items = new SqlCommand(query_items, Database.Con);

                command_items.Parameters.Add("@c", SqlDbType.Int);
                command_items.Parameters["@c"].Value = id_cat;

                SqlDataReader r = command_items.ExecuteReader();

                while (r.Read())
                {
                    int    item_id   = (int)r[0];
                    string item_name = (string)r[1];



                    Byte[] data = new Byte[0];
                    data = (Byte[])(r[2]);
                    MemoryStream mem = new MemoryStream(data);


                    Panel v = new Panel();
                    v.Size   = new System.Drawing.Size(95, 95);
                    v.Click += new EventHandler(product_Click);
                    PictureBox img = new PictureBox();
                    img.Image    = Image.FromStream(mem);
                    img.Size     = new System.Drawing.Size(64, 64);
                    img.SizeMode = PictureBoxSizeMode.StretchImage;
                    img.Click   += new EventHandler(c_product_Click);
                    v.Controls.Add(img);

                    TextBox t = new TextBox();
                    t.Text    = item_id.ToString();
                    t.Name    = "id";
                    t.Visible = false;
                    v.Controls.Add(t);
                    Label l = new Label()
                    {
                        AutoSize  = false,
                        TextAlign = ContentAlignment.MiddleCenter,
                        //Dock = DockStyle.Fill,
                    };
                    l.Click    += new EventHandler(c_product_Click);
                    l.Text      = item_name;
                    l.Location  = new Point(0, 70);
                    l.BackColor = System.Drawing.ColorTranslator.FromHtml("#34495e");
                    l.ForeColor = System.Drawing.ColorTranslator.FromHtml("#ecf0f1");
                    l.Font      = new Font("Arial", 9, FontStyle.Bold);
                    v.Controls.Add(l);
                    v.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    f.Controls.Add(v);
                }
                //f.Size = new System.Drawing.Size(830, 5000);
                f.Dock         = DockStyle.Fill;
                x.AutoScroll   = true;
                f.WrapContents = true;
                f.AutoScroll   = true;
                x.Controls.Add(f);
            }
            Database.disconnect();
        }