Create Cascade Form via MDI at runtime via looping a list - winforms

I have a list that I use a foreach loop to create forms. I am trying to get the forms to cascade. I've been trying to use the MDI container and set the parent form if it meets a condition.
I would like to know if Child MDI forms can only be created inside the parent and not via a loop.
E.g
List<string> FormNames;
FormNames.add("Cat Group");
FormNames.add("Big Cats")
FormNames.add("Medium Cats")
FormNames.add("Small Cats")
Foreach(string Name in FormNames)
{
FormA NewForm = new FormA(Name);
if(NewForm.Name == "Cat Group") <--- This sets the ParentForm if conditions are met.
{
NewForm.IsMdiContainer = true;
NewForm.Layout(MdiLayout.Cascade);
}
else
{
NewForm.IsMdiContainer = false;
NewForm.MDIParent = <-----(what do I put here? I can't put NewForm or else it would reference itself.
}
NewForm.Show();

You just need the help of another variable of your Form. Set this variable to be the reference to the NewForm when you build the MDIContainer and then use it when you create the MdiChilds
List<string> FormNames = new List<string>();
FormNames.Add("Cat Group");
FormNames.Add("Big Cats");
FormNames.Add("Medium Cats");
FormNames.Add("Small Cats");
Form parent = null;
foreach (string Name in FormNames)
{
Form NewForm = new Form();
NewForm.Name = Name;
if (NewForm.Name == "Cat Group")
{
NewForm.IsMdiContainer = true;
parent = NewForm;
parent.LayoutMdi(MdiLayout.Cascade);
}
else
{
NewForm.IsMdiContainer = false;
NewForm.MdiParent = parent;
NewForm.Show();
}
}
parent.Show();

Related

how can i show multiple indenepdent template in top level of telerik radgridview

hello:
i want add multiple template to radgridview and show templates in tabbed style ,
my templates is independent and no relation to each other,
when i add templates to masterTemplate and set datasource of my templates,
datagrid is show empty grid and templates is not visible.
some tried code :
Add Template Section:
GridViewTemplate gvt = new GridViewTemplate();
gvt.AllowDeleteRow = false;
gvt.AllowEditRow = false;
gvt.ShowTotals = true;
gvt.Caption = SubCaption[i];
radResult.MasterTemplate.Templates.Add(gvt);
radResult.Refresh();
Set Data Source Section that Indexnumber is template index:
radResult.MasterTemplate.Templates[IndexNumber].DataSource = dtl;
radResult.MasterTemplate.Templates[IndexNumber].Refresh();
radResult.Refresh();
my desired View is :
RadGridView target view
how must i do that?
thanks advance
RadGridView offers only one master level via the MasterGridViewTemplate. You can add as many child GridViewTemplates to the master level as you need. More information is available here: https://docs.telerik.com/devtools/winforms/controls/gridview/hierarchical-grid/hierarchy-of-one-to-many-relations
However, this requires a relation between the MasterTemplate and each of the child GridViewTemplates.
In order to achieve your design from the screenshot for a tabbed view in RadGridView on the parent level, I can suggest the following approaches:
Use a single RadGridView instance and set up a hierarchy with load on demand. For this purpose, it would be necessary to add a dummy row for the master level and keep it expanded. The following code snippet shows how to achieve it:
private void RadForm1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'nwindDataSet.Products' table. You can move, or remove it, as needed.
this.productsTableAdapter.Fill(this.nwindDataSet.Products);
// TODO: This line of code loads data into the 'nwindDataSet.Orders' table. You can move, or remove it, as needed.
this.ordersTableAdapter.Fill(this.nwindDataSet.Orders);
// TODO: This line of code loads data into the 'nwindDataSet.Categories' table. You can move, or remove it, as needed.
this.categoriesTableAdapter.Fill(this.nwindDataSet.Categories);
this.radGridView1.MasterTemplate.Columns.Add("MasterLevel");
this.radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.MasterTemplate.AllowAddNewRow = false;
this.radGridView1.ShowColumnHeaders = false;
this.radGridView1.ShowGroupPanel = false;
GridViewTemplate childTemplateCategories = new GridViewTemplate();
childTemplateCategories.Caption = "Categories";
foreach (DataColumn col in this.nwindDataSet.Categories.Columns)
{
childTemplateCategories.Columns.Add(col.ColumnName);
}
childTemplateCategories.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.Templates.Add(childTemplateCategories);
childTemplateCategories.HierarchyDataProvider = new GridViewEventDataProvider(childTemplateCategories);
GridViewTemplate childTemplateProducts = new GridViewTemplate();
childTemplateProducts.Caption = "Products";
foreach (DataColumn col in this.nwindDataSet.Products.Columns)
{
childTemplateProducts.Columns.Add(col.ColumnName);
}
childTemplateProducts.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.Templates.Add(childTemplateProducts);
childTemplateProducts.HierarchyDataProvider = new GridViewEventDataProvider(childTemplateProducts);
GridViewTemplate childTemplateOrders = new GridViewTemplate();
childTemplateOrders.Caption = "Orders";
foreach (DataColumn col in this.nwindDataSet.Orders.Columns)
{
childTemplateOrders.Columns.Add(col.ColumnName);
}
childTemplateOrders.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.Templates.Add(childTemplateOrders);
childTemplateOrders.HierarchyDataProvider = new GridViewEventDataProvider(childTemplateOrders);
this.radGridView1.RowSourceNeeded += new GridViewRowSourceNeededEventHandler(radGridView1_RowSourceNeeded);
this.radGridView1.Rows.Add("Master");
this.radGridView1.Rows[0].IsExpanded = true;
}
private void radGridView1_RowSourceNeeded(object sender, GridViewRowSourceNeededEventArgs e)
{
if (e.Template.Caption == "Categories")
{
foreach (DataRow row in this.nwindDataSet.Categories.Rows)
{
GridViewRowInfo r = e.Template.Rows.NewRow();
foreach (GridViewCellInfo cell in r.Cells)
{
cell.Value = row[cell.ColumnInfo.Name];
}
e.SourceCollection.Add(r);
}
}
else if (e.Template.Caption == "Products")
{
foreach (DataRow row in this.nwindDataSet.Products.Rows)
{
GridViewRowInfo r = e.Template.Rows.NewRow();
foreach (GridViewCellInfo cell in r.Cells)
{
cell.Value = row[cell.ColumnInfo.Name];
}
e.SourceCollection.Add(r);
}
}
else if (e.Template.Caption == "Orders")
{
foreach (DataRow row in this.nwindDataSet.Orders.Rows)
{
GridViewRowInfo r = e.Template.Rows.NewRow();
foreach (GridViewCellInfo cell in r.Cells)
{
cell.Value = row[cell.ColumnInfo.Name];
}
e.SourceCollection.Add(r);
}
}
}
Use a RadDock or a RadPageView and add as many tabbed documents/pages as you need. Then, on each tab/page add a separate RadGridView control and populate it with the relevant data.
Feel free to use this approach which suits your requirements best.

AS3 Separating Arrays for different items

I have a function that creates a new value inside an associative array.
var array:Array = new Array(new Array());
var i : int = 0;
function personVelgLand(evt:MouseEvent)
{
for(i = 0; i < personListe.dataProvider.length; i++)
{
if(txtPersonVelg.text == personListe.dataProvider.getItemAt(i).label)
{
personListe.dataProvider.getItemAt(i).reise = array;
personListe.dataProvider.getItemAt(i).reise.push(landListe.selectedItem.land);
}
}
}
What happens is that the 'array' array which becomes 'personListe.dataProvider.getItemAt(i).reise' applies to every item in the list. I want it so that each time the function runs that the .reise only applies to the item chosen and not all of them.
EDIT:
I did this:
personListe.dataProvider.getItemAt(i).reise = new Array(array);
And now they are not the same but now each item in the list can not have multiple .reise values...
EDIT 2: dataProvider is nothing it would work just as fine without it. .reise is created in the function I originally posted it creates .reise in the object getItemAt(i).
personListe is a list which the users add their own items to by the use of a input textfield. It is given by this function:
function regPerson(evt:MouseEvent)
{
regPersoner.push(txtRegPerson.text);
personListe.addItem({label:regPersoner});
regPersoner = new Array();
txtRegPerson.text = "";
}
EDIT 3 : The user can register names which turn in to labels in a list. There is also list with 3 countries, Spain, Portugal and England. The user can then register a country to a person they select. Thats when I want to create the .reise inside the "name" items in the first list which contains the countries they have selected. I want every name to be able to select multiple countries which then will be created in the element .reise inside the item that holds their name. This would be easy if I could use strings. But later I plan to have the user type in a country and then something that would show every user that have selected that country. That is why the countries need to be stored as arrays inside the "name" items..
You should first create a class for the User data that you are modelling. You already know all the properties.
The user can register names
The user can then register a country to a person they select.
able to select multiple countries
Such a class could look like this:
package
{
public class User
{
private var _name:String;
private var _countries:Array;
public function User(name:String)
{
_name = name;
_countries = [];
}
public function get name():String
{
return _name;
}
public function get countries():Array
{
return _countries;
}
public function set countries(value:Array):void
{
_countries = value;
}
}
}
Now create a DataProvider, fill it with objects of that class and use it for the list as described here:
import fl.controls.List;
import fl.data.DataProvider;
var users:List = new List();
users.dataProvider = new DataProvider([
new User("David"),
new User("Colleen"),
new User("Sharon"),
new User("Ronnie"),
new User("James")]);
addChild(users);
users.move(150, 150);
In order to get a label from a User object, define a labelFunction
import fl.controls.List;
import fl.data.DataProvider;
var users:List = new List();
users.labelFunction = userLabelFunction;
function userLabelFunction(item:Object):String
{
return item.name;
}
users.dataProvider = new DataProvider([
new User("David"),
new User("Colleen"),
new User("Sharon"),
new User("Ronnie"),
new User("James")]);
addChild(users);
users.move(150,150);
This way you do not have to add a label property that you don't want in your class.
Selecting a name means selecting a user. The list of countries associated to the name should show up in a second List.
The DataProvider of that List remains constant, a list of all the available countries.
import fl.controls.List;
import fl.data.DataProvider;
// list of users
var users:List = new List();
addChild(users);
users.move(150,150);
users.labelFunction = userLabelFunction;
function userLabelFunction(item:Object):String
{
return item.name;
}
users.dataProvider = new DataProvider([
new User("David"),
new User("Colleen"),
new User("Sharon"),
new User("Ronnie"),
new User("James")]);
// lsit of countries
var countries:List = new List();
addChild(countries);
countries.move(550,150); // adjut position as desired
countries.dataProvider = new DataProvider([
{label:"a"},
{label:"b"},
{label:"c"},
{label:"d"},
{label:"e"},
{label:"f"}]);
Now all you have to do is to wire it all up. If a user is selected, select his countries in the countries list. If a country is selected, add that to the currently selected users list of countries. That could look somethign like this:
users.addEventLsitener(Event.CHANGE, onUserSelected);
function onUserSelected(e:Event):void
{
countries.selectedItems = users.selectedItem.countries;
}
countries.addEventLsitener(Event.CHANGE, onCountrySelected);
function onCountrySelected(e:Event):void
{
users.selectedItem.countries = countries.selectedItems;
}
The full code could look like this. I did not test this, but you get the idea.
// list of users
var users:List = new List();
addChild(users);
users.move(150,150);
users.labelFunction = userLabelFunction;
function userLabelFunction(item:Object):String
{
return item.name;
}
users.dataProvider = new DataProvider([
new User("David"),
new User("Colleen"),
new User("Sharon"),
new User("Ronnie"),
new User("James")]);
// list of countries
var countries:List = new List();
addChild(countries);
countries.move(550,150); // adjut position as desired
countries.dataProvider = new DataProvider([
{label:"a"},
{label:"b"},
{label:"c"},
{label:"d"},
{label:"e"},
{label:"f"}]);
// events
users.addEventLsitener(Event.CHANGE, onUserSelected);
function onUserSelected(e:Event):void
{
countries.selectedItems = users.selectedItem.countries;
}
countries.addEventLsitener(Event.CHANGE, onCountrySelected);
function onCountrySelected(e:Event):void
{
users.selectedItem.countries = countries.selectedItems;
}
From what I understand this seems to work except for the fact that the names are already provided when the program starts. What I want is that the user adds the name themselves while the program is running.
You can add new items with the methods provided by the DataProvider class, like addItem() for example. Just add new User objects.

Get appointments from all Outlook calendars

I'm trying to read appointments from Outlook calendar using ExchangeServiceBinding but my solution takes appointments only from "default" outlook calendar and don't read from "sub calendars/custom calendars". Do you know how to define rest of the calendars or do you know better solution which contains all calendars?
Critical part is that solution shouldn't contain MAPI because of next use in web service.
My current code:
private static List<List<string>> ReadCalendarEvents(string email)
{
List<List<string>> calendarEvents = new List<List<string>>();
// Specify the request version.
esb.RequestServerVersionValue = new RequestServerVersion();
esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2007;
// Form the FindItem request.
FindItemType findItemRequest = new FindItemType();
CalendarViewType calendarView = new CalendarViewType();
calendarView.StartDate = DateTime.Now.AddDays(-7);
calendarView.EndDate = DateTime.Now.AddDays(200);
calendarView.MaxEntriesReturned = 1000;
calendarView.MaxEntriesReturnedSpecified = true;
findItemRequest.Item = calendarView;
// Define which item properties are returned in the response.
ItemResponseShapeType itemProperties = new ItemResponseShapeType();
// Use the Default shape for the response.
//itemProperties.BaseShape = DefaultShapeNamesType.IdOnly;
itemProperties.BaseShape = DefaultShapeNamesType.AllProperties;
findItemRequest.ItemShape = itemProperties;
DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
folderIDArray[0] = new DistinguishedFolderIdType();
folderIDArray[0].Id = DistinguishedFolderIdNameType.calendar;
//
folderIDArray[0].Mailbox = new EmailAddressType();
folderIDArray[0].Mailbox.EmailAddress = email;
findItemRequest.ParentFolderIds = folderIDArray;
// Define the traversal type.
findItemRequest.Traversal = ItemQueryTraversalType.Shallow;
try
{
// Send the FindItem request and get the response.
FindItemResponseType findItemResponse = esb.FindItem(findItemRequest);
// Access the response message.
ArrayOfResponseMessagesType responseMessages = findItemResponse.ResponseMessages;
ResponseMessageType[] rmta = responseMessages.Items;
int folderNumber = 0;
foreach (ResponseMessageType rmt in rmta)
{
// One FindItemResponseMessageType per folder searched.
FindItemResponseMessageType firmt = rmt as FindItemResponseMessageType;
if (firmt.RootFolder == null)
continue;
FindItemParentType fipt = firmt.RootFolder;
object obj = fipt.Item;
// FindItem contains an array of items.
if (obj is ArrayOfRealItemsType)
{
ArrayOfRealItemsType items =
(obj as ArrayOfRealItemsType);
if (items.Items == null)
{
folderNumber++;
}
else
{
foreach (ItemType it in items.Items)
{
if (it is CalendarItemType)
{
CalendarItemType cal = (CalendarItemType)it;
List<string> ce = new List<string>();
ce.Add(cal.Location);
ce.Add(cal.Start.ToShortDateString() + " " + cal.Start.ToShortTimeString());
ce.Add(cal.End.ToShortDateString() + " " + cal.End.ToShortTimeString());
ce.Add(cal.Subject);
if (cal.Organizer != null)
{
ce.Add(cal.Organizer.Item.Name);
}
calendarEvents.Add(ce);
Console.WriteLine(cal.Subject + " " + cal.Start.ToShortDateString() + " " + cal.Start.ToShortTimeString() + " " + cal.Location);
}
}
folderNumber++;
}
}
}
}
catch (Exception e)
{
throw;
}
finally
{
}
return calendarEvents;
}
In EWS you need to query one folder at a time, for non default folders you will first need to find the FolderId before you can then query the appointments (or items) within a Folder. To find all the Calendar folders in a Mailbox you need to use the FindFolder operation and create a restriction to limit the result to folder with a FolderClass of IPF.Appointment eg
// Create the request and specify the travesal type.
FindFolderType findFolderRequest = new FindFolderType();
findFolderRequest.Traversal = FolderQueryTraversalType.Deep;
// Define the properties that are returned in the response.
FolderResponseShapeType responseShape = new FolderResponseShapeType();
responseShape.BaseShape = DefaultShapeNamesType.Default;
findFolderRequest.FolderShape = responseShape;
// Identify which folders to search.
DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
folderIDArray[0] = new DistinguishedFolderIdType();
folderIDArray[0].Id = DistinguishedFolderIdNameType.msgfolderroot;
IsEqualToType iet = new IsEqualToType();
PathToUnindexedFieldType FolderClass = new PathToUnindexedFieldType();
FolderClass.FieldURI = UnindexedFieldURIType.folderFolderClass;
iet.Item = FolderClass;
FieldURIOrConstantType constantType = new FieldURIOrConstantType();
ConstantValueType constantValueType = new ConstantValueType();
constantValueType.Value = "IPF.Appointment";
constantType.Item = constantValueType;
iet.FieldURIOrConstant = constantType;
// Add the folders to search to the request.
RestrictionType restriction = new RestrictionType();
restriction.Item = iet;
findFolderRequest.Restriction = restriction;
findFolderRequest.ParentFolderIds = folderIDArray;
try
{
// Send the request and get the response.
FindFolderResponseType findFolderResponse = esb.FindFolder(findFolderRequest);
// Get the response messages.
ResponseMessageType[] rmta = findFolderResponse.ResponseMessages.Items;
foreach (ResponseMessageType rmt in rmta)
{
// Cast to the correct response message type.
if (((FindFolderResponseMessageType)rmt).ResponseClass == ResponseClassType.Success) {
foreach (FolderType folder in ((FindFolderResponseMessageType)rmt).RootFolder.Folders) {
Console.WriteLine(folder.DisplayName);
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
You also might want to look at using the EWS Managed API which will save you greatly time and the amount of code you need to write
Cheers
Glen

cakephp: creating new records from other controller

I'm going to create 50 temp/dummy rows inside my model database. My problems is how can I create and save new records in my DB? Assume my model Random containts columns (id,randomValue,...).
public function addNew() {
$this->autoRender = false; // We don't render a view in this example
$moduleSize = 50;
$count = $moduleSize;
while ($count > 0) {
$random_number = rand(1000000000, 9999999999);
//check if duplicate
if ($this->checkIfDuplicateSerial($random_number)) {
//nothing to be done
} else {
$this->Random->create(array('randomValue' => $random_number));
$this->Random->save();
$this->Random->clear(); //to init new one
$count--;
}
}
$this->response->body('Inserted' . $moduleSize . 'Random Numbers');
}

context.SaveChanges() not persisting data in database

Im working on a MVC app.
When I call context.SaveChanges to update a specific records. The update is not registered in the database. I do not get any runtime error either. All in notice is that my Records is not updated. I still see the same values. Insert Functionality work Perfectly.
enter code here
public Admission Update(int stuid){
VDData.VidyaDaanEntities context = new VDData.VidyaDaanEntities();
VDData.Student_Master studentmaster = new VDData.Student_Master();
studentmaster.Student_ID = stuid;
studentmaster.Student_First_Name = this.FirstName;
studentmaster.Student_Middle_Name = this.MiddleName;
studentmaster.Student_Last_Name = this.LastName;
studentmaster.Student_Address_1 = this.Address;
studentmaster.Student_Address_2 = this.Address2;
studentmaster.Student_City = this.City;
studentmaster.Student_State = this.State;
studentmaster.Student_Pin_Code = this.Pincode;
context.SaveChanges(); // here it wont give any kind of error. it runs sucessfully. }
First get the entity you are going to update:
var entity = obj.GetEntity(id);
entity.col1 = "value";
context.SaveChanges(entity);
hope this will help.
It seems like you want to update, so your code should be
VDData.Student_Master studentmaster = context.Student_Masters.Single(p=>p.Student_ID == stuid);
And you should not change the Student_ID if it is the primary key.
public Admission Update(int stuid){
VDData.VidyaDaanEntities context = new VDData.VidyaDaanEntities();
//VDData.Student_Master studentmaster = new VDData.Student_Master();
//REPLACE WITH
VDData.Student_Master studentmaster = context.Student_Masters.Where(p=>p.Student_ID == stuid);
studentmaster.Student_ID = stuid;
studentmaster.Student_First_Name = this.FirstName;
studentmaster.Student_Middle_Name = this.MiddleName;
studentmaster.Student_Last_Name = this.LastName;
studentmaster.Student_Address_1 = this.Address;
studentmaster.Student_Address_2 = this.Address2;
studentmaster.Student_City = this.City;
studentmaster.Student_State = this.State;
studentmaster.Student_Pin_Code = this.Pincode;
context.SaveChanges();
Before
context.SaveChanges();
You need to call this
context.Student_Masters.Add(studentmaster );
Edit: introduce Abstraction to your Context class and Create a method in your context class like below, then you can call it whenever you want to create or update your objects.
public void SaveStudent_Master(Student_Master studentmaster)
{
using (var context = new VDData.VidyaDaanEntities())
{
if (studentmaster.Student_ID == 0)
{
context.Student_Masters.Add(studentmaster);
}
else if (studentmaster.Student_ID > 0)
{
//This Updates N-Level deep Object grapgh
//This is important for Updates
var currentStudent_Master = context.Student_Masters
.Single(s => s.Student_ID == studentmaster.Student_ID );
context.Entry(currentStudent_Master ).CurrentValues.SetValues(studentmaster);
}
context.SaveChanges();
}
Then in your Controller replace context.SaveChanges(); with _context.SaveStudent_Master(studentmaster);

Resources