public static int Insert(Event e)
        {
            int result = 0;
            try
            {

                using (MySqlConnection conn = new MySqlConnection(App.setting.connectString))
                {
                    conn.Open();
                    string query = "`p_insert_schedule_device`";
                    using (MySqlCommand cmd = new MySqlCommand(query, conn))
                    {
                        cmd.Parameters.Add(new MySqlParameter("@_device", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Input, Value = e.device_id });
                        cmd.Parameters.Add(new MySqlParameter("@_user", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Input, Value = e.user_id });
                        cmd.Parameters.Add(new MySqlParameter("@_parent", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Input, Value = e.parent_id });
                        cmd.Parameters.Add(new MySqlParameter("@_time_begin", MySqlDbType.DateTime) { Direction = System.Data.ParameterDirection.Input, Value = e.Begin });
                        cmd.Parameters.Add(new MySqlParameter("@_time_end", MySqlDbType.DateTime) { Direction = System.Data.ParameterDirection.Input, Value = e.End });
                        cmd.Parameters.Add(new MySqlParameter("@_loop", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Input, Value = e.loop });
                        cmd.Parameters.Add(new MySqlParameter("@_comment", MySqlDbType.VarChar, 100) { Direction = System.Data.ParameterDirection.Input, Value = e.Content });
                        cmd.Parameters.Add(new MySqlParameter("@result", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Output, Value = 0 });
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.ExecuteScalar();
                        result = Convert.ToInt32(cmd.Parameters["@result"].Value);

                    };
                    conn.Close();
                };
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetBaseException().ToString());
            }
            return result;
        }
Exemplo n.º 2
0
        public bool Add(ref Event E)
        {
            if (this.Mode == ModeGroup.None)
            {
                this.Events.Add(E);
                E.Left = this.Left;
                E.Width = this.Width;
                return true;
            }
            if (E.Id == 7)
            {
                Console.Write(E.Id);
            }
            if (this.Mode == ModeGroup.Vertical)
            {
                bool canAdd = true;
                foreach (Event e in this.Events)
                {
                    double h = 0;
                    int min = (e.BeginIndex <= E.BeginIndex) ? e.BeginIndex : E.BeginIndex;
                    int max = (e.BeginIndex <= E.BeginIndex) ? E.BeginIndex : e.BeginIndex;
                    for (int i = min; i < max; i++)
                    {
                        bool isEx = false;
                        foreach (int j in ExpansionIndex)
                        {
                            if (i == j)
                            {
                                isEx = true;
                                break;
                            }
                        }
                        if (isEx)
                            h += 120;
                        else h += 60;
                    }

                    if (e.BeginIndex < E.BeginIndex || (e.BeginIndex == E.BeginIndex && e.Top <= E.Top))
                    {
                        h -= e.Top;
                        h += E.Top;
                        if (e.Height >= h)
                        {
                            canAdd = false;
                            break;
                        }
                    }
                    else
                    {
                        h += e.Top;
                        h -= E.Top;
                        if (E.Height >= h)
                        {
                            canAdd = false;
                            break;
                        }
                    }

                }
                if (canAdd)
                {
                    this.Events.Add(E);
                    E.Left = this.Left;
                    E.Width = this.Width;
                    return true;
                }
            }
            return false;
        }
        public static void delete(Event e)
        {
            try
            {
                using (MySqlConnection conn = new MySqlConnection(App.setting.connectString))
                {
                    conn.Open();
                    string query = "`p_delete_schedule`";
                    using (MySqlCommand cmd = new MySqlCommand(query, conn))
                    {
                        cmd.Parameters.Add(new MySqlParameter("@_s_id", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Input, Value = e.Id });
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.ExecuteScalar();
                    };
                    conn.Close();
                };
            }
            catch (Exception)
            {

            }
        }