Пример #1
0
 private void LoadData()
 {
     using (DataBaseOrdersContainer db = new DataBaseOrdersContainer())
     {
         try
         {
             var order = db.Orders.ToList <Order>();
             foreach (var item in order)
             {
                 Record record = new Record
                 {
                     OrderNumber  = item.Id,
                     User         = item.User.Name,
                     LineQuantity = item.OrderLines.Count,
                     Sum          = item.OrderLines.Sum(inner => inner.Price),
                     Created      = item.CreatedOn,
                     Modified     = item.ModifiedOn
                 };
                 Records.Add(record);
             }
         }
         catch (ArgumentNullException ex)
         {
             MessageBox.Show(ex.Message);
         }
         catch (OverflowException ex)
         {
             MessageBox.Show(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             MessageBox.Show(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             MessageBox.Show(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Пример #2
0
 private void MainViewModel_ChangeRecord(object sender, PropertyChangedEventArgs e)
 {
     using (DataBaseOrdersContainer db = new DataBaseOrdersContainer())
     {
         try
         {
             List <OrderLine> ordersLines = db.OrderLines.Where(item => item.Order.Id == SelectedRecord.OrderNumber).ToList <OrderLine>();
             RecordsInfos.Clear();
             foreach (var item in ordersLines)
             {
                 RecordInfo recordInfo = new RecordInfo
                 {
                     Product  = item.Product.Name,
                     Price    = item.Price,
                     Quantity = item.Quantity
                 };
                 RecordsInfos.Add(recordInfo);
             }
         }
         catch (ArgumentNullException ex)
         {
             MessageBox.Show(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             MessageBox.Show(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             MessageBox.Show(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }