📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text ;
using System.Runtime .InteropServices ;
using System.IO ;
using SH_DLL;
namespace PBX
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
///
public enum APP_USER_STATUS //User-defined station channel state
{
USER_IDLE, //Station channel idle
USER_LOCAL_RING, //Station channel ringing
USER_GET_1STDTMF, //Press the first DTMF digit on the station channel to select the called party
USER_GET_DTMF, //The station channel judges if the extension number is legal
USER_REQ_USER, //The station channel is waiting for a result to see if the extension has been used
USER_RING_BACK, //The station channel is waiting for the extension to pick up the call
USER_REQ_TRUNK, //The station channel is waiting for a result to see if a trunk channel is used for call connection
USER_DIALOUT, //The station channel dials the trunk channel
USER_WAIT_REMOTE_PICKUP, //The station channel is waiting for the trunk channel to pick up the call
USER_TALKING, //The station channel is talking with the extension
USER_WAIT_HANGUP, //The station channel is waiting to hang up the call
USER_F_GET_DTMF, //The station channel judges if the extension number is legal during a call transfer.
USER_F_REQ_USER, //The station channel is waiting for the result of a call transfer
USER_F_RING_BACK, //The station channel is waiting for the target extension to which the call is transferred to pick up the call
USER_F_TALKING, //The station channel is talking with the target extension to which the call is transferred
USER_F_OPERATE, //
USER_F_WAIT_TALK, //The previously connected station channel is waiting for the connection with the target extension to which the call is transferred
TRUNK_IDLE, //Trunk channel idle
TRUNK_WAIT_1STNUM, //The trunk channel is waiting to dial
TRUNK_DIALING, //The trunk channel is dialing
TRUNK_WAIT_REMOTE_PICKUP, //The trunk channel is waiting for the remote end to pick up the call
TRUNK_WAIT_ACTUAL_PICKUP, //The trunk channel rings, picks up the call and waits for the call connection
TRUNK_WAIT_SELECTION, //The trunk channel judges if the number is compliant with the numbering rule when it is calling the station channel
TRUNK_REQ_USER, //The trunk channel requests a station channel for call connection
TRUNK_RING_BACK, //The trunk channel is waiting for the station channel to pick up the call
TRUNK_CONNECTED, //The trunk channel is connected
TRUNK_FLASHING, //The trunk channel is waiting for the connection with the target extension to which the call is transferred
};
public enum EventMsg
{
E_US_SEIZURE = 0x0040, //Sends a usage request to the extension
E_US_RELEASE, //Sends a release event to the station channel
E_US_SEIZURE_ACK_IDLE, //Answers that the station channel is idle
E_US_SEIZURE_ACK_BUSY, //Answers that the station channel is busy
E_US_PICKUP, //Sends an off-hook event to the calling party
E_US_SEIZURE_TK, //Sends a usage request to the analog channel
E_TK_SEIZURE_TK_ACK_IDLE, //Answers that the analog channel is idle
E_TK_SEIZURE_TK_ACK_BUSY, //Answers that the analog channel is busy
E_TK_RELEASE, //Sends a release event to the trunk channel
E_US_DTMF2TK, //Sends DTMF digits to the trunk channel
E_TK_DIAL_OK, //The trunk channel is successful to dial
E_TK_DIAL_FAIL, //The trunk channel is failed to dial
E_TK_REMOTE_NOANSWER, //No answer from the remote end that the trunk channel is calling
E_TK_REMOTE_PICKUP, //The remote end that the trunk channel is calling picks up the call
E_MSG_RELEASE, //Sends a release event to the connected party
E_MSG_FLASH, //A flash event
E_MSG_CONNECT, //A connect event
E_MSG_HANGUP, //During a call transfer, the previously connected party hangs up the call and sends this event to the target party to which the call is transferred
F_US_SEIZURE, //Sends a request event to the station channel during a flash
};
[StructLayout(LayoutKind.Sequential)]public struct CH_INFO
{
public int nChType; //Channel Type: 0,2 ---Analog channel, Station channel
public int nLinkToCh; //The number of the target channel to be linked
public int nSaveSubmiteCh; //The number of the channel where the previously connected party lies
public int nTimer; //Timer ID
public StringBuilder szPhoneNumBuf;//The buffer storing phone numbers
public StringBuilder szUserNum; //The station channel number
public int nPhoNumLen; //The length of the phone number, i.e. a flag which tells if it is necessary to append numbers
public int nIndex; //Index value list
public bool bPressFlag; //A hook switch flag (TRUE: Pressed; FALSE: Not pressed)
public bool bSubmiteChHookFlag; //A flag used to judge if the previously connected party has hung up the phone (TRUE: On-hook; FALSE: Off-hook)
public StringBuilder szCallerId;//Stores the calling party number
public StringBuilder szCalleeId;//Stores the called party number
public APP_USER_STATUS nStatus; //A channel state value, which is a flag to control the program flow
}
public class Form1 : System.Windows.Forms.Form
{
[DllImport ( "kernel32" ) ] private static extern int GetPrivateProfileString ( string section , string key , string def , StringBuilder retVal , int size , string filePath ) ;
[DllImport ( "kernel32" ) ] private static extern long WritePrivateProfileString ( string section , string key , string val , string filePath ) ;
[DllImport("user32.dll", EntryPoint="SendMessageA")]public static extern int SendMessage (IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
[DllImport("SHP_A3.dll")]public static extern int SsmSetASDT(int ch, bool bEnAutoSendDialTone );
[DllImport("SHP_A3.dll")]public static extern int SsmGetDtmfStr(int ch, StringBuilder pszDtmf);
[DllImport("SHP_A3.dll")]public static extern int SsmSendTone(int ch, int nToneType);
[DllImport("SHP_A3.dll")]public static extern int SsmSearchIdleCallOutCh(int wSearchMode, int dwPrecedence);
[DllImport("SHP_A3.dll")]public static extern int SsmChkSendTone(int ch, ref int pnToneType);
[DllImport("SHP_A3.dll")]public static extern int SsmStopSendTone(int ch);
[DllImport("SHP_A3.dll")]public static extern int SsmStartRing(int ch);
[DllImport("SHP_A3.dll")]public static extern int SsmAppendPhoNum(int ch, string szPhoNum);//ref char szPhoNum);
public const int WM_USER = 0x0400;
public const int CHTYPE_TRUNK = 0; //Analog truck channel
public const int CHTYPE_USER = 2; //Station channel
public const int MAX_CHLIST_ITEM = 6;
public const int MAX_CH = 400;
public const int MAX_USER_DTMFLEN = 4;
public const int NUM_LENGTH = 20;
private System.Windows.Forms.Button button1;
private AxMSFlexGridLib.AxMSFlexGrid ChList;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
int nMaxCh;
CH_INFO[] ChInfo = new CH_INFO [400];
IntPtr hwnd;
public Form1()
{
hwnd=this.Handle ;
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
if(!IntiCtiBoard())
{
Dispose(true);
}
else
{
//set event message programming mode
EVENT_SET_INFO EventSet = new EVENT_SET_INFO ();
EventSet.dwWorkMode = (int)EventType.EVENT_MESSAGE;
EventSet.lpHandlerParam = this.Handle ;
ShDll.SsmSetEvent(-1, -1, true, ref EventSet);
IntiChList(); //initialize list and channel concerned parameter
}
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
ShDll.SsmCloseCti ();
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.ChList = new AxMSFlexGridLib.AxMSFlexGrid();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.ChList)).BeginInit();
this.SuspendLayout();
//
// ChList
//
this.ChList.Location = new System.Drawing.Point(16, 24);
this.ChList.Name = "ChList";
this.ChList.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("ChList.OcxState")));
this.ChList.Size = new System.Drawing.Size(424, 184);
this.ChList.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(360, 232);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "EXIT";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(456, 284);
this.Controls.Add(this.button1);
this.Controls.Add(this.ChList);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.ChList)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
bool IntiCtiBoard()
{
StringBuilder CErrMsg=new StringBuilder (300); //error message
//load configuration file and initialize system
if (ShDll.SsmStartCti("ShConfig.ini", "ShIndex.ini") == -1)
{
ShDll.SsmGetLastErrMsg(CErrMsg); //300-character buffer at minimum
MessageBox.Show (CErrMsg.ToString ());
return false;
}
//to judge whether number of voice board initialized successfully equials that of
//voice board set in configuration file.
if(ShDll.SsmGetMaxUsableBoard() != ShDll.SsmGetMaxCfgBoard())
{
ShDll.SsmGetLastErrMsg(CErrMsg); //300-character buffer at minimum
MessageBox.Show (CErrMsg.ToString ());
return false;
}
return true;
}
void IntiChList()
{
string KeyName;
string szChType = ""; //channel type
int nIndex; //list index
string lpAppName = "USERNUM";
ChList.Cols =6;
ChList.Row =0;
ChList.Col = 0;
ChList.Text = "Ch";
ChList.Col = 1;
ChList.Text = "ChType";
ChList.Col = 2;
ChList.Text = "Status";
ChList.Col = 3;
ChList.Text = "CallerId";
ChList.Col = 4;
ChList.Text = "CalleeId";
ChList.Col = 5;
ChList.Text = "DTMFBuffer";
ChList.set_ColWidth (0,24*12);
ChList.set_ColWidth (1,80*12);
ChList.set_ColWidth (2,130*12);
ChList.set_ColWidth (3,80*12);
ChList.set_ColWidth (4,80*12);
ChList.set_ColWidth (5,100*12);
nMaxCh = ShDll.SsmGetMaxCh(); //to retrieve max channel number set in configuration file
//to initialize each on-board channel
if(nMaxCh >= 0)
{
nIndex=1;
for(int ch=0, i=1; ch<nMaxCh; ch++)
{
ChInfo[ch].szCalleeId = new StringBuilder (20);
ChInfo[ch].szCallerId = new StringBuilder (20);
ChInfo[ch].szPhoneNumBuf = new StringBuilder (20);
ChInfo[ch].szUserNum =new StringBuilder (16);
ChInfo[ch].nLinkToCh = -1;
ChInfo[ch].nIndex = -1;
ChInfo[ch].nTimer = -1;
ChInfo[ch].nSaveSubmiteCh = -1;
ChInfo[ch].bPressFlag = false;
ChInfo[ch].bSubmiteChHookFlag = false;
//to retrive channel type information
if( (ChInfo[ch].nChType = ShDll.SsmGetChType(ch)) == -1 )
{
MessageBox.Show ("Call of function SsmGetChType() failed at initialization");
}
//to judge whether a channel is analog station or trunk channel
if(ChInfo[ch].nChType != 0 && ChInfo[ch].nChType !=2)
{
continue;
}
//to clear DTMF buffer
if(ShDll.SsmClearRxDtmfBuf(ch) == -1)
{
MessageBox.Show ("Call of function SsmClearRxDtmfBuf() failed at initialization ");
}
ChList.AddItem (ch.ToString (), nIndex);
switch(ChInfo[ch].nChType)
{
case 0:
ChInfo[ch].nStatus = APP_USER_STATUS.TRUNK_IDLE;
szChType= "Trunk";
ChInfo[ch].nIndex = nIndex;
break;
case 2:
ChInfo[ch].nStatus = APP_USER_STATUS.USER_IDLE;
szChType= "Station";
ChInfo[ch].nIndex = nIndex;
KeyName = "UserChPhoNum["+i.ToString()+"]";
string dirTemp= Directory.GetCurrentDirectory ();
string dir = dirTemp + "\\pbx.ini";
GetPrivateProfileString(lpAppName, KeyName, "XXXXXXXX", ChInfo[ch].szUserNum, 16, dir);
szChType = "Station " + ChInfo[ch].szUserNum.ToString ();
if(SsmSetASDT(ch, true) == -1)
{
MessageBox.Show ("Call of function SsmSetASDT() failed at initialization");
}
i++;
break;
default:
break;
}
ChList.set_TextMatrix (nIndex, 1, szChType);
ChList.set_TextMatrix (nIndex, 2, "Idle");
nIndex++;
}
}
else
{
if(nMaxCh == -1)
{
MessageBox.Show ("Call of function SsmGetMaxCh() failed at initialization!");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -