123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using QRCoder;
- using Core.RabbitMQBus.Common;
- using Core.RabbitMQBus.EventBus;
- using Core.RabbitMQBus.Extensions;
- using Microsoft.Extensions.DependencyInjection;
- namespace WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- //Run();
- RenderQrCode();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- //Console.WriteLine("Hello World!");
- //IServiceCollection services = new ServiceCollection();
- //services.AddLogging();
- //services.AddTransient<ILoggerFactory, LoggerFactory>();
- //services.AddTransient<ITestService, TestService>();
- //services.RegisterRabbitMQ(e => new RabbitMQOptions() { HostName = "124.71.132.255" }); //localhost
- //services.RabbitMQRegisterSubscriber("RabbitMQBusTest", "Service");
- ////构建容器
- //IServiceProvider serviceProvider = services.BuildServiceProvider();
- //// 创建ConsoleLogProvider并根据日志类目名称(CategoryName)生成Logger实例
- ////解析
- //_rabbitMqPublisher = serviceProvider.GetService<IRabbitMqPublisher>();
- //Publisher();
- }
- //public void Publisher()
- //{
- // for (int i = 0; i < 10000; i++) //100000
- // {
- // Console.WriteLine("PublishTestCount:" + i);
- // _rabbitMqPublisher.Publish("PublishTest1", "测试" + i);
- // _rabbitMqPublisher.Publish("PublishTest2", "测试" + i);
- // }
- //}
- private void RenderQrCode()
- {
- string level = "Q";// comboBoxECC.SelectedItem.ToString();
- QRCodeGenerator.ECCLevel eccLevel = (QRCodeGenerator.ECCLevel)(level == "L" ? 0 : level == "M" ? 1 : level == "Q" ? 2 : 3);
- using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
- {
- using (QRCodeData qrCodeData = qrGenerator.CreateQrCode("9f3274ec-1481-4988-a3c8-698bbafbf14b", eccLevel))
- {
- using (QRCode qrCode = new QRCode(qrCodeData))
- {
- pictureBoxQRCode.BackgroundImage = qrCode.GetGraphic(20, Color.Black, Color.White,
- null, 50);
- this.pictureBoxQRCode.Size = new System.Drawing.Size(pictureBoxQRCode.Width, pictureBoxQRCode.Height);
- //Set the SizeMode to center the image.
- this.pictureBoxQRCode.SizeMode = PictureBoxSizeMode.CenterImage;
- pictureBoxQRCode.SizeMode = PictureBoxSizeMode.StretchImage;
- }
- }
- }
- }
- //private Bitmap GetIconBitmap()
- //{
- // Bitmap img = null;
- // if (iconPath.Text.Length > 0)
- // {
- // try
- // {
- // img = new Bitmap(iconPath.Text);
- // }
- // catch (Exception)
- // {
- // }
- // }
- // return img;
- //}
- //Linq对集合的各种查询
- public static void Run()
- {
- List<Customers> customerlist = new List<Customers>();
- customerlist.Add(new Customers() { id = 1, Name = "Jack", Custom = "Mis" });
- customerlist.Add(new Customers() { id = 2, Name = "Lus", Custom = "Google" });
- customerlist.Add(new Customers() { id = 3, Name = "Qiao", Custom = "Baidu" });
- customerlist.Add(new Customers() { id = 4, Name = "Qiao", Custom = "Apple" });
- customerlist.Add(new Customers() { id = 5, Name = "Adb", Custom = "Adobe" });
- //简单的查询
- var customerQuery = from query in customerlist
- select query;
- //带where筛选
- var customerWhereQuery = from query in customerlist
- where query.id == 1 && query.Name == "Lus"
- select query;
- //排序Ordering
- var customerOrderingQuery = from query in customerlist
- where query.Name == "Lus"
- orderby query.id ascending
- select query;
- //分组Group by
- var customerGroupbyQuery = from query in customerlist
- group query by query.Name;
- //可以使用into进一步查询
- var customerGroupbyIntoQuery = from query in customerlist
- group query by query.Name into queryGroup
- where queryGroup.Key == "Qiao"
- select queryGroup;
- foreach (IGrouping<string, Customers> group in customerlist.GroupBy(c => c.Name))
- {
- Customers model = new Customers();
- model.Name = group.Key;
- foreach (Customers stu in group.OrderBy(a => a.Name))
- {
- Console.Write(stu.Name + ";");
- }
- var customerList = group.OrderBy(a => a.Name).ToList();
- }
- //联接查询 join 子句始终针对对象集合而非直接针对数据库表运行。
- List<Customers> customerJoinlist = new List<Customers>();
- customerJoinlist.Add(new Customers() { id = 1, Name = "Jack", Custom = "Mis" });
- customerJoinlist.Add(new Customers() { id = 2, Name = "Lus", Custom = "Google" });
- customerJoinlist.Add(new Customers() { id = 3, Name = "Qiao", Custom = "Baidu" });
- var customerJoinQuery = from query1 in customerlist
- join query2 in customerJoinlist
- on query1.id equals query2.id
- select new { CustomerName = query1.Name, CustomerName2 = query2.Name };
- //数据源的类型参数始终为查询中的范围变量的类型。
- //比如List<Customers> 类型为Customers 在循环迭代的时候类型必须可以隐式转换为Customer 有一种情况是
- //这种情况下Customers类型转换为了String ..在select query.Name已经将查询目标类型定位了String类型
- var customerTypeQuery = from query in customerlist
- where query.Name == "Lus"
- select query.Name;
- //结合Lamdba对List集合筛选(s => s.Name == "Qiao")
- List<Customers> listString = customerlist.Where(s => s.Name == "Qiao").ToList();
- }
- }
- }
- public class Customers
- {
- public int id { get; set; }
- public string Name { get; set; }
- public string Custom { get; set; }
- }
- public interface ITestService
- {
- }
|