⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 三汇CTI示例程序源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
namespace DTP_Recorder
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListView listView1;
		private System.Windows.Forms.RadioButton radioButton1;
		private System.Windows.Forms.RadioButton radioButton2;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.RadioButton radioButton3;
		private System.Windows.Forms.RadioButton radioButton4;
		private System.Windows.Forms.RadioButton radioButton5;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Label label1;
		[DllImport("SHP_A3.dll")]public static extern int SpyRecToFile(int nCic, ushort wDirection,
			string pszFileName, int nCodecFormat,
			int dwStartPos, int dwBytes, 
			int dwTime,  int nMask);
		[DllImport("SHP_A3.dll")]public static extern int SpyGetCallInCh(int nCic);
		[DllImport("SHP_A3.dll")]public static extern int SpyGetCallOutCh(int nCic);
		[DllImport("SHP_A3.dll")]public static extern int SpyGetCalleeId(int nCic,byte[] pcCid);
		[DllImport("SHP_A3.dll")]public static extern int SpyStopRecToFile(int  nCic);
		[DllImport("SHP_A3.dll")]public static extern int SsmSetRecMixer(int ch, bool bEnRecMixer, int nMixerVolume);
		[DllImport("SHP_A3.dll")]public static extern int SpyGetMaxCic();
		[DllImport("SHP_A3.dll")]public static extern int SsmStartCti(string lpSsmCfgFileName, string lpIndexCfgFileName);
		[DllImport("SHP_A3.dll")]public static extern int SsmCloseCti();
		[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, int 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 SsmStopLinkFrom(int ch1,int ch2);
		[DllImport("SHP_A3.dll")]public static extern int SpyGetCallerId(int nCic,byte[] pcCid);
		[DllImport("SHP_A3.dll")]public static extern int SsmLinkFrom(int ch1,int ch2);
		[DllImport("SHP_A3.dll")]public static extern int SpyChToCic(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_CHG_RcvDTMF = 0x000C;
		public const int E_PROC_RecordEnd = 0x0013;
		public const int E_CHG_SpyState = 0x0031; 
		public const int MAX_CIC = 1000;
		public const int S_SPY_STANDBY = 0;
		public const int S_SPY_RCVPHONUM = 105;
		public const int S_SPY_RINGING = 2;				
		public const int S_SPY_TALKING = 3;

		enum CIRCUIT_STATE
		{
			CIRCUIT_IDLE,			//Idle state
			CIRCUIT_RCV_PHONUM,		//State of receiving phone number
			CIRCUIT_RINGING,		//State of ringing
			CIRCUIT_TALKING			//State of talking
		};


		enum RECORD_DIRECTION
		{
			CALL_IN_RECORD,		//Incoming call recording
			CALL_OUT_RECORD,	//Outgoing call recording
			MIX_RECORD			//Mix-record of incoming/outgoing call 
		};


		[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 CIC_STRUCT
		{
			public int  nCicState;				//State of monitored circuits
			public string szCallerId;		//Calling party number
			public string szCalleeId;		//Called party number
			public char[] szCallInDtmf;		//DTMF received on the incoming channel
			public char[] szCallOutDtmf;	//DTMF received on the outgoing channel
			public ushort wRecDirection;			//Recording direction
			public int  nCallInCh;				//Incoming channel
			public int  nCallOutCh;			//Outgoing channel
			public int  nCallInIndex;			//Used to denote which number is the DTMF received on the incoming channel
			public int  nCallOutIndex;			//Used to denote which number is the DTMF received on the outgoing channel	
		}
		CIC_STRUCT[] CicState = new CIC_STRUCT[1000];

		
		public int nMaxCic;
		public int m_nCallFnMode = 0;

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
			ColumnHeader colHead;
			colHead = new ColumnHeader();
			colHead.Text ="Cic";
			colHead.Width = 60;
			this.listView1.Columns.Add(colHead);
			
			colHead = new ColumnHeader();
			colHead.Text = "CicState";
			colHead.Width = 90;
			this.listView1.Columns.Add(colHead);

			colHead = new ColumnHeader();
			colHead.Text = "CallerId";
			colHead.Width = 90;
			this.listView1.Columns.Add(colHead);

			colHead = new ColumnHeader();
			colHead.Text = "CalleeId";
			colHead.Width = 90;
			this.listView1.Columns.Add(colHead);

			colHead = new ColumnHeader();
			colHead.Text ="InComingCh:DTMF";
			colHead.Width = 120;
			this.listView1.Columns.Add(colHead);

			colHead = new ColumnHeader();
			colHead.Text ="OutgoingCh:DTMF";
			colHead.Width = 120;
			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;
			}

			nMaxCic = SpyGetMaxCic();
			if(nMaxCic == -1)
				MessageBox.Show("Fail to call SpyGetMaxCic");
			//Set event-mode
			EventSet.dwWorkMode = 3;
			EventSet.lpHandlerParam = this.Handle;
			if(SsmSetEvent(-1, -1, true, ref EventSet) == -1)
				MessageBox.Show("Fail to call SsmSetEvent");
			if(SsmSetEvent(E_CHG_SpyState, -1, true, ref EventSet) == -1)
				MessageBox.Show("Fail to call SsmSetEvent when setting E_CHG_SpyState");
			
			//initialize variable
			for(int i = 0; i < nMaxCic; i++)
			{
				CicState[i].szCallInDtmf = new char[100];
				CicState[i].szCallOutDtmf = new char[100];
				CicState[i].szCallerId = "";
				CicState[i].szCalleeId = "";
				CicState[i].nCicState = (int)CIRCUIT_STATE.CIRCUIT_IDLE;
				CicState[i].nCallInIndex = 0;
				CicState[i].nCallOutIndex = 0;
				CicState[i].wRecDirection = (int)RECORD_DIRECTION.MIX_RECORD;	    //mix-record
				CicState[i].nCallInCh = -1;	
				CicState[i].nCallOutCh = -1;
				this.comboBox1.Items.Add(i.ToString());
		
			}
			//	UpdateChList();
		}
		public void UpdateCircuitListCtrl()
		{		
			string str = "";

			this.listView1.Items.Clear();
	
			for(int i = 0; i < nMaxCic; i++)
			{
				ListViewItem lvi;
				ListViewItem.ListViewSubItem lvsi;

				lvi = new ListViewItem();
				lvi.Text = i.ToString();
			
				switch(CicState[i].nCicState)
				{
					case (int)CIRCUIT_STATE.CIRCUIT_IDLE:
						str = "Idle";
						break;
					case (int)CIRCUIT_STATE.CIRCUIT_RCV_PHONUM:
						str = "Receiving Phone number";
						break;
					case (int)CIRCUIT_STATE.CIRCUIT_RINGING:
						str = "Ringing";
						break;
					case (int)CIRCUIT_STATE.CIRCUIT_TALKING:
						str = "Talking";
						break;
				}
				lvsi = new ListViewItem.ListViewSubItem();
				lvsi.Text = str;
				lvi.SubItems.Add(lvsi);
		
				lvsi = new ListViewItem.ListViewSubItem();
				lvsi.Text = CicState[i].szCallerId;
				lvi.SubItems.Add(lvsi);

				lvsi = new ListViewItem.ListViewSubItem();
				lvsi.Text = CicState[i].szCalleeId;
				lvi.SubItems.Add(lvsi);

				lvsi = new ListViewItem.ListViewSubItem();
				str = "";
				str = new string(CicState[i].szCallInDtmf);
				lvsi.Text = CicState[i].nCallInCh.ToString() + ":" + str;
				lvi.SubItems.Add(lvsi);

				lvsi = new ListViewItem.ListViewSubItem();
				str = "";
				str = new string(CicState[i].szCallOutDtmf);
				lvsi.Text = CicState[i].nCallOutCh.ToString() + ":" + str;
				lvi.SubItems.Add(lvsi);
				this.listView1.Items.Add(lvi);
			}
			
		}

			
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if(SsmCloseCti() == -1)
				MessageBox.Show("Fail to call SsmCloseCti");
			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.radioButton1 = new System.Windows.Forms.RadioButton();
			this.radioButton2 = new System.Windows.Forms.RadioButton();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.radioButton3 = new System.Windows.Forms.RadioButton();
			this.radioButton4 = new System.Windows.Forms.RadioButton();
			this.radioButton5 = new System.Windows.Forms.RadioButton();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.label1 = new System.Windows.Forms.Label();
			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(616, 304);
			this.listView1.TabIndex = 0;
			this.listView1.View = System.Windows.Forms.View.Details;
			this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
			// 
			// radioButton1
			// 
			this.radioButton1.Checked = true;
			this.radioButton1.Location = new System.Drawing.Point(16, 24);
			this.radioButton1.Name = "radioButton1";
			this.radioButton1.Size = new System.Drawing.Size(208, 32);
			this.radioButton1.TabIndex = 1;
			this.radioButton1.TabStop = true;
			this.radioButton1.Text = "Call the function with circuit number as its parameter";
			this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
			// 
			// radioButton2
			// 
			this.radioButton2.Location = new System.Drawing.Point(16, 56);
			this.radioButton2.Name = "radioButton2";
			this.radioButton2.Size = new System.Drawing.Size(208, 32);
			this.radioButton2.TabIndex = 2;
			this.radioButton2.Text = "Call the function with channel number as its parameter";
			this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
			// 
			// comboBox1
			// 
			this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.comboBox1.Location = new System.Drawing.Point(56, 40);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(56, 20);
			this.comboBox1.TabIndex = 3;
			this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
			// 
			// radioButton3
			// 
			this.radioButton3.Location = new System.Drawing.Point(120, 16);
			this.radioButton3.Name = "radioButton3";
			this.radioButton3.Size = new System.Drawing.Size(208, 24);
			this.radioButton3.TabIndex = 4;
			this.radioButton3.Text = "Record only incoming channels";
			this.radioButton3.CheckedChanged += new System.EventHandler(this.radioButton3_CheckedChanged);
			// 
			// radioButton4
			// 
			this.radioButton4.Location = new System.Drawing.Point(120, 40);
			this.radioButton4.Name = "radioButton4";
			this.radioButton4.Size = new System.Drawing.Size(208, 24);
			this.radioButton4.TabIndex = 5;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -