Make Scheduler in asp.net using rad ajax toolkit in asp.net

Leave a Comment
Developing scheduler in asp.net you need these things which i mentioned here.

1] rad ajax toolkit
2]database structure

Here i am giving you database design snap where you can see required fields in it.


Now I am giving you  design page to develop schedular:

aspx page:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" >
        </telerik:RadScriptManager>
       
       
    <telerik:RadScheduler ID="RadScheduler1" runat="server" DataKeyField="Schedular_id"
            DataSubjectField="Schedular_name" DataStartField="Schedular_Start_time"
            DataEndField="Schedular_End_time"
            onappointmentdelete="RadScheduler1_AppointmentDelete"
            onappointmentinsert="RadScheduler1_AppointmentInsert" >
   
    </telerik:RadScheduler>
    </div>
    </form>
</body>
</html>
aspx.cs file:

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Data.SqlClient;
using Telerik.Web.UI;
public partial class _Default : System.Web.UI.Page
{
    SqlConnection cn = new SqlConnection(@"Data Source=DEVANG-PC\SQLEXPRESS;Initial Catalog=Schedular_db;User ID=sa;Password=sa123");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            data_bind();
        }
    }
    protected void data_bind()
    {
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter da = new SqlDataAdapter();
        DataTable dt = new DataTable();
        try
        {
            cn.Open();
            cmd.CommandText = "Select * from Schedular_master";
            cmd.Connection = cn;
            cmd.CommandType = CommandType.Text;
            da.SelectCommand = cmd;
            da.Fill(dt);
            cn.Close();
            RadScheduler1.DataSource = dt;
            RadScheduler1.DataBind();
        }
        catch (Exception ex)
        {
            cn.Close();
            Response.Write(ex.Message);
        }
    }
    protected void RadScheduler1_AppointmentDelete(object sender, AppointmentDeleteEventArgs e)
    {
        SqlCommand cmd = new SqlCommand();
        try
        {
            cn.Open();
            string start = e.Appointment.Start.ToString();
            string end = e.Appointment.End.ToString();
            string subject = e.Appointment.Subject;
            string sub_id = e.Appointment.ID.ToString();
            cmd.CommandText = "Delete from Schedular_master where Schedular_id='" + Convert.ToInt32(sub_id) + "' and Schedular_name='" + subject + "' and Schedular_Start_time='" + start + "' and Schedular_End_time='" + end + "'";
            cmd.Connection = cn;
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
            cn.Close();

            data_bind();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
        //protected void RadScheduler1_AppointmentDelete(object sender, Telerik.Web.UI.AppointmentDeleteEventArgs e)
        //{
        //    DateTime dt = (DateTime)e.Appointment.Start;
        //    DateTime dtend = (DateTime)e.Appointment.End;
        //    String s = e.Appointment.Subject.ToString();

        //    SqlConnection conn = new SqlConnection();
        //    conn.ConnectionString = ConfigurationManager.ConnectionStrings["database1ConnectionString2"].ConnectionString.ToString();
        //    conn.Open();
        //    SqlCommand cmd = new SqlCommand("Delete from DateTime where StartDates='" + dt + "'and EndDates='" + dtend + "' and Event='" + s + "';", conn);
        //    cmd.ExecuteNonQuery();

        //}
    }
    protected void RadScheduler1_AppointmentInsert(object sender, AppointmentInsertEventArgs e)
    {
        SqlCommand cmd = new SqlCommand();
        try
        {
            cn.Open();
            string start = e.Appointment.Start.ToString();
            string end = e.Appointment.End.ToString();
            string subject = e.Appointment.Subject;
            cmd.CommandText = "insert into Schedular_master(Schedular_name,Schedular_Start_time,Schedular_End_time) values(@subject,@start,@end)";
            cmd.Parameters.AddWithValue("subject", subject);
            cmd.Parameters.AddWithValue("start", start);
            cmd.Parameters.AddWithValue("end", end);
            cmd.Connection = cn;
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
            cn.Close();
            data_bind();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
}


output:

0 comments:

Post a Comment