コード例 #1
0
        /// <summary>
        /// Saves the panel to the system database, but doesn`t save the filds / controls (so that they can be saved in "next wave", after the panel ID is known
        /// and the the control target panel can be bound to the new panel via this ID
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="recursive"></param>
        private void AddPanelOnly(Panel panel, bool recursive = true)
        {
            Dictionary <string, object> insertVals = new Dictionary <string, object>();

            insertVals["content"]    = panel.Serialize();
            insertVals["id_project"] = CE.project.Id;
            if (panel.parent != null)
            {
                insertVals["id_parent"] = panel.parent.panelId;
            }
            if (!driver.IsInTransaction)
            {
                driver.BeginTransaction();
                driver.query("INSERT INTO", dbe.Table("panels"), dbe.InsVals(insertVals));
                panel.SetCreationId(driver.LastId());
                driver.CommitTransaction();
            }
            else
            {
                driver.query("INSERT INTO", dbe.Table("panels"), dbe.InsVals(insertVals));
                panel.SetCreationId(driver.LastId());
            }
            if (recursive)
            {
                foreach (Panel child in panel.children)
                {
                    AddPanelOnly(child);
                }
            }
        }
コード例 #2
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);
        }