public DialogWindow(Hashtable UIDToGoodsNumber, String Mode, String UserName) { InitializeComponent(); Parameter parameter = new Parameter(); parameter.UIDToGoodsNumber = UIDToGoodsNumber; parameter.UserName = UserName; parameter.Mode = Mode; OperateThread = new Thread(OperateThreadFunction); OperateThread.IsBackground = true; OperateThread.Start((object)parameter); }
public object Ask(Parameter par) { var vlc = main.Children.FindByName(ValueControl); if (vlc != null) main.Children.Remove(vlc); Question.Text = ""; foreach (string s in par.Question.Split(new[] { "\\n" }, StringSplitOptions.None)) { Question.Inlines.Add(new Run { Text = s }); Question.Inlines.Add(new LineBreak()); } if (par.ParamType == ParamType.PBool) { var value = new ComboBox { Width = 100, Height = 20, Name = ValueControl, Margin = new Thickness(5, 0, 0, 0) }; Grid.SetRow(value, 1); main.Children.Add(value); value.Items.Add(Boolean.TrueString); value.Items.Add(Boolean.FalseString); value.SelectedIndex = 0; value.Focus(); } else { var value = new TextBox { Width = 400, Name = ValueControl, Margin = new Thickness(5, 0, 0, 0) }; Grid.SetRow(value, 1); main.Children.Add(value); if (par.ParamType == ParamType.PDouble || par.ParamType == ParamType.PFuzzy) { value.Text = "0"; value.TextChanged += ValueTextChanged; value.Tag = par.ParamType; } else value.Tag = ParamType.PString; value.SelectAll(); value.Focus(); } if (ShowDialog() == true) { UIElement uie = main.Children.FindByName(ValueControl); if (uie is TextBox) { ParamType pt = (ParamType) (uie as TextBox).Tag; if (pt == ParamType.PDouble || pt == ParamType.PFuzzy) return double.Parse((uie as TextBox).Text); return (uie as TextBox).Text; } if (uie is ComboBox) return bool.Parse((uie as ComboBox).Text); } return null; }
/// <summary> /// Activates the view associated with the given parameter. /// </summary> /// <param name="region">The region.</param> /// <param name="parameter">The parameter.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="region"/> is <see langword="null" />. /// </exception> public static void ActivateByParameter(this IRegion region, Parameter parameter) { { Lokad.Enforce.Argument(() => region); } var view = region.GetViewByParameter(parameter); if (view != null) { region.Activate(view); } }
// Выполняется, когда пользователь переходит на эту страницу. protected override void OnNavigatedTo(NavigationEventArgs e) { if (WebContext.Current.User.IsInRole("Clinic")) { RejectButton.Visibility = ConfirmButton.Visibility = Visibility.Collapsed; respondTransplantantDomainDataSource.QueryName = "RespondOwnTransplantant"; Parameter p = new Parameter(); p.Value = WebContext.Current.User.ClinicId; p.ParameterName = "ClinicId"; respondTransplantantDomainDataSource.QueryParameters.Add(p); } else if (WebContext.Current.User.IsInRole("Worker")) { AddButton.Visibility = CancelButton.Visibility = Visibility.Collapsed; } else { ErrorWindow errorWnd = new ErrorWindow("Ошибка доступа.", "У вас нет доступа к данной странице. Возможно вы не авторизировались."); errorWnd.Show(); NavigationService.Navigate(new Uri("/Home", UriKind.Relative)); } }
private void LoginButton_Click(object sender, RoutedEventArgs e) { if (!loginBar.IsIndeterminate) { if (UsernameValidationRule.Validate((object)UsernameTextBox.Text, null).IsValid && PasswordValidationRule.Validate((object)PasswordTextBox.Text, null).IsValid) { //StatusTextBlock.Foreground = new SolidColorBrush(Colors.White); //StatusTextBlock.Text = "Copyright@RFID智能仓储小组"; loginBar.IsIndeterminate = true; LoginButton.Content = "取 消"; loginAnimate.Begin(); Parameter parameter = new Parameter(); parameter.Name = UsernameTextBox.Text.Trim(); parameter.Password = password.Trim(); CheckThread = new Thread(CheckFunction); CheckThread.IsBackground = true; CheckThread.Start((object)parameter); } else { if (UsernameTextBox.Text == "") { UsernameTextBox.Text = ""; } if (PasswordTextBox.Text == "") { PasswordTextBox.Text = ""; } } } else { loginBar.IsIndeterminate = false; LoginButton.Content = "进 入"; cancelAnimate.Begin(); CheckThread.Abort(); CheckThread.Join(); } }
public void InvalidQueryParameterName() { this._dds.AutoLoad = true; this._dds.QueryName = "GetCitiesInStateQuery"; this._dds.DomainContext = new CityDomainContext(); // The first two cases are acceptable and support the binding scenario Parameter p = new Parameter { ParameterName = null, Value = "WA" }; this._dds.QueryParameters.Add(p); p.ParameterName = string.Empty; this._dds.QueryParameters.Clear(); // The second two cases throw exceptions for parameter names that are not valid p.ParameterName = "invalid"; AssertExpectedException( new ArgumentException( string.Format( CultureInfo.InvariantCulture, DomainDataSourceResources.EntityQueryMethodHasMismatchedArguments, "GetCitiesInStateQuery")), () => this._dds.QueryParameters.Add(p)); AssertExpectedException( new ArgumentException( string.Format( CultureInfo.InvariantCulture, DomainDataSourceResources.EntityQueryMethodHasMismatchedArguments, "GetCitiesInStateQuery")), () => p.ParameterName = "invalid2"); }
private void nextParameter() { if (m_params.MoveNext()) { do { m_parameter = m_params.Current; FamilyTB.Text = m_parameter.Element as FamilyInstance != null ? ((FamilyInstance)m_parameter.Element).Name : null; TypeTB.Text = m_parameter.Element as FamilyInstance != null ? ((FamilyInstance)m_parameter.Element).GetParameters("Type").FirstOrDefault().AsString() : null; PararmeterTB.Text = m_parameter.Definition.Name; ContextTB.Clear(); ContextTB.Text = m_parameter.HasValue ? m_parameter.AsString() : String.Empty; } while ( ContextTB.GetNextSpellingErrorCharacterIndex(0, LogicalDirection.Forward) == -1 && m_params.MoveNext()); } else { nextBtn.IsEnabled = false; FamilyTB.Clear(); TypeTB.Clear(); ContextTB.Clear(); ContextTB.Text = END_OF_DOCUMENT; ContextTB.IsEnabled = false; } }
private bool ReccurentSearch(Parameter needed, int level) { _log.Add("Searching for " + needed.ParamName + " :", level); List<Rule> goodrules = _rules.FindAll(r => r.Result.ParamId == needed.ParamId); _log.Add("Rules found: " + goodrules.Count, level); if (goodrules.Count == 0 || goodrules.All(rule => rule.Conditions.Exists(cond => cond.Parameter.ParamId == needed.ParamId))) { return AskQuestion(needed, level); } var fuzzyTermValues = new Dictionary<Term, double>(); foreach (Rule rule in goodrules) { _log.Add("Processing rule:" + rule, level); bool ruleOk = true; double rulefuzzys = 1; foreach (Condition condition in rule.Conditions.Where(cond => cond.Parameter.ParamType != ParamType.PFuzzy)) { _log.Add("Processing condition:" + condition, level); Parameter p = _parameters.First(a => a.ParamId == condition.Parameter.ParamId); if (_paramValues[p] == null) if (ReccurentSearch(p, level + 1) == false) return false; if (!CheckCondition(condition)) { _log.Add("Condition failed", level); ruleOk = false; } else { _log.Add("Condition passed", level); } } if (ruleOk) foreach (Condition condition in rule.Conditions.Where(cond => cond.Parameter.ParamType == ParamType.PFuzzy)) { _log.Add("Processing Fuzzy condition:" + condition, level); Parameter p = _parameters.First(a => a.ParamId == condition.Parameter.ParamId); if (_paramValues[p] == null) if (ReccurentSearch(p, level + 1) == false) return false; if ((condition.Value is CreditParameter && (condition.Value as CreditParameter).ParamType != ParamType.PFuzzy) || condition.Value is double) { bool result = CheckCondition(condition); ruleOk = result && ruleOk; _log.Add("Fuzzy condition is not Fuzzy really. Result is " + result, level); } else { double result = CheckFuzzyCondition(condition); rulefuzzys = Math.Min(rulefuzzys, result); _log.Add("Fuzzy condition returned probability " + result, level); } } _log.Add("Finished processing conditions", level); if (ruleOk) { _rules.Remove(rule); Parameter p = _parameters.First(a => a.ParamId == rule.Result.ParamId); _log.Add("Calculating result parameter " + rule.Result.ParamName + " using function " + rule.ResultValue, level); if (p.ParamType == ParamType.PDouble || (p.ParamType == ParamType.PFuzzy && !p.termGroup.Terms.Exists(term => term.TermName == rule.ResultValue))) { var parser = new Parser(); List<string> vars = rule.ResultValue.Split(new[] {'-', '+', '/', '*', ')', '('}).ToList().ConvertAll(s => s.Trim()); foreach (string var in vars) { Parameter par = _parameters.Find(f => f.ParamName == var); if (par != null && _paramValues[par] == null) if (ReccurentSearch(par, level + 1) == false) return false; } List<CreditParameter> allParameters = _parameters.Cast<CreditParameter>().ToList(); allParameters.AddRange(_creditParam.Keys); //localparameters now contains all parameters and creditparameters List<string> parameterNames = allParameters.ConvertAll(a => a.ParamName); try { parser.Parse(rule.ResultValue, parameterNames); } catch (Exception e) { MessageBox.Show(e.Message); return false; } Dictionary<string, double> allParametersValues = _paramValues.ToValueList(); foreach (var crp in _creditParam.Where(crp => crp.Key.ParamType == ParamType.PDouble)) allParametersValues.Add(crp.Key.ParamName, double.Parse(crp.Value)); try { _paramValues[p] = parser.Calculate(allParametersValues); if (p.ParamType == ParamType.PFuzzy) CalculateTermValues(p, level); } catch (Exception e) { MessageBox.Show(e.Message); return false; } _log.Add("Rule passed => " + p.ParamName + "=" + _paramValues[p], level); return true; } if (p.ParamType == ParamType.PBool && _creditParam.Keys.ToList().Exists(par => par.ParamName == rule.ResultValue)) { _paramValues[p] = _creditParam.First(par => par.Key.ParamName == rule.ResultValue).Value; _log.Add("Rule passed => " + p.ParamName + "=" + _paramValues[p], level); return true; } if (p.ParamType == ParamType.PFuzzy) { Term t = p.termGroup.Terms.First(term => term.TermName == rule.ResultValue); if (fuzzyTermValues.Keys.ToList().Exists(term => term.TermName == t.TermName)) fuzzyTermValues[t] = Math.Max(rulefuzzys, fuzzyTermValues[t]); else fuzzyTermValues[t] = rulefuzzys; _log.Add("Rule passed", level); } //for PString else { _paramValues[p] = rule.ResultValue; _log.Add("Rule passed => " + p.ParamName + "=" + _paramValues[p], level); return true; } } else _log.Add("Rule failed", level); } if (needed.ParamType == ParamType.PFuzzy && fuzzyTermValues.Count()>0) { Parameter p = _parameters.First(a => a.ParamId == needed.ParamId); _fuzparamValues[p] = fuzzyTermValues; _paramValues[p] = Defuz(p, level); return true; } return AskQuestion(needed, level); }
/// <summary> /// Finds the view associated with the given parameter. /// </summary> /// <param name="region">The region.</param> /// <param name="parameter">The parameter.</param> /// <returns>The view that is associated with the given parameter.</returns> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="region"/> is <see langword="null" />. /// </exception> public static object GetViewByParameter(this IRegion region, Parameter parameter) { { Lokad.Enforce.Argument(() => region); } return region.Views.OfType<DependencyObject>().FirstOrDefault(x => parameter.Equals(GetParameter(x))); }
private void CalculateTermValues(Parameter needed, int level) { var dict = new Dictionary<Term, double>(); foreach (Term term in needed.termGroup.Terms) { Parser parser = new Parser(); parser.Parse(term.TermFunction, new List<string> {"x"}); double value; if (_paramValues[needed] is double) value = (double) _paramValues[needed]; else value = double.Parse(_paramValues[needed].ToString()); if (value > term.RightRange) value = term.RightRange; if (value < term.LeftRange) value = term.LeftRange; dict[term] = parser.Calculate(new Dictionary<string, double> {{"x", value}}); _log.Add("Term value for " + term.TermName + " : " + dict[term], level + 1); } _fuzparamValues[needed] = dict; }
private bool AskQuestion(Parameter needed, int level) { if (!String.IsNullOrEmpty(needed.Question)) { _log.Add("Asking user for " + needed.ParamType.GetStringValue() + " variable " + needed.ParamName + " ...", level); AskWindow ask = new AskWindow(); _paramValues[needed] = ask.Ask(needed); if (_paramValues[needed] == null) return false; _log.Add("User answered : " + _paramValues[needed], level); if (needed.ParamType == ParamType.PFuzzy) { CalculateTermValues(needed, level); } return true; } return false; }
public static void SetParameter(DependencyObject obj, Parameter? value) { obj.SetValue(ParameterProperty, value); }
private void RegisterWriteButton_Click(object sender, RoutedEventArgs e) { if (UHF_IsOpen) { if (!UHF_IsPersist) { if (LabelList.SelectedIndex < 0) { StatusTextBlock.Text = "请选择你要操作的UID!"; LabelList.Focus(); return; } String message; if ((Boolean)ClearSwitch.IsChecked) { message = ""; if(!App.StorageDB.DeleteLabel(LabelList.SelectedItem.ToString().Trim())) { this.ShowMessageAsync("错误", "注册删除失败", MahApps.Metro.Controls.MessageDialogStyle.Affirmative); return; } } else { message = ((DataRowView)(GoodsNameComboBox.SelectedItem))[0].ToString() + " " + ((DataRowView)(GoodsNameComboBox.SelectedItem))[1].ToString(); if (!App.StorageDB.RegisterLabel(LabelList.SelectedItem.ToString().Trim(), ((DataRowView)(GoodsNameComboBox.SelectedItem))[0].ToString())) { this.ShowMessageAsync("错误", "注册标签失败", MahApps.Metro.Controls.MessageDialogStyle.Affirmative); return; } } String struii = LabelList.SelectedItem.ToString().Trim(); Byte[] uUii = new Byte[struii.Length / 2]; for (Int32 i = 0; i < uUii.Length; i++) { uUii[i] = Convert.ToByte(struii.Substring(i * 2, 2), 16); } int m = 38 - message.Length; for (int i = 0; i < m; i++) { message += " "; } Parameter parameter = new Parameter(); parameter.UID = uUii; parameter.Message = message; UHF_IsPersist = true; UHF_threadWRT = new Thread(WriteThread); UHF_threadWRT.IsBackground = true; UHF_threadWRT.Start((object)parameter); } else { StatusTextBlock.Text = "现在不能操作,请等待"; return; } } else { StatusTextBlock.Text = "串口未打开"; return; } }
/// <summary> /// Sets the parameter associated with a view. /// </summary> /// <param name="view">The view for which a parameter must be registered.</param> /// <param name="parameter">The parameter which must be registered.</param> public static void SetParameter(object view, Parameter parameter) { var target = view as DependencyObject; if (target == null) { return; } target.SetValue(ParameterProperty, parameter); }
public static bool HasViewByParameter(this IRegion region, Parameter parameter) { { Lokad.Enforce.Argument(() => region); } return region.GetViewByParameter(parameter) != null; }
private Method GetMethodNode(MethodDeclarationSyntax method) { Method methodnode = new Method(); methodnode.ReturnType = method.ReturnType.ToString(); methodnode.Modifier = method.Modifiers.ToString(); methodnode.Name = method.Identifier.ToString(); foreach (var parameter in method.ParameterList.Parameters) { Parameter p = new Parameter(); p.name = parameter.Identifier.ToString(); p.type = parameter.Type.ToString(); methodnode.Parameters.Add(p); } return methodnode; }
private double Defuz(Parameter parameter, int level) { _log.Add("Defuzzing variable:" + parameter.ParamName, level); Dictionary<Term,double> termValues = _fuzparamValues[parameter]; string function = null; foreach (var termValue in termValues) { string localfunction = String.Format("min({0};{1})", termValue.Value.ToString(), termValue.Key.TermFunction); if (String.IsNullOrEmpty(function)) function = localfunction; else function = String.Format("max({0};{1})", function, localfunction); } _log.Add("Compiled function: " + function, level); Parser parser = new Parser(); parser.Parse(function, new List<string> {"x"}); int left = parameter.termGroup.Terms[0].LeftRange; int right = parameter.termGroup.Terms[0].RightRange; double max = double.MinValue; double x = left; for (double i = left; i < right; i += ((double) right - left)/1000) { double value = parser.Calculate(new Dictionary<string, double> {{"x", i}}); if (max<value) { max = value; x = i; } } _log.Add("Max value on x is: " + x, level); return x; }
/// <summary> /// Adds the given view and associates it with the given parameter. /// </summary> /// <param name="region">The region.</param> /// <param name="view">The view for the parameter.</param> /// <param name="parameter">The parameter.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="region"/> is <see langword="null" />. /// </exception> public static void AddWithParameter(this IRegion region, object view, Parameter parameter) { { Lokad.Enforce.Argument(() => region); } SetParameter(view, parameter); region.Add(view); }