Advertisement
AntonioLinux

problemDB

Apr 9th, 2012
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.86 KB | None | 0 0
  1. /* present in Insert.xaml.cs */
  2.      private void button1_Click(object sender, RoutedEventArgs e)
  3.         {         if (textBox1.Text.Length > 0)
  4.           {
  5.                 DB.Interventi newInterventi = new DB.Interventi
  6.                 {
  7.                   Element =textBox1.Text,
  8.                   Note =textBox1.Text.Length,    
  9.                       //I use a listPicker for select element
  10.                   Category = (DB.Elements)listPicker.SelectedItem
  11.                 };
  12.                 MessageBox.Show("data insert");
  13.           }
  14.             else
  15.             {
  16.  
  17.                MessageBox.Show("Insert Element");
  18.             }
  19.      
  20.            App.ViewModel.SaveDB(); }
  21.  
  22.  
  23. /* class Elementi.cs */
  24.  
  25.      [Table]
  26.     public class Elementi : INotifyPropertyChanged, INotifyPropertyChanging
  27.     {
  28.  
  29.         // definisco ID degli elementi del'auto
  30.         private int _id;
  31.  
  32.         [Column(DbType = "INT NOT NULL IDENTITY", IsDbGenerated = true, IsPrimaryKey = true)]
  33.         public int Id
  34.         {
  35.             get { return _id; }
  36.             set
  37.             {
  38.                 NotifyPropertyChanging("Id");
  39.                 _id = value;
  40.                 NotifyPropertyChanged("Id");
  41.             }
  42.         }
  43.      
  44.         private string _elemento;
  45.        [Column]
  46.         public string Elemento
  47.         {
  48.             get { return _elemento; }
  49.             set
  50.             {
  51.                 NotifyPropertyChanging("Elemento");
  52.                 _elemento = value;
  53.                 NotifyPropertyChanged("Elemento");
  54.             }
  55.         }
  56.      
  57.         [Column(IsVersion = true)]
  58.         private Binary _version;
  59.  
  60.         // Define the entity set for the collection side of the relationship.
  61.         private EntitySet<Interventi> _allInterventi;
  62.  
  63.  
  64.         // ASSOCIATION
  65.         [Association(Storage = "_allInterventi", OtherKey = "_categoryId", ThisKey = "Id")]
  66.         public EntitySet<Interventi> AllInterventi
  67.         {
  68.             get { return this._allInterventi; }
  69.             set { this._allInterventi.Assign(value); }
  70.         }
  71.  
  72.         public Elementi()
  73.         {
  74.             _allInterventi = new EntitySet<Interventi>(
  75.                 new Action<Interventi>(this.add_Intervento),
  76.                 new Action<Interventi>(this.remove_Intervento)
  77.                 );
  78.         }
  79.  
  80.         // add
  81.         private void add_Intervento(Interventi interv)
  82.         {
  83.             NotifyPropertyChanging("Interventi");
  84.             interv.Category = this;
  85.         }
  86.  
  87.         // remove
  88.         private void remove_Intervento(Interventi interv)
  89.         {
  90.             NotifyPropertyChanging("Interventi");
  91.             interv.Category = null;
  92.         }
  93.  
  94.  
  95.  
  96. /* class Interventi.cs*/
  97.  
  98.           [Table]
  99.     public class Interventi : INotifyPropertyChanged, INotifyPropertyChanging
  100.     {
  101.             private int _InterventoId;
  102.  
  103.     [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
  104.             public int InterventoId
  105.             {
  106.                 get { return _InterventoId; }
  107.                 set
  108.                 {
  109.  
  110.                     if (_InterventoId != value)
  111.                         NotifyPropertyChanged("InterventoId");
  112.                     this._InterventoId = value;
  113.                     NotifyPropertyChanged("InterventoId");
  114.  
  115.                 }
  116.  
  117.             }
  118.  
  119.     private string _Element;
  120.     [Column(CanBeNull = false)]
  121.     public string Element
  122.     {
  123.         get { return _Element; }
  124.            
  125.         set {
  126.                 if (_Kilometraggio != value)
  127.                 {
  128.                     NotifyPropertyChanging("Element");
  129.                     _Kilometraggio = value;
  130.                     NotifyPropertyChanged("Element");
  131.                 }
  132.     }
  133.     }
  134.  
  135.     private string _Note;
  136.     [Column(CanBeNull = true)]
  137.     public string Note
  138.     {
  139.         get { return _Note; }
  140.  
  141.         set
  142.         {
  143.             if (_Note != value)
  144.             {
  145.                 NotifyPropertyChanging("Note");
  146.                 _Note = value;
  147.                 NotifyPropertyChanged("Note");
  148.             }
  149.         }
  150.     }
  151.  
  152.     [Column(IsVersion = true)]
  153.     private Binary _version;
  154.     [Column]
  155.     internal int _categoryId;
  156.     private EntityRef<Elementi> _category;  
  157.       //ASSOCIATION
  158.         [Association(Storage = "_category", ThisKey = "_categoryId", OtherKey = "Id", IsForeignKey = true)]
  159.    
  160.       public Elementi Category
  161.         {
  162.             // setto il get
  163.             get { return _category.Entity; }
  164.  
  165.             set
  166.             {
  167.                 NotifyPropertyChanging("Category");
  168.                 _category.Entity = value;
  169.                 if (value != null)
  170.                 {
  171.                     _categoryId = value.Id;
  172.                 }
  173.  
  174.                 NotifyPropertyChanging("Category");
  175.             }
  176.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement