Ejemplo n.º 1
0
 /// <summary>
 /// Get all GridSettings
 /// </summary>
 /// <returns>A GridSettingsTD</returns>
 public static DataSet GetGridSettings()
 {
     using (new TransactionScope(TransactionScopeOption.Suppress))
     {
         var ds = new GridSettingsTD();
         var ta = new GridSettingsTDTableAdapters.GridSettingsTableAdapter();
         ta.Fill(ds.GridSettings);
         return(ds);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns true or false if a GridSettings exists
        /// </summary>
        /// <param name="userName">The UserName to check existance</param>
        /// <param name="gridName">The GridName to check existance</param>
        /// <returns>true if GridSettings exists, false if not</returns>
        public static bool IsExistingGridSettings(string userName, string gridName)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(gridName))
            {
                throw new Exception("The UserName and/or GridName is null or empty.");
            }

            using (new TransactionScope(TransactionScopeOption.Suppress))
            {
                var ta = new GridSettingsTDTableAdapters.GridSettingsTableAdapter();
                return(ta.IsExistingGridSettings(userName, gridName) == 0 ? false : true);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get GridSetting row by UserName/GridName
        /// </summary>
        /// <returns>A GridSettingsDataTable with one row if UserName/GridName exists</returns>
        public static DataTable GetGridSetting(string userName, string gridName, string columnName)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(gridName) || string.IsNullOrEmpty(columnName))
            {
                throw new Exception("The UserName and/or GridName and/or ColumnName is null or empty.");
            }

            using (new TransactionScope(TransactionScopeOption.Suppress))
            {
                var ta = new GridSettingsTDTableAdapters.GridSettingsTableAdapter();
                return(ta.GetDataByUserNameGridNameColumnName(userName, gridName, columnName));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Service callable code to Delete GridSettings
        /// </summary>
        /// <returns>A GridSettingsTD. If ALL updated OK contains updated data, if not contains the RowErrors</returns>
        public static void DeleteGridSettingsByUserNameGridName(string userName, string gridName)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(gridName))
            {
                throw new Exception("The UserName and/or GridName is null or empty.");
            }

            using (var ts = new TransactionScope(TransactionScopeOption.Required))
            {
                var taGridSettings = new GridSettingsTDTableAdapters.GridSettingsTableAdapter();
                taGridSettings.DeleteByUserNameGridName(userName, gridName);

                ts.Complete();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Service callable code to Delete/Insert/Update GridSettings
        /// </summary>
        /// <returns>A GridSettingsTD. If ALL updated OK contains updated data, if not contains the RowErrors</returns>
        public static DataSet UpdateGridSettings(DataSet gridSettingsDataSet)
        {
            if (gridSettingsDataSet == null || gridSettingsDataSet.Tables["GridSettings"] == null)
            {
                throw new Exception("The DataSet and/or DataTable is null.");
            }

            var dtGridSettings = new GridSettingsDataTable();

            dtGridSettings.BeginLoadData();
            dtGridSettings.Merge(gridSettingsDataSet.Tables["GridSettings"], false, MissingSchemaAction.Error);

            using (var ts = new TransactionScope(TransactionScopeOption.Required))
            {
                var taGridSettings = new GridSettingsTDTableAdapters.GridSettingsTableAdapter();

                #region do deletes
                foreach (GridSettingsRow deletedRow in dtGridSettings.Select("", "", DataViewRowState.Deleted))
                {
                    // get the primary key value(s) from the Original version (for child deletes)
                    var userName   = (string)deletedRow["UserName", DataRowVersion.Original];
                    var gridName   = (string)deletedRow["GridName", DataRowVersion.Original];
                    var columnName = (string)deletedRow["ColumnName", DataRowVersion.Original];

                    // do child deletes (if any exist)
                    //SettingsChildrenDataSet tasksChildrenDataSet = new SettingsChildrenDataSet();
                    // fill the DataSet with some udpates
                    //SettingsChildrenDataSet.UpdateSettingsChildren(tasksChildrenDataSet, ref sqlTrans);

                    // delete the row
                    taGridSettings.Delete(userName, gridName, columnName);
                }
                #endregion

                #region do inserts
                foreach (GridSettingsRow insertedRow in dtGridSettings.Select("", "", DataViewRowState.Added))
                {
                    insertedRow.SetDefaultValues();

                    if (insertedRow.IsValidRow())
                    {
                        taGridSettings.Update(insertedRow);
                    }
                    else
                    {
                        throw new Exception("A row to be inserted contains invalid data. Entire transaction cancelled.");
                    }
                }
                #endregion

                #region do updates
                foreach (GridSettingsRow modifiedRow in dtGridSettings.Select("", "", DataViewRowState.ModifiedCurrent))
                {
                    // get the primary key value(s) from the Original version
                    var userName   = (string)modifiedRow["UserName", DataRowVersion.Original];
                    var gridName   = (string)modifiedRow["GridName", DataRowVersion.Original];
                    var columnName = (string)modifiedRow["ColumnName", DataRowVersion.Original];

                    // do not allow key changes
                    var userNameCurr   = (string)modifiedRow["UserName", DataRowVersion.Current];
                    var gridNameCurr   = (string)modifiedRow["GridName", DataRowVersion.Current];
                    var columnNameCurr = (string)modifiedRow["ColumnName", DataRowVersion.Current];
                    if (userName != userNameCurr || gridName != gridNameCurr || columnName != columnNameCurr)
                    {
                        throw new Exception("Change of primary key(s) is not permitted. Entire transaction cancelled.");
                    }

                    if (modifiedRow.IsValidRow())
                    {
                        taGridSettings.Update(modifiedRow);
                    }
                    else
                    {
                        throw new Exception("A row to be modified contains invalid data. Entire transaction cancelled.");
                    }
                }
                #endregion

                ts.Complete();
            }
            dtGridSettings.AcceptChanges();
            gridSettingsDataSet.Tables["GridSettings"].Merge(dtGridSettings, false, MissingSchemaAction.Ignore);

            return(gridSettingsDataSet);
        }