/// <summary> /// カレンダーの日付一覧をセットする /// </summary> private void setCalendar() { // 指定月のカレンダーの日付一覧を取得する MonthCalendar.Clear(); var lastDay = new DateTime(YearMonth.AddMonths(1).Year, YearMonth.AddMonths(1).Month, 1).AddDays(-1).Day; Enumerable.Range(1, lastDay).ToList().ForEach(x => MonthCalendar.Add(new CalendarModel(new DateTime(Year, Month, x)))); }
/// <summary> /// 月切り替えコマンド /// </summary> private void OnToggleMonthCommand(object parameter) { int i; int.TryParse(parameter.ToString(), out i); YearMonth = YearMonth.AddMonths(i); setCalendar(); }
public void CanAddMonths() { //- arrange var ym0 = new YearMonth(new DateTime(year: 2010, month: 10, day: 11)); //- act var ym1 = ym0.AddMonths(3); //- assert ym1.Year.Should().Be(2011); ym1.Month.Should().Be(1); }
internal void SaveSplitted(YearMonth startYearMonth, YearMonth endYearMonth) { bool splitOtherCostsUniform = (ApplicationConstants.SPLIT_OTHER_COSTS_ALGORYTHM == ApplicationConstants.SPLIT_OTHER_COSTS_ALGORYTHM_UNIFORM); int monthsNo = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1; decimal[] TEList = Rounding.Divide(this._TE, monthsNo); decimal[] ProtoPartsList = Rounding.Divide(this._ProtoParts, monthsNo); decimal[] ProtoToolingList = Rounding.Divide(this._ProtoTooling, monthsNo); decimal[] TrialsList = Rounding.Divide(this._Trials, monthsNo); decimal[] OtherExpensesList = Rounding.Divide(this._OtherExpenses, monthsNo); for (YearMonth currentYearMonth = new YearMonth(startYearMonth.Value); currentYearMonth.Value <= endYearMonth.Value; currentYearMonth.AddMonths(1)) { InitialBudgetOtherCosts currentOtherCost = new InitialBudgetOtherCosts(this.CurrentConnectionManager); if (splitOtherCostsUniform) { int iteratorPosition = currentYearMonth.GetMonthsDiffrence(startYearMonth); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.TE; currentOtherCost.CostVal = TEList[iteratorPosition]; currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.ProtoParts; currentOtherCost.CostVal = ProtoPartsList[iteratorPosition]; currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.ProtoTooling; currentOtherCost.CostVal = ProtoToolingList[iteratorPosition]; currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.Trials; currentOtherCost.CostVal = TrialsList[iteratorPosition]; currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.OtherExpenses; currentOtherCost.CostVal = OtherExpensesList[iteratorPosition]; currentOtherCost.Save(); } else { currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.TE; currentOtherCost.CostVal = (currentYearMonth.Value == endYearMonth.Value ? this._TE : 0); currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.ProtoParts; currentOtherCost.CostVal = (currentYearMonth.Value == endYearMonth.Value ? this._ProtoParts : 0); currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.ProtoTooling; currentOtherCost.CostVal = (currentYearMonth.Value == endYearMonth.Value ? this._ProtoTooling : 0); currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.Trials; currentOtherCost.CostVal = (currentYearMonth.Value == endYearMonth.Value ? this._Trials : 0); currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.OtherExpenses; currentOtherCost.CostVal = (currentYearMonth.Value == endYearMonth.Value ? this._OtherExpenses : 0); currentOtherCost.Save(); } } }
internal void SaveSplitted(YearMonth startYearMonth, YearMonth endYearMonth, bool isAssociateCurrency, int idCostCenter, int associateCurrency, CurrencyConverter converter) { int monthsNo = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1; decimal[] TEList = Rounding.Divide(this._NewCosts.TE, monthsNo); decimal[] ProtoPartsList = Rounding.Divide(this._NewCosts.ProtoParts, monthsNo); decimal[] ProtoToolingList = Rounding.Divide(this._NewCosts.ProtoTooling, monthsNo); decimal[] TrialsList = Rounding.Divide(this._NewCosts.Trials, monthsNo); decimal[] OtherExpensesList = Rounding.Divide(this._NewCosts.OtherExpenses, monthsNo); for (YearMonth currentYearMonth = new YearMonth(startYearMonth.Value); currentYearMonth.Value <= endYearMonth.Value; currentYearMonth.AddMonths(1)) { int iteratorPosition = currentYearMonth.GetMonthsDiffrence(startYearMonth); RevisedBudgetOtherCosts currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.TE; currentOtherCost.CostVal = TEList[iteratorPosition]; //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.ProtoParts; currentOtherCost.CostVal = ProtoPartsList[iteratorPosition]; //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.ProtoTooling; currentOtherCost.CostVal = ProtoToolingList[iteratorPosition]; //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.Trials; currentOtherCost.CostVal = TrialsList[iteratorPosition]; //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.OtherExpenses; currentOtherCost.CostVal = OtherExpensesList[iteratorPosition]; //Apply the cost center currency if this is the case if (isAssociateCurrency) { currentOtherCost.ApplyCostCenterCurrency(idCostCenter, associateCurrency, converter); } currentOtherCost.Save(); } }
internal void SaveSplitted(YearMonth startYearMonth, YearMonth endYearMonth) { int monthsNo = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1; decimal[] TEList = Rounding.Divide(this._NewCosts.TE, monthsNo); decimal[] ProtoPartsList = Rounding.Divide(this._NewCosts.ProtoParts, monthsNo); decimal[] ProtoToolingList = Rounding.Divide(this._NewCosts.ProtoTooling, monthsNo); decimal[] TrialsList = Rounding.Divide(this._NewCosts.Trials, monthsNo); decimal[] OtherExpensesList = Rounding.Divide(this._NewCosts.OtherExpenses, monthsNo); for (YearMonth currentYearMonth = new YearMonth(startYearMonth.Value); currentYearMonth.Value <= endYearMonth.Value; currentYearMonth.AddMonths(1)) { int iteratorPosition = currentYearMonth.GetMonthsDiffrence(startYearMonth); RevisedBudgetOtherCosts currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.TE; currentOtherCost.CostVal = TEList[iteratorPosition]; currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.ProtoParts; currentOtherCost.CostVal = ProtoPartsList[iteratorPosition]; currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.ProtoTooling; currentOtherCost.CostVal = ProtoToolingList[iteratorPosition]; currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.Trials; currentOtherCost.CostVal = TrialsList[iteratorPosition]; currentOtherCost.Save(); currentOtherCost = CreateInstanceWithSameFlag(currentYearMonth); currentOtherCost.IdCostType = EOtherCostTypes.OtherExpenses; currentOtherCost.CostVal = OtherExpensesList[iteratorPosition]; currentOtherCost.Save(); } }
private void ApplyCurrencyForCostCenterTable(DataSet sourceDS, int associateCurrency, CurrencyConverter converter, int dsIndex) { DataTable sourceTable = sourceDS.Tables[2]; //Cycle through each row of the cost center table foreach (DataRow row in sourceTable.Rows) { //Get the cost center currency for the current row int costCenterCurrency = (int)row["IdCurrency"]; //If both currencies are the same, do nothing if (costCenterCurrency == associateCurrency) { continue; } BudgetColumnsCalculationsList columns = this.GetCalculatedColumns(dsIndex); foreach (KeyValuePair <string, EBudgetCalculationMethod> entry in columns) { //Get the current calculated column name string columnName = entry.Key; if (sourceTable.Columns[columnName].DataType == typeof(decimal)) { //Gets the current value of the column decimal val = (decimal)row[columnName]; //Get the parrent datarow DataRow wpRow = GetParentWPRow(sourceTable.DataSet, row); //Get the start year month and end year month for the currenct cost center YearMonth startYearMonth = new YearMonth((int)wpRow["StartYearMonth"]); YearMonth endYearMonth = new YearMonth((int)wpRow["EndYearMonth"]); //Calculate the existing value for each month in the date interval int numberOfMonths = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1; decimal[] yearMonthValues = Rounding.Divide(val, numberOfMonths); decimal newValue = 0; //Calculates the new value for each month and sum it for (YearMonth currentYearMonth = new YearMonth(startYearMonth.Value); currentYearMonth.Value <= endYearMonth.Value; currentYearMonth.AddMonths(1)) { int valueIterator = currentYearMonth.GetMonthsDiffrence(startYearMonth); newValue += converter.GetConversionValue(yearMonthValues[valueIterator], costCenterCurrency, currentYearMonth, associateCurrency); } //Updates the value row[columnName] = Rounding.Round(newValue); } } } }
/// <summary> /// Save the Initial Budget object by splitting it into several object accordin to /// startYearMonth and endYearMonth values. /// </summary> /// <param name="startYearMonth">The startYearMonth value</param> /// <param name="endYearMonth">The endYearMonth value</param> private void SaveSplitted(YearMonth startYearMonth, YearMonth endYearMonth, InitialBudgetOtherCosts otherCosts) { try { //Get the months difference int monthsNo = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1; int[] totalHours = Rounding.Divide(this.TotalHours, monthsNo); decimal[] sales = Rounding.Divide(this.Sales, monthsNo); decimal[] valHours = Rounding.Divide(this.ValuedHours, monthsNo); int[] detailsIds = new int[monthsNo]; //Iterate through each month and construct the InitialBudget object for (YearMonth currentYearMonth = new YearMonth(startYearMonth.Value); currentYearMonth.Value <= endYearMonth.Value; currentYearMonth.AddMonths(1)) { //construct a new initial budget object InitialBudget newBudget = new InitialBudget(this.CurrentConnectionManager); newBudget.IdProject = this.IdProject; newBudget.IdPhase = this.IdPhase; newBudget.IdWP = this.IdWP; newBudget.IdCostCenter = this.IdCostCenter; newBudget.IdAssociate = this.IdAssociate; newBudget.YearMonth = currentYearMonth.Value; newBudget.TotalHours = totalHours[currentYearMonth.GetMonthsDiffrence(startYearMonth)]; newBudget.ValuedHours = valHours[currentYearMonth.GetMonthsDiffrence(startYearMonth)]; newBudget.Sales = sales[currentYearMonth.GetMonthsDiffrence(startYearMonth)]; if (this.State == EntityState.New) { newBudget.SetNew(); } if (this.State == EntityState.Modified) { newBudget.SetModified(); } if (this.State == EntityState.Deleted) { newBudget.SetDeleted(); } //Saves the new budget if (this.State == EntityState.New) { IdDetail = newBudget.Save(); } else { newBudget.Save(); } } //Insert Other cost object if (otherCosts != null) { otherCosts.SaveSplitted(startYearMonth, endYearMonth); } } catch (Exception exc) { throw new IndException(exc); } }
/// <summary> /// Save the Initial Budget object by splitting it into several object accordin to /// startYearMonth and endYearMonth values. /// </summary> /// <param name="startYearMonth">The startYearMonth value</param> /// <param name="endYearMonth">The endYearMonth value</param> private void SaveSplitted(YearMonth startYearMonth, YearMonth endYearMonth, InitialBudgetOtherCosts otherCosts, bool isAssociateCurrency, int associateCurrency, CurrencyConverter converter, AmountScaleOption scaleOption) { try { //Get the months difference int monthsNo = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1; int[] totalHours = Rounding.Divide(this.TotalHours, monthsNo); decimal[] sales = Rounding.Divide(this.Sales, monthsNo); decimal[] valHours = new decimal[monthsNo]; if (this.ValuedHours != ApplicationConstants.DECIMAL_NULL_VALUE) { valHours = Rounding.Divide(this.ValuedHours, monthsNo); } else { for (int i = 0; i < monthsNo; i++) { valHours[i] = ApplicationConstants.DECIMAL_NULL_VALUE; } } int[] detailsIds = new int[monthsNo]; //Iterate through each month and construct the InitialBudget object for (YearMonth currentYearMonth = new YearMonth(startYearMonth.Value); currentYearMonth.Value <= endYearMonth.Value; currentYearMonth.AddMonths(1)) { //construct a new initial budget object InitialBudget newBudget = new InitialBudget(this.CurrentConnectionManager); newBudget.IdProject = this.IdProject; newBudget.IdPhase = this.IdPhase; newBudget.IdWP = this.IdWP; newBudget.IdCostCenter = this.IdCostCenter; newBudget.IdAssociate = this.IdAssociate; newBudget.YearMonth = currentYearMonth.Value; newBudget.TotalHours = totalHours[currentYearMonth.GetMonthsDiffrence(startYearMonth)]; newBudget.ValuedHours = valHours[currentYearMonth.GetMonthsDiffrence(startYearMonth)]; newBudget.Sales = sales[currentYearMonth.GetMonthsDiffrence(startYearMonth)]; if (this.State == EntityState.New) { newBudget.SetNew(); } if (this.State == EntityState.Modified) { newBudget.SetModified(); } if (this.State == EntityState.Deleted) { newBudget.SetDeleted(); } //Apply the cost center currency if this is the case if (isAssociateCurrency) { newBudget.ApplyCostCenterCurrency(associateCurrency, converter); } //Apply the amount scale newBudget.ApplyAmountScaleOption(scaleOption); //Saves the new budget if (this.State == EntityState.New) { IdDetail = newBudget.Save(); } else { newBudget.Save(); } } //Insert Other cost object if (otherCosts != null) { otherCosts.SaveSplitted(startYearMonth, endYearMonth, isAssociateCurrency, this.IdCostCenter, associateCurrency, converter); } } catch (Exception exc) { throw new IndException(exc); } }
/// <summary> /// Save the Revised Budget object by splitting it into several object according to /// startYearMonth and endYearMonth values. /// </summary> /// <param name="startYearMonth">The startYearMonth value</param> /// <param name="endYearMonth">The endYearMonth value</param> /// <param name="otherCosts">other costs object that will be saved if it is not null</param> /// <param name="isAssociateCurrency">specifies if a conversion must be made from the associate currency to the cost center currency before saving</param> /// <param name="associateCurrency">the id of the associate currency</param> /// <param name="converter">the currency converter object to be used for the currency conversion</param> /// <param name="scaleOption">the amount scale from the budget interface (if it is not unit, a multiplication must be made before saving)</param> private void SaveSplitted(YearMonth startYearMonth, YearMonth endYearMonth, RevisedBudgetOtherCosts otherCosts, bool isAssociateCurrency, int associateCurrency, CurrencyConverter converter, AmountScaleOption scaleOption) { //TODO: Implement transactions //Get the months difference int monthsNo = endYearMonth.GetMonthsDiffrence(startYearMonth) + 1; int[] newHours = Rounding.Divide(this.NewHours, monthsNo); decimal[] newSales = Rounding.Divide(this.NewSales, monthsNo); //Iterate through each month and construct the InitialBudget object for (YearMonth currentYearMonth = new YearMonth(startYearMonth.Value); currentYearMonth.Value <= endYearMonth.Value; currentYearMonth.AddMonths(1)) { //construct a new revised budget object RevisedBudget newBudget = new RevisedBudget(this.CurrentConnectionManager); newBudget.IdProject = this.IdProject; newBudget.IdPhase = this.IdPhase; newBudget.IdWP = this.IdWP; newBudget.IdCostCenter = this.IdCostCenter; newBudget.IdAssociate = this.IdAssociate; newBudget.YearMonth = currentYearMonth.Value; newBudget.NewHours = newHours[currentYearMonth.GetMonthsDiffrence(startYearMonth)]; newBudget.NewSales = newSales[currentYearMonth.GetMonthsDiffrence(startYearMonth)]; newBudget.SaveHours = this.SaveHours; if (this.State == EntityState.New) { newBudget.SetNew(); } if (this.State == EntityState.Modified) { newBudget.SetModified(); } if (this.State == EntityState.Deleted) { newBudget.SetDeleted(); } //Apply the cost center currency if this is the case if (isAssociateCurrency) { newBudget.ApplyCostCenterCurrency(associateCurrency, converter); } //Apply the amount scale newBudget.ApplyAmountScaleOption(scaleOption); //Saves the new budget int idNewBudget = newBudget.Save(); } //Insert Other cost object if (otherCosts != null) { otherCosts.SaveSplitted(startYearMonth, endYearMonth, isAssociateCurrency, this.IdCostCenter, associateCurrency, converter); } }