首页 新闻 会员 周边 捐助

多线程的困扰

0
[待解决问题]

 八个线程 在 踢 足球,并且有八个球门,每个线程对应一个门(这里的门是固定的),一个裁判来监督线程是否犯规,然后再指定犯规的线程进行罚球,裁判要求对应犯规的线程将球踢进对应编号的球门。

   1 using System;
   2 using System.Collections.Generic;
   3 using System.ComponentModel;
   4 using System.Data;
   5 using System.Drawing;
   6 using System.Text;
   7 using System.Windows.Forms;
   8 using System.Xml;
   9 using ClassLibrary;
  10 using System.Net.NetworkInformation;
  11 using System.Net;
  12 using System.Threading;
  13 using System.Runtime.Remoting.Channels;
  14 using System.Runtime.Remoting;
  15 using System.Runtime.Remoting.Channels.Tcp;
  16 using System.Linq;
  17 
  18 namespace PoneMananger
  19 {
  20 
  21 
  22     public partial class TelManagerTest : Form
  23     {
  24         XmlDocument xmlDoc;
  25         common bll = new common();
  26         public int m_DriverOpenFlag, m_TotalChannel, m_TotalVoiceChannel, m_TotalFaxChannel;
  27         LINE[] m_Line;
  28 
  29         delegate void dRunBall(GxVoiceAPI.GxVoice.GX_MESSAGE_INFO _MessageBuffer, uint _intRing, char[] _ctemp);//委托查询单行数据添加到原表中
  30         dRunBall _dRunBall;
  31 
  32         public TelManagerTest()
  33         {
  34             InitializeComponent();
  35         }
  36 
  37         private void TelManagerTest_Load(object sender, EventArgs e)
  38         {
  39             if (!PortInUse(2000))
  40             {
  41                 _dRunBall = new dRunBall(RunBall);
  42                 //用构造函数初始化监听端口,两种方式,这里用TCP 
  43                 TcpServerChannel channel = new TcpServerChannel(2000);
  44                 ChannelServices.RegisterChannel(channel, false);//向信道服务注册信道
  45                 RemotingConfiguration.RegisterWellKnownServiceType(typeof(common), "common", WellKnownObjectMode.SingleCall);
  46 
  47             }
  48             common.modelinfo.Clear();
  49             LisnClient();
  50             InitialGxVoice();
  51             timer1.Start();
  52         }
  53 
  54         /// <summary>
  55         /// 端口的检测
  56         /// </summary>
  57         /// <param name="port"></param>
  58         /// <returns></returns>
  59         public static bool PortInUse(int port)
  60         {
  61             bool inUse = false;
  62 
  63             IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
  64             IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();
  65 
  66             foreach (IPEndPoint endPoint in ipEndPoints)
  67             {
  68                 if (endPoint.Port == port)
  69                 {
  70                     inUse = true;
  71                     break;
  72                 }
  73             }
  74             return inUse;
  75         }
  76 
  77         public void LisnClient()
  78         {
  79             System.Threading.Thread threadtest;
  80             xmlDoc = new XmlDocument();
  81             xmlDoc.Load("ipconfig.xml"); //加载xml文件
  82             //获取bookshop节点的所有子节点 
  83             XmlNodeList nodeList = xmlDoc.SelectSingleNode("IPSettings").ChildNodes;
  84 
  85             //遍历所有子节点 
  86             foreach (XmlNode xn in nodeList)
  87             {
  88                 XmlElement xe = (XmlElement)xn; //将子节点类型转换为XmlElement类型                
  89 
  90                 int ChannelNo = int.Parse(xe.GetAttribute("key"));
  91                 string value = xe.GetAttribute("value");
  92                 switch (ChannelNo)
  93                 {
  94                     case 0:
  95                         //本地
  96                         if (!common.modelinfo.Keys.Contains(ChannelNo.ToString()))
  97                         {
  98                             common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
  99                             bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 100                         }
 101                         else
 102                         {
 103                             if (!string.IsNullOrEmpty(bll.GetModel(ChannelNo.ToString()).CallIp))
 104                             {
 105                                 common.modelinfo.Remove(ChannelNo.ToString());
 106                                 common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
 107                                 bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 108                             }
 109                         }
 110                         threadtest = new Thread(new ThreadStart(StartCardWorkNew));
 111                         threadtest.Start();
 112                         break;
 113                     case 1:
 114                         //张佳
 115                         if (!common.modelinfo.Keys.Contains(ChannelNo.ToString()))
 116                         {
 117                             common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
 118                             bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 119                         }
 120                         else
 121                         {
 122                             if (!string.IsNullOrEmpty(bll.GetModel(ChannelNo.ToString()).CallIp))
 123                             {
 124                                 common.modelinfo.Remove(ChannelNo.ToString());
 125                                 common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
 126                                 bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 127                             }
 128                         }
 129                         threadtest = new Thread(new ThreadStart(StartCardWorkNew));
 130                         threadtest.Start();
 131                         break;
 132                     case 2:
 133                         //田洪帅
 134                         if (!common.modelinfo.Keys.Contains(ChannelNo.ToString()))
 135                         {
 136                             common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
 137                             bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 138                         }
 139                         else
 140                         {
 141                             if (!string.IsNullOrEmpty(bll.GetModel(ChannelNo.ToString()).CallIp))
 142                             {
 143                                 common.modelinfo.Remove(ChannelNo.ToString());
 144                                 common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
 145                                 bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 146                             }
 147                         }
 148                         threadtest = new Thread(new ThreadStart(StartCardWorkNew));
 149                         threadtest.Start();
 150                         break;
 151                     case 3:
 152                         //刘聪
 153                         if (!common.modelinfo.Keys.Contains(ChannelNo.ToString()))
 154                         {
 155                             common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
 156                             bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 157                         }
 158                         else
 159                         {
 160                             if (!string.IsNullOrEmpty(bll.GetModel(ChannelNo.ToString()).CallIp))
 161                             {
 162                                 common.modelinfo.Remove(ChannelNo.ToString());
 163                                 common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
 164                                 bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 165                             }
 166                         }
 167                         threadtest = new Thread(new ThreadStart(StartCardWorkNew));
 168                         threadtest.Start();
 169                         break;
 170                     case 4:
 171                         //王毅力
 172                         if (!common.modelinfo.Keys.Contains(ChannelNo.ToString()))//bll.GetModel(ChannelNo.ToString())
 173                         {
 174                             common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
 175                             bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 176                         }
 177                         else
 178                         {
 179                             if (!string.IsNullOrEmpty(bll.GetModel(ChannelNo.ToString()).CallIp))
 180                             {
 181                                 common.modelinfo.Remove(ChannelNo.ToString());
 182                                 common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
 183                                 bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 184                             }
 185                         }
 186                         threadtest = new Thread(new ThreadStart(StartCardWorkNew));
 187                         threadtest.Start();
 188                         break;
 189                     case 5:
 190                         //李姐
 191                         if (!common.modelinfo.Keys.Contains(ChannelNo.ToString()))
 192                         {
 193                             common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
 194                             bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 195                         }
 196                         else
 197                         {
 198                             if (!string.IsNullOrEmpty(bll.GetModel(ChannelNo.ToString()).CallIp))
 199                             {
 200                                 common.modelinfo.Remove(ChannelNo.ToString());
 201                                 common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
 202                                 bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 203                             }
 204                         }
 205                         threadtest = new Thread(new ThreadStart(StartCardWorkNew));
 206                         threadtest.Start();
 207                         break;
 208                     case 6:
 209                         //张睿
 210 
 211                         if (!common.modelinfo.Keys.Contains(ChannelNo.ToString()))
 212                         {
 213                             common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
 214                             bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 215                         }
 216                         else
 217                         {
 218                             if (!string.IsNullOrEmpty(bll.GetModel(ChannelNo.ToString()).CallIp))
 219                             {
 220                                 common.modelinfo.Remove(ChannelNo.ToString());
 221                                 common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
 222                                 bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 223                             }
 224                         }
 225                         threadtest = new Thread(new ThreadStart(StartCardWorkNew));
 226                         threadtest.Start();
 227                         break;
 228                     case 7:
 229                         if (!common.modelinfo.Keys.Contains(ChannelNo.ToString()))
 230                         {
 231                             common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
 232                             bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 233                         }
 234                         else
 235                         {
 236                             if (!string.IsNullOrEmpty(bll.GetModel(ChannelNo.ToString()).CallIp))
 237                             {
 238                                 common.modelinfo.Remove(ChannelNo.ToString());
 239                                 common.modelinfo.Add(ChannelNo.ToString(), new TestModel());
 240                                 bll.SetModelValue("CallIp", value, bll.GetModel(ChannelNo.ToString()));
 241                             }
 242                         }
 243                         threadtest = new Thread(new ThreadStart(StartCardWorkNew));
 244                         threadtest.Start();
 245                         break;
 246                     default:
 247                         break;
 248                 }
 249             }
 250         }
 251 
 252         private bool InitialGxVoice()
 253         {
 254             try
 255             {
 256                 m_DriverOpenFlag = GxVoiceAPI.GxVoice.GX_InitializeSystem();
 257                 if (m_DriverOpenFlag != GxVoiceAPI.GxVoice.GX_OK)
 258                 {
 259                     foreach (KeyValuePair<string, TestModel> item in common.modelinfo)
 260                     {
 261                         bll.SetModelValue("IsInitialUsbGX", "false", item.Value);
 262                         bll.SetModelValue("Msg", "初始化硬件失败!", item.Value);
 263                     }
 264 
 265                     System.Windows.Forms.MessageBox.Show("初始化硬件失败!");
 266                     return false;
 267                 }
 268 
 269                 m_TotalChannel = GxVoiceAPI.GxVoice.GX_GetTotalChannelCount();
 270                 m_TotalVoiceChannel = GxVoiceAPI.GxVoice.GX_GetTotalVoiceChannel();
 271 
 272                 if (m_TotalVoiceChannel > GxVoiceAPI.GxVoice.MAX_CHANNEL_NUM)
 273                     m_TotalVoiceChannel = GxVoiceAPI.GxVoice.MAX_CHANNEL_NUM;
 274                 m_Line = new LINE[m_TotalVoiceChannel];
 275                 dgv电话管理.Rows.Clear();
 276                 int nType;
 277                 string strType;
 278                 // string strStatus;
 279                 for (ushort i = 0; i < m_TotalVoiceChannel; i++)
 280                 {
 281                     #region 注释掉暂时不用的状态
 282                     //    ushort cStatus = GxVoiceAPI.GxVoice.GX_GetChannelStatus(i);
 283                     //    switch (cStatus)
 284                     //    {
 285                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_IDLE:
 286                     //            strStatus = "未置";
 287                     //            break;
 288                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_OPEN:
 289                     //            strStatus = "内线";
 290                     //            break;
 291                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_TRUNK_HOOK:
 292                     //            strStatus = "外线";
 293                     //            break;
 294                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_USER_RING:
 295                     //            strStatus = "录音";
 296                     //            break;
 297                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_PLAY:
 298                     //            strStatus = "混合";
 299                     //            break;
 300                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_RECORD:
 301                     //            strStatus = "未置";
 302                     //            break;
 303                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_GENERATE_DTMF:
 304                     //            strStatus = "内线";
 305                     //            break;
 306                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_SEND_FSK:
 307                     //            strStatus = "外线";
 308                     //            break;
 309                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_GENERATE_SIGNAL:
 310                     //            strStatus = "录音";
 311                     //            break;
 312                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_DETECT_DTMF:
 313                     //            strStatus = "混合";
 314                     //            break;
 315                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_DETECT_CID:
 316                     //            strStatus = "录音";
 317                     //            break;
 318                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_DETECT_FSK:
 319                     //            strStatus = "混合";
 320                     //            break;
 321                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_DETECT_SIGNAL:
 322                     //            strStatus = "未置";
 323                     //            break;
 324                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_DETECT_POL:
 325                     //            strStatus = "内线";
 326                     //            break;
 327                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_RECEIVE_FAX:
 328                     //            strStatus = "外线";
 329                     //            break;
 330                     //        case GxVoiceAPI.GxVoice.CHANNEL_STATUS_AUTO_DIAL_OUT:
 331                     //            strStatus = "录音";
 332                     //            break;
 333                     //        default:
 334                     //            strStatus = "未知";
 335                     //            break;
 336                     //    } 
 337                     #endregion
 338                     nType = GxVoiceAPI.GxVoice.GX_GetChannelType(i);
 339                     m_Line[i].Status = STATUS.STATUS_IDLE;  //通道状态
 340                     m_Line[i].iType = nType;                //通道类型
 341                     m_Line[i].CallerID = "";                //来电号码
 342                     m_Line[i].Dtmf = "";                    //dtmf按键
 343                     m_Line[i].HookOff = 0;                  //摘机标志
 344                     m_Line[i].Ring = 0;                     //振铃标志
 345                     m_Line[i].TimeCount = 0;
 346 
 347                     switch (nType)
 348                     {
 349                         case GxVoiceAPI.GxVoice.CHANNEL_TYPE_NONE:
 350                             strType = "未置";
 351                             break;
 352                         case GxVoiceAPI.GxVoice.CHANNEL_TYPE_USER:
 353                             strType = "内线";
 354                             break;
 355                         case GxVoiceAPI.GxVoice.CHANNEL_TYPE_TRUNK:
 356                             strType = "外线";
 357                             break;
 358                         case GxVoiceAPI.GxVoice.CHANNEL_TYPE_RECORD:
 359                             strType = "录音";
 360                             break;
 361                         case GxVoiceAPI.GxVoice.CHANNEL_TYPE_MIX:
 362                             strType = "混合";
 363                             break;
 364                         default:
 365                             strType = "未知";
 366                             break;
 367                     }
 368                     /*lv电话管理.Items.Add("Channel "+ i.ToString());
 369                     lv电话管理.Items[i].SubItems.Add(strType);
 370                     lv电话管理.Items[i].SubItems.Add("Idle");*/
 371                     dgv电话管理.Rows.Add(1);
 372                     dgv电话管理.Rows[i].Cells["id"].Value = i.ToString();
 373                     dgv电话管理.Rows[i].Cells["chanelno"].Value = i.ToString();
 374                     dgv电话管理.Rows[i].Cells["chaneltype"].Value = strType;
 375                     dgv电话管理.Rows[i].Cells["chanelstate"].Value = "空闲";
 376                     dgv电话管理.Rows[i].Cells["callcode"].Value = "";
 377                     dgv电话管理.Rows[i].Cells["calltype"].Value = "";
 378                     dgv电话管理.Rows[i].Cells["calldate"].Value = "";
 379 
 380                     if (nType != GxVoiceAPI.GxVoice.CHANNEL_TYPE_NONE)
 381                     {
 382                         if (GxVoiceAPI.GxVoice.GX_OpenChannel(i) == GxVoiceAPI.GxVoice.GX_OK)
 383                         {
 384                             GxVoiceAPI.GxVoice.GX_StartDetectDTMF(i, 0);
 385                             GxVoiceAPI.GxVoice.GX_StartDetectCallerID(i);
 386 
 387                             /***********************************************************/
 388                             /*********************AGC自动增益功能 **********************/
 389                             /************USB1-2路和USB4-8、PCI的函数不一样,请注意******/
 390                             /***********************************************************/
 391                             //USB4-8和PCI
 392                             //GxVoiceAPI.GxVoice.GX_SetRecordAgc(i, 1, 1400, 23);
 393                             //GxVoiceAPI.GxVoice.GX_SetPlayAgc(i, 1, 1400, 23);*/
 394 
 395                             //USB1-2
 396                             //GxVoiceAPI.GxVoice.GX_SetRecordAgcPar(i, 1, 1050, 17, 3900, 196);
 397                         }
 398                     }
 399                     bll.SetModelValue("IsInitialUsbGX", "true", bll.GetModel(i.ToString()));
 400                 }
 401                 return true;
 402             }
 403             catch (Exception ex)
 404             {
 405                 foreach (KeyValuePair<string, TestModel> item in common.modelinfo)
 406                 {
 407                     bll.SetModelValue("IsInitialUsbGX", "false", item.Value);
 408                     bll.SetModelValue("Msg", "初始化硬件失败!", item.Value);
 409                 }
 410                 return true;
 411             }
 412         }
 413 
 414         private bool ReleaseGxVoice()
 415         {
 416             if (m_DriverOpenFlag == GxVoiceAPI.GxVoice.GX_OK)
 417             {
 418                 for (int i = 0; i <= m_TotalVoiceChannel - 1; i++)
 419                 {
 420                     GxVoiceAPI.GxVoice.GX_StopAllOperate((ushort)i);
 421                     GxVoiceAPI.GxVoice.GX_CloseChannel((ushort)i);
 422                 }
 423                 GxVoiceAPI.GxVoice.GX_CloseSystem();
 424             }
 425             dgv电话管理.Rows.Clear();
 426             return true;
 427 
 428         }
 429 
 430 
 431         #region 不同球员的踢球动作
 432         private void xunhuan1(GxVoiceAPI.GxVoice.GX_MESSAGE_INFO MessageBuffer, ushort MessageCode, uint intRing, char[] ctemp)
 433         {
 434             if (m_Line[0].Status == STATUS.STATUS_IDLE)
 435             {
 436                 #region STATUS_IDLE
 437                 switch (MessageCode)
 438                 {
 439                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF方式的主叫事件
 440                         //before hook off,dtmf is dtmf cid.
 441 
 442                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(0, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
 443                         {
 444                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39)     //0-9
 445                             {
 446                                 m_Line[0].CallerID += ctemp[0].ToString();
 447                                 bll.SetModelValue("CallCodeList", m_Line[0].Dtmf, bll.GetModel(0.ToString()));
 448                                 dgv电话管理.Rows[0].Cells["callcode"].Value = m_Line[0].CallerID;
 449                                 dgv电话管理.Rows[0].Cells["calltype"].Value = "呼入";
 450                                 dgv电话管理.Rows[0].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
 451                             }
 452                         }
 453                         break;
 454                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_DTMF://有DTMF方式的主叫事
 455                         StringBuilder CallerIDString = new StringBuilder(256);//要取得出参 必须定义成StringBuilder 给内存分配空间
 456                         if (GxVoiceAPI.GxVoice.GX_GetDTMFCallerID(0, CallerIDString) == GxVoiceAPI.GxVoice.GX_OK)
 457                         {
 458                             bll.SetModelValue("Call_Code", CallerIDString.ToString(), bll.GetModel(0.ToString()));
 459                             ushort StopDTMF = GxVoiceAPI.GxVoice.GX_StopDetectDTMF(0);//停止检测DTMF按键
 460                             ushort ClearDTMF = GxVoiceAPI.GxVoice.GX_ClearDTMFBuffer(0);//清除某一通道已经识别出来的但仍然没有被取走的DTMF按键。
 461 
 462                             GxVoiceAPI.GxVoice.GX_StartTimeOutForWindows(0, 50);
 463                         }
 464                         // common.EventName.Add("有DTMF方式的主叫事件");
 465                         break;
 466                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_FSK:
 467                         {
 468                             char[] CIDdt = new char[50];        //来电时间                                
 469                             char[] CIDTelNo = new char[50];     //主叫号码                                
 470                             char[] CIDName = new char[50];      //主叫名字[一般没用]
 471 
 472                             if (GxVoiceAPI.GxVoice.GX_GetFskCallerID(0, CIDdt, CIDTelNo, CIDName) == GxVoiceAPI.GxVoice.GX_OK)
 473                             {
 474                                 m_Line[0].CallerID = "";
 475                                 dgv电话管理.Rows[0].Cells["chanelstate"].Value = "外线来电";
 476                                 GxVoiceAPI.GxVoice.GX_StartDetectCallerID(0);//接收FSK来电号码后,必需再调用此函数,否则下一个来电无法监测得到
 477                                 m_Line[0].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo)).Trim("\0".ToCharArray()).Trim("\n".ToCharArray());
 478                                 //m_Line[0].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo));
 479 
 480                                 dgv电话管理.Rows[0].Cells["callcode"].Value = m_Line[0].CallerID;
 481                                 dgv电话管理.Rows[0].Cells["calltype"].Value = "呼入";
 482                                 dgv电话管理.Rows[0].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
 483                             }
 484                         }
 485                         break;
 486 
 487                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_END:
 488                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "放音结束";
 489                         break;
 490                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_EXIT:
 491                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "放音退出";
 492                         break;
 493                     case GxVoiceAPI.GxVoice.MESSAGE_GENERATE_DTMF_END:
 494                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "发码结束";
 495                         break;
 496                     case GxVoiceAPI.GxVoice.MESSAGE_SEND_FSK_END:
 497                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "FSK结束";
 498                         break;
 499                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DIAL_TONE:
 500                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "拨号音";
 501                         break;
 502                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BUSY_TONE:
 503                         bll.ClearModel(bll.GetModel(0.ToString()));
 504                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "忙音";
 505                         dgv电话管理.Rows[0].Cells["callcode"].Value = "";
 506                         dgv电话管理.Rows[0].Cells["calldate"].Value = "";
 507                         dgv电话管理.Rows[0].Cells["calltype"].Value = "";
 508                         m_Line[0].HookOff = 1;
 509                         m_Line[0].CallerID = "";
 510                         m_Line[0].Ring = 0;
 511                         m_Line[0].Status = STATUS.STATUS_RECORDING;
 512                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "空闲";
 513 
 514                         ctemp = new char[100];
 515                         break;
 516                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BACK_TONE:
 517                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "回铃音";
 518                         break;
 519                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TONE_DATA:
 520                         break;
 521                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_HELLO_VOICE:
 522                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "爆发音";
 523                         break;
 524                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_SILENCE_DATA:
 525                         if (MessageBuffer.Parameter[0] == 0)
 526                             dgv电话管理.Rows[0].Cells["chanelstate"].Value = "无声音";
 527                         else
 528                             dgv电话管理.Rows[0].Cells["chanelstate"].Value = "有声音";
 529                         break;
 530                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TIME_OUT:
 531                         bll.ClearModel(bll.GetModel(0.ToString()));
 532                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "超时";
 533                         dgv电话管理.Rows[0].Cells["callcode"].Value = "";
 534                         dgv电话管理.Rows[0].Cells["calldate"].Value = "";
 535                         dgv电话管理.Rows[0].Cells["calltype"].Value = "";
 536                         m_Line[0].HookOff = 1;
 537                         m_Line[0].CallerID = "";
 538                         m_Line[0].Ring = 0;
 539                         m_Line[0].Status = STATUS.STATUS_RECORDING;
 540                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "空闲";
 541                         ctemp = new char[100];
 542                         break;
 543 
 544                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_OFF:
 545                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "内线摘机";
 546                         break;
 547                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_ON:
 548                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "内线挂机";
 549                         break;
 550                     case GxVoiceAPI.GxVoice.MESSAGE_USER_PICK_UP:
 551                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "内线拍叉";
 552                         break;
 553                     case GxVoiceAPI.GxVoice.MESSAGE_USER_RING_END:
 554                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "内线震铃结束";
 555                         break;
 556                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_RING:
 557                         m_Line[0].Ring = 1;
 558                         m_Line[0].TimeCount = 0;
 559                         intRing = MessageBuffer.Parameter[0];
 560                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "外线震铃" + Convert.ToString(intRing);
 561                         break;
 562                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_POLE:
 563                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "极性反转";
 564                         break;
 565                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_PICK_UP_END:
 566                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "拍叉结束";
 567                         break;
 568                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_OFF:
 569 
 570                         ushort listen = GxVoiceAPI.GxVoice.GX_ListenChannel(0, 0);//通道监听
 571                         ushort link = GxVoiceAPI.GxVoice.GX_SetLink(0, 0); //两路连接通话 
 572                         bll.SetModelValue("IsJieTing", "true", bll.GetModel(0.ToString()));
 573                         bll.SetModelValue("DateStart", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(0.ToString()));
 574 
 575                         string wavName = "[" + 0.ToString() + "]" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".wav";
 576                         bll.SetModelValue("FileName", wavName, bll.GetModel(0.ToString()));
 577                         GxVoiceAPI.GxVoice.GX_StartRecordWaveFile(0, "C:\\voice\\" + wavName, 0, 0xFFFFFFFF, (char)0x00);
 578                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "录音摘机";
 579                         dgv电话管理.Rows[0].Cells["callcode"].Value = "";
 580                         m_Line[0].HookOff = 1;
 581                         m_Line[0].Ring = 0;
 582                         m_Line[0].Status = STATUS.STATUS_RECORDING;
 583                         break;
 584                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_RING:
 585                         bll.SetModelValue("IsCall", "true", bll.GetModel(0.ToString()));
 586                         bll.SetModelValue("0", 0.ToString(), bll.GetModel(0.ToString()));
 587 
 588                         m_Line[0].Ring = 1;
 589                         m_Line[0].TimeCount = 0;
 590                         intRing = MessageBuffer.Parameter[0];
 591                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "录音震铃" + Convert.ToString(intRing);
 592                         break;
 593                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
 594                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "录音断线";
 595                         dgv电话管理.Rows[0].Cells["callcode"].Value = "";
 596                         dgv电话管理.Rows[0].Cells["calltype"].Value = "";
 597                         dgv电话管理.Rows[0].Cells["calldate"].Value = "";
 598                         m_Line[0].CallerID = "";
 599                         m_Line[0].Dtmf = "";
 600                         m_Line[0].HookOff = 0;
 601                         m_Line[0].Ring = 0;
 602                         break;
 603                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_NO_OPEN_CIRCLE:
 604                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "录音接线";
 605                         dgv电话管理.Rows[0].Cells["callcode"].Value = "";
 606                         dgv电话管理.Rows[0].Cells["calltype"].Value = "";
 607                         dgv电话管理.Rows[0].Cells["calldate"].Value = "";
 608                         m_Line[0].CallerID = "";
 609                         m_Line[0].Dtmf = "";
 610                         m_Line[0].HookOff = 0;
 611                         m_Line[0].Ring = 0;
 612                         break;
 613 
 614                 }
 615                 #endregion
 616             }
 617             else if (m_Line[0].Status == STATUS.STATUS_RECORDING)
 618             {
 619                 #region STATUS_RECORDING
 620                 switch (MessageCode)
 621                 {
 622                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF按键事件
 623                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(0, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
 624                         {
 625                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39) //0-9
 626                             {
 627                                 m_Line[0].Dtmf += Convert.ToString(ctemp[0]);
 628                                 dgv电话管理.Rows[0].Cells["callcode"].Value = m_Line[0].Dtmf;
 629                                 bll.SetModelValue("CallCodeList", m_Line[0].Dtmf, bll.GetModel(0.ToString()));
 630                             }
 631                         }
 632                         break;
 633                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_ON:
 634                         bll.SetModelValue("IsOverCall", "true", bll.GetModel(0.ToString()));
 635                         bll.SetModelValue("DateStop", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(0.ToString()));
 636 
 637                         ushort linkover = GxVoiceAPI.GxVoice.GX_ClearLink(0, 0);  //两路断开通话
 638                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(0);//停止录音
 639                         GxVoiceAPI.GxVoice.GX_UnListenChannel(0);//停止监听
 640 
 641                         bll.SetModelValue("Date", DateDiff(bll.GetModel(0.ToString()).DateStart, bll.GetModel(0.ToString()).DateStop), bll.GetModel(0.ToString()));
 642 
 643                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "录音挂机";
 644                         dgv电话管理.Rows[0].Cells["callcode"].Value = "";
 645                         dgv电话管理.Rows[0].Cells["calldate"].Value = "";
 646                         dgv电话管理.Rows[0].Cells["calltype"].Value = "";
 647                         m_Line[0].HookOff = 1;
 648                         m_Line[0].CallerID = "";
 649                         m_Line[0].Ring = 0;
 650                         m_Line[0].Status = STATUS.STATUS_IDLE;
 651                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "空闲";
 652                         ctemp = new char[100];
 653                         break;
 654                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
 655                         dgv电话管理.Rows[0].Cells["chanelstate"].Value = "录音断线";
 656                         dgv电话管理.Rows[0].Cells["callcode"].Value = "";
 657                         dgv电话管理.Rows[0].Cells["calltype"].Value = "";
 658                         m_Line[0].CallerID = "";
 659                         m_Line[0].Dtmf = "";
 660                         m_Line[0].HookOff = 0;
 661                         m_Line[0].Ring = 0;
 662                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(0);
 663                         m_Line[0].Status = STATUS.STATUS_IDLE;
 664                         break;
 665                 }
 666                 #endregion
 667             }
 668         }
 669         private void xunhuan2(GxVoiceAPI.GxVoice.GX_MESSAGE_INFO MessageBuffer, ushort MessageCode, uint intRing, char[] ctemp)
 670         {
 671             if (m_Line[1].Status == STATUS.STATUS_IDLE)
 672             {
 673                 #region STATUS_IDLE
 674                 switch (MessageCode)
 675                 {
 676                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF方式的主叫事件
 677                         //before hook off,dtmf is dtmf cid.
 678                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(1, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
 679                         {
 680                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39)     //0-9
 681                             {
 682                                 m_Line[1].CallerID += ctemp[0].ToString();
 683                                 bll.SetModelValue("CallCodeList", m_Line[1].Dtmf, bll.GetModel(1.ToString()));
 684                                 dgv电话管理.Rows[1].Cells["callcode"].Value = m_Line[1].CallerID;
 685                                 dgv电话管理.Rows[1].Cells["calltype"].Value = "呼入";
 686                                 dgv电话管理.Rows[1].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
 687                             }
 688                         }
 689                         break;
 690                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_DTMF://有DTMF方式的主叫事
 691                         StringBuilder CallerIDString = new StringBuilder(256);//要取得出参 必须定义成StringBuilder 给内存分配空间
 692                         if (GxVoiceAPI.GxVoice.GX_GetDTMFCallerID(1, CallerIDString) == GxVoiceAPI.GxVoice.GX_OK)
 693                         {
 694                             bll.SetModelValue("Call_Code", CallerIDString.ToString(), bll.GetModel(1.ToString()));
 695                             ushort StopDTMF = GxVoiceAPI.GxVoice.GX_StopDetectDTMF(1);//停止检测DTMF按键
 696                             ushort ClearDTMF = GxVoiceAPI.GxVoice.GX_ClearDTMFBuffer(1);//清除某一通道已经识别出来的但仍然没有被取走的DTMF按键。
 697 
 698                             GxVoiceAPI.GxVoice.GX_StartTimeOutForWindows(1, 50);
 699                         }
 700                         // common.EventName.Add("有DTMF方式的主叫事件");
 701                         break;
 702                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_FSK:
 703                         {
 704                             char[] CIDdt = new char[50];        //来电时间                                
 705                             char[] CIDTelNo = new char[50];     //主叫号码                                
 706                             char[] CIDName = new char[50];      //主叫名字[一般没用]
 707 
 708                             if (GxVoiceAPI.GxVoice.GX_GetFskCallerID(1, CIDdt, CIDTelNo, CIDName) == GxVoiceAPI.GxVoice.GX_OK)
 709                             {
 710                                 m_Line[1].CallerID = "";
 711                                 dgv电话管理.Rows[1].Cells["chanelstate"].Value = "外线来电";
 712                                 GxVoiceAPI.GxVoice.GX_StartDetectCallerID(1);//接收FSK来电号码后,必需再调用此函数,否则下一个来电无法监测得到
 713                                 m_Line[1].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo)).Trim("\0".ToCharArray()).Trim("\n".ToCharArray());
 714                                 //m_Line[1].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo));
 715 
 716                                 dgv电话管理.Rows[1].Cells["callcode"].Value = m_Line[1].CallerID;
 717                                 dgv电话管理.Rows[1].Cells["calltype"].Value = "呼入";
 718                                 dgv电话管理.Rows[1].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
 719                             }
 720                         }
 721                         break;
 722 
 723                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_END:
 724                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "放音结束";
 725                         break;
 726                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_EXIT:
 727                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "放音退出";
 728                         break;
 729                     case GxVoiceAPI.GxVoice.MESSAGE_GENERATE_DTMF_END:
 730                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "发码结束";
 731                         break;
 732                     case GxVoiceAPI.GxVoice.MESSAGE_SEND_FSK_END:
 733                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "FSK结束";
 734                         break;
 735                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DIAL_TONE:
 736                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "拨号音";
 737                         break;
 738                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BUSY_TONE:
 739                         bll.ClearModel(bll.GetModel(1.ToString()));
 740                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "忙音";
 741                         dgv电话管理.Rows[1].Cells["callcode"].Value = "";
 742                         dgv电话管理.Rows[1].Cells["calldate"].Value = "";
 743                         m_Line[1].HookOff = 1;
 744                         m_Line[1].CallerID = "";
 745                         m_Line[1].Ring = 0;
 746                         m_Line[1].Status = STATUS.STATUS_RECORDING;
 747                         dgv电话管理.Rows[1].Cells["calltype"].Value = "";
 748                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "空闲";
 749                         ctemp = new char[100];
 750                         break;
 751                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BACK_TONE:
 752                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "回铃音";
 753                         break;
 754                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TONE_DATA:
 755                         break;
 756                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_HELLO_VOICE:
 757                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "爆发音";
 758                         break;
 759                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_SILENCE_DATA:
 760                         if (MessageBuffer.Parameter[0] == 0)
 761                             dgv电话管理.Rows[1].Cells["chanelstate"].Value = "无声音";
 762                         else
 763                             dgv电话管理.Rows[1].Cells["chanelstate"].Value = "有声音";
 764                         break;
 765                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TIME_OUT:
 766                         bll.ClearModel(bll.GetModel(1.ToString()));
 767                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "超时";
 768                         dgv电话管理.Rows[1].Cells["callcode"].Value = "";
 769                         dgv电话管理.Rows[1].Cells["calldate"].Value = "";
 770                         dgv电话管理.Rows[1].Cells["calltype"].Value = "";
 771                         m_Line[1].HookOff = 1;
 772                         m_Line[1].CallerID = "";
 773                         m_Line[1].Ring = 0;
 774                         m_Line[1].Status = STATUS.STATUS_RECORDING;
 775                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "空闲";
 776                         ctemp = new char[100];
 777                         break;
 778 
 779                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_OFF:
 780                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "内线摘机";
 781                         break;
 782                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_ON:
 783                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "内线挂机";
 784                         break;
 785                     case GxVoiceAPI.GxVoice.MESSAGE_USER_PICK_UP:
 786                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "内线拍叉";
 787                         break;
 788                     case GxVoiceAPI.GxVoice.MESSAGE_USER_RING_END:
 789                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "内线震铃结束";
 790                         break;
 791                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_RING:
 792                         m_Line[1].Ring = 1;
 793                         m_Line[1].TimeCount = 0;
 794                         intRing = MessageBuffer.Parameter[0];
 795                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "外线震铃" + Convert.ToString(intRing);
 796                         break;
 797                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_POLE:
 798                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "极性反转";
 799                         break;
 800                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_PICK_UP_END:
 801                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "拍叉结束";
 802                         break;
 803                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_OFF:
 804 
 805                         ushort listen = GxVoiceAPI.GxVoice.GX_ListenChannel(0, 1);//通道监听
 806                         ushort link = GxVoiceAPI.GxVoice.GX_SetLink(1, 0); //两路连接通话 
 807                         bll.SetModelValue("IsJieTing", "true", bll.GetModel(1.ToString()));
 808                         bll.SetModelValue("DateStart", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(1.ToString()));
 809 
 810                         string wavName = "[" + 1.ToString() + "]" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".wav";
 811                         bll.SetModelValue("FileName", wavName, bll.GetModel(1.ToString()));
 812 
 813                         GxVoiceAPI.GxVoice.GX_StartRecordWaveFile(1, "C:\\voice\\" + wavName, 0, 0xFFFFFFFF, (char)0x00);
 814 
 815                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "录音摘机";
 816                         dgv电话管理.Rows[1].Cells["callcode"].Value = "";
 817                         m_Line[1].HookOff = 1;
 818                         m_Line[1].Ring = 0;
 819                         m_Line[1].Status = STATUS.STATUS_RECORDING;
 820                         break;
 821                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_RING:
 822                         bll.SetModelValue("IsCall", "true", bll.GetModel(1.ToString()));
 823                         bll.SetModelValue("1", 1.ToString(), bll.GetModel(1.ToString()));
 824 
 825                         m_Line[1].Ring = 1;
 826                         m_Line[1].TimeCount = 0;
 827                         intRing = MessageBuffer.Parameter[0];
 828                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "录音震铃" + Convert.ToString(intRing);
 829                         break;
 830                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
 831                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "录音断线";
 832                         dgv电话管理.Rows[1].Cells["callcode"].Value = "";
 833                         dgv电话管理.Rows[1].Cells["calltype"].Value = "";
 834                         m_Line[1].CallerID = "";
 835                         m_Line[1].Dtmf = "";
 836                         m_Line[1].HookOff = 0;
 837                         m_Line[1].Ring = 0;
 838                         break;
 839                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_NO_OPEN_CIRCLE:
 840                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "录音接线";
 841                         dgv电话管理.Rows[1].Cells["callcode"].Value = "";
 842                         dgv电话管理.Rows[1].Cells["calltype"].Value = "";
 843                         m_Line[1].CallerID = "";
 844                         m_Line[1].Dtmf = "";
 845                         m_Line[1].HookOff = 0;
 846                         m_Line[1].Ring = 0;
 847                         break;
 848 
 849                 }
 850                 #endregion
 851             }
 852             else if (m_Line[1].Status == STATUS.STATUS_RECORDING)
 853             {
 854                 #region STATUS_RECORDING
 855                 switch (MessageCode)
 856                 {
 857                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF按键事件
 858                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(1, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
 859                         {
 860                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39) //0-9
 861                             {
 862                                 m_Line[1].Dtmf += Convert.ToString(ctemp[0]);
 863                                 dgv电话管理.Rows[1].Cells["callcode"].Value = m_Line[1].Dtmf;
 864                                 bll.SetModelValue("CallCodeList", m_Line[1].Dtmf, bll.GetModel(1.ToString()));
 865                             }
 866                         }
 867                         break;
 868                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_ON:
 869                         bll.SetModelValue("IsOverCall", "true", bll.GetModel(1.ToString()));
 870                         bll.SetModelValue("DateStop", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(1.ToString()));
 871 
 872                         ushort linkover = GxVoiceAPI.GxVoice.GX_ClearLink(1, 0);  //两路断开通话
 873                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(1);//停止录音
 874                         GxVoiceAPI.GxVoice.GX_UnListenChannel(1);//停止监听
 875 
 876                         bll.SetModelValue("Date", DateDiff(bll.GetModel(1.ToString()).DateStart, bll.GetModel(1.ToString()).DateStop), bll.GetModel(1.ToString()));
 877 
 878                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "录音挂机";
 879                         dgv电话管理.Rows[1].Cells["callcode"].Value = "";
 880                         dgv电话管理.Rows[1].Cells["calldate"].Value = "";
 881                         dgv电话管理.Rows[1].Cells["calltype"].Value = "";
 882                         m_Line[1].HookOff = 1;
 883                         m_Line[1].CallerID = "";
 884                         m_Line[1].Ring = 0;
 885                         m_Line[1].Status = STATUS.STATUS_IDLE;
 886                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "空闲";
 887                         ctemp = new char[100];
 888                         break;
 889                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
 890                         dgv电话管理.Rows[1].Cells["chanelstate"].Value = "录音断线";
 891                         dgv电话管理.Rows[1].Cells["callcode"].Value = "";
 892                         dgv电话管理.Rows[1].Cells["calltype"].Value = "";
 893                         m_Line[1].CallerID = "";
 894                         m_Line[1].Dtmf = "";
 895                         m_Line[1].HookOff = 0;
 896                         m_Line[1].Ring = 0;
 897                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(1);
 898                         m_Line[1].Status = STATUS.STATUS_IDLE;
 899                         break;
 900                 }
 901                 #endregion
 902             }
 903         }
 904         private void xunhuan3(GxVoiceAPI.GxVoice.GX_MESSAGE_INFO MessageBuffer, ushort MessageCode, uint intRing, char[] ctemp)
 905         {
 906             if (m_Line[2].Status == STATUS.STATUS_IDLE)
 907             {
 908                 #region STATUS_IDLE
 909                 switch (MessageCode)
 910                 {
 911                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF方式的主叫事件
 912                         //before hook off,dtmf is dtmf cid.
 913                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(2, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
 914                         {
 915                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39)     //0-9
 916                             {
 917                                 m_Line[2].CallerID += ctemp[0].ToString();
 918                                 bll.SetModelValue("CallCodeList", m_Line[2].Dtmf, bll.GetModel(2.ToString()));
 919                                 dgv电话管理.Rows[2].Cells["callcode"].Value = m_Line[2].CallerID;
 920                                 dgv电话管理.Rows[2].Cells["calltype"].Value = "呼入";
 921                                 dgv电话管理.Rows[2].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
 922                             }
 923                         }
 924                         break;
 925                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_DTMF://有DTMF方式的主叫事
 926                         StringBuilder CallerIDString = new StringBuilder(256);//要取得出参 必须定义成StringBuilder 给内存分配空间
 927                         if (GxVoiceAPI.GxVoice.GX_GetDTMFCallerID(2, CallerIDString) == GxVoiceAPI.GxVoice.GX_OK)
 928                         {
 929                             bll.SetModelValue("Call_Code", CallerIDString.ToString(), bll.GetModel(2.ToString()));
 930                             ushort StopDTMF = GxVoiceAPI.GxVoice.GX_StopDetectDTMF(2);//停止检测DTMF按键
 931                             ushort ClearDTMF = GxVoiceAPI.GxVoice.GX_ClearDTMFBuffer(2);//清除某一通道已经识别出来的但仍然没有被取走的DTMF按键。
 932 
 933                             GxVoiceAPI.GxVoice.GX_StartTimeOutForWindows(2, 50);
 934                         }
 935                         // common.EventName.Add("有DTMF方式的主叫事件");
 936                         break;
 937                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_FSK:
 938                         {
 939                             char[] CIDdt = new char[50];        //来电时间                                
 940                             char[] CIDTelNo = new char[50];     //主叫号码                                
 941                             char[] CIDName = new char[50];      //主叫名字[一般没用]
 942 
 943                             if (GxVoiceAPI.GxVoice.GX_GetFskCallerID(2, CIDdt, CIDTelNo, CIDName) == GxVoiceAPI.GxVoice.GX_OK)
 944                             {
 945                                 m_Line[2].CallerID = "";
 946                                 dgv电话管理.Rows[2].Cells["chanelstate"].Value = "外线来电";
 947                                 GxVoiceAPI.GxVoice.GX_StartDetectCallerID(2);//接收FSK来电号码后,必需再调用此函数,否则下一个来电无法监测得到
 948                                 m_Line[2].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo)).Trim("\0".ToCharArray()).Trim("\n".ToCharArray());
 949                                 //m_Line[2].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo));
 950 
 951                                 dgv电话管理.Rows[2].Cells["callcode"].Value = m_Line[2].CallerID;
 952                                 dgv电话管理.Rows[2].Cells["calltype"].Value = "呼入";
 953                                 dgv电话管理.Rows[2].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
 954                             }
 955                         }
 956                         break;
 957 
 958                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_END:
 959                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "放音结束";
 960                         break;
 961                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_EXIT:
 962                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "放音退出";
 963                         break;
 964                     case GxVoiceAPI.GxVoice.MESSAGE_GENERATE_DTMF_END:
 965                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "发码结束";
 966                         break;
 967                     case GxVoiceAPI.GxVoice.MESSAGE_SEND_FSK_END:
 968                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "FSK结束";
 969                         break;
 970                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DIAL_TONE:
 971                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "拨号音";
 972                         break;
 973                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BUSY_TONE:
 974                         bll.ClearModel(bll.GetModel(2.ToString()));
 975                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "忙音";
 976                         dgv电话管理.Rows[2].Cells["callcode"].Value = "";
 977                         dgv电话管理.Rows[2].Cells["calldate"].Value = "";
 978                         m_Line[2].HookOff = 1;
 979                         m_Line[2].CallerID = "";
 980                         m_Line[2].Ring = 0;
 981                         m_Line[2].Status = STATUS.STATUS_RECORDING;
 982                         dgv电话管理.Rows[2].Cells["calltype"].Value = "";
 983                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "空闲";
 984                         ctemp = new char[100];
 985                         break;
 986                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BACK_TONE:
 987                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "回铃音";
 988                         break;
 989                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TONE_DATA:
 990                         break;
 991                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_HELLO_VOICE:
 992                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "爆发音";
 993                         break;
 994                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_SILENCE_DATA:
 995                         if (MessageBuffer.Parameter[0] == 0)
 996                             dgv电话管理.Rows[2].Cells["chanelstate"].Value = "无声音";
 997                         else
 998                             dgv电话管理.Rows[2].Cells["chanelstate"].Value = "有声音";
 999                         break;
1000                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TIME_OUT:
1001                         bll.ClearModel(bll.GetModel(2.ToString()));
1002                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "超时";
1003                         dgv电话管理.Rows[2].Cells["callcode"].Value = "";
1004                         dgv电话管理.Rows[2].Cells["calldate"].Value = "";
1005                         dgv电话管理.Rows[2].Cells["calltype"].Value = "";
1006                         m_Line[2].HookOff = 1;
1007                         m_Line[2].CallerID = "";
1008                         m_Line[2].Ring = 0;
1009                         m_Line[2].Status = STATUS.STATUS_RECORDING;
1010                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "空闲";
1011                         ctemp = new char[100];
1012                         break;
1013                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_OFF:
1014                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "内线摘机";
1015                         break;
1016                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_ON:
1017                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "内线挂机";
1018                         break;
1019                     case GxVoiceAPI.GxVoice.MESSAGE_USER_PICK_UP:
1020                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "内线拍叉";
1021                         break;
1022                     case GxVoiceAPI.GxVoice.MESSAGE_USER_RING_END:
1023                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "内线震铃结束";
1024                         break;
1025                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_RING:
1026                         m_Line[2].Ring = 1;
1027                         m_Line[2].TimeCount = 0;
1028                         intRing = MessageBuffer.Parameter[0];
1029                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "外线震铃" + Convert.ToString(intRing);
1030                         break;
1031                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_POLE:
1032                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "极性反转";
1033                         break;
1034                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_PICK_UP_END:
1035                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "拍叉结束";
1036                         break;
1037                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_OFF:
1038 
1039                         ushort listen = GxVoiceAPI.GxVoice.GX_ListenChannel(0, 2);//通道监听
1040                         ushort link = GxVoiceAPI.GxVoice.GX_SetLink(2, 0); //两路连接通话 
1041                         bll.SetModelValue("IsJieTing", "true", bll.GetModel(2.ToString()));
1042                         bll.SetModelValue("DateStart", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(2.ToString()));
1043 
1044                         string wavName = "[" + 2.ToString() + "]" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".wav";
1045                         bll.SetModelValue("FileName", wavName, bll.GetModel(2.ToString()));
1046 
1047                         GxVoiceAPI.GxVoice.GX_StartRecordWaveFile(2, "C:\\voice\\" + wavName, 0, 0xFFFFFFFF, (char)0x00);
1048 
1049                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "录音摘机";
1050                         dgv电话管理.Rows[2].Cells["callcode"].Value = "";
1051                         m_Line[2].HookOff = 1;
1052                         m_Line[2].Ring = 0;
1053                         m_Line[2].Status = STATUS.STATUS_RECORDING;
1054                         break;
1055                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_RING:
1056                         bll.SetModelValue("IsCall", "true", bll.GetModel(2.ToString()));
1057                         bll.SetModelValue("2", 2.ToString(), bll.GetModel(2.ToString()));
1058 
1059                         m_Line[2].Ring = 1;
1060                         m_Line[2].TimeCount = 0;
1061                         intRing = MessageBuffer.Parameter[0];
1062                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "录音震铃" + Convert.ToString(intRing);
1063                         break;
1064                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
1065                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "录音断线";
1066                         dgv电话管理.Rows[2].Cells["callcode"].Value = "";
1067                         dgv电话管理.Rows[2].Cells["calltype"].Value = "";
1068                         m_Line[2].CallerID = "";
1069                         m_Line[2].Dtmf = "";
1070                         m_Line[2].HookOff = 0;
1071                         m_Line[2].Ring = 0;
1072                         break;
1073                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_NO_OPEN_CIRCLE:
1074                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "录音接线";
1075                         dgv电话管理.Rows[2].Cells["callcode"].Value = "";
1076                         dgv电话管理.Rows[2].Cells["calltype"].Value = "";
1077                         m_Line[2].CallerID = "";
1078                         m_Line[2].Dtmf = "";
1079                         m_Line[2].HookOff = 0;
1080                         m_Line[2].Ring = 0;
1081                         break;
1082 
1083                 }
1084                 #endregion
1085             }
1086             else if (m_Line[2].Status == STATUS.STATUS_RECORDING)
1087             {
1088                 #region STATUS_RECORDING
1089                 switch (MessageCode)
1090                 {
1091                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF按键事件
1092                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(2, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
1093                         {
1094                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39) //0-9
1095                             {
1096                                 m_Line[2].Dtmf += Convert.ToString(ctemp[0]);
1097                                 dgv电话管理.Rows[2].Cells["callcode"].Value = m_Line[2].Dtmf;
1098                                 bll.SetModelValue("CallCodeList", m_Line[2].Dtmf, bll.GetModel(2.ToString()));
1099                             }
1100                         }
1101                         break;
1102                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_ON:
1103                         bll.SetModelValue("IsOverCall", "true", bll.GetModel(2.ToString()));
1104                         bll.SetModelValue("DateStop", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(2.ToString()));
1105 
1106                         ushort linkover = GxVoiceAPI.GxVoice.GX_ClearLink(2, 0);  //两路断开通话
1107                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(2);//停止录音
1108                         GxVoiceAPI.GxVoice.GX_UnListenChannel(0);//停止监听
1109 
1110                         bll.SetModelValue("Date", DateDiff(bll.GetModel(2.ToString()).DateStart, bll.GetModel(2.ToString()).DateStop), bll.GetModel(2.ToString()));
1111 
1112                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "录音挂机";
1113                         dgv电话管理.Rows[2].Cells["callcode"].Value = "";
1114                         dgv电话管理.Rows[2].Cells["calltype"].Value = "";
1115                         m_Line[2].CallerID = "";
1116                         m_Line[2].Dtmf = "";
1117                         m_Line[2].HookOff = 0;
1118                         m_Line[2].Ring = 0;
1119                         m_Line[2].Status = STATUS.STATUS_IDLE;
1120                         ctemp = new char[100];
1121                         break;
1122                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
1123                         dgv电话管理.Rows[2].Cells["chanelstate"].Value = "录音断线";
1124                         dgv电话管理.Rows[2].Cells["callcode"].Value = "";
1125                         dgv电话管理.Rows[2].Cells["calltype"].Value = "";
1126                         m_Line[2].CallerID = "";
1127                         m_Line[2].Dtmf = "";
1128                         m_Line[2].HookOff = 0;
1129                         m_Line[2].Ring = 0;
1130                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(2);
1131                         m_Line[2].Status = STATUS.STATUS_IDLE;
1132                         break;
1133                 }
1134                 #endregion
1135             }
1136         }
1137         private void xunhuan4(GxVoiceAPI.GxVoice.GX_MESSAGE_INFO MessageBuffer, ushort MessageCode, uint intRing, char[] ctemp)
1138         {
1139             if (m_Line[3].Status == STATUS.STATUS_IDLE)
1140             {
1141                 #region STATUS_IDLE
1142                 switch (MessageCode)
1143                 {
1144                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF方式的主叫事件
1145                         //before hook off,dtmf is dtmf cid.
1146                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(3, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
1147                         {
1148                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39)     //0-9
1149                             {
1150                                 m_Line[3].CallerID += ctemp[0].ToString();
1151                                 bll.SetModelValue("CallCodeList", m_Line[3].Dtmf, bll.GetModel(3.ToString()));
1152                                 dgv电话管理.Rows[3].Cells["callcode"].Value = m_Line[3].CallerID;
1153                                 dgv电话管理.Rows[3].Cells["calltype"].Value = "呼入";
1154                                 dgv电话管理.Rows[3].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
1155                             }
1156                         }
1157                         break;
1158                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_DTMF://有DTMF方式的主叫事
1159                         StringBuilder CallerIDString = new StringBuilder(256);//要取得出参 必须定义成StringBuilder 给内存分配空间
1160                         if (GxVoiceAPI.GxVoice.GX_GetDTMFCallerID(3, CallerIDString) == GxVoiceAPI.GxVoice.GX_OK)
1161                         {
1162                             bll.SetModelValue("Call_Code", CallerIDString.ToString(), bll.GetModel(3.ToString()));
1163                             ushort StopDTMF = GxVoiceAPI.GxVoice.GX_StopDetectDTMF(3);//停止检测DTMF按键
1164                             ushort ClearDTMF = GxVoiceAPI.GxVoice.GX_ClearDTMFBuffer(3);//清除某一通道已经识别出来的但仍然没有被取走的DTMF按键。
1165 
1166                             GxVoiceAPI.GxVoice.GX_StartTimeOutForWindows(3, 50);
1167                         }
1168                         // common.EventName.Add("有DTMF方式的主叫事件");
1169                         break;
1170                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_FSK:
1171                         {
1172                             char[] CIDdt = new char[50];        //来电时间                                
1173                             char[] CIDTelNo = new char[50];     //主叫号码                                
1174                             char[] CIDName = new char[50];      //主叫名字[一般没用]
1175 
1176                             if (GxVoiceAPI.GxVoice.GX_GetFskCallerID(3, CIDdt, CIDTelNo, CIDName) == GxVoiceAPI.GxVoice.GX_OK)
1177                             {
1178                                 m_Line[3].CallerID = "";
1179                                 dgv电话管理.Rows[3].Cells["chanelstate"].Value = "外线来电";
1180                                 GxVoiceAPI.GxVoice.GX_StartDetectCallerID(3);//接收FSK来电号码后,必需再调用此函数,否则下一个来电无法监测得到
1181                                 m_Line[3].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo)).Trim("\0".ToCharArray()).Trim("\n".ToCharArray());
1182                                 //m_Line[3].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo));
1183 
1184                                 dgv电话管理.Rows[3].Cells["callcode"].Value = m_Line[3].CallerID;
1185                                 dgv电话管理.Rows[3].Cells["calltype"].Value = "呼入";
1186                                 dgv电话管理.Rows[3].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
1187                             }
1188                         }
1189                         break;
1190 
1191                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_END:
1192                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "放音结束";
1193                         break;
1194                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_EXIT:
1195                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "放音退出";
1196                         break;
1197                     case GxVoiceAPI.GxVoice.MESSAGE_GENERATE_DTMF_END:
1198                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "发码结束";
1199                         break;
1200                     case GxVoiceAPI.GxVoice.MESSAGE_SEND_FSK_END:
1201                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "FSK结束";
1202                         break;
1203                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DIAL_TONE:
1204                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "拨号音";
1205                         break;
1206                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BUSY_TONE:
1207                         bll.ClearModel(bll.GetModel(3.ToString()));
1208                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "忙音";
1209                         dgv电话管理.Rows[3].Cells["callcode"].Value = "";
1210                         dgv电话管理.Rows[3].Cells["calldate"].Value = "";
1211                         m_Line[3].HookOff = 1;
1212                         m_Line[3].CallerID = "";
1213                         m_Line[3].Ring = 0;
1214                         m_Line[3].Status = STATUS.STATUS_RECORDING;
1215                         dgv电话管理.Rows[3].Cells["calltype"].Value = "";
1216                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "空闲";
1217                         ctemp = new char[100];
1218                         break;
1219                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BACK_TONE:
1220                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "回铃音";
1221                         break;
1222                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TONE_DATA:
1223                         break;
1224                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_HELLO_VOICE:
1225                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "爆发音";
1226                         break;
1227                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_SILENCE_DATA:
1228                         if (MessageBuffer.Parameter[0] == 0)
1229                             dgv电话管理.Rows[3].Cells["chanelstate"].Value = "无声音";
1230                         else
1231                             dgv电话管理.Rows[3].Cells["chanelstate"].Value = "有声音";
1232                         break;
1233                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TIME_OUT:
1234                         bll.ClearModel(bll.GetModel(3.ToString()));
1235                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "超时";
1236                         dgv电话管理.Rows[3].Cells["callcode"].Value = "";
1237                         dgv电话管理.Rows[3].Cells["calldate"].Value = "";
1238                         dgv电话管理.Rows[3].Cells["calltype"].Value = "";
1239                         m_Line[3].HookOff = 1;
1240                         m_Line[3].CallerID = "";
1241                         m_Line[3].Ring = 0;
1242                         m_Line[3].Status = STATUS.STATUS_RECORDING;
1243                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "空闲";
1244                         ctemp = new char[100];
1245                         break;
1246 
1247                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_OFF:
1248                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "内线摘机";
1249                         break;
1250                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_ON:
1251                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "内线挂机";
1252                         break;
1253                     case GxVoiceAPI.GxVoice.MESSAGE_USER_PICK_UP:
1254                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "内线拍叉";
1255                         break;
1256                     case GxVoiceAPI.GxVoice.MESSAGE_USER_RING_END:
1257                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "内线震铃结束";
1258                         break;
1259                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_RING:
1260                         m_Line[3].Ring = 1;
1261                         m_Line[3].TimeCount = 0;
1262                         intRing = MessageBuffer.Parameter[0];
1263                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "外线震铃" + Convert.ToString(intRing);
1264                         break;
1265                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_POLE:
1266                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "极性反转";
1267                         break;
1268                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_PICK_UP_END:
1269                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "拍叉结束";
1270                         break;
1271                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_OFF:
1272 
1273                         ushort listen = GxVoiceAPI.GxVoice.GX_ListenChannel(0, 3);//通道监听
1274                         ushort link = GxVoiceAPI.GxVoice.GX_SetLink(3, 0); //两路连接通话 
1275                         bll.SetModelValue("IsJieTing", "true", bll.GetModel(3.ToString()));
1276                         bll.SetModelValue("DateStart", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(3.ToString()));
1277 
1278                         string wavName = "[" + 3.ToString() + "]" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".wav";
1279                         bll.SetModelValue("FileName", wavName, bll.GetModel(3.ToString()));
1280 
1281                         GxVoiceAPI.GxVoice.GX_StartRecordWaveFile(3, "C:\\voice\\" + wavName, 0, 0xFFFFFFFF, (char)0x00);
1282 
1283                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "录音摘机";
1284                         dgv电话管理.Rows[3].Cells["callcode"].Value = "";
1285                         m_Line[3].HookOff = 1;
1286                         m_Line[3].Ring = 0;
1287                         m_Line[3].Status = STATUS.STATUS_RECORDING;
1288                         break;
1289                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_RING:
1290                         bll.SetModelValue("IsCall", "true", bll.GetModel(3.ToString()));
1291                         bll.SetModelValue("3", 3.ToString(), bll.GetModel(3.ToString()));
1292 
1293                         m_Line[3].Ring = 1;
1294                         m_Line[3].TimeCount = 0;
1295                         intRing = MessageBuffer.Parameter[0];
1296                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "录音震铃" + Convert.ToString(intRing);
1297                         break;
1298                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
1299                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "录音断线";
1300                         dgv电话管理.Rows[3].Cells["callcode"].Value = "";
1301                         dgv电话管理.Rows[3].Cells["calltype"].Value = "";
1302                         m_Line[3].CallerID = "";
1303                         m_Line[3].Dtmf = "";
1304                         m_Line[3].HookOff = 0;
1305                         m_Line[3].Ring = 0;
1306                         break;
1307                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_NO_OPEN_CIRCLE:
1308                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "录音接线";
1309                         dgv电话管理.Rows[3].Cells["callcode"].Value = "";
1310                         dgv电话管理.Rows[3].Cells["calltype"].Value = "";
1311                         m_Line[3].CallerID = "";
1312                         m_Line[3].Dtmf = "";
1313                         m_Line[3].HookOff = 0;
1314                         m_Line[3].Ring = 0;
1315                         break;
1316 
1317                 }
1318                 #endregion
1319             }
1320             else if (m_Line[3].Status == STATUS.STATUS_RECORDING)
1321             {
1322                 #region STATUS_RECORDING
1323                 switch (MessageCode)
1324                 {
1325                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF按键事件
1326                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(3, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
1327                         {
1328                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39) //0-9
1329                             {
1330                                 m_Line[3].Dtmf += Convert.ToString(ctemp[0]);
1331                                 dgv电话管理.Rows[3].Cells["callcode"].Value = m_Line[3].Dtmf;
1332                                 bll.SetModelValue("CallCodeList", m_Line[3].Dtmf, bll.GetModel(3.ToString()));
1333                             }
1334                         }
1335                         break;
1336                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_ON:
1337                         bll.SetModelValue("IsOverCall", "true", bll.GetModel(3.ToString()));
1338                         bll.SetModelValue("DateStop", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(3.ToString()));
1339 
1340                         ushort linkover = GxVoiceAPI.GxVoice.GX_ClearLink(3, 0);  //两路断开通话
1341                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(3);//停止录音
1342                         GxVoiceAPI.GxVoice.GX_UnListenChannel(0);//停止监听
1343 
1344                         bll.SetModelValue("Date", DateDiff(bll.GetModel(3.ToString()).DateStart, bll.GetModel(3.ToString()).DateStop), bll.GetModel(3.ToString()));
1345 
1346                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "录音挂机";
1347                         dgv电话管理.Rows[3].Cells["callcode"].Value = "";
1348                         dgv电话管理.Rows[3].Cells["calltype"].Value = "";
1349                         m_Line[3].CallerID = "";
1350                         m_Line[3].Dtmf = "";
1351                         m_Line[3].HookOff = 0;
1352                         m_Line[3].Ring = 0;
1353                         m_Line[3].Status = STATUS.STATUS_IDLE;
1354 
1355                         dgv电话管理.Rows[3].Cells["calldate"].Value = "";
1356                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "空闲";
1357                         ctemp = new char[100];
1358                         break;
1359                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
1360                         dgv电话管理.Rows[3].Cells["chanelstate"].Value = "录音断线";
1361                         dgv电话管理.Rows[3].Cells["callcode"].Value = "";
1362                         dgv电话管理.Rows[3].Cells["calltype"].Value = "";
1363                         m_Line[3].CallerID = "";
1364                         m_Line[3].Dtmf = "";
1365                         m_Line[3].HookOff = 0;
1366                         m_Line[3].Ring = 0;
1367                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(3);
1368                         m_Line[3].Status = STATUS.STATUS_IDLE;
1369                         break;
1370                 }
1371                 #endregion
1372             }
1373         }
1374         private void xunhuan5(GxVoiceAPI.GxVoice.GX_MESSAGE_INFO MessageBuffer, ushort MessageCode, uint intRing, char[] ctemp)
1375         {
1376             if (m_Line[4].Status == STATUS.STATUS_IDLE)
1377             {
1378                 #region STATUS_IDLE
1379                 switch (MessageCode)
1380                 {
1381                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF方式的主叫事件
1382                         //before hook off,dtmf is dtmf cid.
1383                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(4, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
1384                         {
1385                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39)     //0-9
1386                             {
1387                                 m_Line[4].CallerID += ctemp[0].ToString();
1388                                 bll.SetModelValue("CallCodeList", m_Line[4].Dtmf, bll.GetModel(4.ToString()));
1389                                 dgv电话管理.Rows[4].Cells["callcode"].Value = m_Line[4].CallerID;
1390                                 dgv电话管理.Rows[4].Cells["calltype"].Value = "呼入";
1391                                 dgv电话管理.Rows[4].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
1392                             }
1393                         }
1394                         break;
1395                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_DTMF://有DTMF方式的主叫事
1396                         StringBuilder CallerIDString = new StringBuilder(256);//要取得出参 必须定义成StringBuilder 给内存分配空间
1397                         if (GxVoiceAPI.GxVoice.GX_GetDTMFCallerID(4, CallerIDString) == GxVoiceAPI.GxVoice.GX_OK)
1398                         {
1399                             bll.SetModelValue("Call_Code", CallerIDString.ToString(), bll.GetModel(4.ToString()));
1400                             ushort StopDTMF = GxVoiceAPI.GxVoice.GX_StopDetectDTMF(4);//停止检测DTMF按键
1401                             ushort ClearDTMF = GxVoiceAPI.GxVoice.GX_ClearDTMFBuffer(4);//清除某一通道已经识别出来的但仍然没有被取走的DTMF按键。
1402 
1403                             GxVoiceAPI.GxVoice.GX_StartTimeOutForWindows(4, 50);
1404                         }
1405                         // common.EventName.Add("有DTMF方式的主叫事件");
1406                         break;
1407                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_FSK:
1408                         {
1409                             char[] CIDdt = new char[50];        //来电时间                                
1410                             char[] CIDTelNo = new char[50];     //主叫号码                                
1411                             char[] CIDName = new char[50];      //主叫名字[一般没用]
1412 
1413                             if (GxVoiceAPI.GxVoice.GX_GetFskCallerID(4, CIDdt, CIDTelNo, CIDName) == GxVoiceAPI.GxVoice.GX_OK)
1414                             {
1415                                 m_Line[4].CallerID = "";
1416                                 dgv电话管理.Rows[4].Cells["chanelstate"].Value = "外线来电";
1417                                 GxVoiceAPI.GxVoice.GX_StartDetectCallerID(4);//接收FSK来电号码后,必需再调用此函数,否则下一个来电无法监测得到
1418                                 m_Line[4].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo)).Trim("\0".ToCharArray()).Trim("\n".ToCharArray());
1419                                 //m_Line[4].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo));
1420 
1421                                 dgv电话管理.Rows[4].Cells["callcode"].Value = m_Line[4].CallerID;
1422                                 dgv电话管理.Rows[4].Cells["calltype"].Value = "呼入";
1423                                 dgv电话管理.Rows[4].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
1424                             }
1425                         }
1426                         break;
1427 
1428                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_END:
1429                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "放音结束";
1430                         break;
1431                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_EXIT:
1432                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "放音退出";
1433                         break;
1434                     case GxVoiceAPI.GxVoice.MESSAGE_GENERATE_DTMF_END:
1435                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "发码结束";
1436                         break;
1437                     case GxVoiceAPI.GxVoice.MESSAGE_SEND_FSK_END:
1438                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "FSK结束";
1439                         break;
1440                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DIAL_TONE:
1441                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "拨号音";
1442                         break;
1443                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BUSY_TONE:
1444                         bll.ClearModel(bll.GetModel(4.ToString()));
1445                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "忙音";
1446                         dgv电话管理.Rows[4].Cells["callcode"].Value = "";
1447                         m_Line[4].HookOff = 1;
1448                         m_Line[4].CallerID = "";
1449                         m_Line[4].Ring = 0;
1450                         m_Line[4].Status = STATUS.STATUS_RECORDING;
1451                         dgv电话管理.Rows[4].Cells["calltype"].Value = "";
1452                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "空闲";
1453                         ctemp = new char[100];
1454                         break;
1455                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BACK_TONE:
1456                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "回铃音";
1457                         break;
1458                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TONE_DATA:
1459                         break;
1460                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_HELLO_VOICE:
1461                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "爆发音";
1462                         break;
1463                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_SILENCE_DATA:
1464                         if (MessageBuffer.Parameter[0] == 0)
1465                             dgv电话管理.Rows[4].Cells["chanelstate"].Value = "无声音";
1466                         else
1467                             dgv电话管理.Rows[4].Cells["chanelstate"].Value = "有声音";
1468                         break;
1469                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TIME_OUT:
1470                         bll.ClearModel(bll.GetModel(4.ToString()));
1471                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "超时";
1472                         dgv电话管理.Rows[4].Cells["callcode"].Value = "";
1473                         dgv电话管理.Rows[4].Cells["calldate"].Value = "";
1474                         dgv电话管理.Rows[4].Cells["calltype"].Value = "";
1475                         m_Line[4].HookOff = 1;
1476                         m_Line[4].CallerID = "";
1477                         m_Line[4].Ring = 0;
1478                         m_Line[4].Status = STATUS.STATUS_RECORDING;
1479                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "空闲";
1480                         ctemp = new char[100];
1481                         break;
1482                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_OFF:
1483                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "内线摘机";
1484                         break;
1485                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_ON:
1486                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "内线挂机";
1487                         break;
1488                     case GxVoiceAPI.GxVoice.MESSAGE_USER_PICK_UP:
1489                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "内线拍叉";
1490                         break;
1491                     case GxVoiceAPI.GxVoice.MESSAGE_USER_RING_END:
1492                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "内线震铃结束";
1493                         break;
1494                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_RING:
1495                         m_Line[4].Ring = 1;
1496                         m_Line[4].TimeCount = 0;
1497                         intRing = MessageBuffer.Parameter[0];
1498                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "外线震铃" + Convert.ToString(intRing);
1499                         break;
1500                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_POLE:
1501                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "极性反转";
1502                         break;
1503                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_PICK_UP_END:
1504                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "拍叉结束";
1505                         break;
1506                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_OFF:
1507 
1508                         ushort listen = GxVoiceAPI.GxVoice.GX_ListenChannel(0, 4);//通道监听
1509                         ushort link = GxVoiceAPI.GxVoice.GX_SetLink(4, 0); //两路连接通话 
1510                         bll.SetModelValue("IsJieTing", "true", bll.GetModel(4.ToString()));
1511                         bll.SetModelValue("DateStart", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(4.ToString()));
1512 
1513                         string wavName = "[" + 4.ToString() + "]" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".wav";
1514                         bll.SetModelValue("FileName", wavName, bll.GetModel(4.ToString()));
1515 
1516                         GxVoiceAPI.GxVoice.GX_StartRecordWaveFile(4, "C:\\voice\\" + wavName, 0, 0xFFFFFFFF, (char)0x00);
1517 
1518                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "录音摘机";
1519                         dgv电话管理.Rows[4].Cells["callcode"].Value = "";
1520                         m_Line[4].HookOff = 1;
1521                         m_Line[4].Ring = 0;
1522                         m_Line[4].Status = STATUS.STATUS_RECORDING;
1523                         break;
1524                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_RING:
1525                         bll.SetModelValue("IsCall", "true", bll.GetModel(4.ToString()));
1526                         bll.SetModelValue("4", 4.ToString(), bll.GetModel(4.ToString()));
1527 
1528                         m_Line[4].Ring = 1;
1529                         m_Line[4].TimeCount = 0;
1530                         intRing = MessageBuffer.Parameter[0];
1531                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "录音震铃" + Convert.ToString(intRing);
1532                         break;
1533                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
1534                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "录音断线";
1535                         dgv电话管理.Rows[4].Cells["callcode"].Value = "";
1536                         dgv电话管理.Rows[4].Cells["calltype"].Value = "";
1537                         m_Line[4].CallerID = "";
1538                         m_Line[4].Dtmf = "";
1539                         m_Line[4].HookOff = 0;
1540                         m_Line[4].Ring = 0;
1541                         break;
1542                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_NO_OPEN_CIRCLE:
1543                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "录音接线";
1544                         dgv电话管理.Rows[4].Cells["callcode"].Value = "";
1545                         dgv电话管理.Rows[4].Cells["calltype"].Value = "";
1546                         m_Line[4].CallerID = "";
1547                         m_Line[4].Dtmf = "";
1548                         m_Line[4].HookOff = 0;
1549                         m_Line[4].Ring = 0;
1550                         break;
1551 
1552                 }
1553                 #endregion
1554             }
1555             else if (m_Line[4].Status == STATUS.STATUS_RECORDING)
1556             {
1557                 #region STATUS_RECORDING
1558                 switch (MessageCode)
1559                 {
1560                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF按键事件
1561                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(4, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
1562                         {
1563                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39) //0-9
1564                             {
1565                                 m_Line[4].Dtmf += Convert.ToString(ctemp[0]);
1566                                 dgv电话管理.Rows[4].Cells["callcode"].Value = m_Line[4].Dtmf;
1567                                 bll.SetModelValue("CallCodeList", m_Line[4].Dtmf, bll.GetModel(4.ToString()));
1568                             }
1569                         }
1570                         break;
1571                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_ON:
1572                         bll.SetModelValue("IsOverCall", "true", bll.GetModel(4.ToString()));
1573                         bll.SetModelValue("DateStop", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(4.ToString()));
1574 
1575                         ushort linkover = GxVoiceAPI.GxVoice.GX_ClearLink(4, 0);  //两路断开通话
1576                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(4);//停止录音
1577                         GxVoiceAPI.GxVoice.GX_UnListenChannel(0);//停止监听
1578 
1579                         bll.SetModelValue("Date", DateDiff(bll.GetModel(4.ToString()).DateStart, bll.GetModel(4.ToString()).DateStop), bll.GetModel(4.ToString()));
1580 
1581                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "录音挂机";
1582                         dgv电话管理.Rows[4].Cells["callcode"].Value = "";
1583                         dgv电话管理.Rows[4].Cells["calltype"].Value = "";
1584                         m_Line[4].CallerID = "";
1585                         m_Line[4].Dtmf = "";
1586                         m_Line[4].HookOff = 0;
1587                         m_Line[4].Ring = 0;
1588                         m_Line[4].Status = STATUS.STATUS_IDLE;
1589 
1590                         dgv电话管理.Rows[4].Cells["calldate"].Value = "";
1591                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "空闲";
1592                         ctemp = new char[100];
1593                         break;
1594                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
1595                         dgv电话管理.Rows[4].Cells["chanelstate"].Value = "录音断线";
1596                         dgv电话管理.Rows[4].Cells["callcode"].Value = "";
1597                         dgv电话管理.Rows[4].Cells["calltype"].Value = "";
1598                         m_Line[4].CallerID = "";
1599                         m_Line[4].Dtmf = "";
1600                         m_Line[4].HookOff = 0;
1601                         m_Line[4].Ring = 0;
1602                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(4);
1603                         m_Line[4].Status = STATUS.STATUS_IDLE;
1604                         break;
1605                 }
1606                 #endregion
1607             }
1608         }
1609         private void xunhuan6(GxVoiceAPI.GxVoice.GX_MESSAGE_INFO MessageBuffer, ushort MessageCode, uint intRing, char[] ctemp)
1610         {
1611             if (m_Line[5].Status == STATUS.STATUS_IDLE)
1612             {
1613                 #region STATUS_IDLE
1614                 switch (MessageCode)
1615                 {
1616                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF方式的主叫事件
1617                         //before hook off,dtmf is dtmf cid.
1618                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(5, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
1619                         {
1620                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39)     //0-9
1621                             {
1622                                 m_Line[5].CallerID += ctemp[0].ToString();
1623                                 bll.SetModelValue("CallCodeList", m_Line[5].Dtmf, bll.GetModel(5.ToString()));
1624                                 dgv电话管理.Rows[5].Cells["callcode"].Value = m_Line[5].CallerID;
1625                                 dgv电话管理.Rows[5].Cells["calltype"].Value = "呼入";
1626                                 dgv电话管理.Rows[5].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
1627                             }
1628                         }
1629                         break;
1630                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_DTMF://有DTMF方式的主叫事
1631                         StringBuilder CallerIDString = new StringBuilder(256);//要取得出参 必须定义成StringBuilder 给内存分配空间
1632                         if (GxVoiceAPI.GxVoice.GX_GetDTMFCallerID(5, CallerIDString) == GxVoiceAPI.GxVoice.GX_OK)
1633                         {
1634                             bll.SetModelValue("Call_Code", CallerIDString.ToString(), bll.GetModel(5.ToString()));
1635                             ushort StopDTMF = GxVoiceAPI.GxVoice.GX_StopDetectDTMF(5);//停止检测DTMF按键
1636                             ushort ClearDTMF = GxVoiceAPI.GxVoice.GX_ClearDTMFBuffer(5);//清除某一通道已经识别出来的但仍然没有被取走的DTMF按键。
1637 
1638                             GxVoiceAPI.GxVoice.GX_StartTimeOutForWindows(5, 50);
1639                         }
1640                         // common.EventName.Add("有DTMF方式的主叫事件");
1641                         break;
1642                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_FSK:
1643                         {
1644                             char[] CIDdt = new char[50];        //来电时间                                
1645                             char[] CIDTelNo = new char[50];     //主叫号码                                
1646                             char[] CIDName = new char[50];      //主叫名字[一般没用]
1647 
1648                             if (GxVoiceAPI.GxVoice.GX_GetFskCallerID(5, CIDdt, CIDTelNo, CIDName) == GxVoiceAPI.GxVoice.GX_OK)
1649                             {
1650                                 m_Line[5].CallerID = "";
1651                                 dgv电话管理.Rows[5].Cells["chanelstate"].Value = "外线来电";
1652                                 GxVoiceAPI.GxVoice.GX_StartDetectCallerID(5);//接收FSK来电号码后,必需再调用此函数,否则下一个来电无法监测得到
1653                                 m_Line[5].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo)).Trim("\0".ToCharArray()).Trim("\n".ToCharArray());
1654                                 //m_Line[5].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo));
1655 
1656                                 dgv电话管理.Rows[5].Cells["callcode"].Value = m_Line[5].CallerID;
1657                                 dgv电话管理.Rows[5].Cells["calltype"].Value = "呼入";
1658                                 dgv电话管理.Rows[5].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
1659                             }
1660                         }
1661                         break;
1662 
1663                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_END:
1664                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "放音结束";
1665                         break;
1666                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_EXIT:
1667                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "放音退出";
1668                         break;
1669                     case GxVoiceAPI.GxVoice.MESSAGE_GENERATE_DTMF_END:
1670                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "发码结束";
1671                         break;
1672                     case GxVoiceAPI.GxVoice.MESSAGE_SEND_FSK_END:
1673                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "FSK结束";
1674                         break;
1675                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DIAL_TONE:
1676                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "拨号音";
1677                         break;
1678                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BUSY_TONE:
1679                         bll.ClearModel(bll.GetModel(5.ToString()));
1680                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "忙音";
1681                         dgv电话管理.Rows[5].Cells["callcode"].Value = "";
1682                         dgv电话管理.Rows[5].Cells["calldate"].Value = "";
1683                         m_Line[5].HookOff = 1;
1684                         m_Line[5].CallerID = "";
1685                         m_Line[5].Ring = 0;
1686                         m_Line[5].Status = STATUS.STATUS_RECORDING;
1687                         dgv电话管理.Rows[5].Cells["calltype"].Value = "";
1688                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "空闲";
1689                         ctemp = new char[100];
1690                         break;
1691                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BACK_TONE:
1692                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "回铃音";
1693                         break;
1694                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TONE_DATA:
1695                         break;
1696                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_HELLO_VOICE:
1697                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "爆发音";
1698                         break;
1699                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_SILENCE_DATA:
1700                         if (MessageBuffer.Parameter[0] == 0)
1701                             dgv电话管理.Rows[5].Cells["chanelstate"].Value = "无声音";
1702                         else
1703                             dgv电话管理.Rows[5].Cells["chanelstate"].Value = "有声音";
1704                         break;
1705                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TIME_OUT:
1706                         bll.ClearModel(bll.GetModel(5.ToString()));
1707                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "超时";
1708                         dgv电话管理.Rows[5].Cells["callcode"].Value = "";
1709                         dgv电话管理.Rows[5].Cells["calldate"].Value = "";
1710                         dgv电话管理.Rows[5].Cells["calltype"].Value = "";
1711                         m_Line[5].HookOff = 1;
1712                         m_Line[5].CallerID = "";
1713                         m_Line[5].Ring = 0;
1714                         m_Line[5].Status = STATUS.STATUS_RECORDING;
1715                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "空闲";
1716                         ctemp = new char[100];
1717                         break;
1718 
1719                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_OFF:
1720                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "内线摘机";
1721                         break;
1722                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_ON:
1723                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "内线挂机";
1724                         break;
1725                     case GxVoiceAPI.GxVoice.MESSAGE_USER_PICK_UP:
1726                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "内线拍叉";
1727                         break;
1728                     case GxVoiceAPI.GxVoice.MESSAGE_USER_RING_END:
1729                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "内线震铃结束";
1730                         break;
1731                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_RING:
1732                         m_Line[5].Ring = 1;
1733                         m_Line[5].TimeCount = 0;
1734                         intRing = MessageBuffer.Parameter[0];
1735                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "外线震铃" + Convert.ToString(intRing);
1736                         break;
1737                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_POLE:
1738                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "极性反转";
1739                         break;
1740                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_PICK_UP_END:
1741                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "拍叉结束";
1742                         break;
1743                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_OFF:
1744 
1745                         ushort listen = GxVoiceAPI.GxVoice.GX_ListenChannel(0, 5);//通道监听
1746                         ushort link = GxVoiceAPI.GxVoice.GX_SetLink(5, 0); //两路连接通话 
1747                         bll.SetModelValue("IsJieTing", "true", bll.GetModel(5.ToString()));
1748                         bll.SetModelValue("DateStart", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(5.ToString()));
1749 
1750                         string wavName = "[" + 5.ToString() + "]" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".wav";
1751                         bll.SetModelValue("FileName", wavName, bll.GetModel(5.ToString()));
1752 
1753                         GxVoiceAPI.GxVoice.GX_StartRecordWaveFile(5, "C:\\voice\\" + wavName, 0, 0xFFFFFFFF, (char)0x00);
1754 
1755                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "录音摘机";
1756                         dgv电话管理.Rows[5].Cells["callcode"].Value = "";
1757                         m_Line[5].HookOff = 1;
1758                         m_Line[5].Ring = 0;
1759                         m_Line[5].Status = STATUS.STATUS_RECORDING;
1760                         break;
1761                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_RING:
1762                         bll.SetModelValue("IsCall", "true", bll.GetModel(5.ToString()));
1763                         bll.SetModelValue("5", 5.ToString(), bll.GetModel(5.ToString()));
1764 
1765                         m_Line[5].Ring = 1;
1766                         m_Line[5].TimeCount = 0;
1767                         intRing = MessageBuffer.Parameter[0];
1768                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "录音震铃" + Convert.ToString(intRing);
1769                         break;
1770                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
1771                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "录音断线";
1772                         dgv电话管理.Rows[5].Cells["callcode"].Value = "";
1773                         dgv电话管理.Rows[5].Cells["calltype"].Value = "";
1774                         m_Line[5].CallerID = "";
1775                         m_Line[5].Dtmf = "";
1776                         m_Line[5].HookOff = 0;
1777                         m_Line[5].Ring = 0;
1778                         break;
1779                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_NO_OPEN_CIRCLE:
1780                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "录音接线";
1781                         dgv电话管理.Rows[5].Cells["callcode"].Value = "";
1782                         dgv电话管理.Rows[5].Cells["calltype"].Value = "";
1783                         m_Line[5].CallerID = "";
1784                         m_Line[5].Dtmf = "";
1785                         m_Line[5].HookOff = 0;
1786                         m_Line[5].Ring = 0;
1787                         break;
1788 
1789                 }
1790                 #endregion
1791             }
1792             else if (m_Line[5].Status == STATUS.STATUS_RECORDING)
1793             {
1794                 #region STATUS_RECORDING
1795                 switch (MessageCode)
1796                 {
1797                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF按键事件
1798                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(5, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
1799                         {
1800                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39) //0-9
1801                             {
1802                                 m_Line[5].Dtmf += Convert.ToString(ctemp[0]);
1803                                 dgv电话管理.Rows[5].Cells["callcode"].Value = m_Line[5].Dtmf;
1804                                 bll.SetModelValue("CallCodeList", m_Line[5].Dtmf, bll.GetModel(5.ToString()));
1805                             }
1806                         }
1807                         break;
1808                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_ON:
1809                         bll.SetModelValue("IsOverCall", "true", bll.GetModel(5.ToString()));
1810                         bll.SetModelValue("DateStop", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(5.ToString()));
1811 
1812                         ushort linkover = GxVoiceAPI.GxVoice.GX_ClearLink(5, 0);  //两路断开通话
1813                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(5);//停止录音
1814                         GxVoiceAPI.GxVoice.GX_UnListenChannel(0);//停止监听
1815 
1816                         bll.SetModelValue("Date", DateDiff(bll.GetModel(5.ToString()).DateStart, bll.GetModel(5.ToString()).DateStop), bll.GetModel(5.ToString()));
1817 
1818                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "录音挂机";
1819                         dgv电话管理.Rows[5].Cells["callcode"].Value = "";
1820                         dgv电话管理.Rows[5].Cells["calltype"].Value = "";
1821                         m_Line[5].CallerID = "";
1822                         m_Line[5].Dtmf = "";
1823                         m_Line[5].HookOff = 0;
1824                         m_Line[5].Ring = 0;
1825                         m_Line[5].Status = STATUS.STATUS_IDLE;
1826 
1827                         dgv电话管理.Rows[5].Cells["calldate"].Value = "";
1828                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "空闲";
1829                         ctemp = new char[100];
1830                         break;
1831                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
1832                         dgv电话管理.Rows[5].Cells["chanelstate"].Value = "录音断线";
1833                         dgv电话管理.Rows[5].Cells["callcode"].Value = "";
1834                         dgv电话管理.Rows[5].Cells["calltype"].Value = "";
1835                         m_Line[5].CallerID = "";
1836                         m_Line[5].Dtmf = "";
1837                         m_Line[5].HookOff = 0;
1838                         m_Line[5].Ring = 0;
1839                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(5);
1840                         m_Line[5].Status = STATUS.STATUS_IDLE;
1841                         break;
1842                 }
1843                 #endregion
1844             }
1845         }
1846         private void xunhuan7(GxVoiceAPI.GxVoice.GX_MESSAGE_INFO MessageBuffer, ushort MessageCode, uint intRing, char[] ctemp)
1847         {
1848             if (m_Line[6].Status == STATUS.STATUS_IDLE)
1849             {
1850                 #region STATUS_IDLE
1851                 switch (MessageCode)
1852                 {
1853                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF方式的主叫事件
1854                         //before hook off,dtmf is dtmf cid.
1855                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(6, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
1856                         {
1857                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39)     //0-9
1858                             {
1859                                 m_Line[6].CallerID += ctemp[0].ToString();
1860                                 bll.SetModelValue("CallCodeList", m_Line[6].Dtmf, bll.GetModel(6.ToString()));
1861                                 dgv电话管理.Rows[6].Cells["callcode"].Value = m_Line[6].CallerID;
1862                                 dgv电话管理.Rows[6].Cells["calltype"].Value = "呼入";
1863                                 dgv电话管理.Rows[6].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
1864                             }
1865                         }
1866                         break;
1867                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_DTMF://有DTMF方式的主叫事
1868                         StringBuilder CallerIDString = new StringBuilder(256);//要取得出参 必须定义成StringBuilder 给内存分配空间
1869                         if (GxVoiceAPI.GxVoice.GX_GetDTMFCallerID(6, CallerIDString) == GxVoiceAPI.GxVoice.GX_OK)
1870                         {
1871                             bll.SetModelValue("Call_Code", CallerIDString.ToString(), bll.GetModel(6.ToString()));
1872                             ushort StopDTMF = GxVoiceAPI.GxVoice.GX_StopDetectDTMF(6);//停止检测DTMF按键
1873                             ushort ClearDTMF = GxVoiceAPI.GxVoice.GX_ClearDTMFBuffer(6);//清除某一通道已经识别出来的但仍然没有被取走的DTMF按键。
1874 
1875                             GxVoiceAPI.GxVoice.GX_StartTimeOutForWindows(6, 50);
1876                         }
1877                         // common.EventName.Add("有DTMF方式的主叫事件");
1878                         break;
1879                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_FSK:
1880                         {
1881                             char[] CIDdt = new char[50];        //来电时间                                
1882                             char[] CIDTelNo = new char[50];     //主叫号码                                
1883                             char[] CIDName = new char[50];      //主叫名字[一般没用]
1884 
1885                             if (GxVoiceAPI.GxVoice.GX_GetFskCallerID(6, CIDdt, CIDTelNo, CIDName) == GxVoiceAPI.GxVoice.GX_OK)
1886                             {
1887                                 m_Line[6].CallerID = "";
1888                                 dgv电话管理.Rows[6].Cells["chanelstate"].Value = "外线来电";
1889                                 GxVoiceAPI.GxVoice.GX_StartDetectCallerID(6);//接收FSK来电号码后,必需再调用此函数,否则下一个来电无法监测得到
1890                                 m_Line[6].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo)).Trim("\0".ToCharArray()).Trim("\n".ToCharArray());
1891                                 //m_Line[6].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo));
1892 
1893                                 dgv电话管理.Rows[6].Cells["callcode"].Value = m_Line[6].CallerID;
1894                                 dgv电话管理.Rows[6].Cells["calltype"].Value = "呼出";
1895                                 dgv电话管理.Rows[6].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
1896                             }
1897                         }
1898                         break;
1899 
1900                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_END:
1901                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "放音结束";
1902                         break;
1903                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_EXIT:
1904                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "放音退出";
1905                         break;
1906                     case GxVoiceAPI.GxVoice.MESSAGE_GENERATE_DTMF_END:
1907                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "发码结束";
1908                         break;
1909                     case GxVoiceAPI.GxVoice.MESSAGE_SEND_FSK_END:
1910                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "FSK结束";
1911                         break;
1912                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DIAL_TONE:
1913                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "拨号音";
1914                         break;
1915                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BUSY_TONE:
1916                         bll.ClearModel(bll.GetModel(6.ToString()));
1917                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "忙音";
1918                         dgv电话管理.Rows[6].Cells["callcode"].Value = "";
1919                         dgv电话管理.Rows[6].Cells["calldate"].Value = "";
1920                         m_Line[6].HookOff = 1;
1921                         m_Line[6].CallerID = "";
1922                         m_Line[6].Ring = 0;
1923                         m_Line[6].Status = STATUS.STATUS_RECORDING;
1924                         dgv电话管理.Rows[6].Cells["calltype"].Value = "";
1925                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "空闲";
1926                         ctemp = new char[100];
1927                         break;
1928                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BACK_TONE:
1929                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "回铃音";
1930                         break;
1931                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TONE_DATA:
1932                         break;
1933                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_HELLO_VOICE:
1934                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "爆发音";
1935                         break;
1936                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_SILENCE_DATA:
1937                         if (MessageBuffer.Parameter[0] == 0)
1938                             dgv电话管理.Rows[6].Cells["chanelstate"].Value = "无声音";
1939                         else
1940                             dgv电话管理.Rows[6].Cells["chanelstate"].Value = "有声音";
1941                         break;
1942                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TIME_OUT:
1943                         bll.ClearModel(bll.GetModel(6.ToString()));
1944                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "超时";
1945                         dgv电话管理.Rows[6].Cells["callcode"].Value = "";
1946                         dgv电话管理.Rows[6].Cells["calldate"].Value = "";
1947                         dgv电话管理.Rows[6].Cells["calltype"].Value = "";
1948                         m_Line[6].HookOff = 1;
1949                         m_Line[6].CallerID = "";
1950                         m_Line[6].Ring = 0;
1951                         m_Line[6].Status = STATUS.STATUS_RECORDING;
1952                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "空闲";
1953                         ctemp = new char[100];
1954                         break;
1955 
1956                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_OFF:
1957                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "内线摘机";
1958                         break;
1959                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_ON:
1960                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "内线挂机";
1961                         break;
1962                     case GxVoiceAPI.GxVoice.MESSAGE_USER_PICK_UP:
1963                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "内线拍叉";
1964                         break;
1965                     case GxVoiceAPI.GxVoice.MESSAGE_USER_RING_END:
1966                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "内线震铃结束";
1967                         break;
1968                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_RING:
1969                         m_Line[6].Ring = 1;
1970                         m_Line[6].TimeCount = 0;
1971                         intRing = MessageBuffer.Parameter[0];
1972                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "外线震铃" + Convert.ToString(intRing);
1973                         break;
1974                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_POLE:
1975                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "极性反转";
1976                         break;
1977                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_PICK_UP_END:
1978                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "拍叉结束";
1979                         break;
1980                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_OFF:
1981 
1982                         ushort listen = GxVoiceAPI.GxVoice.GX_ListenChannel(0, 6);//通道监听
1983                         ushort link = GxVoiceAPI.GxVoice.GX_SetLink(6, 0); //两路连接通话 
1984                         bll.SetModelValue("IsJieTing", "true", bll.GetModel(6.ToString()));
1985                         bll.SetModelValue("DateStart", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(6.ToString()));
1986 
1987                         string wavName = "[" + 6.ToString() + "]" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".wav";
1988                         bll.SetModelValue("FileName", wavName, bll.GetModel(6.ToString()));
1989 
1990                         GxVoiceAPI.GxVoice.GX_StartRecordWaveFile(6, "C:\\voice\\" + wavName, 0, 0xFFFFFFFF, (char)0x00);
1991 
1992                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "录音摘机";
1993                         dgv电话管理.Rows[6].Cells["callcode"].Value = "";
1994                         m_Line[6].HookOff = 1;
1995                         m_Line[6].Ring = 0;
1996                         m_Line[6].Status = STATUS.STATUS_RECORDING;
1997                         break;
1998                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_RING:
1999                         bll.SetModelValue("IsCall", "true", bll.GetModel(6.ToString()));
2000                         bll.SetModelValue("6", 6.ToString(), bll.GetModel(6.ToString()));
2001 
2002                         m_Line[6].Ring = 1;
2003                         m_Line[6].TimeCount = 0;
2004                         intRing = MessageBuffer.Parameter[0];
2005                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "录音震铃" + Convert.ToString(intRing);
2006                         break;
2007                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
2008                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "录音断线";
2009                         dgv电话管理.Rows[6].Cells["callcode"].Value = "";
2010                         dgv电话管理.Rows[6].Cells["calltype"].Value = "";
2011                         m_Line[6].CallerID = "";
2012                         m_Line[6].Dtmf = "";
2013                         m_Line[6].HookOff = 0;
2014                         m_Line[6].Ring = 0;
2015                         break;
2016                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_NO_OPEN_CIRCLE:
2017                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "录音接线";
2018                         dgv电话管理.Rows[6].Cells["callcode"].Value = "";
2019                         dgv电话管理.Rows[6].Cells["calltype"].Value = "";
2020                         m_Line[6].CallerID = "";
2021                         m_Line[6].Dtmf = "";
2022                         m_Line[6].HookOff = 0;
2023                         m_Line[6].Ring = 0;
2024                         break;
2025 
2026                 }
2027                 #endregion
2028             }
2029             else if (m_Line[6].Status == STATUS.STATUS_RECORDING)
2030             {
2031                 #region STATUS_RECORDING
2032                 switch (MessageCode)
2033                 {
2034                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF按键事件
2035                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(6, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
2036                         {
2037                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39) //0-9
2038                             {
2039                                 m_Line[6].Dtmf += Convert.ToString(ctemp[0]);
2040                                 dgv电话管理.Rows[6].Cells["callcode"].Value = m_Line[6].Dtmf;
2041                                 bll.SetModelValue("CallCodeList", m_Line[6].Dtmf, bll.GetModel(6.ToString()));
2042                             }
2043                         }
2044                         break;
2045                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_ON:
2046                         bll.SetModelValue("IsOverCall", "true", bll.GetModel(6.ToString()));
2047                         bll.SetModelValue("DateStop", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(6.ToString()));
2048 
2049                         ushort linkover = GxVoiceAPI.GxVoice.GX_ClearLink(6, 0);  //两路断开通话
2050                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(6);//停止录音
2051                         GxVoiceAPI.GxVoice.GX_UnListenChannel(0);//停止监听
2052 
2053                         bll.SetModelValue("Date", DateDiff(bll.GetModel(6.ToString()).DateStart, bll.GetModel(6.ToString()).DateStop), bll.GetModel(6.ToString()));
2054 
2055                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "录音挂机";
2056                         dgv电话管理.Rows[6].Cells["callcode"].Value = "";
2057                         dgv电话管理.Rows[6].Cells["calltype"].Value = "";
2058                         m_Line[6].CallerID = "";
2059                         m_Line[6].Dtmf = "";
2060                         m_Line[6].HookOff = 0;
2061                         m_Line[6].Ring = 0;
2062                         m_Line[6].Status = STATUS.STATUS_IDLE;
2063 
2064                         dgv电话管理.Rows[6].Cells["calldate"].Value = "";
2065                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "空闲";
2066                         ctemp = new char[100];
2067                         break;
2068                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
2069                         dgv电话管理.Rows[6].Cells["chanelstate"].Value = "录音断线";
2070                         dgv电话管理.Rows[6].Cells["callcode"].Value = "";
2071                         dgv电话管理.Rows[6].Cells["calltype"].Value = "";
2072                         m_Line[6].CallerID = "";
2073                         m_Line[6].Dtmf = "";
2074                         m_Line[6].HookOff = 0;
2075                         m_Line[6].Ring = 0;
2076                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(6);
2077                         m_Line[6].Status = STATUS.STATUS_IDLE;
2078                         break;
2079                 }
2080                 #endregion
2081             }
2082         }
2083         private void xunhuan8(GxVoiceAPI.GxVoice.GX_MESSAGE_INFO MessageBuffer, ushort MessageCode, uint intRing, char[] ctemp)
2084         {
2085             if (m_Line[7].Status == STATUS.STATUS_IDLE)
2086             {
2087                 #region STATUS_IDLE
2088                 switch (MessageCode)
2089                 {
2090                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF方式的主叫事件
2091                         //before hook off,dtmf is dtmf cid.
2092                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(7, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
2093                         {
2094                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39)     //0-9
2095                             {
2096                                 m_Line[7].CallerID += ctemp[0].ToString();
2097                                 bll.SetModelValue("CallCodeList", m_Line[7].Dtmf, bll.GetModel(7.ToString()));
2098                                 dgv电话管理.Rows[7].Cells["callcode"].Value = m_Line[7].CallerID;
2099                                 dgv电话管理.Rows[7].Cells["calltype"].Value = "呼入";
2100                                 dgv电话管理.Rows[7].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
2101                             }
2102                         }
2103                         break;
2104                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_DTMF://有DTMF方式的主叫事
2105                         StringBuilder CallerIDString = new StringBuilder(256);//要取得出参 必须定义成StringBuilder 给内存分配空间
2106                         if (GxVoiceAPI.GxVoice.GX_GetDTMFCallerID(7, CallerIDString) == GxVoiceAPI.GxVoice.GX_OK)
2107                         {
2108                             bll.SetModelValue("Call_Code", CallerIDString.ToString(), bll.GetModel(7.ToString()));
2109                             ushort StopDTMF = GxVoiceAPI.GxVoice.GX_StopDetectDTMF(7);//停止检测DTMF按键
2110                             ushort ClearDTMF = GxVoiceAPI.GxVoice.GX_ClearDTMFBuffer(7);//清除某一通道已经识别出来的但仍然没有被取走的DTMF按键。
2111 
2112                             GxVoiceAPI.GxVoice.GX_StartTimeOutForWindows(7, 50);
2113                         }
2114                         // common.EventName.Add("有DTMF方式的主叫事件");
2115                         break;
2116                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_CID_FSK:
2117                         {
2118                             char[] CIDdt = new char[50];        //来电时间                                
2119                             char[] CIDTelNo = new char[50];     //主叫号码                                
2120                             char[] CIDName = new char[50];      //主叫名字[一般没用]
2121 
2122                             if (GxVoiceAPI.GxVoice.GX_GetFskCallerID(7, CIDdt, CIDTelNo, CIDName) == GxVoiceAPI.GxVoice.GX_OK)
2123                             {
2124                                 m_Line[7].CallerID = "";
2125                                 dgv电话管理.Rows[7].Cells["chanelstate"].Value = "外线来电";
2126                                 GxVoiceAPI.GxVoice.GX_StartDetectCallerID(7);//接收FSK来电号码后,必需再调用此函数,否则下一个来电无法监测得到
2127                                 m_Line[7].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo)).Trim("\0".ToCharArray()).Trim("\n".ToCharArray());
2128                                 //m_Line[7].CallerID = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.Unicode.GetBytes(CIDTelNo));
2129 
2130                                 dgv电话管理.Rows[7].Cells["callcode"].Value = m_Line[7].CallerID;
2131                                 dgv电话管理.Rows[7].Cells["calltype"].Value = "呼出";
2132                                 dgv电话管理.Rows[7].Cells["calldate"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
2133                             }
2134                         }
2135                         break;
2136 
2137                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_END:
2138                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "放音结束";
2139                         break;
2140                     case GxVoiceAPI.GxVoice.MESSAGE_PLAY_VOICE_EXIT:
2141                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "放音退出";
2142                         break;
2143                     case GxVoiceAPI.GxVoice.MESSAGE_GENERATE_DTMF_END:
2144                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "发码结束";
2145                         break;
2146                     case GxVoiceAPI.GxVoice.MESSAGE_SEND_FSK_END:
2147                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "FSK结束";
2148                         break;
2149                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DIAL_TONE:
2150                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "拨号音";
2151                         break;
2152                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BUSY_TONE:
2153                         bll.ClearModel(bll.GetModel(7.ToString()));
2154                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "忙音";
2155                         dgv电话管理.Rows[7].Cells["callcode"].Value = "";
2156                         dgv电话管理.Rows[7].Cells["calldate"].Value = "";
2157                         m_Line[7].HookOff = 1;
2158                         m_Line[7].CallerID = "";
2159                         m_Line[7].Ring = 0;
2160                         m_Line[7].Status = STATUS.STATUS_RECORDING;
2161                         dgv电话管理.Rows[7].Cells["calltype"].Value = "";
2162                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "空闲";
2163                         ctemp = new char[100];
2164                         break;
2165                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_BACK_TONE:
2166                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "回铃音";
2167                         break;
2168                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TONE_DATA:
2169                         break;
2170                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_HELLO_VOICE:
2171                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "爆发音";
2172                         break;
2173                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_SILENCE_DATA:
2174                         if (MessageBuffer.Parameter[0] == 0)
2175                             dgv电话管理.Rows[7].Cells["chanelstate"].Value = "无声音";
2176                         else
2177                             dgv电话管理.Rows[7].Cells["chanelstate"].Value = "有声音";
2178                         break;
2179                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_TIME_OUT:
2180                         bll.ClearModel(bll.GetModel(7.ToString()));
2181                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "超时";
2182                         dgv电话管理.Rows[7].Cells["callcode"].Value = "";
2183                         dgv电话管理.Rows[7].Cells["calldate"].Value = "";
2184                         dgv电话管理.Rows[7].Cells["calltype"].Value = "";
2185                         m_Line[7].HookOff = 1;
2186                         m_Line[7].CallerID = "";
2187                         m_Line[7].Ring = 0;
2188                         m_Line[7].Status = STATUS.STATUS_RECORDING;
2189                         dgv电话管理.Rows[7].Cells["calltype"].Value = "";
2190                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "空闲";
2191                         ctemp = new char[100];
2192                         break;
2193 
2194                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_OFF:
2195                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "内线摘机";
2196                         break;
2197                     case GxVoiceAPI.GxVoice.MESSAGE_USER_HOOK_ON:
2198                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "内线挂机";
2199                         break;
2200                     case GxVoiceAPI.GxVoice.MESSAGE_USER_PICK_UP:
2201                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "内线拍叉";
2202                         break;
2203                     case GxVoiceAPI.GxVoice.MESSAGE_USER_RING_END:
2204                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "内线震铃结束";
2205                         break;
2206                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_RING:
2207                         m_Line[7].Ring = 1;
2208                         m_Line[7].TimeCount = 0;
2209                         intRing = MessageBuffer.Parameter[0];
2210                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "外线震铃" + Convert.ToString(intRing);
2211                         break;
2212                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_POLE:
2213                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "极性反转";
2214                         break;
2215                     case GxVoiceAPI.GxVoice.MESSAGE_TRUNK_PICK_UP_END:
2216                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "拍叉结束";
2217                         break;
2218                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_OFF:
2219 
2220                         ushort listen = GxVoiceAPI.GxVoice.GX_ListenChannel(0, 7);//通道监听
2221                         ushort link = GxVoiceAPI.GxVoice.GX_SetLink(7, 0); //两路连接通话 
2222                         bll.SetModelValue("IsJieTing", "true", bll.GetModel(7.ToString()));
2223                         bll.SetModelValue("DateStart", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(7.ToString()));
2224 
2225                         string wavName = "[" + 7.ToString() + "]" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".wav";
2226                         bll.SetModelValue("FileName", wavName, bll.GetModel(7.ToString()));
2227 
2228                         GxVoiceAPI.GxVoice.GX_StartRecordWaveFile(7, "C:\\voice\\" + wavName, 0, 0xFFFFFFFF, (char)0x00);
2229 
2230                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "录音摘机";
2231                         dgv电话管理.Rows[7].Cells["callcode"].Value = "";
2232                         m_Line[7].HookOff = 1;
2233                         m_Line[7].Ring = 0;
2234                         m_Line[7].Status = STATUS.STATUS_RECORDING;
2235                         break;
2236                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_RING:
2237                         bll.SetModelValue("IsCall", "true", bll.GetModel(7.ToString()));
2238                         bll.SetModelValue("7", 7.ToString(), bll.GetModel(7.ToString()));
2239 
2240                         m_Line[7].Ring = 1;
2241                         m_Line[7].TimeCount = 0;
2242                         intRing = MessageBuffer.Parameter[0];
2243                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "录音震铃" + Convert.ToString(intRing);
2244                         break;
2245                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
2246                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "录音断线";
2247                         dgv电话管理.Rows[7].Cells["callcode"].Value = "";
2248                         dgv电话管理.Rows[7].Cells["calltype"].Value = "";
2249                         m_Line[7].CallerID = "";
2250                         m_Line[7].Dtmf = "";
2251                         m_Line[7].HookOff = 0;
2252                         m_Line[7].Ring = 0;
2253                         break;
2254                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_NO_OPEN_CIRCLE:
2255                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "录音接线";
2256                         dgv电话管理.Rows[7].Cells["callcode"].Value = "";
2257                         dgv电话管理.Rows[7].Cells["calltype"].Value = "";
2258                         m_Line[7].CallerID = "";
2259                         m_Line[7].Dtmf = "";
2260                         m_Line[7].HookOff = 0;
2261                         m_Line[7].Ring = 0;
2262                         break;
2263 
2264                 }
2265                 #endregion
2266             }
2267             else if (m_Line[7].Status == STATUS.STATUS_RECORDING)
2268             {
2269                 #region STATUS_RECORDING
2270                 switch (MessageCode)
2271                 {
2272                     case GxVoiceAPI.GxVoice.MESSAGE_HAVE_DTMF:  //DTMF按键事件
2273                         if (GxVoiceAPI.GxVoice.GX_GetDTMFKey(7, 1, ctemp) == GxVoiceAPI.GxVoice.GX_OK)
2274                         {
2275                             if ((ctemp[0] >= 0x30) && ctemp[0] <= 0x39) //0-9
2276                             {
2277                                 m_Line[7].Dtmf += Convert.ToString(ctemp[0]);
2278                                 dgv电话管理.Rows[7].Cells["callcode"].Value = m_Line[7].Dtmf;
2279                                 bll.SetModelValue("CallCodeList", m_Line[7].Dtmf, bll.GetModel(7.ToString()));
2280                             }
2281                         }
2282                         break;
2283                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_HOOK_ON:
2284                         bll.SetModelValue("IsOverCall", "true", bll.GetModel(7.ToString()));
2285                         bll.SetModelValue("DateStop", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), bll.GetModel(7.ToString()));
2286 
2287                         ushort linkover = GxVoiceAPI.GxVoice.GX_ClearLink(7, 0);  //两路断开通话
2288                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(7);//停止录音
2289                         GxVoiceAPI.GxVoice.GX_UnListenChannel(0);//停止监听
2290 
2291                         bll.SetModelValue("Date", DateDiff(bll.GetModel(7.ToString()).DateStart, bll.GetModel(7.ToString()).DateStop), bll.GetModel(7.ToString()));
2292 
2293                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "录音挂机";
2294                         dgv电话管理.Rows[7].Cells["callcode"].Value = "";
2295                         dgv电话管理.Rows[7].Cells["calltype"].Value = "";
2296                         m_Line[7].CallerID = "";
2297                         m_Line[7].Dtmf = "";
2298                         m_Line[7].HookOff = 0;
2299                         m_Line[7].Ring = 0;
2300                         m_Line[7].Status = STATUS.STATUS_IDLE;
2301 
2302                         dgv电话管理.Rows[7].Cells["calldate"].Value = "";
2303                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "空闲";
2304                         ctemp = new char[100];
2305                         break;
2306                     case GxVoiceAPI.GxVoice.MESSAGE_RECORD_OPEN_CIRCLE:
2307                         dgv电话管理.Rows[7].Cells["chanelstate"].Value = "录音断线";
2308                         dgv电话管理.Rows[7].Cells["callcode"].Value = "";
2309                         dgv电话管理.Rows[7].Cells["calltype"].Value = "";
2310                         m_Line[7].CallerID = "";
2311                         m_Line[7].Dtmf = "";
2312                         m_Line[7].HookOff = 0;
2313                         m_Line[7].Ring = 0;
2314                         GxVoiceAPI.GxVoice.GX_StopRecordVoice(7);
2315                         m_Line[7].Status = STATUS.STATUS_IDLE;
2316                         break;
2317                 }
2318                 #endregion
2319             }
2320         }
2321         #endregion
2322 
2323         #region 动作注释
2324 
2325         #endregion
2326 
2327         #region 开始点球准备工作
2328         /// <summary>
2329         /// 开始点球准备工作
2330         /// </summary>
2331         /// <param name="action"></param>
2332         public void RunBallReadyAction(ushort ChannelNo)
2333         {
2334             switch (m_Line[ChannelNo].Status)
2335             {
2336                 //点球开始准备动作
2337                 case STATUS.STATUS_IDLE:
2338                     //  RunBallStartReadyAction();
2339                     break;
2340                 //点球完成准备动作
2341                 case STATUS.STATUS_RECORDING:
2342 
2343                     break;
2344                 default:
2345                     break;
2346             }
2347         }
2348         #endregion
2349 
2350         #region 开始点球
2351         /// <summary>
2352         /// 开始点球
2353         /// </summary>
2354         /// <param name="ChannelNo"></param>
2355         public void RunBall(GxVoiceAPI.GxVoice.GX_MESSAGE_INFO MessageBuffer, uint intRing, char[] ctemp)
2356         {
2357             ushort caller = GxVoiceAPI.GxVoice.GX_StartDetectCallerID(0);
2358             ushort dtmf = GxVoiceAPI.GxVoice.GX_StartDetectDTMF(MessageBuffer.ChannelNo, 1);//识别按键
2359             switch (MessageBuffer.ChannelNo)
2360             {
2361                 case 0:
2362                     //本地
2363                     xunhuan1(MessageBuffer, MessageBuffer.MessageCode, intRing, ctemp);
2364                     break;
2365                 case 1:
2366                     //张佳
2367                     xunhuan2(MessageBuffer, MessageBuffer.MessageCode, intRing, ctemp);
2368                     break;
2369                 case 2:
2370                     //田洪帅
2371                     xunhuan3(MessageBuffer, MessageBuffer.MessageCode, intRing, ctemp);
2372                     break;
2373                 case 3:
2374                     //刘聪
2375                     xunhuan4(MessageBuffer, MessageBuffer.MessageCode, intRing, ctemp);
2376                     break;
2377                 case 4:
2378                     //王毅力
2379                     xunhuan5(MessageBuffer, MessageBuffer.MessageCode, intRing, ctemp);
2380                     break;
2381                 case 5:
2382                     //李姐
2383                     xunhuan6(MessageBuffer, MessageBuffer.MessageCode, intRing, ctemp);
2384                     break;
2385                 case 6:
2386                     //张睿
2387                     xunhuan7(MessageBuffer, MessageBuffer.MessageCode, intRing, ctemp);
2388                     break;
2389                 case 7:
2390                     xunhuan8(MessageBuffer, MessageBuffer.MessageCode, intRing, ctemp);
2391                     break;
2392                 default:
2393                     break;
2394             }
2395         }
2396         #endregion
2397 
2398         /// <summary>
2399         /// 这个是裁判(用死循环来做裁判的实时监督权限)
2400         /// </summary>
2401         private void StartCardWorkNew()
2402         {
2403             try
2404             {
2405                 while (true)
2406                 {
2407                     Thread.Sleep(200);
2408                     GxVoiceAPI.GxVoice.GX_MESSAGE_INFO MessageBuffer;
2409                     char[] ctemp = new char[100];
2410                     uint intRing = 0;
2411                     #region 判断球员是否有犯规
2412                     while (GxVoiceAPI.GxVoice.GX_GetMessageForWindows(5, out MessageBuffer) == GxVoiceAPI.GxVoice.GX_OK)
2413                     {
2414                         #region 如果犯规了,开始指定犯规的线程球员进行点球
2415                         //this.Invoke(RunBall, ChannelNo);
2416                         this.BeginInvoke(_dRunBall, MessageBuffer, intRing, ctemp);
2417                         // RunBall(MessageBuffer, intRing, ctemp);
2418                         #endregion
2419 
2420                     }
2421                     #endregion
2422 
2423                 }
2424             }
2425             catch (Exception ex)
2426             {
2427                 MessageBox.Show(ex.ToString());
2428             }
2429         }
2430 
2431         private void timer1_Tick(object sender, EventArgs e)
2432         {
2433             int i;
2434             for (i = 0; i < m_TotalVoiceChannel; i++)
2435             {
2436                 if (m_Line[i].Ring == 1)
2437                 {
2438                     m_Line[i].TimeCount++;
2439                     if (m_Line[i].TimeCount > 6)
2440                     {
2441                         dgv电话管理.Rows[i].Cells["chanelstate"].Value = "空闲";
2442                         dgv电话管理.Rows[i].Cells["callcode"].Value = "";
2443                         dgv电话管理.Rows[i].Cells["calltype"].Value = "空闲";
2444                         dgv电话管理.Rows[i].Cells["calldate"].Value = "";
2445                         m_Line[i].CallerID = "";
2446                         m_Line[i].Dtmf = "";
2447                         m_Line[i].HookOff = 0;
2448                         m_Line[i].Ring = 0;
2449                         m_Line[i].Status = STATUS.STATUS_IDLE;
2450                     }
2451                 }
2452             }
2453         }
2454 
2455         #region 返回时间差
2456         public static string DateDiff(DateTime DateTime1, DateTime DateTime2)
2457         {
2458             string dateDiff = null;
2459             try
2460             {
2461                 TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
2462                 TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
2463                 TimeSpan ts = ts1.Subtract(ts2).Duration();
2464                 string hours = ts.Hours.ToString(), minutes = ts.Minutes.ToString(), seconds = ts.Seconds.ToString();
2465                 if (ts.Hours < 10)
2466                 {
2467                     hours = "0" + ts.Hours.ToString();
2468                 }
2469                 if (ts.Minutes < 10)
2470                 {
2471                     minutes = "0" + ts.Minutes.ToString();
2472                 }
2473                 if (ts.Seconds < 10)
2474                 {
2475                     seconds = "0" + ts.Seconds.ToString();
2476                 }
2477                 dateDiff = hours + ":" + minutes + ":" + seconds;
2478             }
2479             catch
2480             {
2481 
2482             }
2483             return dateDiff;
2484         }
2485         #endregion
2486 
2487         private void TelManagerTest_FormClosing(object sender, FormClosingEventArgs e)
2488         {
2489             if (MessageBox.Show("你真的要退出系统吗?", "C# Demo", MessageBoxButtons.YesNo) == DialogResult.No)
2490             {
2491                 e.Cancel = true;
2492             }
2493         }
2494 
2495         private void TelManagerTest_FormClosed(object sender, FormClosedEventArgs e)
2496         {
2497             Application.Exit();
2498             Application.ExitThread();
2499             System.Environment.Exit(0);
2500             ReleaseGxVoice();
2501         }
2502     }
2503 }
View Code
卖苹果的小林的主页 卖苹果的小林 | 菜鸟二级 | 园豆:202
提问于:2016-04-26 09:24
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册