private void SwitchIndices(DomainObject1 currentObject, DomainObject1 targetObject) { int oldIndex = currentObject.Index; currentObject.Index = targetObject.Index; targetObject.Index = oldIndex; ObjectSpace.CommitChanges(); }
private void CreateDomainObject1(String name, int value1, int value2, int value3) { DomainObject1 obj = ObjectSpace.CreateObject <DomainObject1>(); obj.Name = name; obj.Value1 = value1; obj.Value2 = value2; obj.Value3 = value3; }
public override void UpdateDatabaseAfterUpdateSchema() { base.UpdateDatabaseAfterUpdateSchema(); if (ObjectSpace.FindObject <DomainObject1>(null) == null) { DateTime dt = DateTime.Today.AddDays(-10); for (int i = 1; i < 30; i++) { DomainObject1 obj = ObjectSpace.CreateObject <DomainObject1>(); obj.Name = string.Format("sample{0:d3}", i); obj.Date = dt.AddDays(i); } } }
public void Run() { SecuritySystemRole adminRole = ObjectSpace.FindObject <SecuritySystemRole>( new BinaryOperator("Name", SecurityStrategy.AdministratorRoleName)); if (adminRole == null) { adminRole = ObjectSpace.CreateObject <SecuritySystemRole>(); adminRole.Name = SecurityStrategy.AdministratorRoleName; adminRole.IsAdministrative = true; adminRole.Save(); } SecuritySystemUser adminUser = ObjectSpace.FindObject <SecuritySystemUser>( new BinaryOperator("UserName", "admin")); if (adminUser == null) { adminUser = ObjectSpace.CreateObject <SecuritySystemUser>(); adminUser.UserName = "******"; adminUser.SetPassword(""); adminUser.Roles.Add(adminRole); } string name = "Bob"; DomainObject1 theObject = ObjectSpace.FindObject <DomainObject1>(CriteriaOperator.Parse("Name=?", name)); if (theObject == null) { theObject = ObjectSpace.CreateObject <DomainObject1>(); theObject.Name = name; theObject.Amount = 1000; theObject.Category1 = "Payments"; theObject.Category2 = "Other Payments"; theObject.TranDate = new DateTime(2014, 5, 6); } name = "Alice"; theObject = ObjectSpace.FindObject <DomainObject1>(CriteriaOperator.Parse("Name=?", name)); if (theObject == null) { theObject = ObjectSpace.CreateObject <DomainObject1>(); theObject.Name = name; theObject.Amount = 1000; theObject.Category1 = "Receipts"; theObject.Category2 = "Other Receipts"; theObject.TranDate = new DateTime(2014, 5, 5); } }
void ObjectSpace_Committing(object sender, CancelEventArgs e) { if (View.CurrentObject != null) { DomainObject1 obj = View.CurrentObject as DomainObject1; if (obj.File != null) { try { string filePath = HttpContext.Current.Request.MapPath("~/FileData/" + obj.File.FileName); Stream stream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write); obj.File.SaveToStream(stream); obj.ImageUrl = "~/FileData/" + obj.File.FileName; e.Cancel = true; } catch (SecurityException s) { Console.WriteLine(s.Message); } //FileIOPermission f2 = new FileIOPermission(FileIOPermissionAccess.Read, HttpContext.Current.Request.MapPath("~/FileData/")); //f2.AddPathList(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, HttpContext.Current.Request.MapPath("~/FileData/" + obj.File.FileName)); //try //{ // string filePath = HttpContext.Current.Request.MapPath("~/FileData/" + obj.File.FileName); // Stream stream = new FileStream(HttpContext.Current.Request.MapPath("~/FileData/" + obj.File.FileName), FileMode.CreateNew, FileAccess.Write); // obj.File.SaveToStream(stream); // e.Cancel = true; // obj.ImageUrl = "~/FileData/" + obj.File.FileName; // f2.Demand(); //} //catch (SecurityException s) //{ // Console.WriteLine(s.Message); //} } } }
protected void Grid_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) { string[] parameters = e.Parameters.Split(';'); int index = int.Parse(parameters[0]); string fieldname = parameters[1]; bool isGroupRowSelected = bool.Parse(parameters[2]); ReadOnlyCollection <GridViewDataColumn> groupedCols = Grid.GetGroupedColumns(); if (groupedCols[groupedCols.Count - 1].FieldName == fieldname) { // Checked groupcolumn is the lowest level groupcolumn; // we can apply original recursive checking here Grid.ExpandRow(index, true); // Expand grouped column for consistent behaviour for (int childIndex = 0; childIndex < Grid.GetChildRowCount(index); childIndex++) { var key = (Grid.GetChildRow(index, childIndex) as DomainObject1).Oid; Grid.Selection.SetSelectionByKey(key, isGroupRowSelected); } } else { // checked row is not the lowest level groupcolumn: // we will find the Datarows that are to be checked recursively by iterating all rows // and compare the fieldvalues of the fields described by the checked groupcolumn // and all its parent groupcolumns. Rows that match these criteria are to the checked. // CAVEAT: only expanded rows can be iterated, so we will have to expand clicked row recursivly before iterating the grid // Get index of current grouped column int checkedGroupedColumnIndex = -1; foreach (GridViewDataColumn gcol in groupedCols) { if (gcol.FieldName == fieldname) { checkedGroupedColumnIndex = groupedCols.IndexOf(gcol); break; } } //Build dictionary with checked groupcolumn and its parent groupcolumn fieldname and values DomainObject1 checkedDataRow = Grid.GetRow(index) as DomainObject1; Dictionary <string, object> dictParentFieldNamesValues = new Dictionary <string, object>(); string parentFieldName; object parentKeyValue; for (int i = checkedGroupedColumnIndex; i >= 0; i--) { // find parent groupcols and parentkeyvalue GridViewDataColumn pcol = groupedCols[i]; parentFieldName = pcol.FieldName; parentKeyValue = checkedDataRow.Oid; dictParentFieldNamesValues.Add(parentFieldName, parentKeyValue); } bool isChildDataRowOfClickedGroup; Grid.ExpandRow(index, true); // Expand grouped column for consistent behaviour for (int i = 0; i <= Grid.VisibleRowCount - 1; i++) { DomainObject1 row = Grid.GetRow(i) as DomainObject1; // Check whether row does belong to checked group all the parent groups of the clicked group isChildDataRowOfClickedGroup = true; foreach (KeyValuePair <string, object> kvp in dictParentFieldNamesValues) { parentFieldName = kvp.Key; parentKeyValue = kvp.Value; if (row.Oid.Equals(parentKeyValue) == false) { isChildDataRowOfClickedGroup = false; break; //Iterated row does not belong to at least one parentgroup of the clicked groupbox; do not change selection state for this row } } if (isChildDataRowOfClickedGroup == true) { // Row meets all the criteria for belonging to the clicked group and all parents of the clicked group: // change selection state Grid.Selection.SetSelectionByKey(row.Oid, isGroupRowSelected); } } } }