Ejemplo n.º 1
0
        protected override void OnDelete(Entity item, out string message, ref Action <Entity> afterConfirm)
        {
            if (afterConfirm == null)
            {
                throw new ArgumentNullException(nameof(afterConfirm));
            }

            message = ((Subject)item).SubjectCode + " - " + ((Subject)item).Description;

            afterConfirm = currentItem =>
            {
                try
                {
                    var deletedItem = (Subject)currentItem;


                    deletedItem.RowStatus = RecordStatus.DeletedRecord;

                    //Save to Database
                    var dataWriter = new SubjectDataWriter(App.CurrentUser.User.Username, deletedItem);
                    dataWriter.SaveChanges();


                    ItemDataCollection.Remove((Subject)currentItem);

                    App.LogAction("Subject", "Deleted Subject : " + deletedItem.SubjectCode);
                }
                catch (Exception ex)
                {
                    MessageDialog.ShowError(ex, this);
                }
            };
        }
Ejemplo n.º 2
0
        void LbSubjectsItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (loadingSubjects)
            {
                return;
            }

            if (e.Index == 0)
            {
                try
                {
                    ignoreServicesLoading = true;
                    loadingSubjects       = true;
                    LockUpdate(true);
                    if (e.NewValue == CheckState.Checked)
                    {                      //all
                        subjects.Clear();
                        subjects.AddRange(supportedSubjects);
                        for (int i = 1; i < lbSubjects.Items.Count; i++)
                        {
                            lbSubjects.SetItemCheckState(i, e.NewValue);
                        }
                    }
                    else if (e.NewValue == CheckState.Unchecked)
                    {
                        subjects.Clear();
                        subjects.Add((lbSubjects.Items[1] as SubjectContainer).Subject);

                        lbSubjects.SetItemCheckState(1, CheckState.Checked);

                        for (int i = 2; i < lbSubjects.Items.Count; i++)
                        {
                            lbSubjects.SetItemCheckState(i, e.NewValue);
                        }
                    }

                    SetLanguages(profile.GetLanguagePairs());

                    LanguagePairCollection to_delete = new LanguagePairCollection();
                    int index;
                    foreach (LanguagePair lp in history)
                    {
                        index = Languages.BinarySearch(lp);
                        if (index < 0)
                        {
                            to_delete.Add(lp);
                        }
                    }

                    foreach (LanguagePair lp in to_delete)
                    {
                        history.Remove(lp);
                    }
                    LoadHistory();
                }
                finally
                {
                    LockUpdate(false);
                    ignoreServicesLoading = false;
                    loadingSubjects       = false;
                    serviceItemsSettings  = null;                    //reset
                    LoadServices(false);
                }

                if (SubjectsChanged != null)
                {
                    SubjectsChanged(this, new EventArgs());
                }

                return;
            }


            SubjectContainer sc = (SubjectContainer)lbSubjects.Items[e.Index];

            if (e.NewValue == CheckState.Checked)
            {
                subjects.Add(sc.Subject);
            }
            else if (e.NewValue == CheckState.Unchecked)
            {
                if (subjects.Count == 1)
                {
                    int new_idx = e.Index;
                    new_idx++;
                    if (new_idx >= lbSubjects.Items.Count)
                    {
                        new_idx = 1;
                    }
                    lbSubjects.SetItemChecked(new_idx, true);
                }
                subjects.Remove(sc.Subject);
            }

            try
            {
                ignoreServicesLoading = true;
                SetLanguages(profile.GetLanguagePairs());
                LanguagePairCollection to_delete = new LanguagePairCollection();
                int index;
                foreach (LanguagePair lp in history)
                {
                    index = Languages.BinarySearch(lp);
                    if (index < 0)
                    {
                        to_delete.Add(lp);
                    }
                }

                foreach (LanguagePair lp in to_delete)
                {
                    history.Remove(lp);
                }
                LoadHistory();
            }
            finally
            {
                ignoreServicesLoading = false;
                serviceItemsSettings  = null;                //reset
                LoadServices(false);
            }

            if (SubjectsChanged != null)
            {
                SubjectsChanged(this, new EventArgs());
            }
        }