123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using AGV_WPF_Global;
- using AGV_WPF.Commands;
- using System.Data;
- namespace AGV_WPF.Models
- {
- public class ExceptionManageModel
- {
- public ExceptionManageModel(Window w)
- {
- exceptionManage = w as ExceptionManage;
- DeleteAllCommand = new DelegateCommand();
- DeleteAllCommand.ExecuteAction = new Action<object>(this.DeleteAll);
- LoadExType();
- }
- ExceptionManage exceptionManage;
- public bool IsManager
- {
- get
- {
- return GlobalPara.IsManager;
- }
- }
- public Visibility IsVisible
- {
- get
- {
- if (GlobalPara.IsManager)
- return Visibility.Visible;
- else
- return Visibility.Hidden;
- }
- }
- public DelegateCommand DeleteAllCommand { get; set; }
- public void DeleteAll(object parameter)
- {
- if (MessageBox.Show("确定要删除所有记录?", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
- return;
- DAL.ZSql sql1 = new DAL.ZSql();
- sql1.Open("delete from T_Ex");
- sql1.Close();
- }
- void LoadExType()
- {
- DAL.ZSql sql1 = new DAL.ZSql();
- sql1.Open("select distinct ExType from T_Ex");
- DataTable table = sql1.m_table;
- for (int i = 0; i < table.Rows.Count;i++ )
- {
- string str = table.Rows[i]["ExType"].ToString().Trim();
- exceptionManage.comboBoxExType.Items.Add(str);
- }
- //加载生产区
- sql1.Open("select distinct ExWorkLine from T_Ex order by ExWorkLine");
- table = sql1.m_table;
- for (int i = 0; i < table.Rows.Count;i++ )
- {
- string str = table.Rows[i]["ExWorkLine"].ToString().Trim();
- if(!string.IsNullOrEmpty(str))
- exceptionManage.comboBoxWorkLine.Items.Add(str);
- }
- exceptionManage.comboBoxExType.Items.Add("所有报警");
- sql1.Close();
- }
- /// <summary>
- /// 加载报警数据排行
- /// </summary>
- /// <param name="date">待排行日期,空串所有时间报警,否则为当前选定日期</param>
- /// <param name="type">对AGV哪种报警排行</param>
- /// <param name="kind">排行种类,可以是AGV,报警类型</param>
- /// <param name="workLine">生产区,只用于对站点的排行</param>
- /// <param name="carID">要排行的当前AGV编号</param>
- public void LoadRankData(string date, string type, string kind,string workLine,string carID)
- {
- DAL.ZSql sql1 = new DAL.ZSql();
- if (string.IsNullOrEmpty(date))//所有时间的报警
- {
- if (kind == "全部AGV")
- {
- if (type == "所有报警")
- {
- sql1.Open(string.Format("select CarID as AGV,count(CarID) as Counts from T_Ex group by CarID order by count(CarID) desc"));
- exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
- }
- else
- {
- 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));
- exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
- }
- }
- else if (kind == "报警类型")
- {
- sql1.Open(string.Format("select ExType as ExType,count(ExType) as Counts from T_Ex group by ExType order by count(ExType) desc"));
- exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
- }
- else if (kind == "站点" && !string.IsNullOrEmpty(workLine))
- {
- if (type == "所有报警")
- {
- 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));
- exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
- }
- else
- {
- 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));
- exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
- }
- }
- else if (kind == "当前AGV" && !string.IsNullOrEmpty(carID))
- {
- 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));
- exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
- }
- }
- else//选定日期
- {
- if (kind == "全部AGV")
- {
- if (type == "所有报警")
- {
- 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));
- exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
- }
- else
- {
- 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));
- exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
- }
- }
- else if (kind == "报警类型")
- {
- 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));
- exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
- }
- else if (kind == "站点" && !string.IsNullOrEmpty(workLine))
- {
- if (type == "所有报警")
- {
- 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));
- exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
- }
- else
- {
- 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));
- exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
- }
- }
- else if (kind == "当前AGV" && !string.IsNullOrEmpty(carID))
- {
- 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));
- exceptionManage.listBox1.ItemsSource = sql1.m_table.DefaultView;
- }
- }
- sql1.Close();
- }
- }
- }
|