Beispiel #1
0
        private void EnsureView(object source)
        {
            if (_isInitializing || _deferLevel > 0)
            {
                return;
            }

            // get the view
            ICollectionView view = null;

            if (source != null)
            {
                ViewRecord viewRecord = GetViewRecord(source);

                if (viewRecord != null)
                {
                    view = viewRecord.View;
                    _isViewInitialized = viewRecord.IsInitialized;

                    // bring view up to date with the CollectionViewSource
                    if (_version != viewRecord.Version)
                    {
                        //ApplyPropertiesToView(view);
                        viewRecord.Version = _version;
                    }
                }
            }

            // update the View property
            SetValue(ViewProperty, view);
        }
        private void EnsureView(object source)
        {
            ICollectionView view;

            if (this.isInitializing || this.deferLevel > 0)
            {
                return;
            }
            if (source == null)
            {
                view = null;
            }
            else
            {
                ViewRecord viewRecord = ViewManager.Current.GetViewRecord(source, this);
                view = viewRecord.View;
                this.isViewInitialized = viewRecord.IsInitialized;
                if (this.version != viewRecord.Version)
                {
                    this.ApplyPropertiesToView(view);
                    viewRecord.Version = this.version;
                }
            }
            this.SetValue(CollectionViewSource.ViewProperty, view);
        }
        public ViewRecord AddRecord(Record rcd, string token)
        {
            ViewRecord ViewRecord = new ViewRecord();

            try
            {
                var client = new HttpClient();
                client.DefaultRequestHeaders.Add("Authorization", token);
                var request = new HttpRequestMessage(HttpMethod.Post, new Uri(getTokenUrl));
                // Setup header(s)
                request.Headers.Add("Accept", "application/json");

                // Add body content
                var json = JsonConvert.SerializeObject(rcd);
                request.Content = new StringContent(
                    json.ToString(),
                    Encoding.UTF8,
                    "application/json"
                    );
                // Send the request
                var result = client.SendAsync(request).Result;
                ViewRecord = result.Content.ReadAsAsync <ViewRecord>().Result;
                return(ViewRecord);
            }
            catch (Exception ex)
            {
                return(ViewRecord);
            }
        }
        public IHttpActionResult PostRecord(ViewRecord viewRecord)
        {
            int    id     = JwtAuthUtil.GetId(Request.Headers.Authorization.Parameter);
            int    week   = Utility.GetWeek();
            Record record = new Record();

            foreach (var infoitem in viewRecord.StudentInfo)
            {
                record.Subject           = viewRecord.Subject;
                record.ClassId           = viewRecord.ClassId;
                record.LessonOrder       = viewRecord.LessonOrder;
                record.RollCallTime      = DateTime.Now;
                record.LessonDate        = DateTime.Today;
                record.RollCallTeacherId = id;
                record.Week       = (WeekType)week;
                record.StudentId  = infoitem.StudentId;
                record.Attendance = (AttendanceType)infoitem.Attendance;
                db.Records.Add(record);
                db.SaveChanges();
            }
            //return CreatedAtRoute("DefaultApi", new { id = record.Id }, record);
            return(Ok(new
            {
                code = 1,
                message = "點名成功"
            }));
        }
Beispiel #5
0
        private ViewRecord GetViewRecord(object source)
        {
            // Order of precendence in acquiring the View:
            // 1) If the CollectionView for this collection has been cached, then
            //    return the cached instance.
            // 2) If the collection is an ICollectionViewFactory use ICVF.CreateView()
            //    from the collection
            // 3) If the collection is an IList return a new ListCollectionView
            // 4) If the collection is an IEnumerable, return a new EnumerableCollectionView
            // 5) return null

            // if the view already exists, just return it
            ViewRecord viewRecord = GetExistingViewRecord(source);

            if (viewRecord != null)
            {
                return(viewRecord);
            }

            ICollectionView icv = null;

            ICollectionViewFactory icvf = source as ICollectionViewFactory;

            if (icvf != null)
            {
                // collection is a view factory - call its factory method
                icv = icvf.CreateView();
            }
            else
            {
                // collection is not a factory - create an appropriate view
                IList il = source as IList;
                if (il != null)
                {
                    icv = new ListCollectionView(il);
                }
                else
                {
                    // collection is not IList, wrap it
                    IEnumerable ie = source as IEnumerable;
                    if (ie != null)
                    {
                        icv = new EnumerableCollectionView(ie);
                    }
                }
            }

            // if we got a view, add it to the tables
            if (icv != null)
            {
                viewRecord = new ViewRecord(icv);
                this.CachedViews[source] = viewRecord;
            }

            return(viewRecord);
        }
Beispiel #6
0
        public ViewRecord PostRecord([FromBody] Record record)
        {
            if (!ModelState.IsValid)
            {
                throw new Exception("No valido");
            }
            db.Record.Add(record);
            db.SaveChanges();
            ViewRecord viewRecord = record;

            return(viewRecord);
        }
Beispiel #7
0
        //
        //  Internal Methods
        //

        // Return the default view for the given source.  This view is never
        // affiliated with any CollectionViewSource.  It may be a
        // CollectionViewProxy over the original view
        static internal CollectionView GetDefaultCollectionView(object source, bool createView, Func <object, object> GetSourceItem = null)
        {
            if (!IsValidSourceForView(source))
            {
                return(null);
            }

            DataBindEngine engine     = DataBindEngine.CurrentDataBindEngine;
            ViewRecord     viewRecord = engine.GetViewRecord(source, DefaultSource, null, createView, GetSourceItem);

            return((viewRecord != null) ? (CollectionView)viewRecord.View : null);
        }
        private void btnRecreateAddress_Click(object sender, EventArgs e)
        {
            ViewRecord row = gridView1.GetFocusedRow() as ViewRecord;

            if (row == null)
            {
                return;
            }
            long personOid = RecreateAddress(row);

            UpdateRows();
            gridView1.SetFocusedRowCellValue(colOid, personOid);
        }
 public IHttpActionResult PutRecord(ViewRecord viewRecord)
 {
     foreach (var infoitem in viewRecord.StudentInfo)
     {
         Record record = db.Records.Single(x => x.Id == infoitem.Id);
         record.RollCallTime = DateTime.Now;
         record.Attendance   = (AttendanceType)infoitem.Attendance;
         db.SaveChanges();
     }
     return(Ok(new
     {
         code = 1,
         message = "修改成功"
     }));
 }
        public void GetSummaryValues(GridViewCustomBindingGetSummaryValuesArgs e)
        {
            XPView data = new XPView(Session, ClassInfo);

            data.Criteria = CriteriaOperator.Parse(e.FilterExpression) & GetGroupFilter(e.GroupInfoList);
            foreach (GridViewSummaryItemState summaryItem in e.SummaryItems)
            {
                Aggregate        aggregateType        = GetAggregateType(summaryItem.SummaryType);
                CriteriaOperator aggregatedExpression = new OperandProperty(summaryItem.FieldName);
                CriteriaOperator property             = new AggregateOperand(null, aggregatedExpression, aggregateType, null);
                string           name = string.Concat(summaryItem.FieldName, summaryItem.SummaryType);
                data.AddProperty(name, property);
            }
            ArrayList  result = new ArrayList();
            ViewRecord rec    = data[0];

            for (int i = 0; i < data.Properties.Count; i++)
            {
                result.Add(rec[i]);
            }
            e.Data = result;
        }
        private static long RecreateAddress(ViewRecord selectedRow)
        {
            long personOid;

            using (ExplicitUnitOfWork explicitUnitOfWork = new ExplicitUnitOfWork(DatabaseHelper.DataLayer)) {
                //Get selected person object.
                Person person = explicitUnitOfWork.GetObjectByKey <Person>(selectedRow["Oid"]);
                if (person == null || person.Address == null)
                {
                    throw new ArgumentNullException("person");
                }
                //Remember person key value.
                personOid = person.Oid;
                Address       address       = person.Address;
                long          addressOid    = address.Oid;
                List <Person> referenceList = new List <Person>(address.Persons);
                //Reset references to the Address object.
                for (int i = 0; i < referenceList.Count; i++)
                {
                    referenceList[i].Address = null;
                }
                //Delete the Address object.
                explicitUnitOfWork.Delete(address);
                //Save changes to the database in case of an explicit transaction.
                explicitUnitOfWork.FlushChanges();

                //Create a new instance of the Address object.
                address = DatabaseHelper.CreateNewAddress(explicitUnitOfWork, addressOid);
                //Recover references to the Address object.
                for (int i = 0; i < referenceList.Count; i++)
                {
                    referenceList[i].Address = address;
                }
                explicitUnitOfWork.CommitChanges();
            }
            return(personOid);
        }
Beispiel #12
0
        void EnsureView(object source, Type collectionViewType)
        {
            if (_isInitializing || _deferLevel > 0)
            {
                return;
            }

            DataSourceProvider dataProvider = source as DataSourceProvider;

            // listen for DataChanged events from an DataSourceProvider
            if (dataProvider != _dataProvider)
            {
                if (_dataProvider != null)
                {
                    DataChangedEventManager.RemoveHandler(_dataProvider, OnDataChanged);
                }

                _dataProvider = dataProvider;

                if (_dataProvider != null)
                {
                    DataChangedEventManager.AddHandler(_dataProvider, OnDataChanged);
                    _dataProvider.InitialLoad();
                }
            }

            // if the source is DataSourceProvider, use its Data instead
            if (dataProvider != null)
            {
                source = dataProvider.Data;
            }

            // get the view
            ICollectionView view = null;

            if (source != null)
            {
                DataBindEngine engine     = DataBindEngine.CurrentDataBindEngine;
                ViewRecord     viewRecord = engine.GetViewRecord(source, this, collectionViewType, true,
                                                                 (object x) =>
                {
                    BindingExpressionBase beb = BindingOperations.GetBindingExpressionBase(this, SourceProperty);
                    return((beb != null) ? beb.GetSourceItem(x) : null);
                });

                if (viewRecord != null)
                {
                    view = viewRecord.View;
                    _isViewInitialized = viewRecord.IsInitialized;

                    // bring view up to date with the CollectionViewSource
                    if (_version != viewRecord.Version)
                    {
                        ApplyPropertiesToView(view);
                        viewRecord.Version = _version;
                    }
                }
            }

            // update the View property
            SetValue(ViewPropertyKey, view);
        }