private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            Equipment        ec  = (sender as Button).Tag as Equipment;
            MessageBoxResult mbr = MessageBox.Show("是否删除" + ec.Name, "删除", MessageBoxButton.OKCancel, MessageBoxImage.Warning);

            if (mbr == MessageBoxResult.OK)
            {
                using (var context = new EMDBEntities())
                {
                    context.Entry(ec).State = EntityState.Deleted;
                    context.SaveChanges();
                    ecs.Remove(ec);
                }
            }
        }
Esempio n. 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            List <TextBox> ltb = new List <TextBox>
            {
                Num, Price
            };

            foreach (var item in ltb)
            {
                if (Validation.GetHasError(item))
                {
                    List <ValidationError> lv = Validation.GetErrors(item).ToList();
                    foreach (var v in lv)
                    {
                        MessageBox.Show(v.ErrorContent.ToString());
                    }
                    return;
                }
            }
            try
            {
                using (var context = new EMDBEntities())
                {
                    if (ec.Id == 0)
                    {
                        context.Equipments.Add(ec);
                        context.SaveChanges();
                        ocec.Add(ec);
                    }
                    else
                    {
                        ec.Remark += "。";
                        context.Entry(ec).State = EntityState.Modified;
                        context.SaveChanges();
                    }
                }
                MessageBox.Show("操作成功");
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }