Beispiel #1
0
 private void OKBtn_Click(object sender, EventArgs e)
 {
     //todo: Check that this works as planned hn
     INCCDB.StratumDescriptor ToDelete = list.ElementAt(StratumIdComboBox.SelectedIndex);
     string name = ToDelete.Desc.Name;
     //Check for associated detectors, warn if associated
     DB.Strata strata = new DB.Strata();
     List<string> dets = strata.GetAssociationsByStratum(name);
     if (dets.Count > 0)
         if (MessageBox.Show ("There are detectors associated with this stratum.  Do you still want to delete?", "WARNING", MessageBoxButtons.YesNo) == DialogResult.No)
             return;
     //check for associated items, warn if associated
     ItemIdListImpl il = new ItemIdListImpl();
     List<ItemId> ItemList = il.GetListByStratumID(name);
     if (ItemList.Count > 0)
         if (MessageBox.Show("There are items associated with this stratum.  Do you still want to delete?", "WARNING", MessageBoxButtons.YesNo) == DialogResult.No)
             return;
     //Check acquire_recs for the stratum id, warn if used
     List<AcquireParameters> acq_with_stratum = new List<AcquireParameters>();
     Dictionary <INCCDB.AcquireSelector, AcquireParameters> all_acq = NC.App.DB.AcquireParametersMap();
     foreach (KeyValuePair<INCCDB.AcquireSelector, AcquireParameters> kv in all_acq)
     {
         if (((AcquireParameters)kv.Value).stratum_id.Name == name)
             acq_with_stratum.Add((AcquireParameters)kv.Value);
     }
     if (acq_with_stratum.Count > 0)
     {
         if (MessageBox.Show("There are acquisition records associated with this stratum.  Do you still want to delete?", "WARNING", MessageBoxButtons.YesNo) == DialogResult.No)
             return;
     }
     //they have chosen to go ahead with the delete, remove detector associations
     foreach (string det_name in dets)
     {
         strata.Unassociate(det_name);
     }
     if (NC.App.DB.DeleteStratum(ToDelete.Desc))
     {
         RefreshCombo();
     }
     else
         MessageBox.Show("Failed to delete stratum from DB", "There was a problem deleting this stratum from the database.", MessageBoxButtons.OKCancel);
     DialogResult = DialogResult.OK;
     // Refreshes global strata list
     list = NC.App.DB.StrataList(det);
     this.Close();
 }
Beispiel #2
0
        private void OKBtn_Click(object sender, EventArgs e)
        {
            //todo: Check that this works as planned hn
            INCCDB.StratumDescriptor ToDelete = list.ElementAt(StratumIdComboBox.SelectedIndex);
            string name = ToDelete.Desc.Name;

            //Check for associated detectors, warn if associated
            DB.Strata     strata = new DB.Strata();
            List <string> dets   = strata.GetAssociationsByStratum(name);

            if (dets.Count > 0)
            {
                if (MessageBox.Show("There are detectors associated with this stratum.  Do you still want to delete?", "WARNING", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }
            //check for associated items, warn if associated
            ItemIdListImpl il       = new ItemIdListImpl();
            List <ItemId>  ItemList = il.GetListByStratumID(name);

            if (ItemList.Count > 0)
            {
                if (MessageBox.Show("There are items associated with this stratum. Do you still want to delete?", "WARNING", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }
            //Check acquire_recs for the stratum id, warn if used
            List <AcquireParameters> acq_with_stratum = new List <AcquireParameters>();
            Dictionary <INCCDB.AcquireSelector, AcquireParameters> all_acq = NC.App.DB.AcquireParametersMap;

            foreach (KeyValuePair <INCCDB.AcquireSelector, AcquireParameters> kv in all_acq)
            {
                if (((AcquireParameters)kv.Value).stratum_id.Name == name)
                {
                    acq_with_stratum.Add((AcquireParameters)kv.Value);
                }
            }
            if (acq_with_stratum.Count > 0)
            {
                if (MessageBox.Show("There are acquisition records associated with this stratum. Do you still want to delete?", "WARNING", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }
            //they have chosen to go ahead with the delete, remove detector associations
            foreach (string det_name in dets)
            {
                strata.Unassociate(det_name);
            }
            if (NC.App.DB.DeleteStratum(ToDelete.Desc))
            {
                RefreshCombo();
            }
            else
            {
                MessageBox.Show("Failed to delete stratum from DB", "There was a problem deleting this stratum from the database.", MessageBoxButtons.OKCancel);
            }
            DialogResult = DialogResult.OK;
            // Refreshes global strata list
            list = NC.App.DB.StrataList(det);
            this.Close();
        }