private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            m_RunningApps.Clear();
            IDictionary <IntPtr, String> runningApps = ScreenCast.EnumWindows();

            foreach (var item in runningApps)
            {
                m_RunningApps.Add(new RunningApp(item.Key, item.Value, ScreenCast.GetSmallWindowIcon(item.Key)));
            }
            m_RunningApps.Add(new RunningApp(IntPtr.Zero, "Entire screen", null));
        }
Esempio n. 2
0
        public void AddRangeTest2()
        {
            var collection = new MyObservableCollection <int>();

            Enumerable.Range(10, 15).ForEach(val => collection.Add(val));
            int initCount     = collection.Count;
            int attachedCount = 0;

            collection.ItemAttached += (sender, newItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                attachedCount++;
            };
            int addedCount = 0;

            collection.ItemAdded += (sender, newItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                addedCount++;
            };

            var newItems = Enumerable.Range(0, 5).ToArray();

            collection.AddRange(newItems);
            Assert.AreEqual(attachedCount, newItems.Length);
            Assert.AreEqual(addedCount, newItems.Length);
            Assert.AreEqual(newItems.Length, collection.Count - initCount);
            foreach (var item in newItems)
            {
                Assert.IsTrue(collection.Contains(item));
            }
        }
Esempio n. 3
0
        /*
         *      private string conString = Properties.Settings.Default.StoreDBConnString;
         *
         *      public MyObservableCollection<Product> GetProducts()
         *      {
         *          hasError = false;
         *          SqlConnection con = new SqlConnection(conString);
         *          SqlCommand cmd = new SqlCommand("GetProducts", con);
         *          cmd.CommandType = CommandType.StoredProcedure;
         *
         *          MyObservableCollection<Product> products = new MyObservableCollection<Product>();
         *          try
         *          {
         *              con.Open();
         *              SqlDataReader reader = cmd.ExecuteReader();
         *              while (reader.Read())
         *              {
         *                  //create a Product object for the row
         *                  SqlProduct sqlProduct = new SqlProduct(
         *                      (int) reader["ProductId"],
         *                      (string)reader["ModelNumber"],
         *                      (string)reader["ModelName"],
         *                      (decimal)reader["UnitCost"],
         *                      GetStringOrNull(reader, "Description"),
         *                      (String)reader["CategoryName"]);
         *                  products.Add(sqlProduct.SqlProduct2Product());
         *              } //while
         *          } //try
         *          catch (SqlException ex)
         *          {
         *              errorMessage = "GetProducts SQL error, " + ex.Message;
         *              hasError = true;
         *          }
         *          catch (Exception ex)
         *          {
         *              errorMessage = "GetProducts error, " + ex.Message;
         *              hasError = true;
         *          }
         *          finally
         *          {
         *              con.Close();
         *          }
         *          return products;
         *      } //GetProducts()
         */
        public MyObservableCollection <Product> GetProducts()
        {
            hasError = false;
            MyObservableCollection <Product> products = new MyObservableCollection <Product>();

            try
            {
                LinqDataContext dc    = new LinqDataContext();
                var             query = from q in dc.LinqProducts
                                        select new SqlProduct {
                    ProductId   = q.ProductID, ModelNumber = q.ModelNumber,
                    ModelName   = q.ModelName, UnitCost = (decimal)q.UnitCost,
                    Description = q.Description, CategoryName = q.LinqCategory.CategoryName
                };
                foreach (SqlProduct sp in query)
                {
                    products.Add(sp.SqlProduct2Product());
                }
            } //try
            catch (Exception ex)
            {
                errorMessage = "GetProducts() error, " + ex.Message;
                hasError     = true;
            }
            return(products);
        } //GetProducts()
        public MyObservableCollection <Product> GetProducts()
        {
            hasError = false;
            MyObservableCollection <Product> products = new MyObservableCollection <Product>();

            try
            {
                ContactDBEntities3 db = new ContactDBEntities3();
                var query             = from q in db.Contacts
                                        select new SqlProduct
                {
                    ContactID = q.ContactID,
                    FirstName = q.FirstName,
                    LastName  = q.LastName,
                    EmailID   = q.EmailID,
                    PhNo      = q.PhNo,
                    State     = q.State,
                    City      = q.City
                };


                foreach (SqlProduct sp in query)
                {
                    // products.Add(sp.SqlProduct2Product());
                    products.Add(sp.SqlProduct2Product());
                }
            } //try
            catch (Exception ex)
            {
                errorMessage = "GetProducts() error, " + ex.Message;
                hasError     = true;
            }
            return(products);
        } //GetProducts()
Esempio n. 5
0
 public void Add(MbBits4x4 bits4x4)
 {
     if (bits4x4 != null)
     {
         m_Row.Add(bits4x4);
     }
 }
 public override void RegisterMessenger()
 {
     MessengerInstance.Register <Address>(this, MSG_PERSON_ADD_ADDRESS, (address) =>
     {
         Addresses.Add(address);
     });
     MessengerInstance.Register <ContactMethod>(this, MSG_PERSON_ADD_CONTACT, (contact) =>
     {
         Contacts.Add(contact);
     });
     MessengerInstance.Register <Email>(this, MSG_PERSON_ADD_EMAIL, (email) =>
     {
         Emails.Add(email);
     });
     MessengerInstance.Register <Address>(this, MSG_PERSON_DEL_ADDRESS, (address) =>
     {
         Addresses.Remove(address);
     });
     MessengerInstance.Register <ContactMethod>(this, MSG_PERSON_DEL_CONTACT, (contact) =>
     {
         Contacts.Remove(contact);
     });
     MessengerInstance.Register <Email>(this, MSG_PERSON_DEL_EMAIL, (email) =>
     {
         Emails.Remove(email);
     });
 }
Esempio n. 7
0
        public MyObservableCollection <Libro> GetLibros()
        {
            hasError = false;
            MyObservableCollection <Libro> libros = new MyObservableCollection <Libro>();

            try
            {
                EnlaceLibreriaDataContext dc = new EnlaceLibreriaDataContext();
                var query = from q in dc.Libros
                            select new SqlLibro
                {
                    LibroID        = q.LibroID,
                    EditorialID    = q.EditorialID,
                    NombreAutor    = q.NombreAutor,
                    Genero         = q.Genero,
                    PrecioUnitario = Convert.ToDecimal(q.PrecioUnitario),
                    Descricion     = q.Descricion,
                };
                foreach (SqlLibro sp in query)
                {
                    libros.Add(sp.SqlLibro2Libro());
                }
            } //try
            catch (Exception ex)
            {
                errorMessage = "GetLibros() error, " + ex.Message;
                hasError     = true;
            }
            return(libros);
        }
Esempio n. 8
0
        public MyObservableCollection <Inmueble> GetInmuebles()
        {
            hasError = false;
            MyObservableCollection <Inmueble> inmueble = new MyObservableCollection <Inmueble>();

            try
            {
                LinqDataContext dc    = new LinqDataContext();
                var             query = from q in dc.LinqProducts
                                        select new SqlInmueble {
                    InmuebleId  = q.ProductID, Direccion = q.ModelNumber,
                    Vendedor    = q.ModelName, Precio = (decimal)q.UnitCost,
                    Descripcion = q.Description, Categoria = q.LinqCategory.CategoryName
                };
                foreach (SqlInmueble sp in query)
                {
                    inmueble.Add(sp.SqlProduct2Product());
                }
            }
            catch (Exception ex)
            {
                errorMessage = "GetInmuebles() error, " + ex.Message;
                hasError     = true;
            }
            return(inmueble);
        }
Esempio n. 9
0
        public static void AddFilm(
            FilmViewModel film,
            ref MyObservableCollection <ActorViewModel> actors,
            ref MyObservableCollection <ProducerViewModel> producers)
        {
            foreach (var actor in film?.Actors)
            {
                bool res = false;
                foreach (var act in actors)
                {
                    if (act.FullName == actor.FullName)
                    {
                        res = true;
                    }
                }
                if (!res)
                {
                    actors.Add(actor);
                }
            }
            var  prod = film.Prod;
            bool res1 = false;

            foreach (var producer in producers)
            {
                if (producer.Name == prod.Name)
                {
                    res1 = true;
                }
            }
            if (!res1)
            {
                producers.Add(new ProducerViewModel(prod));
            }
        }
Esempio n. 10
0
        public MyObservableCollection <Record> GetRecords()
        {
            hasError = false;
            MyObservableCollection <Record> products = new MyObservableCollection <Record>();

            try
            {
                TESTEntities ef    = new TESTEntities();
                var          query = from q in ef.TestTable
                                     select new SqlRecord
                {
                    IdReg    = q.idreg,
                    ElCampo1 = q.elCampo1,
                    ElCampo2 = q.elCampo2
                };
                foreach (SqlRecord sr in query)
                {
                    products.Add(sr.SqlProduct2Product());
                }
            } //try
            catch (Exception ex)
            {
                errorMessage = "GetRecords() error, " + ex.Message;
                hasError     = true;
            }
            return(products);
        } //GetProducts()
Esempio n. 11
0
        public void ShowMacroblock(Macroblock mb)
        {
            lock (this)
            {
                if ((m_Mb != mb) && mb != null)
                {
                    m_Mb = mb;
                    Int32[] bits4x4;
                    UInt32  YCount = 0, UCount = 0, VCount = 0;

                    m_DataSourceY.Clear();
                    m_DataSourceU.Clear();
                    m_DataSourceV.Clear();

                    m_TextBlockMacroblockInfo.Text = String.Format("{0} / MB {1}({2}, {3}) / Slice:{4} / Picture:{5} / Layer:{6}", m_Title, mb.Mb.Address, mb.Mb.X << 4, mb.Mb.Y << 4, mb.SliceId, mb.PictureId, mb.LayerId);

                    for (uint y = 0; y < 4; y++)
                    {
                        MbBits4x4Row rowY = new MbBits4x4Row();
                        MbBits4x4Row rowU = new MbBits4x4Row();
                        MbBits4x4Row rowV = new MbBits4x4Row();
                        for (uint x = 0; x < 4; x++)
                        {
                            // Y
                            bits4x4 = m_Mb.Mb.GetMbBits4x4(CommonYuvLine_t.CommonYuvLine_Y, m_DataType, x, y);
                            if (bits4x4 != null)
                            {
                                rowY.Add(new MbBits4x4(YCount++, x, y, bits4x4));
                            }
                            // U
                            bits4x4 = m_Mb.Mb.GetMbBits4x4(CommonYuvLine_t.CommonYuvLine_U, m_DataType, x, y);
                            if (bits4x4 != null)
                            {
                                rowU.Add(new MbBits4x4(UCount++, x, y, bits4x4));
                            }
                            // V
                            bits4x4 = m_Mb.Mb.GetMbBits4x4(CommonYuvLine_t.CommonYuvLine_V, m_DataType, x, y);
                            if (bits4x4 != null)
                            {
                                rowV.Add(new MbBits4x4(VCount++, x, y, bits4x4));
                            }
                        }
                        if (rowY.Row.Count > 0)
                        {
                            m_DataSourceY.Add(rowY);
                        }
                        if (rowU.Row.Count > 0)
                        {
                            m_DataSourceU.Add(rowU);
                        }
                        if (rowV.Row.Count > 0)
                        {
                            m_DataSourceV.Add(rowV);
                        }
                    }
                }
            }
        }
Esempio n. 12
0
        private void setSubBalanceColection()
        {
            bool envelopes = MyData.getInstance().Account.FindByid(this.AccountID).envelopes;
            MyObservableCollection <BalanceModel> tempSubs = new MyObservableCollection <BalanceModel>();

            if (this._Type == BalanceModel.BalType.Account && envelopes == true)
            {
                int[] ids =
                    (from EnvelopeLine in MyData.getInstance().EnvelopeLine
                     where EnvelopeLine.LineItemRow.accountID == this.AccountID
                     select EnvelopeLine.envelopeID).Distinct().ToArray();

                foreach (int envID in ids)
                {
                    BalanceModel bm = new BalanceModel(this.AccountID, envID, true);
                    if (bm.Balance != 0.0m)
                    {
                        tempSubs.Add(bm);
                    }
                }
            }
            else if (this._Type == BalanceModel.BalType.Envelope)
            {
                int[] ids =
                    (from EnvelopeLine in MyData.getInstance().EnvelopeLine
                     where EnvelopeLine.envelopeID == this.EnvelopeID
                     select EnvelopeLine.LineItemRow.accountID).Distinct().ToArray();

                foreach (int accID in ids)
                {
                    BalanceModel bm = new BalanceModel(accID, this.EnvelopeID, false);
                    if (bm.Balance != 0.0m)
                    {
                        tempSubs.Add(bm);
                    }
                }
            }

            if (tempSubs.Count > 0)
            {
                tempSubs.Sort(new BalanceModelComparer());
                this.SubBalances = tempSubs;
            }
        }
Esempio n. 13
0
        public ScreenHdr(Elt elt)
        {
            InitializeComponent();

            m_Elements = new MyObservableCollection <Elt>();
            m_Elements.Add(elt); // we want element at zero to be displayed

            DataSource       = m_Elements;
            treeView.Loaded += new RoutedEventHandler(treeView_Loaded);
        }
Esempio n. 14
0
 public override void RegisterMessenger()
 {
     MessengerInstance.Register <IdentificationDocument>(this, MSG_PERSON_ADD_DOCUMENT, (doc) =>
     {
         Documents.Add(doc);
     });
     MessengerInstance.Register <IdentificationDocument>(this, MSG_PERSON_DEL_DOCUMENT, (doc) =>
     {
         Documents.Remove(doc);
     });
 }
Esempio n. 15
0
        public async Task When_Collection_Reset()
        {
            var SUT = new ComboBox();

            try
            {
                WindowHelper.WindowContent = SUT;

                var c = new MyObservableCollection <string>();
                c.Add("One");
                c.Add("Two");
                c.Add("Three");

                SUT.ItemsSource = c;

                await WindowHelper.WaitForIdle();

                Assert.AreEqual(SUT.Items.Count, 3);

                using (c.BatchUpdate())
                {
                    c.Add("Four");
                    c.Add("Five");
                }

                SUT.IsDropDownOpen = true;

                // Items are materialized when the popup is opened
                await WindowHelper.WaitForIdle();

                Assert.AreEqual(SUT.Items.Count, 5);
                Assert.IsNotNull(SUT.ContainerFromItem("One"));
                Assert.IsNotNull(SUT.ContainerFromItem("Four"));
                Assert.IsNotNull(SUT.ContainerFromItem("Five"));
            }
            finally
            {
                SUT.IsDropDownOpen = false;
            }
        }
Esempio n. 16
0
        void Explode(CommonElt elt)
        {
            CommonEltVectorPtr elts = elt.getElements();
            Elt _elt;

            foreach (CommonElt e in elts)
            {
                if ((_elt = Elt.New(e)) != null)
                {
                    m_Elements.Add(_elt);
                }
            }
        }
        private void fillEnvelopeLines()
        {
            MyObservableCollection <SubLineRegModel> reg = new MyObservableCollection <SubLineRegModel>();

            FFDataSet.EnvelopeLineRow[] lines = MyData.getInstance().Envelope.FindByid(this.currentEnvelopeID).GetEnvelopeLineRows();

            foreach (FFDataSet.EnvelopeLineRow line in lines)
            {
                reg.Add(new SubLineRegModel(line));
            }

            reg.Sort(new SubLineRegModelComparer());
            this.SubRegistryLines = reg;
            this.calcEnvelopeBalance();
        }
Esempio n. 18
0
        public MyObservableCollection <ViewModel.ClassStudent> GetClassStudents()
        {
            hasError = false;
            MyObservableCollection <ViewModel.ClassStudent> products = new MyObservableCollection <ViewModel.ClassStudent>();

            try
            {
                DataClasses1DataContext dc = new DataClasses1DataContext();
                var query = from q in dc.ClassStudents
                            join c in dc.Classes on q.ClassId equals c.ID
                            join s in dc.Students on q.StudentId equals s.ID

                            select new SqlClassStudent
                {
                    Id                 = q.ID,
                    StudentId          = q.StudentId,
                    StudentName        = s.FirstName + " " + s.LastName,
                    ClassId            = q.ClassId,
                    ClassName          = c.ClassName,
                    ClassTuition       = c.Tuition,
                    TuitionPaid        = q.TuitionPaid,
                    Comment            = q.Comment,
                    UpdateDateTime     = q.UpdateDateTime,
                    InvoiceNumber      = q.InvoiceNumber,
                    CasherName         = q.CasherName,
                    CashReceived       = q.CashReceived,
                    CheckReceived      = q.CheckReceived,
                    CheckNumber        = q.CheckNumber,
                    CreditCardReceived = q.CreditCardReceived,
                    OtherReceived      = q.OtherReceived,
                    OtherSource        = q.OtherSource,
                    RegistrationDate   = q.RegistrationDate,
                    Grouping           = c.ClassName + " " + c.Semester + " " + c.Dayofweek + " " + c.Timeofweek
                };
                foreach (SqlClassStudent sp in query)
                {
                    products.Add(sp.SqlProduct2Product());
                }
            } //try
            catch (Exception ex)
            {
                errorMessage = "GetProducts() error, " + ex.Message;
                hasError     = true;
                log.Error("In StoreDB..GetClassStudents: " + ex.Message);
            }
            return(products);
        } //GetProducts()
        private void fillRegistryLines()
        {
            LineItemRegModel.setAccount(this.currentAccountID);

            MyObservableCollection <LineItemRegModel> reg = new MyObservableCollection <LineItemRegModel>();

            FFDataSet.LineItemRow[] lines = MyData.getInstance().Account.FindByid(this.currentAccountID).GetLineItemRows();

            foreach (FFDataSet.LineItemRow line in lines)
            {
                reg.Add(new LineItemRegModel(line));
            }

            reg.Sort(new RegistryComparer());
            this.RegistryLines = reg;
            this.calcAccountBalance();
        }
        public void reloadEnvelopeBalances()
        {
            MyObservableCollection <BalanceModel> tempEnv = new MyObservableCollection <BalanceModel>();

            foreach (FFDataSet.EnvelopeRow row in MyData.getInstance().Envelope)
            {
                if (row.closed == false && row.id > 0)
                {
                    tempEnv.Add(new BalanceModel(row));
                }
            }

            tempEnv.Sort(new BalanceModelComparer());

            this.Envelopes = tempEnv;
            this.RaisePropertyChanged("Envelopes");
        }
Esempio n. 21
0
        public TodoItemViewModel()
        {
            var db = App.conn;

            using (var statement = db.Prepare("SELECT Id, Title, Description, Time, Imguri FROM todolist"))
            {
                StringBuilder result = new StringBuilder();
                SQLiteResult  r      = statement.Step();
                while (SQLiteResult.ROW == r)
                {
                    for (int num = 0; num < statement.DataCount; num += 5)
                    {
                        allitems.Add(new Models.TodoItem((string)statement[num], (string)statement[num + 1], (string)statement[num + 2], Convert.ToDateTime((string)statement[num + 3]), new Uri((string)statement[num + 4])));
                    }
                    r = statement.Step();
                }
                if (SQLiteResult.DONE == r)
                {
                }
            }
        }
Esempio n. 22
0
        public void setTransaction(int transID)
        {
            MyObservableCollection <LineItemModel> credits = new MyObservableCollection <LineItemModel>();
            MyObservableCollection <LineItemModel> debits  = new MyObservableCollection <LineItemModel>();

            this.transactionRow = MyData.getInstance().Transaction.FindByid(transID);
            FFDataSet.LineItemRow[] lines = this.transactionRow.GetLineItemRows();


            foreach (FFDataSet.LineItemRow line in lines)
            {
                if (line.creditDebit == LineCD.CREDIT)
                {
                    credits.Add(new LineItemModel(line));
                }
                else
                {
                    debits.Add(new LineItemModel(line));
                }
            }

            LineItemModel.TransactionID = transID;

            this.Debits  = debits;
            this.Credits = credits;



            this.RaisePropertyChanged("Date");
            this.RaisePropertyChanged("TypeID");
            this.RaisePropertyChanged("TypeName");
            this.RaisePropertyChanged("Description");
            this.RaisePropertyChanged("ConfirmationNumber");
            this.RaisePropertyChanged("Complete");
            this.RaisePropertyChanged("TransactionError");
            this.RaisePropertyChanged("Credits");
            this.RaisePropertyChanged("Debits");
        }
Esempio n. 23
0
        } //AddProduct()

        public MyObservableCollection <ViewModel.MyStudent> GetStudentsByClass(int classId)
        {
            hasError = false;
            MyObservableCollection <ViewModel.MyStudent> products = new MyObservableCollection <ViewModel.MyStudent>();

            try
            {
                DataClasses1DataContext dc = new DataClasses1DataContext();
                var query = from q in dc.vwStudentByClasses
                            where q.ClassId == classId
                            select new MyStudent(q.ID, q.BirthDate + " " + q.Gender, q.FirstName, q.LastName);

                foreach (MyStudent sp in query)
                {
                    products.Add(sp);
                }
            } //try
            catch (Exception ex)
            {
                errorMessage = "GetProducts() error, " + ex.Message;
                hasError     = true;
            }
            return(products);
        } //GetProducts()
Esempio n. 24
0
        /// <summary>
        /// Adds the specified group to the collection
        /// </summary>
        /// <param name="group">The group to add</param>
        private void AddGroup(Group group)
        {
            //If the group has no name, create a default group
            if (String.IsNullOrEmpty(group.Name))
            {
                AddGroup(new Group());
            }
            int    index      = 0;
            bool   nameExists = true;
            String name       = "";

            //Check if the group name already exists. If so, create it with a number on the end.
            while (nameExists)
            {
                nameExists = false;
                if (index == 0)
                {
                    name = String.Copy(group.Name);
                }
                else
                {
                    name = String.Copy(group.Name) + index.ToString();
                }
                foreach (Group currGroup in _groups)
                {
                    if (name.Equals(currGroup.Name))
                    {
                        nameExists = true;
                    }
                }
                index++;
            }
            group.Name = name;
            _groups.Add(group);
            this.SelectedGroupIndex = this.Groups.Count;
        }
        public void reloadAccountBalances()
        {
            MyObservableCollection <BalanceModel> tempAcc = new MyObservableCollection <BalanceModel>();
            MyObservableCollection <BalanceModel> tempIn  = new MyObservableCollection <BalanceModel>();
            MyObservableCollection <BalanceModel> tempEx  = new MyObservableCollection <BalanceModel>();

            foreach (FFDataSet.AccountRow row in MyData.getInstance().Account)
            {
                if (row.closed == false && row.id > 0)
                {
                    if (row.catagory == SpclAccountCat.ACCOUNT)
                    {
                        tempAcc.Add(new BalanceModel(row));
                    }
                    else if (row.catagory == SpclAccountCat.EXPENSE)
                    {
                        tempEx.Add(new BalanceModel(row));
                    }
                    else if (row.catagory == SpclAccountCat.INCOME)
                    {
                        tempIn.Add(new BalanceModel(row));
                    }
                }
            }

            tempAcc.Sort(new BalanceModelComparer());
            tempEx.Sort(new BalanceModelComparer());
            tempIn.Sort(new BalanceModelComparer());

            this.Accounts = tempAcc;
            this.Expences = tempEx;
            this.Incomes  = tempIn;
            this.RaisePropertyChanged("Accounts");
            this.RaisePropertyChanged("Expences");
            this.RaisePropertyChanged("Incomes");
        }
Esempio n. 26
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (MainWindow.Paused)
            {
                return;
            }

            if (JobQueue.Count == 0 && PriorityJobQueue.Count == 0)
            {
                return;
            }

            var job = (PriorityJobQueue.Count > 0) ? PriorityJobQueue.Dequeue() : JobQueue.Dequeue();

            UIContext.Send((a) =>
            {
                try
                {
                    switch (job.Item2)
                    {
                    case Action.Add:
                        collection.Add(job.Item1);
                        break;

                    case Action.Remove:
                        if (equilityComparer == null)
                        {
                            collection.Remove(job.Item1);
                        }
                        else
                        {
                            T toRemove = default(T);
                            foreach (T item in collection)
                            {
                                if (equilityComparer(job.Item1, item))
                                {
                                    toRemove = item; break;
                                }
                            }
                            collection.Remove(toRemove);
                        }
                        break;
                    }
                }
                catch (Exception ex)
                {
                    // ignore for now
                }
            }, null);

            if (JobQueue.Count + PriorityJobQueue.Count >= 500)
            {
                timer.Interval = TimeSpan.FromMilliseconds(30);
            }
            else
            {
                timer.Interval = TimeSpan.FromMilliseconds(60);
            }

            JobFinished?.Invoke(this, job, collection);
        }
        public MyObservableCollection<Product> GetProducts()
        {
            hasError = false;
            MyObservableCollection<Product> products = new MyObservableCollection<Product>();
            try
            {
                ContactDBEntities3 db = new ContactDBEntities3();
                var query = from q in db.Contacts
                            select new SqlProduct
                            {
                                ContactID = q.ContactID,
                                FirstName  = q.FirstName,
                                LastName=q.LastName,
                                EmailID = q.EmailID,
                                PhNo=q.PhNo,
                                State = q.State,
                                City = q.City
                            };

                foreach (SqlProduct sp in query)
                    // products.Add(sp.SqlProduct2Product());
                    products.Add(sp.SqlProduct2Product());
            } //try
            catch (Exception ex)
            {
                errorMessage = "GetProducts() error, " + ex.Message;
                hasError = true;
            }
            return products;
        }
Esempio n. 28
0
        public async Task When_Full_Collection_Reset()
        {
            var SUT = new ComboBox();

            SUT.ItemTemplate = new DataTemplate(() => {
                var tb = new TextBlock();
                tb.SetBinding(TextBlock.TextProperty, new Windows.UI.Xaml.Data.Binding {
                    Path = "Text"
                });
                tb.SetBinding(TextBlock.NameProperty, new Windows.UI.Xaml.Data.Binding {
                    Path = "Text"
                });

                return(tb);
            });

            try
            {
                WindowHelper.WindowContent = SUT;

                var c = new MyObservableCollection <ItemModel>();
                c.Add(new ItemModel {
                    Text = "One"
                });
                c.Add(new ItemModel {
                    Text = "Two"
                });
                c.Add(new ItemModel {
                    Text = "Three"
                });

                SUT.ItemsSource = c;

                await WindowHelper.WaitForIdle();

                SUT.IsDropDownOpen = true;

                await WindowHelper.WaitForIdle();

                SUT.IsDropDownOpen = false;

                Assert.AreEqual(SUT.Items.Count, 3);

                using (c.BatchUpdate())
                {
                    c.Clear();
                    c.Add(new ItemModel {
                        Text = "Five"
                    });
                    c.Add(new ItemModel {
                        Text = "Six"
                    });
                    c.Add(new ItemModel {
                        Text = "Seven"
                    });
                }

                SUT.IsDropDownOpen = true;

                // Items are materialized when the popup is opened
                await WindowHelper.WaitForIdle();

                Assert.AreEqual(3, SUT.Items.Count);
                Assert.IsNotNull(SUT.ContainerFromItem(c[0]));
                Assert.IsNotNull(SUT.ContainerFromItem(c[1]));
                Assert.IsNotNull(SUT.ContainerFromItem(c[2]));

                Assert.IsNotNull(SUT.FindName("Seven"));
                Assert.IsNotNull(SUT.FindName("Five"));
                Assert.IsNotNull(SUT.FindName("Six"));
            }
            finally
            {
                SUT.IsDropDownOpen = false;
            }
        }
Esempio n. 29
0
        public void MyObservableCollectionTest()
        {
            char xChar         = '-';
            char xChar2        = '-';
            int  xIndex        = -1;
            var  collection    = new MyObservableCollection <char>();
            bool attachedEvent = false;

            collection.ItemAttached += (sender, newItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                Assert.AreEqual(xChar, newItem);
                Assert.AreEqual(xIndex, index);
                attachedEvent = true;
            };
            bool detachedEvent = false;

            collection.ItemDetached += (sender, oldItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                Assert.AreEqual(xChar2, oldItem);
                Assert.AreEqual(xIndex, index);
                detachedEvent = true;
            };
            bool addedEvent = false;

            collection.ItemAdded += (sender, newItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                Assert.AreEqual(xChar, newItem);
                Assert.AreEqual(xIndex, index);
                addedEvent = true;
            };
            bool removedEvent = false;

            collection.ItemRemoved += (sender, oldItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                Assert.AreEqual(xChar2, oldItem);
                Assert.AreEqual(xIndex, index);
                removedEvent = true;
            };
            bool movedEvent = false;

            collection.ItemMoved += (sender, oldIndex, newIndex) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                Assert.AreEqual(xChar, oldIndex);
                Assert.AreEqual(xIndex, newIndex);
                movedEvent = true;
            };
            bool changedEvent = false;

            collection.ItemChanged += (sender, oldItem, newItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                Assert.AreEqual(xChar2, oldItem);
                Assert.AreEqual(xChar, newItem);
                Assert.AreEqual(xIndex, index);
                changedEvent = true;
            };

            xChar  = 'a';
            xChar2 = xChar;
            xIndex = 0;
            collection.Add('a');
            Assert.IsTrue(addedEvent);
            Assert.IsTrue(attachedEvent);
            xChar  = 'b';
            xChar2 = xChar;
            xIndex = 1;
            collection.Add('b');

            collection.Remove('b');
            Assert.IsTrue(removedEvent);
            Assert.IsTrue(detachedEvent);
            removedEvent  = false;
            detachedEvent = false;
            collection.Add('b');
            addedEvent    = false;
            attachedEvent = false;
            xChar         = 'c';
            collection[1] = 'c';
            Assert.IsTrue(changedEvent);
            Assert.IsTrue(detachedEvent);
            Assert.IsTrue(attachedEvent);
            changedEvent  = false;
            detachedEvent = false;
            attachedEvent = false;

            int removedCount = 0;
        }
Esempio n. 30
0
    public static void Main()
    {
        MyObservableCollection <MyItem> list = new MyObservableCollection <MyItem> ();

        list.Add(new MyItem());
    }
Esempio n. 31
0
        /*
                private string conString = Properties.Settings.Default.StoreDBConnString;

                public MyObservableCollection<Product> GetProducts()
                {
                    hasError = false;
                    SqlConnection con = new SqlConnection(conString);
                    SqlCommand cmd = new SqlCommand("GetProducts", con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    MyObservableCollection<Product> products = new MyObservableCollection<Product>();
                    try
                    {
                        con.Open();
                        SqlDataReader reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            //create a Product object for the row
                            SqlProduct sqlProduct = new SqlProduct(
                                (int) reader["ProductId"],
                                (string)reader["ModelNumber"],
                                (string)reader["ModelName"],
                                (decimal)reader["UnitCost"],
                                GetStringOrNull(reader, "Description"),
                                (String)reader["CategoryName"]);
                            products.Add(sqlProduct.SqlProduct2Product());
                        } //while
                    } //try
                    catch (SqlException ex)
                    {
                        errorMessage = "GetProducts SQL error, " + ex.Message;
                        hasError = true;
                    }
                    catch (Exception ex)
                    {
                        errorMessage = "GetProducts error, " + ex.Message;
                        hasError = true;
                    }
                    finally
                    {
                        con.Close();
                    }
                    return products;
                } //GetProducts()
        */
        public MyObservableCollection<Product> GetProducts()
        {
            hasError = false;
            MyObservableCollection<Product> products = new MyObservableCollection<Product>();
            try
            {
                LinqDataContext dc = new LinqDataContext();
                var query = from q in dc.LinqProducts
                    select new SqlProduct{
                        ProductId = q.ProductID, ModelNumber = q.ModelNumber,
                        ModelName=q.ModelName, UnitCost = (decimal)q.UnitCost,
                        Description = q.Description, CategoryName = q.LinqCategory.CategoryName
                    };
                foreach (SqlProduct sp in query)
                    products.Add(sp.SqlProduct2Product());
            } //try
            catch(Exception ex)
            {
                errorMessage = "GetProducts() error, " + ex.Message;
                hasError = true;
            }
            return products;
        }