/// <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> /// 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> /// 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> /// returns the selected Family ID /// </summary> /// <returns>void</returns> public Int32 GetFamilyID() { return(Convert.ToInt32(((DataRowView)FDataGrid.SelectedDataRows[0]).Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()])); }
/// <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 { } }