📄 form1.cs
字号:
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace ATP_Event
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.RadioButton radioButton3;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
[DllImport("SHP_A3.dll")]public static extern int SsmStartCti(string lpSsmCfgFileName, string lpIndexCfgFileName);
[DllImport("SHP_A3.dll")]public static extern int SsmCloseCti();//added by sh for calling function SsmCloseCti(), 2006-9-25
[DllImport("SHP_A3.dll")]public static extern string SsmGetLastErrMsgA();
[DllImport("SHP_A3.dll")]public static extern int SsmGetMaxCfgBoard();
[DllImport("SHP_A3.dll")]public static extern int SsmGetMaxUsableBoard();
[DllImport("SHP_A3.dll")]public static extern int SsmGetMaxCh();
[DllImport("SHP_A3.dll")]public static extern int SsmGetChType(int ch);
[DllImport("SHP_A3.dll")]public static extern int SsmRecToFile(int ch,string pszFileName, int nFormat, uint dwStartPos, int dwLen, uint dwTime, int nMask);
[DllImport("SHP_A3.dll")]public static extern int SsmPlayFile(int ch,string pszFileName, int nFormat, int dwStartPos, uint dwLen);
[DllImport("SHP_A3.dll")]public static extern int SsmStopRecToFile(int ch);
[DllImport("SHP_A3.dll")]public static extern int SsmClearRxDtmfBuf(int ch);
[DllImport("SHP_A3.dll")]public static extern int SsmGetCallerId(int ch, byte[] szCallerId);
[DllImport("SHP_A3.dll")]public static extern int SsmSetEvent(int wEvent, int nReference, bool bEnable, ref EVENT_SET_INFO pEventSet);
[DllImport("SHP_A3.dll")]public static extern int SsmSetBargeInSens(int ch, int nBargeInSens);
[DllImport("SHP_A3.dll")]public static extern int SsmSetDtrmLineVoltage(int ch, ushort wDtrmValtage);
[DllImport("SHP_A3.dll")]public static extern int SsmGetIgnoreLineVoltage(int ch);
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public const int WM_USER = 0x0400;
public const int E_CHG_ChState = 0x0018;
public const int E_SYS_BargeIn = 0x002E;
public const int E_SYS_NoSound = 0x002F;
public const int E_CHG_RcvDTMF = 0x000C;
public const int E_PROC_RecordEnd = 0x0013;
public const int E_CHG_RingCount = 0x001E;
enum TRUNK_STATUS
{
S_CALL_STANDBY =0,
S_CALL_PICKUPED=1,
S_CALL_RINGING =2,
S_CALL_TALKING =3,
S_CALL_ANALOG_WAITDIALTONE =4,
S_CALL_ANALOG_TXPHONUM =5,
S_CALL_ANALOG_WAITDIALRESULT=6,
S_CALL_PENDING =7,
S_CALL_OFFLINE =8,
S_CALL_WAIT_REMOTE_PICKUP =9,
S_CALL_ANALOG_CLEAR =10,
S_CALL_UNAVAILABLE =11,
S_CALL_LOCKED =12
};
enum TRUNK_STATE //self-defined channel state
{
TRK_IDLE, //idle
TRK_PICKUP, //off-hook
TRK_RECORD, //recording
TRK_OUTLINE, //off-line
TRK_RINGING //ringing
};
enum Control //recording working mode
{
VOICE_CTRL, //voice-control mode
VOLTAGE_CTRL, //voltage-control mode
DTMF_CTRL //code-control mode
};
[StructLayout(LayoutKind.Sequential)]public struct EVENT_SET_INFO
{
public uint dwWorkMode;
public IntPtr lpHandlerParam;
public uint dwOutCondition;
public uint dwOutParamVal;
public uint dwUser;
}
EVENT_SET_INFO EventSet = new EVENT_SET_INFO();
[StructLayout(LayoutKind.Sequential)]public struct TRK_STATE
{
public int WorkState; //self-defined channel state
public int ConState; //recording working mode
public string szCallerId; //CallerId
public char[] szDTMF; //DTMF
public int nIndex;
public bool bIgnoreLineVoltage;
}
TRK_STATE[] ChState = new TRK_STATE[1000];
public int nMaxCh;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
int nTemp;
ColumnHeader colHead;
colHead = new ColumnHeader();
colHead.Text ="Channel";
colHead.Width = 60;
this.listView1.Columns.Add(colHead);
colHead = new ColumnHeader();
colHead.Text = "Channel state";
colHead.Width = 90;
this.listView1.Columns.Add(colHead);
colHead = new ColumnHeader();
colHead.Text = "Working mode";
colHead.Width = 90;
this.listView1.Columns.Add(colHead);
colHead = new ColumnHeader();
colHead.Text = "Startup key";
colHead.Width = 52;
this.listView1.Columns.Add(colHead);
colHead = new ColumnHeader();
colHead.Text ="DTMF";
colHead.Width = 100;
this.listView1.Columns.Add(colHead);
colHead = new ColumnHeader();
colHead.Text ="CallerID";
colHead.Width = 100;
this.listView1.Columns.Add(colHead);
//load configuration file and initialize system
if(SsmStartCti("ShConfig.ini", "ShIndex.ini") == -1)
{
MessageBox.Show(SsmGetLastErrMsgA());
return;
}
//Judge if the number of initialized boards is the same as
//that of boards specified in the configuration file
if(SsmGetMaxUsableBoard() != SsmGetMaxCfgBoard())
{
MessageBox.Show(SsmGetLastErrMsgA());
return;
}
nMaxCh = SsmGetMaxCh();
if(nMaxCh == -1)
MessageBox.Show("Fail to call SsmGetMaxCh");
//Set event-mode
EventSet.dwWorkMode = 3;
EventSet.lpHandlerParam = this.Handle;
if(SsmSetEvent(-1, -1, true, ref EventSet) == -1)
MessageBox.Show("Fail to call SsmSetEvent");
//initialize variable
for(int i = 0; i < nMaxCh; i++)
{
nTemp = SsmGetChType(i);
if(nTemp == -1)
MessageBox.Show("Fail to call SsmGetChType");
else if(nTemp == 3)
{
ChState[i].nIndex = 0;
ChState[i].WorkState = (int)TRUNK_STATE.TRK_IDLE;
ChState[i].ConState = (int)Control.VOLTAGE_CTRL;
ChState[i].szDTMF = new char[100];
ChState[i].szCallerId = "";
nTemp = SsmGetIgnoreLineVoltage(i);
if(nTemp == 0) //detect voltage
ChState[i].bIgnoreLineVoltage = false;
else if(nTemp == 1)
ChState[i].bIgnoreLineVoltage = true;
//+++START+++ masked by sh , 2006-09-25
/*
if(SsmSetBargeInSens(i, 8) == -1) //set BargeIn sensitivity to 8
MessageBox.Show("Fail to call SsmSetBargeInSens");
if(SsmSetDtrmLineVoltage(i, 12) == -1) //set detection voltage of hook state to 12V
MessageBox.Show("Fail to call SsmSetDtrmLineVoltage");
*/
//+++ END +++ masked by sh , 2006-09-25
this.comboBox1.Items.Add(i.ToString());
}
else
{
ChState[i].nIndex = 0;
ChState[i].WorkState = -1;
ChState[i].ConState = -1;
ChState[i].szDTMF = new char[100];
ChState[i].szCallerId = "";
ChState[i].bIgnoreLineVoltage = false;
}
}
UpdateChList();
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
//+++START+++ added by sh for calling function SsmCloseCti(), 2006-9-25
if(SsmCloseCti() == -1)
MessageBox.Show("Fail to call SsmCloseCti");
//+++ END +++ added by sh for calling function SsmCloseCti(), 2006-9-25
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.listView1 = new System.Windows.Forms.ListView();
this.label1 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// listView1
//
this.listView1.Location = new System.Drawing.Point(16, 16);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(496, 152);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 208);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 16);
this.label1.TabIndex = 1;
this.label1.Text = "Channel ID";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.radioButton3);
this.groupBox1.Controls.Add(this.radioButton2);
this.groupBox1.Controls.Add(this.radioButton1);
this.groupBox1.Controls.Add(this.comboBox1);
this.groupBox1.Location = new System.Drawing.Point(16, 176);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(240, 104);
this.groupBox1.TabIndex = 2;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Recording Mode";
//
// radioButton3
//
this.radioButton3.Location = new System.Drawing.Point(112, 72);
this.radioButton3.Name = "radioButton3";
this.radioButton3.TabIndex = 3;
this.radioButton3.Text = "Code-control";
this.radioButton3.CheckedChanged += new System.EventHandler(this.radioButton3_CheckedChanged);
//
// radioButton2
//
this.radioButton2.Location = new System.Drawing.Point(112, 48);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(120, 24);
this.radioButton2.TabIndex = 2;
this.radioButton2.Text = "Voltage-control";
this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
//
// radioButton1
//
this.radioButton1.Location = new System.Drawing.Point(112, 24);
this.radioButton1.Name = "radioButton1";
this.radioButton1.TabIndex = 1;
this.radioButton1.Text = "Voice-control";
this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.Location = new System.Drawing.Point(16, 56);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(56, 20);
this.comboBox1.TabIndex = 0;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.button1);
this.groupBox2.Controls.Add(this.button2);
this.groupBox2.Controls.Add(this.button3);
this.groupBox2.Location = new System.Drawing.Point(272, 176);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(240, 104);
this.groupBox2.TabIndex = 3;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Other Functions";
//
// button1
//
this.button1.Location = new System.Drawing.Point(72, 24);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 23);
this.button1.TabIndex = 0;
this.button1.Text = "SetListen";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(72, 48);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(104, 23);
this.button2.TabIndex = 0;
this.button2.Text = "PlayFile";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(72, 72);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(104, 23);
this.button3.TabIndex = 0;
this.button3.Text = "SetAGC";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(528, 293);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.label1);
this.Controls.Add(this.listView1);
this.Controls.Add(this.groupBox1);
this.Name = "Form1";
this.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.Text = "Recorder-ATP";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public void UpdateChList()
{
int nTemp;
string str = "";
this.listView1.Items.Clear();
for(int i = 0; i < nMaxCh; i++)
{
ListViewItem lvi;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -