search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Open edit window after creating

Asked by Anonymous
7 years ago.

Hi everyone,

following tutorial for doctors - https://code.daypilot.org/55027/asp.net-doctor-appointment-scheduling

I want to open EDIT.ASPX for new created event right after creation, without clicking, it´s possible? I tryied to call "edit(e)" method fom c# code after creation of new event, but it´s not working.

It´s possible to do it?

Answer posted by Dan Letecky [DayPilot]
7 years ago.

It's possible to open the edit dialog on the client side as soon as the TimeRangeSelected callback is finished. You can pass custom data back to the client side using DayPilotCalendar.Update() and read it using AfterRenderJavaScript:

Modified Doctor.aspx:
<asp:Panel runat="server" ID="Schedule">
    <div style="float:left; width: 150px;">
        <DayPilot:DayPilotNavigator 
            runat="server" 
            ID="DayPilotNavigator1" 
            ClientIDMode="Static"
            BoundDayPilotID="DayPilotCalendar1"
            ShowMonths="3"    
            SelectMode="Week"
        
            OnBeforeCellRender="DayPilotNavigator1_OnBeforeCellRender"
            />  
    </div>
    
    <div style="margin-left: 150px;">
        <DayPilot:DayPilotCalendar 
            runat="server" 
            ID="DayPilotCalendar1"
            ClientObjectName="dp"
            ClientIDMode="Static"
            ViewType="Week"
        
            OnCommand="DayPilotCalendar1_OnCommand"
            TimeRangeSelectedHandling="CallBack"
            OnTimeRangeSelected="DayPilotCalendar1_OnTimeRangeSelected"
            OnBeforeEventRender="DayPilotCalendar1_OnBeforeEventRender"
            EventClickHandling="JavaScript"
            EventClickJavaScript="edit(e.id());"
            EventMoveHandling="CallBack"
            OnEventMove="DayPilotCalendar1_OnEventMove"
            EventResizeHandling="CallBack"
            OnEventResize="DayPilotCalendar1_OnEventResize"
            
            AfterRenderJavaScript="if (data && data.open) { edit(data.open); }"
            />
    </div>
</asp:Panel>
    
    
<script>
function edit(id) {
    new DayPilot.Modal({
        onClosed: function(args) {
            if (args.result == "OK") {
                dp.commandCallBack('refresh');
            }
        }
    }).showUrl("Edit.aspx?id=" + id);
}
</script>
</asp:Content>

Note that AfterRenderJavaScript is added and the edit() JS function is modified to accept event id instead of DayPilot.Event object.

Modified Doctor.aspx.cs:
    protected void DayPilotCalendar1_OnTimeRangeSelected(object sender, TimeRangeSelectedEventArgs e)
    {
        int doctor = Convert.ToInt32(Request.QueryString["id"]);

        int id = Db.CreateAppointment(doctor, e.Start, e.End);

        LoadCalendarData();

        Hashtable msg = new Hashtable();
        msg["open"] = id;
        DayPilotCalendar1.Update(msg);
    }

Note that Update() sends a custom object with back to the client (it holds the event id). This object is available as "data" variable in AfterRenderJavaScript.

Modified Db.CreateAppointment():
    public static int CreateAppointment(int doctor, DateTime start, DateTime end)
    {
        using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["daypilot"].ConnectionString))
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("INSERT INTO [Appointment] ([AppointmentStart], [AppointmentEnd], [DoctorId]) VALUES(@start, @end, @doctor)", con);
            cmd.Parameters.AddWithValue("start", start);
            cmd.Parameters.AddWithValue("end", end);
            cmd.Parameters.AddWithValue("doctor", doctor);
            cmd.ExecuteNonQuery();

            cmd = new SqlCommand("select @@identity;", con);
            int id = Convert.ToInt32(cmd.ExecuteScalar());
            return id;
        }
    }

It returns an id of the new record.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.