Ejemplo n.º 1
0
        private void btn2_Click(object sender, RoutedEventArgs e)
        {
            if (cb_Foods.SelectedItem == null)
            {
                MessageBox.Show("先选一种食物!");
                return;
            }
            Foods foods = cb_Foods.SelectedItem as Foods;

            if (foods == null)
            {
                MessageBox.Show("foods转换出错!");
                return;
            }

            List <FoodNutritionsPostDto> datas = new List <FoodNutritionsPostDto>();
            string        inputElements        = txtInputElements.Text;
            List <string> ElementsList         = inputElements.Split(',').ToList();

            if (ElementsList.Count() != 31)
            {
                MessageBox.Show("输入错误");
                return;
            }

            for (int i = 0; i < 30; i++)
            {
                FoodNutritionsPostDto newData = new FoodNutritionsPostDto()
                {
                    FoodId             = foods.Id,
                    NutritiveElementId = NutritiveElementIdList[i],
                    Value = (string.IsNullOrEmpty(ElementsList[i + 1]))?0:double.Parse(ElementsList[i + 1])
                };
                datas.Add(newData);
            }
            try
            {
                INRDataProcessService myDataService = BusinessStaticInstances.GetSingleDataProcessServiceInstance();
                myDataService.CreateFoodNutritionsForTesting(datas);
                List <Foods> tempsource = cb_Foods.ItemsSource as List <Foods>;
                tempsource.Remove(foods);
                cb_Foods.ItemsSource   = tempsource;
                cb_Foods.SelectedIndex = -1;
                MessageBox.Show("提交成功!");
                txtInputElements.Text = string.Empty;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 2
0
        private void btn_Click(object sender, RoutedEventArgs e)
        {
            if (cb_Foods.SelectedItem == null)
            {
                MessageBox.Show("先选一种食物!");
                return;
            }
            Foods foods = cb_Foods.SelectedItem as Foods;

            if (foods == null)
            {
                MessageBox.Show("foods转换出错!");
                return;
            }
            List <FoodNutritionsPostDto> datas = new List <FoodNutritionsPostDto>();
            List <TextBox> listTextBox         = GetChildObjects <TextBox>(myWrapPanel, "tb_Element");

            foreach (var item in listTextBox)
            {
                FoodNutritionsPostDto newData = new FoodNutritionsPostDto()
                {
                    FoodId             = foods.Id,
                    NutritiveElementId = Guid.Parse(item.Tag.ToString()),
                    Value = (string.IsNullOrEmpty(item.Text) ? 0 : double.Parse(item.Text))
                };
                datas.Add(newData);
            }
            try
            {
                INRDataProcessService myDataService = BusinessStaticInstances.GetSingleDataProcessServiceInstance();
                myDataService.CreateFoodNutritionsForTesting(datas);
                List <Foods> tempsource = cb_Foods.ItemsSource as List <Foods>;
                tempsource.Remove(foods);
                cb_Foods.ItemsSource   = tempsource;
                cb_Foods.SelectedIndex = -1;
                MessageBox.Show("提交成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }