ExceptionManageModel.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using AGV_WPF_Global;
  7. using AGV_WPF.Commands;
  8. using System.Data;
  9. namespace AGV_WPF.Models
  10. {
  11. public class ExceptionManageModel
  12. {
  13. public ExceptionManageModel(Window w)
  14. {
  15. exceptionManage = w as ExceptionManage;
  16. DeleteAllCommand = new DelegateCommand();
  17. DeleteAllCommand.ExecuteAction = new Action<object>(this.DeleteAll);
  18. LoadExType();
  19. }
  20. ExceptionManage exceptionManage;
  21. public bool IsManager
  22. {
  23. get
  24. {
  25. return GlobalPara.IsManager;
  26. }
  27. }
  28. public Visibility IsVisible
  29. {
  30. get
  31. {
  32. if (GlobalPara.IsManager)
  33. return Visibility.Visible;
  34. else
  35. return Visibility.Hidden;
  36. }
  37. }
  38. public DelegateCommand DeleteAllCommand { get; set; }
  39. public void DeleteAll(object parameter)
  40. {
  41. if (MessageBox.Show("确定要删除所有记录?", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
  42. return;
  43. DAL.ZSql sql1 = new DAL.ZSql();
  44. sql1.Open("delete from T_Ex");
  45. sql1.Close();
  46. }
  47. void LoadExType()
  48. {
  49. DAL.ZSql sql1 = new DAL.ZSql();
  50. sql1.Open("select distinct ExType from T_Ex");
  51. DataTable table = sql1.m_table;
  52. for (int i = 0; i < table.Rows.Count;i++ )
  53. {
  54. string str = table.Rows[i]["ExType"].ToString().Trim();
  55. exceptionManage.comboBoxExType.Items.Add(str);
  56. }
  57. //加载生产区
  58. sql1.Open("select distinct ExWorkLine from T_Ex order by ExWorkLine");
  59. table = sql1.m_table;
  60. for (int i = 0; i < table.Rows.Count;i++ )
  61. {
  62. string str = table.Rows[i]["ExWorkLine"].ToString().Trim();
  63. if(!string.IsNullOrEmpty(str))
  64. exceptionManage.comboBoxWorkLine.Items.Add(str);
  65. }
  66. exceptionManage.comboBoxExType.Items.Add("所有报警");
  67. sql1.Close();
  68. }
  69. /// <summary>
  70. /// 加载报警数据排行
  71. /// </summary>
  72. /// <param name="date">待排行日期,空串所有时间报警,否则为当前选定日期</param>
  73. /// <param name="type">对AGV哪种报警排行</param>
  74. /// <param name="kind">排行种类,可以是AGV,报警类型</param>
  75. /// <param name="workLine">生产区,只用于对站点的排行</param>
  76. /// <param name="carID">要排行的当前AGV编号</param>
  77. public void LoadRankData(string date, string type, string kind,string workLine,string carID)
  78. {
  79. DAL.ZSql sql1 = new DAL.ZSql();
  80. if (string.IsNullOrEmpty(date))//所有时间的报警
  81. {
  82. if (kind == "全部AGV")
  83. {
  84. if (type == "所有报警")
  85. {
  86. sql1.Open(string.Format("select CarID as AGV,count(CarID) as Counts from T_Ex group by CarID order by count(CarID) desc"));
  87. exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
  88. }
  89. else
  90. {
  91. sql1.Open(string.Format("select CarID as AGV,count(CarID) as Counts from T_Ex where ExType like '%{0}%'group by CarID order by count(CarID) desc", type));
  92. exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
  93. }
  94. }
  95. else if (kind == "报警类型")
  96. {
  97. sql1.Open(string.Format("select ExType as ExType,count(ExType) as Counts from T_Ex group by ExType order by count(ExType) desc"));
  98. exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
  99. }
  100. else if (kind == "站点" && !string.IsNullOrEmpty(workLine))
  101. {
  102. if (type == "所有报警")
  103. {
  104. sql1.Open(string.Format("select ExMarkNum as Station,count(ExMarkNum) as Counts from T_Ex where ExWorkLine={0} group by ExMarkNum order by count(ExMarkNum) desc",workLine));
  105. exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
  106. }
  107. else
  108. {
  109. sql1.Open(string.Format("select ExMarkNum as Station,count(ExMarkNum) as Counts from T_Ex where ExWorkLine={0} and ExType like '%{1}%' group by ExMarkNum order by count(ExMarkNum) desc", workLine,type));
  110. exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
  111. }
  112. }
  113. else if (kind == "当前AGV" && !string.IsNullOrEmpty(carID))
  114. {
  115. sql1.Open(string.Format("select ExType as ExType,count(ExType) as Counts from T_Ex where CarID={0} group by ExType order by count(ExType) desc",carID));
  116. exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
  117. }
  118. }
  119. else//选定日期
  120. {
  121. if (kind == "全部AGV")
  122. {
  123. if (type == "所有报警")
  124. {
  125. sql1.Open(string.Format("select CarID as AGV,count(CarID) as Counts from T_Ex where ExTimer like '%{0}%' group by CarID order by count(CarID) desc",date));
  126. exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
  127. }
  128. else
  129. {
  130. sql1.Open(string.Format("select CarID as AGV,count(CarID) as Counts from T_Ex where ExType like '%{0}%'and ExTimer like '%{1}%' group by CarID order by count(CarID) desc", type, date));
  131. exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
  132. }
  133. }
  134. else if (kind == "报警类型")
  135. {
  136. sql1.Open(string.Format("select ExType as ExType,count(ExType) as Counts from T_Ex where ExTimer like '%{0}%' group by ExType order by count(ExType) desc",date));
  137. exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
  138. }
  139. else if (kind == "站点" && !string.IsNullOrEmpty(workLine))
  140. {
  141. if (type == "所有报警")
  142. {
  143. sql1.Open(string.Format("select ExMarkNum as Station,count(ExMarkNum) as Counts from T_Ex where ExWorkLine={0} and ExTimer like '%{1}%' group by ExMarkNum order by count(ExMarkNum) desc", workLine,date));
  144. exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
  145. }
  146. else
  147. {
  148. sql1.Open(string.Format("select ExMarkNum as Station,count(ExMarkNum) as Counts from T_Ex where ExWorkLine={0} and ExType like '%{1}%' and ExTimer like '%{2}%' group by ExMarkNum order by count(ExMarkNum) desc", workLine, type,date));
  149. exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
  150. }
  151. }
  152. else if (kind == "当前AGV" && !string.IsNullOrEmpty(carID))
  153. {
  154. sql1.Open(string.Format("select ExType as ExType,count(ExType) as Counts from T_Ex where CarID={0} and ExTimer like '%{1}%'group by ExType order by count(ExType) desc", carID,date));
  155. exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
  156. }
  157. }
  158. sql1.Close();
  159. }
  160. }
  161. }