//this method update the actual cost field in the actual cost table public bool addActualCost(double total, string cm) { try { using (adoraDBContext a = new adoraDBContext()) { ActualCost actCost = new ActualCost(); actCost.CM = cm; actCost.TotalCost = Convert.ToDecimal(total); a.ActualCosts.Add(actCost); a.SaveChanges(); return true; } } catch (Exception e) { MessageBox.Show(e.ToString()); addException(e, "addActualCost()"); return false; } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { // If the user is authorized to perform the delete operation if (_userType.getUserLevel() == 1 || _userType.getUserLevel() == 2) { try { string id = lblShipID.Content.ToString(); if (MessageBox.Show("Do you want to delete " + id, "Confirm", MessageBoxButton.YesNoCancel, MessageBoxImage.Question) == MessageBoxResult.Yes) { adoraDBContext adb = new adoraDBContext(); PurchasingShipment psp = adb.PurchasingShipments.FirstOrDefault(i => i.ShipmentID == id); adb.PurchasingShipments.Remove(psp); adb.SaveChanges(); // this.purchasingShipmentDataGrid.Items.Refresh(); //context.PurchasingShipments.Load(); populateShipmentNames(txtDelShipName); MessageBox.Show("Successfully Deleted", "Done", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception es) { MessageBox.Show("You cannot delete Shipments which are having associated frequencies! Please delete associated frequencies before deleting the shipment"); } //adoraDBContext _con = new adoraDBContext(); //_con.PurchasingShipments.Load(); //this.purchasingShipmentDataGrid.Items.Refresh(); refresh(); } else { ModernDialog.ShowMessage("You are not privilaged to perform this action", "Access Denied!", MessageBoxButton.OK); } }
//this method add data to fabriccost table public bool addFabricCost(FabricCostData data) { try { using (adoraDBContext a = new adoraDBContext()) { FabricCost actCost = new FabricCost(); actCost.Type = data.Type; actCost.Amount = (float)data.Amount; actCost.Cost = (decimal)data.Cost; actCost.ACostID = data.ACostID; actCost.costPyard = (float)data.CostPyard; a.FabricCosts.Add(actCost); int done = a.SaveChanges(); if (done != -1) return true; else return false; } } catch (InvalidCastException invalidCastException) { addException(invalidCastException, "addFabricCost()"); return false; } catch(Exception ex) { return false; } }