using MetroGauges.Database.Enitys; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace MetroGauges.Database.Forms { /// /// ProSetting.xaml 的交互逻辑 /// public partial class ProSetting : Window { private BlockInfo blockInfo; public ProSetting() { InitializeComponent(); } public void BindData(BlockInfo Info) { blockInfo = Info; dgFileds.ItemsSource = blockInfo.FieldData; } private void btAdd_Click(object sender, RoutedEventArgs e) { int r; if (int.TryParse(txtName.Text, out r)) { MessageBox.Show("属性名不能为数字"); return; } if (string.IsNullOrWhiteSpace(txtName.Text)) { MessageBox.Show("请录入属性名"); return; } if (string.IsNullOrWhiteSpace(txtValue.Text)) { MessageBox.Show("请录入属性值"); return; } FieldInfo fieldInfo = new FieldInfo(); fieldInfo.Blockid = blockInfo.Id; fieldInfo.Display = txtName.Text; fieldInfo.Fieldname = txtName.Text; fieldInfo.Fieldvalue = txtValue.Text; bool reuslt = BlockDAL.CreateField(fieldInfo); if (reuslt) { blockInfo.FieldData.Add(fieldInfo); txtName.Text = ""; txtValue.Text = ""; } } private void btcancel_Click(object sender, RoutedEventArgs e) { this.Close(); } private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { int id =int.Parse((sender as Image).Tag.ToString()); BlockDAL.DeleteFiled(id); FieldInfo fieldInfo = blockInfo.FieldData.Where(p => p.Id == id).FirstOrDefault(); blockInfo.FieldData.Remove(fieldInfo); } } }