示例#1
0
 public override ValidationResult Validate(object value, CultureInfo cultureInfo)
 {
     try
     {
         BindingGroup bindingGroup = (BindingGroup)value;
         MyListItem   eli          = (MyListItem)bindingGroup.Items[0];
         int          reamin       = Convert.ToInt32(bindingGroup.GetValue(eli, "Remain"));
         int          num          = Convert.ToInt32(bindingGroup.GetValue(eli, "Num"));
         if (num < 0)
         {
             return(new ValidationResult(false, "输入的数字不合法"));
         }
         if (num > reamin)
         {
             return(new ValidationResult(false, "租赁数量超过剩余数量"));
         }
         else
         {
             return(new ValidationResult(true, null));
         }
     }
     catch (Exception ex)
     {
         return(new ValidationResult(false, ex.Message));
     }
 }
        private void DataGrid1_MouseUp(object sender, MouseButtonEventArgs e)
        {
            MyListItem mli = DataGrid1.SelectedItem as MyListItem;

            if (mli != null)
            {
                SelectNumWindow snw = new SelectNumWindow(mli);
                snw.ShowDialog();
            }
        }
示例#3
0
 public override ValidationResult Validate(object value, CultureInfo cultureInfo)
 {
     try
     {
         BindingGroup bindingGroup = (BindingGroup)value;
         MyListItem   mli          = (MyListItem)bindingGroup.Items[0];
         int          num          = Convert.ToInt32((string)bindingGroup.GetValue(mli, "Num"));
         if (num < 0)
         {
             return(new ValidationResult(false, "请输入大于等于0的数字"));
         }
         if (num > mli.Remain)
         {
             return(new ValidationResult(false, "输入的数量超过上限"));
         }
         return(new ValidationResult(true, null));
     }
     catch (Exception ex)
     {
         return(new ValidationResult(false, "请输入合法的数字"));
     }
 }
        public SelectNumWindow(MyListItem mli)
        {
            InitializeComponent();

            MylistItemStackPanel.DataContext = mli;
        }