Ejemplo n.º 1
0
        public override Panel ShowAddForm(object Object = null)
        {
            category EditCategory = (category)Object;
            bool     EditState    = EditCategory != null;

            ClearAllFields();
            //  UpdateList();
            Button BtnAdd = new Button()
            {
                Text = "Add"
            };

            BtnAdd.Click += (e, o) =>
            {
                category Category = new category()
                {
                    id            = EditState ? InputID.Text : null,
                    category_name = InputCategoryName.Text.Trim(),
                    books         = null
                };
                if (null != UserClient.AddCategory(Category, AppUser))
                {
                    MessageBox.Show("Success");
                    EntityForm.Navigate(0, 0);
                }
                else
                {
                    MessageBox.Show("Failed");
                }
            };
            InputID.Enabled = false;
            InputID.Text    = "GENERATED";

            if (EditState)
            {
                InputID.Text           = EditCategory.id;
                InputCategoryName.Text = EditCategory.category_name.Trim();
            }

            Control[] Controls = new Control[]
            {
                new TitleLabel(20)
                {
                    Text = "Add Category"
                }, new BlankControl(),
                new Label()
                {
                    Text = "ID"
                }, InputID,
                new Label()
                {
                    Text = "Name"
                }, InputCategoryName,
                BtnAdd, null
            };

            return(ControlUtil.GeneratePanel(2, Controls, 5, 180, 30, Color.Aqua));
        }