/// <summary> /// The fact that the CostCentreCode is the database primary key causes SO MUCH GRIEF all over the system! /// </summary> /// <param name="ACostCentreNode"></param> /// <returns></returns> private Boolean ProtectedChangeOfPrimaryKey(CostCentreNodeDetails ACostCentreNode) { String NewValue = txtDetailCostCentreCode.Text; try { ACostCentreNode.CostCentreRow.CostCentreCode = NewValue; return true; } catch (System.Data.ConstraintException) { txtDetailCostCentreCode.Text = strOldDetailCostCentreCode; FRecentlyUpdatedDetailCostCentreCode = INTERNAL_UNASSIGNED_DETAIL_COSTCENTRE_CODE; ShowStatus(Catalog.GetString("Account Code change REJECTED!")); MessageBox.Show(String.Format( Catalog.GetString( "Renaming Cost Centre Code '{0}' to '{1}' is not possible because a Cost Centre Code by the name of '{1}' already exists." + "\r\n\r\n--> Cost Centre Code reverted to previous value."), strOldDetailCostCentreCode, NewValue), Catalog.GetString("Renaming Not Possible - Conflicts With Existing Cost Centre Code"), MessageBoxButtons.OK, MessageBoxIcon.Error); txtDetailCostCentreCode.Focus(); } return false; }
private void InsertNodeIntoTreeView(TreeNode AParent, DataView view, ACostCentreRow ADetailRow) { TreeNode newNode = new TreeNode(""); CostCentreNodeDetails NewNodeDetails = CostCentreNodeDetails.AddNewCostCentre(newNode, ADetailRow); NewNodeDetails.IsNew = false; SetNodeLabel(ADetailRow, newNode); if (AParent == null) { trvCostCentres.Nodes.Add(newNode); } else { InsertInOrder(AParent, newNode); } view.RowFilter = ACostCentreTable.GetCostCentreToReportToDBName() + " = '" + ADetailRow.CostCentreCode + "'"; if (view.Count > 0) { // A cost centre cannot be deleted if it has children. NewNodeDetails.CanDelete = false; NewNodeDetails.Msg = Catalog.GetString("Child Cost Centres must be deleted first."); NewNodeDetails.CanHaveChildren = true; foreach (DataRowView rowView in view) { InsertNodeIntoTreeView(newNode, view, (ACostCentreRow)rowView.Row); } } }
// End of (mostly copied) drag-drop functions private void InsertInOrder(TreeNode Parent, TreeNode Child) { int Idx; CostCentreNodeDetails ChildTag = (CostCentreNodeDetails)Child.Tag; for (Idx = 0; Idx < Parent.Nodes.Count; Idx++) { if (Parent.Nodes[Idx].Text.CompareTo(Child.Text) > 0) { break; } } if (Idx == Parent.Nodes.Count) { Parent.Nodes.Add(Child); } else { Parent.Nodes.Insert(Idx, Child); } if (!FDuringInitialisation) { FParentForm.SetSelectedCostCentre(ChildTag); } }
/// <summary> /// Make this CostCentre 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)) { CostCentreNodeDetails DraggedCostCentre = (CostCentreNodeDetails)AChild.Tag; if (DraggedCostCentre.CostCentreRow.SystemCostCentreFlag) { MessageBox.Show(String.Format(Catalog.GetString("{0} is a System Cost Centre and cannot be moved."), ((CostCentreNodeDetails)AChild.Tag).CostCentreRow.CostCentreCode), Catalog.GetString("Re-assign Cost Centre"), MessageBoxButtons.OK, MessageBoxIcon.Stop); ShowNodeSelected(null); return; } String PrevParent = AChild.Parent.Text; String NewParentCostCentreCode = ((CostCentreNodeDetails)ANewParent.Tag).CostCentreRow.CostCentreCode; TreeNode NewNode = (TreeNode)AChild.Clone(); DraggedCostCentre.CostCentreRow.CostCentreToReportTo = NewParentCostCentreCode; DraggedCostCentre.linkedTreeNode = NewNode; InsertInOrder(ANewParent, NewNode); NewNode.Expand(); ANewParent.Expand(); ((CostCentreNodeDetails)ANewParent.Tag).CostCentreRow.PostingCostCentreFlag = false; // The parent is now a summary CostCentre! ANewParent.BackColor = Color.White; FParentForm.ShowStatus(String.Format(Catalog.GetString("{0} was moved from {1} to {2}."), AChild.Text, PrevParent, ANewParent.Text)); //Remove Original Node AChild.Remove(); FPetraUtilsObject.SetChangedFlag(); } }
/// <summary> /// Add this new CostCentre as child of the currently selected node /// </summary> public void AddNewCostCentre(ACostCentreRow CostCentreRow) { trvCostCentres.BeginUpdate(); TreeNode newNode = trvCostCentres.SelectedNode.Nodes.Add(CostCentreRow.CostCentreCode); CostCentreNodeDetails NewCostCentre = CostCentreNodeDetails.AddNewCostCentre(newNode, CostCentreRow); trvCostCentres.EndUpdate(); FParentForm.SetSelectedCostCentre(NewCostCentre); // This will set my FSelectedCostCentre and my trvCostCentres.SelectedNode }
/// <summary> /// Called from the user controls when the user selects a row, /// this common method keeps both user controls in sync. /// </summary> public void SetSelectedCostCentre(CostCentreNodeDetails AnewSelection) { FCurrentCostCentre = AnewSelection; ucoCostCentreList.SelectedCostCentre = AnewSelection; ucoCostCentreTree.SelectedCostCentre = AnewSelection; pnlDetails.Enabled = (AnewSelection != null); if (pnlDetails.Enabled) { strOldDetailCostCentreCode = FCurrentCostCentre.CostCentreRow.CostCentreCode; Console.WriteLine("Current account code is {0}", FCurrentCostCentre.CostCentreRow.CostCentreCode); } }
/// <summary> /// Create an CostCentreNodeDetails object for this CostCentre /// </summary> public static CostCentreNodeDetails AddNewCostCentre(TreeNode NewTreeNode, ACostCentreRow CostCentreRow) { CostCentreNodeDetails NodeDetails = new CostCentreNodeDetails(); NodeDetails.CanHaveChildren = true; if (CostCentreRow.PostingCostCentreFlag) // A "Posting CostCentre" that's not been used may yet be promoted to a "Summary CostCentre". { NodeDetails.CanHaveChildren = null; } else // A "Summary CostCentre" can have children. { NodeDetails.CanHaveChildren = true; } NodeDetails.IsNew = true; NodeDetails.CostCentreRow = CostCentreRow; NewTreeNode.Tag = NodeDetails; NodeDetails.linkedTreeNode = NewTreeNode; return NodeDetails; }
private void treeView_DragOver(object sender, DragEventArgs e) { Point pt = trvCostCentres.PointToClient(new Point(e.X, e.Y)); FDragTarget = trvCostCentres.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) { CostCentreNodeDetails NodeDetails = (CostCentreNodeDetails)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> /// Change CostCentre Value /// /// The Cost Centre code is a foreign key in loads of tables, /// so renaming a Cost Centre code is a major work on the server. /// From the client's perspective it's easy - we just need to ask the server to do it! /// /// </summary> private bool CheckCostCentreValueChanged() { if ((FIAmUpdating > 0) || (strOldDetailCostCentreCode == null)) { return false; } String strNewDetailCostCentreCode = txtDetailCostCentreCode.Text; bool changeAccepted = false; if (strNewDetailCostCentreCode != FRecentlyUpdatedDetailCostCentreCode) { if (strNewDetailCostCentreCode != strOldDetailCostCentreCode) { if (strOldDetailCostCentreCode.IndexOf(FnameForNewCostCentre) < 0) // If they're just changing this from the initial value, don't show warning. { if (MessageBox.Show(String.Format(Catalog.GetString( "You have changed the Cost Centre Code from '{0}' to '{1}'.\r\n\r\n" + "Please confirm that you want to rename this Cost Centre Code by choosing 'OK'.\r\n\r\n" + "(Renaming will take a few moments, then the form will be re-loaded.)"), strOldDetailCostCentreCode, strNewDetailCostCentreCode), Catalog.GetString("Rename Cost Centre Code: Confirmation"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK) { txtDetailCostCentreCode.Text = strOldDetailCostCentreCode; btnRename.Visible = false; return false; } } this.UseWaitCursor = true; this.Refresh(); FRecentlyUpdatedDetailCostCentreCode = strNewDetailCostCentreCode; changeAccepted = ProtectedChangeOfPrimaryKey(FCurrentCostCentre); if (changeAccepted) { ucoCostCentreTree.SetNodeLabel(FCurrentCostCentre.CostCentreRow); if (FCurrentCostCentre.IsNew) { // This is the code for changes in "un-committed" nodes: // there are no references to this new row yet, apart from children nodes, so I can just change them here and carry on! // fixup children nodes ucoCostCentreTree.FixupChildrenAfterCostCentreNameChange(); strOldDetailCostCentreCode = strNewDetailCostCentreCode; FPetraUtilsObject.HasChanges = true; } else { ShowStatus(Catalog.GetString("Updating Cost Centre Code change - please wait.\r\n")); TVerificationResultCollection VerificationResults; // If this code was previously in the DB, I need to assume that there may be transactions posted against it. // There's a server call I need to use, and after the call I need to re-load this page. // (No other changes will be lost, because the change would not have been allowed if there were already changes.) this.Cursor = Cursors.WaitCursor; bool Success = TRemote.MFinance.Setup.WebConnectors.RenameCostCentreCode(strOldDetailCostCentreCode, strNewDetailCostCentreCode, FLedgerNumber, out VerificationResults); this.Cursor = Cursors.Default; if (Success) { TDataCache.TMFinance.RefreshCacheableFinanceTable(Shared.TCacheableFinanceTablesEnum.CostCentreList, FLedgerNumber); FMainDS = TRemote.MFinance.Setup.WebConnectors.LoadCostCentreHierarchy(FLedgerNumber); strOldDetailCostCentreCode = ""; FIAmUpdating++; FPetraUtilsObject.SuppressChangeDetection = false; txtDetailCostCentreCode.Text = ""; FPetraUtilsObject.SuppressChangeDetection = false; FCurrentCostCentre = null; ucoCostCentreTree.PopulateTreeView(FMainDS); ucoCostCentreList.PopulateListView(FMainDS, FLedgerNumber); FIAmUpdating--; ucoCostCentreTree.SelectNodeByName(FRecentlyUpdatedDetailCostCentreCode); ClearStatus(); changeAccepted = true; ShowStatus(String.Format("Cost Centre Code changed to '{0}'.\r\n", strNewDetailCostCentreCode)); } else { MessageBox.Show(VerificationResults.BuildVerificationResultString(), Catalog.GetString("Rename Cost Centre Code")); } } } // if changeAccepted this.UseWaitCursor = false; } // if changed } return changeAccepted; }
private String IsLockedByParent(CostCentreNodeDetails ThisNode) { TreeNode Parent = ThisNode.linkedTreeNode.Parent; if (Parent == null) { return ""; } CostCentreNodeDetails ParentNode = (CostCentreNodeDetails)Parent.Tag; if (ParentNode.CostCentreRow.RollupStyle.IndexOf("LOCK_") == 0) { return ParentNode.CostCentreRow.CostCentreCode; } else { return IsLockedByParent(ParentNode); } }
private void ShowEquityOrClearingControls(CostCentreNodeDetails AnewSelection) { FPetraUtilsObject.SuppressChangeDetection = true; grpClearing.Visible = (AnewSelection.CostCentreRow.CostCentreType == "Foreign"); grpEquitySettings.Visible = ((!grpClearing.Visible) && (AnewSelection.CostCentreRow.CostCentreCode != MFinanceConstants.INTER_LEDGER_HEADING)); grpProjectStatusBox.Visible = grpEquitySettings.Visible && AnewSelection.CostCentreRow.PostingCostCentreFlag; grpEquitySettings.Height = grpProjectStatusBox.Visible ? 70 : 170; FPetraUtilsObject.SuppressChangeDetection = false; }