private Boolean HasFamilyFamilyMembers() { Boolean ReturnValue; DataView TmpDV; ReturnValue = false; if (FMainDS.Tables.Contains(PartnerEditTDSFamilyMembersTable.GetTableName())) { TmpDV = new DataView(FMainDS.FamilyMembers, "", "", DataViewRowState.CurrentRows); if (TmpDV.Count > 0) { ReturnValue = true; } } else { if (FMainDS.MiscellaneousData[0].ItemsCountFamilyMembers > 0) { ReturnValue = true; } } return(ReturnValue); }
/// <summary> /// Loads FamilyMembers Data from Petra Server into FMainDS. /// /// </summary> /// <returns>true if successful and Family has Family Members, otherwise false. /// //DevAge.ComponentModel.Validator;</returns> public Boolean LoadDataOnDemand() { Boolean ReturnValue; TRecalculateScreenPartsEventArgs RecalculateScreenPartsEventArgs; Int64 FamilyPartnerKey; if (FMainDS.PPartner[0].PartnerClass == SharedTypes.PartnerClassEnumToString(TPartnerClass.FAMILY)) { FamilyPartnerKey = FMainDS.PFamily[0].PartnerKey; } else { FamilyPartnerKey = FMainDS.PPerson[0].FamilyKey; } // retrieve Family Members from PetraServer // If family has no members, returns false try { // Make sure that Typed DataTable is already there at Client side if (FMainDS.FamilyMembers == null) { FMainDS.Tables.Add(new PartnerEditTDSFamilyMembersTable(PartnerEditTDSFamilyMembersTable.GetTableName())); FMainDS.InitVars(); } FMainDS.FamilyMembers.Rows.Clear(); FMainDS.Merge(FPartnerEditUIConnector.GetDataFamilyMembers(FamilyPartnerKey, "")); FMainDS.FamilyMembers.AcceptChanges(); if (FMainDS.FamilyMembers.Rows.Count > 0) { ReturnValue = true; } else { ReturnValue = false; } } catch (System.NullReferenceException) { ReturnValue = false; return(false); } catch (Exception) { ReturnValue = false; // raise; } // Fire OnRecalculateScreenParts event RecalculateScreenPartsEventArgs = new TRecalculateScreenPartsEventArgs(); RecalculateScreenPartsEventArgs.ScreenPart = TScreenPartEnum.spCounters; OnRecalculateScreenParts(RecalculateScreenPartsEventArgs); FDataGrid.Selection.Focus(new Position(1, 1), true); return(ReturnValue); }
/// <summary> /// Sets up the DataBinding of the Grid. /// /// </summary> /// <returns>void</returns> public void DataBindGrid() { FFamilyMembersDV = FFamilyMembersDT.DefaultView; FFamilyMembersDV.AllowNew = false; FFamilyMembersDV.AllowEdit = true; FFamilyMembersDV.AllowDelete = false; FFamilyMembersDV.Sort = PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName() + " ASC"; // DataBind the DataGrid this.FDataGrid.DataSource = new DevAge.ComponentModel.BoundDataView(FFamilyMembersDV); this.FDataGrid.Selection.SelectRow(1, true); }
/// <summary> /// This function determines the current PartnerKey /// /// </summary> /// <returns>void</returns> public Int64 DeterminePartnerKeyFromRowNumber(System.Int32 ARowNumber) { System.Data.DataRowView mRowView; System.Data.DataRow mRow; System.Object mObject; // TLogging.Log('Begin of DeterminePartnerKeyFromRowNumber: ' + ARowNumber.ToString, [TLoggingType.ToLogfile]); // Grid starts counting with 1 mRowView = (DataRowView)this.FDataGrid.Rows.IndexToDataSourceRow(ARowNumber + 1); mRow = mRowView.Row; mObject = mRow[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()]; return((System.Int64)(mObject)); // TLogging.Log('PartnerKey: ' + Result.ToString, [TLoggingType.ToLogfile]); // TLogging.Log('End of DeterminePartnerKeyFromRowNumber: ' + ARowNumber.ToString, [TLoggingType.ToLogfile]); }
/// <summary> /// returns Arraylist that has FamilyID and PartnerID pairs. For testing purposes. /// </summary> /// <returns>void</returns> public ArrayList PrintOrder() { Int32 i; ArrayList List; List = new ArrayList(); // Goes through the FamilyMembers, and list FamilyID and PartnerKey for (i = 0; i <= (GetNumberOfRows() - 1); i += 1) { List.Add(Convert.ToString(FFamilyMembersDV[i].Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()]) + ':' + Convert.ToString(FFamilyMembersDV[i].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()])); } return(List); }
/// <summary> /// Sets the order of colums /// </summary> /// <returns>void</returns> public void CreateColumns() { SourceGrid.Cells.Editors.TextBoxUITypeEditor l_editorDt2; Ict.Common.TypeConverter.TDateConverter DateTypeConverter; FFamilyMembersDT = FMainDS.FamilyMembers; // Editor for Date of Birth column (Petra Date format) l_editorDt2 = new SourceGrid.Cells.Editors.TextBoxUITypeEditor(typeof(DateTime)); l_editorDt2.EditableMode = EditableMode.None; DateTypeConverter = new Ict.Common.TypeConverter.TDateConverter(); // DateTypeConverter. l_editorDt2.TypeConverter = DateTypeConverter; try { this.FDataGrid.AddTextColumn("Person Name", FFamilyMembersDT.Columns[PartnerEditTDSFamilyMembersTable.GetPartnerShortNameDBName()], -1, FSpecialCellController, null, null, null); this.FDataGrid.AddTextColumn("Gender", FFamilyMembersDT.Columns[PartnerEditTDSFamilyMembersTable.GetGenderDBName()], -1, FSpecialCellController, null, null, null); this.FDataGrid.AddTextColumn("Date of Birth", FFamilyMembersDT.Columns[PartnerEditTDSFamilyMembersTable.GetDateOfBirthDBName()], -1, FSpecialCellController, l_editorDt2, null, null); this.FDataGrid.AddTextColumn("Partner Key", FFamilyMembersDT.Columns[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()], -1, FSpecialCellController, null, null, null); FamilyIDDropDownValues = new Int32[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; FFamilyIDEditor = new SourceGrid.Cells.Editors.ComboBox(typeof(Int32), FamilyIDDropDownValues, false); this.FDataGrid.AddTextColumn("Family ID", FFamilyMembersDT.Columns[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()], 80, FFamilyIDEditor); DisableEditing(); FFamilyIDEditor.EnableEdit = false; FFamilyIDEditor.Control.Validating += new CancelEventHandler(this.FamilyID_Validating); // DevAge.ComponentModel.Validator.ValueMapping FamilyIDDropDownMapping = new DevAge.ComponentModel.Validator.ValueMapping(); } catch (System.NullReferenceException) { } // to do if no lines. }
/// <summary> /// Finds out the number of row, and it's Partnerkey in datagrid that's selected. /// </summary> /// <returns>void</returns> public void GetRowSelected(out Int32 ARowNumber, out Int64 ASiteKey) { System.Int32 CurrentRow; DataView AGridDataView; AGridDataView = ((DevAge.ComponentModel.BoundDataView)FDataGrid.DataSource).DataView; ARowNumber = 0; ASiteKey = Convert.ToInt64(((DataRowView)FDataGrid.SelectedDataRows[0]).Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()]); // goes throuhg the FamilyID:s in datagrid, break when comes to selected. for (CurrentRow = 0; CurrentRow <= AGridDataView.Count - 1; CurrentRow += 1) { ARowNumber = ARowNumber + 1; if (Convert.ToInt64(AGridDataView[CurrentRow].Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()]) == ASiteKey) { break; } } }
/// <summary> /// This function determines the current PartnerKey /// /// </summary> /// <returns>void</returns> public Int64 DetermineCurrentFamilyMemberPartnerKey(TSgrdDataGrid AGrid) { DataRowView[] TheDataRowViewArray; Int64 PersonPartnerKey; // MessageBox.Show(ARow.ToString); TheDataRowViewArray = AGrid.SelectedDataRowsAsDataRowView; // get PartnerKey of current DataRow try { PersonPartnerKey = Convert.ToInt64(TheDataRowViewArray[0].Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()]); } catch (Exception) { throw; } // MessageBox.Show(PersonPartnerKey.ToString); return(PersonPartnerKey); }
/// <summary> /// This procedure initializes this System.Object. /// /// </summary> /// <returns>void</returns> public void InitialisePartnerTypeFamilyMembers(PartnerEditTDSFamilyMembersTable AFamilyMembersDT) { // Create the result table if (FFamilyMembersResultDT == null) { FFamilyMembersResultDT = new PartnerEditTDSPartnerTypeChangeFamilyMembersPromotionTable(); } // Logger := new Ict.Common.Logging.TLogging('U:\delphi.net\ICT\Petra\Client\_bin\Debug\Propagation.log'); // Set the column names for the FFamilyMembersResultDT table. this.FResultPartnerKeyName = PartnerEditTDSPartnerTypeChangeFamilyMembersPromotionTable.GetPartnerKeyDBName(); this.FResultTypeCodeName = PartnerEditTDSPartnerTypeChangeFamilyMembersPromotionTable.GetTypeCodeDBName(); this.FResultAddTypeCodeName = PartnerEditTDSPartnerTypeChangeFamilyMembersPromotionTable.GetAddTypeCodeDBName(); this.FResultRemoveTypeCodeName = PartnerEditTDSPartnerTypeChangeFamilyMembersPromotionTable.GetRemoveTypeCodeDBName(); // Set the column names for the FFamilyMembersDT table. this.FFamilyMembersDT = AFamilyMembersDT; this.FTypeCodeModifyName = PartnerEditTDSFamilyMembersTable.GetTypeCodeModifyDBName(); this.FTypeCodePresentName = PartnerEditTDSFamilyMembersTable.GetTypeCodePresentDBName(); this.FPartnerKeyName = PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName(); }
/// <summary> /// Checks if the selected FamilyID is maximum. /// </summary> /// <returns>void</returns> public Boolean IsMaximum() { Boolean ReturnValue = false; Int32 Counter; Int32 FamilyIDint; FamilyIDint = Convert.ToInt32(((DataRowView)FDataGrid.SelectedDataRows[0])[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()]); // Goes throuht the FamilyID:s, If finds larger than selected, breaks and returns false. Otherwice true. for (Counter = 0; Counter <= (this.GetNumberOfRows() - 1); Counter += 1) { if (Convert.ToInt64(FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()]) > FamilyIDint) { ReturnValue = false; break; } ReturnValue = true; } return(ReturnValue); }
/// <summary> /// This procedure creates the colums of the DataGrid displayed /// /// </summary> /// <returns>void</returns> public void CreateColumns(TSgrdDataGrid AGrid, System.Data.DataTable ASourceTable, String AAction) { String FAddRemoveHeaderText; SourceGrid.Cells.Editors.TextBoxUITypeEditor l_editor; Ict.Common.TypeConverter.TBooleanToYesNoConverter BooleanToYesNoConverter; l_editor = new SourceGrid.Cells.Editors.TextBoxUITypeEditor(typeof(Boolean)); l_editor.EditableMode = EditableMode.None; BooleanToYesNoConverter = new Ict.Common.TypeConverter.TBooleanToYesNoConverter(); // PetraDtConverter. l_editor.TypeConverter = BooleanToYesNoConverter; this.DataGrid = AGrid; // Assemble column heading if (AAction == "ADD") { FAddRemoveHeaderText = "Add?"; this.FAction = "ADD"; } else { FAddRemoveHeaderText = "Remove?"; this.FAction = "REMOVE"; } // TLogging.Log('Hello Test Markusm: ', [TLoggingType.ToLogfile]); this.FDataGrid.AddCheckBoxColumn(FAddRemoveHeaderText, ASourceTable.Columns[PartnerEditTDSFamilyMembersTable.GetTypeCodeModifyDBName()]); this.FDataGrid.AddTextColumn("Currently assigned", ASourceTable.Columns[PartnerEditTDSFamilyMembersTable.GetTypeCodePresentDBName()], -1, FSpecialCellController, l_editor, null, null); this.FDataGrid.AddTextColumn("Person Name", ASourceTable.Columns[PartnerEditTDSFamilyMembersTable.GetPartnerShortNameDBName()]); this.FDataGrid.AddTextColumn("Person PartnerKey", ASourceTable.Columns[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()]); this.FDataGrid.AddTextColumn("Family ID", ASourceTable.Columns[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()]); // Add controller to each line // mNumberRows := AGrid.Rows.Count; // messagebox.show('Number of rows in the grid: ' + mNumberRows.ToString); }
/// <summary> /// gets asd sets the combox values. Redraws the grids last column. causes errors. /// </summary> /// <returns>void</returns> public void GetComboBoxValues(out Int32[] ComboBoxValues) { Int32 Counter; ArrayList List; String epo; // fills the list with numbers 0,1,...9 ComboBoxValues = new Int32[(10 - GetNumberOfRows())]; List = new ArrayList(); for (Counter = 0; Counter <= 9; Counter += 1) { List.Add(Counter.ToString()); } // removes the existing familyID:s from the list for (Counter = 0; Counter <= this.GetNumberOfRows() - 1; Counter += 1) { epo = Convert.ToString(FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()]); List.Remove(epo); // ShowArraylistMembers(List); } // creates the array of int 32 of the ArrayList members for (Counter = 0; Counter <= List.Count - 1; Counter += 1) { try { ComboBoxValues[Counter] = Convert.ToInt32(List[Counter]); } catch (System.ArgumentOutOfRangeException e) { MessageBox.Show("Again a error:" + e.ToString()); } } }
private void FamilyID_Validating(object sender, System.ComponentModel.CancelEventArgs e) { const int NEWFAMILYID_DEFAULT = -1; Int32 Counter; Int64 PartnerKey; Boolean IsInUse; IsInUse = false; int NewFamilyID = NEWFAMILYID_DEFAULT; bool ValidFormat = true; try { try { NewFamilyID = Convert.ToInt32((sender as Control).Text); } catch (System.FormatException) { ValidFormat = false; } catch (Exception exp) { e.Cancel = true; MessageBox.Show("Exception in FamilyID_Validating: " + exp.ToString()); throw; } if (ValidFormat) { if ((NewFamilyID < 0) || (NewFamilyID > 99)) { MessageBox.Show("Family ID needs to be a number between 0 and 99!"); e.Cancel = true; return; } } else { MessageBox.Show("Only numbers are allowed as Family IDs!"); e.Cancel = true; return; } PartnerKey = this.GetPartnerKeySelected(); // checks if the FamilyID selected from the Combobox is already in use for (Counter = 0; Counter <= (GetNumberOfRows() - 1); Counter += 1) { if (FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()].ToString() == NewFamilyID.ToString()) { if (FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()].ToString() == this.GetFamilyID().ToString()) { break; } IsInUse = true; // the validating event is cancelled. (for saving the old FamilyID e.Cancel = true; break; } } // if The Family ID selected from the Combobox is already in use, copies the old FamilyID to that Person edited. // This needs to be done, because the combobox (or FFamilyIDEditor) is databinded to the database. if (IsInUse) { for (Counter = 0; Counter <= (GetNumberOfRows() - 1); Counter += 1) { if (FFamilyMembersDV[Counter].Row == (object)PartnerKey) { FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()] = (object)this.GetFamilyID(); // Int32 LocationMemory = Counter; break; } } MessageBox.Show("Please, select another Family ID, the one you selected (" + NewFamilyID.ToString() + ") is already in use!"); } } catch { throw; } }
/// <summary> /// Demotes selected ID (and promotes the FamilyID next (lower) to selected FamilyID /// </summary> /// <returns>void</returns> public void DemoteFamilyID() { Int32 Buttonvalue = -1; Int32 NumberOfRows; Int32 Counter; Int32 CounterToMax; Int32 FamilyIDint; System.Object PartnerKey; System.Object FamilyID = -1; System.Object PreviousFamilyID = -1; System.Object PersonName1 = ""; System.Object PersonName2 = ""; Boolean MemberFind; MessageBoxButtons Button; // Get the PartnerKey of the selected Row PartnerKey = ((DataRowView)FDataGrid.SelectedDataRows[0]).Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()]; NumberOfRows = GetNumberOfRows(); // for loop to get the selected partners ID for (Counter = 0; Counter <= (NumberOfRows - 1); Counter += 1) { if (FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()].ToString() == PartnerKey.ToString()) { FamilyID = FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()]; PersonName1 = FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetPartnerShortNameDBName()]; break; } } if ((this.IsMinimum()) && (Convert.ToInt32(FamilyID) > 0)) { FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()] = (object)0; Buttonvalue = 1; FamilyID = (object)0; } // loop to find the nearest smaller FamilyID compared to selected FamilyID. // sets the previous FamilyID to correct. MemberFind = true; FamilyIDint = Convert.ToInt32(FamilyID); // If Family ID is 2, or A parent is to be replaced with child, gives warning. if (FamilyIDint == 2) { Button = MessageBoxButtons.YesNo; if (MessageBox.Show("Parents should be Family ID 0 or 1" + "\r\nAre you sure you want to change this Family ID?", "Family ID Change", Button) == DialogResult.No) { Buttonvalue = 1; } } // if FamilyID to be demoted is 2 and cancel is selected from warnind messagebox, does nothing. otherwice goes through the for loop if (Buttonvalue != 1) { // Goes through the FamilyID:s from 1 to selected FamilyID for (CounterToMax = 1; CounterToMax <= FamilyIDint; CounterToMax += 1) { // Goes through all the FamilyID:s for (Counter = 0; Counter <= (NumberOfRows - 1); Counter += 1) { // when finds FamilyID next to selected (below), Sets the found Family ID to selected if (Convert.ToInt32(FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()].ToString()) == (FamilyIDint - CounterToMax)) { // saves the found FamilyID PreviousFamilyID = FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()]; FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()] = (object)(Convert.ToInt32(PreviousFamilyID) + 1); PersonName2 = FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetPartnerShortNameDBName()]; if (PersonName2 == PersonName1) { PersonName1 = PreviousPartnerMemory; } MemberFind = false; break; } } if (!MemberFind) { break; } } // loop to set the selected FamilyID to the PreviousFamilyID for (Counter = 0; Counter <= (NumberOfRows - 1); Counter += 1) { if (FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()].ToString() == PartnerKey.ToString()) { FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()] = PreviousFamilyID; break; } } MessageBox.Show(String.Format(StrFamilyIDChangeDone, PersonName1, FamilyID, PreviousFamilyID, PersonName2, PreviousFamilyID, (Convert.ToInt32(PreviousFamilyID) + 1)), StrFamilyIDChangeDoneTitle); PreviousPartnerMemory = PersonName1; } else { } }
/// <summary> /// Sets the order of colums /// </summary> /// <returns>void</returns> private void CreateGridColumns() { SourceGrid.Cells.Editors.TextBoxUITypeEditor l_editorDt2; Ict.Common.TypeConverter.TDateConverter DateTypeConverter; FFamilyMembersDT = FMainDS.FamilyMembers; // Editor for Date of Birth column (Petra Date format) l_editorDt2 = new SourceGrid.Cells.Editors.TextBoxUITypeEditor(typeof(DateTime)); l_editorDt2.EditableMode = EditableMode.None; DateTypeConverter = new Ict.Common.TypeConverter.TDateConverter(); // DateTypeConverter. l_editorDt2.TypeConverter = DateTypeConverter; try { grdFamilyMembers.AddTextColumn("Person Name", FFamilyMembersDT.Columns[PartnerEditTDSFamilyMembersTable.GetPartnerShortNameDBName()], -1, FSpecialCellController, null, null, null); grdFamilyMembers.AddTextColumn("Gender", FFamilyMembersDT.Columns[PartnerEditTDSFamilyMembersTable.GetGenderDBName()], -1, FSpecialCellController, null, null, null); grdFamilyMembers.AddTextColumn("Date of Birth", FFamilyMembersDT.Columns[PartnerEditTDSFamilyMembersTable.GetDateOfBirthDBName()], -1, FSpecialCellController, l_editorDt2, null, null); grdFamilyMembers.AddPartnerKeyColumn("Partner Key", FFamilyMembersDT.Columns[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()]); FamilyIDDropDownValues = new Int32[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; FFamilyIDEditor = new SourceGrid.Cells.Editors.ComboBox(typeof(Int32), FamilyIDDropDownValues, false); grdFamilyMembers.AddTextColumn("Family ID", FFamilyMembersDT.Columns[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()], 80, FFamilyIDEditor); DisableEditing(); FFamilyIDEditor.EnableEdit = false; FFamilyIDEditor.Control.Validating += new CancelEventHandler(this.FamilyID_Validating); // DevAge.ComponentModel.Validator.ValueMapping FamilyIDDropDownMapping = new DevAge.ComponentModel.Validator.ValueMapping(); } catch (System.NullReferenceException) { } // to do if no lines. }
private void SpecialSubmitProcessingFamilyMembers( PartnerEditTDSFamilyMembersTable AFamilyMembersTable, TDBTransaction ASubmitChangesTransaction) { Int32 DummyCounter = 100; /* * Load the Persons of a Family */ PPersonTable FamilyPersonsDT = PPersonAccess.LoadViaPFamily(FPartnerEditScreenDS.PFamily[0].PartnerKey, ASubmitChangesTransaction); /* * Now change the FamilyID of those rows that have been modified on the * Client side (first to a dummy value to prevent uniqueness constraint * violations) */ for (int Counter = 0; Counter <= AFamilyMembersTable.Rows.Count - 1; Counter += 1) { PPersonRow ChangePersonRow = (PPersonRow)FamilyPersonsDT.Rows.Find(new Object[] { AFamilyMembersTable[Counter].PartnerKey }); ChangePersonRow.FamilyId = DummyCounter; // TLogging.LogAtLevel(7, "Person " + ChangePersonRow.PartnerKey.ToString() + ": changed OldFamilyID to Dummy " + DummyCounter.ToString()); DummyCounter = DummyCounter - 1; } // Save the dummy values PPersonAccess.SubmitChanges(FamilyPersonsDT, ASubmitChangesTransaction); FamilyPersonsDT.AcceptChanges(); // Now change it to the real values for (int Counter = 0; Counter <= AFamilyMembersTable.Rows.Count - 1; Counter += 1) { PPersonRow ChangePersonRow = (PPersonRow)FamilyPersonsDT.Rows.Find(new Object[] { AFamilyMembersTable[Counter].PartnerKey }); ChangePersonRow.FamilyId = AFamilyMembersTable[Counter].FamilyId; // TLogging.LogAtLevel(7, "Person " + ChangePersonRow.PartnerKey.ToString() + ": changed OldFamilyID to " + ChangePersonRow.FamilyId.ToString()); } // Save the changes PPersonAccess.SubmitChanges(FamilyPersonsDT, ASubmitChangesTransaction); }
/// <summary> /// Promotes selected ID (and demotes the FamilyID next (up) to selected FamilyID /// </summary> /// <returns>void</returns> public void PromoteFamilyID() { Int32 buttonvalue = -1; Int32 Counter1; Int32 NumberOfRows; Int32 Counter2; Int32 Counter2ToMax; Int32 FamilyIDint; System.Object PartnerKey; System.Object FamilyID = -1; System.Object PersonName1 = ""; System.Object PersonName2 = ""; System.Object NextFamilyID = ""; Boolean MemberFind; MessageBoxButtons Button; // Get the PartnerKey of the selected Row PartnerKey = ((DataRowView)FDataGrid.SelectedDataRows[0]).Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()]; NumberOfRows = GetNumberOfRows(); // for loop to get the selected partners ID for (Counter2 = 0; Counter2 <= (NumberOfRows - 1); Counter2 += 1) { if (FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()].ToString() == PartnerKey.ToString()) { FamilyID = FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()]; PersonName1 = FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetPartnerShortNameDBName()]; break; } } // loop to find the nearest FamilyID compared to selected FamilyID. // sets the next FamilyID to correct. MemberFind = true; FamilyIDint = Convert.ToInt32(FamilyID); // If Family ID 1 (parent) is about to be promoted if (FamilyIDint == 1) { Button = MessageBoxButtons.YesNo; buttonvalue = 0; // if pressed No to question below, does nothing. if (MessageBox.Show("Parents should be Family ID 0 or 1" + "\r\nAre you sure you want to change this Family ID?", "Family ID Change", Button) == DialogResult.No) { buttonvalue = 1; } } // Executes this loop, if Family ID to be promoted is not 1. if (buttonvalue != 1) { Counter2ToMax = 100; // goes through all values from selected +1 to 100+selected. for (Counter1 = 1; Counter1 <= Counter2ToMax; Counter1 += 1) { // goes through all FamilyID:s for (Counter2 = 0; Counter2 <= (NumberOfRows - 1); Counter2 += 1) { // When finds FamilyID that's next (above) to selected FamilyID, Replaces the Found Family members ID with selected ID if (Convert.ToInt32(FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()].ToString()) == FamilyIDint + Counter1) { // saves the FamilyIF just found NextFamilyID = FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()]; FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()] = FamilyID; PersonName2 = FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetPartnerShortNameDBName()]; MemberFind = false; break; } } if (!MemberFind) { break; } } // end; // loop to set the selected FamilyID to the PreviousFamilyID for (Counter2 = 0; Counter2 <= (NumberOfRows - 1); Counter2 += 1) { if (FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()].ToString() == PartnerKey.ToString()) { FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()] = (object)(FamilyIDint + 1); break; } } // button := MessageBoxButtons.OK; MessageBox.Show(String.Format(StrFamilyIDChangeDone, PersonName1, FamilyID, (FamilyIDint + 1), PersonName2, NextFamilyID, FamilyID), StrFamilyIDChangeDoneTitle); } else { } }
private PartnerEditTDSFamilyMembersTable GetFamilyMembersInternal(Int64 AFamilyPartnerKey, String AWorkWithSpecialType, out Int32 ACount, Boolean ACountOnly) { TDBTransaction ReadTransaction; OdbcParameter[] ParametersArray; Boolean NewTransaction = false; PartnerEditTDSFamilyMembersTable PartnerTypeFamilyMembersDT; PPersonTable FamilyPersonsDT; PPartnerTypeTable PartnerTypesDT; DataRow[] PartnerTypesFoundRows; PartnerEditTDSFamilyMembersRow NewRow; StringCollection RequiredColumns; int Counter; Boolean TypeCodePresent; DataSet TmpDS; PartnerTypeFamilyMembersDT = new PartnerEditTDSFamilyMembersTable(); try { ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead, TEnforceIsolationLevel.eilMinimum, out NewTransaction); ParametersArray = new OdbcParameter[1]; ParametersArray[0] = new OdbcParameter("", OdbcType.Decimal, 10); ParametersArray[0].Value = (System.Object)AFamilyPartnerKey; if (ACountOnly) { ACount = Convert.ToInt32(DBAccess.GDBAccessObj.ExecuteScalar( "SELECT COUNT(*) " + "FROM PUB_" + PPersonTable.GetTableDBName() + " INNER JOIN " + "PUB_" + PPartnerTable.GetTableDBName() + " ON " + "PUB_" + PPersonTable.GetTableDBName() + '.' + PPartnerTable.GetPartnerKeyDBName() + " = " + "PUB_" + PPartnerTable.GetTableDBName() + '.' + PPartnerTable.GetPartnerKeyDBName() + ' ' + "WHERE " + PPersonTable.GetFamilyKeyDBName() + " = ? " + "AND " + PPartnerTable.GetStatusCodeDBName() + " <> '" + SharedTypes.StdPartnerStatusCodeEnumToString(TStdPartnerStatusCode.spscMERGED) + "'", ReadTransaction, ParametersArray)); // Make sure we don't count MERGED Partners (shouldn't have a p_family_key_n, but just in case.) } else { // Find all Persons that belong to the Family // TLogging.LogAtLevel(7, "TPartnerEditUIConnector.GetFamilyMembersInternal: loading Persons for Family " + AFamilyPartnerKey.ToString() + "..."); TmpDS = new DataSet(); FamilyPersonsDT = new PPersonTable(); TmpDS.Tables.Add(FamilyPersonsDT); DBAccess.GDBAccessObj.Select(TmpDS, "SELECT " + "PUB_" + PPartnerTable.GetTableDBName() + '.' + PPartnerTable.GetPartnerKeyDBName() + ", " + PPersonTable.GetFamilyNameDBName() + ", " + PPersonTable.GetTitleDBName() + ", " + PPersonTable.GetFirstNameDBName() + ", " + PPersonTable.GetMiddleName1DBName() + ", " + PPersonTable.GetFamilyIdDBName() + ", " + PPersonTable.GetGenderDBName() + ", " + PPersonTable.GetDateOfBirthDBName() + ' ' + "FROM PUB_" + PPersonTable.GetTableDBName() + " INNER JOIN " + "PUB_" + PPartnerTable.GetTableDBName() + " ON " + "PUB_" + PPersonTable.GetTableDBName() + '.' + PPartnerTable.GetPartnerKeyDBName() + " = " + "PUB_" + PPartnerTable.GetTableDBName() + '.' + PPartnerTable.GetPartnerKeyDBName() + ' ' + "WHERE " + PPersonTable.GetFamilyKeyDBName() + " = ? " + "AND " + PPartnerTable.GetStatusCodeDBName() + " <> '" + SharedTypes.StdPartnerStatusCodeEnumToString(TStdPartnerStatusCode.spscMERGED) + "'", // Make sure we don't load MERGED Partners (shouldn't have a p_family_key_n, but just in case.) PPersonTable.GetTableName(), ReadTransaction, ParametersArray, 0, 0); ACount = FamilyPersonsDT.Rows.Count; RequiredColumns = new StringCollection(); RequiredColumns.Add(PPartnerTypeTable.GetTypeCodeDBName()); TypeCodePresent = false; // Add Persons to Table for (Counter = 0; Counter <= FamilyPersonsDT.Rows.Count - 1; Counter += 1) { // Load a Person's SpecialTypes if requested if (AWorkWithSpecialType != "") { PartnerTypesDT = PPartnerTypeAccess.LoadViaPPartner( FamilyPersonsDT[Counter].PartnerKey, RequiredColumns, ReadTransaction, null, 0, 0); if (PartnerTypesDT.Rows.Count != 0) { // check if the searched for Special Type is present PartnerTypesFoundRows = PartnerTypesDT.Select( PPartnerTypeTable.GetTypeCodeDBName() + " = '" + AWorkWithSpecialType + "'"); if ((PartnerTypesFoundRows != null) && (PartnerTypesFoundRows.Length > 0)) { TypeCodePresent = true; } else { TypeCodePresent = false; } } else { TypeCodePresent = false; } } NewRow = PartnerTypeFamilyMembersDT.NewRowTyped(false); NewRow.PartnerKey = FamilyPersonsDT[Counter].PartnerKey; NewRow.PartnerShortName = Calculations.DeterminePartnerShortName(TSaveConvert.StringColumnToString(FamilyPersonsDT.ColumnFamilyName, FamilyPersonsDT[Counter]), TSaveConvert.StringColumnToString(FamilyPersonsDT.ColumnTitle, FamilyPersonsDT[Counter]), TSaveConvert.StringColumnToString(FamilyPersonsDT.ColumnFirstName, FamilyPersonsDT[Counter]), TSaveConvert.StringColumnToString(FamilyPersonsDT.ColumnMiddleName1, FamilyPersonsDT[Counter])); NewRow.FamilyId = FamilyPersonsDT[Counter].FamilyId; if (AWorkWithSpecialType != "") { NewRow.TypeCodePresent = TypeCodePresent; NewRow.TypeCodeModify = false; // TODO 2 oChristianK cSpecial Types / Family Members : Add all other Special Types of each Person NewRow.OtherTypeCodes = "#NOT YET RETRIEVED FROM DB!#"; } NewRow.Gender = FamilyPersonsDT[Counter].Gender; try { NewRow.DateOfBirth = FamilyPersonsDT[Counter].DateOfBirth; } catch (System.Data.StrongTypingException) { NewRow.DateOfBirth = System.DateTime.MinValue; } PartnerTypeFamilyMembersDT.Rows.Add(NewRow); } } } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(7, "TPartnerEditUIConnector.GetFamilyMembersInternal: committed own transaction."); } } return PartnerTypeFamilyMembersDT; }
/// <summary> /// returns the selected Family ID /// </summary> /// <returns>void</returns> public Int32 GetFamilyID() { return(Convert.ToInt32(((DataRowView)FDataGrid.SelectedDataRows[0]).Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()])); }
/// <summary> /// todoComment /// </summary> /// <returns></returns> public Int64 GetPartnerKeySelected() { return(Convert.ToInt64(((DataRowView)FDataGrid.SelectedDataRows[0]).Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()])); }
/// <summary> /// This procedure initializes this System.Object. /// /// </summary> /// <returns>void</returns> public void InitialisePartnerTypeFamilyMembers(PartnerEditTDSFamilyMembersTable AFamilyMembersDT) { // Create the result table if (FFamilyMembersResultDT == null) { FFamilyMembersResultDT = new PartnerEditTDSPartnerTypeChangeFamilyMembersPromotionTable(); } // Logger := new Ict.Common.Logging.TLogging('U:\delphi.net\ICT\Petra\Client\_bin\Debug\Propagation.log'); // Set the column names for the FFamilyMembersResultDT table. this.FResultPartnerKeyName = PartnerEditTDSPartnerTypeChangeFamilyMembersPromotionTable.GetPartnerKeyDBName(); this.FResultTypeCodeName = PartnerEditTDSPartnerTypeChangeFamilyMembersPromotionTable.GetTypeCodeDBName(); this.FResultAddTypeCodeName = PartnerEditTDSPartnerTypeChangeFamilyMembersPromotionTable.GetAddTypeCodeDBName(); this.FResultRemoveTypeCodeName = PartnerEditTDSPartnerTypeChangeFamilyMembersPromotionTable.GetRemoveTypeCodeDBName(); // Set the column names for the FFamilyMembersDT table. this.FFamilyMembersDT = AFamilyMembersDT; this.FTypeCodeModifyName = PartnerEditTDSFamilyMembersTable.GetTypeCodeModifyDBName(); this.FTypeCodePresentName = PartnerEditTDSFamilyMembersTable.GetTypeCodePresentDBName(); this.FPartnerKeyName = PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName(); }