Beispiel #1
0
        public TankListUIObjects GetTankList(long stationid)
        {
            currentStationId = stationid;
            // populate our list of customers from the data access layer
            TankListUIObjects iTabObjs = new TankListUIObjects();

            try
            {
                App.Log.LogDebugMessage(String.Format(@"GetALLTank w stationid = {0}", stationid));
                List <TankListRecord> iTabDataObjects = dataAccessLayer.GetAllTank(stationid);

                foreach (TankListRecord iTabDataObject in iTabDataObjects)
                {
                    // create a business object from each data object
                    TankUIObject tobj = new TankUIObject(iTabDataObject);
                    tobj.StationId = stationid;
                    iTabObjs.Add(tobj);
                }

                iTabObjs.TankListItemEndEdit += new TankListItemEndEditEventHandler(TankListItemEndEdit);
                iTabObjs.CollectionChanged   += new NotifyCollectionChangedEventHandler(TankListCollectionChanged);
                App.Log.LogDebugMessage(String.Format(@"GetALLTank w stationid = {0} success!", stationid));
            }
            catch (Exception err)
            {
                App.Log.LogException(err);
                //throw;
            }


            return(iTabObjs);
        }
Beispiel #2
0
        void TankListCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            //throw new NotImplementedException();
            if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                try
                {
                    foreach (object item in e.OldItems)
                    {
                        TankUIObject iTabObject = item as TankUIObject;

                        // use the data access layer to delete the wrapped data object
                        dataAccessLayer.DeleteTank(iTabObject.GetDataObject());
                    }
                }
                catch (Exception ex)
                {
                    if (TankListPersistenceError != null)
                    {
                        TankListPersistenceError(this, ex);
                    }
                    App.Log.LogException(ex);
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Add)
            {
                try
                {
                    foreach (object item in e.NewItems)
                    {
                        TankUIObject iTabObject = item as TankUIObject;
                        iTabObject.StationId = currentStationId;
                    }
                }
                catch (Exception ex)
                {
                    if (TankListPersistenceError != null)
                    {
                        TankListPersistenceError(this, ex);
                    }
                    App.Log.LogException(ex);
                }
            }
        }
Beispiel #3
0
        void TankListItemEndEdit(System.ComponentModel.IEditableObject sender)
        {
            //throw new NotImplementedException();
            TankUIObject iTabObject = sender as TankUIObject;

            try
            {
                //if (iTabObject.TankId == 0)
                //{
                //    iTabObject.TankId = currTankId;
                //}
                // use the data access layer to update the wrapped data object
                dataAccessLayer.UpdateTank(iTabObject.GetDataObject());
                iTabObject.NotifyIdChange();
            }
            catch (Exception ex)
            {
                if (TankListPersistenceError != null)
                {
                    TankListPersistenceError(this, ex);
                }
                App.Log.LogException(ex); App.Log.LogInfoMessage(ex.Message);
            }
        }