Пример #1
0
        public string AddSchedule(string data, Client client, Server server)
        {
            string[] strs     = data.Split('$');
            string   time     = strs[0];
            byte     isNotice = byte.Parse(strs[1]);
            string   content  = strs[2];
            int      id       = scheduleDAO.AddSchedule(client.MySQLConn, client.GetUserId(), time, isNotice, content);

            return(id + "$" + UpdateSchedule("", client, server));
        }
        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            string idstr = boxID.Text;

            try
            {
                Schedule schedule = new Schedule();

                schedule.Name           = boxNombre.Text;
                schedule.Description    = boxDescripcion.Text;
                schedule.Fk_institution = int.Parse(selInstitution.SelectedValue);
                schedule.Lunesin        = boxLunesin.Text;
                schedule.Lunesout       = boxLunesout.Text;
                schedule.Martesin       = boxMartesin.Text;
                schedule.Martesout      = boxMartesout.Text;
                schedule.Miercolesin    = boxMiercolesin.Text;
                schedule.Miercolesout   = boxMiercolesout.Text;
                schedule.Juevesin       = boxJuevesin.Text;
                schedule.Juevesout      = boxJuevesout.Text;
                schedule.Viernesin      = boxViernesin.Text;
                schedule.Viernesout     = boxViernesout.Text;
                schedule.Sabadoin       = boxSabadoin.Text;
                schedule.Sabadoout      = boxSabadoout.Text;
                schedule.Domingoin      = boxDomingoin.Text;
                schedule.Domingoout     = boxDomingoout.Text;

                if (String.IsNullOrEmpty(idstr)) //new
                {
                    ScheduleDAO.AddSchedule(schedule);
                }
                else //update
                {
                    schedule.Id = int.Parse(boxID.Text);
                    ScheduleDAO.ModSchedule(schedule);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.StackTrace);
                Debug.WriteLine(ex.Message);
            }

            Response.Redirect("~/ScheduleList");
            Context.ApplicationInstance.CompleteRequest();
        }
        protected void btnNew_Click(object sender, EventArgs e)
        {
            string id    = txtScheduleID.Text;
            string date  = ParseExactDateString(txtDate.Text.Trim());
            string time  = ConvertToTime(dlHour.SelectedValue, dlMinute.SelectedValue, dlState.SelectedValue.ToUpper());
            float  price = 0;

            try
            {
                price = float.Parse(txtPrice.Text);
            }
            catch
            {
                SetMessageTextAndColor("Price must be a number!", Color.Red);
                return;
            }
            if (!CheckDateTime(date, time))
            {
                SetMessageTextAndColor("Date Format is invalid, format: MM/dd/yyyy.", Color.Red);
                return;
            }
            string             datetime = date + " " + time;
            string             movieid  = dlMovieID.SelectedValue;
            int                roomID   = Convert.ToInt32(dlRoomID.SelectedValue);
            List <ScheduleDTO> list     = (List <ScheduleDTO>)Session["AdminScheduleList"];

            foreach (ScheduleDTO item in list)
            {
                if (movieid.Equals(item.MovieID) && roomID == item.RoomID && datetime.Equals(ConvertScheduleDateInListToCompare(item.ScheduleDate.ToString())))
                {
                    SetMessageTextAndColor("This time: " + datetime + " with Room: " + roomID + " and MovieID: " + movieid + " has already been added, please try again!", Color.Red);
                    return;
                }
                else if (datetime.Equals(ConvertScheduleDateInListToCompare(item.ScheduleDate.ToString())) && roomID == item.RoomID)
                {
                    SetMessageTextAndColor("This time: " + datetime + ", at Room: " + roomID + " has already been set up. Please try again.", Color.Red);
                    return;
                }
            }
            string      format = "MM/dd/yyyy hh:mm:ss tt";
            ScheduleDTO dto    = new ScheduleDTO
            {
                ScheduleID    = id,
                ScheduleDate  = DateTime.ParseExact(datetime, format, CultureInfo.CurrentCulture),
                MovieID       = movieid,
                RoomID        = roomID,
                PriceOfTicket = price
            };

            try
            {
                if (ScheduleDaos.AddSchedule(dto))
                {
                    SetMessageTextAndColor("Successfully added!", Color.Green);
                }
                else
                {
                    SetMessageTextAndColor("Failed to add!", Color.Red);
                }
            }
            catch
            {
                SetMessageTextAndColor("ScheduleID is duplicated, please choose another one!", Color.Red);
            }
        }