Ejemplo n.º 1
0
        private int SaveField(int itemId, SchemaItemField field, ICaisisInputControl c, int DisplayOrder)
        {
            field[SchemaItemField.SchemaItemId] = itemId;
            field[SchemaItemField.DestTable]    = c.Table;
            field[SchemaItemField.DestField]    = c.Field;
            field[SchemaItemField.DestValue]    = c.Value;
            field[SchemaItemField.DisplayOrder] = DisplayOrder++;

            field.Save();

            return(DisplayOrder);
        }
Ejemplo n.º 2
0
        public override void SaveControl(int schemaItemId, bool bParentTable, bool bCreateNew)
        {
            int DisplayOrder = 0;

            IEnumerable <ICaisisInputControl> list = ExtractCaisisInputControls(SchemaItemsListRptr);

            foreach (ICaisisInputControl c in list)
            {
                if (existingData.ContainsKey(c.Field))
                {
                    DataRow fieldRow = existingData[c.Field];
                    int     fieldId  = (int)fieldRow[SchemaItemField.SchemaItemFieldId];
                    if (bCreateNew)
                    {
                        fieldId = -1;
                    }
                    SchemaItemField field = new SchemaItemField();

                    AdjustFieldValue(c);

                    if (string.IsNullOrEmpty(c.Value) && !c.Required)
                    {
                        // delete the field
                        //field.Delete(fieldId);
                        ProtocolMgmtDa.DeleteSchemaItemField(fieldId);
                    }
                    else
                    {
                        // update the field
                        field.Get(fieldId);
                        field[SchemaItemField.SchemaItemId]  = schemaItemId;
                        field[SchemaItemField.DestTable]     = c.Table;
                        field[SchemaItemField.DestField]     = c.Field;
                        field[SchemaItemField.DestValue]     = c.Value;
                        field[SchemaItemField.DisplayOrder]  = DisplayOrder++;
                        field[SchemaItemField.FieldRowIndex] = DBNull.Value;

                        field.Save();
                    }
                }
                else
                {
                    // for new fields
                    // insert

                    AdjustFieldValue(c);

                    if (!string.IsNullOrEmpty(c.Value) || c.Required)
                    {
                        SchemaItemField field = new SchemaItemField();
                        field[SchemaItemField.SchemaItemId]  = schemaItemId;
                        field[SchemaItemField.DestTable]     = c.Table;
                        field[SchemaItemField.DestField]     = c.Field;
                        field[SchemaItemField.DestValue]     = c.Value;
                        field[SchemaItemField.DisplayOrder]  = DisplayOrder++;
                        field[SchemaItemField.FieldRowIndex] = DBNull.Value;

                        field.Save();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public override void SaveControl(int schemaItemId, bool bParentTable, bool bCreateNew)
        {
            Panel pnl = Page.FindControl(TableName + "Holder") as Panel;

            if (pnl != null)
            {
                // primary key for already saved values
                int nPrimaryKey = -1;

                int nFieldRowIndex = -1;

                // if FieldRowIndex hidden field is set to -1 then delete the record
                // otherwise, insert the record
                bool bSkipRow = true;

                Row_Actions action = Row_Actions.Update;

                int DisplayOrder = 0;

                foreach (ICaisisInputControl c in ExtractCaisisInputControls(pnl))
                {
                    if (c is CaisisHidden && (c.Field == null || !c.Field.EndsWith("Date")))
                    {
                        CaisisHidden csHidden = c as CaisisHidden;
                        if (csHidden.ID == "SchemaItemFieldId")
                        {
                            Int32.TryParse(csHidden.Value, out nPrimaryKey);

                            if (bCreateNew)
                            {
                                nPrimaryKey = -1;
                            }
                        }
                        else if (csHidden.ID == "FieldRowIndex")
                        {
                            DisplayOrder = 0;

                            // Adjust FieldRowIndex so they are sequential
                            if (!String.IsNullOrEmpty(csHidden.Value))
                            {
                                bSkipRow = false;

                                if (csHidden.Value == "-1")
                                {
                                    action = Row_Actions.Delete;
                                }
                                else
                                {
                                    action = Row_Actions.Update;

                                    nFieldRowIndex++;
                                }
                            }
                            else
                            {
                                bSkipRow = true;
                            }
                        }
                    }
                    else if (!bSkipRow)
                    {
                        // if no check boxes checked and a new record, don't save
                        if (!OptionsSelected() &&
                            nPrimaryKey <= 0)
                        {
                            continue;
                        }

                        SchemaItemField field = new SchemaItemField();
                        field.Get(nPrimaryKey);

                        // If csHidden.Value == -1 then delete
                        if (action == Row_Actions.Update)
                        {
                            AdjustFieldValueSave(c);

                            if (!String.IsNullOrEmpty(c.Value))
                            {
                                field[SchemaItemField.FieldRowIndex] = nFieldRowIndex;
                                field[SchemaItemField.SchemaItemId]  = schemaItemId;
                                field[SchemaItemField.DestTable]     = c.Table;
                                field[SchemaItemField.DestField]     = c.Field;
                                field[SchemaItemField.DestValue]     = c.Value;
                                field[SchemaItemField.DisplayOrder]  = DisplayOrder++;

                                field.Save();
                            }
                            else
                            {
                                if (!field.IsNull(SchemaItemField.SchemaItemFieldId))
                                {
                                    int schemaItemFieldId = (int)field[SchemaItemField.SchemaItemFieldId];
                                    ProtocolMgmtDa.DeleteSchemaItemField(schemaItemFieldId);
                                }
                            }
                        }
                        else if (action == Row_Actions.Delete)
                        {
                            if (!field.IsNull(SchemaItemField.SchemaItemFieldId))
                            {
                                int schemaItemFieldId = (int)field[SchemaItemField.SchemaItemFieldId];
                                ProtocolMgmtDa.DeleteSchemaItemField(schemaItemFieldId);
                            }
                        }
                    }
                }
            }
        }