Community
Showing results for 
Search instead for 
Do you mean 
Reply

Configurable Button Control

Nickel Elite Contributor
Posts: 937
Country: USA

Re: Configurable Button Control

[ Edited ]

Here's the class file for the control.

Copper Contributor
Posts: 32
Country: United_Kingdom

Re: Configurable Button Control

Thanks alduet
Copper Contributor
Posts: 42
Country: Germany

Re: Configurable Button Control

[ Edited ]

Here's a simplyfied version of the Control, we use it to create a new Contact with some fields filled with values from a sql-query.

using Act.Framework.Contacts;
using Act.Shared.ComponentModel;
using Act.UI;
using System;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace Act.Configbutton
{
    [
       CustomControlAttribute(true), // mark as a custom control
       LayoutToolboxItemFriendlyName(), // give the control a name
    ]
    class Configbutton : Button
    {
        private ActApplication ACTapp;
        public Configbutton()
        {
            ACTapp = Act.UI.ActApplication.Instance;
            this.Click += btn_clicked;
        }
        ~Configbutton()
        {
            this.Click -= btn_clicked;
        }
        private void btn_clicked(object sender, EventArgs de)
        {
            SqlConnection sqlConn = new SqlConnection("<your connection string>");
            SqlCommand sqlComm = new SqlCommand("<sql query>", sqlConn);
            Contact c = ACTapp.ActFramework.Contacts.CreateContact();
            c.Fields["Department", Act.Framework.MutableEntities.FieldNameType.Alias] = "<dept. to set>";
            sqlConn.Open();
            SqlDataReader sqlRead = sqlComm.ExecuteReader();
            c.Fields["<Fieldname in ACT>", Act.Framework.MutableEntities.FieldNameType.Alias] = sqlRead.Read()?sqlRead[0]:"<Value if empty recordset was returned from reader>";
            c.Update();
            sqlRead.Close();
            sqlRead.Dispose();//don't know if the disposing is neccessary
            sqlComm.Dispose();
            sqlConn.Close();
            sqlConn.Dispose();
            ACTapp.UIContactManager.ShowContact(c);
        }
        public static string LayoutToolboxFriendlyName
        {
            get
            {
                return "<Give the control a name>";
            }
        }
    }
}