Ejemplo n.º 1
0
        public override bool Remove(Category category)
        {
            try {
                category = Get(category.CategoryID);
                if (category != null)
                {
                    foreach (var referencedProp in
                             PropsRepository.Instanse.GetAll(prop => prop.CategoryID == category.CategoryID))
                    {
                        referencedProp.CategoryID = null;
                        PropsService.Instanse.Insert(referencedProp);
                    }
                    foreach (var referencedMaterial in
                             MaterialsRepository.Instanse.GetAll(material => material.CategoryID == category.CategoryID))
                    {
                        referencedMaterial.CategoryID = null;
                        MaterialsService.Insert(referencedMaterial);
                    }

                    LogsService.Instanse.Insert(new Log {
                        HostTable = (short)HostTable.Categories,
                        Details   = Log.CategoryDetailer(category, ActionType.Removed)
                    });
                    CategoriesRepository.Instanse.DeleteAndSubmit(category);
                    return(true);
                }
                return(false);
            } catch (Exception exception) {
                Logger.Write(exception);
                return(false);
            }
        }
Ejemplo n.º 2
0
        protected override void SaveWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (ValidateFields())
            {
                var      initialAmount = 0;
                Material material      = null;
                if (EditMode)
                {
                    material = _current;
                }

                if (material == null)
                {
                    object returnValue;
                    uint   temp;
                    if (InputWindowHelpers.Show(this, x => uint.TryParse(x.ToString(), out temp),
                                                MaterialsResources.InitialAmountDescription,
                                                MaterialsResources.InitialAmount, out returnValue, 0))
                    {
                        initialAmount = int.Parse(returnValue.ToString());
                    }
                    material = new Material();
                }
                material.Name          = cmbNames.Text.Trim();
                material.Unit          = (short)cmbMesureUnit.SelectedIndex;
                material.LowestAmount  = int.Parse(tbLowestAmount.Text);
                material.Formula       = tbFormula.Text;
                material.MolecularMass = tbMolecularMass.Text;
                material.Description   = tbDescription.Text.Trim();
                if (cmbCategories.SelectedValue != null)
                {
                    material.CategoryID = (Guid)cmbCategories.SelectedValue;
                }

                if (MaterialsService.Insert(material, initialAmount))
                {
                    Global.SubmissionSuceeded(this);
                    EditMode             = btnCancelChanges.IsEnabled = ChangesHappened = false;
                    btnDelete.IsEnabled  = cutTextBox.IsEnabled = true;
                    cmbNames.ItemsSource = MaterialsService.Instanse.GetAll();
                    ResetFields();
                    TryToLoad();
                }
                else
                {
                    Global.SubmissionFailed(this);
                }
            }
            aiLoader.Visibility = Visibility.Collapsed;
            OnSaving            = false;
        }