I'm attempting to write a screen pop call log using a dll to capture events on a telephone system. As you can see in the code below the 3 events:
OnOffering - calls method upon phone ringing passing current number
OnConnect - calls method upon answering passing current number
OnDisconnect - calls disconnect method
The idea is to pull information from an SQL database when the OnConnect method is called and display on a windows form (providing the number has been previously stored). I've designed the form and wrote all the sql functions in a separate class and I can call these from my form ok. The method I plan to call when the event occurs returns a datatable from the database referencing the incoming number.
I can call my sql search method fine from within the OnConnect method, but the problem is how do I pass the datatable to my Form?
Or is there a better method?
Thanks
Program.cs
using System;
using System.Windows.Forms;
using TelephonyProxy;
using System.Data;
namespace CallLog
{
static class Program
{
private static Listener listener;
private static MainForm mainForm;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
mainForm = new MainForm();
listener = new Listener();
SubcribeToListener();
Application.Run(mainForm);
}
private static void SubcribeToListener()
{
listener.Connect += OnConnect;
listener.Disconnect += OnDisconnect;
listener.Offering += OnOffering;
}
private static void OnOffering(string name, string number)
{
}
private static void OnDisconnect()
{
}
private static void OnConnect(string name, string number)
{
DataTable dt;
dt = CommonSQLFunctions.SearchQuery(number);
}
}
}
1 个答案:
答案 0 :(得分:0)
So, do should have a MainForm.cs, and I think it would make more sense to have the subscribe, offer, connect, and disconnect methods in that MainForm class, instead of in your Program class.
Your MainForm class would have a Listener field, and in the MainForm constructor, you can call the SubscribeToListener method to attach your event handlers to the events on the Listener. That way, when your OnConnect event handler runs, you are already in the MainForm, so you can easily do whatever you need to with your data set at that point.