FormManager.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace СУБД_Альфапол
  13. {
  14. public partial class FormManager : Form
  15. {
  16. public FormManager()
  17. {
  18. InitializeComponent();
  19. }
  20. void FillPartner()
  21. {
  22. SqlConnection conection = new SqlConnection(FormAuthorizathion.txtcon);
  23. conection.Open();
  24. string additional = $"Where (Namepartner like '{tbxSearch.Text}%' or Surname like '{tbxSearch.Text}%') ";//условие поиска
  25. if (cbxRatingSearch.Checked && tbxMinR.Text !="" && tbxMaxR.Text != "")
  26. {
  27. try
  28. {
  29. additional += $" and Rating >='{int.Parse(tbxMinR.Text)}' and Rating <='{int.Parse(tbxMaxR.Text)}'";
  30. }
  31. catch { return; }//на случай если рейтинг не число
  32. }
  33. string query = @"SELECT distinct partner.IDPartner ,partner.Namepartner, TypePartner.TypePartner, Partner.Surname, Partner.Name, Partner.Patronomyc, Partner.Phone, Partner.Rating,
  34. (SELECT sum(CountProduct) FROM PartnerProducts where IDPartner = partner.IDPartner group by IDPartner) as countsales
  35. FROM Partner INNER JOIN
  36. TypePartner ON Partner.IDTypePartner = TypePartner.IDTypePartner INNER JOIN
  37. PartnerProducts ON Partner.IDPartner = PartnerProducts.IDPartner " + additional;
  38. SqlCommand command = new SqlCommand(query, conection);
  39. SqlDataReader res;
  40. try
  41. {
  42. res = command.ExecuteReader();
  43. }
  44. catch { dgvPartner.Rows.Clear(); tbxMinR.Text = ""; tbxMaxR.Text = ""; return; }
  45. dgvPartner.Rows.Clear();
  46. while (res.Read())
  47. {
  48. string info = $@"{res["TypePartner"]}| {res["NamePartner"]}
  49. {res["Surname"]} {res["Name"]} {res["Patronomyc"]}
  50. {res["Phone"]}
  51. Рейтинг: {res["Rating"]}";
  52. string proc = "0%";
  53. int countSales = int.Parse(res["countsales"].ToString());
  54. try
  55. {
  56. if (countSales < 10000)
  57. {
  58. proc = "0%";
  59. }
  60. else if (countSales <= 50000 && countSales> 10000)
  61. {
  62. proc = "5%";
  63. }
  64. else if (countSales < 300000 && countSales >= 50000)
  65. {
  66. proc = "10%";
  67. }
  68. else
  69. {
  70. proc = "15%";
  71. }
  72. }
  73. catch { }
  74. dgvPartner.Rows.Add(res["IDPartner"], info,proc);
  75. if (proc == "0%")
  76. {
  77. dgvPartner.Rows[dgvPartner.RowCount-1].DefaultCellStyle.BackColor = Color.Orange;
  78. }
  79. if (proc == "15%")
  80. {
  81. dgvPartner.Rows[dgvPartner.RowCount - 1].DefaultCellStyle.BackColor = Color.DarkRed;
  82. }
  83. if (proc == "10%")
  84. {
  85. dgvPartner.Rows[dgvPartner.RowCount - 1].DefaultCellStyle.BackColor = Color.Green;
  86. }
  87. if (proc == "5%")
  88. {
  89. dgvPartner.Rows[dgvPartner.RowCount - 1].DefaultCellStyle.BackColor = Color.Yellow;
  90. }
  91. }
  92. //try
  93. //{
  94. //}
  95. //finally
  96. //{
  97. // res.Close();
  98. //}
  99. conection.Close();
  100. }
  101. private void FormManager_Load(object sender, EventArgs e)
  102. {
  103. // TODO: This line of code loads data into the 'alfafloorGDVDataSet1.Type4Filter' table. You can move, or remove it, as needed.
  104. this.type4FilterTableAdapter.Fill(this.alfafloorGDVDataSet1.Type4Filter);
  105. // TODO: This line of code loads data into the 'alfafloorGDVDataSet1.Manager' table. You can move, or remove it, as needed.
  106. this.managerTableAdapter.Fill(this.alfafloorGDVDataSet1.Manager);
  107. try
  108. {
  109. pbxProfile.Image = Image.FromFile(Application.StartupPath + "\\profilepic\\" + lblphoto.Text);
  110. }
  111. catch
  112. {
  113. MessageBox.Show("Фото менеджера отсутствует в папке", "Внимание",MessageBoxButtons.OK,MessageBoxIcon.Information);
  114. }
  115. lblphoto.Hide();
  116. FillPartner();
  117. }
  118. private void btnExit_Click(object sender, EventArgs e)
  119. {
  120. this.Close();
  121. }
  122. private void tbxSearch_TextChanged(object sender, EventArgs e)
  123. {
  124. FillPartner();
  125. }
  126. private void cbxRatingSearch_CheckedChanged(object sender, EventArgs e)
  127. {
  128. if (cbxRatingSearch.Checked)
  129. {
  130. FillPartner();
  131. }
  132. FillPartner();
  133. }
  134. }
  135. }