private void CalculateDetailDTO(ForecastDetailDTO forecastDetailDTO, string propertyName) { if (propertyName == CommonExpressions.PropertyName <ForecastDetailDTO>(p => p.CommodityID)) { IList <SearchCommodity> searchCommodities = this.commodityAPIs.SearchCommodities(forecastDetailDTO.CommodityID, ContextAttributes.User.LocationID, null, null, null); ////WE MUST USE ContextAttributes.User.LocationID, INSTEAD OF quantityDetailDTO.LocationID, BECAUSE AT FIRST quantityDetailDTO.LocationID = 0. WHEN SAVE: GenericService.PreSaveRoutines WILL UPDATE DTO.LocationID = ContextAttributes.User.LocationID. SEE GenericService.PreSaveRoutines FOR MORE INFORMATION!!! if (searchCommodities.Count > 0) { forecastDetailDTO.CommodityCode = searchCommodities[0].Code; forecastDetailDTO.CommodityName = searchCommodities[0].Name; forecastDetailDTO.CommodityCategoryName = searchCommodities[0].CommodityCategoryName; } } }
private void ViewDetails_ListChanged(object sender, ListChangedEventArgs e) { if (e.ListChangedType == ListChangedType.ItemAdded || e.ListChangedType == ListChangedType.ItemDeleted || e.ListChangedType == ListChangedType.Reset) { this.customTabCenter.TabPages[0].Text = "Forecast Details [" + this.forecastViewModel.ViewDetails.Count.ToString("N0") + " Line(s)] "; } if (this.EditableMode && e.PropertyDescriptor != null && e.NewIndex >= 0 && e.NewIndex < this.forecastViewModel.ViewDetails.Count) { ForecastDetailDTO forecastDetailDTO = this.forecastViewModel.ViewDetails[e.NewIndex]; if (forecastDetailDTO != null) { this.CalculateDetailDTO(forecastDetailDTO, e.PropertyDescriptor.Name); } } }
protected override void wizardDetail() { try { ExceptionTable exceptionTable = new ExceptionTable(new string[2, 2] { { "ExceptionCategory", "System.String" }, { "Description", "System.String" } }); decimal decimalValue; if (this.excelDataTable != null && this.excelDataTable.Rows.Count > 0) { this.forecastViewModel.ViewDetails.RaiseListChangedEvents = false; foreach (DataRow excelDataRow in this.excelDataTable.Rows) { if (excelDataRow["WarehouseCode"] != null && excelDataRow["WarehouseCode"].ToString().Trim() != "") { WarehouseBase warehouseBase = this.warehouseAPIs.GetWarehouseBase(excelDataRow["WarehouseCode"].ToString().Trim()); if (warehouseBase != null && warehouseBase.LocationID == this.forecastViewModel.ForecastLocationID) { CommodityBase commodityBase = this.commodityAPIs.GetCommodityBase(excelDataRow["CommodityCode"].ToString()); if (commodityBase != null) { ForecastDetailDTO forecastDetailDTO = new ForecastDetailDTO(); forecastDetailDTO.CommodityID = commodityBase.CommodityID; forecastDetailDTO.CommodityCode = commodityBase.Code; forecastDetailDTO.CommodityName = commodityBase.Name; forecastDetailDTO.CommodityCategoryName = commodityBase.CommodityCategoryName; if (decimal.TryParse(excelDataRow["CurrentMonth"].ToString(), out decimalValue)) { if (this.forecastViewModel.QuantityVersusVolume == 0) { forecastDetailDTO.Quantity = decimalValue; } else { forecastDetailDTO.LineVolume = decimalValue; } } else { exceptionTable.AddException(new string[] { "Type mismatch; number value required", "Column current month: " + excelDataRow["CurrentMonth"].ToString() }); } if (decimal.TryParse(excelDataRow["NextMonth"].ToString(), out decimalValue)) { if (this.forecastViewModel.QuantityVersusVolume == 0) { forecastDetailDTO.QuantityM1 = decimalValue; } else { forecastDetailDTO.LineVolumeM1 = decimalValue; } } else { exceptionTable.AddException(new string[] { "Type mismatch; number value required", "Column next month: " + excelDataRow["NextMonth"].ToString() }); } if (decimal.TryParse(excelDataRow["NextTwoMonth"].ToString(), out decimalValue)) { if (this.forecastViewModel.QuantityVersusVolume == 0) { forecastDetailDTO.QuantityM2 = decimalValue; } else { forecastDetailDTO.LineVolumeM2 = decimalValue; } } else { exceptionTable.AddException(new string[] { "Type mismatch; number value required", "Column next two month: " + excelDataRow["NextTwoMonth"].ToString() }); } if (decimal.TryParse(excelDataRow["NextThreeMonth"].ToString(), out decimalValue)) { if (this.forecastViewModel.QuantityVersusVolume == 0) { forecastDetailDTO.QuantityM3 = decimalValue; } else { forecastDetailDTO.LineVolumeM3 = decimalValue; } } else { exceptionTable.AddException(new string[] { "Type mismatch; number value required", "Column next three month: " + excelDataRow["NextThreeMonth"].ToString() }); } if (forecastDetailDTO.Quantity != 0 || forecastDetailDTO.QuantityM1 != 0 || forecastDetailDTO.QuantityM2 != 0 || forecastDetailDTO.QuantityM3 != 0 || forecastDetailDTO.LineVolume != 0 || forecastDetailDTO.LineVolumeM1 != 0 || forecastDetailDTO.LineVolumeM2 != 0 || forecastDetailDTO.LineVolumeM3 != 0) { this.forecastViewModel.ViewDetails.Add(forecastDetailDTO); } } else { exceptionTable.AddException(new string[] { "Item not found", "Item: " + excelDataRow["CommodityCode"].ToString() }); } } else { exceptionTable.AddException(new string[] { "Warehouse does not match", "Warehouse: " + excelDataRow["WarehouseCode"].ToString() }); } } } } if (exceptionTable.Table.Rows.Count > 0) { throw new CustomException("Lỗi import file excel. Vui lòng xem danh sách đính kèm. Click vào từng nội dung để xem chi tiết.", exceptionTable.Table); } } catch (System.Exception exception) { ExceptionHandlers.ShowExceptionMessageBox(this, exception); } finally { this.forecastViewModel.ViewDetails.RaiseListChangedEvents = true; this.forecastViewModel.ViewDetails.ResetBindings(); } }