Exemplo n.º 1
0
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            string password1 = this.Password1.Password;
            string password2 = this.Password2.Password;

            if (password1 != password2)
            {
                ShopproHelper.ShowMessageWindow(this, "Error", "The passwords you entered did not match.", false);
            }
            else
            {
                string userName  = this.Name.Text;
                string userEmail = this.Email.Text;
                this.NewAdmin     = new NewAdminData(userName, userEmail, password1);
                this.DialogResult = true;
            }
        }
        void WSClient_fetch_MyGlobCompleted(object sender, fetch_MyGlobCompletedEventArgs e)
        {
            Globals.WSClient.fetch_MyGlobCompleted -= new EventHandler <fetch_MyGlobCompletedEventArgs>(WSClient_fetch_MyGlobCompleted);

            ShopproHelper.HideBusyIndicator(this);
            if (e.Error == null)
            {
                ObservableCollection <myGlob> globalCollection = new ObservableCollection <myGlob>();
                globalCollection.Add(e.Result as myGlob);
                this.Dispatcher.BeginInvoke(delegate()
                {
                    this.itemDataForm.ItemsSource  = ViewModelHelper.Convert(globalCollection as ObservableCollection <myGlob>);
                    this.itemDataForm.CurrentIndex = 0;
                });
            }
            else
            {
                ShopproHelper.ShowMessageWindow(this, "Error", e.Error.Message, false);
            }
        }
        /// <summary>
        /// 'Delete' button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Delete_Button_Click(object sender, RoutedEventArgs e)
        {
            if (this.selectedItemId != null && this.selectedItemId.Count != 0)
            {
                ShopproHelper.ShowBusyIndicator(this);

                WSEntryManagerClient wsClient = Globals.NewWSClient;

                wsClient.removeMany_BrandCompleted += (s, e1) =>
                {
                    // Won't check status. Do this in any event
                    this.selectedItemId.Clear();
                    this.NeedUpdateTableData = true;
                    this.NeedUpdateTableUI   = true;
                    this.BeginUpdateEntireUI();
                };
                wsClient.removeMany_BrandAsync(this.selectedItemId.ToArray());
            }
            else
            {
                ShopproHelper.ShowMessageWindow(this, "Warning", "There are no selected records.", false);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Call back of get order by OrderNo
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void WSClient_getByCondition_OrderCompleted(object sender, getByCondition_OrderCompletedEventArgs e)
        {
            Globals.WSClient.getByCondition_OrderCompleted -= new EventHandler <getByCondition_OrderCompletedEventArgs>(WSClient_getByCondition_OrderCompleted);

            if (e.Error == null)
            {
                // Array -> ObservableCollection
                ObservableCollection <order> orderCollection = new ObservableCollection <order>();
                foreach (order i in e.Result)
                {
                    orderCollection.Add(i);
                }

                this.ContentPageCtx.DataSource = orderCollection;
                this.CurrentViewTitle          = string.Format(UIResources.MAINVIEW_RECORDSNUMBER, this.CurrentBodyViewTitleDesc, this.ContentPageCtx.TotalItemCount);
                this.UpdateTableUI();
                ShopproHelper.HideBusyIndicator(this);
            }
            else
            {
                ShopproHelper.HideBusyIndicator(this);
                ShopproHelper.ShowMessageWindow(this, "Error", e.Error.Message, false);
            }
        }
        /// <summary>
        /// Thread body for changing order status
        /// </summary>
        /// <param name="state"></param>
        private void StartWork_ChangeOrderStatus(object state)
        {
            OrderStatusChanging change = state as OrderStatusChanging;

            OrderView      orderView             = change.orderView;
            order          savedOrder            = null;
            AutoResetEvent nextOneAutoResetEvent = new AutoResetEvent(false);
            EventHandler <changeOrderStatus_OrderCompletedEventArgs> h1 = (s, e) =>
            {
                if (e.Error == null)
                {
                    savedOrder = e.Result;
                    nextOneAutoResetEvent.Set();
                }
            };

            Globals.WSClient.changeOrderStatus_OrderCompleted += h1;
            Globals.WSClient.changeOrderStatus_OrderAsync(change.OrderId, change.NewOrderStatus);
            nextOneAutoResetEvent.WaitOne();
            Globals.WSClient.changeOrderStatus_OrderCompleted -= h1;

            if (null != savedOrder)
            {
                this.Dispatcher.BeginInvoke(delegate()
                {
                    orderView.Restore(new OrderView(savedOrder));
                });
                this.ContentPageCtx.ListChanged = true;
            }
            else
            {
                ShopproHelper.ShowMessageWindow(this, "Error", "Fail to change status of this order", false);
            }

            ShopproHelper.HideBusyIndicator(this);
        }
        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);
                }
            }
        }
        /// <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);
            }
        }