private void TableView_CellValueChanged(object sender, DevExpress.Xpf.Grid.CellValueChangedEventArgs e) { if (e.Column == null) { return; } if (e.Row != null) { if (e.Row as ICleanEntityRef != null) { (e.Row as ICleanEntityRef).CleanEntityRef(e.Column.FieldName); } } if (e.Column.Name == "clmMaterialCode") { if (e.Value != null && e.Value.ToString() != String.Empty) { Product product = ProductManager.Instance.GetByMaterialCode(e.Value.ToString()); (e.Row as AnimationProduct).MaterialCode = null; if (product != null) { try { AnimationProduct ap = e.Row as AnimationProduct; ap.Product = product; ap.Description = null; IEnumerable<Multiple> multiples = MultipleManager.Instance.MultipleGetToProduct(product.ID); cboNormalMultiple.ItemsSource = multiples; cboWarehouseMultiple.ItemsSource = multiples; // clear multiples if not valid if (ap.NormalMultiple != String.Empty) { if (multiples.Where(m => m.Value == Convert.ToInt32(ap.NormalMultiple) && m.IDProduct == product.ID).Count() == 0) (e.Row as AnimationProduct).Multiple = null; } if (ap.WarehouseMultiple != String.Empty) { if (multiples.Where(m => m.Value == Convert.ToInt32(ap.WarehouseMultiple) && m.IDProduct == product.ID).Count() == 0) (e.Row as AnimationProduct).Multiple1 = null; } } catch (Exception exc) { Logger.Log(exc.ToString(), LogLevel.Error); } } else { IEnumerable<string> materialCodes = ProductManager.Instance.GetMaterialCodes(e.Value.ToString()); if (materialCodes.Count() > 0) { string materialCode = materialCodes.First(); grdProduct.SetCellValue(e.RowHandle, e.Column, materialCode); } else { if (e.OldValue != null) (e.Row as AnimationProduct).MaterialCode = e.OldValue.ToString(); else (e.Row as AnimationProduct).MaterialCode = null; //MessageBox.Show(string.Format("No product exists for material code '{0}'", e.Value)); MessageBox.Show(SystemMessagesManager.Instance.GetMessage("ProductAnimationProductNotFound", e.Value.ToString())); } return; } } } else if (e.Column.Name == "clmProductDescription") { if (e.Value != null && e.Value.ToString() != String.Empty) { Product product = ProductManager.Instance.GetByDescription(e.Value.ToString()); (e.Row as AnimationProduct).Description = null; if (product != null) { try { (e.Row as AnimationProduct).Product = product; (e.Row as AnimationProduct).MaterialCode = null; IEnumerable<Multiple> multiples = MultipleManager.Instance.MultipleGetToProduct(product.ID); cboNormalMultiple.ItemsSource = multiples; cboWarehouseMultiple.ItemsSource = multiples; } catch (Exception exc) { Logger.Log(exc.ToString(), LogLevel.Error); } } else { IEnumerable<string> descriptions = ProductManager.Instance.GetDescriptions(e.Value.ToString()); if (descriptions.Count() > 0) { string description = descriptions.First(); grdProduct.SetCellValue(e.RowHandle, e.Column, description); } else { if (e.OldValue != null) (e.Row as AnimationProduct).Description = e.OldValue.ToString(); else (e.Row as AnimationProduct).Description = null; //MessageBox.Show(string.Format("No product exists for description '{0}'", e.Value)); MessageBox.Show(SystemMessagesManager.Instance.GetMessage("ProductAnimationDescriptionNotFound", e.Value.ToString())); } return; } } } else if (e.Column.Name == "clmItemGroup" && e.RowHandle != GridControl.NewItemRowHandle && e.RowHandle != GridControl.InvalidRowHandle) { (e.Row as AnimationProduct).ItemGroup = DbDataContext.GetInstance().ItemGroups.Single(ig => ig.ID == (Guid)e.Value); } else if (e.Column.Name == "clmItemType" && e.RowHandle != GridControl.NewItemRowHandle && e.Value != null) { if ((Guid)e.Value != Guid.Empty) { (e.Row as AnimationProduct).ItemType = DbDataContext.GetInstance().ItemTypes.Single(it => it.ID == (Guid)e.Value); } } else if (e.Column.FieldName == "ConfirmedMadMonthString") { if (e.Value != null && e.Value.ToString() != String.Empty) { string date = madMonths.Where(m=>m.Contains(e.Value.ToString())).FirstOrDefault(); cboMadMonth.ItemsSource = madMonths.Where(m => m.Contains(e.Value.ToString())); if (!string.IsNullOrEmpty(date)) { try { (e.Row as AnimationProduct).ConfirmedMADMonth = DateTime.Parse(date); (e.Row as AnimationProduct).ConfirmedMadMonthString = string.Empty; } catch (Exception exc) { Logger.Log(exc.ToString(), LogLevel.Error); } } else { (e.Row as AnimationProduct).ConfirmedMadMonthString = string.Empty; return; } } } // insert or update if (e.Row != null && e.Value != null && e.Value.Equals(e.OldValue) == false) { AnimationProduct entity = e.Row as AnimationProduct; if (e.Column.FieldName == "IDSignature") { entity.CleanEntityRef("IDBrandAxe"); entity.IDBrandAxe = null; } if (entity.ID != Guid.Empty) { InsertOrUpdate(entity); if (e.Column.FieldName == "MaterialCode" || e.Column.FieldName == "Description") { calcType = RecalculationType.CalculateActiveAnimations; } else if (e.Column.FieldName == "IDItemType" || e.Column.FieldName == "IDSignature" || e.Column.FieldName == "IDBrandAxe" || e.Column.FieldName == "IDCategory") { entity.CalculateTotalCapacity(); if (animationManager.Allocations != null) { animationManager.Allocations.RefreshAllocations(); } } else if (e.Column.FieldName == "ConfirmedMadMonthString") { entity.CalculateProductRecieved(); } } } }
public void RecalculateAnimationProduct(RecalculationType calcType, AnimationProduct entity = null) { if (calcType == RecalculationType.CalculateTotal) { LongTaskExecutor recalculationExecutor = new LongTaskExecutor("Recalculating capacities ..."); recalculationExecutor.DoWork += new DoWorkEventHandler(recalculationExecutor_DoWork); recalculationExecutor.Run(entity); } else if (calcType == RecalculationType.CalculateActiveAnimations) { LongTaskExecutor calcActiveAnimationExecutor = new LongTaskExecutor("Recalculating active animations ..."); calcActiveAnimationExecutor.DoWork += new DoWorkEventHandler(calcActiveAnimationExecutor_DoWork); calcActiveAnimationExecutor.Run(); } else if (calcType == RecalculationType.CalculateTotalCapacity && entity != null) { LongTaskExecutor calcTotalCapacityExecutor = new LongTaskExecutor("Recalculating total capacity for " + entity.ProductIdentifier); calcTotalCapacityExecutor.DoWork += new DoWorkEventHandler(calcTotalCapacityExecutor_DoWork); calcTotalCapacityExecutor.Run(); } else if (calcType == RecalculationType.CalculateProductRecieved && entity != null) { LongTaskExecutor calcTotalCapacityExecutor = new LongTaskExecutor("Recalculating product recieved "); calcTotalCapacityExecutor.DoWork += new DoWorkEventHandler(calcProductRecievedExecutor_DoWork); calcTotalCapacityExecutor.Run(); } else if (calcType == RecalculationType.CalculateTotalAnimationQuantity) { Animation.AnimationProducts.ToList().ForEach(ap => ap.TotalAnimationQuantity = -1); } }
void View_RowUpdated(object sender, DevExpress.Xpf.Grid.RowEventArgs e) { if (e.RowHandle == GridControl.NewItemRowHandle) { AnimationProduct entity = (e.Source as TableView).FocusedRow as AnimationProduct; InsertOrUpdate(entity); entity.CalculateTotalCapacity(); animationManager.RecalculateAnimationProduct(RecalculationType.CalculateActiveAnimations); animationManager.Animation.ObservableProductDetails = null; calcType = RecalculationType.None; return; } if (calcType != RecalculationType.None) { animationManager.RecalculateAnimationProduct(calcType); calcType = RecalculationType.None; } }