Scheduler breaks after grid update and scheduler new appt

1 posts, 0 answers
  1. EJ
    EJ avatar
    6 posts
    Member since:
    Dec 2014

    Posted 17 Jan Link to this post

    I'm having a very strange issue.  When I update or save a record in any one of my 3 RadGrids, then add a new appointment to the Scheduler, it saves the new appointment but then the scheduler stops reacting to any events.  It will not let you edit, or add new appointments and the radtooltip will error as if it were not registered.  I've included my add code for the scheduler and save function from one of my RadGrids (they're all similar).

    protected void RadScheduler1_AppointmentInsert(object sender, AppointmentInsertEventArgs e)
    {
        string newslot = e.Appointment.Attributes["SlotDesc"].ToString();
        if (!IsValidAppointment(e.Appointment, newslot))
        {
            e.Cancel = true;
            EventsDataSource.SelectCommand = eventsselectsql;
            RadScheduler1.Rebind();
            return;
        }
        if (e.Appointment.Resources.GetResourceByType("Status").Key.ToString().Equals("UNSCHEDULED", StringComparison.OrdinalIgnoreCase))
            return;
        string fakeid = string.Empty;
        try
        {
            fakeid = e.Appointment.ID.ToString();
            Session["OrigApptID"] = fakeid;
            e.Appointment.Attributes["SystemID"] = null;
        }
        catch
        { }
        int custid = -1;
        try
        {
            custid = int.Parse(Session["CurrentCustomerID"].ToString());
            Session.Remove("CurrentCustomerID");
        }
        catch{}
        if(!e.Appointment.Subject.Equals("CLOSED", StringComparison.OrdinalIgnoreCase) && !e.Appointment.Subject.Equals("LUNCH", StringComparison.OrdinalIgnoreCase))
        {
            string trailerID = e.Appointment.Attributes["TrailerID"];
            string carrierID = e.Appointment.Resources.GetResourceByType("CarrierID") == null ? null : e.Appointment.Resources.GetResourceByType("CarrierID").Key.ToString();
            if (!string.IsNullOrWhiteSpace(trailerID) && !string.IsNullOrWhiteSpace(carrierID))
            {
                InOpenTrailers(trailerID, carrierID);
            }
     
            UpdatePOList(int.Parse(fakeid), custid);
            rgOpenTrailers.Rebind();
            rgOpenPO.Rebind();
        }
        ClearSearch();
    }
    private void ClearSearch()
    {
        GridDataSource.SelectCommand = originalUnschedQuery;
        rgUnscheduled.DataBind();
        Session["ApptID"] = -1;
        btnResetSearch.Visible = false;
        txtSearch.Text = "";
        RadScheduler1.DayStartTime = cliconf.DayStartTime;
        RadScheduler1.DayEndTime = cliconf.DayEndTime;
        RadScheduler1.WorkDayStartTime = cliconf.WorkDayStartTime;
        RadScheduler1.WorkDayEndTime = cliconf.WorkDayEndTime;
     
        DateTime date = RadScheduler1.SelectedDate;
        Session.Add("CurrentDate", date.AddDays(-1).ToShortDateString());
        Session.Add("NextDate", date.AddDays(1).ToShortDateString());
        EventsDataSource.SelectCommand = eventsselectsql;
        RadScheduler1.Rebind();
        foreach (GridColumn column in SearchGrid.MasterTableView.OwnerGrid.Columns)
        {
            column.CurrentFilterFunction = GridKnownFunction.NoFilter;
            column.CurrentFilterValue = string.Empty;
        }
        searchWhere = string.Empty;
        SearchGrid.MasterTableView.FilterExpression = string.Empty;
        SearchGrid.MasterTableView.Rebind();
        SearchGrid.Rebind();
    }
    protected void btnTrailerSave_Click(object sender, EventArgs e)
    {
        string update = string.Empty;
        if (txtApptID.ReadOnly)
        {
            update = "UPDATE OpenTrailers SET ";
            update += "TrailerTypeID = '" + cboTrailerTrailerType.SelectedValue + "'";
            update += ", TrailerTypeDesc = '" + cboTrailerTrailerType.SelectedItem.Text + "'";
            update += ", RefField1='" + txtTrailerRef1.Text.TrimAndSafeDB() + "'";
            update += ", RefField2='" + txtTrailerRef2.Text.TrimAndSafeDB() + "'";
            update += ", RefField3='" + txtTrailerRef3.Text.TrimAndSafeDB() + "'";
            update += ", RefField4='" + txtTrailerRef4.Text.TrimAndSafeDB() + "'";
            update += ", RefField5='" + txtTrailerRef5.Text.TrimAndSafeDB() + "'";
            update += ", LocationID = '" + cboTrailerLocation.SelectedValue + "'";
            update += ", LocationDesc = '" + cboTrailerLocation.SelectedItem.Text + "'";
            update += " WHERE TrailerID='" + txtApptID.Text + "' AND CarrierID=" + cboTrailerCarrier.SelectedValue;
            update = string.Concat(update, " and ClientID=", Session["ClientID"].ToString(), " and AccountID=", Session["AccountID"].ToString(), " and WarehouseID=", Session["WarehouseID"].ToString());
        }
        else
        {
            update = "INSERT INTO OpenTrailers (ClientID, ClientName, AccountID, AccountName, WarehouseID, WarehouseName, CarrierID, CarrierDesc, TrailerID, TrailerTypeID, TrailerTypeDesc, RefField1, RefField2, RefField3, RefField4, RefField5, LocationID, LocationDesc, CreatedBy, CreatedDateTime, ModifiedBy, ModifiedDateTime) values (";
            update += Session["ClientID"].ToString() + ", ";
            update += "(Select ClientName from Client where ClientID=" + Session["ClientID"].ToString() + "), ";
            update += Session["AccountID"].ToString() + ", ";
            update += "(Select AccountName from Account where AccountID=" + Session["AccountID"].ToString() + "), ";
            update += Session["WarehouseID"].ToString() + ", ";
            update += "(Select WarehouseName from Warehouse where WarehouseID=" + Session["WarehouseID"].ToString() + "), ";
            update += cboTrailerCarrier.SelectedValue + ", ";
            update += "'" + cboTrailerCarrier.SelectedItem.Text + "', ";
            update += "'" + txtApptID.Text +"', ";
            update += "'" + cboTrailerTrailerType.SelectedValue + "', ";
            update += "'" + cboTrailerTrailerType.SelectedItem.Text + "', ";
            update += "'" + txtTrailerRef1.Text.TrimAndSafeDB() + "', ";
            update += "'" + txtTrailerRef2.Text.TrimAndSafeDB() + "', ";
            update += "'" + txtTrailerRef3.Text.TrimAndSafeDB() + "', ";
            update += "'" + txtTrailerRef4.Text.TrimAndSafeDB() + "', ";
            update += "'" + txtTrailerRef5.Text.TrimAndSafeDB() + "', ";
            update += "'" + cboTrailerLocation.SelectedValue + "', ";
            update += "'" + cboTrailerLocation.SelectedItem.Text + "', ";
            update += "'" + Session["UserID"].ToString() + "', ";
            update += "'" + DateTime.Now + "', ";
            update += "'" + Session["UserID"].ToString() + "', ";
            update += "'" + DateTime.Now + "') ";
        }
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DMSConnectionString"].ConnectionString);
        conn.Open();
        SqlTransaction trans = conn.BeginTransaction();
        SqlCommand cmd = new SqlCommand(update);
        cmd.Transaction = trans;
        try
        {
            cmd.Connection = conn;
            cmd.ExecuteNonQuery();
            trans.Commit();
        resetGrids();
        }
        catch (Exception ex)
        {
            RadAjaxManager1.Alert("An error occurred during the save: " + ex.Message);
            cmd.Dispose();
            hdnTrailerIndex.Value = "OPEN";
            trans.Rollback();
        }
        finally
        {
            cmd.Dispose();
            conn.Close();
            conn.Dispose();
        }
    }
Back to Top