/// <summary> /// 查询数据库 /// </summary> /// <param name="date"></param> /// <param name="type"></param> /// <param name="itemName"></param> public void QueryDatabase(DateTime date, TYPE_COFFEE type, string itemName) { int countFailItem = 0; string[] results = MySQLTool.MySql.CheckResultSelect(date, type.ToString()); List <float> listItems = MySQLTool.MySql.SelectItem(date, type.ToString(), itemName); int i = Int32.Parse(Regex.Replace(itemName, @"^[A-Za-z]+", string.Empty)); Global.ChangeCoffeeType(type); foreach (var item in listItems) { if (item < Global.ListItemParameter[i - 1].UserMin || item > Global.ListItemParameter[i - 1].UserMax) { countFailItem++; } } Global.ChangeCoffeeType((TYPE_COFFEE)Enum.Parse(typeof(TYPE_COFFEE), type.ToString())); string[] statistic = new string[results.Length + 1]; for (int j = 0; j < results.Length; j++) { statistic[j] = results[j]; } statistic[statistic.Length - 1] = countFailItem.ToString(); if (UpdateMainViewRecords != null) { UpdateMainViewRecords(statistic); } }
/// <summary> /// 保存检测项参数配置 /// </summary> public static void Serialize(TYPE_COFFEE type) { //string currentDirectory = Directory.GetCurrentDirectory(); string currentDirectory = @"E:\佐帕斯\Coffee\Zoppas\bin\Debug"; File.Delete(currentDirectory + "\\" + type.ToString() + ".txt"); FileStream fs = new FileStream(currentDirectory + "\\" + type.ToString() + ".txt", FileMode.Create); XmlSerializer serializer = new XmlSerializer(typeof(List <Parameter>)); serializer.Serialize(fs, ListItemParameter); fs.Close(); }
public MainViewModel() { _Manager = Manager.Instance; // 从配置文件导入参数表 //Global.LoadFactory(_Manager.Type); //Global.ParameterChanged += OnParameterChanged; //Global.Deserialize(TYPE_COFFEE.T_7319); _Parameters = Global.ListItemParameter; _CalibrationParameters = Global.ListItemParameterCalibration; //Global.Serialize(TYPE_COFFEE.T_7319); //for (int i = 0; i < Global.ListItemParameter.Count; i++) //{ // _Parameters.Add(new Parameter() // { // Name = Global.ListItemName[i], // FactoryMin = Global.ListItemParameter[i].StdMin.ToString(), // FactoryMax = Global.ListItemParameter[i].StdMax.ToString() // }); //} //Global.Serialize(_Manager.Type); //Global.Deserialize(_Manager.Type); //for (int i = 0; i < Global.ListItemParameter.Count; i++) //{ // _Parameters[i].UserMin = Global.ListItemParameter[i].StdMin.ToString(); // _Parameters[i].UserMax = Global.ListItemParameter[i].StdMax.ToString(); //} _Products = new AsyncObservableCollection <ViewProduct>(); _Records = new AsyncObservableCollection <Record>(); _Type = _Manager.Type; _QueryCommand = new RelayCommand(() => { _Manager.QueryDatabase(Time, Type, Item); }); _InitCommand = new RelayCommand(_Manager.Init); _LoadFileParametersCommand = new RelayCommand(() => { Global.Deserialize(_Manager.Type); }); _SaveFileParametersCommand = new RelayCommand(() => { Global.Serialize(_Manager.Type); }); _CloseMainWindowCommand = new RelayCommand(() => { _Manager.Close(); }); _Manager.UpdateMainViewProducts += OnUpdateMainViewProducts; _Manager.UpdateMainViewRecords += OnUpdateMainViewRecords; _Manager.UpdateViewCalibrationResults += new Action <List <string> >(OnUpdateViewCalibrationResults); _Items = new ObservableCollection <Item>(); for (int i = 0; i < Global.ListItemNameCalibration.Count; i++) { _Items.Add(new Item { Name = Global.ListItemNameCalibration[i], Min = Global.ListItemParameterCalibration[i].UserMin.ToString(), Max = Global.ListItemParameterCalibration[i].UserMax.ToString() }); } _Manager.UpdateMainViewStatus += (s) => { Status = s; }; }
/// <summary> /// 切换咖啡壶的种类 /// </summary> public static void ChangeCoffeeType(TYPE_COFFEE type) { switch (type) { case TYPE_COFFEE.T_7319: _Workmode = WORK_MODE.PUSH; //_ListItemName = _ListItemName7319; _DictItemID = _DictItemID7319; _ListItemParameter = _ListItemParameter7319; _ListOP = _ListOP7319; _ListItemType = _ListItemType7319; break; case TYPE_COFFEE.T_7320: break; default: throw new NotImplementedException("Unsupported type."); } }
/// <summary> /// 切换壶的种类,根据种类再切换相关参数 /// </summary> /// <param name="type"></param> private void OnChangeCoffeeType(TYPE_COFFEE type) { _Type = type; Global.ChangeCoffeeType(type); }
/// <summary> /// 导入检测项参数配置 /// </summary> public static void Deserialize(TYPE_COFFEE type) { //string currentDirectory = Directory.GetCurrentDirectory(); string currentDirectory = @"E:\佐帕斯\Coffee\Zoppas\bin\Debug"; FileStream fs = null; try { fs = new FileStream(currentDirectory + "\\" + type.ToString() + ".txt", FileMode.Open); } catch (Exception) { Logger.Fatal("Open file failed."); _ListItemParameter7319 = new List <Parameter> { { new Parameter("mm") { Name = "平整度", FactoryMin = 0, FactoryMax = 0.5, UserMin = 0, UserMax = 0.5 } }, { new Parameter("mm") { Name = "NTC孔处加热丝位置", FactoryMin = 39, FactoryMax = 45, UserMin = 39, UserMax = 45 } }, { new Parameter("mm") { Name = "螺钉位置", FactoryMin = 52.5, FactoryMax = 53.5, UserMin = 52.5, UserMax = 53.5 } }, { new Parameter("度") { Name = "螺钉角度", FactoryMin = 88.5, FactoryMax = 91.5, UserMin = 88.5, UserMax = 91.5 } }, { new Parameter("mm") { Name = "左电极位置", FactoryMin = 98, FactoryMax = 104, UserMin = 98, UserMax = 104 } }, { new Parameter("mm") { Name = "水嘴位置", FactoryMin = 85, FactoryMax = 87, UserMin = 85, UserMax = 87 } }, { new Parameter("mm") { Name = "NTC孔直径", FactoryMin = 4.0, FactoryMax = 4.2, UserMin = 4.0, UserMax = 4.2 } }, { new Parameter("mm") { Name = "NTC位置", FactoryMin = 31.65, FactoryMax = 32.25, UserMin = 31.65, UserMax = 32.25 } }, { new Parameter("mm") { Name = "右电极位置", FactoryMin = 98, FactoryMax = 104, UserMin = 98, UserMax = 104 } }, { new Parameter("mm") { Name = "温控器到加热管间隙", FactoryMin = 0.5, FactoryMax = 2, UserMin = 0.5, UserMax = 2 } }, { new Parameter("mm") { Name = "热熔断器到加热管间隙", FactoryMin = 0.5, FactoryMax = 1.2, UserMin = 0.5, UserMax = 1.2 } }, { new Parameter("mm") { Name = "2加热丝间隙", FactoryMin = 1, FactoryMax = 999, UserMin = 1, UserMax = 999 } }, }; return; } XmlSerializer serializer = new XmlSerializer(typeof(List <Parameter>)); _ListItemParameter7319 = (List <Parameter>)serializer.Deserialize(fs); _ListItemParameter = _ListItemParameter7319; //ChangeCoffeeType(TYPE_COFFEE.T_7319); //NotifyView(); fs.Close(); }
public static void LoadFactory(TYPE_COFFEE type) { //ChangeCoffeeType(type); //NotifyView(); }