Пример #1
0
        /// <summary>
        /// Service callable code to Delete/Insert/Update FormSettings
        /// </summary>
        /// <param name="cd">A ClientDataSet of type FormSettingsCD</param>
        /// <returns>A FormSettingsCD ClientDataSet. If ALL OK contains updated data, if not contains the RowErrors</returns>
        public static FormSettingsCD UpdateFormSettings(FormSettingsCD cd)
        {
            if (cd == null || cd.Tables["FormSettings"] == null)
            {
                throw new Exception("The DataSet and/or DataTable is null.");
            }

            var tt = new FormSettingsTD.FormSettingsDataTable();
// ReSharper disable RedundantNameQualifier
            var ct = new FormSettingsCD.FormSettingsDataTable();

// ReSharper restore RedundantNameQualifier

            foreach (FormSettingsRow modifiedRow in cd.FormSettings.Select("", "", DataViewRowState.ModifiedCurrent))
            {
                ct.Clear();                                                                          // clear for next row to import
                ct.ImportRow(modifiedRow);                                                           // import single row into Table for merge

                tt.Merge(FormSettingsTD.GetFormSetting(modifiedRow.UserName, modifiedRow.FormName)); // populate with all current columns
                tt.Merge(ct, false, MissingSchemaAction.Ignore);                                     // overlay with updated columns
            }

            var td = new FormSettingsTD();

            td.FormSettings.BeginLoadData();
            td.FormSettings.Merge(cd.FormSettings, false, MissingSchemaAction.Ignore);
            td.FormSettings.Merge(tt, false, MissingSchemaAction.Ignore);

            using (var ts = new TransactionScope(TransactionScopeOption.Required))
            {
                FormSettingsTD.UpdateFormSettings(td);
                ts.Complete();
            }

            return(cd);
        }