This is a migrated thread and some comments may be shown as answers.

CRUD of SQL Server in Bussiness Object

13 Answers 183 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
shahab
Top achievements
Rank 1
shahab asked on 19 Jun 2013, 08:05 AM
Dear support team
I used  http://www.telerik.com/help/winforms/scheduler-data-binding-binding-to-business-objects.html link to impemelent appointment. 
I do not know how to load data and edit them.
I search in example but Binding Example did not answer my requirement.
Please guide me  on that!

13 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 24 Jun 2013, 10:51 AM
Hello Shahab,

Thank you for writing.

The information you have provided is not enough for me to be able to help you accurately. In order to avoid me guessing what you are trying to do and what your setup is, I would kindly ask you to send me a more detailed explanation of your setup and desired goals. This will save both me and you time which would otherwise be lost in communication back and forth. Things like, where do you store your appointments data, what is the format of the stored data, what operations you want to perform on the appointments inside RadScheduler and anything else you think might be relevant to the case.

Looking forward to your reply.

Regards,
Ivan Petrov
Telerik
RadChart for WinForms is obsolete. Now what?
0
shahab
Top achievements
Rank 1
answered on 24 Jun 2013, 07:22 PM
Dear Ivan
I need to save appointment in SQL Server Database. I red many documentation and implemented them but they did not work. I want a guide to impelement update, Insert and delete SQL-based scheduler.(I used business object to insert,update,delete and select from database)
0
Ivan Petrov
Telerik team
answered on 27 Jun 2013, 04:04 PM
Hello Shahab,

Thank you for writing back.

I still do not have enough information to help you adequately. I would kindly ask you to send me your project so I can get a clear idea as to what you are trying to achieve what your approach is and then I will be able to accurately help you address any problems you have in the whole scenario.

Looking forward to your reply.

Regards,
Ivan Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
shahab
Top achievements
Rank 1
answered on 27 Jun 2013, 04:47 PM
I need a complete example to work with SQL Server Database. I want to store appointment information in SQL server Tables. Existed example in online documentation did not work! I'd tested them.

For examples:
1. I do not know at least Id is in GUID or Int type. in some example it is in GUID type and in another it is in Int format!!!!??
2. When I used business object how should I define Insert to database?
0
Ivan Petrov
Telerik team
answered on 02 Jul 2013, 12:53 PM
Hi Shahab,

Thank you for writing back.

You can find a full working example of binding RadScheduler to Business Objects in our demo application. You should navigate to RadScheduler >> Data Binding. 

I hope this will be useful. Should you have further questions, I would be glad to help.

Regards,
Ivan Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
shahab
Top achievements
Rank 1
answered on 04 Jul 2013, 05:42 AM
Dear Ivan
As I mentioned before I check demo and forums about this. I implemented sample step by step but it did not work. In Bussiness Object demo We can not insert, update and delete from database. I do not know how can I use defined Insert, update and delete method from Bussiness Object in scheduler
0
shahab
Top achievements
Rank 1
answered on 07 Jul 2013, 06:49 AM
Dear Ivan
At least I could work by business object:

But now when I want to open CustomEdiftFormDialog as was mentioned in your samples I got this error:
"Entry point was not found."

Stack trace:
   at Telerik.WinControls.UI.IEvent.set_Start(DateTime value)<br>   at Telerik.WinControls.UI.RadScheduler.AddNewAppointmentWithDialog(DateTimeInterval interval, Boolean recurringAppointment, SchedulerResourceCollection resources)<br>   at Telerik.WinControls.UI.RadScheduler.appointmentItem_Click(Object sender, EventArgs e)<br>   at Telerik.WinControls.RadItem.DoClick(EventArgs e)<br>   at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)<br>   at Telerik.WinControls.ComponentInputBehavior.OnMouseUp(MouseEventArgs e)<br>   at Telerik.WinControls.RadControl.OnMouseUp(MouseEventArgs e)<br>   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)<br>   at System.Windows.Forms.Control.WndProc(Message& m)<br>   at Telerik.WinControls.RadControl.WndProc(Message& m)<br>   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)<br>   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)<br>   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)<br>   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)<br>   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)<br>   at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)<br>   at UserInterface.UserLogin.LoginUser() in h:\Company\DeltaSystem\Clinic\CLINIC\UserLogin.cs:line 58

I create appointment Table as attached image. I define ID(int) and UniqueID(UniqueIdentifier) because Scheduler has uniqueID columns.
I defined business class to do Insert,Update, Delete and select from Database.
my CustomEditForm is like your sample but Scheduler.cs is like this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace UserInterface.Scheduler.Patient
{
    public partial class SchedulerUI : Telerik.WinControls.UI.RadForm//, IMessageFilter
    {
        ExceptionHandlerBOL _ExceptionHandlerBOL;
        AccessMode _AccessMode;
        AppointmentBLL _AppointmentBLL = new AppointmentBLL();
        DoctorBLL _DoctorBLL = new DoctorBLL();
        CustomEditAppointmentDialog appointmentDialog = null;
 
        public SchedulerUI()
        {
            InitializeComponent();
            scheduler.AppointmentFactory = new CustomAppointmentFactory();               
        }
        public SchedulerUI(AccessMode accessMode)
        {
            InitializeComponent();
            _AccessMode = accessMode;
            scheduler.AppointmentFactory = new CustomAppointmentFactory();               
        }
        private void PatientSchedulerUI_Load(object sender, EventArgs e)
        {
            FillScheduler();
        }
        void scheduler_AppointmentEditDialogShowing(object sender, AppointmentEditDialogShowingEventArgs e)
        {
                if (this.appointmentDialog == null)
                {
                    this.appointmentDialog = new CustomEditAppointmentDialog();
                }               
                e.AppointmentEditDialog = this.appointmentDialog;            
        }
        private void FillScheduler()
        {
                RadSchedulerLocalizationProvider.CurrentProvider = new CustomSchedulerLocalizationProvider();
                SchedulerNavigatorLocalizationProvider.CurrentProvider = new CustomSchedulerNavigatorLocalizationProvider();
                var persianCulture = new PersianCulture();
                scheduler.Culture = persianCulture;
                scheduler.GetDayView().DayCount = 1;
 
                AppointmentBOL[] AppointmentRecords = _AppointmentBLL.Select();
                scheduler.Appointments.Clear();
                if (AppointmentRecords != null)
                    for (int index = 0; index < AppointmentRecords.Length; index++)
                    {
                        Appointment appointment = new Appointment(AppointmentRecords[index].Start, AppointmentRecords[index].End, AppointmentRecords[index].Subject, AppointmentRecords[index].DoctorName);
                        appointment.UniqueId = new EventId(AppointmentRecords[index].UniqueID);
                        scheduler.Appointments.Add(appointment);
                    }
 
                SchedulerBindingDataSource dataSource = new SchedulerBindingDataSource();
                dataSource.EventProvider.AppointmentFactory = scheduler.AppointmentFactory;
                AppointmentMappingInfo appointmentMappingInfo = new AppointmentMappingInfo();
                appointmentMappingInfo.Mappings.Add(new SchedulerMapping("Tel", "Tel"));
                appointmentMappingInfo.Mappings.Add(new SchedulerMapping("Mobile", "Mobile"));
                dataSource.EventProvider.Mapping = appointmentMappingInfo;
 
                BindingList<Doctor> resources = _DoctorBLL.SelectList();
                ResourceMappingInfo resourceMappingInfo = new ResourceMappingInfo();
                resourceMappingInfo.Name = "Name";
                resourceMappingInfo.Id = "Id";
                dataSource.ResourceProvider.Mapping = resourceMappingInfo;
                dataSource.ResourceProvider.DataSource = resources;
 
                SchedulerMapping backgroundIdSchedulerMapping = appointmentMappingInfo.FindBySchedulerProperty("BackgroundId");
                SchedulerMapping locationSchedulerMapping = appointmentMappingInfo.FindBySchedulerProperty("Location");
                SchedulerMapping uniqueIdSchedulerMapping = appointmentMappingInfo.FindBySchedulerProperty("UniqueId");
 
                appointmentMappingInfo.Location = "Location";
        }
        private void scheduler_AppointmentAdded(object sender, AppointmentAddedEventArgs e)
        {
                AppointmentBOL _AppointmentBOL = new AppointmentBOL((Guid)e.Appointment.UniqueId.KeyValue, e.Appointment.End, e.Appointment.Start, e.Appointment.ResourceId, string.Empty, string.Empty, string.Empty, e.Appointment.Summary, e.Appointment.Description, e.Appointment.Location, e.Appointment.RecurrenceRule, e.Appointment.MasterEvent, e.Appointment.BackgroundId);
                _AppointmentBOL.DoctorId = 5;
                _AppointmentBLL.Insert(_AppointmentBOL);
        }
        private void scheduler_AppointmentDeleted(object sender, SchedulerAppointmentEventArgs e)
        {
                AppointmentBOL _AppointmentBOL = new AppointmentBOL((Guid)e.Appointment.UniqueId.KeyValue);
                _AppointmentBLL.Delete(_AppointmentBOL);            
        }
    }
}

My CustomFactory is:
public class CustomAppointmentFactory : IAppointmentFactory
{
    #region IAppointmentFactory Members
    public IEvent CreateNewAppointment()
    {
        return new AppointmentBOL();
    }
    #endregion
}


My CustomAppointment object is:
public class AppointmentBOL : Appointment
  {
      private Guid uniqueID;
      private string tel = string.Empty;
      private string mobile = string.Empty;
      private int id;
      private short doctorId;
      private string doctorName;
      private int masterEventId;
 
      public Guid UniqueID
      {
          get
          {
              return uniqueID;
          }
          set
          {
              uniqueID = value;
          }
      }
      public int MasterEventId
      {
          get
          {
              return masterEventId;
          }
          set
          {
              masterEventId = value;
          }
      }
      public int Id
      {
          get
          {
              return id;
          }
          set
          {
              id = value;
          }
      }
      public short DoctorId
      {
          get
          {
              return doctorId;
          }
          set
          {
              doctorId = value;
          }
      }
      public string DoctorName
      {
          get
          {
              return doctorName;
          }
          set
          {
              doctorName = value;
          }
      }
      public string Mobile
      {
          get
          {
              return this.mobile;
          }
          set
          {
              if (this.mobile != value)
              {
                  this.mobile = value;
                  this.OnPropertyChanged("Mobile");
              }
          }
      }
      public string Tel
      {
          get
          {
              return this.tel;
          }
          set
          {
              if (this.tel != value)
              {
                  this.tel = value;
                  this.OnPropertyChanged("Tel");
              }
          }
      }
      public AppointmentBOL(): base()
      {
 
      }
      public AppointmentBOL(int? Id)
      {
          // this.id = Id;           
      }
      public AppointmentBOL(Guid UniqueID, DateTime End, DateTime Start, EventId ResourceId, string DoctorName, string Tel, string Mobile, string Summery, string Description, string Location, RecurrenceRule RecurrenceRule, IEvent MasterEventId, int BackgroundId)
      {
          this.UniqueID = UniqueID;
          this.End = End;
          this.Start = Start;
          this.ResourceId = ResourceId;
          this.tel = Tel;
          this.mobile = Mobile;
          this.Summary = Summery;
          this.Description = Description;
          this.Location = Location;
          this.RecurrenceRule = RecurrenceRule;
          //this.MasterEvent = MasterEventId;
          this.BackgroundId = BackgroundId;
      }
      public AppointmentBOL(Guid UniqueID, int Id, DateTime End, DateTime Start, short DoctorId, string DoctorName, string Tel, string Mobile, string Summery, string Description, string Location, string RecurrenceRule, int? MasterEventId, int BackgroundId)
      {
          this.UniqueID = UniqueID;
          this.Id = Id;
          this.End = End;
          this.Start = Start;
          this.DoctorId = DoctorId;
          this.Tel = Tel;
          this.Mobile = Mobile;
          this.Summary = Summery;
          this.Description = Description;
          this.Location = Location;
          //this.RecurrenceRule = RecurrenceRule;
          //this.MasterEvent = MasterEventId;
          this.BackgroundId = BackgroundId;
      }
      public AppointmentBOL(Guid UniqueID)
      {
          this.UniqueID = UniqueID;
      }
      protected override Event CreateOccurrenceInstance()
      {
          AppointmentBOL _AppointmentBOL = new AppointmentBOL();
          _AppointmentBOL.Mobile = this.Mobile;
          _AppointmentBOL.Tel = this.Tel;
          return _AppointmentBOL;
      }
  }



0
Ivan Petrov
Telerik team
answered on 08 Jul 2013, 01:40 PM
Hi Shahab,

Thank you for writing back.

This exception is usually thrown when there is no Main method in a project. Since this is happening when you try to load other assemblies (probably when you click the button) I would kindly ask you to check all assemblies you are referencing. You should check whether they are all the same version and that they are the appropriate version for your project's target framework. Our controls come in two versions. The first is build targeting .NET Framework 2.0 and the second is build targeting .NET Framework 4.0. You should ensure you are referencing the appropriate assemblies for your project's target framework. Also you must reference assemblies of the same .NET version. To differentiate the two versions you can check the last two digits. They are either 20 or 40 e.g. 2013.2.612.20 or 2013.2.612.40

I hope this will help. Do not hesitate to write back with further questions.

Regards,
Ivan Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
shahab
Top achievements
Rank 1
answered on 08 Jul 2013, 04:35 PM
Dear Ivan
I used vesrsion 4.0(). I inheritance AppointmentBOL from Appointment. But I got error:
Error   6   The type or namespace name 'Telerik' could not be found (are you missing a using directive or an assembly reference?)   D:\Company\Delta System\TFS\Windows\Clinic\BusinessObjectLayer\Scheduler\Patient\AppointmentBOL.cs  2   7   BusinessObjectLayer
But when i changed it to 2.0. it is ok!
It is very bad there is no complete sample to work with business object. your sample just select appointment.
0
shahab
Top achievements
Rank 1
answered on 09 Jul 2013, 05:25 AM
Dear Ivan
Finally I can do it! I replace all dll with  version 2.0.
Please guide me when customeditappointmentdialog is opened how can I find it is in edit mode or insert mode?
I want to Attach completed sample which works with business object to do CRUD in SQL server but does not accept zip format
0
Ivan Petrov
Telerik team
answered on 11 Jul 2013, 01:41 PM
Hello Shahab,

Thank you for your reply.

You can determine whether the dialog was open for adding or editing by checking the Appointment property of the dialog that is about to be opened. It will be equal to null if the dialog is about to be opened for adding, otherwise it will be an appointment instance holding the appointment that will be edited.
private void radScheduler1_AppointmentEditDialogShowing(object sender, AppointmentEditDialogShowingEventArgs e)
{
    bool add = ((EditAppointmentDialog)e.AppointmentEditDialog).Appointment == null;
}

You are allowed to attach only images to a forum post. If you have prepared a full example you can submit it as a CodeLibrary which will allow other members of the community to benefit from your effort and knowledge.

I hope this will help. Should you need further assistance, I would be glad to provide it.

Regards,
Ivan Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
shahab
Top achievements
Rank 1
answered on 13 Jul 2013, 08:59 AM
FormMode _FormMode = ((EditAppointmentDialog)e.AppointmentEditDialog).Appointment == null ? FormMode.Insert:FormMode.Update;               
            if (this.appointmentDialog == null)               
                this.appointmentDialog = new CustomAppointmentEditForm();
            ((CustomAppointmentEditForm)this.appointmentDialog)._FormMode = _FormMode;
            e.AppointmentEditDialog = this.appointmentDialog;
I implemented above code but it does not ok. When i have an appoinment for edit and after that want to insert new appointment it does not work.
Is there another way to get Insert/Update mode  in CustomAppointmentEditForm.
0
Ivan Petrov
Telerik team
answered on 17 Jul 2013, 02:26 PM
Hi Shahab,

Thank you for writing.

Indeed, this method does not provide valid identification on whether the dialog is opened for editing or adding. Here is another way to get indication on the purpose for which the dialog is opened:
private void radScheduler1_AppointmentEditDialogShowing(object sender, AppointmentEditDialogShowingEventArgs e)
{
    bool add = !this.radScheduler1.Appointments.Contains(e.Appointment);
}

I hope this will be useful. If your need further assistance, I would be glad to provide it.

Regards,
Ivan Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
Scheduler and Reminder
Asked by
shahab
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
shahab
Top achievements
Rank 1
Share this question
or