コード例 #1
0
        private async void LoadUserList(string connectionString, ListBox listbox)
        {
            listbox.Items.Clear();
            listbox.Items.Add("Loading...");

            try
            {
                using (var model = new WintotalModel(connectionString))
                {
                    var users = await (from n in model.QuickListNames
                                       join q in model.QuickLists on n.QLNameID equals q.QLNameID into qlstats
                                       orderby n.Name
                                       select new WintotalUser
                                       {
                                           QLNameID = n.QLNameID,
                                           Name = n.Name + " - " + qlstats.Count() + " list(s)"
                                       }).ToListAsync();

                    listbox.Items.Clear();
                    listbox.SelectedValuePath = "QLNameID";
                    listbox.DisplayMemberPath = "Name";

                    foreach (var user in users.Distinct())
                    {
                        listbox.Items.Add(user);
                    }
                }
            }
            catch (Exception e)
            {
                UiUtilities.ShowErrorMessage("An error occurred loading data: " + e.Message);
            }
        }
コード例 #2
0
        public static void CopyQuickLists(int sourceQlNameID, int destQlNameID, string sourceConnStr, string destConnStr)
        {
            // The technique used to copy the quick lists came from http://stackoverflow.com/a/18114082/132374
            try
            {
                using (var sourceModel = new WintotalModel(sourceConnStr))
                {
                    using (var destinationModel = new WintotalModel(destConnStr))
                    {
                        var quickLists = sourceModel.QuickLists
                            .Where(q => q.QLNameID == sourceQlNameID)
                            .Include("QuickListEntries")
                            .AsNoTracking();
                        foreach (var quickList in quickLists.ToList())
                        {
                            // Assign the quick list to the destination user
                            quickList.QLNameID = destQlNameID;

                            // The PK value will be recreated
                            quickList.QLID = 0;

                            destinationModel.QuickLists.Add(quickList);
                        }

                        destinationModel.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                UiUtilities.ShowErrorMessage("An error occurred while copying the quick lists: " + e.Message);
            }
        }
コード例 #3
0
        public static void DeleteQuickListsOfUser(int qlNameID, string connectionString)
        {
            try
            {
                using (var model = new WintotalModel(connectionString))
                {
                    var quickLists = from q in model.QuickLists
                                     where q.QLNameID == qlNameID
                                     select q;
                    foreach (var quickList in quickLists.ToList())
                    {
                        model.QuickLists.Remove(quickList);
                    }

                    model.SaveChanges();
                }
            }
            catch (Exception e)
            {
                UiUtilities.ShowErrorMessage("An error occurred while attempting to delete the destination "
                    + "user's quick lists: " + e.Message);
            }
        }