コード例 #1
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);
        }
コード例 #2
0
        // use only through FullProject load, if there is no panel in session or project version has changed
        #region Deserialization

        /// <summary>
        /// loads the whole project from database (in 3 queries)
        /// </summary>
        public void FullProjectLoad()
        {
            Panels = new Dictionary <int, Panel>();

            driver.BeginTransaction();
            FK        control_panel = new FK("controls", "id_panel", "panels", "id_panel", null);
            FK        field_panel   = new FK("fields", "id_panel", "panels", "id_panel", null);
            DataTable panels        = driver.fetchAll("SELECT * FROM ", dbe.Table("panels"), "WHERE id_project =", CE.project.Id);
            DataTable controls      = driver.fetchAll("SELECT controls.* FROM ", dbe.Table("controls"), dbe.Join(control_panel), "WHERE id_project =", CE.project.Id);
            DataTable fields        = driver.fetchAll("SELECT fields.* FROM ", dbe.Table("fields"), dbe.Join(field_panel), "WHERE id_project =", CE.project.Id);

            driver.CommitTransaction();

            panels.TableName   = "panels";
            controls.TableName = "controls";
            fields.TableName   = "fields";

            DataSet ds = new DataSet();

            /*
             * panels.PrimaryKey = new DataColumn[] { panels.Columns["id_panel"] };
             * controls.PrimaryKey = new DataColumn[] { panels.Columns["id_control"] };
             * fields.PrimaryKey = new DataColumn[] { panels.Columns["id_field"] };
             */
            if (panels.DataSet is DataSet)
            {
                panels.DataSet.Tables.Clear();
            }
            if (controls.DataSet is DataSet)
            {
                controls.DataSet.Tables.Clear();
            }
            if (fields.DataSet is DataSet)
            {
                fields.DataSet.Tables.Clear();
            }
            ds.Tables.Add(panels);
            ds.Tables.Add(controls);
            ds.Tables.Add(fields);

            ds.Relations.Add(new DataRelation(CC.SYSDRIVER_FK_CONTROL_PANEL, ds.Tables["panels"].Columns["id_panel"], ds.Tables["controls"].Columns["id_panel"], true));
            ds.Relations.Add(new DataRelation(CC.SYSDRIVER_FK_FIELD_PANEL, ds.Tables["panels"].Columns["id_panel"], ds.Tables["fields"].Columns["id_panel"], true));
            ds.Relations.Add(new DataRelation(CC.SYSDRIVER_FK_PANEL_PARENT, ds.Tables["panels"].Columns["id_panel"], ds.Tables["panels"].Columns["id_parent"], true));
            DataSet2Architecture(ds);
        }