/// <summary> /// Creates the controls for displaying the field /// </summary> protected override void CreateValueControl() { base.CreateValueControl(); ValueControl.ValueChanged += ValueControl_ValueChanged; PrimaryKeys.Clear(); using (DataBase db = DataBase.CreateDataBase()) { Operations.Select select = new Operations.Select(); select.DataType = DataType; var primaryKey = DataType.PrimaryKey.ToArray(); foreach (object instance in db.Select(select)) { //add item as a string ValueControl.Items.Add(instance.ToString()); //single column primary key? add as a single object if (primaryKey.Length == 1) { PrimaryKeys.Add(primaryKey.Single().Member.GetValue(instance)); } //multiple column primary key? add as an array of objects else { //add primary key IComparable[] pkValues = new IComparable[primaryKey.Length]; for (int i = 0; i < primaryKey.Length; i++) { pkValues[i] = (IComparable) primaryKey[i].Member.GetValue(instance); } PrimaryKeys.Add(pkValues); } } } }
/// <summary> /// Creates the controls for displaying the field /// </summary> protected override void CreateValueControl() { base.CreateValueControl(); ValueControl.ValueChanged += ValueControl_ValueChanged; PrimaryKeys.Clear(); using (DataBase db = DataBase.CreateDataBase()) { Operations.Select select = new Operations.Select(); select.DataType = DataType; var primaryKey = DataType.PrimaryKey.ToArray(); foreach (object instance in db.Select(select)) { //add item as a string ValueControl.Items.Add(instance.ToString()); //single column primary key? add as a single object if (primaryKey.Length == 1) { PrimaryKeys.Add(primaryKey.Single().Member.GetValue(instance)); } //multiple column primary key? add as an array of objects else { //add primary key IComparable[] pkValues = new IComparable[primaryKey.Length]; for (int i = 0; i < primaryKey.Length; i++) { pkValues[i] = (IComparable)primaryKey[i].Member.GetValue(instance); } PrimaryKeys.Add(pkValues); } } } }
/// <summary> /// Starts instance for confirmation to remove controls. /// </summary> /// <summary xml:lang="es"> /// Inicia la instancia para los controles de confirmacion de aliminar. /// </summary> public override void Start() { base.Start(); //add label with instance names, select from database ILabel lblInstanceNames = Platform.Current.Create<ILabel>(); lblInstanceNames.Text = string.Empty; Operations.Select select = new Operations.Select(); select.DataType = Delete.DataType; select.Where.AddRange(Delete.Where); int count = 0; using (var db = DataBase.CreateDataBase()) { foreach(object instance in db.Select(select)) { lblInstanceNames.Text += instance.ToString() + "\n"; count++; } } lblInstanceNames.Text = count + " records will be deleted:\n\n" + lblInstanceNames.Text; //add confirmation checkbox lblConfirm = Platform.Current.Create<ILabel>(); lblConfirm.Text = Resources.Strings.OKHOSTING_ORM_UI_DeleteController_Confirm; chkConfirm = Platform.Current.Create<ICheckBox>(); //add delete button IButton delete = Platform.Current.Create<IButton>(); delete.Text = Resources.Strings.OKHOSTING_ORM_UI_DeleteController_Delete; delete.Click += Delete_Click; //add Cancel button IButton cancel = Platform.Current.Create<IButton>(); cancel.Text = Resources.Strings.OKHOSTING_ORM_UI_UpdateController_Cancel; cancel.Click += Cancel_Click; //add label for error messages lblMessages = Platform.Current.Create<ILabel>(); lblMessages.Visible = false; //create our own grid IGrid grid = Platform.Current.Create<IGrid>(); grid.ColumnCount = 2; grid.RowCount = 4; grid.SetContent(0, 0, lblInstanceNames); grid.SetColumnSpan(2, lblInstanceNames); grid.SetContent(1, 0, lblConfirm); grid.SetContent(1, 1, chkConfirm); grid.SetContent(2, 0, delete); grid.SetContent(2, 1, cancel); grid.SetContent(3, 0, lblMessages); grid.SetColumnSpan(2, lblMessages); Platform.Current.Page.Title = Resources.Strings.OKHOSTING_ORM_UI_DeleteController_Delete + ' ' + Translator.Translate(Delete.DataType.InnerType); Platform.Current.Page.Content = grid; }
/// <summary> /// Creates a field that will contain a value of a specific type /// <para xml:lang="es"> /// Crea un campo que contendra un valor de un tipo especifco /// </para> /// </summary> public static FormField CreateFieldFrom(Type type) { //validate arguments if (type == null) throw new ArgumentNullException("type"); //field FormField field; //The type is a persistent type if (DataType.IsMapped(type)) { var select = new Operations.Select(); select.DataType = type; field = new ObjectListPickerField(select); ////show total records //Operations.SelectAggregate count = new Operations.SelectAggregate(); //count.DataType = type; //count.AggregateMembers.Add(new Operations.SelectAggregateMember(select.DataType.PrimaryKey.First(), Operations.SelectAggregateFunction.Count)); //int totalRecords = 0; //using (var db = DataBase.CreateDataBase()) //{ // totalRecords = Data.Convert.ChangeType<int>(db.SelectScalar(count)); //} ////if it's a short list, create a DropDown //if (totalRecords <= 100) //{ // field = new ObjectListPickerField(select); //} ////otherwise create an autocomplete //else //{ // field = new ObjectAutoCompleteField(select); //} } //DataType else if (type.Equals(typeof(DataType))) { field = new DataTypeField(); } //just create a simple field for common values else { field = FormField.CreateFieldFrom(type); } //return return field; }