/// <summary> /// Call back of get order by orderNo /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void WSClient_getByOrderNo_OrderCompleted(object sender, getByOrderNo_OrderCompletedEventArgs e) { Globals.WSClient.getByOrderNo_OrderCompleted -= new EventHandler <getByOrderNo_OrderCompletedEventArgs>(WSClient_getByOrderNo_OrderCompleted); if (e.Error == null) { // Array -> ObservableCollection ObservableCollection <order> orderCollection = new ObservableCollection <order>(); if (e.Result != null) { orderCollection.Add(e.Result); } this.ContentPageCtx.DataSource = orderCollection; if (orderCollection.Count == 0) { this.CurrentViewTitle = @"Order not found: " + this.CurrentBodyViewTitleDesc; } else { this.CurrentViewTitle = @"Order found: " + this.CurrentBodyViewTitleDesc; } this.UpdateTableUI(); ShopproHelper.HideBusyIndicator(this); } else { ShopproHelper.HideBusyIndicator(this); ShopproHelper.ShowMessageWindow(this, "Error", e.Error.Message, false); } }
void WSClient_getAll_CategoryCompleted(object sender, getAll_CategoryCompletedEventArgs e) { Globals.WSClient.getAll_CategoryCompleted -= new EventHandler <getAll_CategoryCompletedEventArgs>(WSClient_getAll_CategoryCompleted); if (e.Error == null) { // Array -> ObservableCollection ObservableCollection <category> categoryCollection = new ObservableCollection <category>(); foreach (category i in e.Result) { categoryCollection.Add(i); } this.ContentPageCtx.TotalItemCount = categoryCollection.Count; this.ContentPageCtx.DataSource = categoryCollection; 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); } Globals.WSClient.getAll_CategoryCompleted -= new EventHandler <getAll_CategoryCompletedEventArgs>(WSClient_getAll_CategoryCompleted); }
/// <summary> /// Call back of item get by condition /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WSClient_getByCondition_ItemCompleted(object sender, getByCondition_ItemCompletedEventArgs e) { Globals.WSClient.getByCondition_ItemCompleted -= new EventHandler <getByCondition_ItemCompletedEventArgs>(WSClient_getByCondition_ItemCompleted); if (e.Error == null) { this.NeedUpdateTableUI = true; // Array -> ObservableCollection ObservableCollection <item> itemCollection = new ObservableCollection <item>(); foreach (item i in e.Result) { itemCollection.Add(i); } this.ContentPageCtx.DataSource = itemCollection; Debug.WriteLine(string.Format("this: {0}, Old CurrentViewTitle: {1}", this.GetHashCode(), this.CurrentViewTitle)); this.CurrentViewTitle = string.Format(UIResources.MAINVIEW_RECORDSNUMBER, this.CurrentBodyViewTitleDesc, this.ContentPageCtx.TotalItemCount); Debug.WriteLine(string.Format("this: {0}, New CurrentViewTitle: {1}", this.GetHashCode(), this.CurrentViewTitle)); this.UpdateTableUI(); ShopproHelper.HideBusyIndicator(this); } else { ShopproHelper.HideBusyIndicator(this); ShopproHelper.ShowMessageWindow(this, "Error", e.Error.Message, false); } // Detach event handler Globals.WSClient.getByCondition_ItemCompleted -= new EventHandler <getByCondition_ItemCompletedEventArgs>(WSClient_getByCondition_ItemCompleted); }
/// <summary> /// Call back of get items by search text /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WSClient_searchByText_ItemCompleted(object sender, HappyDog.SL.Beelun.Shoppro.WSEntryManager.searchByText_ItemCompletedEventArgs e) { if (e.Error == null) { this.NeedUpdateTableUI = true; // Array -> ObservableCollection ObservableCollection <item> itemCollection = new ObservableCollection <item>(); foreach (item i in e.Result) { itemCollection.Add(i); } this.ContentPageCtx.DataSource = itemCollection; this.CurrentViewTitle = string.Format(UIResources.MAINVIEW_RECORDSNUMBER, "Search results for:" + this.ContentPageCtx.SearchText, this.ContentPageCtx.TotalItemCount); this.UpdateTableUI(); ShopproHelper.HideBusyIndicator(this); } else { ShopproHelper.ShowMessageWindow(this, "Error", e.Error.Message, false); } // Detach event handler Globals.WSClient.searchByText_ItemCompleted -= new EventHandler <HappyDog.SL.Beelun.Shoppro.WSEntryManager.searchByText_ItemCompletedEventArgs>(WSClient_searchByText_ItemCompleted); }
/// <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_SaveAMedia(object state) { ShopproHelper.ShowBusyIndicator(this, "Saving this new media to libary..."); MediaView mediaView = state as MediaView; media savedMedia = null; media theMedia = new media(); mediaView.Merge(theMedia, DataFormMode.AddNew); // Get file content byte[] content = ShopproHelper.ReadFully(fileInfo.OpenRead()); // Save to the backend EventHandler <createNew_MediaCompletedEventArgs> h1 = (s, e) => { // TODO: handle error from server side savedMedia = e.Result; nextOneAutoResetEvent.Set(); }; Globals.WSClient.createNew_MediaCompleted += h1; Globals.WSClient.createNew_MediaAsync(theMedia, content); nextOneAutoResetEvent.WaitOne(); Globals.WSClient.createNew_MediaCompleted -= h1; // Check return result. If failure, savedCategory will be null if (savedMedia != null) { this.ResultingImageUrl = savedMedia.myUrl; this.Dispatcher.BeginInvoke(delegate() { mediaView.Restore(new MediaView(savedMedia)); }); } else { // Show error message ShopproHelper.ShowMessageWindow(this, "Error", "Fail to save this entry.", false); } this.fileInfo = null; // Hide busy indicator ShopproHelper.HideBusyIndicator(this); // Now close the window this.Dispatcher.BeginInvoke(delegate() { Debug.WriteLine("Going to call Close()."); // This will close this window automatically: http://msdn.microsoft.com/en-us/library/system.windows.controls.childwindow.close%28VS.95%29.aspx this.DialogResult = true; Debug.WriteLine("Called Close()."); }); }
/// <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); } }
/// <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); } }
/// <summary> /// Thread body /// </summary> /// <param name="state"></param> private void StartWork(object state) { GlobalView globalView = state as GlobalView; myGlob savedGlobal = null; myGlob theGlobal = new myGlob(); globalView.Merge(theGlobal, editMode); // Save to backend AutoResetEvent nextOneAutoResetEvent = new AutoResetEvent(false); EventHandler <save_MyGlobCompletedEventArgs> h1 = (s, e) => { // TODO: handle error from server side savedGlobal = e.Result; nextOneAutoResetEvent.Set(); }; Globals.WSClient.save_MyGlobCompleted += h1; Globals.WSClient.save_MyGlobAsync(theGlobal); nextOneAutoResetEvent.WaitOne(); Globals.WSClient.save_MyGlobCompleted -= h1; // Check return result. If failure, savedCategory will be null if (savedGlobal != null) { this.Dispatcher.BeginInvoke(delegate() { globalView.Restore(new GlobalView(savedGlobal)); }); } 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 globalView.CancelEdit(); this.itemDataForm.CancelEdit(); }); } ShopproHelper.HideBusyIndicator(this); // No unsaved item this.editMode = DataFormMode.ReadOnly; }
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> /// 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); }
/// <summary> /// Interaction about Item/Category mapping /// </summary> /// <param name="state"></param> private void StartWork_MappingRelated(object state) { List <long> idList = state as List <long>; if (idList != null) { // Start get current mapping status AutoResetEvent nextOneAutoResetEvent = new AutoResetEvent(false); List <MappingView> l = new List <MappingView>(); EventHandler <getMappingStatus_CategoryCompletedEventArgs> h1 = (s, e) => { foreach (mappingStatus m in e.Result) { l.Add(new MappingView(ShopproHelper.ConvertToCheckedValue(m.mappingStatus1.ToString()), m.name, m.id)); } nextOneAutoResetEvent.Set(); }; Globals.WSClient.getMappingStatus_CategoryCompleted += h1; Globals.WSClient.getMappingStatus_CategoryAsync(idList.ToArray()); nextOneAutoResetEvent.WaitOne(); Globals.WSClient.getMappingStatus_CategoryCompleted -= h1; // Hide busy indicator ShopproHelper.HideBusyIndicator(this); // Show picker this.Dispatcher.BeginInvoke(delegate() { MappingPicker cp = new MappingPicker(l); cp.Title = "Tab mapping"; cp.Instruction = "Add selected categories to tab or remove them from tabs:"; cp.Closed += new EventHandler(cp_Closed); cp.Show(); }); } else { Dictionary <long, bool> changedMapping = state as Dictionary <long, bool>; if (null != changedMapping) { // Start get current mapping status AutoResetEvent nextOneAutoResetEvent = new AutoResetEvent(false); // TODO: optimize this? foreach (long cid in changedMapping.Keys) { EventHandler <setMappingStatus_CategoryCompletedEventArgs> h2 = (s, e) => { // TODO: error handling nextOneAutoResetEvent.Set(); }; Globals.WSClient.setMappingStatus_CategoryCompleted += h2; Globals.WSClient.setMappingStatus_CategoryAsync(this.selectedItemId.ToArray(), cid, (changedMapping[cid] == true) ? mappingStatusEnum.ALL : mappingStatusEnum.NONE); nextOneAutoResetEvent.WaitOne(); Globals.WSClient.setMappingStatus_CategoryCompleted -= h2; } } // Hide busy indicator ShopproHelper.HideBusyIndicator(this); } }
/// <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); } }