/// <summary>
        /// 'save' or 'cancel' button is hit
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void itemDataForm_EditEnded(object sender, DataFormEditEndedEventArgs e)
        {
            if (!this.contentLoaded)
            {
                return;
            }

            if (e.EditAction == DataFormEditAction.Commit)
            {
                ShopproHelper.ShowBusyIndicator(this);

                this.ContentPageCtx.ListChanged = true;

                // Start data access in another thread to avoid blocking UI thread
                ThreadPool.QueueUserWorkItem(StartWork, this.itemDataForm.CurrentItem);
            }
            else
            {
                // If only one new page, return to the original one
                if (this.ContentPageCtx.GotoAddNewPage)
                {
                    ShopproHelper.GoToContentPage(this, PageEnum.TabListPage);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Double click one list item
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void MyList_DblClick(object sender, MouseEventArgs e)
 {
     // Caculate current index
     this.ContentPageCtx.CurrentIndex   = Convert.ToInt32(MyList.FocusedRowVisibleIndex.ToString()) + (this.ContentPageCtx.CurrentPageNumber - 1) * this.ContentPageCtx.ItemsPerPage;
     this.ContentPageCtx.GotoAddNewPage = false;
     ShopproHelper.GoToContentPage(this, PageEnum.OrderDetailsPage);
 }
        /// <summary>
        /// Thread body
        /// </summary>
        /// <param name="state"></param>
        private void StartWork(object state)
        {
            OrderView orderView  = state as OrderView;
            order     savedOrder = null;
            order     theOrder   = new order();

            orderView.Merge(theOrder, editMode);
            AutoResetEvent nextOneAutoResetEvent           = new AutoResetEvent(false);
            EventHandler <save_OrderCompletedEventArgs> h1 = (s, e) =>
            {
                // TODO: handle error in server side
                savedOrder = e.Result;
                nextOneAutoResetEvent.Set();
            };

            Globals.WSClient.save_OrderCompleted += h1;
            Globals.WSClient.save_OrderAsync(theOrder);
            nextOneAutoResetEvent.WaitOne();
            Globals.WSClient.save_OrderCompleted -= h1;
            orderView.Restore(new OrderView(savedOrder));

            ShopproHelper.HideBusyIndicator(this);

            // No unsaved item
            this.editMode = DataFormMode.ReadOnly;

            // If only one new page, return the original one
            if (this.ContentPageCtx.GotoAddNewPage)
            {
                ShopproHelper.GoToContentPage(this, PageEnum.OrderListPage);
            }
        }
        /// <summary>
        /// Thread body
        /// </summary>
        /// <param name="state"></param>
        private void StartWork(object state)
        {
            TabView tabView  = state as TabView;
            tab     savedTab = null;
            tab     theTab   = new tab();

            tabView.Merge(theTab, editMode);

            // Save to backend
            AutoResetEvent nextOneAutoResetEvent         = new AutoResetEvent(false);
            EventHandler <save_TabCompletedEventArgs> h1 = (s, e) =>
            {
                // TODO: handle error from server side
                savedTab = e.Result;
                nextOneAutoResetEvent.Set();
            };

            Globals.WSClient.save_TabCompleted += h1;
            Globals.WSClient.save_TabAsync(theTab);
            nextOneAutoResetEvent.WaitOne();
            Globals.WSClient.save_TabCompleted -= h1;

            // Check return result. If failure, savedCategory will be null
            if (savedTab != null)
            {
                this.Dispatcher.BeginInvoke(delegate()
                {
                    tabView.Restore(new TabView(savedTab));
                });
            }
            else
            {
                // Show error message
                this.ShowMessageWindow("Error", "Fail to save this entry. It is probably because you are trying to save a entry with conficting fields. \n'Name' and 'Url' fields are required unique for category.", false);

                // Back to readonly mode
                this.Dispatcher.BeginInvoke(delegate()
                {
                    // Restore cached UI data
                    tabView.CancelEdit();
                    this.itemDataForm.CancelEdit();
                });
            }

            ShopproHelper.HideBusyIndicator(this);

            // No unsaved item
            this.editMode = DataFormMode.ReadOnly;

            // If only one new page, return to the original one
            if (this.ContentPageCtx.GotoAddNewPage)
            {
                ShopproHelper.GoToContentPage(this, PageEnum.TabListPage);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Thread body
        /// </summary>
        /// <param name="state"></param>
        private void StartWork(object state)
        {
            BrandView brandView  = state as BrandView;
            brand     savedBrand = null;
            brand     theBrand   = new brand();

            brandView.Merge(theBrand, editMode);

            AutoResetEvent nextOneAutoResetEvent           = new AutoResetEvent(false);
            EventHandler <save_BrandCompletedEventArgs> h1 = (s, e) =>
            {
                // TODO: handle error from server side
                savedBrand = e.Result;
                nextOneAutoResetEvent.Set();
            };

            Globals.WSClient.save_BrandCompleted += h1;
            Globals.WSClient.save_BrandAsync(theBrand);
            nextOneAutoResetEvent.WaitOne();
            Globals.WSClient.save_BrandCompleted -= h1;

            // Check return result. If failure, savedCategory will be null
            if (savedBrand != null)
            {
                this.Dispatcher.BeginInvoke(delegate()
                {
                    brandView.Restore(new BrandView(savedBrand));
                });
            }
            else
            {
                // Show error message
                ShopproHelper.ShowMessageWindow(this, "Error", "Fail to save this entry.", false);

                // Back to readonly mode
                this.Dispatcher.BeginInvoke(delegate()
                {
                    // Restore cached UI data
                    brandView.CancelEdit();
                    this.brandDataForm.CancelEdit();
                });
            }

            // No unsaved item
            this.editMode = DataFormMode.ReadOnly;

            // Hide busy indicator
            ShopproHelper.HideBusyIndicator(this);

            // Go to original page if necessary
            if (this.ContentPageCtx.GotoAddNewPage)
            {
                ShopproHelper.GoToContentPage(this, PageEnum.BrandListPage);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Double click one list item
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void MyList_DblClick(object sender, MouseEventArgs e)
        {
            // Caculate current index
            this.ContentPageCtx.CurrentIndex = Convert.ToInt32(MyList.FocusedRowVisibleIndex.ToString()) + (this.ContentPageCtx.CurrentPageNumber - 1) * this.ContentPageCtx.ItemsPerPage;

            // Show readonly page first
            this.ContentPageCtx.GotoAddNewPage = false;

            // Navigate to the item details page
            ShopproHelper.GoToContentPage(this, PageEnum.ItemDetailsPage, this.ContentPageCtx.FilterId);
        }
        private void mediaDataForm_EditEnded(object sender, DataFormEditEndedEventArgs e)
        {
            if (!this.contentLoaded)
            {
                // If content is not laoded yet, ignore this event. This could happen when we change data form data context.
                return;
            }

            // If 'new' but there is no file selected, show error
            if (e.EditAction == DataFormEditAction.Commit && this.editMode == DataFormMode.AddNew && this.fileInfo == null)
            {
                ShopproHelper.ShowMessageWindow(this, "Error", "A file must be selected.", false);
                return;
            }

            if (e.EditAction == DataFormEditAction.Commit)
            {
                // 'Save' button is hit
                ShopproHelper.ShowBusyIndicator(this);

                this.ContentPageCtx.ListChanged = true;

                // Start data access in another thread to avoid blocking UI thread
                ThreadPool.QueueUserWorkItem(StartWork, this.mediaDataForm.CurrentItem);
            }
            else
            {
                this.fileInfo = null;

                // If only one new page, return to the original one
                if (this.ContentPageCtx.GotoAddNewPage)
                {
                    ShopproHelper.GoToContentPage(this, PageEnum.MediaListPage);
                }
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// 'Add' button is clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Add_Button_Click(object sender, RoutedEventArgs e)
 {
     this.ContentPageCtx.GotoAddNewPage = true;
     ShopproHelper.GoToContentPage(this, PageEnum.CategoryDetailsPage);
 }
 /// <summary>
 /// Double click one list item
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void MyList_DblClick(object sender, MouseEventArgs e)
 {
     // Caculate current index
     this.ContentPageCtx.CurrentIndex = Convert.ToInt32(MyList.FocusedRowVisibleIndex.ToString());
     ShopproHelper.GoToContentPage(this, PageEnum.TabDetailsPage);
 }
 private void Add_Button_Click(object sender, RoutedEventArgs e)
 {
     this.ContentPageCtx.GotoAddNewPage = true;  // Go to 'New' page directly
     ShopproHelper.GoToContentPage(this, PageEnum.TemplateDetailsPage);
 }
 /// <summary>
 /// 'Add' button is clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Add_Button_Click(object sender, RoutedEventArgs e)
 {
     // Navigate to the item details page
     ShopproHelper.GoToContentPage(this, PageEnum.UserDetailsPage);
 }
        /// <summary>
        /// Thread body
        /// </summary>
        /// <param name="state"></param>
        private void StartWork(object state)
        {
            MediaView mediaView  = state as MediaView;
            media     savedMedia = null;
            media     theMedia   = new media();

            mediaView.Merge(theMedia, editMode);

            // Save to backend
            if (this.editMode == DataFormMode.Edit)
            {
                // Edit mode
                AutoResetEvent nextOneAutoResetEvent           = new AutoResetEvent(false);
                EventHandler <save_MediaCompletedEventArgs> h1 = (s, e) =>
                {
                    // TODO: handle error from server side
                    savedMedia = e.Result;
                    nextOneAutoResetEvent.Set();
                };
                Globals.WSClient.save_MediaCompleted += h1;
                Globals.WSClient.save_MediaAsync(theMedia);
                nextOneAutoResetEvent.WaitOne();
                Globals.WSClient.save_MediaCompleted -= h1;
            }
            else
            {
                //
                // Add new mode
                //

                // Get file content
                byte[] content = ShopproHelper.ReadFully(fileInfo.OpenRead());

                // Save to the backend
                AutoResetEvent nextOneAutoResetEvent = new AutoResetEvent(false);
                EventHandler <createNew_MediaCompletedEventArgs> h3 = (s, e) =>
                {
                    // TODO: handle error from server side
                    savedMedia = e.Result;
                    nextOneAutoResetEvent.Set();
                };
                Globals.WSClient.createNew_MediaCompleted += h3;
                Globals.WSClient.createNew_MediaAsync(theMedia, content);
                nextOneAutoResetEvent.WaitOne();
                Globals.WSClient.createNew_MediaCompleted -= h3;
            }

            // Check return result. If failure, savedCategory will be null
            if (savedMedia != null)
            {
                this.Dispatcher.BeginInvoke(delegate()
                {
                    mediaView.Restore(new MediaView(savedMedia));
                });
            }
            else
            {
                // Show error message
                ShopproHelper.ShowMessageWindow(this, "Error", "Fail to save this entry.", false);

                // Back to readonly mode
                this.Dispatcher.BeginInvoke(delegate()
                {
                    // Restore cached UI data
                    mediaView.CancelEdit();
                    this.mediaDataForm.CancelEdit();
                });
            }

            // No unsaved item
            this.editMode = DataFormMode.ReadOnly;
            this.fileInfo = null;

            // Hide busy indicator
            ShopproHelper.HideBusyIndicator(this);

            // Go to original page if necessary
            if (this.ContentPageCtx.GotoAddNewPage)
            {
                ShopproHelper.GoToContentPage(this, PageEnum.MediaListPage);
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// 'Add' button is clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Add_Button_Click(object sender, RoutedEventArgs e)
 {
     // Navigate to the item details page
     this.ContentPageCtx.GotoAddNewPage = true;
     ShopproHelper.GoToContentPage(this, PageEnum.ArticleDetailsPage);
 }