Example #1
0
 private void ResetButtonClick(object sender, MouseButtonEventArgs e)
 {
     this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 38, 400);
     UIErr.Animation_Opacity_View_Frame(false, null, 300);
     UIErr.Text = string.Empty;
     this.LoadUI(this.e);
 }
Example #2
0
        private void SaveButtonClick(object sender, MouseButtonEventArgs e)
        {
            if (!App.curUser.Permision.mana_schedule)
            {
                this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                UIErr.Animation_Opacity_View_Frame(true, null, 550);
                UIErr.Text = "* Bạn không có quyền thực hiện chức năng này!";
                return;
            }
            if (this.UITimeEnd <= this.UITimeBegin)
            {
                this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                UIErr.Animation_Opacity_View_Frame(true, null, 550);
                UIErr.Text = "* Thời gian bắt đầu phải nhỏ hơn thời gian kết thúc";
                return;
            }
            if (this.UIComment.isEmpty())
            {
                this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                UIErr.Animation_Opacity_View_Frame(true, null, 550);
                UIErr.Text = "* Tên lịch chiếu không được để trống";

                return;
            }
            if (this.UIUser.SelectedItem == null)
            {
                this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                UIErr.Animation_Opacity_View_Frame(true, null, 550);
                UIErr.Text = "* Hãy nhập tên User bạn muốn đặt lịch";
                return;
            }
            if (this.UIDevice.SelectedItem == null)
            {
                this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                UIErr.Animation_Opacity_View_Frame(true, null, 550);
                UIErr.Text = "* Hãy nhập IP thiết bị bạn muốn đặt lịch";
                return;
            }

            #region Validate
            Event tmp = new Event();
            tmp.Content   = this.UIComment.Text;
            tmp.Begin     = UITimeBegin.Time;
            tmp.End       = UITimeEnd.Time;
            tmp.device_id = Convert.ToInt32(this.UIDevice.SelectedItem.key);
            tmp.parent_id = (this.ParentEvent == null) ? 0 : this.ParentEvent.Id;
            tmp.user_id   = Convert.ToInt32(this.UIUser.SelectedItem.key);
            tmp.loop      = this.UILoop.IsChecked.Value;
            if (this.ParentEvent != null)
            {
                if (this.ParentEvent.loop && tmp.loop)
                {
                    if (this.ParentEvent.Begin.TimeOfDay > tmp.Begin.TimeOfDay)
                    {
                        this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                        UIErr.Animation_Opacity_View_Frame(true, null, 550);
                        UIErr.Text = string.Format("* Thời gian bắt đầu phải lớn hơn {0:HH:mm:ss}", this.ParentEvent.Begin);
                        return;
                    }
                    else if (this.ParentEvent.End.TimeOfDay < tmp.End.TimeOfDay)
                    {
                        this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                        UIErr.Animation_Opacity_View_Frame(true, null, 550);
                        UIErr.Text = string.Format("* Thời gian kết thúc phải nhỏ hơn {0:HH:mm:ss}", this.ParentEvent.End);
                        return;
                    }
                }
                else if (this.ParentEvent.loop && !tmp.loop)
                {
                    if (tmp.Begin.Date != tmp.End.Date)
                    {
                        this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                        UIErr.Animation_Opacity_View_Frame(true, null, 550);
                        UIErr.Text = string.Format("* Ngày bắt đầu phải bằng ngày kết thúc");
                        return;
                    }
                    else if (this.ParentEvent.Begin.TimeOfDay > tmp.Begin.TimeOfDay)
                    {
                        this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                        UIErr.Animation_Opacity_View_Frame(true, null, 550);
                        UIErr.Text = string.Format("* Thời gian bắt đầu phải lớn hơn {0:HH:mm:ss} {1:dd/MM/yyyy}", this.ParentEvent.Begin, tmp.Begin);
                        return;
                    }
                    else if (this.ParentEvent.End.TimeOfDay < tmp.End.TimeOfDay)
                    {
                        this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                        UIErr.Animation_Opacity_View_Frame(true, null, 550);
                        UIErr.Text = string.Format("* Thời gian kết thúc phải nhỏ hơn {0:HH:mm:ss}  {1:dd/MM/yyyy}", this.ParentEvent.End, tmp.Begin);
                        return;
                    }
                }
                else if (!this.ParentEvent.loop && tmp.loop)
                {
                    if (this.ParentEvent.Begin.Date == this.ParentEvent.End.Date && this.ParentEvent.Begin.TimeOfDay > tmp.Begin.TimeOfDay)
                    {
                        this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                        UIErr.Animation_Opacity_View_Frame(true, null, 550);
                        UIErr.Text = string.Format("* Thời gian bắt đầu phải lớn hơn {0:HH:mm:ss}", this.ParentEvent.Begin);
                        return;
                    }
                    else if (this.ParentEvent.Begin.Date == this.ParentEvent.End.Date && this.ParentEvent.End.TimeOfDay < tmp.End.TimeOfDay)
                    {
                        this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                        UIErr.Animation_Opacity_View_Frame(true, null, 550);
                        UIErr.Text = string.Format("* Thời gian kết thúc phải nhỏ hơn {0:HH:mm:ss}", this.ParentEvent.End);
                        return;
                    }
                }
                else
                {
                    if (this.ParentEvent.Begin > tmp.Begin)
                    {
                        this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                        UIErr.Animation_Opacity_View_Frame(true, null, 550);
                        UIErr.Text = string.Format("* Thời gian bắt đầu phải lớn hơn {0:HH:mm:ss dd/MM/yyyy}", this.ParentEvent.Begin);
                        return;
                    }
                    else if (this.ParentEvent.End < tmp.End)
                    {
                        this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                        UIErr.Animation_Opacity_View_Frame(true, null, 550);
                        UIErr.Text = string.Format("* Thời gian kết thúc phải nhỏ hơn {0:HH:mm:ss dd/MM/yyyy}", this.ParentEvent.End);
                        return;
                    }
                }
            }
            this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 38, 400);
            UIErr.Animation_Opacity_View_Frame(false, null, 300);
            UIErr.Text = string.Empty;
            #endregion

            if (this.e == null)
            {
                #region Insert Event
                int result = Event.Insert(tmp);
                if (result != 1)
                {
                    this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                    UIErr.Animation_Opacity_View_Frame(true, null, 550);
                    UIErr.Text = string.Format("* Không thể thêm lịch phát vào khoảng thời gian này.");
                    return;
                }
                else
                {
                    if (this.CloseEvent != null)
                    {
                        this.CloseEvent(this, new CloseUIEventData()
                        {
                            Data = tmp
                        });
                    }
                }
                #endregion  Insert Event
            }
            else
            {
                #region Edit Event
                tmp.Id        = this.e.Id;
                tmp.parent_id = this.e.parent_id;
                int result = tmp.Save();
                if (result != 1)
                {
                    this.UIContent.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 67, 500);
                    UIErr.Animation_Opacity_View_Frame(true, null, 550);
                    UIErr.Text = string.Format("* Không thể thêm lịch phát vào khoảng thời gian này.");
                    return;
                }
                else
                {
                    if (this.CloseEvent != null)
                    {
                        this.CloseEvent(this, new CloseUIEventData()
                        {
                            Data = tmp
                        });
                    }
                }
                #endregion  Edit Event
            }
        }