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

📄 form1.cs

📁 三汇CTI示例程序源码
💻 CS
📖 第 1 页 / 共 3 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO ;
using System.Resources;
using System.Text;
using System.Threading;
using System.Timers;
using System.Runtime.InteropServices;

namespace SHR_DEvent
{
	/// <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.Label label2;
		private System.Windows.Forms.RadioButton radioButton1;
		private System.Windows.Forms.RadioButton radioButton2;
		private System.Windows.Forms.RadioButton radioButton3;
		private System.Windows.Forms.RadioButton radioButton4;
		private System.Windows.Forms.RadioButton radioButton5;
		private System.Windows.Forms.RadioButton radioButton6;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Timer timer1;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.Button button2;

	
		[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, 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 void SsmGetLastErrMsg(byte[] szErrMsgBuf);	
		[DllImport("SHP_A3.dll")]public static extern int SsmGetChState(int ch);
		[DllImport("SHP_A3.dll")]public static extern int SsmChkRecToFile(int ch);
		[DllImport("SHP_A3.dll")]public static extern int SsmWaitForEventA(int dwTimeOut, ref SSM_EVENT pEvent);
		[DllImport("SHP_A3.dll")]public static extern int SsmStopListenTo(int ch1, int ch2);
		[DllImport("SHP_A3.dll")]public static extern int SsmListenTo(int ch1, int ch2);
		private System.ComponentModel.IContainer components;

		enum CH_STATE							//Channel state
		{
			CH_IDLE				= 0,			//Idle state
			CH_RING				= 1,			//Ringing state
			CH_ACTIVE			= 2,			//Active state
			CH_OFFLINE			= 3,			//Outline state
			CH_WAITFOR_ONHOOK	= 4				//Far end has been on hook ,waiting for near end on hook;
		};

		enum CH_LISTEN //Listen state
		{
			UNLISTEN			= 5,            //UNLISTEN
			LISTEN				= 6             //Listen 
		};

		enum CH_RECORD //Record state
		{
			UNRECORD			= 7,            //Unrecord 
			RECORD				= 8             //Record
		};

		enum DIRECTION //call dir
		{
			UNKNOWN				= 9,             //UNKNOWN 
			UP					= 10,            //Call out
			DOWN				= 11             //Call in
		};
		public const int  MAX_CALLID_LEN = 50;
		public const int  MAX_LCD_LEN	 = 300;
		public const int  MAX_ERRMSG_LEN = 300;
		public const ushort  E_CHG_ChState = 0x0018;
		public const ushort  E_RCV_DSTDChannel = 0x0041;
		public const int DST_OFFHOOK = 0x8;
		public const int DST_RING_ON =0x101f;
		public const int DST_MSG_CHG = 0x1008;
		public const int DST_RING_OFF = 0x1020;
		public const int DST_ONHOOK = 0xe;
		public const int DST_ABANDONED = 0x103a;
		public const int MAX_BUFFERLEN = 300;

		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
		};

		[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 CHANNEL
		{
			public int		  WorkState;				//Channel state
			public int		  IsListen;					//Listen state
			public int		  IsRecord;					//Record state
			public char[]     pCallId;					//Pho Num
			public int		  LCDLen;					//length of LCD information
			public int		  CallIdLen;				//length of call ID;
			public char[]     Lcd;						//LCD info
			public int		  Dir;						//Call dir  
			public char[]	  pErrMsg;					//Wrong info
		}

		
		[StructLayout(LayoutKind.Sequential)]unsafe public struct SSM_EVENT
		{
			public ushort 	wEventCode;
			public int		nReference;
			public int		dwParam;
			public int		dwUser;
			public int		dwSubReason;			//Event sub-reason
			public int		dwXtraInfo;				//Extra information
			public byte*			pvBuffer;
			public int      dwBufferLength;			//Length of buffer pointed by pvBuffer
			public int      dwDataLength;			//Length of data in buffer pointed by pvBuffer
			public int      dwEventFlag;            //Falgs of the following:
													//bit 0,	=1 - App created the event
													//			=0 - SHP_A3.DLL created the event
													//bit 1,	Reserved
													//bit 2,	=1 - data has been truncated
													//			=0 - data has not been truncated
			public int      dwReserved1;
			public long		llReserved2;
		};
		public int nTimer;
		CHANNEL[] ChannelState = new CHANNEL[200];
		public char[] szErrMsg;
		public int	MaxLine;
		public int	ListenChannel;
		public int	nRecFormat;
		public Thread ThreadHandle;

		unsafe public void ThreadHandleEvent()
		{
			byte* pucBuffer = stackalloc byte[MAX_BUFFERLEN];
			SSM_EVENT SsmEvent = new SSM_EVENT();
			char[]  szErrMsg = new char[400];
			int nretWaitForEvent;
			
			while(true)
			{
				SsmEvent.pvBuffer = pucBuffer;
				SsmEvent.dwBufferLength = MAX_BUFFERLEN;
				nretWaitForEvent = SsmWaitForEventA(50, ref SsmEvent);
				if(nretWaitForEvent == 0)
				{
					this.EventHandler(ref SsmEvent);
				}
				else if (nretWaitForEvent == -2)
				{
					WriteLog(SsmGetLastErrMsgA());
					break;
				}
			}
		}
	
		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
			
			ColumnHeader colHead;
			colHead = new ColumnHeader();
			colHead.Text ="Channel num";
			colHead.Width = 80;
			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 = "Listen state";
			colHead.Width = 90;
			this.listView1.Columns.Add(colHead);

			colHead = new ColumnHeader();
			colHead.Text = "Record state";
			colHead.Width = 85;
			this.listView1.Columns.Add(colHead);

			colHead = new ColumnHeader();
			colHead.Text ="Phone num";
			colHead.Width = 70;
			this.listView1.Columns.Add(colHead);

			colHead = new ColumnHeader();
			colHead.Text ="LCD info";
			colHead.Width = 230;
			this.listView1.Columns.Add(colHead);

			colHead = new ColumnHeader();
			colHead.Text ="Call direction";
			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;
			}

			MaxLine = SsmGetMaxCh();
			if(MaxLine == -1)
			{
				MessageBox.Show("Fail to call SsmGetMaxCh");
				return;
			}

			//Set event-mode
			EventSet.dwWorkMode = 1;
	
			if(SsmSetEvent(-1, -1, true, ref EventSet) == -1)
			{
				MessageBox.Show("Fail to call SsmSetEvent");
				return;
			}

			ListenChannel = MaxLine;
			InitChannelState();                            //Initialize channel info

			timer1.Enabled = true;
			ThreadHandle = new Thread(new ThreadStart(ThreadHandleEvent));
			ThreadHandle.Start();
			
			nRecFormat = -1;	//default format
			radioButton1.Checked = true;
			radioButton2.Checked = false;
			radioButton3.Checked = false;
			radioButton4.Checked = false;
			radioButton5.Checked = false;
			radioButton6.Checked = false;
		}
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			SsmCloseCti();			//close the driver
			ThreadHandle.Abort();	//abort the thread
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.listView1 = new System.Windows.Forms.ListView();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.radioButton1 = new System.Windows.Forms.RadioButton();
			this.radioButton2 = new System.Windows.Forms.RadioButton();
			this.radioButton3 = new System.Windows.Forms.RadioButton();
			this.radioButton4 = new System.Windows.Forms.RadioButton();
			this.radioButton5 = new System.Windows.Forms.RadioButton();
			this.radioButton6 = new System.Windows.Forms.RadioButton();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			this.SuspendLayout();
			// 
			// listView1
			// 
			this.listView1.Location = new System.Drawing.Point(16, 16);
			this.listView1.Name = "listView1";
			this.listView1.Size = new System.Drawing.Size(744, 360);
			this.listView1.TabIndex = 0;
			this.listView1.View = System.Windows.Forms.View.Details;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(48, 392);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(136, 16);
			this.label1.TabIndex = 1;
			this.label1.Text = "Record Coding Format:";
			this.label1.Click += new System.EventHandler(this.label1_Click);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(48, 424);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(136, 16);
			this.label2.TabIndex = 2;
			this.label2.Text = "Listened Channel:";
			// 
			// radioButton1
			// 
			this.radioButton1.Location = new System.Drawing.Point(200, 392);
			this.radioButton1.Name = "radioButton1";

⌨️ 快捷键说明

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