/// <summary> /// Show all the data (Account Code and description) /// </summary> public void PopulateListView(GLSetupTDS MainDS, Int32 LedgerNumber, String SelectedHierarchy) { // FLedgerNumber = LedgerNumber; // FSelectedHierarchy = SelectedHierarchy; FDataView = new DataView(MainDS.AAccount); FDataView.Sort = "a_account_code_c"; FDataView.AllowNew = false; grdAccounts.DataSource = new DevAge.ComponentModel.BoundDataView(FDataView); grdAccounts.Columns.Clear(); grdAccounts.AddTextColumn(Catalog.GetString("Code"), MainDS.AAccount.ColumnAccountCode); grdAccounts.AddTextColumn(Catalog.GetString("Descr"), MainDS.AAccount.ColumnAccountCodeShortDesc); // grdAccounts.AddCurrencyColumn(Catalog.GetString("YTD Actual"), MainDS.AAccount.ColumnYtdActualBase); // grdAccounts.AddCurrencyColumn(Catalog.GetString("Foreign"), MainDS.AAccount.ColumnYtdActualForeign); if (FSelectedAccount != null) { this.SelectedAccount = FSelectedAccount; } else { grdAccounts.SelectRowInGrid(0); } }
/// <summary> /// The fact that the AccountCode is the database primary key causes SO MUCH GRIEF all over the system! /// </summary> /// <param name="AAccountNode"></param> /// <returns></returns> private Boolean ProtectedChangeOfPrimaryKey(AccountNodeDetails AAccountNode) { String NewValue = txtDetailAccountCode.Text; try { AAccountNode.AccountRow.AccountCode = NewValue; AAccountNode.DetailRow.ReportingAccountCode = NewValue; return(true); } catch (System.Data.ConstraintException) { txtDetailAccountCode.Text = strOldDetailAccountCode; FRecentlyUpdatedDetailAccountCode = INTERNAL_UNASSIGNED_DETAIL_ACCOUNT_CODE; ShowStatus(Catalog.GetString("Account Code change REJECTED!")); MessageBox.Show(String.Format( Catalog.GetString( "Renaming Account Code '{0}' to '{1}' is not possible because an Account Code by the name of '{1}' already exists." + "\r\n\r\n--> Account Code reverted to previous value."), strOldDetailAccountCode, NewValue), Catalog.GetString("Renaming Not Possible - Conflicts With Existing Account Code"), MessageBoxButtons.OK, MessageBoxIcon.Error); txtDetailAccountCode.Focus(); } return(false); }
/// <summary> /// Add this new account as child of the currently selected node /// </summary> public void AddNewAccount(GLSetupTDSAAccountRow AccountRow, AAccountHierarchyDetailRow HierarchyDetailRow) { trvAccounts.BeginUpdate(); TreeNode newNode = trvAccounts.SelectedNode.Nodes.Add(AccountRow.AccountCode); AccountNodeDetails NewAccount = AccountNodeDetails.AddNewAccount(newNode, AccountRow, HierarchyDetailRow); trvAccounts.EndUpdate(); FParentForm.SetSelectedAccount(NewAccount); }
/// <summary> /// Make this account a child of the selected one in the hierarchy (from drag-drop). /// </summary> /// <param name="AChild"></param> /// <param name="ANewParent"></param> private void DoReassignment(TreeNode AChild, TreeNode ANewParent) { if ((AChild != null) && (ANewParent != null)) { if (((AccountNodeDetails)AChild.Tag).AccountRow.SystemAccountFlag) { MessageBox.Show(String.Format(Catalog.GetString("{0} is a System Account and cannot be moved."), ((AccountNodeDetails)AChild.Tag).AccountRow.AccountCode), Catalog.GetString("Re-assign Account"), MessageBoxButtons.OK, MessageBoxIcon.Stop); ShowNodeSelected(null); return; } AAccountRow newParentRow = ((AccountNodeDetails)ANewParent.Tag).AccountRow; if (newParentRow.PostingStatus) { if (MessageBox.Show(String.Format(Catalog.GetString("Do you want to promote {0} to a summary Account?"), newParentRow.AccountCode), Catalog.GetString("Move Account"), MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No) { ShowNodeSelected(null); return; } } FParentForm.SetSelectedAccount(null); String PrevParent = AChild.Parent.Text; AccountNodeDetails DraggedAccount = (AccountNodeDetails)AChild.Tag; TreeNode NewNode = (TreeNode)AChild.Clone(); // A new TreeNode is made (and the previous will be deleted), // but the actual DataRows are only tweaked to show the new parent. DraggedAccount.linkedTreeNode = NewNode; DraggedAccount.DetailRow.AccountCodeToReportTo = newParentRow.AccountCode; InsertInOrder(ANewParent, NewNode); NewNode.Expand(); ANewParent.Expand(); newParentRow.PostingStatus = false; // The parent is now a summary account! ((AccountNodeDetails)ANewParent.Tag).CanDelete = false; ANewParent.BackColor = Color.White; FParentForm.ShowStatus(String.Format(Catalog.GetString("{0} was moved from {1} to {2}."), AChild.Text, PrevParent, ANewParent.Text)); AChild.Remove(); FPetraUtilsObject.SetChangedFlag(); FParentForm.SetSelectedAccount(DraggedAccount); // SetSelectionUsingTimer(DraggedAccount); // Calling SetSelectedAccount directly doesn't work // because Remove(), above, has left a selection "in the queue". } }
// End of (mostly copied) drag-drop functions private void InsertInOrder(TreeNode Parent, TreeNode Child) { int Idx; AccountNodeDetails ChildTag = (AccountNodeDetails)Child.Tag; /* * Apparently it is best to always use the Reporting Order, for both Summary and Posting accounts. * * if (ChildTag.AccountRow.PostingStatus) // Posting accounts are sorted alphabetically: * { * for (Idx = 0; Idx < Parent.Nodes.Count; Idx++) * { * if (Parent.Nodes[Idx].Text.CompareTo(Child.Text) > 0) * { * break; * } * } * } * else // For summary accounts I need to use the ReportOrder, then alphabetic: */ { String ChildDescr = ChildTag.DetailRow.ReportOrder.ToString("000") + Child.Text; for (Idx = 0; Idx < Parent.Nodes.Count; Idx++) { AccountNodeDetails SiblingTag = (AccountNodeDetails)Parent.Nodes[Idx].Tag; if ((SiblingTag.DetailRow.ReportOrder.ToString("000") + Child.Text).CompareTo(ChildDescr) > 0) { break; } } } if (Idx == Parent.Nodes.Count) { Parent.Nodes.Add(Child); } else { Parent.Nodes.Insert(Idx, Child); } if (!FDuringInitialisation) { FParentForm.SetSelectedAccount(ChildTag); } }
private void InsertNodeIntoTreeView(GLSetupTDS MainDS, Int32 LedgerNumber, TreeNode AParent, DataView view, AAccountHierarchyDetailRow ADetailRow) { GLSetupTDSAAccountRow AccountRow = (GLSetupTDSAAccountRow)MainDS.AAccount.Rows.Find( new object[] { LedgerNumber, ADetailRow.ReportingAccountCode }); TreeNode Child = new TreeNode(); AccountNodeDetails NodeTag = AccountNodeDetails.AddNewAccount(Child, AccountRow, ADetailRow); NodeTag.IsNew = (ADetailRow.RowState == DataRowState.Added); SetNodeLabel(AccountRow, Child); if (AParent == null) { trvAccounts.Nodes.Add(Child); } else { InsertInOrder(AParent, Child); } // Now add the children of this node: view.RowFilter = AAccountHierarchyDetailTable.GetAccountHierarchyCodeDBName() + " = '" + ADetailRow.AccountHierarchyCode + "' AND " + AAccountHierarchyDetailTable.GetAccountCodeToReportToDBName() + " = '" + ADetailRow.ReportingAccountCode + "'"; if (view.Count > 0) { // An account cannot be deleted if it has children. NodeTag.CanDelete = false; NodeTag.Msg = Catalog.GetString("Child accounts must be deleted first."); NodeTag.CanHaveChildren = true; foreach (DataRowView rowView in view) { AAccountHierarchyDetailRow accountDetail = (AAccountHierarchyDetailRow)rowView.Row; InsertNodeIntoTreeView(MainDS, LedgerNumber, Child, view, accountDetail); } } }
/// <summary> /// Called from the user controls when the user selects a row, /// this common method keeps both user controls in sync. /// </summary> public void SetSelectedAccount(AccountNodeDetails AnewSelection) { if (FCurrentAccount != AnewSelection) { FCurrentAccount = AnewSelection; ucoAccountsList.SelectedAccount = AnewSelection; ucoAccountsTree.SelectedAccount = AnewSelection; pnlDetails.Enabled = (AnewSelection != null); /* * String Msg = "null"; * if (FCurrentAccount != null) * { * Msg = FCurrentAccount.AccountRow.AccountCode; * } * ShowStatus("SetSelectedAccount: " + Msg); */ } }
/// <summary> /// Create an AccountNodeDetails object for this account /// </summary> public static AccountNodeDetails AddNewAccount(TreeNode NewTreeNode, AAccountRow AccountRow, AAccountHierarchyDetailRow HierarchyDetailRow) { AccountNodeDetails NodeDetails = new AccountNodeDetails(); NodeDetails.CanHaveChildren = true; if (AccountRow.PostingStatus) // A "Posting account" that's not been used may yet be promoted to a "Summary account". { NodeDetails.CanHaveChildren = null; } else // A "Summary account" can have children. { NodeDetails.CanHaveChildren = true; } NodeDetails.IsNew = true; NodeDetails.DetailRow = HierarchyDetailRow; NodeDetails.AccountRow = AccountRow; NewTreeNode.Tag = NodeDetails; NodeDetails.linkedTreeNode = NewTreeNode; return(NodeDetails); }
private void treeView_DragOver(object sender, DragEventArgs e) { Point pt = trvAccounts.PointToClient(new Point(e.X, e.Y)); FDragTarget = trvAccounts.GetNodeAt(pt); if (FDragTarget == null) { return; } ScrollIntoView(FDragTarget); // Is the referenced node a valid drop target? bool CantDropHere = (FDragTarget == FDragNode) || IsDescendantOf(FDragTarget, FDragNode); if (!CantDropHere) { AccountNodeDetails NodeDetails = (AccountNodeDetails)FDragTarget.Tag; NodeDetails.GetAttrributes(); if (!NodeDetails.CanHaveChildren.Value) { CantDropHere = true; } } if (CantDropHere) { e.Effect = DragDropEffects.Scroll; FDragTarget = null; } else { e.Effect = DragDropEffects.Move | DragDropEffects.Scroll; ShowNodeSelected(FDragTarget); } }
/// <summary> /// The fact that the AccountCode is the database primary key causes SO MUCH GRIEF all over the system! /// </summary> /// <param name="AAccountNode"></param> /// <returns></returns> private Boolean ProtectedChangeOfPrimaryKey(AccountNodeDetails AAccountNode) { String NewValue = txtDetailAccountCode.Text; try { AAccountNode.AccountRow.AccountCode = NewValue; AAccountNode.DetailRow.ReportingAccountCode = NewValue; return true; } catch (System.Data.ConstraintException) { txtDetailAccountCode.Text = strOldDetailAccountCode; FRecentlyUpdatedDetailAccountCode = INTERNAL_UNASSIGNED_DETAIL_ACCOUNT_CODE; ShowStatus(Catalog.GetString("Account Code change REJECTED!")); MessageBox.Show(String.Format( Catalog.GetString( "Renaming Account Code '{0}' to '{1}' is not possible because an Account Code by the name of '{1}' already exists." + "\r\n\r\n--> Account Code reverted to previous value."), strOldDetailAccountCode, NewValue), Catalog.GetString("Renaming Not Possible - Conflicts With Existing Account Code"), MessageBoxButtons.OK, MessageBoxIcon.Error); txtDetailAccountCode.Focus(); } return false; }
/// <summary> /// Create an AccountNodeDetails object for this account /// </summary> public static AccountNodeDetails AddNewAccount(TreeNode NewTreeNode, AAccountRow AccountRow, AAccountHierarchyDetailRow HierarchyDetailRow) { AccountNodeDetails NodeDetails = new AccountNodeDetails(); NodeDetails.CanHaveChildren = true; if (AccountRow.PostingStatus) // A "Posting account" that's not been used may yet be promoted to a "Summary account". { NodeDetails.CanHaveChildren = null; } else // A "Summary account" can have children. { NodeDetails.CanHaveChildren = true; } NodeDetails.IsNew = true; NodeDetails.DetailRow = HierarchyDetailRow; NodeDetails.AccountRow = AccountRow; NewTreeNode.Tag = NodeDetails; NodeDetails.linkedTreeNode = NewTreeNode; return NodeDetails; }
/// <summary> /// Show all the data (Account Code and description) /// </summary> public void PopulateListView(GLSetupTDS MainDS, Int32 LedgerNumber, String SelectedHierarchy) { // FLedgerNumber = LedgerNumber; // FSelectedHierarchy = SelectedHierarchy; FDataView = new DataView(MainDS.AAccount); FDataView.Sort = "a_account_code_c"; FDataView.AllowNew = false; grdAccounts.DataSource = new DevAge.ComponentModel.BoundDataView(FDataView); grdAccounts.Columns.Clear(); grdAccounts.AddTextColumn(Catalog.GetString("Code"), MainDS.AAccount.ColumnAccountCode); grdAccounts.AddTextColumn(Catalog.GetString("Descr"), MainDS.AAccount.ColumnAccountCodeShortDesc); grdAccounts.AddCurrencyColumn(Catalog.GetString("YTD Actual"), MainDS.AAccount.ColumnYtdActualBase); grdAccounts.AddCurrencyColumn(Catalog.GetString("Foreign"), MainDS.AAccount.ColumnYtdActualForeign); if (FSelectedAccount != null) { this.SelectedAccount = FSelectedAccount; } else { grdAccounts.SelectRowInGrid(0); } }