Example #1
0
        private bool SaveScript()
        {
            if (ConfigHelper.Current == null || ConfigHelper.Current.PragmaSqlDbConn == null)
            {
                MessageBox.Show("PragmaSQL Systtem connection not specified!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            SharedScriptsService facade = new SharedScriptsService();

            facade.ConnParams = ConfigHelper.Current.PragmaSqlDbConn;

            SharedScriptsItemData data = ucSharedScripts1.SelectedNodeData;
            int?parentID = null;

            if (data.Type == GenericItemType.Folder)
            {
                parentID    = data.ID;
                data        = SharedScriptsItemDataFactory.Create(txtItemName.Text, GenericItemType.Item, null, parentID, String.Empty);
                data.Script = Script;
                facade.AddItem(data);
                _savedItemData = data;
                return(true);
            }
            else if (data.Type == GenericItemType.Item)
            {
                if (data.Name.ToLowerInvariant() == txtItemName.Text.ToLowerInvariant())
                {
                    DialogResult dlgRes = MessageBox.Show("Item with name \"" + data.Name + "\" already exists!\n"
                                                          + "Do you want to overwrite this item?", "Warning"
                                                          , MessageBoxButtons.YesNo
                                                          , MessageBoxIcon.Warning
                                                          , MessageBoxDefaultButton.Button2
                                                          );

                    if (dlgRes == DialogResult.No)
                    {
                        return(false);
                    }
                    data.Script = Script;
                    facade.UpdateItem(data);
                    _savedItemData = data;
                    return(true);
                }
                else
                {
                    parentID    = data.ParentID;
                    data        = SharedScriptsItemDataFactory.Create(txtItemName.Text, GenericItemType.Item, null, parentID, String.Empty);
                    data.Script = Script;
                    facade.AddItem(data);
                    _savedItemData = data;
                    return(true);
                }
            }
            else
            {
                throw new Exception("Item type not supported!");
            }
        }
Example #2
0
        public IList <SharedScriptsItemData> GetChildren(int?parentID)
        {
            if (ConnParams == null)
            {
                throw new NullPropertyException("Connection parameters is null!");
            }

            IList <SharedScriptsItemData> result = new List <SharedScriptsItemData>();

            using (SqlConnection conn = _connParams.CreateSqlConnection(true, false))
            {
                string     cmdText = "exec spPragmaSQL_Script_GetChildren @ParentID";
                SqlCommand cmd     = new SqlCommand(cmdText, conn);
                cmd.CommandTimeout = 0;
                AddParam(cmd, "@ParentID", System.Data.SqlDbType.Int, parentID);

                SqlDataReader reader = cmd.ExecuteReader();

                string   name         = String.Empty;
                string   serverName   = String.Empty;
                string   databaseName = String.Empty;
                string   helpText     = String.Empty;
                int?     type         = null;
                int?     id           = null;
                DateTime?createdOn    = null;
                string   createdBy    = String.Empty;
                string   updatedBy    = String.Empty;
                DateTime?updatedOn    = null;
                string   script       = String.Empty;
                bool     isDeleted    = false;

                SharedScriptsItemData data = null;
                try
                {
                    while (reader.Read())
                    {
                        name         = reader["Name"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["Name"];
                        serverName   = reader["ServerName"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["ServerName"];
                        databaseName = reader["DatabaseName"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["DatabaseName"];
                        type         = reader["Type"].GetType() == typeof(DBNull) ? null : (int?)reader["Type"];
                        id           = reader["ScriptID"].GetType() == typeof(DBNull) ? null : (int?)reader["ScriptID"];
                        createdOn    = reader["CreatedOn"].GetType() == typeof(DBNull) ? null : (DateTime?)reader["CreatedOn"];
                        createdBy    = reader["CreatedBy"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["CreatedBy"];
                        updatedOn    = reader["ModifiedOn"].GetType() == typeof(DBNull) ? null : (DateTime?)reader["ModifiedOn"];
                        updatedBy    = reader["ModifiedBy"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["ModifiedBy"];

                        script    = reader["Script"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["Script"];
                        isDeleted = reader["IsDeleted"].GetType() == typeof(DBNull) ? false : (bool)reader["IsDeleted"];
                        helpText  = reader["HelpText"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["HelpText"];

                        data           = SharedScriptsItemDataFactory.Create(name, type, id, parentID, createdBy);
                        data.Script    = script;
                        data.IsDeleted = isDeleted;
                        data.CreatedOn = createdOn;
                        data.UpdatedBy = updatedBy;
                        data.UpdatedOn = updatedOn;
                        data.HelpText  = helpText;

                        data.ServerName   = serverName;
                        data.DatabaseName = databaseName;
                        result.Add(data);
                    }
                }
                finally
                {
                    reader.Close();
                }
            }

            return(result);
        }