예제 #1
0
        /// <summary>
        /// Saves a new contol to the database (must have null ID, which will be set to the AI from the database).
        /// </summary>
        /// <param name="control"></param>
        public void AddControl(Control control)
        {
            // fieldId = 0
            Dictionary<string, object> insertVals = new Dictionary<string, object>();

            insertVals["id_panel"] = control.panelId;
            insertVals["content"] = control.Serialize();
            if (!driver.IsInTransaction)
            {
                bool wasInTrans = driver.IsInTransaction;
                if(!wasInTrans) driver.BeginTransaction();
                driver.query("INSERT INTO controls", dbe.InsVals(insertVals));
                control.SetCreationId(driver.LastId());    // must be 0 in creation
                if(!wasInTrans) driver.CommitTransaction();
            }
            else
            {
                driver.query("INSERT INTO controls", dbe.InsVals(insertVals));
                control.SetCreationId(driver.LastId());    // must be 0 in creation
            }
            if (control is TreeControl)
            {
                SaveStroedHierarchyOfControl((TreeControl)control);
                TreeControl tc = control as TreeControl;
                if (tc.storedHierarchyData is HierarchyNavTable)
                {
                    DataSet ds = new DataSet();
                    if (tc.storedHierarchyData.DataSet != null)
                    {
                        tc.storedHierarchyData.DataSet.Relations.Clear();
                        tc.storedHierarchyData.DataSet.Tables.Clear();
                    }
                    ds.Tables.Add(tc.storedHierarchyData);
                    tc.storedHierarchyData.ChildRelations.Add(new DataRelation(CC.CONTROL_HIERARCHY_RELATION,
                    tc.storedHierarchyData.Columns["Id"], tc.storedHierarchyData.Columns["ParentId"], true));
                }
            }
        }
예제 #2
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);
            }
        }
예제 #3
0
 private void UpdateControl(Control control)
 {
     MemoryStream ms = new MemoryStream();
     DataContractSerializer ser = new DataContractSerializer(typeof(Control));
     ser.WriteObject(ms, control);
     driver.query("UPDATE controls SET content = ", Functions.StreamToString(ms), " WHERE id_control = ", control.controlId);
     if (control is TreeControl) {
         SaveStroedHierarchyOfControl((TreeControl)control);
     }
 }
예제 #4
0
 public void RemoveControl(Control control)
 {
     driver.query("DELETE FROM controls WHERE id_control = ", control.controlId);
     driver.query("DELETE FROM hierarchy_nav_tables WHERE id_control = ", control.controlId);
 }
예제 #5
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            // extract the data for fields from the table
            List <IField> fields = new List <IField>();
            int           i      = 1;

            Dictionary <DataColumn, Dictionary <string, object> > customs = new Dictionary <DataColumn, Dictionary <string, object> >();

            foreach (DataColumn col in mm.Stats.ColumnTypes[actPanel.tableName])
            {       // standard fields
                TableRow r = tbl.Rows[i++];
                if (!((CheckBox)r.Cells[1].Controls[0]).Checked)
                {
                    continue;
                }
                // label, present, type, valid, caption

                IColumnFieldFactory factory = factories[Int32.Parse(((DropDownList)r.Cells[2].Controls[0]).SelectedValue)];


                // cell 3 is there for FK display column dropList

                bool required = false;
                bool unique   = false;
                if (r.Cells[4].Controls.Count == 4)
                {
                    CheckBox reqChb = (CheckBox)r.Cells[4].Controls[1];
                    CheckBox uniChb = (CheckBox)r.Cells[4].Controls[3];
                    required = reqChb.Checked;
                    unique   = uniChb.Checked;
                }

                string caption = ((TextBox)r.Cells[5].Controls[0]).Text;
                if (caption == "")
                {
                    caption = null;
                }

                if (factory is ICustomizableColumnFieldFactory)
                {
                    customs[col]             = new Dictionary <string, object>();
                    customs[col]["factory"]  = factory.Clone();     // so that each field gets its factory even if there more custom fields of the same type
                    customs[col]["required"] = required;
                    customs[col]["unique"]   = unique;
                    customs[col]["caption"]  = caption;
                    continue;
                }

                IField newField;

                //PBPR

                // react to the changes to the displaycolumn for the FK
                if (col.ExtendedProperties.Contains("FK"))
                {
                    FK colFK = (FK)(col.ExtendedProperties["FK"]);
                    colFK.displayColumn          = ((DropDownList)(r.Cells[3].Controls[0])).SelectedValue;
                    col.ExtendedProperties["FK"] = colFK;
                }
                newField          = factory.Create(col);
                newField.Caption  = caption;
                newField.Required = required;
                if (newField is IColumnField)
                {
                    ((IColumnField)newField).Unique = unique;
                }
                fields.Add(newField);
            }

            i = 1;
            foreach (M2NMapping mapping in mappings)
            {                // mappings
                TableRow r = mappingsTbl.Rows[i++];
                // label, present, type (mappingType), valid (req?), caption
                if (!((CheckBox)r.Cells[1].Controls[0]).Checked)
                {
                    continue;
                }

                // must be mappingType...

                List <ValidationRules> rules = new List <ValidationRules>();
                // no validation for a mapping

                mapping.displayColumn = ((DropDownList)(r.Cells[3].Controls[0])).SelectedValue;

                string caption = ((TextBox)r.Cells[5].Controls[0]).Text;

                M2NMappingField m2nf = new M2NMappingField(mapping, caption);
                fields.Add(m2nf);
            }

            // crate a control for each checked action
            List <_min.Models.Control> controls = new List <_min.Models.Control>();           // controls

            bool          valid     = true;
            List <string> errorMsgs = new List <string>();

            if (actions.RetrieveStringData().Count == 0)
            {
                valid = false;
                errorMsgs.Add("Choose at least one action for the panel, please.");
            }

            foreach (string actionString in actions.RetrieveStringData())
            {
                _min.Models.Control c = new _min.Models.Control(0, actionString,
                                                                (UserAction)Enum.Parse(typeof(UserAction), actionString));
                c.targetPanel = actPanel.controls[0].targetPanel;

                c.targetPanelId = actPanel.controls[0].targetPanelId;       //  a miserable way to find out the target panel...really

                controls.Add(c);
            }

            MPanel resPanel = new MPanel(actPanel.tableName, actPanel.panelId, PanelTypes.Editable, new List <MPanel>(),
                                         fields, controls, actPanel.PKColNames, null, actPanel.parent);

            resPanel.panelName = panelName.Text;


            valid = valid && mm.Architect.checkPanelProposal(resPanel, out errorMsgs, customs);

            // validate the Panel using Architect`s validator - don`t edit PKs, unique columns must have the constraint, must contain all collumns except Nullable
            // and AI and more rules
            validationResult.Items.Clear();
            if (valid)
            {
                if (customs.Count == 0)
                {
                    validationResult.Items.Add(new ListItem("Valid"));

                    actPanel = resPanel;
                    mm.SysDriver.BeginTransaction();
                    mm.SysDriver.UpdatePanel(actPanel);
                    Session.Clear();
                    mm.SysDriver.IncreaseVersionNumber();
                    mm.SysDriver.CommitTransaction();

                    validationResult.Items.Add(new ListItem("Saved"));
                    Response.Redirect(Page.Request.RawUrl);
                }
                else
                {
                    Session["interPanel"] = resPanel;
                    Session["customs"]    = customs;
                    Response.RedirectToRoute("ArchitectEditEditableCustomRoute", new { projectName = CE.project.Name, panelId = actPanel.panelId });
                    // for the sake of unity (and SysDriver)
                }
            }
            else
            {
                foreach (string s in errorMsgs)
                {
                    validationResult.Items.Add(new ListItem(s));
                }
            }
        }
예제 #6
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            // extract the data for fields from the table
            List<IField> fields = new List<IField>();
            int i = 1;

            Dictionary<DataColumn, Dictionary<string, object>> customs = new Dictionary<DataColumn, Dictionary<string, object>>();

            foreach (DataColumn col in mm.Stats.ColumnTypes[actPanel.tableName])
            {       // standard fields
                TableRow r = tbl.Rows[i++];
                if (!((CheckBox)r.Cells[1].Controls[0]).Checked)
                    continue;
                // label, present, type, valid, caption

               IColumnFieldFactory factory = factories[Int32.Parse(((DropDownList)r.Cells[2].Controls[0]).SelectedValue)];

                // cell 3 is there for FK display column dropList

               bool required = false;
               bool unique = false;
                if(r.Cells[4].Controls.Count == 4){
                    CheckBox reqChb = (CheckBox)r.Cells[4].Controls[1];
                    CheckBox uniChb = (CheckBox)r.Cells[4].Controls[3];
                    required = reqChb.Checked;
                    unique = uniChb.Checked;
                }

                string caption = ((TextBox)r.Cells[5].Controls[0]).Text;
                if (caption == "") caption = null;

                if (factory is ICustomizableColumnFieldFactory)
                {
                    customs[col] = new Dictionary<string, object>();
                    customs[col]["factory"] = factory.Clone();      // so that each field gets its factory even if there more custom fields of the same type
                    customs[col]["required"] = required;
                    customs[col]["unique"] = unique;
                    customs[col]["caption"] = caption;
                    continue;
                }

                IField newField;

                //PBPR

                // react to the changes to the displaycolumn for the FK
                if (col.ExtendedProperties.Contains("FK")) {
                    FK colFK = (FK)(col.ExtendedProperties["FK"]);
                    colFK.displayColumn = ((DropDownList)(r.Cells[3].Controls[0])).SelectedValue;
                    col.ExtendedProperties["FK"] = colFK;
                }
                    newField = factory.Create(col);
                    newField.Caption = caption;
                    newField.Required = required;
                    if (newField is IColumnField)
                    {
                        ((IColumnField)newField).Unique = unique;
                    }
                fields.Add(newField);
            }

            i = 1;
            foreach (M2NMapping mapping in mappings)
            {                // mappings
                TableRow r = mappingsTbl.Rows[i++];
                // label, present, type (mappingType), valid (req?), caption
                if (!((CheckBox)r.Cells[1].Controls[0]).Checked)
                    continue;

                // must be mappingType...

                List<ValidationRules> rules = new List<ValidationRules>();
                // no validation for a mapping

                mapping.displayColumn = ((DropDownList)(r.Cells[3].Controls[0])).SelectedValue;

                string caption = ((TextBox)r.Cells[5].Controls[0]).Text;

                M2NMappingField m2nf = new M2NMappingField(mapping, caption);
                fields.Add(m2nf);
            }

            // crate a control for each checked action
            List<_min.Models.Control> controls = new List<_min.Models.Control>();           // controls

            bool valid = true;
            List<string> errorMsgs = new List<string>();
            if (actions.RetrieveStringData().Count == 0) {
                valid = false;
                errorMsgs.Add("Choose at least one action for the panel, please.");
            }

            foreach (string actionString in actions.RetrieveStringData())
            {
                    _min.Models.Control c = new _min.Models.Control(0, actionString,
                        (UserAction)Enum.Parse(typeof(UserAction), actionString));
                    c.targetPanel = actPanel.controls[0].targetPanel;

                    c.targetPanelId = actPanel.controls[0].targetPanelId;   //  a miserable way to find out the target panel...really

                    controls.Add(c);
            }

            MPanel resPanel = new MPanel(actPanel.tableName, actPanel.panelId, PanelTypes.Editable, new List<MPanel>(),
                fields, controls, actPanel.PKColNames, null, actPanel.parent);
            resPanel.panelName = panelName.Text;

            valid = valid && mm.Architect.checkPanelProposal(resPanel, out errorMsgs, customs);

            // validate the Panel using Architect`s validator - don`t edit PKs, unique columns must have the constraint, must contain all collumns except Nullable
            // and AI and more rules
            validationResult.Items.Clear();
            if (valid)
            {
                if (customs.Count == 0)
                {
                    validationResult.Items.Add(new ListItem("Valid"));

                    actPanel = resPanel;
                    mm.SysDriver.BeginTransaction();
                    mm.SysDriver.UpdatePanel(actPanel);
                    Session.Clear();
                    mm.SysDriver.IncreaseVersionNumber();
                    mm.SysDriver.CommitTransaction();

                    validationResult.Items.Add(new ListItem("Saved"));
                    Response.Redirect(Page.Request.RawUrl);
                }
                else {
                    Session["interPanel"] = resPanel;
                    Session["customs"] = customs;
                    Response.RedirectToRoute("ArchitectEditEditableCustomRoute", new {projectName = CE.project.Name, panelId = actPanel.panelId});
                        // for the sake of unity (and SysDriver)
                }
            }
            else
            {
                foreach (string s in errorMsgs)
                {
                    validationResult.Items.Add(new ListItem(s));
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Ignores mappings, displays first 4 columns in a classic NavTable 
        /// or the first display column in a NavTree if a self-referential FK is present.
        /// navtable includes edit and delete action buttons, second control - insert button
        /// </summary>
        /// <param name="tableName">string</param>
        /// <returns>Panel</returns>
        public Panel proposeSummaryPanel(string tableName)
        {
            DataColumnCollection cols = stats.ColumnTypes[tableName];
            List<FK> FKs = stats.FKs[tableName];
            // a table with more than one self-referential FK is improbable
            List<FK> selfRefs = new List<FK>(from FK in FKs where FK.myTable == FK.refTable select FK as FK);
            List<string> PKCols = stats.PKs[tableName];
            FK selfRefFK = null;
            // strict hierarchy structure validation - not nice => no Tree
            if (hierarchies.Contains(tableName))
                selfRefFK = selfRefs.First();
            List<string> displayColOrder = stats.ColumnsToDisplay[tableName];

            Control control;
            DataTable controlTab = new DataTable();

            List<Control> Controls = new List<Control>();
            if (selfRefFK != null)  // this will be a NavTree
            {
                Panel res = new Panel(tableName, 0, PanelTypes.NavTree, new List<Panel>(), new List<IField>(),
                    new List<Control>(), PKCols);
                res.displayAccessRights = 1;
                control = new TreeControl(0, new HierarchyNavTable(), PKCols[0], selfRefFK.myColumn,
                     displayColOrder[0], new List<UserAction> { UserAction.View });
                Controls.Add(control);
                control = new Control(0, null, PKCols, UserAction.Insert);
                Controls.Add(control);

                res.AddControls(Controls);
                return res;
            }
            else
            {       // a simple NavTable
                Panel res = new Panel(tableName, 0, PanelTypes.NavTable, new List<Panel>(), new List<IField>(),
                    new List<Control>(), PKCols);
                res.displayAccessRights = 1;
                List<UserAction> actions = new List<UserAction>(new UserAction[] { UserAction.View, UserAction.Delete });
                List<string> displayColumns = displayColOrder.GetRange(0, Math.Min(displayColOrder.Count, 4));
                List<FK> neededFKs = (from FK fk in FKs where displayColumns.Contains(fk.myColumn) select fk).ToList();

                control = new NavTableControl(0, null, PKCols, neededFKs, actions);

                control.displayColumns = displayColumns;
                Controls.Add(control);
                control = new Control(0, null, PKCols, UserAction.Insert);
                Controls.Add(control);

                res.AddControls(Controls);
                return res;
            }
        }
예제 #8
0
        protected void Page_Init(object sender, EventArgs e)
        {
            ValidationResult.Items.Clear();
            mm = (MinMaster)Master;

            string projectName = Page.RouteData.Values["projectName"] as string;
            int    panelId     = Int32.Parse(Page.RouteData.Values["panelId"] as string);

            actPanel = mm.SysDriver.Panels[panelId];
            DataColumnCollection cols = mm.Stats.ColumnTypes[actPanel.tableName];

            PanelName.Text = actPanel.panelName;
            _min.Models.Control control = actPanel.controls.Where(x => x is NavTableControl || x is TreeControl).First();
            FKs = mm.Stats.FKs[actPanel.tableName];
            List <string> colNames = (from DataColumn col in cols select col.ColumnName).ToList <string>();

            // a M2NControl to select the columns of the table displayed in the GridView - for a tree we take only the first item
            DisplayCols.SetOptions(colNames);
            DisplayCols.SetIncludedOptions(control.displayColumns);

            // what actions can be triggered from the navigation control
            List <string> possibleAcitons = new List <string>(new string[] { UserAction.Insert.ToString(), UserAction.View.ToString(),
                                                                             UserAction.Delete.ToString() });
            List <UserAction> originalActions = new List <UserAction>();

            if (control is NavTableControl)
            {
                foreach (UserAction ua in ((NavTableControl)control).actions)
                {
                    originalActions.Add(ua);
                }
            }
            else
            {
                foreach (UserAction ua in ((TreeControl)control).actions)
                {
                    originalActions.Add(ua);
                }
            }


            // if the panel contains a NavTable or TreeControl, it is the only control of a complex type and other controls therefore must be
            // simple buttons.
            foreach (_min.Models.Control simpleControl in actPanel.controls)
            {
                if (simpleControl == control)
                {
                    continue;
                }
                originalActions.Add(simpleControl.action);
            }

            List <string> originalActionStrings = new List <string>();

            foreach (UserAction a in originalActions)
            {
                originalActionStrings.Add(a.ToString());
            }

            actionsControl.SetOptions(possibleAcitons);
            actionsControl.SetIncludedOptions(originalActionStrings);


            hierarchy = mm.Stats.SelfRefFKs().Find(x => x.myTable == actPanel.tableName);
            string[] CTypeOptions = hierarchy == null ? new string[] { "Navigation Table" } :
            new string[] { "Navigation Table", "Navigation Tree" };
            // a radio button list - contains navtable and maybe treeview option
            NavControlType.DataSource = CTypeOptions;
            NavControlType.DataBind();
            // let the default be the current
            if (control is TreeControl)
            {
                NavControlType.SelectedIndex = 1;
            }
            else
            {
                NavControlType.SelectedIndex = 0;
            }

            BackButton.PostBackUrl = BackButton.GetRouteUrl("ArchitectShowRoute", new { projectName = projectName });
        }
예제 #9
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);
            }
        }