Exemplo n.º 1
0
        /// <summary>
        /// Creates new category from the file system.
        /// no save() is required after that.
        /// </summary>
        /// <param name="parentCategory">the parent</param>
        /// <param name="fileName">the full path</param>
        /// <param name="deep">determine if you will make a deep copy, 
        /// or you will just copy only the images in this category</param>
        public Category(Category parentCategory, String fileName, bool deep)
        {
            if (parentCategory == null || fileName == null)
            {
                throw new ObjectDBException("Problem creating category!", this);
            }
            // the user of the new category is the
            // same as the user of the parent category
            this.parent = parentCategory;
            user = parentCategory.User;
            SqlTransaction trans = null;
            try
            {
                trans = user.Connection.getInstance().BeginTransaction();
                SqlCommand cmd = new SqlCommand();

                cmd.Connection = user.Connection.getInstance();
                cmd.Transaction = trans;
                cmd.CommandType = CommandType.StoredProcedure;
                if (!deep)
                {
                    FileManger.saveSingleFolder(cmd, this, fileName);
                }
                else
                {

                }
                trans.Commit();
            }
            catch (SqlException e)
            {
                if (trans != null) trans.Rollback();
                throw new ServerInfoException(
                    e.Message, user.Connection.ServerInfos, e);
            }
            catch (Exception e)
            {
                if (trans != null) trans.Rollback();
                if (e is ServerInfoException) throw e;
                else
                {
                    throw new ObjectDBException("Problem creating new category!", this, e);
                }

            }
            shared = false;
        }
Exemplo n.º 2
0
 public Category(Category parentCategory)
 {
     this.parent = parentCategory;
     this.user = parentCategory.User;
 }
Exemplo n.º 3
0
        public void save()
        {
            if (this.id >= 0 || parent == null || categoryName == null)
            {
                // Category should not have an id to be inserted
                throw new ObjectDBException("Problem creating category!", this);
            }
            // the user of the new category is the
            // same as the user of the parent category
            user = parent.user;
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = user.Connection.getInstance();
                // no transaction needed here
                cmd.CommandType = CommandType.StoredProcedure;
                FileManger.saveCategory(cmd, this);
            }
            catch (SqlException e)
            {
                throw new ServerInfoException(
                    e.Message, user.Connection.ServerInfos, e);
            }
            catch (Exception e)
            {
                if (e is ServerInfoException) throw e;
                else
                {
                    throw new ObjectDBException("Problem creating new category!", this, e);
                }

            }
            parent = null;
            shared = false;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Loads a new existing image by its id.
 /// Since this is internal constructor it 
 /// dosen't wrap the exceptions(i.e. danegrouse code). 
 /// </summary>
 /// <param name="categoryId">the id of the image</param>
 /// <param name="cmd">the command object to be used
 /// (convinient when using transactions)</param>
 /// <param name="user">the current user of this image</param>
 internal Image(Int32 imageId, SqlCommand cmd, User user)
 {
     this.user = user;
     load(imageId, cmd);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Loads a new existing category by its id.
 /// Since this is internal constructor it 
 /// dosen't wrap the exceptions(i.e. danegrouse code). 
 /// </summary>
 /// <param name="categoryId">the id of the category</param>
 /// <param name="cmd">the command object to be used
 /// (convinient when using transactions)</param>
 /// <param name="user">the current user of this category</param>
 internal Category(Int32 categoryId, SqlCommand cmd, User user)
 {
     this.user = user;
     load(categoryId, cmd);
 }
Exemplo n.º 6
0
 private void MenuItemChangePassword_Click(object sender, System.EventArgs e)
 {
     ChangePasswordDialog dialog = new ChangePasswordDialog();
     dialog.Alias = currentUser.Alias;
     if (dialog.ShowDialog() == DialogResult.OK && currentUser != null)
     {
         try
         {
             if (currentUser.checkUser(dialog.Alias, dialog.Password))
             {
                 currentUser.Password = dialog.NewPassword;
                 MessageBox.Show(this, "Password successfuly changed!", "Info",
                     MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             dialog.Dispose();
         }
         catch (ServerInfoException ex)
         {
             MessageBox.Show(this, ex.Message, "Info",
                 MessageBoxButtons.OK, MessageBoxIcon.Information);
             dialog.Dispose();
             // try again
             MenuItemChangePassword_Click(sender, e);
         }
         catch (ObjectDBException ex)
         {
             MessageBox.Show(this, ex.Message, "Error",
                 MessageBoxButtons.OK, MessageBoxIcon.Error);
             currentUser.Dispose();
             currentUser = null;
             enableMenu(false);
         }
     }
 }
Exemplo n.º 7
0
 public Image(String fileName, Category parentCategory)
 {
     this.realFileName = fileName;
     this.parentCategory = parentCategory;
     this.user = parentCategory.User;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 protected override void Dispose( bool disposing )
 {
     if( disposing )
     {
         if(components != null)
         {
             components.Dispose();
         }
         if (currentUser != null)
         {
             currentUser.Dispose();
             currentUser = null;
         }
     }
     base.Dispose( disposing );
 }
Exemplo n.º 9
0
        private void MenuItemNewUser_Click(object sender, System.EventArgs e)
        {
            NewUserDialog dialog = new NewUserDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                currentUser = new User();
                try
                {
                    currentUser.Alias = dialog.Alias;
                    currentUser.Name = dialog.UserName;
                    currentUser.Surname = dialog.UserSurname;
                    currentUser.Password = dialog.Password;
                    currentUser.save();

                    // set the root element of the tree
                    Category rootCat = currentUser.RootCategory;
                    TreeNode root = new TreeNode(rootCat.Name);
                    root.Tag = rootCat;
                    root.ImageIndex = 0;
                    MainFormTreeView.Nodes.Add(root);

                    enableMenu(true);
                    dialog.Dispose();
                }
                catch (ServerInfoException ex)
                {
                    MessageBox.Show(dialog, ex.Message, "Info",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    dialog.Dispose();
                    // try again
                    MenuItemNewUser_Click(sender, e);
                }
                catch (ObjectDBException ex)
                {
                    MessageBox.Show(this, ex.Message + "\n" +
                        "Application will terminate.", "Error",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dialog.Dispose();
                }
            }
        }
Exemplo n.º 10
0
 private void MenuItemLogout_Click(object sender, System.EventArgs e)
 {
     if (MenuItemLogout.Enabled == true && currentUser != null)
     {
         try
         {
             currentUser.performLogout();
             currentUser.Dispose();
             currentUser = null;
             MainFormTreeView.Nodes.Clear();
             ListViewImageList.Images.Clear();
             MainFrameListView.Items.Clear();
             enableMenu(false);
             GC.Collect();
         }
         catch (ServerInfoException ex)
         {
             MessageBox.Show(this, ex.Message, "Info",
                 MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         catch (ObjectDBException ex)
         {
             MessageBox.Show(this, ex.Message +
                 "/n     Application will terminate!", "Error",
                 MessageBoxButtons.OK, MessageBoxIcon.Error);
             this.Dispose();
             currentUser = null;
         }
     }
 }
Exemplo n.º 11
0
        private void MenuItemLogin_Click(object sender, System.EventArgs e)
        {
            LoginDialog dialog = new LoginDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                if (currentUser == null) {
                    currentUser = new User();
                }
                try
                {
                    currentUser.performLogin(dialog.Loginame, dialog.Password);

                    // set the root element of the tree
                    Category rootCat = currentUser.RootCategory;
                    TreeNode root = new TreeNode(rootCat.Name);
                    root.Tag = rootCat;
                    root.ImageIndex = 0;
                    MainFormTreeView.Nodes.Add(root);
                    MainFormTreeView.Refresh();

                    enableMenu(true);
                    dialog.Dispose();
                }
                catch (ServerInfoException ex)
                {
                    MessageBox.Show(this, ex.Message, "Info",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    dialog.Dispose();
                    // try again
                    MenuItemLogin_Click(sender, e);
                }
                catch (ObjectDBException ex)
                {
                    MessageBox.Show(this, ex.Message, "Error",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dialog.Dispose();
                }
                dialog = null;
                GC.Collect();
            }
        }
Exemplo n.º 12
0
 private void MenuItemDeleteUser_Click(object sender, System.EventArgs e)
 {
     if (MenuItemDeleteUser.Enabled == true && currentUser != null)
     {
         try
         {
             bool confirmed = MessageBox.Show(
                 "This operation will delete all the data associated with this user.\n"+
                 "\tDo you want to continue?",
                 "Confirmation Dialog",	MessageBoxButtons.YesNo,
                 MessageBoxIcon.Warning) == DialogResult.Yes;
             if (confirmed)
             {
                 currentUser.delete();
                 currentUser.Dispose();
                 currentUser = null;
                 MainFormTreeView.Nodes.Clear();
                 MainFrameListView.Items.Clear();
                 ListViewImageList.Images.Clear();
                 enableMenu(false);
                 GC.Collect();
             }
         }
         catch (ServerInfoException ex)
         {
             MessageBox.Show(this, ex.Message, "Info",
                 MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         catch (ObjectDBException ex)
         {
             MessageBox.Show(this, ex.Message + "\n" +
                 "Application will terminate.", "Error",
                 MessageBoxButtons.OK, MessageBoxIcon.Error);
             Dispose(true);
         }
     }
 }