Telerik Scheduler - drag and drop - telerik-scheduler

I use Telerik demo scheduler as my base, as it seen in http://www.telerik.com/community/forums/wpf/scheduler/uniqueid-property-how-to-access-it.aspx
So i have implemented data loading from SQL to this scheduler. Now I want to implement drag and drop. So, how can I get my appointment values in old place and values in new place on scheduler and what the best technique to do that? I would use these values, to implement update of appointment dates in SQL.

private void OnAppointmentEdited(object sender, AppointmentEditedEventArgs e)
{
Appointment eAppo = e.Appointment as Appointment;
SessionAppointment ses = e.Appointment as SessionAppointment;
if(eAppo != null && ses != null)
{
DateTime dateStart = eAppo.Start; //new datestart
DateTime dateEnd = eAppo.End;//new dateend
string id = ses.UniqueId;//id
}
}

Related

How to set cell value using rowupdating event before query execution C#?

I am using table adapter in my WinForms application to load data from database to gridview. Things work fine except I need to set one field value to be updated too in the database.
Here is my code:
//Fill dataset from database:
attendanceTypeTableAdapter.Fill(dsDataset.attendanceType);
//add rowUpdating event
attendanceTableAdapter.Adapter.RowUpdating += new OleDbRowUpdatingEventHandler(tableAdapter_RowUpdating);
Set modifiedBy field before query executed against database
private void tableAdapter_RowUpdating(object sender, OleDbRowUpdatingEventArgs e)
{
if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Update)
{
//set modifiedBy field to current userId
e.Row["modifiedBy"] = globals.userId;
e.Row.AcceptChanges();
}
}
'modifiedBy' field using above code appears in the gridview but unfortunately does not get updated in the database!
What am I missing here?

Telerik OpenAccess - Search With Non-Persistent Property

I'm using Telerik OpenAccess and SQL Server on a project and I need to be able to search by what someone's age will be on a certain date. The problem that I am running into is that the person's date of birth is stored in one table and the date to compare to is in another table, which prevents me from using a computed column. They are, however, joined together so that I can calculate the age by creating my own non-persistent property in the partial class like so:
public partial class Student
{
[Telerik.OpenAccess.Transient]
private int? _ageUponArrival;
public virtual int? AgeUponArrival
{
get
{
try
{
var dob = DateTime.Parse(this.StudentProfiles.First().Person.YearOfBirth);
var programStart = (DateTime)(this.StudentPrograms.First().ProgramStart);
this._ageUponArrival = programStart.Year - dob.Year;
if (dob > programStart.AddYears(-(int)(this._ageUponArrival)))
{
(this._ageUponArrival)--;
}
}
catch (Exception e)
{
this._ageUponArrival = null;
}
return _ageUponArrival;
}
set { }
}
}
Please ignore how bad the tables are set up, it's something that I inherited and can't change at this point. The problem with this approach is that the property is not available to search on with Linq. I know that I could create a view that would do this for me, but I would much rather not have to maintain a view just for this. Is there any way at all to create a calculated property through Telerik that would be calculated on the db server in such a way as to be searchable?
It appears that this is not possible at this point. http://www.telerik.com/community/forums/orm/linq-questions/dynamic-query-with-extended-field.aspx

Custom column in LinqServerModeDataSource

I have table in my database names User with fields:
Id
FirstName
LastName
LoginName
Now I would like to present this table in ASPxGridView using LinqServerModeDataSource.
What I did is :
<dxdtlnq:LinqServerModeDataSource ID="LinqServerModeDataSource1" runat="server" OnSelecting="LinqServerModeDataSource1_OnSelecting"
ContextTypeName="MyContext" EnableDelete="True"
EnableInsert="True" EnableUpdate="True" TableName="Users" >
</dxdtlnq:LinqServerModeDataSource>
protected void LinqServerModeDataSource1_OnSelecting(object sender, LinqServerModeDataSourceSelectEventArgs e)
{
MyContext context = new MyContext();
var qry = from s in context.Users select s;
e.QueryableSource = qry;
}
That works great with my ASPxGridView. I can display data, insert and delete but now I would like to have additional column UserName which is FirstName + LastName.
So I did something like that:
Added appropriate column to my ASPxGridView (FieldName = "UserName")
and modified OnSelecting handler:
protected void LinqServerModeDataSource1_OnSelecting(object sender, LinqServerModeDataSourceSelectEventArgs e) {
KozuModelDataContext context = new MyContext();
var qry = (from s in context.Substitutions
select new
{
Id = s.Id,
FirstName = s.FirstName,
LastName = s.LastName,
LoginName = s.LoginName,
UserName = s.FirstName + " " + s.LastName,
}).AsQueryable();
e.KeyExpression = "Id";
e.QueryableSource = qry;
}
Now data in the grid is displayed buyt when I want to insert or edit data fields cannot be filled, textboxes doesnt respond in inserting form I cant type in any text.
Is there any solution for inserting and editing data in this manner ?
Thanks for help
I have tried to reproduce this issue and see this behavior. To be able to edit data using this approach, I suggest that you do the following:
1) Handle the ASPxGridView.CellEditorIntitialize event and set the e.Editor.ReadOnly property to false. This will allow the end-user to modify data in the EditForm editors;
2) Handle the ASPxGridView.RowUpdating (RowInserting) event and update data manually. Also, you should set the e.Cancel parameter to true (to prevent the grid from updating data itself) and also call the GridView's CancelEdit method to close the EditForm.
I should also mention that there is no need to fetch data for the UserName from the DB. This can be done using the ASPxGridView's CustomColumnDisplayText event handler:
protected void ASPxGridView1_CustomColumnDisplayText(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDisplayTextEventArgs e) {
if(e.Column.FieldName == "") {
object[] values = ASPxGridView1.GetRowValues(e.VisibleRowIndex, new string[] { "FirstName", "LastName" }) as object[];
e.DisplayText = values[0].ToString() + " " + values[1].ToString();
}
}
If this approach works for you, you can avoid using the Selecting event and thus set the LinqServerModeDataSource's TableName. This will allow you to provide the data editing feature not using the approach I explained above.

What's problem on linq databinding

<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False"
KeyFieldName="CategoryID">
<SettingsEditing Mode="Inline" />
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0">
<EditButton Visible="True"></EditButton>
<NewButton Visible="True"></NewButton>
<DeleteButton Visible="True"></DeleteButton>
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn Caption="CategoryID" FieldName="CategoryID"
VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="CategoryName" FieldName="CategoryName"
VisibleIndex="2">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Description" FieldName="Description"
VisibleIndex="3">
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
C# syntax:
NorthwindDataContext db = new NorthwindDataContext();
var lresult = (db.Categories
.Select(p => new { p.CategoryID, p.CategoryName, p.Description}));
ASPxGridView1.DataSource = lresult;
ASPxGridView1.DataBind();
If you run the code, you get a gridview which is filled by NorthWind Categories table. If you click on command button of grid whose are on left side, you get insert/update field, but you have not access to give input. They are gone to read only mode.
If I replace the above C# syntax with below
NorthwindDataContext db = new NorthwindDataContext();
var lresult = (db.Categories);
ASPxGridView1.DataSource = lresult;
ASPxGridView1.DataBind();
then it works fine. Now you can work with command button with out facing any problem.
I want to know what the problem is, why the first syntax does not work. Maybe you say
Anonymous types are class types that consist of one or more public read-only properties. But when you need to join more than one table and need to select several fields not all than what you do. Hope you not say linq is fail to do that or Don't think it is possible. Hope there must be any technique or else something to bind control with Anonymous type. Plz show some syntax .
The problem is that the result set is collection of Anonymous type as you supposed and the grid doesn't know how to treat it. What you have to do is to use RowInserting and RowUpdating events of the grid.
Here is an example of how I use DevExpress grid with NHibernate:
protected void gridAgentGroups_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
{
ASPxGridView currentGrid = sender as ASPxGridView;
var currentAgentGroup = new AgentGroup();
if (e.NewValues.Contains("Name"))
{
var newValue = (string)e.NewValues["Name"];
currentAgentGroup.Name = newValue;
}
if (e.NewValues.Contains("PhysicalAddress"))
{
var newValue = (string)e.NewValues["PhysicalAddress"];
currentAgentGroup.PhysicalAddress = newValue;
}
AgentGroupsDataAccess.SaveAgentGroup(currentAgentGroup);
e.Cancel = true;
currentGrid.CancelEdit();
currentGrid.DataBind();
}
protected void gridAgentGroups_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
ASPxGridView currentGrid = sender as ASPxGridView;
int currentAgentGroupId = (int)((AgentGroup)currentGrid.GetRow(currentGrid.EditingRowVisibleIndex)).Id;
var currentAgentGroup = AgentGroups.Where(ag => ag.Id == currentAgentGroupId).FirstOrDefault();
if (e.NewValues.Contains("Name"))
{
var newValue = (string)e.NewValues["Name"];
currentAgentGroup.Name = newValue;
}
if (e.NewValues.Contains("PhysicalAddress"))
{
var newValue = (string)e.NewValues["PhysicalAddress"];
currentAgentGroup.PhysicalAddress = newValue;
}
AgentGroupsDataAccess.SaveAgentGroup(currentAgentGroup);
e.Cancel = true;
currentGrid.CancelEdit();
currentGrid.DataBind();
}
I hope this will help.
Just a wild guess - you're binding your data to the grid using field names - yet, your anonymous type doesn't really have any field names.
Does it make any difference if you try this code:
NorthwindDataContext db = new NorthwindDataContext();
var lresult = (db.Categories
.Select(p => new { CategoryID = p.CategoryID,
CategoryName = p.CategoryName,
Description = p.Description}));
ASPxGridView1.DataSource = lresult;
ASPxGridView1.DataBind();
Again - I don't have the means to test this right now, it's just a gut feeling..... try it - does that help at all??
You actually can bind with anonymous type as you see the already filled rows. But: the grid itself cannot know how you build the query and what to add additionally to the visible columns (if there are valid default values).
As you use Developer Express' grid you have the option to provide your own update / edit form and handle everything needed on your own.

Using DataObjectTypeName in DataObjectSource

The functionality I am trying to use is:
- Create a ObjectDataSource for selection and updating controls on a web page (User Control).
- Use the DataObjectTypeName to have an object created that would send the data to an UpdateMethod.
- Before the values are populated in the DataObjectTypeName’s object, I would like to pre-populate the object so the unused items in the class are not defaulted to zeros and empty strings without me knowing whether the zero or default string was set by the user or by the application.
I cannot find a way to pre-populate the values (this was an issue back in 2006 with framework 2.0). One might ask “Why would anyone need to pre-populate the object?”. The simple answer is: I want to be able to randomly place controls on different User Controls and not have to be concerned with which UpdateMethod needs to handle which fields of an object.
For Example, let’s say I have a class (that reflects a SQL Table) that includes the fields: FirstName, LastName, Address, City, State, Zip. I may want to give the user the option to change the FirstName and LastName and not even see the Address, City, State, Zip (or vice-versa). I do not want to create two UpdateMethods where one handled FirstName and LastName and the other method handles the other fields. I am working with a Class of some 40+ columns from multiple tables and I may want some fields on one screen and not another and decide later to change those fields from one screen to another (which breaks my UpdateMethods without me knowing).
I hope I explained my issue well enough.
Thanks
This is hardly a solution to the problem, but it's my best stab at it.
I have a GridView with its DataSourceID set to an ObjectDataSource.
Whenever a row is updated, I want the property values in the object to be selectively updated - that is - only updated if they appear as columns in the GridView.
I've created the following extension:
public static class GridViewExtensions
{
public static void EnableLimitUpdateToGridViewColumns(this GridView gridView)
{
_gridView = gridView;
if (_gridView.DataSourceObject != null)
{
((ObjectDataSource)_gridView.DataSourceObject)
.Updating += new ObjectDataSourceMethodEventHandler(objectDataSource_Updating);
}
}
private static GridView _gridView;
private static void objectDataSource_Updating(object sender, ObjectDataSourceMethodEventArgs e)
{
var newObject = ((object)e.InputParameters[0]);
var oldObjects = ((ObjectDataSource)_gridView.DataSourceObject).Select().Cast<object>();
Type type = oldObjects.First().GetType();
object oldObject = null;
foreach (var obj in oldObjects)
{
if (type.GetProperty(_gridView.DataKeyNames.First()).GetValue(obj, null).ToString() ==
type.GetProperty(_gridView.DataKeyNames.First()).GetValue(newObject, null).ToString())
{
oldObject = obj;
break;
}
}
if (oldObject == null) return;
var dynamicColumns = _gridView.Columns.OfType<DynamicField>();
foreach (var property in type.GetProperties())
{
if (dynamicColumns.Where(c => c.DataField == property.Name).Count() == 0)
{
property.SetValue(newObject, property.GetValue(oldObject, null), null);
}
}
}
}
And in the Page_Init event of my page, I apply it to the GridView, like so:
protected void Page_Init()
{
GridView1.EnableLimitUpdateToGridViewColumns();
}
This is working well for me at the moment.
You could probably apply similar logic to other controls, e.g. ListView or DetailsView.
I'm currently scratching my head to think of a way this can be done in a rendering-agnostic manner - i.e. without having to know about the rendering control being used.
I hope this ends up as a normal feature of the GridView or ObjectDataSource control rather than having to hack it.

Resources