コード例 #1
0
        public ActionResult appointment_edit(juggle.Models.tbl_appointment appointment)
        {
            if (Session["User_Id"] == null)
            {
                return(RedirectToAction("Appointment", "Appointment"));
            }
            if (Session["User_Id"] != null)
            {
                try
                {
                    using (jugglecontext dbcon = new jugglecontext())
                    {
                        tbl_appointment editappointment   = new tbl_appointment();
                        string          multipleattribute = Request.Form["attribute_iddata"].ToString();
                        editappointment.appointment_id = appointment.appointment_id;
                        editappointment.description    = appointment.description;
                        editappointment.recurring      = appointment.recurring;
                        editappointment.start_date     = appointment.start_date;
                        editappointment.end_date       = appointment.end_date;
                        editappointment.time           = appointment.time;
                        string multiplevalue = Request.Form["multiple"];

                        if (appointment.recurring)
                        {
                            //appointment.end_date = null;
                        }

                        if (!string.IsNullOrEmpty(multiplevalue))
                        {
                            editappointment.day = multiplevalue;
                        }
                        else
                        {
                            multiplevalue = "0"; editappointment.day = "0";
                        }

                        editappointment.updated_date = DateTime.Now;
                        if (!string.IsNullOrEmpty(appointment.notes))
                        {
                            editappointment.notes = appointment.notes;
                        }
                        else
                        {
                            editappointment.notes = "N/A";
                        }
                        //   editappointment.notes = appointment.notes;
                        editappointment.time_range_start = appointment.time_range_start;
                        editappointment.time_range_end   = appointment.time_range_end;

                        // add two extra field that store the calendar start time and end time
                        // it is use for the event of google calendar only
                        // start

                        string   startdate1    = appointment.start_date.ToString();
                        DateTime strstartdate1 = Convert.ToDateTime(startdate1);

                        string   enddate1    = appointment.end_date.ToString();
                        DateTime strenddate1 = Convert.ToDateTime(enddate1);

                        DateTime cal_startdate = Convert.ToDateTime(strstartdate1.ToString("yyyy/MM/dd") + " " + appointment.time_range_start);
                        DateTime cal_enddate   = Convert.ToDateTime(strenddate1.ToString("yyyy/MM/dd") + " " + appointment.time_range_end);

                        editappointment.Calendar_Start_datetime = DateTimeOffset.Parse(cal_startdate.ToString()).UtcDateTime;
                        editappointment.Calendar_End_datetime   = DateTimeOffset.Parse(cal_enddate.ToString()).UtcDateTime;

                        string       timezone   = "West Asia Standard Time";
                        TimeZoneInfo targetZone = TimeZoneInfo.FindSystemTimeZoneById(timezone);
                        cal_startdate = TimeZoneInfo.ConvertTimeFromUtc(cal_startdate, targetZone);
                        cal_enddate   = TimeZoneInfo.ConvertTimeFromUtc(cal_enddate, targetZone);

                        editappointment.Calendar_Start_datetime = cal_startdate;
                        editappointment.Calendar_End_datetime   = cal_enddate;

                        // end

                        // get time into total minutes
                        string startingtime = appointment.time_range_start.ToString();
                        string endindtime   = appointment.time_range_end.ToString();

                        TimeSpan starttime = TimeSpan.Parse(startingtime);
                        TimeSpan endatime  = TimeSpan.Parse(endindtime);

                        TimeSpan Difflength = endatime.Subtract(starttime);                 // difference between start time and end time
                        int      total      = (Difflength.Hours * 60) + Difflength.Minutes; // convert difference in minutes

                        editappointment.length = total;

                        editappointment.client_id          = Convert.ToInt32(appointment.client_id);
                        editappointment.attribute_id       = multipleattribute.ToString();
                        editappointment.emp_id             = Convert.ToInt32(appointment.emp_id);
                        editappointment.work_id            = Convert.ToInt32(appointment.work_id);
                        editappointment.time_interval_id   = Convert.ToInt32(appointment.time_interval_id);
                        editappointment.user_id            = Convert.ToInt32(Session["User_Id"]);
                        dbcon.Entry(editappointment).State = System.Data.Entity.EntityState.Modified;
                        dbcon.SaveChanges();

                        // delete the appointment already inserted days and again insert into another table
                        //SqlConnection appointmentconnection = new SqlConnection(dbcon.connectionString());
                        //var appointmentcommand = new SqlCommand("appooint_day", appointmentconnection);
                        //appointmentcommand.CommandType = CommandType.StoredProcedure;
                        //appointmentcommand.Parameters.AddWithValue("@appointment_id", Convert.ToInt32(appointment.appointment_id));
                        //appointmentcommand.Parameters.AddWithValue("@type", "deleteappointmentday");
                        //appointmentconnection.Open();
                        //SqlDataReader appointmentreader = appointmentcommand.ExecuteReader();
                        //appointmentconnection.Close();

                        SqlConnection connectiondeleteday = new SqlConnection(dbcon.connectionString());
                        var           commanddeleteday    = new SqlCommand("Appointmentday", connectiondeleteday);
                        commanddeleteday.CommandType = CommandType.StoredProcedure;
                        commanddeleteday.Parameters.AddWithValue("@maxid", Convert.ToInt32(0));
                        commanddeleteday.Parameters.AddWithValue("@day", Convert.ToInt32(0));
                        commanddeleteday.Parameters.AddWithValue("@appointmentid", Convert.ToInt32(appointment.appointment_id));
                        commanddeleteday.Parameters.AddWithValue("@type", "deleteday");
                        connectiondeleteday.Open();
                        SqlDataReader rdrdelete = commanddeleteday.ExecuteReader();
                        connectiondeleteday.Close();

                        if (!string.IsNullOrEmpty(multiplevalue))
                        {
                            string[] values = multiplevalue.Split(',');
                            for (int i = 0; i < values.Length; i++)
                            {
                                values[i] = values[i].Trim();

                                SqlConnection connectionupdateday = new SqlConnection(dbcon.connectionString());
                                var           commandupdateday    = new SqlCommand("Appointmentday", connectionupdateday);
                                commandupdateday.CommandType = CommandType.StoredProcedure;
                                commandupdateday.Parameters.AddWithValue("@maxid", Convert.ToInt32(appointment.appointment_id));
                                commandupdateday.Parameters.AddWithValue("@day", Convert.ToInt32(values[i]));
                                commandupdateday.Parameters.AddWithValue("@appointmentid", Convert.ToInt32(0));
                                commandupdateday.Parameters.AddWithValue("@type", "updateday");
                                connectionupdateday.Open();
                                SqlDataReader rdrupdate = commandupdateday.ExecuteReader();
                                connectiondeleteday.Close();
                            }
                        }
                        return(RedirectToAction("Appointment", "Appointment"));
                    }
                }

                catch (DbEntityValidationException ex)
                {
                    foreach (var entityValidationErrors in ex.EntityValidationErrors)
                    {
                        foreach (var validationError in entityValidationErrors.ValidationErrors)
                        {
                            Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                        }
                    }
                    return(View());
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
コード例 #2
0
        public ActionResult Create_Appointment(juggle.Models.tbl_appointment appointment)
        {
            if (Session["User_Id"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            using (jugglecontext dbcon = new jugglecontext())
            {
                try
                {
                    tbl_appointment addappointment    = new tbl_appointment();
                    string          multipleattribute = Request.Form["attribute_idmul"].ToString();
                    string          multiplelist      = null;

                    if (appointment.recurring)
                    {
                        multiplelist = Request.Form["multiple"];
                    }
                    else
                    {
                        multiplelist = null;
                    }
                    addappointment.created_date = DateTime.Now;
                    addappointment.description  = appointment.description;
                    addappointment.recurring    = appointment.recurring;

                    if (!string.IsNullOrEmpty(multiplelist))
                    {
                        addappointment.day = multiplelist;
                    }
                    else
                    {
                        multiplelist = "0"; addappointment.day = "0";
                    }

                    //addappointment.day = appointment.day;
                    addappointment.start_date       = appointment.start_date;
                    addappointment.end_date         = appointment.end_date;
                    addappointment.time_range_start = appointment.time_range_start;
                    addappointment.time_range_end   = appointment.time_range_end;


                    // add two extra field that store the calendar start time and end time
                    // it is use for the event of google calendar only
                    // start

                    string   startdate1    = appointment.start_date.ToString();
                    DateTime strstartdate1 = Convert.ToDateTime(startdate1);

                    string   enddate1    = appointment.end_date.ToString();
                    DateTime strenddate1 = Convert.ToDateTime(enddate1);

                    DateTime cal_startdate = Convert.ToDateTime(strstartdate1.ToString("yyyy/MM/dd") + " " + appointment.time_range_start);
                    DateTime cal_enddate   = Convert.ToDateTime(strenddate1.ToString("yyyy/MM/dd") + " " + appointment.time_range_end);

                    addappointment.Calendar_Start_datetime = DateTimeOffset.Parse(cal_startdate.ToString()).UtcDateTime;
                    addappointment.Calendar_End_datetime   = DateTimeOffset.Parse(cal_enddate.ToString()).UtcDateTime;

                    string       timezone   = "West Asia Standard Time";
                    TimeZoneInfo targetZone = TimeZoneInfo.FindSystemTimeZoneById(timezone);
                    cal_startdate = TimeZoneInfo.ConvertTimeFromUtc(cal_startdate, targetZone);
                    cal_enddate   = TimeZoneInfo.ConvertTimeFromUtc(cal_enddate, targetZone);

                    addappointment.Calendar_Start_datetime = cal_startdate;
                    addappointment.Calendar_End_datetime   = cal_enddate;

                    // end
                    string startingtime = appointment.time_range_start.ToString();
                    string endindtime   = appointment.time_range_end.ToString();

                    TimeSpan starttime = TimeSpan.Parse(startingtime);
                    TimeSpan endatime  = TimeSpan.Parse(endindtime);

                    TimeSpan Difflength = endatime.Subtract(starttime);
                    int      total      = (Difflength.Hours * 60) + Difflength.Minutes;

                    addappointment.length = total;
                    if (!string.IsNullOrEmpty(addappointment.notes))
                    {
                        addappointment.notes = appointment.notes;
                    }
                    else
                    {
                        addappointment.notes = "N/A";
                    }

                    addappointment.client_id        = Convert.ToInt32(appointment.client_id);
                    addappointment.work_id          = Convert.ToInt32(appointment.work_id);
                    addappointment.time_interval_id = Convert.ToInt32(appointment.time_interval_id);
                    addappointment.user_id          = Convert.ToInt32(Session["User_Id"]);

                    addappointment.attribute_id = multipleattribute.ToString();
                    addappointment.time         = appointment.time;
                    dbcon.tbl_appointment.Add(addappointment);
                    dbcon.SaveChanges();
                    var maxid = 0;
                    try
                    {
                        var context_latest_Id = new jugglecontext();

                        var maxappointmentid = (from a in context_latest_Id.tbl_appointment
                                                select new
                        {
                            a.appointment_id
                        }).ToList();

                        maxid = Convert.ToInt32(maxappointmentid[0].appointment_id);

                        for (int i = 0; i < maxappointmentid.Count; i++)
                        {
                            if (maxid < Convert.ToInt32(maxappointmentid[i].appointment_id))
                            {
                                maxid = Convert.ToInt32(maxappointmentid[i].appointment_id);
                            }
                        }
                    }
                    catch { }

                    if (!string.IsNullOrEmpty(multiplelist))
                    {
                        string[] values = multiplelist.Split(',');

                        if (appointment.recurring)
                        {
                            appointment.end_date = null;
                        }

                        for (int i = 0; i < values.Length; i++)
                        {
                            values[i] = values[i].Trim();

                            // add day into another table
                            SqlConnection connectioninsertday = new SqlConnection(dbcon.connectionString());
                            var           commandinsertday    = new SqlCommand("Appointmentday", connectioninsertday);
                            commandinsertday.CommandType = CommandType.StoredProcedure;
                            commandinsertday.Parameters.AddWithValue("@maxid", Convert.ToInt32(maxid));
                            commandinsertday.Parameters.AddWithValue("@day", Convert.ToInt32(values[i]));
                            commandinsertday.Parameters.AddWithValue("@appointmentid", Convert.ToInt32(0));
                            //commandinsertday.Parameters.AddWithValue("@date", dating);
                            commandinsertday.Parameters.AddWithValue("@type", "insertday");
                            connectioninsertday.Open();
                            SqlDataReader rdr = commandinsertday.ExecuteReader();
                            connectioninsertday.Close();
                        }
                    }

                    return(RedirectToAction("AppointMent", "AppointMent"));
                }

                catch (DbEntityValidationException ex)
                {
                    foreach (var entityValidationErrors in ex.EntityValidationErrors)
                    {
                        foreach (var validationError in entityValidationErrors.ValidationErrors)
                        {
                            Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                        }
                    }
                    return(View(appointment));
                }
            }
        }