/// <summary> /// Insert an additional payable item into the current working set. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks>Created: Theo Crous 23/08/2012</remarks> private void btnAddAdditionalPayment_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { AdditionalPaymentDialogue childForm = new AdditionalPaymentDialogue(); childForm.Tag = this; childForm.PaymentAccounts = accountsColumns.Select(l => l.Key).ToList(); if (childForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { DataRow newrow = entriesDataSource.NewRow(); newrow["AccountId"] = childForm.DebtorAccountId; newrow["Title"] = childForm.DebtorAccountTitle; newrow["Description"] = childForm.Description; newrow["Date"] = childForm.Date; newrow["Balance"] = childForm.Amount; newrow["Period"] = DataContext.EntitySystemContext.SYS_Period.Where(n => childForm.Date >= n.StartDate && childForm.Date <= n.EndDate).Select(n => n.Code).FirstOrDefault(); newrow["TrackNumber"] = childForm.TrackNumber; newrow["LineId"] = -1; //newrow["Reference"] = childForm.Reference; newrow["colCheck"] = true; newrow["colEntryDate"] = childForm.Date; newrow["colEntryReference"] = childForm.Reference; newrow["colEntryAdditional"] = true; newrow["colEntryAging"] = Agings.Where(n => n.Code.Equals(childForm.Aging)).Select(n => n.Id).FirstOrDefault(); newrow["Aging"] = childForm.Aging; newrow["colReceived" + childForm.PaymentAccountId] = childForm.Amount; newrow["colTotal"] = childForm.Amount; entriesDataSource.Rows.Add(newrow); chkAccount.Enabled = false; } } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } }
/// <summary> /// Handels and cell changes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks>Created: Werner Scheffer 14/08/2013</remarks> private void grvOpenItem_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { DataRowView FocusedRow = grvOpenItem.GetFocusedRow() as DataRowView; bool rowchecked = false; Boolean.TryParse(e.Value.ToString(), out rowchecked); if (grvOpenItem.FocusedColumn.Equals(colCheck)) { if (rowchecked) { pnlReceiveInto.Enabled = false; //If you change default payment accounts value set the other accounts to Zero if (defaultPaymentAccountColumn == e.Column.FieldName) { foreach (var acc in accountsColumns) { if (FocusedRow[acc.Value] != System.DBNull.Value && acc.Value != defaultPaymentAccountColumn) { FocusedRow[acc.Value] = 0; } } } if (FocusedRow["colTotal"] == System.DBNull.Value) { FocusedRow[defaultPaymentAccountColumn] = Convert.ToDecimal(FocusedRow["Balance"]); } if (FocusedRow["Type"].Equals("BBF")) { FocusedRow["colEntryAging"] = Agings.Where(n => n.Code.Equals(FocusedRow["Aging"])).Select(n => n.Id).FirstOrDefault(); } else if (FocusedRow["Type"].Equals("OI")) { DateTime entryDate = Convert.ToDateTime(FocusedRow["colEntryDate"]); entryDate = entryDate.AddDays(-(entryDate.Day - 1)); DateTime date = Convert.ToDateTime(FocusedRow["Date"]); date = date.AddDays(-(date.Day - 1)); int monthDiff = (int)entryDate.Subtract(date).Days / (365 / 12); if (monthDiff >= 5) { FocusedRow["colEntryAging"] = 5; } else { FocusedRow["colEntryAging"] = monthDiff + 1; } } } else { if (grvOpenItem.FocusedColumn.Equals(colCheck)) { FocusedRow["colEntryAging"] = System.DBNull.Value; } } } else if (grvOpenItem.FocusedColumn.FieldName.Equals("colEntryDate")) { if (FocusedRow["Type"].Equals("BBF")) { DateTime entryDate = Convert.ToDateTime(FocusedRow["colEntryDate"]); entryDate = entryDate.AddDays(-(entryDate.Day - 1)); DateTime date = Convert.ToDateTime(FocusedRow["Date"]); date = date.AddDays(-(date.Day - 1)); int monthDiff = (int)date.Subtract(entryDate).Days / (365 / 12); //Date in the future then dont change aging if (monthDiff <= 0) { FocusedRow["colEntryAging"] = Agings.Where(n => n.Code.Equals(FocusedRow["Aging"])).Select(n => n.Id).FirstOrDefault(); } //If date in the aging range then calculate if (monthDiff > 0 && monthDiff < 5) { FocusedRow["colEntryAging"] = Agings.Where(n => n.Code.Equals(FocusedRow["Aging"])).Select(n => n.Id).FirstOrDefault() - monthDiff; } //If date more than 4 months back then use current if (monthDiff > 4) { FocusedRow["colEntryAging"] = 1; } } else if (FocusedRow["Type"].Equals("OI")) { DateTime entryDate = Convert.ToDateTime(FocusedRow["colEntryDate"]); entryDate = entryDate.AddDays(-(entryDate.Day - 1)); DateTime date = Convert.ToDateTime(FocusedRow["Date"]); date = date.AddDays(-(date.Day - 1)); int monthDiff = (int)entryDate.Subtract(date).Days / (365 / 12); if (monthDiff < 0) { FocusedRow["colEntryAging"] = 1; } else if (monthDiff >= 5) { FocusedRow["colEntryAging"] = 5; } else { FocusedRow["colEntryAging"] = monthDiff + 1; } } } else if (grvOpenItem.FocusedColumn.FieldName.StartsWith("colReceive")) { //If changed cel value is not default payment accounts cell if (defaultPaymentAccountColumn != e.Column.FieldName) { decimal defaultPaymentAccountValue = 0M; foreach (var acc in accountsColumns) { if (acc.Value != defaultPaymentAccountColumn) { defaultPaymentAccountValue += Convert.ToDecimal(FocusedRow[acc.Value] == System.DBNull.Value ? 0 : FocusedRow[acc.Value]); } } if (FocusedRow["colTotal"] == System.DBNull.Value) { FocusedRow[defaultPaymentAccountColumn] = Convert.ToDecimal(FocusedRow["Balance"]); } else { FocusedRow[defaultPaymentAccountColumn] = Convert.ToDecimal(FocusedRow["colTotal"] == System.DBNull.Value ? 0 : FocusedRow["colTotal"]) - defaultPaymentAccountValue; } } } decimal sum = 0M; foreach (var acc in accountsColumns) { sum += Convert.ToDecimal(FocusedRow[acc.Value] == System.DBNull.Value ? 0 : FocusedRow[acc.Value]); } if (sum.Equals(0)) { FocusedRow["colTotal"] = System.DBNull.Value; } else { FocusedRow["colTotal"] = sum; } }