コード例 #1
0
 /// <summary>
 /// updates the db row identified by the panel PK, using data from panel fields
 /// </summary>
 /// <param name="panel"></param>
 // TODO : row PK cannot change once created!
 public void UpdatePanel(Panel panel)
 {
     CheckAgainstOriginalDataRow(panel);
     foreach (IField f in panel.fields)
     {
         if (f is IColumnField)
         {
             IColumnField cf = (IColumnField)f;
             if (cf.Unique && panel.RetrievedManagedData[cf.ColumnName] != null)       // TODO make sure all fields are set to null when should be
             {
                 bool unique = driver.CheckUniqueness(panel.tableName, cf.ColumnName, panel.RetrievedManagedData[cf.ColumnName], panel.PK);
                 if (!unique)
                 {
                     throw new ConstraintException("Field \"" + cf.Data + "\" is restrained to be unique and \""
                                                   + cf.Data.ToString() + "\" is already present");
                 }
             }
         }
     }
     foreach (DataColumn PKcol in panel.PK.Table.Columns)    // row PK midified
     {
         if (panel.PK[PKcol.ColumnName].ToString() != panel.RetrievedManagedData[PKcol.ColumnName].ToString())
         {
             throw new WebDriverValidationException("The field '" + PKcol.ColumnName +
                                                    "' is a part of the item`s identity and cannot be changed unless the item is recreated.");
         }
     }
     try
     {
         driver.BeginTransaction();
         int affected = driver.query("UPDATE " + panel.tableName + " SET ", dbe.UpdVals(panel.RetrievedInsertData), " WHERE ", dbe.Condition(panel.PK));
         if (affected > 1)
         {
             driver.RollbackTransaction();
             throw new Exception("Panel PK not unique, trying to update multiple rows at a time!");
         }
         driver.CommitTransaction();
     }
     catch (ConstraintException ce) {
         driver.RollbackTransaction();
         throw new ConstraintException(FriendlyConstraintException(ce.Message, panel), null);
     }
     foreach (IField f in panel.fields)
     {
         if (f is M2NMappingField)
         {
             M2NMappingField m2nf = (M2NMappingField)f;
             int             ID   = (int)panel.PK[m2nf.Mapping.myColumn];
             UnmapM2NMappingKey(m2nf.Mapping, ID);
             MapM2NVals(m2nf.Mapping, ID, (List <int>)m2nf.Data);
         }
     }
 }
コード例 #2
0
        public void UpdateProduct(IColumnField field)
        {
            if (!(field is ImageField))
            {
                throw new ArgumentException();
            }
            ImageField imf = (ImageField)field;

            imf.MainDirectory  = mainPath;
            imf.ThumbDirectory = thumbPath;
            imf.FullWidth      = fullWidth;
            imf.ThumbWidth     = thumbWidth;
        }
コード例 #3
0
        public void LoadProduct(IColumnField field)
        {
            if (!(field is ImageField))
            {
                throw new ArgumentException();
            }
            ImageField imf = (ImageField)field;

            mainPath     = imf.MainDirectory;
            thumbPath    = imf.ThumbDirectory;
            fullWidth    = imf.FullWidth;
            thumbWidth   = imf.ThumbWidth;
            targetFormat = imf.TargetFormat;
            useThubs     = thumbPath != null;
            FillFields();
        }
コード例 #4
0
        /// <summary>
        /// inserts a new row into the table managed by the panel, with the vlaues stored in it`s fields, also inserts in mapping tables
        /// </summary>
        /// <param name="panel"></param>
        /// <returns></returns>
        public int InsertIntoPanel(Panel panel)
        {
            foreach (IField f in panel.fields)
            {
                if (f is IColumnField)
                {
                    IColumnField cf = (IColumnField)f;
                    if (panel.RetrievedManagedData[cf.ColumnName] != null && cf.Unique)
                    {
                        bool unique = driver.CheckUniqueness(panel.tableName, cf.ColumnName, panel.RetrievedManagedData[cf.ColumnName]);
                        if (!unique)
                        {
                            throw new ConstraintException("Field \"" + cf.Caption + "\" is restrained to be unique and \""
                                                          + cf.Data.ToString() + "\" is already present");
                        }
                    }
                }
            }
            int ID;

            try
            {
                driver.BeginTransaction();
                driver.query("INSERT INTO ", dbe.Table(panel.tableName), dbe.InsVals(panel.RetrievedInsertData));
                ID = driver.LastId();      // TODO safe? Does transaction ensure insert separation?
                driver.CommitTransaction();
            }
            catch (MySql.Data.MySqlClient.MySqlException mye) {
                // Can occur, if there is a unique Key on multiple columns - such constraint cannot be set in panel management
                // (very rare indeed). The exception is attached a user-friendly comment and bubbles to the Show.cs, where
                // it will be displayed as a standard validation error (but probably with a notable delay).

                // will already be out of transaction - BaseDriver closes it immediately
                //if(IsInTransaction)
                //    driver.RollbackTransaction();
                throw new ConstraintException(FriendlyConstraintException(mye.Message, panel), null);
            }
            foreach (IField f in panel.fields)
            {
                if (f is M2NMappingField)
                {
                    M2NMappingField m2nf = (M2NMappingField)f;
                    MapM2NVals(m2nf.Mapping, ID, (List <int>)m2nf.Data);
                }
            }
            return(ID);
        }
コード例 #5
0
        /// <summary>
        /// each custom field has its ICustomizableColumnFieldFactory, which will read the form, validate it,
        /// report errors or modify the ICustomizableField object accordingly.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            bool valid = true;

            validationResult.Items.Clear();
            foreach (Dictionary <string, object> colSettings in customs.Values)
            {
                var factory = (ICustomizableColumnFieldFactory)colSettings["factory"];
                factory.ValidateForm();
                if (factory.ErrorMessage != null)
                {
                    validationResult.Items.Add(factory.ErrorMessage);
                    valid = false;
                }
            }
            if (valid)
            {
                List <IField> customizedFields = new List <Interfaces.IField>();
                foreach (DataColumn col in customs.Keys)
                {
                    var factory = (ICustomizableColumnFieldFactory)customs[col]["factory"];

                    IColumnField field = factory.Create(col);
                    field.Required = (bool)customs[col]["required"];
                    field.Unique   = (bool)customs[col]["unique"];
                    field.Caption  = (string)customs[col]["caption"];
                    customizedFields.Add(field);
                }
                interPanel.AddFields(customizedFields);

                validationResult.Items.Add(new ListItem("Valid"));

                // finally save the new panel
                mm.SysDriver.BeginTransaction();
                mm.SysDriver.UpdatePanel(interPanel);
                Session.Clear();
                mm.SysDriver.IncreaseVersionNumber();
                mm.SysDriver.CommitTransaction();

                validationResult.Items.Add(new ListItem("Saved"));
                Response.RedirectToRoute("ArchitectEditEditableRoute", new { projectName = mm.ProjectName, panelId = interPanel.panelId });
            }
        }
コード例 #6
0
        /// <summary>
        /// each custom field will get a cell in the main table containing a WebControls.Panel, into which it can display its customization form.
        /// Each customizable field is associated with a factory of corresponding type, which will load its properties and fill the fields of the customization form.
        /// The factory is also resposible for displaying and validating the form.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Init(object sender, EventArgs e)
        {
            mm         = (MinMaster)Master;
            interPanel = (MPanel)Session["interPanel"];
            // the custom fields have the basic settings alreadyu saved in the session - now only the custom parts will be configured.
            customs = (Dictionary <DataColumn, Dictionary <string, object> >)Session["customs"];
            backButton.PostBackUrl = backButton.GetRouteUrl("ArchitectEditEditableRoute", new { projectName = mm.ProjectName, panelId = interPanel.panelId });
            Table customSettingsTbl = new Table();


            foreach (DataColumn customCol in customs.Keys)
            {
                TableRow  captionRow  = new TableRow();
                TableCell captionCell = new TableCell();
                captionCell.Text = customCol.ColumnName;
                captionRow.Cells.Add(captionCell);
                customSettingsTbl.Rows.Add(captionRow);

                TableRow  settingsRow  = new TableRow();
                TableCell settingsCell = new TableCell();
                WPanel    container    = new WPanel();
                var       factory      = (ICustomizableColumnFieldFactory)customs[customCol]["factory"];
                if (!Page.IsPostBack)
                {
                    MPanel       oldPanel   = mm.SysDriver.Panels[interPanel.panelId];
                    IColumnField oldVersion = (IColumnField)(from f in oldPanel.fields
                                                             where f.GetType() == factory.ProductionType &&
                                                             ((IColumnField)f).ColumnName == customCol.ColumnName
                                                             select f).FirstOrDefault <IField>();
                    if (oldVersion != null)
                    {
                        factory.LoadProduct((IColumnField)oldVersion);
                    }
                }
                factory.ShowForm(container);
                settingsCell.Controls.Add(container);
                settingsRow.Controls.Add(settingsCell);
                customSettingsTbl.Rows.Add(settingsRow);
            }

            MainPanel.Controls.Add(customSettingsTbl);
        }
コード例 #7
0
        /// <summary>
        /// Fills panel with data based on the columns included and possibly the Primary Key
        /// </summary>
        /// <param name="panel"></param>
        public void FillPanel(Panel panel)
        {
            if (panel.fields.Count() > 0)
            { // editable Panel, fetch the DataRow, simple controls - must have unique PK
                var       columns = panel.fields.Where(x => x is IColumnField).Select(x => ((IColumnField)x).ColumnName).ToList <string>();
                DataTable table   = driver.fetchAll("SELECT ", dbe.Cols(columns), " FROM ", panel.tableName, "WHERE", dbe.Condition(panel.PK));
                if (table.Rows.Count > 1)
                {
                    throw new Exception("PK is not unique");
                }
                if (table.Rows.Count == 0)
                {
                    throw new WebDriverDataModificationException(
                              "No data fulfill the condition. The record may have been removed.");
                }
                DataRow row = table.Rows[0];
                panel.OriginalData = table.Rows[0];

                foreach (IField field in panel.fields)       // fill the fields
                {
                    if (field is IColumnField)
                    {        // value
                        IColumnField cf = (IColumnField)field;
                        cf.Data = row[cf.ColumnName].GetType() != typeof(MySql.Data.Types.MySqlDateTime) ? row[cf.ColumnName] :
                                  ((MySql.Data.Types.MySqlDateTime)row[cf.ColumnName]).GetDateTime();
                    }
                    else
                    {           // mapping values are yet to fetch
                        M2NMappingField m2nf = (M2NMappingField)field;
                        m2nf.Data = FetchMappingValues(m2nf.Mapping, (int)panel.PK[0]);
                    }
                }
            }

            foreach (Control c in panel.controls)
            {
                if (c is NavTableControl)
                {
                    AssignDataForNavTable((NavTableControl)c, false);
                }
                // always gets the whole table, save in session
                else if (c is TreeControl && c.data is DataTable)
                {   // there are no data in storedHierarchy - that is only the case of menu in base panel - fill it
                    TreeControl tc = (TreeControl)c;
                    tc.data.DataSet.EnforceConstraints = false;
                    tc.data.Rows.Clear();
                    HierarchyNavTable hierarchy = (HierarchyNavTable)(tc.data);

                    List <IDbCol> selectCols = new List <IDbCol>();
                    // don`t need to use constants - the column names are set in HierarchNavTable
                    DataTable fetched = driver.fetchAll("SELECT",
                                                        dbe.Col(tc.PKColNames[0], "Id"), ",",
                                                        dbe.Cols(selectCols), dbe.Col(tc.parentColName, "ParentId"), ",",
                                                        "CAST(", dbe.Col(tc.displayColName), "AS CHAR) AS \"Caption\"", ",",
                                                        dbe.Col(tc.PKColNames[0], "NavId"),
                                                        "FROM", panel.tableName);


                    hierarchy.Merge(fetched);
                    tc.data.DataSet.EnforceConstraints = true;
                }
            }

            /*
             * foreach (Panel p in panel.children)
             *  FillPanel(p);
             */
        }
コード例 #8
0
        /// <summary>
        /// propose the editable panel for a table, if table will probably not be self-editable
        /// (such as an M2N mapping), return null
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns>Panel (or null)</returns>
        public Panel ProposeForTable(string tableName)
        {
            // don`t care for indexes for now

            DataColumnCollection cols   = stats.ColumnTypes[tableName];
            List <FK>            FKs    = stats.FKs[tableName];
            List <string>        PKCols = stats.PKs[tableName];

            List <IField> fields = new List <IField>();


            foreach (M2NMapping mapping in mappings)    // find mappings related to this table
            {
                if (mapping.myTable != tableName)
                {
                    continue;
                }
                List <string> displayColOrder = stats.ColumnsToDisplay[mapping.refTable];
                mapping.displayColumn = displayColOrder[0];
                fields.Add(new M2NMappingField(mapping, "Mapping " + mapping.myTable + " to " + mapping.refTable));
            }

            List <IColumnFieldFactory> factories = (List <IColumnFieldFactory>)(System.Web.HttpContext.Current.Application["ColumnFieldFactories"]);

            foreach (DataColumn col in cols)
            {
                if (col.AutoIncrement)
                {
                    continue;
                }
                IColumnFieldFactory leadingFactory = (from f in factories
                                                      where f.CanHandle(col) && !(f is ICustomizableColumnFieldFactory)
                                                      orderby f.Specificity descending
                                                      select f).FirstOrDefault();
                if (leadingFactory == null && !col.AllowDBNull)
                {
                    return(null);
                }
                IColumnField field = leadingFactory.Create(col);
                field.Required = !col.AllowDBNull;
                field.Unique   = col.Unique;
                fields.Add(field);
            }

            PropertyCollection controlProps = new PropertyCollection();
            PropertyCollection viewProps    = new PropertyCollection();
            string             panelName    = tableName + " Editation";

            List <Control> controls = new List <Control>();

            // all the controls
            controls.Add(new Control(0, UserAction.Insert.ToString(), UserAction.Insert));
            controls.Add(new Control(0, UserAction.Update.ToString(), UserAction.Update));
            controls.Add(new Control(0, UserAction.Update.ToString(), UserAction.Delete));

            List <Control> controlsAsControl = new List <Control>(controls);

            Panel res = new Panel(tableName, 0, PanelTypes.Editable,
                                  new List <Panel>(), fields, controlsAsControl, PKCols);

            return(res);
        }
コード例 #9
0
        /// <summary>
        /// checks if edited fields exist in webDB and their types are adequate, checks constraints on FKs and mapping tables,
        /// also checks if controls` dataTables` columns exist and everything that has to be inserted in DB is a required field,
        /// whether attributes don`t colide and every panel has something to display.
        /// </summary>
        /// <param name="proposalPanel"></param>
        /// <param name="recursive">run itself on panel children</param>
        /// <returns>true if no errors were found, true otherwise</returns>
        public bool checkPanelProposal(Panel proposalPanel, out List <string> errorMsgs, Dictionary <DataColumn, Dictionary <string, object> > customs)
        // non-recursive checking after the initial check - after panel modification
        {
            errorMsgs = new List <string>();

            DataColumnCollection cols = stats.ColumnTypes[proposalPanel.tableName];

            List <FK>         FKs      = stats.FKs[proposalPanel.tableName];
            List <M2NMapping> mappings = stats.Mappings[proposalPanel.tableName];

            bool good = true;

            if (proposalPanel.type == PanelTypes.Editable)
            // this is indeed the only panelType containing fields => only editable
            {
                foreach (IField field in proposalPanel.fields)
                {
                    if (!(field is IColumnField))
                    {
                        continue;                            // M2Ns are OK - strict UI
                    }
                    IColumnField cf = (IColumnField)field;
                    string       messageBeginning = "Column " + cf.ColumnName + " managed by field " + cf.Caption + " ";
                    if (!(cols.Contains(cf.ColumnName)))
                    {
                        errorMsgs.Add(messageBeginning + "does not exist in table");
                        good = false;
                    }
                    else
                    {
                        if (!(cf is FKField))                               // NavTable won`t be edited in the panel
                        {
                            if (cols[cf.ColumnName].AllowDBNull == false && // things that have to be filled in must be required
                                !cols[cf.ColumnName].AutoIncrement &&
                                !(cf is CheckboxField) &&
                                !cf.Required)
                            {
                                errorMsgs.Add(messageBeginning
                                              + "cannot be set to null, but the coresponding field is not required");
                                good = false;
                            }

                            // PBPR

                            // other validation requirements will be fullfilled based on the field type - the panel editation GUI will not let the user
                            // select a field type that is inconsistent with the column datatype

                            if (cols[cf.ColumnName].Unique && !cf.Unique)
                            {
                                errorMsgs.Add(messageBeginning + " is constrained to be unique, but the corresponding field does not have "
                                              + "the \"Unique\" validation rule set.");
                                good = false;
                            }
                            else if (cf.Unique && !cols[cf.ColumnName].Unique)      // require uniqueness that is not guaranteed by the database
                            {
                                IBaseDriver tmpBaseDriver = null;
                                switch (CE.project.ServerType)
                                {
                                case DbServer.MySql:
                                    tmpBaseDriver = new BaseDriverMySql(CE.project.ConnstringWeb);
                                    break;

                                case DbServer.MsSql:
                                    tmpBaseDriver = new BaseDriverMsSql(CE.project.ConnstringWeb);
                                    break;

                                default:
                                    break;
                                }
                                bool truelyUnique = tmpBaseDriver.CheckUniquenessManually(proposalPanel.tableName, cf.ColumnName);
                                if (!truelyUnique)
                                {
                                    errorMsgs.Add(String.Format("{0} is not unique in its values - the constraint cannot be enforced.", messageBeginning));
                                    good = false;
                                }
                            }
                        }
                    }
                }

                // Columns that are not covered and should be - allowdbnull is false, they do not have any default value
                // and are not AutoIncrements and none of the fields refers to them.
                var colsx = stats.ColumnTypes[proposalPanel.tableName];
                IEnumerable <string> requiredColsMissing = from DataColumn col in stats.ColumnTypes[proposalPanel.tableName]
                                                           where col.AllowDBNull == false && col.AutoIncrement == false &&
                                                           (col.DefaultValue == null || col.DefaultValue == DBNull.Value) &&
                                                           !proposalPanel.fields.Exists(x => x is IColumnField && ((IColumnField)x).ColumnName == col.ColumnName) &&
                                                           (!customs.ContainsKey(col) || (bool)customs[col]["required"] == false)
                                                           select col.ColumnName;

                // if the colum is contained in customs, only the custom factory validation will be left
                //so this validation does not need to be called again

                foreach (string missingCol in requiredColsMissing)
                {
                    good = false;
                    errorMsgs.Add("Column " + missingCol + " cannot be NULL and has no default value." +
                                  " It must therefore be included in the panel");
                }
                if (proposalPanel.panelName == "")
                {
                    errorMsgs.Add("Does this panel not deserve a name?");
                    good = false;
                }

                if (proposalPanel.controls.Count == 0)
                {
                    errorMsgs.Add("A panel with no controls would be useless...");
                }
            }
            else
            {
                throw new Exception("Validation-non editable panel as an editable one.");
            }


            return(good);
        }
コード例 #10
0
        /// <summary>
        /// collects data from its fields and fillst them into a DataRow so that it is prepared for being passed to the database driver for UPDATE / INSERT commands
        /// </summary>
        public void RetrieveDataFromFields()
        {
            // form two tables to match the structure of data included in the fields

            // one suitable for update commands
            DataTable tbl = new DataTable();

            // one for inserts (does not contain AI ...)
            DataTable insTbl = new DataTable();

            if (PK != null)
            {
                foreach (DataColumn col in PK.Table.Columns)
                {
                    tbl.Columns.Add(new DataColumn(col.ColumnName, col.DataType));
                }
            }
            foreach (IField f in fields)
            {
                if (!(f is IColumnField))
                {
                    continue;
                }
                IColumnField cf = f as IColumnField;
                if (cf.Data != null && cf.Data != DBNull.Value)
                {
                    // do not create  duplicities - if the column is a part of the primary key, do not add it to the update table again.
                    // Moreover, the PK of a record should not change
                    if (PK == null || !PK.Table.Columns.Contains(cf.ColumnName))
                    {
                        tbl.Columns.Add(new DataColumn(cf.ColumnName, cf.Data.GetType()));
                    }
                    insTbl.Columns.Add(new DataColumn(cf.ColumnName, cf.Data.GetType()));
                }
                else
                {
                    // columns without value vill be passed as ints - it will not matter in the end as the command will be concatenated from string parts
                    if (PK == null || !PK.Table.Columns.Contains(cf.ColumnName))
                    {
                        tbl.Columns.Add(new DataColumn(cf.ColumnName, typeof(int)));
                    }
                    insTbl.Columns.Add(new DataColumn(cf.ColumnName, typeof(int)));
                }
            }

            // create DataRows from these new tables
            RetrievedManagedData = tbl.NewRow();
            RetrievedInsertData  = insTbl.NewRow();
            if (PK != null)
            {
                // add the PK finally
                foreach (DataColumn col in PK.Table.Columns)
                {
                    RetrievedManagedData[col.ColumnName] = PK[col.ColumnName];
                }
            }

            // fill the DataRows with data
            foreach (IField f in fields)
            {
                if (!(f is IColumnField))
                {
                    continue;
                }
                IColumnField cf = f as IColumnField;
                if (cf.Data != null && (cf.Data.ToString() != ""))      // dangerous?
                {
                    RetrievedManagedData[cf.ColumnName] = cf.Data;
                    RetrievedInsertData[cf.ColumnName]  = cf.Data;
                }
                else
                {
                    RetrievedManagedData[cf.ColumnName] = DBNull.Value;
                    RetrievedInsertData[cf.ColumnName]  = DBNull.Value;
                }
            }
        }
コード例 #11
0
ファイル: EditEditable.aspx.cs プロジェクト: radtek/Webmin
        protected void Page_Init(object sender, EventArgs e)
        {
            mm        = (MinMaster)Master;
            factories = (List <IColumnFieldFactory>)Application["ColumnFieldFactories"];

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

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

            // the field types - default and special subsets allowed for special data types - i.e. a foereign key cannot be edited via nothing but
            // a FKFiels
            string[] fieldTypes = new string[] { FieldTypes.ShortText.ToString(), FieldTypes.Bool.ToString(),
                     FieldTypes.Date.ToString(), FieldTypes.DateTime.ToString(), FieldTypes.Text.ToString() };
            string[] EnumType        = new string[] { FieldTypes.Enum.ToString() };
            string[] FKtype          = new string[] { FieldTypes.FK.ToString() };
            string[] mappingType     = new string[] { FieldTypes.M2NMapping.ToString() };
            string[] validationRules = Enum.GetNames(typeof(ValidationRules));

            //possible bugpoing (see repo)

            // a  FKField can be only required - let referential integrity take care of the rest
            string[] requiredRule = new string[] { Enum.GetName(typeof(ValidationRules), ValidationRules.Required) };
            FKs      = mm.Stats.FKs[actPanel.tableName];
            mappings = new List <M2NMapping>();
            mappings = mm.Stats.Mappings[actPanel.tableName];

            panelName.Text = actPanel.panelName;

            // create a datarow for each column, specifiing...
            foreach (DataColumn col in cols)            // std. fields (incl. FKs)

            {
                IColumnField cf = (IColumnField)actPanel.fields.Find(x => x is IColumnField && ((IColumnField)x).ColumnName == col.ColumnName);

                TableRow r = new TableRow();
                r.ID = col.ColumnName;

                //...the name,...
                TableCell nameCell  = new TableCell();
                Label     nameLabel = new Label();
                nameLabel.Text = col.ColumnName;
                nameCell.Controls.Add(nameLabel);
                r.Cells.Add(nameCell);

                //...whether the column will be accessible to editation at all,...
                TableCell presentCell = new TableCell();
                CheckBox  present     = new CheckBox();
                present.Checked = cf != null;
                presentCell.Controls.Add(present);
                r.Cells.Add(presentCell);


                FK fk = FKs.Find(x => x.myColumn == col.ColumnName);
                if (cf != null && cf is FKField)
                {
                    fk = ((FKField)cf).FK;
                }
                //...the FieldType,...
                TableCell                typeCell    = new TableCell();
                DropDownList             dl          = new DropDownList();
                Dictionary <int, string> typeOptions = new Dictionary <int, string>();

                int current = -1;
                for (int i = 0; i < factories.Count; i++)
                {
                    if (factories[i].CanHandle(col))
                    {
                        typeOptions.Add(i, factories[i].UIName);
                    }
                    if (cf != null && cf.GetType() == (factories[i].ProductionType))
                    {
                        current = typeOptions.Count - 1;
                    }
                }

                dl.DataSource     = typeOptions;
                dl.DataValueField = "Key";
                dl.DataTextField  = "Value";
                dl.DataBind();

                dl.SelectedIndex = current;
                typeCell.Controls.Add(dl);
                r.Cells.Add(typeCell);

                //...what column of the referred table to display in the dropdown
                TableCell FKDisplayCell = new TableCell();
                // set default value if the field was originally present in the editation form
                if (fk != null)
                {
                    DropDownList fkddl = new DropDownList();
                    fkddl.DataSource = mm.Stats.ColumnsToDisplay[fk.refTable];
                    fkddl.DataBind();
                    if (cf != null)
                    {
                        fkddl.SelectedIndex = fkddl.Items.IndexOf(fkddl.Items.FindByValue(((FKField)cf).FK.displayColumn));
                    }
                    FKDisplayCell.Controls.Add(fkddl);
                }
                r.Cells.Add(FKDisplayCell);

                //PBPR

                //...the validation rules...
                TableCell validCell = new TableCell();

                CheckBox requiredCb    = new CheckBox();
                Label    requiredlabel = new Label();
                requiredlabel.Text = "required ";
                CheckBox uniCheck = new CheckBox();
                Label    uniLabel = new Label();
                uniLabel.Text = "unique";

                if (cf != null)
                {
                    requiredCb.Checked = cf.Required;
                    uniCheck.Checked   = cf.Unique;
                }

                if (!(cf is CheckBoxField))
                {
                    validCell.Controls.Add(requiredlabel);
                    validCell.Controls.Add(requiredCb);
                    validCell.Controls.Add(uniLabel);
                    validCell.Controls.Add(uniCheck);
                }

                r.Cells.Add(validCell);

                //...and the caption
                TableCell captionCell = new TableCell();
                TextBox   caption     = new TextBox();
                captionCell.Controls.Add(caption);
                r.Cells.Add(captionCell);

                if (cf != null)
                {
                    caption.Text = cf.Caption;
                }
                // index 6

                tbl.Rows.Add(r);
            }


            // mappings will get a similiar table, but some collumns (like validation) will just be left empty
            foreach (M2NMapping mapping in mappings)
            {
                M2NMappingField f = actPanel.fields.Find(
                    x => x is M2NMappingField && ((M2NMappingField)x).Mapping.myColumn == mapping.myColumn) as M2NMappingField;

                TableRow r = new TableRow();

                TableCell nameCell  = new TableCell();
                Label     nameLabel = new Label();
                nameLabel.Text = mapping.myTable + " to " + mapping.refTable + " via " + mapping.mapTable;
                nameCell.Controls.Add(nameLabel);
                r.Cells.Add(nameCell);

                TableCell presentCell = new TableCell();
                CheckBox  present     = new CheckBox();
                present.Checked = f != null;
                presentCell.Controls.Add(present);
                r.Cells.Add(presentCell);

                TableCell    typeCell = new TableCell();
                DropDownList dl       = new DropDownList();
                dl.DataSource = mappingType;
                dl.DataBind();
                typeCell.Controls.Add(dl);
                r.Cells.Add(typeCell);

                TableCell    displayCell = new TableCell();
                DropDownList displayDrop = new DropDownList();
                displayDrop.DataSource = mm.Stats.ColumnsToDisplay[mapping.refTable];
                displayDrop.DataBind();
                if (f != null)
                {
                    displayDrop.SelectedIndex = displayDrop.Items.IndexOf(displayDrop.Items.FindByValue(f.Mapping.displayColumn));
                }
                displayCell.Controls.Add(displayDrop);
                r.Cells.Add(displayCell);

                TableCell validCell = new TableCell();  // leave it empty
                r.Cells.Add(validCell);


                TableCell captionCell = new TableCell();
                TextBox   caption     = new TextBox();
                captionCell.Controls.Add(caption);
                r.Cells.Add(captionCell);

                if (f != null)
                {
                    caption.Text = f.Caption;
                }

                mappingsTbl.Rows.Add(r);
            }

            // what can be done with the panel
            string[] actionTypes = new string[] { UserAction.Insert.ToString(),
                     UserAction.Update.ToString(),
                     UserAction.Delete.ToString() };                  // controls
            List <string> activeActions = (from _min.Models.Control control in actPanel.controls
                                           select Enum.GetName(typeof(UserAction), control.action)).ToList <string>();

            actions.SetOptions(new List <string>(actionTypes));
            actions.SetIncludedOptions(activeActions);

            backButton.PostBackUrl = backButton.GetRouteUrl("ArchitectShowRoute", new { projectName = mm.ProjectName });
        }
コード例 #12
0
ファイル: ImageField.cs プロジェクト: rjankovic/webminVS2010
 public void UpdateProduct(IColumnField field)
 {
     if (!(field is ImageField))
         throw new ArgumentException();
     ImageField imf = (ImageField)field;
     imf.MainDirectory = mainPath;
     imf.ThumbDirectory = thumbPath;
     imf.FullWidth = fullWidth;
     imf.ThumbWidth = thumbWidth;
 }
コード例 #13
0
ファイル: ImageField.cs プロジェクト: rjankovic/webminVS2010
 public void LoadProduct(IColumnField field)
 {
     if (!(field is ImageField))
         throw new ArgumentException();
     ImageField imf = (ImageField)field;
     mainPath = imf.MainDirectory;
     thumbPath = imf.ThumbDirectory;
     fullWidth = imf.FullWidth;
     thumbWidth = imf.ThumbWidth;
     targetFormat = imf.TargetFormat;
     useThubs = thumbPath != null;
     FillFields();
 }