Пример #1
0
    public void SetImageKeywords(string imageid, string[] keywords)
    {
        int i_id = Convert.ToInt32(imageid);

        ArrayList k_ids = new ArrayList();

        for (int i = 0; i < keywords.Length; i++)
        {
            AddKeyword(keywords[i]);
            int k_id = (int)keywords_hash[keywords[i]];
            if (!k_ids.Contains(k_id))
            {
                k_ids.Add(k_id);
            }
        }

        // wtb transactions..
        IDbCommand cmd = db_conn.CreateCommand();

        cmd.CommandText = DbProvider.SqlHelper.sqlDbDeleteImageKeywords(i_id);
        cmd.ExecuteNonQuery();

        foreach (int k_id in k_ids)
        {
            cmd.CommandText = DbProvider.SqlHelper.sqlDbAddImageKeyword(i_id, k_id);
            cmd.ExecuteNonQuery();
        }

        if (OnRepositoryChange != null)
        {
            RepositoryChangeEventArgs rcea = new RepositoryChangeEventArgs
                                                 (RepositoryChangeEventArgs.RepositoryChangeType.ImageChanged, imageid);
            OnRepositoryChange(this, rcea);
        }
    }
Пример #2
0
    // IImageRepository
    public ImageItem AddImage(ImageItem item)
    {
        // This may be not necessary
        // we may want to allow adding an image that already has a repo and.. copy it?
        if (item.Repo != null)
        {
            throw new InvalidOperationException();
        }

        IDbCommand cmd = db_conn.CreateCommand();

        cmd.CommandText = DbProvider.SqlHelper.sqlDbAddImage(item.Filename,
                                                             item.Dirname,
                                                             item.Width,
                                                             item.Height,
                                                             item.Caption,
                                                             item.Filesize);
        cmd.ExecuteNonQuery();

        int new_iid;

        // FIXME -- libgda doesn't export sqlite_last_insert_rowid, and there's no way to SELECT it
        // so we do some magic to figure out the id
        cmd.CommandText =
            "SELECT i_id FROM mp_images WHERE i_filename = '" + item.Filename + "' AND i_dirname = '" + item.Dirname + "'";
//        Console.WriteLine ("SQL: " + cmd.CommandText);
        IDataReader r = cmd.ExecuteReader();

        if (r == null || !r.Read())
        {
            throw new InvalidOperationException();
        }

        if (DbProvider.DbUsesStrings(r, 0))
        {
            new_iid = Convert.ToInt32((string)r.GetValue(0));
        }
        else
        {
            new_iid = (int)r.GetValue(0);
        }

        r.Close();

        i_id_array.Add(new_iid);

        item.thisInfo.imageid = new_iid.ToString();
        item.thisInfo.repo    = this;

        if (OnRepositoryChange != null)
        {
            RepositoryChangeEventArgs rcea = new RepositoryChangeEventArgs
                                                 (RepositoryChangeEventArgs.RepositoryChangeType.ImageAdded, new_iid.ToString());
            OnRepositoryChange(this, rcea);
        }
        return(item);
    }
Пример #3
0
 void RepositoryChanged(IImageRepository repo, RepositoryChangeEventArgs ea)
 {
     if (ea.ChangeType == RepositoryChangeEventArgs.RepositoryChangeType.CollectionAdded ||
         ea.ChangeType == RepositoryChangeEventArgs.RepositoryChangeType.CollectionRemoved)
     {
         if (ea.ChangeType == RepositoryChangeEventArgs.RepositoryChangeType.CollectionAdded)
         {
             repo.GetCollection(ea.WhichID).OnCollectionChange += new CollectionChangeHandler(CollectionChanged);
         }
         else if (ea.ChangeType == RepositoryChangeEventArgs.RepositoryChangeType.CollectionRemoved)
         {
             repo.GetCollection(ea.WhichID).OnCollectionChange -= new CollectionChangeHandler(CollectionChanged);
         }
         Refresh();
     }
 }
Пример #4
0
    public void RemoveImageKeyword(string imageid, string keyword)
    {
        int i_id = Convert.ToInt32(imageid);
        int k_id = (int)keywords_hash [keyword];

        IDbCommand cmd = db_conn.CreateCommand();

        cmd.CommandText = DbProvider.SqlHelper.sqlDbAddImageKeyword(i_id, k_id);
        cmd.ExecuteNonQuery();

        if (OnRepositoryChange != null)
        {
            RepositoryChangeEventArgs rcea = new RepositoryChangeEventArgs
                                                 (RepositoryChangeEventArgs.RepositoryChangeType.ImageChanged, imageid);
            OnRepositoryChange(this, rcea);
        }
    }
Пример #5
0
    public void RepositoryChanged(IImageRepository r, RepositoryChangeEventArgs rcea)
    {
        if (!image_ids.Contains(rcea.WhichID))
        {
            return;
        }

        if (rcea.ChangeType == RepositoryChangeEventArgs.RepositoryChangeType.ImageRemoved)
        {
            UpdateFromID(null);
            return;
        }

        if (rcea.ChangeType == RepositoryChangeEventArgs.RepositoryChangeType.ImageChanged)
        {
            UpdateFromID((ArrayList)image_ids.Clone());
        }
    }
Пример #6
0
        private async void EmployeeJobsChanged(object sender, RepositoryChangeEventArgs <EmployeeJob> args)
        {
            if (SelectedEmployee != null && SelectedEmployee.Id == args.Item.EmployeeId)
            {
                async Task AddJob()
                {
                    var job = CreateEmployeeJobViewModel(args.Item);
                    await job.Initialize();

                    EmployeeJobs.Add(job);
                }

                void DeleteJob()
                {
                    var job = EmployeeJobs.FirstOrDefault(e => e.EmployeeJob.Equals(args.Item));

                    EmployeeJobs.Remove(job);
                }

                switch (args.OperationType)
                {
                case OperationType.Add:
                    await AddJob();

                    break;

                case OperationType.Edit:
                    DeleteJob();
                    await AddJob();

                    break;

                case OperationType.Delete:
                    DeleteJob();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Пример #7
0
    public DbImageCollection CreateCollection()
    {
        IDbCommand cmd = db_conn.CreateCommand();

        cmd.CommandText =
            DbProvider.SqlHelper.sqlDbNewCollection("Collection " + c_id_array.Count);
        cmd.ExecuteNonQuery();

        // sucky sucky
        cmd.CommandText =
            DbProvider.SqlHelper.sqlDbGetCollectionByName("Collection " + c_id_array.Count);
        IDataReader r       = cmd.ExecuteReader();
        int         new_cid = -1;

        while (r.Read())
        {
            if (DbProvider.DbUsesStrings(r, 0))
            {
                new_cid = Convert.ToInt32((string)r.GetValue(0));
            }
            else
            {
                new_cid = (int)r.GetValue(0);
            }
        }

        if (new_cid == -1)
        {
            throw new ApplicationException("Couldn't find newly created collection!");
        }

        c_id_array.Add(new_cid);
        if (OnRepositoryChange != null)
        {
            RepositoryChangeEventArgs rcea = new RepositoryChangeEventArgs
                                                 (RepositoryChangeEventArgs.RepositoryChangeType.CollectionAdded, new_cid.ToString());
            OnRepositoryChange(this, rcea);
        }
        return(GetCollection(new_cid));
    }
Пример #8
0
	void RepositoryChanged (IImageRepository repo, RepositoryChangeEventArgs ea)
	{
		if (ea.ChangeType == RepositoryChangeEventArgs.RepositoryChangeType.CollectionAdded ||
		    ea.ChangeType == RepositoryChangeEventArgs.RepositoryChangeType.CollectionRemoved)
		{
			if (ea.ChangeType == RepositoryChangeEventArgs.RepositoryChangeType.CollectionAdded) {
				repo.GetCollection (ea.WhichID).OnCollectionChange += new CollectionChangeHandler (CollectionChanged);
			} else if (ea.ChangeType == RepositoryChangeEventArgs.RepositoryChangeType.CollectionRemoved) {
				repo.GetCollection (ea.WhichID).OnCollectionChange -= new CollectionChangeHandler (CollectionChanged);
			}
			Refresh ();
		}
	}
Пример #9
0
 /// <summary>
 /// Repositories the changing.
 /// </summary>
 /// <param name="args">The <see cref="T:ContactSearch.DataLayer.RepositoryChangeEventArgs" /> instance containing the event data.</param>
 /// <returns></returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public EventHandler RepositoryChanging(RepositoryChangeEventArgs args)
 {
     throw new NotImplementedException();
 }
Пример #10
0
	public void RepositoryChanged (IImageRepository r, RepositoryChangeEventArgs rcea)
	{
		if (!image_ids.Contains (rcea.WhichID))
			return;

		if (rcea.ChangeType == RepositoryChangeEventArgs.RepositoryChangeType.ImageRemoved) {
			UpdateFromID (null);
			return;
		}

		if (rcea.ChangeType == RepositoryChangeEventArgs.RepositoryChangeType.ImageChanged) {
			UpdateFromID ((ArrayList) image_ids.Clone ());
		}
	}
Пример #11
0
	public void SetImageKeywords (string imageid, string[] keywords)
	{
		int i_id = Convert.ToInt32 (imageid);

		ArrayList k_ids = new ArrayList ();

		for (int i = 0; i < keywords.Length; i++) {
			AddKeyword (keywords[i]);
			int k_id = (int) keywords_hash[keywords[i]];
			if (!k_ids.Contains (k_id))
				k_ids.Add (k_id);
		}

		// wtb transactions..
		IDbCommand cmd = db_conn.CreateCommand ();
		cmd.CommandText = DbProvider.SqlHelper.sqlDbDeleteImageKeywords (i_id);
		cmd.ExecuteNonQuery ();

		foreach (int k_id in k_ids) {
			cmd.CommandText = DbProvider.SqlHelper.sqlDbAddImageKeyword (i_id, k_id);
			cmd.ExecuteNonQuery ();
		}

		if (OnRepositoryChange != null) {
			RepositoryChangeEventArgs rcea = new RepositoryChangeEventArgs
			(RepositoryChangeEventArgs.RepositoryChangeType.ImageChanged, imageid);
			OnRepositoryChange (this, rcea);
		}
	}
Пример #12
0
	public void RemoveImageKeyword (string imageid, string keyword)
	{
		int i_id = Convert.ToInt32 (imageid);
		int k_id = (int) keywords_hash [keyword];

		IDbCommand cmd = db_conn.CreateCommand ();
		cmd.CommandText = DbProvider.SqlHelper.sqlDbAddImageKeyword (i_id, k_id);
		cmd.ExecuteNonQuery ();

		if (OnRepositoryChange != null) {
			RepositoryChangeEventArgs rcea = new RepositoryChangeEventArgs
			(RepositoryChangeEventArgs.RepositoryChangeType.ImageChanged, imageid);
			OnRepositoryChange (this, rcea);
		}
	}
Пример #13
0
	public DbImageCollection CreateCollection ()
	{
		IDbCommand cmd = db_conn.CreateCommand ();
		cmd.CommandText =
		DbProvider.SqlHelper.sqlDbNewCollection ("Collection " + c_id_array.Count);
		cmd.ExecuteNonQuery ();

		// sucky sucky
		cmd.CommandText =
		DbProvider.SqlHelper.sqlDbGetCollectionByName ("Collection " + c_id_array.Count);
		IDataReader r = cmd.ExecuteReader ();
		int new_cid = -1;
		while (r.Read ()) {
			if (DbProvider.DbUsesStrings (r, 0)) {
				new_cid = Convert.ToInt32 ((string) r.GetValue (0));
			} else {
				new_cid = (int) r.GetValue (0);
			}
		}

		if (new_cid == -1) {
			throw new ApplicationException ("Couldn't find newly created collection!");
		}

		c_id_array.Add (new_cid);
		if (OnRepositoryChange != null) {
			RepositoryChangeEventArgs rcea = new RepositoryChangeEventArgs
			(RepositoryChangeEventArgs.RepositoryChangeType.CollectionAdded, new_cid.ToString ());
			OnRepositoryChange (this, rcea);
		}
		return GetCollection (new_cid);
	}
Пример #14
0
	// IImageRepository
	public ImageItem AddImage (ImageItem item)
	{
		// This may be not necessary
		// we may want to allow adding an image that already has a repo and.. copy it?
		if (item.Repo != null) {
			throw new InvalidOperationException ();
		}

		IDbCommand cmd = db_conn.CreateCommand ();
		cmd.CommandText = DbProvider.SqlHelper.sqlDbAddImage (item.Filename,
								      item.Dirname,
								      item.Width,
								      item.Height,
								      item.Caption,
								      item.Filesize);
		cmd.ExecuteNonQuery ();

		int new_iid;

		// FIXME -- libgda doesn't export sqlite_last_insert_rowid, and there's no way to SELECT it
		// so we do some magic to figure out the id
		cmd.CommandText =
		"SELECT i_id FROM mp_images WHERE i_filename = '" + item.Filename + "' AND i_dirname = '" + item.Dirname + "'";
//        Console.WriteLine ("SQL: " + cmd.CommandText);
		IDataReader r = cmd.ExecuteReader ();
		if (r == null || !r.Read ()) {
			throw new InvalidOperationException ();
		}

		if (DbProvider.DbUsesStrings (r, 0)) {
			new_iid = Convert.ToInt32 ((string) r.GetValue (0));
		} else {
			new_iid = (int) r.GetValue (0);
		}

		r.Close ();

		i_id_array.Add (new_iid);

		item.thisInfo.imageid = new_iid.ToString();
		item.thisInfo.repo = this;

		if (OnRepositoryChange != null) {
			RepositoryChangeEventArgs rcea = new RepositoryChangeEventArgs
			(RepositoryChangeEventArgs.RepositoryChangeType.ImageAdded, new_iid.ToString ());
			OnRepositoryChange (this, rcea);
		}
		return item;
	}