Form1.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using QRCoder;
  12. using Core.RabbitMQBus.Common;
  13. using Core.RabbitMQBus.EventBus;
  14. using Core.RabbitMQBus.Extensions;
  15. using Microsoft.Extensions.DependencyInjection;
  16. namespace WindowsFormsApp1
  17. {
  18. public partial class Form1 : Form
  19. {
  20. public Form1()
  21. {
  22. InitializeComponent();
  23. }
  24. private void button1_Click(object sender, EventArgs e)
  25. {
  26. //Run();
  27. RenderQrCode();
  28. }
  29. private void button2_Click(object sender, EventArgs e)
  30. {
  31. //Console.WriteLine("Hello World!");
  32. //IServiceCollection services = new ServiceCollection();
  33. //services.AddLogging();
  34. //services.AddTransient<ILoggerFactory, LoggerFactory>();
  35. //services.AddTransient<ITestService, TestService>();
  36. //services.RegisterRabbitMQ(e => new RabbitMQOptions() { HostName = "124.71.132.255" }); //localhost
  37. //services.RabbitMQRegisterSubscriber("RabbitMQBusTest", "Service");
  38. ////构建容器
  39. //IServiceProvider serviceProvider = services.BuildServiceProvider();
  40. //// 创建ConsoleLogProvider并根据日志类目名称(CategoryName)生成Logger实例
  41. ////解析
  42. //_rabbitMqPublisher = serviceProvider.GetService<IRabbitMqPublisher>();
  43. //Publisher();
  44. }
  45. //public void Publisher()
  46. //{
  47. // for (int i = 0; i < 10000; i++) //100000
  48. // {
  49. // Console.WriteLine("PublishTestCount:" + i);
  50. // _rabbitMqPublisher.Publish("PublishTest1", "测试" + i);
  51. // _rabbitMqPublisher.Publish("PublishTest2", "测试" + i);
  52. // }
  53. //}
  54. private void RenderQrCode()
  55. {
  56. string level = "Q";// comboBoxECC.SelectedItem.ToString();
  57. QRCodeGenerator.ECCLevel eccLevel = (QRCodeGenerator.ECCLevel)(level == "L" ? 0 : level == "M" ? 1 : level == "Q" ? 2 : 3);
  58. using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
  59. {
  60. using (QRCodeData qrCodeData = qrGenerator.CreateQrCode("9f3274ec-1481-4988-a3c8-698bbafbf14b", eccLevel))
  61. {
  62. using (QRCode qrCode = new QRCode(qrCodeData))
  63. {
  64. pictureBoxQRCode.BackgroundImage = qrCode.GetGraphic(20, Color.Black, Color.White,
  65. null, 50);
  66. this.pictureBoxQRCode.Size = new System.Drawing.Size(pictureBoxQRCode.Width, pictureBoxQRCode.Height);
  67. //Set the SizeMode to center the image.
  68. this.pictureBoxQRCode.SizeMode = PictureBoxSizeMode.CenterImage;
  69. pictureBoxQRCode.SizeMode = PictureBoxSizeMode.StretchImage;
  70. }
  71. }
  72. }
  73. }
  74. //private Bitmap GetIconBitmap()
  75. //{
  76. // Bitmap img = null;
  77. // if (iconPath.Text.Length > 0)
  78. // {
  79. // try
  80. // {
  81. // img = new Bitmap(iconPath.Text);
  82. // }
  83. // catch (Exception)
  84. // {
  85. // }
  86. // }
  87. // return img;
  88. //}
  89. //Linq对集合的各种查询
  90. public static void Run()
  91. {
  92. List<Customers> customerlist = new List<Customers>();
  93. customerlist.Add(new Customers() { id = 1, Name = "Jack", Custom = "Mis" });
  94. customerlist.Add(new Customers() { id = 2, Name = "Lus", Custom = "Google" });
  95. customerlist.Add(new Customers() { id = 3, Name = "Qiao", Custom = "Baidu" });
  96. customerlist.Add(new Customers() { id = 4, Name = "Qiao", Custom = "Apple" });
  97. customerlist.Add(new Customers() { id = 5, Name = "Adb", Custom = "Adobe" });
  98. //简单的查询
  99. var customerQuery = from query in customerlist
  100. select query;
  101. //带where筛选
  102. var customerWhereQuery = from query in customerlist
  103. where query.id == 1 && query.Name == "Lus"
  104. select query;
  105. //排序Ordering
  106. var customerOrderingQuery = from query in customerlist
  107. where query.Name == "Lus"
  108. orderby query.id ascending
  109. select query;
  110. //分组Group by
  111. var customerGroupbyQuery = from query in customerlist
  112. group query by query.Name;
  113. //可以使用into进一步查询
  114. var customerGroupbyIntoQuery = from query in customerlist
  115. group query by query.Name into queryGroup
  116. where queryGroup.Key == "Qiao"
  117. select queryGroup;
  118. foreach (IGrouping<string, Customers> group in customerlist.GroupBy(c => c.Name))
  119. {
  120. Customers model = new Customers();
  121. model.Name = group.Key;
  122. foreach (Customers stu in group.OrderBy(a => a.Name))
  123. {
  124. Console.Write(stu.Name + ";");
  125. }
  126. var customerList = group.OrderBy(a => a.Name).ToList();
  127. }
  128. //联接查询 join 子句始终针对对象集合而非直接针对数据库表运行。
  129. List<Customers> customerJoinlist = new List<Customers>();
  130. customerJoinlist.Add(new Customers() { id = 1, Name = "Jack", Custom = "Mis" });
  131. customerJoinlist.Add(new Customers() { id = 2, Name = "Lus", Custom = "Google" });
  132. customerJoinlist.Add(new Customers() { id = 3, Name = "Qiao", Custom = "Baidu" });
  133. var customerJoinQuery = from query1 in customerlist
  134. join query2 in customerJoinlist
  135. on query1.id equals query2.id
  136. select new { CustomerName = query1.Name, CustomerName2 = query2.Name };
  137. //数据源的类型参数始终为查询中的范围变量的类型。
  138. //比如List<Customers> 类型为Customers 在循环迭代的时候类型必须可以隐式转换为Customer 有一种情况是
  139. //这种情况下Customers类型转换为了String ..在select query.Name已经将查询目标类型定位了String类型
  140. var customerTypeQuery = from query in customerlist
  141. where query.Name == "Lus"
  142. select query.Name;
  143. //结合Lamdba对List集合筛选(s => s.Name == "Qiao")
  144. List<Customers> listString = customerlist.Where(s => s.Name == "Qiao").ToList();
  145. }
  146. }
  147. }
  148. public class Customers
  149. {
  150. public int id { get; set; }
  151. public string Name { get; set; }
  152. public string Custom { get; set; }
  153. }
  154. public interface ITestService
  155. {
  156. }