LoginDetails _userType = new LoginDetails(); //Access Privilages handler

        public FinalAnalysis()
        {
            InitializeComponent();
            _context = new adoraDBContext();                 // Initialize DB Context
            _dao = new FinalAnalysisDAO();                   // Initialize Data access object

            // Set the ChartController class as the dataContext for this class
            DataContext = new ChartController();

            // Yearly radio button is checked defaultly
            radioYearly.IsChecked = true;

            // Yearly radio button in tabular format is checked defaultly
            radioYearly1.IsChecked = true;
           

            // Add years from 2012 onwards till current year
            for (int i = 2012; i <= DateTime.Today.Year; i++)
            {
                dropYear.Items.Add(i);
                dropYear1.Items.Add(i);
            }

            // Select Current Year and month defaultly
            dropYear1.SelectedIndex = dropYear1.Items.Count -1;
            dropMonth1.SelectedIndex = DateTime.Now.Month -1;

            // Populate statistical data
            populateData();
        }
        //method a list of strings
        public List<string> getItems()
        {
            try
            {
                
                using (adoraDBContext a = new adoraDBContext())
                {
                    var items = (from e in a.StockInHands
                                where e.ACostID == null
                                select new {e.ItemName, e.StockID}
                   ).Distinct().ToList();

                    List<string> rlist = new List<string>();

                    for (int i = 0; i < items.Count; i++)
                    {
                        rlist.Add(items[i].ItemName +" |" + items[i].StockID.ToString());
                    }
                    return rlist;
                }
            }
            catch (ArgumentException argumentException)
            {
                addException(argumentException, "getItems()");
                return null;
            }
        }
        //this method is used to update the combobox contet according to the users key strocks in fabric tab, catagory combo box
        public void updateSearchComboBoxFab(ComboBox cmbBox)
        {
            try
            {
                using (adoraDBContext a = new adoraDBContext())
                {
                    String searchText = cmbBox.Text.ToString();

                   
                    var fabtype = (from e in a.Fabrics
                                       where e.Category.Contains(searchText)
                                       select new { e.Category }
                   ).Distinct().ToList();

                    List<String> nList = new List<string>();

                    for (int i = 0; i < fabtype.Count; i++)
                    {
                        String n = fabtype[i].Category.ToString();
                      

                        String nm = n;
                        nList.Add(nm);
                    }
                    cmbBox.ItemsSource = nList;
                    cmbBox.IsDropDownOpen = true;
                }
            }
            catch (Exception e)
            {
            }
        }
        //this method will update the combo box unit in accessories according to the users key strokes
        public void updateSearchComboBoxAccUni(ComboBox cmbBox)
        {
            try
            {
                using (adoraDBContext a = new adoraDBContext())
                {
                    String searchText = cmbBox.Text.ToString();


                    var unitType = (from e in a.Accessories
                                       where e.UnitType.Contains(searchText)
                                       select new { e.UnitType }
                   ).Distinct().ToList();

                    List<String> nList = new List<string>();

                    for (int i = 0; i < unitType.Count; i++)
                    {
                        String n = unitType[i].UnitType.ToString();


                        String nm = n;
                        nList.Add(nm);
                    }
                    cmbBox.ItemsSource = nList;
                    cmbBox.IsDropDownOpen = true;
                }
            }
            catch (Exception e)
            {
            }
        }
        }//addFixedOverHead method ends

        //this returns the month if it is already in the fixed overhead table eles returs null
        public string getmonth(int month, int year)
        {

            string fixID = "";

            try
            {
                using (adoraDBContext a = new adoraDBContext())
                {
                    var mnth = (from ea in a.FixedOverheads
                                where (ea.Year == year && ea.Month == month)
                                select ea.FixID
                  ).ToList();

                    if (mnth.Count() > 0)
                    {

                        fixID = mnth.First();
                    }
                    else
                        fixID = null;
                    return fixID;
                }

            }
            catch (Exception ex)
            {
                addException(ex, "getmonth");
                return null;
            }
        }//getmonth methods ends
        // This method calculates total price for given item and display it in a given currency type
        public double calctotalPrice(double pricePerPiece, int noOfPieces, String currency) 
        {
            double total = (pricePerPiece * noOfPieces);            // Calculates the total Price in LKR
            double trueValue = 0;

            // If the user selected currency type is not LKR
            if (currency != "LKR") 
            { 
                using (adoraDBContext a = new adoraDBContext())
                {
                    // Linq query to get the ID of the currency which is specified by the user
                    var id = (from e in a.CurCategories
                              where (e.Category == currency)
                              select e.CurCatID).SingleOrDefault();

                    // Linq query to get the value of the currency specified by the user
                    var val = (from s in a.Currencies
                               where s.CurrencyCategory == id
                               select s.Value).ToList();
                    // Convert the retrieved value to double
                    double value = Convert.ToDouble(val.Last());

                    // Convert the LKR to required currency type
                    trueValue = total / value;
                }
        }

        // If the selected currency is LKR
        else 
            {
                trueValue = total;
            }
            
            return trueValue;
        }
 public StockLotsSales()
 {
     InitializeComponent();
     _context = new adoraDBContext();                 // Initialize DB Context
     _handler = new StockLotSalesHandle();            // Initialize Handler
     _dao = new StockLotSalesDAO();                   // Initialize Data access object
     _validator = new StockLotsSalesValidator();      // Initialize validator object
     _userHandler = new LoginDetails();               // Initialize user handler object
     _val = new Validations();
 }
        //this method returns a list of fabric types
        public List<string> getFabTypes()
        {
            try
            {
                using (adoraDBContext a = new adoraDBContext())
                {
                    var items = (from e in a.Fabrics

                                 select e.Category
                   ).Distinct().ToList();

                    return items;
                }
            }
            catch (ArgumentException argumentException)
            {
                addException(argumentException, "getFabTypes()");
                return null;
            }
        }
        //this method update stockin hand table when actual cost is calculated
        public bool updateStock(string id, string actId)
        {
            try{
                using (adoraDBContext a = new adoraDBContext())
                {
                    StockInHand stockObj = _context.StockInHands.First(i => i.StockID == id);
                    stockObj.ACostID = actId;
                    int chk = _context.SaveChanges();
                    if (chk != -1)
                        return true;
                    else
                        return false;
                }
            }
            catch (InvalidCastException invalidCastException)
            {
                addException(invalidCastException, "updateStock()");
                return false;
            }
 
        }
          private void populateFabID(ComboBox fabID,ComboBox fabCat)
        {
            String category =null;

            if ((fabCat.SelectedItem) != null)
            {
                category = fabCat.SelectedValue.ToString();

                try
                {
                    using (adoraDBContext a = new adoraDBContext())
                    {
                        var fbID = (from e in a.Fabrics
                                     where e.Category == category
                                     select e.FabID
                       ).Distinct().ToList();

                        fabID.ItemsSource = fbID;
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.InnerException.ToString());
                }
            }
                 
        }
        // This method reloads the table displaying data
        // @returns nothing
        private void refreshTable()
        {
            // Create new viewsource and set the current viewsource to it
            System.Windows.Data.CollectionViewSource showBnSDetailViewSource =
                ((System.Windows.Data.CollectionViewSource)(this.FindResource("showBnSDetailViewSource")));

            // Create new db Context
            adoraDBContext adbc = new adoraDBContext();
            adbc.BnSFrequencies.Load(); // Reload BnSFrequency table
            adbc.showBnSDetails.Load(); // Reload showBnSDetails table

            // Reassign the viewsource with reloaded BnSDetails view
            showBnSDetailViewSource.Source = adbc.showBnSDetails.Local; 
        }
        private void refreshTable()
        {
            System.Windows.Data.CollectionViewSource showCurDetailViewSource =
                ((System.Windows.Data.CollectionViewSource)(this.FindResource("showCurDetailViewSource")));

            adoraDBContext adbc = new adoraDBContext();
            adbc.showCurDetails.Load();

            showCurDetailViewSource.Source = adbc.showCurDetails.Local;

            System.Windows.Data.CollectionViewSource userViewSource =
                ((System.Windows.Data.CollectionViewSource)(this.FindResource("userViewSource")));

            adbc.Users.Load();

            userViewSource.Source = adbc.Users.Local;
        }
        private void populateCurrencyTypes(ComboBox cmbBox)
        {
            try
            {
                using (adoraDBContext a = new adoraDBContext())
                {
                    var types = (from e in a.CurCategories
                                 select e.Category
                   ).Distinct().ToList();

                    cmbBox.ItemsSource = types;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.InnerException.ToString());
            }
        }
        private void dropCurrency_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((txtAddTotalCost.Text != null && txtAddTotalCost.Text != "") && (txtAddCPP.Text != null && txtAddCPP.Text != ""))
            {
                int No = Convert.ToInt32(txtAddNoPieces.Text);
                double PPP = Convert.ToDouble(txtAddPricePiece.Text);
                double Trans = Convert.ToDouble(txtAddTrans.Text);
                double SupCom = Convert.ToDouble(txtAddSupComm.Text);
                double Misc = Convert.ToDouble(txtAddMisc.Text);

                StockLotPurchaseHandle stl = new StockLotPurchaseHandle();

                double total = Convert.ToDouble(stl.CalcTotShipment(No, PPP, Trans, SupCom, Misc));
                //txtAddTotalCost.Text = value1.ToString("0.00");

                double actual = Convert.ToDouble(stl.CalcCPP(No, PPP, Trans, SupCom, Misc));
                //txtAddCPP.Text = value2.ToString("0.00");

                double trueTotal = 0;
                double trueActual = 0;
                if (dropCurrency.SelectedValue.ToString() != "LKR")
                {

                    using (adoraDBContext a = new adoraDBContext())
                    {
                        var id = (from ee in a.CurCategories
                                  where (ee.Category == dropCurrency.SelectedValue.ToString())
                                  select ee.CurCatID).SingleOrDefault();
                        var val = (from s in a.Currencies
                                   where s.CurrencyCategory == id
                                   select s.Value).ToList();

                        double value = Convert.ToDouble(val.Last());
                        trueTotal = total / value;
                        trueActual = actual / value;
                    }
                }
                else
                {
                    trueTotal = total;
                    trueActual = actual;
                }

                //MessageBox.Show(dropCurrency.SelectedValue.ToString());

                txtAddTotalCost.Text = trueTotal.ToString("F");
                txtAddCPP.Text = trueActual.ToString("F");

                curlbl1.Content = dropCurrency.SelectedValue.ToString();
                curlbl2.Content = dropCurrency.SelectedValue.ToString();
            }
        }
 //populate combo box unit
 public void populateAccUnit(ComboBox cmbBox)
 {
     try
     {
         using (adoraDBContext a = new adoraDBContext())
         {
             var unitType = (from e in a.Accessories
                            select e.UnitType
            ).Distinct().ToList();
             cmbBox.ItemsSource = unitType;
         }
     }
     catch (Exception e)
     {
     }
 }
          private void fillvalsToTextAcc(ComboBox accID)
          {
              if (accID.SelectedItem != null)
              {
                  try
                  {
                      String accesID = accID.Text;
                      lbleditAssID.Content = accesID;

                      using (adoraDBContext a = new adoraDBContext())
                      {
                          
                          var Category = (from e in a.Accessories
                                          where (e.AccID == accesID)
                                          select e.Category).SingleOrDefault();
                          var pricePerunit = (from e in a.Accessories
                                              where (e.AccID == accesID)
                                              select e.PricePerUnit).SingleOrDefault();
                          var noOfUnits = (from s in a.Accessories
                                           where (s.AccID == accesID)
                                         select s.NoOfUnits).SingleOrDefault();
                          var transport = (from s in a.Accessories
                                           where (s.AccID == accesID)
                                           select s.TransportCost).SingleOrDefault();
                          var unit = (from s in a.Accessories
                                           where (s.AccID == accesID)
                                           select s.UnitType).SingleOrDefault();


                          cmbFOBPAddAccUnit.SelectedItem = unit.ToString();
                          cmbFOBPAddAccType.SelectedItem = Category.ToString();
                          txtFOBPAddAccPricePerUnit.Text = pricePerunit.ToString();
                          txtFOBPAddAccNoOfUnits.Text = noOfUnits.ToString();
                          txtFOBPAddAccCourierTransport.Text = transport.ToString();
                          calAss();
                          btnFOBPAddAccAdd.Content = "Update";

                      }
                  }
                  catch (Exception e)
                  {
                      MessageBox.Show(e.InnerException.ToString());
                  }
              }
              else
              {

              }
          }
        // this section is use to refresh the table
        private void refreshTable()
        {

            System.Windows.Data.CollectionViewSource showFobSalesDataSource =

                ((System.Windows.Data.CollectionViewSource)(this.FindResource("fOBSalesFrequencyViewSource")));

            // creating the new databse context object
            adoraDBContext adbc = new adoraDBContext();

            // loading the FOBSalesFrequencies table
            adbc.FOBSalesFrequencies.Load();

            showFobSalesDataSource.Source = adbc.FOBSalesFrequencies.Local;

        }
        // This method returns a frequency object according to the given details
        public BnSFrequency getFrequency(String shipId, int freqId, adoraDBContext _Context)
        {
            try
            {
                // LINQ query to get the required frequency object
                var freq = (from s1 in _Context.BnSFrequencies
                            where (s1.ShipmentID == shipId && s1.FrequencyID == freqId)
                            select s1).FirstOrDefault();

                return freq;
            }
            catch (ArgumentNullException e)
            {
                addException(e, "updateFrequency");
                return null;
            }
        }
        private void populateShipmentNames(ComboBox cmbBox)
        {
            try
            {
                using (adoraDBContext a = new adoraDBContext())
                {
                    var shipments = (from e in a.PurchasingShipments
                                     select e.Title
                   ).Distinct().ToList();

                    cmbBox.ItemsSource = shipments;
                }
                txtDelDate.SelectedIndex = -1;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.InnerException.ToString());
            }
        }
        public void refresh()
        {
            System.Windows.Data.CollectionViewSource purchasingShipmentViewSource =
                     ((System.Windows.Data.CollectionViewSource)(this.FindResource("purchasingShipmentViewSource")));

            // Load is an extension method on IQueryable,  
            // defined in the System.Data.Entity namespace. 
            // This method enumerates the results of the query,  
            // similar to ToList but without creating a list. 
            // When used with Linq to Entities this method  
            // creates entity objects and adds them to the context.
            adoraDBContext adb = new adoraDBContext();
            adb.PurchasingShipments.Load();

            // After the data is loaded call the DbSet<T>.Local property  
            // to use the DbSet<T> as a binding source. 

            purchasingShipmentViewSource.Source = adb.PurchasingShipments.Local;

            btnEdit.Visibility = Visibility.Hidden;
        
        }
        }//updateFixData method ends

        //this method return the fixed ID when the month and year
        public string getIdByMonthNYear(int month, int year)
        {
            using (adoraDBContext a = new adoraDBContext())
            {
                var fid = (from ea in a.FixedOverheads
                           where (ea.Year == year && ea.Month == month)
                           select ea.FixID
              ).ToList();
                return fid.First();

            }
        }//getIdByMonthNYear mothod ends
        }//deleteFixOH method ends

        public List<int?> getMonthByYear(int year)
        {
            try
            {
                using (adoraDBContext a = new adoraDBContext())
                {
                    var mnth = (from e in a.FixedOverheads
                                where e.Year == year
                                select e.Month
                   ).Distinct().ToList();

                    return mnth; 
                }
            }
            catch (Exception eb)
            {
                addException(eb, "getMonthByYear()");
                return null; 
            }
        }//getmonthebyyear method ends
 public void populateAccCat(ComboBox cmbBox)
 {
     try
     {
         using (adoraDBContext a = new adoraDBContext())
         {
             var catog = (from e in a.Accessories
                          select e.Category
            ).Distinct().ToList();
             cmbBox.ItemsSource = catog;
         }
     }
     catch (Exception e)
     {
     }
 }
          private void populateAccID(ComboBox accID, ComboBox accCat)
          {
              String category = null;

              if ((accCat.SelectedItem) != null)
              {
                  category = accCat.SelectedValue.ToString();

                  try
                  {
                      using (adoraDBContext a = new adoraDBContext())
                      {
                          var accId = (from e in a.Accessories
                                       where e.Category == category
                                       select e.AccID
                         ).Distinct().ToList();

                          accID.ItemsSource = accId;
                      }
                  }
                  catch (Exception e)
                  {
                      MessageBox.Show(e.InnerException.ToString());
                  }
              }

          }
          private void fillvalsToTextFab(ComboBox fabID)
          {
              if (fabID.SelectedItem != null)
              {
                  try
                  {
                      String fabricID = fabID.Text;
                      lbleditFabID.Content = fabricID;

                      using (adoraDBContext a = new adoraDBContext())
                      {
                         
                          var Category = (from e in a.Fabrics
                                            where (e.FabID == fabricID)
                                            select e.Category).SingleOrDefault();
                          var pricePerYard = (from e in a.Fabrics
                                             where (e.FabID == fabricID)
                                             select e.PricePerYard).SingleOrDefault();
                          var yardage = (from s in a.Fabrics
                                            where (s.FabID == fabricID)
                                         select s.Yardage).SingleOrDefault();
                          var transport = (from s in a.Fabrics
                                         where (s.FabID == fabricID)
                                           select s.TransportCost).SingleOrDefault();


                          cmbFOBPAddFabType.SelectedItem = Category.ToString();
                          txtFOBPAddFabPricePerYard.Text = Convert.ToDouble(pricePerYard).ToString("0.00"); 
                          txtFOBPAddFabYardage.Text = Convert.ToDouble(yardage).ToString("0.00"); 
                          txtFOBPAddFabCourierTransport.Text =Convert.ToDouble(transport).ToString("0.00"); 
                          calFab();
                          btnFOBPAddFab.Content = "Update";
                           
                      }
                  }
                  catch (Exception e)
                  {
                      MessageBox.Show(e.InnerException.ToString());
                  }
              }
              else
              {
                
              }
          }
        private void fillForEdit()
        {

            btnEdit.Visibility = Visibility.Visible;
            string ShipmentID = null;
            lblShipID.Content = ShipmentID;
            string ShipName = txtDelShipName.Text;
            //System.DateTime ShipDate = Convert.ToDateTime(txtDelDate.SelectedValue);


            try
            {
                using (adoraDBContext ad = new adoraDBContext())
                {
                    lblShipID.Content = txtDelDate.SelectedValue.ToString();
                    ShipmentID = lblShipID.Content.ToString();
                   

                    var NoPieces = (from ab in ad.PurchasingShipments
                                    where (ab.ShipmentID == ShipmentID)
                                    select ab.NoOfPieces).SingleOrDefault();

                    var PPP = (from ab in ad.PurchasingShipments
                               where (ab.ShipmentID == ShipmentID)
                               select ab.PricePerPiece).SingleOrDefault();

                    var Trans = (from ab in ad.PurchasingShipments
                                 where (ab.ShipmentID == ShipmentID)
                                 select ab.TransportCost).SingleOrDefault();

                    var SupCom = (from ab in ad.PurchasingShipments
                                  where (ab.ShipmentID == ShipmentID)
                                  select ab.SupplierCommission).SingleOrDefault();

                    var Misc = (from ab in ad.PurchasingShipments
                                where (ab.ShipmentID == ShipmentID)
                                select ab.Micelleneous).SingleOrDefault();

                    var Date = (from ab in ad.PurchasingShipments
                                where (ab.ShipmentID == ShipmentID)
                                select ab.date).SingleOrDefault();

                    txtAddDate.SelectedDate = Convert.ToDateTime(Date.ToString());
                    txtAddShipName.Text = txtDelShipName.Text;
                    txtAddNoPieces.Text = NoPieces.ToString();
                    txtAddPricePiece.Text = PPP.ToString();
                    txtAddTrans.Text = Trans.ToString();
                    txtAddSupComm.Text = SupCom.ToString();
                    txtAddMisc.Text = Misc.ToString();

                }
            }
            catch (Exception e)
            {
               // MessageBox.Show(e.ToString());
            }
        
        }
        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);  
              }
            
        }
        }//getmonthebyyear method ends

        public void populateYears(ComboBox cmbBox, ComboBox cmbFOHEditMonth)
        {
            cmbBox.SelectedIndex = -1;
            cmbFOHEditMonth.SelectedIndex = -1;
            try
            {
                using (adoraDBContext a = new adoraDBContext())
                {
                    var year = (from e in a.FixedOverheads select e.Year).Distinct().ToList();
                    cmbBox.ItemsSource = year;
                }
            }
            catch (ArgumentException argumentException)
            {
                addException(argumentException, "populateYears()");
            }
        }//populateYears method ends
        private void populateShipmentID(ComboBox ID, ComboBox shipName)
        {
            String shipmentName = null;

            if ((shipName.SelectedItem) != null)
            {
                shipmentName = shipName.SelectedValue.ToString();

                try
                {
                    using (adoraDBContext a = new adoraDBContext())
                    {
                        var ids = (from e in a.PurchasingShipments
                                     where e.Title == shipmentName
                                     select e.ShipmentID
                       ).Distinct().ToList();

                        ID.ItemsSource = ids;
                        //date.SelectedIndex = 0;
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                }
            }

        }
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            ValidateValues();

            bool a = lblAddNoPieces.IsVisible;
            bool b = lblAddTrans.IsVisible;
            bool c = lblAddSupCom.IsVisible;
            bool d = lblAddMisc.IsVisible;
            bool f = lblAddPPP.IsVisible;
            bool g = lblAddDate.IsVisible;
            bool h = lblAddShipName.IsVisible;

            if (a || b || c || d || f || g || h)
            {
                MessageBox.Show("Check Values Again", "Message");
            }
            else
            {
                StockLotPurchaseHandle stl = new StockLotPurchaseHandle();

                int No = Convert.ToInt32(txtAddNoPieces.Text);
                double PPP = Convert.ToDouble(txtAddPricePiece.Text);
                double Trans = Convert.ToDouble(txtAddTrans.Text);
                double SupCom = Convert.ToDouble(txtAddSupComm.Text);
                double Misc = Convert.ToDouble(txtAddMisc.Text);
                string ShipID = lblShipID.Content.ToString();

                double total = stl.CalcTotShipment(No, PPP, Trans, SupCom, Misc);
                double actualcostpp = stl.CalcCPP(No, PPP, Trans, SupCom, Misc);

                decimal pPPP = Convert.ToDecimal(PPP);
                decimal pTrans = Convert.ToDecimal(Trans);
                decimal pSupCom = Convert.ToDecimal(SupCom);
                decimal pMisc = Convert.ToDecimal(Misc);
                string pShipName = txtAddShipName.Text;
                DateTime pDate = Convert.ToDateTime(txtAddDate.Text);
                

                try
                {
                    adoraDBContext con = new adoraDBContext();
                    PurchasingShipment ps = _context.PurchasingShipments.First(i => i.ShipmentID == ShipID);
                    ps.PricePerPiece = pPPP;
                    ps.TransportCost = pTrans;
                    ps.SupplierCommission = pSupCom;
                    ps.Micelleneous = pMisc;
                    ps.Title = pShipName;
                    ps.date = pDate;

                    _context.SaveChanges();
                    populateShipmentNames(txtDelShipName);
                    this.purchasingShipmentDataGrid.Items.Refresh();
                    _context.PurchasingShipments.Load();
                    System.Windows.MessageBox.Show("Succesfully Updated", "Done", MessageBoxButton.OK, MessageBoxImage.Information);
                    refresh();
                    reset();

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

            }

        }