Пример #1
0
        internal void EventCreate(DateTime start, DateTime end, string text, string resource, string recurrenceJson)
        {
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["daypilot"].ConnectionString))
            {
                con.Open();

                SqlCommand cmd = new SqlCommand("INSERT INTO [event] (eventstart, eventend, name, resource) VALUES (@start, @end, @name, @resource); ", con);  // SELECT SCOPE_IDENTITY();
                cmd.Parameters.AddWithValue("start", start);
                cmd.Parameters.AddWithValue("end", end);
                cmd.Parameters.AddWithValue("name", text);
                cmd.Parameters.AddWithValue("resource", resource);
                //cmd.Parameters.AddWithValue("recurrence", recurrence);
                cmd.ExecuteScalar();

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

                RecurrenceRule rule             = RecurrenceRule.FromJson(id.ToString(), start, recurrenceJson);
                string         recurrenceString = rule.Encode();
                if (!String.IsNullOrEmpty(recurrenceString))
                {
                    cmd = new SqlCommand("update [event] set [recurrence] = @recurrence where [id] = @id", con);
                    cmd.Parameters.AddWithValue("recurrence", rule.Encode());
                    cmd.Parameters.AddWithValue("id", id);
                    cmd.ExecuteNonQuery();
                }
            }
        }
Пример #2
0
    protected void ButtonSave_Click(object sender, EventArgs e)
    {
        string id       = Request.QueryString["id"];
        string masterId = Request.QueryString["master"];

        DataRow master = table.Rows.Find(masterId);
        DataRow row    = table.Rows.Find(id);

        switch (Mode)
        {
        case EventMode.Master:
            RecurrenceRule rule = RecurrenceRule.FromJson(masterId, (DateTime)master["start"], Recurrence.Value);
            master["name"]       = TextBoxName.Text;
            master["start"]      = Convert.ToDateTime(TextBoxStart.Text);
            master["end"]        = Convert.ToDateTime(TextBoxEnd.Text);
            master["recurrence"] = rule.Encode();
            table.AcceptChanges();
            break;

        case EventMode.NewException:
            DataRow r = table.NewRow();
            r["id"]         = Guid.NewGuid().ToString();
            r["name"]       = TextBoxName.Text;
            r["start"]      = Convert.ToDateTime(TextBoxStart.Text);
            r["end"]        = Convert.ToDateTime(TextBoxEnd.Text);
            r["recurrence"] = RecurrenceRule.EncodeExceptionModified(masterId, Occurrence);
            table.Rows.Add(r);
            table.AcceptChanges();
            break;

        case EventMode.Exception:
            row["name"]  = TextBoxName.Text;
            row["start"] = Convert.ToDateTime(TextBoxStart.Text);
            row["end"]   = Convert.ToDateTime(TextBoxEnd.Text);
            table.AcceptChanges();
            break;

        case EventMode.Regular:
            row["name"]       = TextBoxName.Text;
            row["start"]      = Convert.ToDateTime(TextBoxStart.Text);
            row["end"]        = Convert.ToDateTime(TextBoxEnd.Text);
            row["recurrence"] = RecurrenceRule.FromJson(id, (DateTime)row["start"], Recurrence.Value).Encode();
            table.AcceptChanges();
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }

        Modal.Close(this, "OK");
    }
Пример #3
0
    private DataTable GetData()
    {
        DataTable dt;

        dt = new DataTable();
        dt.Columns.Add("start", typeof(DateTime));
        dt.Columns.Add("end", typeof(DateTime));
        dt.Columns.Add("name", typeof(string));
        dt.Columns.Add("id", typeof(string));
        dt.Columns.Add("recurrence", typeof(string));

        DataRow dr;

        DateTime start = Week.FirstDayOfWeek().AddHours(15);
        // starting on the first day of this week today at 15:00, repeated every week, five times
        RecurrenceRule rule = RecurrenceRule.FromDateTime("1", start).Weekly().Times(5);

        dr               = dt.NewRow();
        dr["id"]         = 1;
        dr["start"]      = start;
        dr["end"]        = start.AddHours(1);
        dr["name"]       = "Every week";
        dr["recurrence"] = rule.Encode();
        dt.Rows.Add(dr);

        DateTime start2 = Week.FirstDayOfWeek().AddHours(10);
        // starting on the first day of this week at 10:00, repeated every day for one month
        //RecurrenceRule rule2 = RecurrenceRule.FromDateTime("2", start2).Daily().Until(start2.AddDays(31));
        RecurrenceRule rule2 = RecurrenceRule.FromDateTime("2", start2).Daily(2).Times(2);

        dr               = dt.NewRow();
        dr["id"]         = 2;
        dr["start"]      = start2;
        dr["end"]        = start2.AddHours(1);
        dr["name"]       = "Every day";
        dr["recurrence"] = rule2.Encode();
        dt.Rows.Add(dr);

        DateTime start3 = Week.FirstDayOfWeek().AddDays(1).AddHours(13);

        dr          = dt.NewRow();
        dr["id"]    = 3;
        dr["start"] = start3;
        dr["end"]   = start3.AddHours(1);
        dr["name"]  = "By hour (custom)";
        dt.Rows.Add(dr);

        dt.PrimaryKey = new DataColumn[] { dt.Columns["id"] };

        return(dt);
    }
Пример #4
0
    public ActionResult Edit(FormCollection form)
    {
        string id       = form["Id"];
        string masterId = Request.QueryString["master"];

        string   recurrence = form["Recurrence"];
        DateTime start      = Convert.ToDateTime(form["Start"]);
        DateTime end        = Convert.ToDateTime(form["End"]);
        string   text       = form["Text"];
        string   resource   = form["Resource"];

        var row    = new EventManager().Get(id) ?? new EventManager.Event();
        var master = new EventManager().Get(masterId) ?? new EventManager.Event();

        switch (Mode(id))
        {
        case EventMode.Master:
            RecurrenceRule rule = RecurrenceRule.FromJson(masterId, master.Start, recurrence);
            new EventManager().EventEdit(masterId, text, start, end, resource, rule.Encode());
            break;

        case EventMode.NewException:
            new EventManager().EventCreateException(start, end, text, resource, RecurrenceRule.EncodeExceptionModified(masterId, Occurrence));
            break;

        case EventMode.Exception:
            new EventManager().EventEdit(id, text, start, end, resource);
            break;

        case EventMode.Regular:
            new EventManager().EventEdit(id, text, start, end, resource, RecurrenceRule.FromJson(id, row.Start, recurrence).Encode());
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }

        return(JavaScript(SimpleJsonSerializer.Serialize("OK")));
    }