Beispiel #1
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            string            panelName   = PanelName.Text;
            List <string>     displayCols = DisplayCols.RetrieveStringData();
            List <UserAction> actions     = new List <UserAction>();

            foreach (string s in actionsControl.RetrieveStringData())
            {
                actions.Add((UserAction)Enum.Parse(typeof(UserAction), s));
            }

            ValidationResult.Items.Clear();
            // validate the proposal
            if (panelName == ".")
            {
                ValidationResult.Items.Add("Give the pannel a name, please.");
            }
            else if (displayCols.Count == 0)
            {
                ValidationResult.Items.Add("Select at leas one column to display");
            }
            else if (actions.Count == 0)
            {
                ValidationResult.Items.Add("Check at least one action users can perform in thie panel, please");
            }
            else
            {
                ValidationResult.Items.Add("Valid");
                // => create the panel and save it
                _min.Models.Control        c;
                List <_min.Models.Control> controls = new List <_min.Models.Control>();

                _min.Models.Control insertButton = null;

                // insert is a separate button
                if (actions.Contains(UserAction.Insert))
                {
                    insertButton = new _min.Models.Control(actPanel.panelId, "Insert", UserAction.Insert);
                    actions.Remove(UserAction.Insert);
                }

                // it is a NavTable
                if (NavControlType.SelectedValue.EndsWith("Table"))
                {
                    List <FK> neededFKs = (from FK fk in FKs where displayCols.Contains(fk.myColumn) select fk).ToList <FK>();
                    c = new NavTableControl(actPanel.panelId, new System.Data.DataTable(), mm.Stats.PKs[actPanel.tableName],
                                            neededFKs, actions);
                    c.displayColumns = displayCols;
                }
                else                                   // NavTree
                {
                    actions.Remove(UserAction.Delete); // cannot use delete in NavTrees
                    c = new TreeControl(actPanel.panelId, new HierarchyNavTable(), mm.Stats.PKs[actPanel.tableName][0],
                                        hierarchy.myColumn, displayCols[0], actions);
                }
                controls.Add(c);
                if (insertButton != null)
                {
                    controls.Add(insertButton);
                }


                foreach (_min.Models.Control listedControl in controls)
                {
                    listedControl.targetPanelId = actPanel.controls[0].targetPanelId;
                }

                MPanel resPanel = new MPanel(actPanel.tableName, actPanel.panelId,
                                             c is TreeControl ? PanelTypes.NavTree : PanelTypes.NavTable, new List <MPanel>(),
                                             new List <IField>(), controls, actPanel.PKColNames, null, actPanel.parent);
                resPanel.panelName = panelName;

                actPanel = resPanel;

                mm.SysDriver.BeginTransaction();
                mm.SysDriver.UpdatePanel(actPanel);
                mm.SysDriver.CommitTransaction();
                mm.SysDriver.IncreaseVersionNumber();
                ValidationResult.Items.Add("Saved");
                Response.Redirect(Page.Request.RawUrl);
            }
        }
Beispiel #2
0
        void CreateWebControlsForPanel(MPanel activePanel, System.Web.UI.WebControls.Panel containerPanel)
        {
            List <BaseValidator> validators = new List <BaseValidator>();

            validationSummary             = new ValidationSummary();
            validationSummary.BorderWidth = 0;
            MainPanel.Controls.Add(validationSummary);

            // no data in active panel => have to fill it
            if (!Page.IsPostBack || noSessionForActPanel)
            {
                if (CE.GlobalState == GlobalState.Architect)
                {
                    foreach (IField field in activePanel.fields)
                    {
                        field.InventData();
                    }
                    foreach (_min.Models.Control c in activePanel.controls)
                    {
                        c.InventData();
                    }
                }
                else
                {
                    mm.WebDriver.FillPanelFKOptions(activePanel);
                    if (activePanel.PK != null || activePanel.type != PanelTypes.Editable)
                    {
                        try
                        {
                            mm.WebDriver.FillPanel(activePanel);
                        }
                        catch (WebDriverDataModificationException me) {
                            // the row with the corresponding PK had been deleted in the meantime
                            _min.Common.ValidationError.Display(me.Message, Page);
                        }
                    }
                }
            }

            if (activePanel.type == PanelTypes.Editable)
            {
                // create a table with fields and captions tod display
                Table tbl = new Table();
                tbl.CssClass = "formTbl";

                foreach (IField f in activePanel.fields)
                {
                    if (activePanel.PK == null && !Page.IsPostBack)
                    {
                        f.Data = null;
                    }
                    //if (f.type == FieldTypes.Holder) throw new NotImplementedException("Holder fields not yet supported in UI");
                    TableRow  row         = new TableRow();
                    TableCell captionCell = new TableCell();
                    Label     caption     = new Label();
                    caption.Text = f.Caption;
                    captionCell.Controls.Add(caption);
                    row.Cells.Add(captionCell);

                    TableCell fieldCell = new TableCell();
                    System.Web.UI.WebControls.WebControl c = f.MyControl;
                    validators.AddRange(f.GetValidators());

                    foreach (BaseValidator v in validators)
                    {
                        this.Form.Controls.Add(v);
                    }

                    fieldCell.Controls.Add(c);
                    row.Cells.Add(fieldCell);
                    tbl.Rows.Add(row);
                }

                MainPanel.Controls.Add(tbl);
            }

            // add the Constrols
            foreach (_min.Models.Control control in activePanel.controls)
            {
                if (control is TreeControl)
                {
                    ((TreeControl)control).ToUControl(containerPanel, navigator.TreeHandler);
                }
                else if (control is NavTableControl)
                {        // it is a mere gridview of a summary panel
                    NavTableControl ntc = (NavTableControl)control;
                    ntc.ToUControl(containerPanel, new GridViewCommandEventHandler(GridCommandEventHandler), GridView_PageIndexChanging, GridView_Sorting);
                }
                else    // a simple Button or alike
                {
                    if ((control.action == UserAction.Update || control.action == UserAction.Delete) && Page.Request.QueryString.Count == 0)
                    {
                        continue;
                    }
                    control.ToUControl(containerPanel, (CommandEventHandler)UserActionCommandHandler);
                }
                // not GridViewCommandEventHandler
            }


            foreach (BaseValidator validator in validators)
            {
                MainPanel.Controls.Add(validator);
            }


            // set the webcontrols from the stored value (initially null)
            foreach (_min.Interfaces.IField f in activePanel.fields)
            {
                f.FillData();
            }
        }