| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace Агенты
- {
- public partial class MainForm : Form
- {
- class ItemPanel : Panel
- {
- public System.Windows.Forms.PictureBox PbxLogo;
- public System.Windows.Forms.Label LblPhone;
- public System.Windows.Forms.Label LblTitle;
- public string ID;
- public ItemPanel()
- {
- this.PbxLogo = new System.Windows.Forms.PictureBox();
- this.LblTitle = new System.Windows.Forms.Label();
- this.LblPhone = new System.Windows.Forms.Label();
- //
- // panel1
- //
- this.BackColor = System.Drawing.Color.White;
- this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.Controls.Add(this.LblPhone);
- this.Controls.Add(this.LblTitle);
- this.Controls.Add(this.PbxLogo);
- this.Location = new System.Drawing.Point(76, 43);
- this.Name = "panel1";
- this.Size = new System.Drawing.Size(296, 200);
- this.TabIndex = 0;
- //
- // PbxLogo
- //
- this.PbxLogo.Location = new System.Drawing.Point(13, 18);
- this.PbxLogo.Name = "PbxLogo";
- this.PbxLogo.Size = new System.Drawing.Size(119, 120);
- this.PbxLogo.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
- this.PbxLogo.TabIndex = 0;
- this.PbxLogo.TabStop = false;
- //
- // LblTitle
- //
- this.LblTitle.AutoSize = true;
- this.LblTitle.Location = new System.Drawing.Point(13, 145);
- this.LblTitle.Name = "LblTitle";
- this.LblTitle.Size = new System.Drawing.Size(46, 17);
- this.LblTitle.TabIndex = 1;
- this.LblTitle.Text = "label1";
- //
- // LblPhone
- //
- this.LblPhone.AutoSize = true;
- this.LblPhone.Location = new System.Drawing.Point(13, 171);
- this.LblPhone.Name = "LblPhone";
- this.LblPhone.Size = new System.Drawing.Size(46, 17);
- this.LblPhone.TabIndex = 2;
- this.LblPhone.Text = "label2";
- }
- }
- public MainForm()
- {
- InitializeComponent();
- }
- string TxtCon = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\agent1.mdf;Integrated Security=True;Connect Timeout=30";
- struct Agent
- {
- // название, адрес, телефон, логотип
- public string ID, Title, Address, Phone, Logo;
- }
- List<Agent> LstAgent = new List<Agent>();
- ItemPanel CurrentItem;
- void GetDateFromDB()
- {
- //SqlConnection Con = new SqlConnection(TxtCon);
- //Con.Open();
- //string TxtQuery = "SELECT ID, Title, Address, Phone, Logo FROM Agent";
- //SqlCommand Query = new SqlCommand(TxtQuery, Con);
- //SqlDataReader Res = Query.ExecuteReader();
- //LstAgent.Clear();
- //while (Res.Read())
- //{
- // Agent Agent1 = new Agent();
- // Agent1.Title = Res["Title"].ToString(); // название
- // Agent1.Address = Res["Address"].ToString(); // адрес
- // Agent1.Phone = Res["Phone"].ToString(); // телефон
- // Agent1.Logo = Res["Logo"].ToString(); // логотип
- // Agent1.ID = Res["ID"].ToString();
- // LstAgent.Add(Agent1);
- //}
- //Con.Close();
- string[] Titles= new string[] {"Ковалев", "Бонда", "Кривошеев", "Лебедкин"};
- string[] Addresses = new string[] { "Новозыбков", "Брянск", "Москва", "Париж" };
- string[] Phones = new string[] { "3-15-24", "+8(48343)336985", "+375(940)45225621", "0-00-012" };
- string[] Logos = new string[] { "agent_1.png", "agent_2.png", "agent_3.png", "agent_4.png", "agent_5.png", "agent_6.png", "agent_7.png" };
- LstAgent.Clear();
- Random rnd = new Random();
- for (int i=0; i<20; i++)
- {
- Agent Agent1 = new Agent();
- Agent1.Title = Titles[rnd.Next(0, Titles.Length)]; // название
- Agent1.Address = Addresses[rnd.Next(0, Addresses.Length)];
- Agent1.Phone = Phones[rnd.Next(0, Phones.Length)];
- Agent1.Logo = Logos[rnd.Next(0, Logos.Length)]; //
- LstAgent.Add(Agent1);
- }
- }
- void FillPanel()
- {
- MainPanel.Controls.Clear();
- foreach(Agent Agent1 in LstAgent)
- {
- ItemPanel Item = new ItemPanel();
- Item.LblTitle.Text = Agent1.Title;
- Item.LblPhone.Text = Agent1.Phone;
- Item.ID = Agent1.ID;
- try
- {
- Item.PbxLogo.Image = Image.FromFile(Application.StartupPath + "\\agents\\" + Agent1.Logo);
- }
- catch
- {
- Item.PbxLogo.Image = Image.FromFile(Application.StartupPath + "\\agents\\picture.png");
- }
- MainPanel.Controls.Add(Item);
- Item.Click += Item_Click;
- Item.PbxLogo.Click += Object_Click;
- Item.LblTitle.Click += Object_Click;
- Item.LblPhone.Click += Object_Click;
- if (MainPanel.Controls.Count == 1)
- {
- CurrentItem = Item;
- CurrentItem.BackColor = Color.LightGreen;
- }
- }
- }
- private void Object_Click(object sender, EventArgs e)
- {
- CurrentItem.BackColor = Color.White;
- CurrentItem = (sender as Control).Parent as ItemPanel;
- CurrentItem.BackColor = Color.LightGreen;
- }
- private void Item_Click(object sender, EventArgs e)
- {
- CurrentItem.BackColor = Color.White;
- CurrentItem = sender as ItemPanel;
- CurrentItem.BackColor = Color.LightGreen;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- GetDateFromDB();
- FillPanel();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- //MessageBox.Show(CurrentItem.ID);
- GetDateFromDB();
- FillPanel();
- }
- }
- }
|