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(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(); } /// /// 加载报警数据排行 /// /// 待排行日期,空串所有时间报警,否则为当前选定日期 /// 对AGV哪种报警排行 /// 排行种类,可以是AGV,报警类型 /// 生产区,只用于对站点的排行 /// 要排行的当前AGV编号 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(); } } }