public void Commodity_ToString_ReturnsCommodityName() { CommodityBase commBase1 = new CommodityBase("comm1"); Commodity commodity11 = new Commodity(CommodityPool.Current, commBase1); Assert.AreEqual("comm1", commodity11.ToString()); }
public void Commodity_ExplicitBool_ChecksForNullCommodities() { Commodity commodity1 = null; CommodityBase commBase2 = new CommodityBase("comm1"); Commodity commodity2 = new Commodity(CommodityPool.Current, commBase2); Commodity commodity3 = CommodityPool.Current.NullCommodity; Assert.IsFalse((bool)commodity1); Assert.IsTrue((bool)commodity2); Assert.IsFalse((bool)commodity3); }
public void Commodity_Flags_ReturnBaseFlags() { var flags = CommodityFlagsEnum.COMMODITY_KNOWN | CommodityFlagsEnum.COMMODITY_SAW_ANNOTATED | CommodityFlagsEnum.COMMODITY_STYLE_DECIMAL_COMMA; CommodityBase commBase1 = new CommodityBase("comm1") { Flags = flags }; Commodity commodity11 = new Commodity(CommodityPool.Current, commBase1); Assert.AreEqual(flags, commodity11.Flags); }
public void Commodity_Flags_ChangesAffectBaseFlags() { var flags = CommodityFlagsEnum.COMMODITY_KNOWN | CommodityFlagsEnum.COMMODITY_SAW_ANNOTATED; CommodityBase commBase1 = new CommodityBase("comm1") { Flags = flags }; Commodity commodity11 = new Commodity(CommodityPool.Current, commBase1); commodity11.Flags |= CommodityFlagsEnum.COMMODITY_STYLE_SUFFIXED; Assert.AreEqual(flags | CommodityFlagsEnum.COMMODITY_STYLE_SUFFIXED, commBase1.Flags); }
protected override void CommonControl_BindingComplete(object sender, BindingCompleteEventArgs e) { base.CommonControl_BindingComplete(sender, e); if (sender.Equals(this.bindingCommodityID)) { if (this.combexCommodityID.SelectedItem != null) { CommodityBase commodityBase = (CommodityBase)this.combexCommodityID.SelectedItem; this.batchViewModel.CommodityName = commodityBase.Name; this.batchViewModel.CommodityAPICode = commodityBase.APICode; } } }
public void Commodity_CompareByCommodityComparison_ReturnsZeroForEqualAmounts() { CommodityBase commBase1 = new CommodityBase("comm1"); CommodityBase commBase2 = new CommodityBase("comm2"); Commodity commodity1 = new Commodity(CommodityPool.Current, commBase1); Commodity commodity2 = new Commodity(CommodityPool.Current, commBase2); Amount amt1 = new Amount(10, commodity1); Amount amt1a = new Amount(10, commodity1); Amount amt2 = new Amount(10, commodity2); Assert.AreEqual(0, Commodity.CompareByCommodityComparison(amt1, amt1a)); Assert.AreEqual(-1, Commodity.CompareByCommodityComparison(amt1, amt2)); Assert.AreEqual(1, Commodity.CompareByCommodityComparison(amt2, amt1)); }
public void Commodity_Equals_IgnoresAnnotatedCommodities() { CommodityBase commBase1 = new CommodityBase("comm1"); Commodity commodity11 = new Commodity(CommodityPool.Current, commBase1); Commodity commodity12 = new Commodity(CommodityPool.Current, commBase1); AnnotatedCommodity annCommodity = new AnnotatedCommodity(commodity11, new Annotation(new Amount(10), (Date)DateTime.Now.Date, "tag")); Assert.IsTrue(commodity11.Equals(commodity11)); Assert.IsTrue(commodity11.Equals(commodity12)); Assert.IsFalse(commodity11.Equals(annCommodity)); Assert.IsTrue(commodity11 == commodity11); Assert.IsTrue(commodity11 == commodity12); Assert.IsTrue(commodity11 != annCommodity); }
protected override void CommonControl_BindingComplete(object sender, BindingCompleteEventArgs e) { base.CommonControl_BindingComplete(sender, e); if (sender.Equals(this.bindingCommodityID) && this.combexCommodityID.SelectedItem != null) { CommodityBase commodityBase = (CommodityBase)this.combexCommodityID.SelectedItem; this.commoditySettingViewModel.CommodityCode = commodityBase.Code; this.commoditySettingViewModel.CommodityName = commodityBase.Name; this.commoditySettingViewModel.CommodityCategoryName = commodityBase.CommodityCategoryName; this.commoditySettingViewModel.PackageSize = commodityBase.PackageSize; this.commoditySettingViewModel.PackageVolume = commodityBase.PackageVolume; this.customTabCenter.TabPages[0].Text = " Settings for " + this.commoditySettingViewModel.CommodityCode + " "; } }
public void Commodity_Equals_ComparesBases() { CommodityBase commBase1 = new CommodityBase("comm1"); CommodityBase commBase2 = new CommodityBase("comm2"); Commodity commodity11 = new Commodity(CommodityPool.Current, commBase1); Commodity commodity12 = new Commodity(CommodityPool.Current, commBase1); Commodity commodity21 = new Commodity(CommodityPool.Current, commBase2); Assert.IsTrue(commodity11.Equals(commodity11)); Assert.IsTrue(commodity11.Equals(commodity12)); Assert.IsFalse(commodity11.Equals(commodity21)); Assert.IsTrue(commodity11 == commodity11); Assert.IsTrue(commodity11 == commodity12); Assert.IsTrue(commodity11 != commodity21); }
public void Commodity_Equals_IgnoresAnnotatedCommodities() { CommodityBase commBase1 = new CommodityBase("comm1"); Commodity commodity11 = new Commodity(CommodityPool.Current, commBase1); Commodity commodity12 = new Commodity(CommodityPool.Current, commBase1); AnnotatedCommodity annCommodity = new AnnotatedCommodity(commodity11, new Annotation(new Amount(10), (Date)DateTime.Now.Date, "tag")); Assert.IsTrue(commodity11.Equals(commodity11)); Assert.IsTrue(commodity11.Equals(commodity12)); Assert.IsFalse(commodity11.Equals(annCommodity)); // [DM] Hide warning "Comparison made to the same variable" #pragma warning disable 1718 Assert.IsTrue(commodity11 == commodity11); #pragma warning restore Assert.IsTrue(commodity11 == commodity12); Assert.IsTrue(commodity11 != annCommodity); }
public void ReportCommodities_Flush_ReturnsItemsInAlphabeticalOrder() { CommodityBase commBase1 = new CommodityBase("comm1"); Commodity commodity11 = new Commodity(CommodityPool.Current, commBase1) { QualifiedSymbol = "A1" }; Commodity commodity12 = new Commodity(CommodityPool.Current, commBase1) { QualifiedSymbol = "A2" }; Commodity commodity13 = new Commodity(CommodityPool.Current, commBase1) { QualifiedSymbol = "A3" }; Post post1 = new Post() { Amount = new NLedger.Amounts.Amount(1, commodity13) }; Post post2 = new Post() { Amount = new NLedger.Amounts.Amount(1, commodity11) }; Post post3 = new Post() { Amount = new NLedger.Amounts.Amount(1, commodity12) }; Report report = new Report(new Session()); StringWriter output = new StringWriter(); report.OutputStream = output; ReportCommodities reportCommodities = new ReportCommodities(report); reportCommodities.Handle(post1); reportCommodities.Handle(post2); reportCommodities.Handle(post3); reportCommodities.Flush(); report.OutputStream.Flush(); Assert.Equal("A1\nA2\nA3\n", report.OutputStream.ToString().RemoveCarriageReturns()); }
public void Commodity_Equals_ComparesBases() { CommodityBase commBase1 = new CommodityBase("comm1"); CommodityBase commBase2 = new CommodityBase("comm2"); Commodity commodity11 = new Commodity(CommodityPool.Current, commBase1); Commodity commodity12 = new Commodity(CommodityPool.Current, commBase1); Commodity commodity21 = new Commodity(CommodityPool.Current, commBase2); Assert.IsTrue(commodity11.Equals(commodity11)); Assert.IsTrue(commodity11.Equals(commodity12)); Assert.IsFalse(commodity11.Equals(commodity21)); // [DM] Hide warning "Comparison made to the same variable" #pragma warning disable 1718 Assert.IsTrue(commodity11 == commodity11); #pragma warning restore Assert.IsTrue(commodity11 == commodity12); Assert.IsTrue(commodity11 != commodity21); }
public void Commodity_Supports_IComparable() { CommodityBase commBase1 = new CommodityBase("comm1"); Commodity commodity11 = new Commodity(CommodityPool.Current, commBase1) { QualifiedSymbol = "A1" }; Commodity commodity12 = new Commodity(CommodityPool.Current, commBase1) { QualifiedSymbol = "A2" }; IComparable comparable = commodity11 as IComparable; Assert.IsNotNull(comparable); var result = comparable.CompareTo(commodity12); Assert.AreEqual(-1, result); }
public bool ImportExcel(string fileName, string sheetName) { try { OleDbAPIs oleDbAPIs = new OleDbAPIs(CommonNinject.Kernel.Get <IOleDbAPIRepository>(), GlobalEnums.MappingTaskID.BatchMaster); CommodityViewModel commodityViewModel = CommonNinject.Kernel.Get <CommodityViewModel>(); CommodityController commodityController = new CommodityController(CommonNinject.Kernel.Get <ICommodityService>(), commodityViewModel); int intValue; decimal decimalValue; DateTime dateTimeValue; ExceptionTable exceptionTable = new ExceptionTable(new string[2, 2] { { "ExceptionCategory", "System.String" }, { "Description", "System.String" } }); //////////TimeSpan timeout = TimeSpan.FromMinutes(90); //////////using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required, timeout)) //////////{ //////////if (!this.Editable(this.)) throw new System.ArgumentException("Import", "Permission conflict"); DataTable excelDataTable = oleDbAPIs.OpenExcelSheet(fileName, sheetName); if (excelDataTable != null && excelDataTable.Rows.Count > 0) { foreach (DataRow excelDataRow in excelDataTable.Rows) { exceptionTable.ClearDirty(); string code = excelDataRow["Code"].ToString().Trim(); if (code.Length < 5) { code = new String('0', 5 - code.Length) + code; } BatchMasterBase batchMasterBase = this.batchMasterAPIs.GetBatchMasterBase(code); if (batchMasterBase == null) { this.batchMasterController.Create(); this.batchMasterViewModel.EntryDate = new DateTime(2000, 1, 1); this.batchMasterViewModel.Code = code; if (DateTime.TryParse(excelDataRow["PlannedDate"].ToString(), out dateTimeValue)) { this.batchMasterViewModel.PlannedDate = dateTimeValue; } else { exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu Plan start date", "Batch: " + code + ": " + excelDataRow["PlannedDate"].ToString() }); } if (decimal.TryParse(excelDataRow["PlannedQuantity"].ToString(), out decimalValue)) { this.batchMasterViewModel.PlannedQuantity = decimalValue; } else { exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu SL Kế hoạch", "Batch: " + code + ": " + excelDataRow["PlannedQuantity"].ToString() }); } CommodityBase commodityBase = this.commodityAPIs.GetCommodityBase(excelDataRow["CommodityCode"].ToString()); if (commodityBase != null) { this.batchMasterViewModel.CommodityID = commodityBase.CommodityID; } else { commodityController.Create(); commodityViewModel.Code = excelDataRow["CommodityCode"].ToString(); commodityViewModel.APICode = excelDataRow["CommodityAPICode"].ToString().Replace("'", ""); commodityViewModel.CartonCode = excelDataRow["CommodityCartonCode"].ToString().Replace("'", ""); commodityViewModel.Name = excelDataRow["CommodityName"].ToString(); commodityViewModel.OfficialName = excelDataRow["CommodityName"].ToString(); commodityViewModel.CommodityCategoryID = 2; commodityViewModel.FillingLineIDs = "1,2"; if (decimal.TryParse(excelDataRow["Volume"].ToString(), out decimalValue)) { commodityViewModel.Volume = decimalValue / 1000; } else { exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu Trọng lượng", "Batch: " + code + ": " + excelDataRow["Volume"].ToString() }); } if (int.TryParse(excelDataRow["PackPerCarton"].ToString(), out intValue)) { commodityViewModel.PackPerCarton = intValue; } else { exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu QC thùng", "Batch: " + code + ": " + excelDataRow["PackPerCarton"].ToString() }); } if (int.TryParse(excelDataRow["CartonPerPallet"].ToString(), out intValue)) { commodityViewModel.CartonPerPallet = intValue / commodityViewModel.PackPerCarton; } else { exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu QC pallet", "Batch: " + code + ": " + excelDataRow["CartonPerPallet"].ToString() }); } commodityViewModel.PackageSize = commodityViewModel.PackPerCarton.ToString("N0") + "x" + commodityViewModel.Volume.ToString("N2") + "kg"; if (int.TryParse(excelDataRow["Shelflife"].ToString(), out intValue)) { commodityViewModel.Shelflife = intValue; } else { exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu Expiration months", "Batch: " + code + ": " + excelDataRow["Shelflife"].ToString() }); } if (!commodityViewModel.IsValid) { exceptionTable.AddException(new string[] { "Lỗi dữ liệu sản phẩm không hợp lệ", excelDataRow["CommodityCode"].ToString() + ": " + commodityViewModel.Error }); } else if (commodityViewModel.IsDirty) { if (commodityController.Save()) { this.batchMasterViewModel.CommodityID = commodityViewModel.CommodityID; } else { exceptionTable.AddException(new string[] { "Lỗi lưu dữ liệu [thêm sản phẩm mới]", excelDataRow["CommodityCode"].ToString() + commodityController.BaseService.ServiceTag }); } } } BatchStatusBase batchStatusBase = this.batchStatusAPIs.GetBatchStatusBase(excelDataRow["BatchStatusCode"].ToString()); if (batchStatusBase != null) { this.batchMasterViewModel.BatchStatusID = batchStatusBase.BatchStatusID; } else { exceptionTable.AddException(new string[] { "Lỗi cột dữ liệu Trạng thái", "Batch: " + code + ": " + excelDataRow["BatchStatusCode"].ToString() }); } if (!this.batchMasterViewModel.IsValid) { exceptionTable.AddException(new string[] { "Lỗi dữ liệu Batch không hợp lệ", "Batch: " + code + ": " + this.batchMasterViewModel.Error }); } ; if (!exceptionTable.IsDirty) { if (this.batchMasterViewModel.IsDirty && !this.batchMasterController.Save()) { exceptionTable.AddException(new string[] { "Lỗi lưu dữ liệu [thêm batch mới]", code + this.batchMasterController.BaseService.ServiceTag }); } } } else { exceptionTable.AddException(new string[] { "Batch không được import, do đã tồn tại trên hệ thống", "Batch: " + code }); } } } if (exceptionTable.Table.Rows.Count <= 0) { return(true); } else { 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) { throw exception; } }
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(); } }