private void btnConfirm_Click(object sender, RoutedEventArgs e) { string sText = txtSampleCount.Text; int res; bool bok = int.TryParse(sText, out res); if(!bok) { txtSampleCount.Foreground = Brushes.Red; txtSampleCount.Text = "输入的样品数必须为数字!"; return; } int maxCount = int.Parse(ConfigurationManager.AppSettings["maxSampleCount"]); if (res <= 0 || res > maxCount) { SetInfo(string.Format("输入样品数必须在1-{0}之间!",maxCount),Brushes.Red); return; } //GlobalVals.hasBuffy = (bool)chkHasBuffy.IsChecked; GlobalVals.totalSample = res; GlobalVals.samplesThisBatch = int.Parse(ConfigurationManager.AppSettings[stringRes.sampleCountPerColumn]); if (GlobalVals.totalSample < GlobalVals.maxSamplesPerBatch * GlobalVals.curBatch) GlobalVals.samplesThisBatch = GlobalVals.totalSample % GlobalVals.maxSamplesPerBatch; //configs.hasBuffy = GlobalVals.hasBuffy; if (lstConfigs.SelectedItem == null) lstConfigs.SelectedIndex = 0; configs.sConfigFile = lstConfigs.SelectedItem.ToString(); GlobalVals.sCalibFile = Calib.GetCalibFolder() + configs.sConfigFile + ".xml"; string stest = ConfigurationManager.AppSettings["testOnly"]; bool bUseTestImage = bool.Parse(stest); if (bUseTestImage) { string testImagePath = Helper.GetCalibPath() + Others.covert2Short(GlobalVals.sCalibFile) + ".jpg"; if (!File.Exists(testImagePath)) { SetInfo("没有相应的实验背景图!", Brushes.Red); return; } } this.Visibility = Visibility.Hidden; XmlSerialize serializer = new XmlSerialize(stringRes.configFilePath); serializer.Serialize(configs); if( onFinished != null) onFinished(); }
void SettingWindow_Loaded(object sender, RoutedEventArgs e) { XmlSerialize serializer = new XmlSerialize(stringRes.configFilePath); List<string> files = Directory.EnumerateFiles(Helper.GetExeParentFolder() + stringRes.calibFolder,"*.xml").ToList(); int nSample = int.Parse(ConfigurationManager.AppSettings["maxSampleCount"]); sampleCountConstrain.Content = string.Format("样本数量在1-{0}之间", nSample); InitListBox(files); InitSampleCount(); List<string> shortNames = new List<string>(); foreach(var file in files) { shortNames.Add(Others.covert2Short(file)); } if (shortNames.Contains(GlobalVals.sCalibFile)) configs = new Configs(GlobalVals.sCalibFile); else { configs = (Configs)serializer.DeSerialize(typeof(Configs)); if (configs == null) { configs = new Configs(shortNames[0]); } } //chkHasBuffy.IsChecked = configs.hasBuffy; SelectListBox(configs.sConfigFile); }