C#和硬件驱动交互编程<二> --东进语音卡项目例子.
最近公司的项目比较忙所以没及时更新第二篇.不要骂我是贴代码...
在做这个项目的时候我发现一个问题,假如不是使用机器的内存,而是使用硬件的内存的时候,一定要手动Flush硬件的内存.
我相信这个问题在做东进语音卡项目的时候很多人都会遇到.
好,继续开贴...
myTelNum
1using System;
2using System.Data;
3using System.Data.Sql;
4using System.Data.SqlClient;
5using System.Configuration;
6using System.Collections.Generic;
7using System.Text;
8
9namespace DJVoiceCard.DBMod
10{
11 /**//// <summary>
12 /// 电话号码连接层.连同数据处理;
13 /// </summary>
14 public class myTelNum
15 {
16 private string SqlConnString = ConfigurationSettings.AppSettings["LinkStr"];
17
18 private string _newTelNum=string.Empty;
19 private string _newTelPass=string.Empty;
20 private string[] _newTelStr=new string[2];
21 /**//// <summary>
22 /// 构造连接层
23 /// </summary>
24 public myTelNum()
25 {
26 newTelNum();
27 }
28 数据获取操作#region 数据获取操作
29 /**//// <summary>
30 /// 获取新电话用户得号码
31 /// </summary>
32 private void newTelNum()
33 {
34 string telTemp = string.Empty;
35 SqlConnection sqlConn = new SqlConnection(SqlConnString);
36 string sqlStr = "select top 1* from xwtx_reg_telUser where iIsPassSend=0";
37 SqlDataReader sqlReader;
38 sqlReader = null;
39
40 SqlCommand sqlComm = new SqlCommand(sqlStr, sqlConn);
41 sqlConn.Open();
42 sqlReader = sqlComm.ExecuteReader();
43 if (sqlReader.Read())
44 {
45 if (sqlReader["sTelUserID"]!=null)
46 {
47 _newTelStr[0] = sqlReader["sTelUserID"].ToString();
48 }
49 else
50 {
51 _newTelStr[0] = string.Empty;
52 }
53
54 if (sqlReader["sTelUserPass"] != null)
55 {
56 _newTelStr[1] = sqlReader["sTelUserPass"].ToString();
57 }
58 else
59 {
60 _newTelStr[1] = string.Empty;
61 }
62 }
63 else
64 {
65
66 }
67 sqlReader.Close();
68 sqlConn.Close();
69 sqlComm.Dispose();
70 }
71 /**//// <summary>
72 /// 取得电话号码
73 /// </summary>
74 public string theTelNum
75 {
76 get {
77 if (_newTelStr != null)
78 {
79 newTelNum();
80 if (_newTelStr.Length == 2)
81 {
82 if (_newTelStr[0] != null)
83 {
84 _newTelNum = _newTelStr[0];
85 }
86 else
87 {
88 _newTelNum="";
89 }
90 }
91 else
92 { _newTelNum = ""; }
93 }
94 return _newTelNum; }
95
96 }
97
98 /**//// <summary>
99 /// 获取电话号码对应得密码
100 /// </summary>
101 public string theTelPass
102 {
103 get {
104 if (_newTelStr != null)
105 {
106 if (_newTelStr.Length == 2)
107 {
108 if (_newTelStr[1] != null)
109 {
110 _newTelPass = _newTelStr[1];
111 }
112 else
113 {
114 _newTelPass = "";
115 }
116 }
117 else
118 { _newTelPass = ""; }
119 }
120 return _newTelPass;
121 }
122 }
123
124 /**//// <summary>
125 /// 根据号码获取密码
126 /// </summary>
127 /// <param name="TelNum"></param>
128 /// <returns></returns>
129 public string GetTelPass(string TelNum)
130 {
131 string Pass = string.Empty;
132 SqlConnection sqlConn = new SqlConnection(SqlConnString);
133 string sqlStr = "select * from xwtx_reg_telUser where sTelUserID='" + TelNum + "'";
134 SqlDataReader sqlReader;
135 sqlReader = null;
136 SqlCommand sqlComm = new SqlCommand(sqlStr, sqlConn);
137 sqlConn.Open();
138 sqlReader = sqlComm.ExecuteReader();
139 if (sqlReader.Read())
140 {
141 if (sqlReader["sTelUserPass"] != null)
142 {
143 Pass = sqlReader["sTelUserPass"].ToString();
144 }
145 else
146 {
147 Pass = string.Empty;
148 }
149 }
150 else
151 {
152
153 }
154 sqlReader.Close();
155 sqlConn.Close();
156 sqlComm.Dispose();
157 return Pass;
158 }
159
160 #endregion
161
162 数据更新#region 数据更新
163 /**//// <summary>
164 /// 密码发送成功
165 /// </summary>
166 /// <param name="TelNum"></param>
167 /// <returns></returns>
168 private bool ISupdateTelNum(string TelNum)
169 {
170 if (TelNum==string.Empty)
171 {
172 TelNum = "0";
173 }
174 string sqlStr = "Update xwtx_reg_telUser set iIsPassSend=1 where sTelUserID='" + TelNum + "'";
175 SqlConnection sqlconn = new SqlConnection(SqlConnString);
176 SqlCommand sqlComm = new SqlCommand(sqlStr, sqlconn);
177 try
178 {
179 sqlconn.Open();
180 sqlComm.ExecuteNonQuery();
181
182 sqlconn.Close();
183 return true;
184 }
185 catch
186 {
187 if (sqlconn.State.ToString().ToLower() != "closed")
188 { sqlconn.Close(); }
189 return false;
190 }
191 }
192 /**//// <summary>
193 /// 密码发送后调用
194 /// </summary>
195 public bool ISmodify
196 {
197 get { return ISupdateTelNum(_newTelNum); }
198 }
199
200 public bool ISCompelet(string TelNum)
201 {
202 return ISupdateTelNum(TelNum);
203 }
204 /**//// <summary>
205 /// 密码发送失败
206 /// </summary>
207 /// <param name="TelNum"></param>
208 public void FailSend(string TelNum)
209 {
210 if (TelNum == string.Empty)
211 {
212 TelNum = "0";
213 }
214 string sqlStr = "Update xwtx_reg_telUser set iIsPassSend=3 where sTelUserID='" + TelNum + "'";
215 SqlConnection sqlconn = new SqlConnection(SqlConnString);
216 SqlCommand sqlComm = new SqlCommand(sqlStr, sqlconn);
217 try
218 {
219 sqlconn.Open();
220 sqlComm.ExecuteNonQuery();
221
222 sqlconn.Close();
223
224 }
225 catch
226 {
227 if (sqlconn.State.ToString().ToLower() != "closed")
228 { sqlconn.Close(); }
229
230 }
231 }
232 #endregion
233
234 日志记录#region 日志记录
235 public void LogModify(string TelNum,string ErrorMessage)
236 {
237 if (TelNum == string.Empty)
238 {
239 TelNum = "0";
240 }
241 string sqlStr = "insert into xwtx_reg_telUser_Log(logContxt,logDate) values('发送用户" + TelNum + "密码时,发生" + ErrorMessage + ":错误','" + DateTime.Now + "')";
242 SqlConnection sqlconn = new SqlConnection(SqlConnString);
243 SqlCommand sqlComm = new SqlCommand(sqlStr, sqlconn);
244 try
245 {
246 sqlconn.Open();
247 sqlComm.ExecuteNonQuery();
248
249 sqlconn.Close();
250
251 }
252 catch
253 {
254 if (sqlconn.State.ToString().ToLower() != "closed")
255 { sqlconn.Close(); }
256
257 }
258 }
259 #endregion
260
261 }
262}
263
1using System;
2using System.Data;
3using System.Data.Sql;
4using System.Data.SqlClient;
5using System.Configuration;
6using System.Collections.Generic;
7using System.Text;
8
9namespace DJVoiceCard.DBMod
10{
11 /**//// <summary>
12 /// 电话号码连接层.连同数据处理;
13 /// </summary>
14 public class myTelNum
15 {
16 private string SqlConnString = ConfigurationSettings.AppSettings["LinkStr"];
17
18 private string _newTelNum=string.Empty;
19 private string _newTelPass=string.Empty;
20 private string[] _newTelStr=new string[2];
21 /**//// <summary>
22 /// 构造连接层
23 /// </summary>
24 public myTelNum()
25 {
26 newTelNum();
27 }
28 数据获取操作#region 数据获取操作
29 /**//// <summary>
30 /// 获取新电话用户得号码
31 /// </summary>
32 private void newTelNum()
33 {
34 string telTemp = string.Empty;
35 SqlConnection sqlConn = new SqlConnection(SqlConnString);
36 string sqlStr = "select top 1* from xwtx_reg_telUser where iIsPassSend=0";
37 SqlDataReader sqlReader;
38 sqlReader = null;
39
40 SqlCommand sqlComm = new SqlCommand(sqlStr, sqlConn);
41 sqlConn.Open();
42 sqlReader = sqlComm.ExecuteReader();
43 if (sqlReader.Read())
44 {
45 if (sqlReader["sTelUserID"]!=null)
46 {
47 _newTelStr[0] = sqlReader["sTelUserID"].ToString();
48 }
49 else
50 {
51 _newTelStr[0] = string.Empty;
52 }
53
54 if (sqlReader["sTelUserPass"] != null)
55 {
56 _newTelStr[1] = sqlReader["sTelUserPass"].ToString();
57 }
58 else
59 {
60 _newTelStr[1] = string.Empty;
61 }
62 }
63 else
64 {
65
66 }
67 sqlReader.Close();
68 sqlConn.Close();
69 sqlComm.Dispose();
70 }
71 /**//// <summary>
72 /// 取得电话号码
73 /// </summary>
74 public string theTelNum
75 {
76 get {
77 if (_newTelStr != null)
78 {
79 newTelNum();
80 if (_newTelStr.Length == 2)
81 {
82 if (_newTelStr[0] != null)
83 {
84 _newTelNum = _newTelStr[0];
85 }
86 else
87 {
88 _newTelNum="";
89 }
90 }
91 else
92 { _newTelNum = ""; }
93 }
94 return _newTelNum; }
95
96 }
97
98 /**//// <summary>
99 /// 获取电话号码对应得密码
100 /// </summary>
101 public string theTelPass
102 {
103 get {
104 if (_newTelStr != null)
105 {
106 if (_newTelStr.Length == 2)
107 {
108 if (_newTelStr[1] != null)
109 {
110 _newTelPass = _newTelStr[1];
111 }
112 else
113 {
114 _newTelPass = "";
115 }
116 }
117 else
118 { _newTelPass = ""; }
119 }
120 return _newTelPass;
121 }
122 }
123
124 /**//// <summary>
125 /// 根据号码获取密码
126 /// </summary>
127 /// <param name="TelNum"></param>
128 /// <returns></returns>
129 public string GetTelPass(string TelNum)
130 {
131 string Pass = string.Empty;
132 SqlConnection sqlConn = new SqlConnection(SqlConnString);
133 string sqlStr = "select * from xwtx_reg_telUser where sTelUserID='" + TelNum + "'";
134 SqlDataReader sqlReader;
135 sqlReader = null;
136 SqlCommand sqlComm = new SqlCommand(sqlStr, sqlConn);
137 sqlConn.Open();
138 sqlReader = sqlComm.ExecuteReader();
139 if (sqlReader.Read())
140 {
141 if (sqlReader["sTelUserPass"] != null)
142 {
143 Pass = sqlReader["sTelUserPass"].ToString();
144 }
145 else
146 {
147 Pass = string.Empty;
148 }
149 }
150 else
151 {
152
153 }
154 sqlReader.Close();
155 sqlConn.Close();
156 sqlComm.Dispose();
157 return Pass;
158 }
159
160 #endregion
161
162 数据更新#region 数据更新
163 /**//// <summary>
164 /// 密码发送成功
165 /// </summary>
166 /// <param name="TelNum"></param>
167 /// <returns></returns>
168 private bool ISupdateTelNum(string TelNum)
169 {
170 if (TelNum==string.Empty)
171 {
172 TelNum = "0";
173 }
174 string sqlStr = "Update xwtx_reg_telUser set iIsPassSend=1 where sTelUserID='" + TelNum + "'";
175 SqlConnection sqlconn = new SqlConnection(SqlConnString);
176 SqlCommand sqlComm = new SqlCommand(sqlStr, sqlconn);
177 try
178 {
179 sqlconn.Open();
180 sqlComm.ExecuteNonQuery();
181
182 sqlconn.Close();
183 return true;
184 }
185 catch
186 {
187 if (sqlconn.State.ToString().ToLower() != "closed")
188 { sqlconn.Close(); }
189 return false;
190 }
191 }
192 /**//// <summary>
193 /// 密码发送后调用
194 /// </summary>
195 public bool ISmodify
196 {
197 get { return ISupdateTelNum(_newTelNum); }
198 }
199
200 public bool ISCompelet(string TelNum)
201 {
202 return ISupdateTelNum(TelNum);
203 }
204 /**//// <summary>
205 /// 密码发送失败
206 /// </summary>
207 /// <param name="TelNum"></param>
208 public void FailSend(string TelNum)
209 {
210 if (TelNum == string.Empty)
211 {
212 TelNum = "0";
213 }
214 string sqlStr = "Update xwtx_reg_telUser set iIsPassSend=3 where sTelUserID='" + TelNum + "'";
215 SqlConnection sqlconn = new SqlConnection(SqlConnString);
216 SqlCommand sqlComm = new SqlCommand(sqlStr, sqlconn);
217 try
218 {
219 sqlconn.Open();
220 sqlComm.ExecuteNonQuery();
221
222 sqlconn.Close();
223
224 }
225 catch
226 {
227 if (sqlconn.State.ToString().ToLower() != "closed")
228 { sqlconn.Close(); }
229
230 }
231 }
232 #endregion
233
234 日志记录#region 日志记录
235 public void LogModify(string TelNum,string ErrorMessage)
236 {
237 if (TelNum == string.Empty)
238 {
239 TelNum = "0";
240 }
241 string sqlStr = "insert into xwtx_reg_telUser_Log(logContxt,logDate) values('发送用户" + TelNum + "密码时,发生" + ErrorMessage + ":错误','" + DateTime.Now + "')";
242 SqlConnection sqlconn = new SqlConnection(SqlConnString);
243 SqlCommand sqlComm = new SqlCommand(sqlStr, sqlconn);
244 try
245 {
246 sqlconn.Open();
247 sqlComm.ExecuteNonQuery();
248
249 sqlconn.Close();
250
251 }
252 catch
253 {
254 if (sqlconn.State.ToString().ToLower() != "closed")
255 { sqlconn.Close(); }
256
257 }
258 }
259 #endregion
260
261 }
262}
263
这段是获取数据库里面的东东的.具体来说对整个例子的意义不大..
下面开始的是业务逻辑部分.个人觉得是比较重要的部分.里面有很多代码没有经过优化.我贴出来了.希望大家不要骂我呃.
DailMain
1using System;
2using System.Collections.Generic;
3using System.Configuration;
4using System.ComponentModel;
5using System.Data;
6using System.Drawing;
7using System.Text;
8using System.Windows.Forms;
9using DJVoiceCard.DL;
10using System.Runtime.InteropServices;
11using DJVoiceCard.Lib;
12using System.Data.OleDb;
13using System.IO;
14using System.Threading;
15using DJVoiceCard.DBMod;
16
17namespace DJVoiceCard.App
18{
19 public partial class DailMain : Form
20 {
21
22 //private static string[] _FileArr;
23
24 /**////// <summary>
25 ///// 语音文件路径
26 ///// </summary>
27 //public string[] FileArr { get { return _FileArr; } set { _FileArr = value; } }
28 //private static string _CalloutST=string.Empty;
29
30 /**////// <summary>
31 ///// 调用状态
32 ///// </summary>
33 //public static string CalloutST
34 //{
35 // get { return _CalloutST; }
36 // set { _CalloutST = value; }
37 //}
38 /**//// <summary>
39 /// 中继通道总数;
40 /// </summary>
41 private int iTunkTotal;
42 /**//// <summary>
43 /// 用户通道数
44 /// </summary>
45 private int iUserTotal;
46
47 /**//// <summary>
48 /// 主叫电话号码
49 /// </summary>
50 public string MyCallNO =ConfigurationSettings.AppSettings["calleeNum"];
51 public string WelcomeTo=ConfigurationSettings.AppSettings["Welcome"];
52 public string PassReadBegin = ConfigurationSettings.AppSettings["PassReadBegin"];
53 public string PassRead = ConfigurationSettings.AppSettings["PassRead"];
54 public string EndSystem = ConfigurationSettings.AppSettings["EndSystem"];
55 private string DbPath = ConfigurationSettings.AppSettings["LinkStr"];
56 private string CallOutNum = string.Empty;
57
58 public string VoiceST = string.Empty;
59 ulong nOutCall ;
60 ulong nMyCallNo ;
61
62 /**//// <summary>
63 /// 公共线程,主要用来拨号
64 /// </summary>
65 //public Thread TheadCall;
66
67 /**//// <summary>
68 /// 信道使用状态
69 /// </summary>
70 public string TrunkState=string.Empty;
71 /**//// <summary>
72 /// 用户状态
73 /// </summary>
74 public UR_ST[] URS = new UR_ST[120];
75
76 /**//// <summary>
77 /// 信道状态
78 /// </summary>
79 public TRK_ST[] TST = new TRK_ST[120];
80 string[] CallST=new string[120];
81 int[] arrVoiceChn=new int[10];
82 public DailMain()
83 {
84 InitializeComponent();
85 }
86
87 private void Dail_Load(object sender, EventArgs e)
88 {
89 SysInit();
90 }
91
92 private void DailMain_FormClosing(object sender, FormClosingEventArgs e)
93 {
94 ReacurseTrunk();
95 SysFunction.SysExit();
96 this.Dispose();
97 base.Dispose();
98 }
99
100 private void btnExit_Click(object sender, EventArgs e)
101 {
102 ExitSys();
103 }
104
105 private void TimeChk_Tick(object sender, EventArgs e)
106 {
107 SysFunction.Push_GerEvent();
108 TrunkTimerWork();
109 StateView();
110 dbCall();
111 }
112
113 private void btnCall_Click(object sender, EventArgs e)
114 {
115 string telNum=txtTelNO.Text.Trim();
116 if (telNum.Length < 6)
117 {
118
119 MessageBox.Show("请输入正确的号码");
120 txtTelNO.Text = "";
121 }
122 else
123 {
124 CallOut(telNum);
125 }
126
127 }
128
129 初始化系统#region 初始化系统
130 /**//// <summary>
131 /// 初始化系统
132 /// </summary>
133 private void SysInit()
134 {
135 string sErr = string.Empty;
136 bool isSysLoad = SysFunction.SysInit(ref sErr);
137 if (isSysLoad)
138 {
139 iTunkTotal = SysFunction.iTrkTotal();
140 for (int i = 0; i < iTunkTotal; i++)
141 {
142 TST[i].ConnTrID = -1;
143 TST[i].ConnUrID = -1;
144 TST[i].ST = TRUNK_ST.TRK_FREE;
145 TST[i].DialNum = string.Empty;
146 }
147
148 iUserTotal = SysFunction.iUserTotal();
149 for (int i = 0; i < iUserTotal; i++)
150 {
151 SysFunction.UserPowerOn(i);
152 if (SysFunction.UserEnableDailSound(i))
153 {
154 URS[i].ConnTrID = -1;
155 URS[i].ConnTrID = -1;
156 URS[i].ST = USER_STATE.USR_ONHOOK;
157 }
158 else
159 {
160 MessageBox.Show("初始化用户模块失败");
161 ExitSys();
162 break;
163 }
164 }
165
166 arrVoiceChn[1] = SysFunction.iFreeVoiceCHNID();
167 StringBuilder busy = new StringBuilder("BUSY");
168 if (SysFunction.LoopVoiceM(arrVoiceChn[1], busy))
169 {
170
171 }
172 arrVoiceChn[2] = SysFunction.iFreeVoiceCHNID();
173 StringBuilder ring = new StringBuilder("RING");
174 if (SysFunction.LoopVoiceM(arrVoiceChn[2], ring))
175 {
176
177 }
178 arrVoiceChn[3] = SysFunction.iFreeVoiceCHNID();
179 StringBuilder tone = new StringBuilder("TONE");
180 if (SysFunction.LoopVoiceM(arrVoiceChn[2], tone))
181 {
182
183 }
184
185 lvChn.BeginUpdate();
186 for (int i = 0; i < iTunkTotal; i++)
187 {
188 ListViewItem lvi = new ListViewItem();
189 lvi.Text = i.ToString();
190 lvi.SubItems.Add("");
191 lvi.SubItems.Add("");
192 lvi.SubItems.Add("");
193 lvi.SubItems.Add("");
194 lvi.SubItems.Add("");
195 lvi.SubItems.Add("");
196 lvChn.Items.Add(lvi);
197 }
198 lvChn.EndUpdate();
199 StateView();
200 }
201 else
202 {
203 //MessageBox.Show(sErr);
204 // ExitSys();
205 }
206 }
207 #endregion
208
209 Exit System#region Exit System
210 /**//// <summary>
211 /// 退出系统
212 /// </summary>
213 public void ExitSys()
214 {
215 ReacurseTrunk();
216 SysFunction.SysExit();
217 this.Dispose();
218 base.Dispose();
219 }
220
221
222 #endregion
223
224 数据处理#region 数据处理
225 /**//// <summary>
226 /// 读取数据 拨号
227 /// </summary>
228 public void dbCall()
229 {
230 if (TrunkState != "Calling")
231 {
232 myTelNum mytel = new myTelNum();
233 if (mytel.theTelNum != string.Empty)
234 {
235 lblMsg.Text = DateTime.Now.ToString()+"自动发送";
236 TheadCallOut();
237 }
238 else
239 {
240 lblMsg.Text = DateTime.Now + "无可用号码";
241 }
242
243 }
244 else
245 {
246 lblMsg.Text = DateTime.Now+"自动发送信道使用中";
247 }
248 }
249 #endregion
250
251 更新控件数据显示#region 更新控件数据显示
252
253 /**//// <summary>
254 /// 向控件更新数据
255 /// </summary>
256 public void StateView()
257 {
258 SysFunction.Push_GerEvent();
259 iTunkTotal = SysFunction.iTrkTotal();
260 for (int i = 0; i < iTunkTotal; i++)
261 {
262 DrawTrunkState(i);
263 }
264 }
265 #endregion
266
267 信道状态轮询#region 信道状态轮询
268 /**//// <summary>
269 /// 轮询
270 /// </summary>
271 public void TrunkTimerWork()
272 {
273 //int iVoiceID;
274 int iResult;
275 iTunkTotal = SysFunction.iTrkTotal();
276
277 for (int i = 0; i < iTunkTotal; i++)
278 {
279
280 iResult = SysFunction.iRaleyStetes((byte)(i / 30), (byte)(i % 30));
281 if (iResult == (int)RelayStates.ISUP_CH_WAIT_RELEASE)
282 {
283 VoiceST =string.Empty;
284 TrunkState = string.Empty;
285 ReaseceTrunckCHN(i);
286 SysFunction.SetRelayStates(i, (int)RelayStates.ISUP_CH_FREE);
287 lvChn.BeginUpdate();
288 lvChn.Items[i].SubItems[5].Text = "";
289 lvChn.EndUpdate();
290 }
291
292 if (SysFunction.iRaleyStetes(((byte)(i / 30)), ((byte)(i % 30))) == (int)RelayStates.ISUP_CALLER_CONNECT)
293 {
294 //lblMsg.Text = "去话连通.";
295 TrunkState = "Calling";
296 bool beFinish = false;
297 int iST = SysFunction.iCallOutStates(i / 30, i % 30);
298 string calleeNum = CalleeNum(i / 30, i % 30);
299 处理声音播放#region 处理声音播放
300 unsafe
301 {
302 byte[] filePath = GetFilePath(WelcomeTo);
303
304 try
305 {
306 TrunkState = "Calling";
307 lblTrunk.Text = "信道状态是:" + VoiceST;
308 注释掉的东西,以后备用#region 注释掉的东西,以后备用
309 /**//*if (Convert.ToBoolean(iST & 0x10))
310 {
311 int iCPGval = SysFunction.iCPGReval(i);
312 int iISUPval = SysFunction.ISUPReVal(i);
313 }*/
314
315 //if (SysFunction.iRaleyStetes(((byte)(i / 30)), ((byte)(i % 30))) == (int)RelayStates.ISUP_CALLER_CONNECT)
316 //{
317 out#region out
318 //PlayFiles(i);
319 //PlayVoiceBegin(i, MusicFile);
320 //PlayVoice(i, "call.005");
321 //PlayVoiceEnd(i, "call.006");
322
323 /**//*if (SysFunction.bISplayVoice(i, filePath))
324 {
325 beFinish = true;
326 lblMsg.Text += Encoding.UTF8.GetString(filePath);
327 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
328 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
329 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
330 {
331 SysFunction.StopPlayVocInTrunk(i);
332 ReaseceTrunckCHN(i);
333 beFinish = true;
334 }
335 }
336 else
337 {
338 TST[i].ST = TRUNK_ST.TRK_PLAY;
339 }*/
340 /**//*
341 bool PlayNext = false;
342
343 if(SysFunction.bISplayVoice(i,filePath))
344 {
345 if (PlayNext)
346 {
347 SysFunction.StopPlayVocInTrunk(i);
348 ReaseceTrunckCHN(i);
349 }
350 if (!PlayNext)
351 {
352 SysFunction.StopPlayVocInTrunk(i);
353 ReaseceTrunckCHN(i);
354 }
355 }
356 beFinish = true;
357 * */
358
359 /**//*if (SysFunction.bISplayVoice(i, filePath))
360 {
361 lblMsg.Text += Encoding.UTF8.GetString(filePath);
362 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
363 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
364 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
365 {
366 SysFunction.StopPlayVocInTrunk(i);
367 ReaseceTrunckCHN(i);
368 beFinish = true;
369 }
370 }*/
371 #endregion
372 //MessageBox.Show(VoiceST);
373 声音播放状态判断#region 声音播放状态判断
374 //声音播放状态
375 /**//*
376 switch (VoiceST)
377 {
378 case "Callout":
379 {
380 lblTrunk.Text = "信道状态是:" + VoiceST;
381 SysFunction.bISplayVoice(i, filePath);
382 VoiceST = "Welcome";
383 //if (SysFunction.bISplayVoice(i, filePath))
384 //{
385 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
386 //int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
387 //if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
388 //{
389 // lblTrunk.Text = "信道状态是:" + VoiceST;
390 // //SysFunction.StopPlayVocInTrunk(i);
391 // //ReaseceTrunckCHN(i);
392 // //beFinish = true;
393 // VoiceST = "Welcome";
394 //}
395 //}
396 break;
397 }
398 case "Welcome":
399 {
400 lblTrunk.Text = "信道状态是:" + VoiceST;
401 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
402 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
403 {
404 SysFunction.bISplayVoice(i, GetFilePath("bank.005"));
405 VoiceST = "ReadUser";
406 //if (SysFunction.bISplayVoice(i, GetFilePath("bank.005")))
407 //{
408 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
409 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
410 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
411 // {
412 // lblTrunk.Text = "信道状态是:" + VoiceST;
413 // //SysFunction.StopPlayVocInTrunk(i);
414 // //ReaseceTrunckCHN(i);
415 // //beFinish = true;
416 // VoiceST = "ReadUser";
417 // }
418 //}
419 }
420 break;
421 }
422 case "ReadUser":
423 {
424 lblTrunk.Text = "信道状态是:" + VoiceST;
425 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
426 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
427 {
428 SysFunction.bISplayVoice(i, GetFilePath("bank.006"));
429 VoiceST = "SendUser";
430 //if (SysFunction.bISplayVoice(i, GetFilePath("bank.006")))
431 //{
432 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
433 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
434 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
435 // {
436 // lblTrunk.Text = "信道状态是:" + VoiceST;
437 // //SysFunction.StopPlayVocInTrunk(i);
438 // //ReaseceTrunckCHN(i);
439 // //beFinish = true;
440 // VoiceST = "SendUser";
441 // }
442 //}
443 }
444 break;
445 }
446 case "SendUser":
447 {
448 lblTrunk.Text = "信道状态是:" + VoiceST;
449 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
450 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
451 {
452 SysFunction.bISplayVoice(i, GetFilePath("bank.007"));
453 VoiceST = "ReadPass";
454 //if (SysFunction.bISplayVoice(i, GetFilePath("bank.007")))
455 //{
456 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
457 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
458 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
459 // {
460 // lblTrunk.Text = "信道状态是:" + VoiceST;
461 // //SysFunction.StopPlayVocInTrunk(i);
462 // //ReaseceTrunckCHN(i);
463 // //beFinish = true;
464 // VoiceST = "ReadPass";
465 // }
466 //}
467 }
468 break;
469 }
470 case "ReadPass":
471 {
472 lblTrunk.Text = "信道状态是:" + VoiceST;
473 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
474 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
475 {
476 SysFunction.bISplayVoice(i, GetFilePath("bank.001"));
477 VoiceST = "SendPass";
478 //if (SysFunction.bISplayVoice(i, GetFilePath("bank.001")))
479 //{
480 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
481 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
482 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
483 // {
484 // lblTrunk.Text = "信道状态是:" + VoiceST;
485 // //SysFunction.StopPlayVocInTrunk(i);
486 // //ReaseceTrunckCHN(i);
487 // //beFinish = true;
488 // VoiceST = "SendPass";
489 // }
490 //}
491 }
492 break;
493 }
494 case "SendPass":
495 {
496 lblTrunk.Text = "信道状态是:" + VoiceST;
497 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
498 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
499 {
500 SysFunction.bISplayVoice(i, GetFilePath("D1"));
501 VoiceST = "ReSendPass";
502 //if (SysFunction.bISplayVoice(i, GetFilePath("D1")))
503 //{
504 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
505 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
506 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
507 // {
508 // lblTrunk.Text = "信道状态是:" + VoiceST;
509 // //SysFunction.StopPlayVocInTrunk(i);
510 // //ReaseceTrunckCHN(i);
511 // //beFinish = true;
512 // VoiceST = "ReSendPass";
513 // }
514 //}
515 }
516 break;
517 }
518 case "ReSendPass":
519 {
520 lblTrunk.Text = "信道状态是:" + VoiceST;
521 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
522 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
523 {
524 SysFunction.bISplayVoice(i, GetFilePath("D1"));
525 VoiceST = "EndSystem";
526 //if (SysFunction.bISplayVoice(i, GetFilePath("D1")))
527 //{
528 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
529 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
530 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
531 // {
532 // lblTrunk.Text = "信道状态是:" + VoiceST;
533 // //SysFunction.StopPlayVocInTrunk(i);
534 // //ReaseceTrunckCHN(i);
535 // //beFinish = true;
536 // VoiceST = "EndSystem";
537 // }
538 //}
539 }
540 break;
541 }
542 case "EndSystem":
543 {
544 lblTrunk.Text = "信道状态是:" + VoiceST;
545 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
546 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
547 {
548 SysFunction.bISplayVoice(i, GetFilePath("bank.002"));
549 VoiceST = "ExitSystem";
550 //if (SysFunction.bISplayVoice(i, GetFilePath("bank.002")))
551 //{
552 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
553 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
554 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
555 // {
556 // lblTrunk.Text = "信道状态是:" + VoiceST;
557 // SysFunction.StopPlayVocInTrunk(i);
558 // ReaseceTrunckCHN(i);
559 // beFinish = true;
560 // VoiceST = "";
561 // }
562 //}
563 }
564 break;
565 }
566 case "ExitSystem":
567 {
568 lblTrunk.Text = "信道状态是:" + VoiceST;
569 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
570 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
571 {
572 SysFunction.StopPlayVocInTrunk(i);
573 ReaseceTrunckCHN(i);
574 beFinish = true;
575 }
576 //if (SysFunction.bISplayVoice(i, filePath))
577 //{
578 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
579 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
580 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
581 // {
582 // lblTrunk.Text = "信道状态是:" + VoiceST;
583 // //SysFunction.StopPlayVocInTrunk(i);
584 // //ReaseceTrunckCHN(i);
585 // //beFinish = true;
586 // VoiceST = "Welcome";
587 // }
588 //}
589 break;
590 }
591 default:
592 {
593 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
594 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
595 {
596 SysFunction.StopPlayVocInTrunk(i);
597 ReaseceTrunckCHN(i);
598 beFinish = false;
599 }
600 break;
601 }
602
603
604 }
605 */
606 #endregion
607 //}
608
609 #endregion
610
611 if (VoiceST == "Callout")
612 {
613 myTelNum tn = new myTelNum();
614 string TelNum = calleeNum;
615 SysFunction.PlayFileInit(i);
616 AddIndexFiles(i, WelcomeTo);
617 string SysCalleeNum = Encoding.UTF8.GetString(SysFunction.GetCallNum(i / 30, i % 30).bCallNum);
618 string TelPass = tn.GetTelPass(SysCalleeNum);
619 for (int t = 0; t < SysCalleeNum.Length; t++)
620 {
621 string tmp = "d" + SysCalleeNum[t].ToString();
622 AddIndexFiles(i, tmp.Trim());
623 }
624 if (TelPass != string.Empty || TelPass != null)
625 {
626 AddIndexFiles(i, PassReadBegin);
627 AddIndexFiles(i, PassRead);
628 for (int p = 0; p < TelPass.Length; p++)
629 {
630 string ptmp = "d" + TelPass[p].ToString();
631 AddIndexFiles(i, ptmp.Trim());
632 }
633 AddIndexFiles(i, PassRead);
634 for (int p = 0; p < TelPass.Length; p++)
635 {
636 string ptmp = "d" + TelPass[p].ToString();
637 AddIndexFiles(i, ptmp.Trim());
638 }
639 }
640 AddIndexFiles(i, EndSystem);
641 SysFunction.PlayFileStart(i);
642 VoiceST="FilePlay";
643 }
644
645 if (VoiceST == "FilePlay")
646 {
647 if (SysFunction.PlayFileEndCHK(i))
648 {
649 VoiceST = "PlayEnd";
650 }
651 //if()
652 }
653 if (VoiceST == "PlayEnd")
654 {
655 SysFunction.PlayFileEnd(i);
656 beFinish = true;
657 }
658
659 }
660 catch (Exception ex)
661 {
662 lblTrunk.Text =ex.Message.ToString();
663
664 myTelNum tn = new myTelNum();
665 tn.LogModify(Encoding.UTF8.GetString(SysFunction.GetCallNum(i / 30, i % 30).bCallNum), ex.Message);
666 beFinish = false;
667 ReaseceTrunckCHN(i);
668 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_FREE);
669 TrunkState = string.Empty;
670
671 }
672 }
673
674 //数据插入
675 if (beFinish)
676 {
677 lblTrunk.Text = "播放结束";
678 myTelNum mt = new myTelNum();
679 mt.ISCompelet(Encoding.UTF8.GetString(SysFunction.GetCallNum(i / 30, i % 30).bCallNum));
680 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
681 ReaseceTrunckCHN(i);
682 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_FREE);
683 TrunkState = string.Empty;
684 VoiceST = string.Empty;
685 }
686 else
687 {
688 //MessageBox.Show("beFinish:" + beFinish.ToString());
689 /**//*ReaseceTrunckCHN(i);
690 myTelNum tn = new myTelNum();
691 tn.LogModify(calleeNum,"密码发送失败");
692 beFinish = false;
693 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_FREE);
694 TrunkState = string.Empty;*/
695
696 }
697 #endregion
698 }
699
700 //if (SysFunction.iRaleyStetes(((byte)(i / 30)), ((byte)(i % 30))) == (int)RelaySet.ISUP_CH_SET_REL)
701 //{
702 // lblTrunk.Text = "播放完毕,准备挂机";
703 // ReaseceTrunckCHN(i);
704 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_FREE);
705 // TrunkState = string.Empty;
706 // VoiceST = string.Empty;
707 //}
708
709 if (SysFunction.iRaleyStetes(((byte)(i / 30)), ((byte)(i % 30))) == (int)RelayStates.ISUP_CALLER_WAIT_ANM)
710 {
711 TrunkState = "Calling";
712 lblMsg.Text = "等待被叫响应";
713 }
714 if (SysFunction.iRaleyStetes(((byte)(i / 30)), ((byte)(i % 30))) == (int)RelayStates.ISUP_CALLEE_RECV_IAM)
715 {
716 TrunkState = "Calling";
717 lblMsg.Text = "呼叫到达";
718 }
719 注释掉的东西不知道以后有没有用哈#region 注释掉的东西不知道以后有没有用哈
720 /**//*if (TST[i].ST == TRUNK_ST.TRK_PLAY)
721 {
722 iVoiceID = SysFunction.iVoicePlayForTrunk(i);
723 if (iVoiceID == -1)
724 {
725 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
726 return;
727 }
728 else
729 {
730 if (SysFunction.bIsVocPlayEnd(iResult))
731 {
732 SysFunction.StopPlayVocInTrunk(i);
733 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
734 TST[i].ST = TRUNK_ST.TRK_HANGUP;
735 }
736 }
737 }*/
738 #endregion
739 }
740 }
741 #endregion
742
743 播放声音#region 播放声音
744
745 /**//// <summary>
746 /// 开始播放声音
747 /// </summary>
748 /// <param name="TrunkID"></param>
749 /// <param name="FileNames"></param>
750 public void PlayVoiceBegin(int TrunkID, string FileNames)
751 {
752 byte[] filePath = GetFilePath(FileNames);
753 //int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(TrunkID);
754 if (SysFunction.iRaleyStetes(((byte)(TrunkID / 30)), ((byte)(TrunkID % 30))) == (int)RelayStates.ISUP_CALLEE_CONNECT)
755 {
756 bool IsPlay = SysFunction.bISplayVoice(TrunkID, filePath);
757 }
758 }
759
760 /**//// <summary>
761 /// 连续播放声音
762 /// </summary>
763 /// <param name="TrunkID"></param>
764 /// <param name="FileNames"></param>
765 public void PlayVoice(int TrunkID, string FileNames)
766 {
767 byte[] filePath = GetFilePath(FileNames);
768 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(TrunkID);
769 if (SysFunction.bIsVocPlayEnd(TrunkID))
770 {
771 bool IsPlay = SysFunction.bISplayVoice(TrunkID, filePath);
772 if(IsPlay)
773 {
774 SysFunction.StopPlayVocInTrunk(TrunkID);
775 ReaseceTrunckCHN(TrunkID);
776 //beFinish = true;
777 //此处处理程序;
778 }
779 }
780 }
781
782 public void PlayVoiceEnd(int TrunkID, string FileNames)
783 {
784 byte[] filePath = GetFilePath(FileNames);
785 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(TrunkID);
786 if (SysFunction.bIsVocPlayEnd(TrunkID))
787 {
788 bool IsPlay = SysFunction.bISplayVoice(TrunkID, filePath);
789 if (IsPlay)
790 {
791 //此处处理程序;
792 }
793 }
794 }
795 #endregion
796
797 索引播音(多文件播音)#region 索引播音(多文件播音)
798
799 /**//// <summary>
800 /// 添加索引音乐文件
801 /// </summary>
802 /// <param name="TrunkID"></param>
803 /// <param name="FileNames"></param>
804 public void AddIndexFiles(int TrunkID,string FileNames)
805 {
806 byte[] FileArr = GetFilePath(FileNames);
807 SysFunction.AddIndexFile(TrunkID, FileArr);
808 }
809
810 #endregion
811
812 中继通道状态遍历#region 中继通道状态遍历
813 /**//// <summary>
814 /// 信道状态
815 /// </summary>
816 /// <param name="iTrunkID"></param>
817 /// <returns></returns>
818
819 public void DrawTrunkState(int iTrunkID)
820 {
821 string sST = string.Empty;
822 string sCalleeNum = string.Empty;
823 string sCallerNum = string.Empty;
824 int iTrunkST = SysFunction.iRaleyStetes((byte)(iTrunkID / 30), (byte)(iTrunkID % 30));
825 switch (iTrunkST)
826 {
827 case (int)RelayStates.ISUP_CH_WAIT_RELEASE:
828 {
829 sST = ("不可用");
830 break;
831 }
832 case (int)RelayStates.ISUP_CH_FREE:
833 {
834 sST = ("空闲");
835 break;
836 }
837 case (int)RelayStates.ISUP_CALLEE_CONNECT:
838 {
839 sST = ("来话摘机");
840 break;
841 }
842 case (int)RelayStates.ISUP_CALLER_CONNECT:
843 {
844 TrunkState = "Calling";
845 sCalleeNum =Encoding.UTF8.GetString(SysFunction.GetCallNum(iTrunkID / 30, iTrunkID % 30).bCallNum);
846 myTelNum mt = new myTelNum();
847 sCallerNum =mt.GetTelPass(sCalleeNum);
848 sST = "电话呼出";
849 break;
850 }
851 case (int)RelayStates.ISUP_CALLER_WAIT_ANM:
852 {
853 sCalleeNum =Encoding.UTF8.GetString(SysFunction.GetCallNum(iTrunkID / 30, iTrunkID % 30).bCallNum);
854 sCallerNum = Encoding.UTF8.GetString(SysFunction.GetCallNum(iTrunkID / 30, iTrunkID % 30).bCalleeNum);
855 TrunkState = "Calling";
856 VoiceST = "Callout";
857 sST = "呼出等待";
858 break;
859 }
860 case (int)RelayStates.ISUP_CH_LOCAL_BLOCK:
861 {
862 sST = "本地闭塞";
863 break;
864 }
865 case (int)RelayStates.ISUP_CH_LOCAL_SUSPEND:
866 {
867 sST = "本地暂停";
868 break;
869 }
870 case (int)RelayStates.ISUP_CH_REMOTE_BLOCK:
871 {
872 sST = "远端闭塞";
873 break;
874 }
875 case (int)RelayStates.ISUP_CH_REMOTE_SUSPEND:
876 {
877 sST = "远端暂停";
878 break;
879 }
880 default:
881 {
882 sST = "中间状态";
883 break;
884
885 }
886 }
887 lvChn.Items[iTrunkID].SubItems[3].Text = sST;
888 lvChn.Items[iTrunkID].SubItems[4].Text = sCallerNum;
889 lvChn.Items[iTrunkID].SubItems[5].Text = sCalleeNum;
890 }
891 #endregion
892
893 声音文件转换#region 声音文件转换
894 /**//// <summary>
895 /// 文件名转换成byte[]
896 /// </summary>
897 /// <param name="FileName"></param>
898 /// <returns></returns>
899 public byte[] GetFilePath(string FileName)
900 {
901 string appFile = SysFunction.appDIRStr().ToString();
902 //MessageBox.Show(appFile);
903 char[] charTemp = new char[256];
904 byte[] byteTemp = new byte[256];
905 long Pos = 0;
906 long tmp = 0;
907
908
909 appFile.ToCharArray().CopyTo(charTemp, Pos);
910 for (short x = 0; x < charTemp.Length; x++)
911 {
912 if (charTemp[x] != 0)
913 {
914 tmp++;
915 }
916 }
917 Pos = tmp;
918 @"voc\".ToCharArray().CopyTo(charTemp, Pos);
919 FileName.ToCharArray().CopyTo(charTemp, Pos + 4);
920 Encoding.Unicode.GetBytes(FileName.ToCharArray()).CopyTo(byteTemp, 0);
921 for (int i =0; i < charTemp.Length; i++)
922 {
923 byteTemp[i] = (byte)charTemp[i];
924 }
925 return byteTemp;
926 }
927 #endregion
928
929 电话号码转换#region 电话号码转换
930 /**//// <summary>
931 /// 电话号码转换
932 /// </summary>
933 /// <param name="Str"></param>
934 /// <param name="PCMno"></param>
935 /// <param name="RelayNo"></param>
936 /// <returns></returns>
937 public byte[] CalleestringTobyte(string Str,int PCMno,int RelayNo)
938 {
939 TC_INI_TYPE TC = new TC_INI_TYPE();
940 char[] charTemp = new char[256];
941 byte[] byteTemp = new byte[256];
942 long Pos = 0;
943 long tmp = 0;
944
945
946 TC=SysFunction.GetCallNum(PCMno,RelayNo);
947 TC.bCalleeNum.CopyTo(byteTemp, Pos);
948 for (short x = 0; x < Pos;x++ )
949 {
950 if(TC.bCalleeNum[x]!=0)
951 {
952 tmp++;
953 }
954 }
955 Pos = tmp;
956 Encoding.Unicode.GetBytes(Str.ToCharArray()).CopyTo(byteTemp, 0);
957 return byteTemp;
958 }
959 #endregion
960
961 被叫电话号码#region 被叫电话号码
962 public string CalleeNum(int PCMno, int RelayNo)
963 {
964 TC_INI_TYPE TC = new TC_INI_TYPE();
965 char[] charTemp = new char[256];
966 byte[] byteTemp = new byte[256];
967 long Pos = 0;
968 long tmp = 0;
969
970
971 TC = SysFunction.GetCallNum(PCMno, RelayNo);
972 TC.bCalleeNum.CopyTo(byteTemp, Pos);
973 for (short x = 0; x < Pos; x++)
974 {
975 if (TC.bCalleeNum[x] != 0)
976 {
977 tmp++;
978 }
979 }
980 Pos = tmp;
981 // Encoding.Unicode.GetBytes(Str.ToCharArray()).CopyTo(byteTemp, 0);
982 return Encoding.UTF8.GetString(byteTemp);
983 }
984 #endregion
985
986 拨号#region 拨号
987 /**//// <summary>
988 /// 手动拨号
989 /// </summary>
990 ///
991
992 public void CallOut(string iTelNum)
993 {
994
995 unsafe
996 {
997 nOutCall = Convert.ToUInt64(iTelNum);
998 nMyCallNo = Convert.ToUInt64(MyCallNO);
999 TelNum telNO = new TelNum();
1000 byte[] iTelNO = new byte[256];
1001 char[] tempTel = new char[256];
1002 tempTel = iTelNum.ToCharArray();
1003 telNO.arrTelNum = Encoding.ASCII.GetBytes(tempTel);
1004 char[] tempCall = new char[256];
1005 byte[] iCallNO = new byte[256];
1006 tempCall = MyCallNO.ToCharArray();
1007 telNO.arrCallNum = Encoding.ASCII.GetBytes(tempCall);
1008 int iFreeTrunkID = SysFunction.iFreePCM();
1009 string sErr = string.Empty;
1010 if (iFreeTrunkID == -1)
1011 {
1012 return;
1013 }
1014 else
1015 {
1016 StringBuilder sbCallee = new StringBuilder(iTelNum);
1017 StringBuilder sbCaller = new StringBuilder(MyCallNO);
1018 try
1019 {
1020 bool charISCallout = SysFunction.bCallOut(iFreeTrunkID, sbCallee, sbCaller);
1021 }
1022 catch (Exception ex)
1023 {
1024 lblTrunk.Text = ex.Message;
1025 }
1026
1027 try
1028 {
1029 bool bCallout = SysFunction.bCallOut(iFreeTrunkID, iTelNum, MyCallNO, ref sErr);
1030 }
1031 catch (Exception ex)
1032 {
1033 lblTrunk.Text = ex.Message + sErr;
1034 }
1035 try
1036 {
1037 bool bISout = SysFunction.bCallOut(iFreeTrunkID, iTelNum, MyCallNO, false, false);
1038 }
1039 catch (Exception ex)
1040 {
1041 lblTrunk.Text = ex.Message;
1042 }
1043 try
1044 {
1045 bool bIsCallOut = SysFunction.bCallOut(iFreeTrunkID, CalleestringTobyte(iTelNum, iFreeTrunkID / 30, iFreeTrunkID % 30), iCallNO);
1046 }
1047 catch (Exception ex)
1048 {
1049 lblTrunk.Text = ex.Message;
1050 }
1051 try
1052 {
1053 bool bSisCallOut = SysFunction.bCallOut(iFreeTrunkID, nOutCall, nMyCallNo);
1054 }
1055 catch (Exception ex)
1056 {
1057 lblTrunk.Text = ex.Message;
1058 }
1059 lvChn.BeginUpdate();
1060 lvChn.Items[iFreeTrunkID].SubItems[5].Text = iTelNum;
1061 lvChn.EndUpdate();
1062 VoiceST = "Callout";
1063 TrunkState = "Calling";
1064 }
1065 }
1066
1067 }
1068
1069
1070 /**//// <summary>
1071 /// 自动拨号
1072 /// </summary>
1073 ///
1074
1075
1076 public void TheadCallOut()
1077 {
1078
1079 DBMod.myTelNum tn = new DJVoiceCard.DBMod.myTelNum();
1080 string iTelNum = tn.theTelNum;
1081 CallOutNum = tn.theTelNum;
1082
1083 unsafe
1084 {
1085 TrunkState = "Calling";
1086 ulong nOutCall = Convert.ToUInt64(iTelNum);
1087 ulong nMyCallNo = Convert.ToUInt64(MyCallNO);
1088 TelNum telNO = new TelNum();
1089 byte[] iTelNO = new byte[256];
1090 char[] tempTel = new char[256];
1091 tempTel = iTelNum.ToCharArray();
1092 telNO.arrTelNum = Encoding.ASCII.GetBytes(tempTel);
1093 char[] tempCall = new char[256];
1094 byte[] iCallNO = new byte[256];
1095 tempCall = MyCallNO.ToCharArray();
1096 telNO.arrCallNum = Encoding.ASCII.GetBytes(tempCall);
1097 int iFreeTrunkID = SysFunction.iFreePCM();
1098 string sErr = string.Empty;
1099 if (iFreeTrunkID == -1)
1100 {
1101
1102 }
1103 else
1104 {
1105
1106 StringBuilder sbCallee = new StringBuilder(iTelNum);
1107 StringBuilder sbCaller = new StringBuilder(MyCallNO);
1108 try
1109 {
1110 bool charISCallout = SysFunction.bCallOut(iFreeTrunkID, sbCallee, sbCaller);
1111 }
1112 catch(Exception ex)
1113 {
1114 lblTrunk.Text = ex.Message;
1115 }
1116
1117 try
1118 {
1119 bool bCallout = SysFunction.bCallOut(iFreeTrunkID, iTelNum, MyCallNO, ref sErr);
1120 }
1121 catch (Exception ex)
1122 {
1123 lblTrunk.Text = ex.Message + sErr;
1124 }
1125 try
1126 {
1127 bool bISout = SysFunction.bCallOut(iFreeTrunkID, iTelNum, MyCallNO, false, false);
1128 }
1129 catch (Exception ex)
1130 {
1131 lblTrunk.Text = ex.Message;
1132 }
1133 try
1134 {
1135 bool bIsCallOut = SysFunction.bCallOut(iFreeTrunkID, CalleestringTobyte(iTelNum, iFreeTrunkID / 30, iFreeTrunkID % 30), iCallNO);
1136 }
1137 catch (Exception ex)
1138 {
1139 lblTrunk.Text = ex.Message;
1140 }
1141 try
1142 {
1143 bool bSisCallOut = SysFunction.bCallOut(iFreeTrunkID, nOutCall, nMyCallNo);
1144 }
1145 catch (Exception ex)
1146 {
1147 lblTrunk.Text = ex.Message;
1148 }
1149 lvChn.BeginUpdate();
1150 lvChn.Items[iFreeTrunkID].SubItems[5].Text = iTelNum;
1151 lvChn.EndUpdate();
1152 TrunkState = "Calling";
1153 VoiceST = "Callout";
1154 }
1155 }
1156
1157 }
1158
1159 #endregion
1160
1161 释放资源#region 释放资源
1162 /**//// <summary>
1163 /// 释放用户通道
1164 /// </summary>
1165 /// <param name="iUserCHNID"></param>
1166 public void ReaseceUserCHN(int iUserCHNID)
1167 {
1168 if(iUserCHNID!=-1)
1169 {
1170 if(SysFunction.bIsRingDerctor(iUserCHNID))
1171 {
1172 if (SysFunction.bIsStopRing(iUserCHNID))
1173 {
1174 }
1175
1176 }
1177 if(SysFunction.bClearVoiceFromUser(iUserCHNID))
1178 {}
1179 if(SysFunction.bIsInitDailBuf(iUserCHNID))
1180 {}
1181 URS[iUserCHNID].ConnTrID = -1;
1182 URS[iUserCHNID].ConnUrID = -1;
1183 URS[iUserCHNID].ST = USER_STATE.USR_ONHOOK;
1184
1185 }
1186 }
1187
1188 /**//// <summary>
1189 /// 释放中继信道资源
1190 /// </summary>
1191 /// <param name="iTrunkCHNID"></param>
1192 public void ReaseceTrunckCHN(int iTrunkCHNID)
1193 {
1194 bool bISCHK = (iTrunkCHNID == -1 && (SysFunction.iRaleyStetes(((byte)(iTrunkCHNID / 30)), ((byte)(iTrunkCHNID % 30))) == (int)RelayStates.ISUP_CH_FREE));
1195 if(!bISCHK)
1196 {
1197 int iUserCHNID = SysFunction.iLinkUserCHNID(iTrunkCHNID);
1198 if(iUserCHNID>-1)
1199 {
1200 if (SysFunction.ClearCHN(iTrunkCHNID))
1201 { }
1202 }
1203
1204 int iVoiceID = SysFunction.iVoicePlayForTrunk(iTrunkCHNID);
1205 if (iVoiceID > -1)
1206 {
1207 SysFunction.bIsClearTrunkVoiceLink(iTrunkCHNID);
1208 }
1209
1210 SysFunction.bIsInitDtmfByTrunkID(iTrunkCHNID);
1211
1212 TST[iTrunkCHNID].ST = TRUNK_ST.TRK_FREE;
1213 TST[iTrunkCHNID].DialNum = string.Empty;
1214 TST[iTrunkCHNID].ConnTrID = -1;
1215 TST[iTrunkCHNID].ConnUrID = -1;
1216
1217 SysFunction.SetRelayStates(iTrunkCHNID, (int)RelayStates.ISUP_CH_FREE);
1218 }
1219 }
1220 /**//// <summary>
1221 /// 释放资源
1222 /// </summary>
1223 public void ReacurseTrunk()
1224 {
1225 iTunkTotal = SysFunction.iTrkTotal();
1226 for (int i = 0; i < iTunkTotal; i++)
1227 {
1228 ReaseceTrunckCHN(i);
1229 }
1230 iUserTotal = SysFunction.iUserTotal();
1231 for (int i = 0; i < iUserTotal; i++)
1232 {
1233 ReaseceUserCHN(i);
1234 }
1235
1236 }
1237
1238 #endregion
1239
1240 private void button1_Click(object sender, EventArgs e)
1241 {
1242 ReacurseTrunk();
1243 }
1244 }
1245}
1using System;
2using System.Collections.Generic;
3using System.Configuration;
4using System.ComponentModel;
5using System.Data;
6using System.Drawing;
7using System.Text;
8using System.Windows.Forms;
9using DJVoiceCard.DL;
10using System.Runtime.InteropServices;
11using DJVoiceCard.Lib;
12using System.Data.OleDb;
13using System.IO;
14using System.Threading;
15using DJVoiceCard.DBMod;
16
17namespace DJVoiceCard.App
18{
19 public partial class DailMain : Form
20 {
21
22 //private static string[] _FileArr;
23
24 /**////// <summary>
25 ///// 语音文件路径
26 ///// </summary>
27 //public string[] FileArr { get { return _FileArr; } set { _FileArr = value; } }
28 //private static string _CalloutST=string.Empty;
29
30 /**////// <summary>
31 ///// 调用状态
32 ///// </summary>
33 //public static string CalloutST
34 //{
35 // get { return _CalloutST; }
36 // set { _CalloutST = value; }
37 //}
38 /**//// <summary>
39 /// 中继通道总数;
40 /// </summary>
41 private int iTunkTotal;
42 /**//// <summary>
43 /// 用户通道数
44 /// </summary>
45 private int iUserTotal;
46
47 /**//// <summary>
48 /// 主叫电话号码
49 /// </summary>
50 public string MyCallNO =ConfigurationSettings.AppSettings["calleeNum"];
51 public string WelcomeTo=ConfigurationSettings.AppSettings["Welcome"];
52 public string PassReadBegin = ConfigurationSettings.AppSettings["PassReadBegin"];
53 public string PassRead = ConfigurationSettings.AppSettings["PassRead"];
54 public string EndSystem = ConfigurationSettings.AppSettings["EndSystem"];
55 private string DbPath = ConfigurationSettings.AppSettings["LinkStr"];
56 private string CallOutNum = string.Empty;
57
58 public string VoiceST = string.Empty;
59 ulong nOutCall ;
60 ulong nMyCallNo ;
61
62 /**//// <summary>
63 /// 公共线程,主要用来拨号
64 /// </summary>
65 //public Thread TheadCall;
66
67 /**//// <summary>
68 /// 信道使用状态
69 /// </summary>
70 public string TrunkState=string.Empty;
71 /**//// <summary>
72 /// 用户状态
73 /// </summary>
74 public UR_ST[] URS = new UR_ST[120];
75
76 /**//// <summary>
77 /// 信道状态
78 /// </summary>
79 public TRK_ST[] TST = new TRK_ST[120];
80 string[] CallST=new string[120];
81 int[] arrVoiceChn=new int[10];
82 public DailMain()
83 {
84 InitializeComponent();
85 }
86
87 private void Dail_Load(object sender, EventArgs e)
88 {
89 SysInit();
90 }
91
92 private void DailMain_FormClosing(object sender, FormClosingEventArgs e)
93 {
94 ReacurseTrunk();
95 SysFunction.SysExit();
96 this.Dispose();
97 base.Dispose();
98 }
99
100 private void btnExit_Click(object sender, EventArgs e)
101 {
102 ExitSys();
103 }
104
105 private void TimeChk_Tick(object sender, EventArgs e)
106 {
107 SysFunction.Push_GerEvent();
108 TrunkTimerWork();
109 StateView();
110 dbCall();
111 }
112
113 private void btnCall_Click(object sender, EventArgs e)
114 {
115 string telNum=txtTelNO.Text.Trim();
116 if (telNum.Length < 6)
117 {
118
119 MessageBox.Show("请输入正确的号码");
120 txtTelNO.Text = "";
121 }
122 else
123 {
124 CallOut(telNum);
125 }
126
127 }
128
129 初始化系统#region 初始化系统
130 /**//// <summary>
131 /// 初始化系统
132 /// </summary>
133 private void SysInit()
134 {
135 string sErr = string.Empty;
136 bool isSysLoad = SysFunction.SysInit(ref sErr);
137 if (isSysLoad)
138 {
139 iTunkTotal = SysFunction.iTrkTotal();
140 for (int i = 0; i < iTunkTotal; i++)
141 {
142 TST[i].ConnTrID = -1;
143 TST[i].ConnUrID = -1;
144 TST[i].ST = TRUNK_ST.TRK_FREE;
145 TST[i].DialNum = string.Empty;
146 }
147
148 iUserTotal = SysFunction.iUserTotal();
149 for (int i = 0; i < iUserTotal; i++)
150 {
151 SysFunction.UserPowerOn(i);
152 if (SysFunction.UserEnableDailSound(i))
153 {
154 URS[i].ConnTrID = -1;
155 URS[i].ConnTrID = -1;
156 URS[i].ST = USER_STATE.USR_ONHOOK;
157 }
158 else
159 {
160 MessageBox.Show("初始化用户模块失败");
161 ExitSys();
162 break;
163 }
164 }
165
166 arrVoiceChn[1] = SysFunction.iFreeVoiceCHNID();
167 StringBuilder busy = new StringBuilder("BUSY");
168 if (SysFunction.LoopVoiceM(arrVoiceChn[1], busy))
169 {
170
171 }
172 arrVoiceChn[2] = SysFunction.iFreeVoiceCHNID();
173 StringBuilder ring = new StringBuilder("RING");
174 if (SysFunction.LoopVoiceM(arrVoiceChn[2], ring))
175 {
176
177 }
178 arrVoiceChn[3] = SysFunction.iFreeVoiceCHNID();
179 StringBuilder tone = new StringBuilder("TONE");
180 if (SysFunction.LoopVoiceM(arrVoiceChn[2], tone))
181 {
182
183 }
184
185 lvChn.BeginUpdate();
186 for (int i = 0; i < iTunkTotal; i++)
187 {
188 ListViewItem lvi = new ListViewItem();
189 lvi.Text = i.ToString();
190 lvi.SubItems.Add("");
191 lvi.SubItems.Add("");
192 lvi.SubItems.Add("");
193 lvi.SubItems.Add("");
194 lvi.SubItems.Add("");
195 lvi.SubItems.Add("");
196 lvChn.Items.Add(lvi);
197 }
198 lvChn.EndUpdate();
199 StateView();
200 }
201 else
202 {
203 //MessageBox.Show(sErr);
204 // ExitSys();
205 }
206 }
207 #endregion
208
209 Exit System#region Exit System
210 /**//// <summary>
211 /// 退出系统
212 /// </summary>
213 public void ExitSys()
214 {
215 ReacurseTrunk();
216 SysFunction.SysExit();
217 this.Dispose();
218 base.Dispose();
219 }
220
221
222 #endregion
223
224 数据处理#region 数据处理
225 /**//// <summary>
226 /// 读取数据 拨号
227 /// </summary>
228 public void dbCall()
229 {
230 if (TrunkState != "Calling")
231 {
232 myTelNum mytel = new myTelNum();
233 if (mytel.theTelNum != string.Empty)
234 {
235 lblMsg.Text = DateTime.Now.ToString()+"自动发送";
236 TheadCallOut();
237 }
238 else
239 {
240 lblMsg.Text = DateTime.Now + "无可用号码";
241 }
242
243 }
244 else
245 {
246 lblMsg.Text = DateTime.Now+"自动发送信道使用中";
247 }
248 }
249 #endregion
250
251 更新控件数据显示#region 更新控件数据显示
252
253 /**//// <summary>
254 /// 向控件更新数据
255 /// </summary>
256 public void StateView()
257 {
258 SysFunction.Push_GerEvent();
259 iTunkTotal = SysFunction.iTrkTotal();
260 for (int i = 0; i < iTunkTotal; i++)
261 {
262 DrawTrunkState(i);
263 }
264 }
265 #endregion
266
267 信道状态轮询#region 信道状态轮询
268 /**//// <summary>
269 /// 轮询
270 /// </summary>
271 public void TrunkTimerWork()
272 {
273 //int iVoiceID;
274 int iResult;
275 iTunkTotal = SysFunction.iTrkTotal();
276
277 for (int i = 0; i < iTunkTotal; i++)
278 {
279
280 iResult = SysFunction.iRaleyStetes((byte)(i / 30), (byte)(i % 30));
281 if (iResult == (int)RelayStates.ISUP_CH_WAIT_RELEASE)
282 {
283 VoiceST =string.Empty;
284 TrunkState = string.Empty;
285 ReaseceTrunckCHN(i);
286 SysFunction.SetRelayStates(i, (int)RelayStates.ISUP_CH_FREE);
287 lvChn.BeginUpdate();
288 lvChn.Items[i].SubItems[5].Text = "";
289 lvChn.EndUpdate();
290 }
291
292 if (SysFunction.iRaleyStetes(((byte)(i / 30)), ((byte)(i % 30))) == (int)RelayStates.ISUP_CALLER_CONNECT)
293 {
294 //lblMsg.Text = "去话连通.";
295 TrunkState = "Calling";
296 bool beFinish = false;
297 int iST = SysFunction.iCallOutStates(i / 30, i % 30);
298 string calleeNum = CalleeNum(i / 30, i % 30);
299 处理声音播放#region 处理声音播放
300 unsafe
301 {
302 byte[] filePath = GetFilePath(WelcomeTo);
303
304 try
305 {
306 TrunkState = "Calling";
307 lblTrunk.Text = "信道状态是:" + VoiceST;
308 注释掉的东西,以后备用#region 注释掉的东西,以后备用
309 /**//*if (Convert.ToBoolean(iST & 0x10))
310 {
311 int iCPGval = SysFunction.iCPGReval(i);
312 int iISUPval = SysFunction.ISUPReVal(i);
313 }*/
314
315 //if (SysFunction.iRaleyStetes(((byte)(i / 30)), ((byte)(i % 30))) == (int)RelayStates.ISUP_CALLER_CONNECT)
316 //{
317 out#region out
318 //PlayFiles(i);
319 //PlayVoiceBegin(i, MusicFile);
320 //PlayVoice(i, "call.005");
321 //PlayVoiceEnd(i, "call.006");
322
323 /**//*if (SysFunction.bISplayVoice(i, filePath))
324 {
325 beFinish = true;
326 lblMsg.Text += Encoding.UTF8.GetString(filePath);
327 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
328 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
329 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
330 {
331 SysFunction.StopPlayVocInTrunk(i);
332 ReaseceTrunckCHN(i);
333 beFinish = true;
334 }
335 }
336 else
337 {
338 TST[i].ST = TRUNK_ST.TRK_PLAY;
339 }*/
340 /**//*
341 bool PlayNext = false;
342
343 if(SysFunction.bISplayVoice(i,filePath))
344 {
345 if (PlayNext)
346 {
347 SysFunction.StopPlayVocInTrunk(i);
348 ReaseceTrunckCHN(i);
349 }
350 if (!PlayNext)
351 {
352 SysFunction.StopPlayVocInTrunk(i);
353 ReaseceTrunckCHN(i);
354 }
355 }
356 beFinish = true;
357 * */
358
359 /**//*if (SysFunction.bISplayVoice(i, filePath))
360 {
361 lblMsg.Text += Encoding.UTF8.GetString(filePath);
362 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
363 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
364 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
365 {
366 SysFunction.StopPlayVocInTrunk(i);
367 ReaseceTrunckCHN(i);
368 beFinish = true;
369 }
370 }*/
371 #endregion
372 //MessageBox.Show(VoiceST);
373 声音播放状态判断#region 声音播放状态判断
374 //声音播放状态
375 /**//*
376 switch (VoiceST)
377 {
378 case "Callout":
379 {
380 lblTrunk.Text = "信道状态是:" + VoiceST;
381 SysFunction.bISplayVoice(i, filePath);
382 VoiceST = "Welcome";
383 //if (SysFunction.bISplayVoice(i, filePath))
384 //{
385 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
386 //int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
387 //if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
388 //{
389 // lblTrunk.Text = "信道状态是:" + VoiceST;
390 // //SysFunction.StopPlayVocInTrunk(i);
391 // //ReaseceTrunckCHN(i);
392 // //beFinish = true;
393 // VoiceST = "Welcome";
394 //}
395 //}
396 break;
397 }
398 case "Welcome":
399 {
400 lblTrunk.Text = "信道状态是:" + VoiceST;
401 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
402 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
403 {
404 SysFunction.bISplayVoice(i, GetFilePath("bank.005"));
405 VoiceST = "ReadUser";
406 //if (SysFunction.bISplayVoice(i, GetFilePath("bank.005")))
407 //{
408 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
409 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
410 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
411 // {
412 // lblTrunk.Text = "信道状态是:" + VoiceST;
413 // //SysFunction.StopPlayVocInTrunk(i);
414 // //ReaseceTrunckCHN(i);
415 // //beFinish = true;
416 // VoiceST = "ReadUser";
417 // }
418 //}
419 }
420 break;
421 }
422 case "ReadUser":
423 {
424 lblTrunk.Text = "信道状态是:" + VoiceST;
425 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
426 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
427 {
428 SysFunction.bISplayVoice(i, GetFilePath("bank.006"));
429 VoiceST = "SendUser";
430 //if (SysFunction.bISplayVoice(i, GetFilePath("bank.006")))
431 //{
432 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
433 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
434 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
435 // {
436 // lblTrunk.Text = "信道状态是:" + VoiceST;
437 // //SysFunction.StopPlayVocInTrunk(i);
438 // //ReaseceTrunckCHN(i);
439 // //beFinish = true;
440 // VoiceST = "SendUser";
441 // }
442 //}
443 }
444 break;
445 }
446 case "SendUser":
447 {
448 lblTrunk.Text = "信道状态是:" + VoiceST;
449 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
450 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
451 {
452 SysFunction.bISplayVoice(i, GetFilePath("bank.007"));
453 VoiceST = "ReadPass";
454 //if (SysFunction.bISplayVoice(i, GetFilePath("bank.007")))
455 //{
456 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
457 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
458 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
459 // {
460 // lblTrunk.Text = "信道状态是:" + VoiceST;
461 // //SysFunction.StopPlayVocInTrunk(i);
462 // //ReaseceTrunckCHN(i);
463 // //beFinish = true;
464 // VoiceST = "ReadPass";
465 // }
466 //}
467 }
468 break;
469 }
470 case "ReadPass":
471 {
472 lblTrunk.Text = "信道状态是:" + VoiceST;
473 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
474 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
475 {
476 SysFunction.bISplayVoice(i, GetFilePath("bank.001"));
477 VoiceST = "SendPass";
478 //if (SysFunction.bISplayVoice(i, GetFilePath("bank.001")))
479 //{
480 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
481 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
482 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
483 // {
484 // lblTrunk.Text = "信道状态是:" + VoiceST;
485 // //SysFunction.StopPlayVocInTrunk(i);
486 // //ReaseceTrunckCHN(i);
487 // //beFinish = true;
488 // VoiceST = "SendPass";
489 // }
490 //}
491 }
492 break;
493 }
494 case "SendPass":
495 {
496 lblTrunk.Text = "信道状态是:" + VoiceST;
497 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
498 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
499 {
500 SysFunction.bISplayVoice(i, GetFilePath("D1"));
501 VoiceST = "ReSendPass";
502 //if (SysFunction.bISplayVoice(i, GetFilePath("D1")))
503 //{
504 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
505 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
506 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
507 // {
508 // lblTrunk.Text = "信道状态是:" + VoiceST;
509 // //SysFunction.StopPlayVocInTrunk(i);
510 // //ReaseceTrunckCHN(i);
511 // //beFinish = true;
512 // VoiceST = "ReSendPass";
513 // }
514 //}
515 }
516 break;
517 }
518 case "ReSendPass":
519 {
520 lblTrunk.Text = "信道状态是:" + VoiceST;
521 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
522 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
523 {
524 SysFunction.bISplayVoice(i, GetFilePath("D1"));
525 VoiceST = "EndSystem";
526 //if (SysFunction.bISplayVoice(i, GetFilePath("D1")))
527 //{
528 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
529 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
530 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
531 // {
532 // lblTrunk.Text = "信道状态是:" + VoiceST;
533 // //SysFunction.StopPlayVocInTrunk(i);
534 // //ReaseceTrunckCHN(i);
535 // //beFinish = true;
536 // VoiceST = "EndSystem";
537 // }
538 //}
539 }
540 break;
541 }
542 case "EndSystem":
543 {
544 lblTrunk.Text = "信道状态是:" + VoiceST;
545 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
546 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
547 {
548 SysFunction.bISplayVoice(i, GetFilePath("bank.002"));
549 VoiceST = "ExitSystem";
550 //if (SysFunction.bISplayVoice(i, GetFilePath("bank.002")))
551 //{
552 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
553 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
554 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
555 // {
556 // lblTrunk.Text = "信道状态是:" + VoiceST;
557 // SysFunction.StopPlayVocInTrunk(i);
558 // ReaseceTrunckCHN(i);
559 // beFinish = true;
560 // VoiceST = "";
561 // }
562 //}
563 }
564 break;
565 }
566 case "ExitSystem":
567 {
568 lblTrunk.Text = "信道状态是:" + VoiceST;
569 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
570 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
571 {
572 SysFunction.StopPlayVocInTrunk(i);
573 ReaseceTrunckCHN(i);
574 beFinish = true;
575 }
576 //if (SysFunction.bISplayVoice(i, filePath))
577 //{
578 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
579 // int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
580 // if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
581 // {
582 // lblTrunk.Text = "信道状态是:" + VoiceST;
583 // //SysFunction.StopPlayVocInTrunk(i);
584 // //ReaseceTrunckCHN(i);
585 // //beFinish = true;
586 // VoiceST = "Welcome";
587 // }
588 //}
589 break;
590 }
591 default:
592 {
593 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(i);
594 if (SysFunction.bIsVocPlayEnd(iVoiceLinkTunk))
595 {
596 SysFunction.StopPlayVocInTrunk(i);
597 ReaseceTrunckCHN(i);
598 beFinish = false;
599 }
600 break;
601 }
602
603
604 }
605 */
606 #endregion
607 //}
608
609 #endregion
610
611 if (VoiceST == "Callout")
612 {
613 myTelNum tn = new myTelNum();
614 string TelNum = calleeNum;
615 SysFunction.PlayFileInit(i);
616 AddIndexFiles(i, WelcomeTo);
617 string SysCalleeNum = Encoding.UTF8.GetString(SysFunction.GetCallNum(i / 30, i % 30).bCallNum);
618 string TelPass = tn.GetTelPass(SysCalleeNum);
619 for (int t = 0; t < SysCalleeNum.Length; t++)
620 {
621 string tmp = "d" + SysCalleeNum[t].ToString();
622 AddIndexFiles(i, tmp.Trim());
623 }
624 if (TelPass != string.Empty || TelPass != null)
625 {
626 AddIndexFiles(i, PassReadBegin);
627 AddIndexFiles(i, PassRead);
628 for (int p = 0; p < TelPass.Length; p++)
629 {
630 string ptmp = "d" + TelPass[p].ToString();
631 AddIndexFiles(i, ptmp.Trim());
632 }
633 AddIndexFiles(i, PassRead);
634 for (int p = 0; p < TelPass.Length; p++)
635 {
636 string ptmp = "d" + TelPass[p].ToString();
637 AddIndexFiles(i, ptmp.Trim());
638 }
639 }
640 AddIndexFiles(i, EndSystem);
641 SysFunction.PlayFileStart(i);
642 VoiceST="FilePlay";
643 }
644
645 if (VoiceST == "FilePlay")
646 {
647 if (SysFunction.PlayFileEndCHK(i))
648 {
649 VoiceST = "PlayEnd";
650 }
651 //if()
652 }
653 if (VoiceST == "PlayEnd")
654 {
655 SysFunction.PlayFileEnd(i);
656 beFinish = true;
657 }
658
659 }
660 catch (Exception ex)
661 {
662 lblTrunk.Text =ex.Message.ToString();
663
664 myTelNum tn = new myTelNum();
665 tn.LogModify(Encoding.UTF8.GetString(SysFunction.GetCallNum(i / 30, i % 30).bCallNum), ex.Message);
666 beFinish = false;
667 ReaseceTrunckCHN(i);
668 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_FREE);
669 TrunkState = string.Empty;
670
671 }
672 }
673
674 //数据插入
675 if (beFinish)
676 {
677 lblTrunk.Text = "播放结束";
678 myTelNum mt = new myTelNum();
679 mt.ISCompelet(Encoding.UTF8.GetString(SysFunction.GetCallNum(i / 30, i % 30).bCallNum));
680 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
681 ReaseceTrunckCHN(i);
682 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_FREE);
683 TrunkState = string.Empty;
684 VoiceST = string.Empty;
685 }
686 else
687 {
688 //MessageBox.Show("beFinish:" + beFinish.ToString());
689 /**//*ReaseceTrunckCHN(i);
690 myTelNum tn = new myTelNum();
691 tn.LogModify(calleeNum,"密码发送失败");
692 beFinish = false;
693 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_FREE);
694 TrunkState = string.Empty;*/
695
696 }
697 #endregion
698 }
699
700 //if (SysFunction.iRaleyStetes(((byte)(i / 30)), ((byte)(i % 30))) == (int)RelaySet.ISUP_CH_SET_REL)
701 //{
702 // lblTrunk.Text = "播放完毕,准备挂机";
703 // ReaseceTrunckCHN(i);
704 // SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_FREE);
705 // TrunkState = string.Empty;
706 // VoiceST = string.Empty;
707 //}
708
709 if (SysFunction.iRaleyStetes(((byte)(i / 30)), ((byte)(i % 30))) == (int)RelayStates.ISUP_CALLER_WAIT_ANM)
710 {
711 TrunkState = "Calling";
712 lblMsg.Text = "等待被叫响应";
713 }
714 if (SysFunction.iRaleyStetes(((byte)(i / 30)), ((byte)(i % 30))) == (int)RelayStates.ISUP_CALLEE_RECV_IAM)
715 {
716 TrunkState = "Calling";
717 lblMsg.Text = "呼叫到达";
718 }
719 注释掉的东西不知道以后有没有用哈#region 注释掉的东西不知道以后有没有用哈
720 /**//*if (TST[i].ST == TRUNK_ST.TRK_PLAY)
721 {
722 iVoiceID = SysFunction.iVoicePlayForTrunk(i);
723 if (iVoiceID == -1)
724 {
725 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
726 return;
727 }
728 else
729 {
730 if (SysFunction.bIsVocPlayEnd(iResult))
731 {
732 SysFunction.StopPlayVocInTrunk(i);
733 SysFunction.SetRelayStates(i, (int)RelaySet.ISUP_CH_SET_REL);
734 TST[i].ST = TRUNK_ST.TRK_HANGUP;
735 }
736 }
737 }*/
738 #endregion
739 }
740 }
741 #endregion
742
743 播放声音#region 播放声音
744
745 /**//// <summary>
746 /// 开始播放声音
747 /// </summary>
748 /// <param name="TrunkID"></param>
749 /// <param name="FileNames"></param>
750 public void PlayVoiceBegin(int TrunkID, string FileNames)
751 {
752 byte[] filePath = GetFilePath(FileNames);
753 //int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(TrunkID);
754 if (SysFunction.iRaleyStetes(((byte)(TrunkID / 30)), ((byte)(TrunkID % 30))) == (int)RelayStates.ISUP_CALLEE_CONNECT)
755 {
756 bool IsPlay = SysFunction.bISplayVoice(TrunkID, filePath);
757 }
758 }
759
760 /**//// <summary>
761 /// 连续播放声音
762 /// </summary>
763 /// <param name="TrunkID"></param>
764 /// <param name="FileNames"></param>
765 public void PlayVoice(int TrunkID, string FileNames)
766 {
767 byte[] filePath = GetFilePath(FileNames);
768 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(TrunkID);
769 if (SysFunction.bIsVocPlayEnd(TrunkID))
770 {
771 bool IsPlay = SysFunction.bISplayVoice(TrunkID, filePath);
772 if(IsPlay)
773 {
774 SysFunction.StopPlayVocInTrunk(TrunkID);
775 ReaseceTrunckCHN(TrunkID);
776 //beFinish = true;
777 //此处处理程序;
778 }
779 }
780 }
781
782 public void PlayVoiceEnd(int TrunkID, string FileNames)
783 {
784 byte[] filePath = GetFilePath(FileNames);
785 int iVoiceLinkTunk = SysFunction.iVoicePlayForTrunk(TrunkID);
786 if (SysFunction.bIsVocPlayEnd(TrunkID))
787 {
788 bool IsPlay = SysFunction.bISplayVoice(TrunkID, filePath);
789 if (IsPlay)
790 {
791 //此处处理程序;
792 }
793 }
794 }
795 #endregion
796
797 索引播音(多文件播音)#region 索引播音(多文件播音)
798
799 /**//// <summary>
800 /// 添加索引音乐文件
801 /// </summary>
802 /// <param name="TrunkID"></param>
803 /// <param name="FileNames"></param>
804 public void AddIndexFiles(int TrunkID,string FileNames)
805 {
806 byte[] FileArr = GetFilePath(FileNames);
807 SysFunction.AddIndexFile(TrunkID, FileArr);
808 }
809
810 #endregion
811
812 中继通道状态遍历#region 中继通道状态遍历
813 /**//// <summary>
814 /// 信道状态
815 /// </summary>
816 /// <param name="iTrunkID"></param>
817 /// <returns></returns>
818
819 public void DrawTrunkState(int iTrunkID)
820 {
821 string sST = string.Empty;
822 string sCalleeNum = string.Empty;
823 string sCallerNum = string.Empty;
824 int iTrunkST = SysFunction.iRaleyStetes((byte)(iTrunkID / 30), (byte)(iTrunkID % 30));
825 switch (iTrunkST)
826 {
827 case (int)RelayStates.ISUP_CH_WAIT_RELEASE:
828 {
829 sST = ("不可用");
830 break;
831 }
832 case (int)RelayStates.ISUP_CH_FREE:
833 {
834 sST = ("空闲");
835 break;
836 }
837 case (int)RelayStates.ISUP_CALLEE_CONNECT:
838 {
839 sST = ("来话摘机");
840 break;
841 }
842 case (int)RelayStates.ISUP_CALLER_CONNECT:
843 {
844 TrunkState = "Calling";
845 sCalleeNum =Encoding.UTF8.GetString(SysFunction.GetCallNum(iTrunkID / 30, iTrunkID % 30).bCallNum);
846 myTelNum mt = new myTelNum();
847 sCallerNum =mt.GetTelPass(sCalleeNum);
848 sST = "电话呼出";
849 break;
850 }
851 case (int)RelayStates.ISUP_CALLER_WAIT_ANM:
852 {
853 sCalleeNum =Encoding.UTF8.GetString(SysFunction.GetCallNum(iTrunkID / 30, iTrunkID % 30).bCallNum);
854 sCallerNum = Encoding.UTF8.GetString(SysFunction.GetCallNum(iTrunkID / 30, iTrunkID % 30).bCalleeNum);
855 TrunkState = "Calling";
856 VoiceST = "Callout";
857 sST = "呼出等待";
858 break;
859 }
860 case (int)RelayStates.ISUP_CH_LOCAL_BLOCK:
861 {
862 sST = "本地闭塞";
863 break;
864 }
865 case (int)RelayStates.ISUP_CH_LOCAL_SUSPEND:
866 {
867 sST = "本地暂停";
868 break;
869 }
870 case (int)RelayStates.ISUP_CH_REMOTE_BLOCK:
871 {
872 sST = "远端闭塞";
873 break;
874 }
875 case (int)RelayStates.ISUP_CH_REMOTE_SUSPEND:
876 {
877 sST = "远端暂停";
878 break;
879 }
880 default:
881 {
882 sST = "中间状态";
883 break;
884
885 }
886 }
887 lvChn.Items[iTrunkID].SubItems[3].Text = sST;
888 lvChn.Items[iTrunkID].SubItems[4].Text = sCallerNum;
889 lvChn.Items[iTrunkID].SubItems[5].Text = sCalleeNum;
890 }
891 #endregion
892
893 声音文件转换#region 声音文件转换
894 /**//// <summary>
895 /// 文件名转换成byte[]
896 /// </summary>
897 /// <param name="FileName"></param>
898 /// <returns></returns>
899 public byte[] GetFilePath(string FileName)
900 {
901 string appFile = SysFunction.appDIRStr().ToString();
902 //MessageBox.Show(appFile);
903 char[] charTemp = new char[256];
904 byte[] byteTemp = new byte[256];
905 long Pos = 0;
906 long tmp = 0;
907
908
909 appFile.ToCharArray().CopyTo(charTemp, Pos);
910 for (short x = 0; x < charTemp.Length; x++)
911 {
912 if (charTemp[x] != 0)
913 {
914 tmp++;
915 }
916 }
917 Pos = tmp;
918 @"voc\".ToCharArray().CopyTo(charTemp, Pos);
919 FileName.ToCharArray().CopyTo(charTemp, Pos + 4);
920 Encoding.Unicode.GetBytes(FileName.ToCharArray()).CopyTo(byteTemp, 0);
921 for (int i =0; i < charTemp.Length; i++)
922 {
923 byteTemp[i] = (byte)charTemp[i];
924 }
925 return byteTemp;
926 }
927 #endregion
928
929 电话号码转换#region 电话号码转换
930 /**//// <summary>
931 /// 电话号码转换
932 /// </summary>
933 /// <param name="Str"></param>
934 /// <param name="PCMno"></param>
935 /// <param name="RelayNo"></param>
936 /// <returns></returns>
937 public byte[] CalleestringTobyte(string Str,int PCMno,int RelayNo)
938 {
939 TC_INI_TYPE TC = new TC_INI_TYPE();
940 char[] charTemp = new char[256];
941 byte[] byteTemp = new byte[256];
942 long Pos = 0;
943 long tmp = 0;
944
945
946 TC=SysFunction.GetCallNum(PCMno,RelayNo);
947 TC.bCalleeNum.CopyTo(byteTemp, Pos);
948 for (short x = 0; x < Pos;x++ )
949 {
950 if(TC.bCalleeNum[x]!=0)
951 {
952 tmp++;
953 }
954 }
955 Pos = tmp;
956 Encoding.Unicode.GetBytes(Str.ToCharArray()).CopyTo(byteTemp, 0);
957 return byteTemp;
958 }
959 #endregion
960
961 被叫电话号码#region 被叫电话号码
962 public string CalleeNum(int PCMno, int RelayNo)
963 {
964 TC_INI_TYPE TC = new TC_INI_TYPE();
965 char[] charTemp = new char[256];
966 byte[] byteTemp = new byte[256];
967 long Pos = 0;
968 long tmp = 0;
969
970
971 TC = SysFunction.GetCallNum(PCMno, RelayNo);
972 TC.bCalleeNum.CopyTo(byteTemp, Pos);
973 for (short x = 0; x < Pos; x++)
974 {
975 if (TC.bCalleeNum[x] != 0)
976 {
977 tmp++;
978 }
979 }
980 Pos = tmp;
981 // Encoding.Unicode.GetBytes(Str.ToCharArray()).CopyTo(byteTemp, 0);
982 return Encoding.UTF8.GetString(byteTemp);
983 }
984 #endregion
985
986 拨号#region 拨号
987 /**//// <summary>
988 /// 手动拨号
989 /// </summary>
990 ///
991
992 public void CallOut(string iTelNum)
993 {
994
995 unsafe
996 {
997 nOutCall = Convert.ToUInt64(iTelNum);
998 nMyCallNo = Convert.ToUInt64(MyCallNO);
999 TelNum telNO = new TelNum();
1000 byte[] iTelNO = new byte[256];
1001 char[] tempTel = new char[256];
1002 tempTel = iTelNum.ToCharArray();
1003 telNO.arrTelNum = Encoding.ASCII.GetBytes(tempTel);
1004 char[] tempCall = new char[256];
1005 byte[] iCallNO = new byte[256];
1006 tempCall = MyCallNO.ToCharArray();
1007 telNO.arrCallNum = Encoding.ASCII.GetBytes(tempCall);
1008 int iFreeTrunkID = SysFunction.iFreePCM();
1009 string sErr = string.Empty;
1010 if (iFreeTrunkID == -1)
1011 {
1012 return;
1013 }
1014 else
1015 {
1016 StringBuilder sbCallee = new StringBuilder(iTelNum);
1017 StringBuilder sbCaller = new StringBuilder(MyCallNO);
1018 try
1019 {
1020 bool charISCallout = SysFunction.bCallOut(iFreeTrunkID, sbCallee, sbCaller);
1021 }
1022 catch (Exception ex)
1023 {
1024 lblTrunk.Text = ex.Message;
1025 }
1026
1027 try
1028 {
1029 bool bCallout = SysFunction.bCallOut(iFreeTrunkID, iTelNum, MyCallNO, ref sErr);
1030 }
1031 catch (Exception ex)
1032 {
1033 lblTrunk.Text = ex.Message + sErr;
1034 }
1035 try
1036 {
1037 bool bISout = SysFunction.bCallOut(iFreeTrunkID, iTelNum, MyCallNO, false, false);
1038 }
1039 catch (Exception ex)
1040 {
1041 lblTrunk.Text = ex.Message;
1042 }
1043 try
1044 {
1045 bool bIsCallOut = SysFunction.bCallOut(iFreeTrunkID, CalleestringTobyte(iTelNum, iFreeTrunkID / 30, iFreeTrunkID % 30), iCallNO);
1046 }
1047 catch (Exception ex)
1048 {
1049 lblTrunk.Text = ex.Message;
1050 }
1051 try
1052 {
1053 bool bSisCallOut = SysFunction.bCallOut(iFreeTrunkID, nOutCall, nMyCallNo);
1054 }
1055 catch (Exception ex)
1056 {
1057 lblTrunk.Text = ex.Message;
1058 }
1059 lvChn.BeginUpdate();
1060 lvChn.Items[iFreeTrunkID].SubItems[5].Text = iTelNum;
1061 lvChn.EndUpdate();
1062 VoiceST = "Callout";
1063 TrunkState = "Calling";
1064 }
1065 }
1066
1067 }
1068
1069
1070 /**//// <summary>
1071 /// 自动拨号
1072 /// </summary>
1073 ///
1074
1075
1076 public void TheadCallOut()
1077 {
1078
1079 DBMod.myTelNum tn = new DJVoiceCard.DBMod.myTelNum();
1080 string iTelNum = tn.theTelNum;
1081 CallOutNum = tn.theTelNum;
1082
1083 unsafe
1084 {
1085 TrunkState = "Calling";
1086 ulong nOutCall = Convert.ToUInt64(iTelNum);
1087 ulong nMyCallNo = Convert.ToUInt64(MyCallNO);
1088 TelNum telNO = new TelNum();
1089 byte[] iTelNO = new byte[256];
1090 char[] tempTel = new char[256];
1091 tempTel = iTelNum.ToCharArray();
1092 telNO.arrTelNum = Encoding.ASCII.GetBytes(tempTel);
1093 char[] tempCall = new char[256];
1094 byte[] iCallNO = new byte[256];
1095 tempCall = MyCallNO.ToCharArray();
1096 telNO.arrCallNum = Encoding.ASCII.GetBytes(tempCall);
1097 int iFreeTrunkID = SysFunction.iFreePCM();
1098 string sErr = string.Empty;
1099 if (iFreeTrunkID == -1)
1100 {
1101
1102 }
1103 else
1104 {
1105
1106 StringBuilder sbCallee = new StringBuilder(iTelNum);
1107 StringBuilder sbCaller = new StringBuilder(MyCallNO);
1108 try
1109 {
1110 bool charISCallout = SysFunction.bCallOut(iFreeTrunkID, sbCallee, sbCaller);
1111 }
1112 catch(Exception ex)
1113 {
1114 lblTrunk.Text = ex.Message;
1115 }
1116
1117 try
1118 {
1119 bool bCallout = SysFunction.bCallOut(iFreeTrunkID, iTelNum, MyCallNO, ref sErr);
1120 }
1121 catch (Exception ex)
1122 {
1123 lblTrunk.Text = ex.Message + sErr;
1124 }
1125 try
1126 {
1127 bool bISout = SysFunction.bCallOut(iFreeTrunkID, iTelNum, MyCallNO, false, false);
1128 }
1129 catch (Exception ex)
1130 {
1131 lblTrunk.Text = ex.Message;
1132 }
1133 try
1134 {
1135 bool bIsCallOut = SysFunction.bCallOut(iFreeTrunkID, CalleestringTobyte(iTelNum, iFreeTrunkID / 30, iFreeTrunkID % 30), iCallNO);
1136 }
1137 catch (Exception ex)
1138 {
1139 lblTrunk.Text = ex.Message;
1140 }
1141 try
1142 {
1143 bool bSisCallOut = SysFunction.bCallOut(iFreeTrunkID, nOutCall, nMyCallNo);
1144 }
1145 catch (Exception ex)
1146 {
1147 lblTrunk.Text = ex.Message;
1148 }
1149 lvChn.BeginUpdate();
1150 lvChn.Items[iFreeTrunkID].SubItems[5].Text = iTelNum;
1151 lvChn.EndUpdate();
1152 TrunkState = "Calling";
1153 VoiceST = "Callout";
1154 }
1155 }
1156
1157 }
1158
1159 #endregion
1160
1161 释放资源#region 释放资源
1162 /**//// <summary>
1163 /// 释放用户通道
1164 /// </summary>
1165 /// <param name="iUserCHNID"></param>
1166 public void ReaseceUserCHN(int iUserCHNID)
1167 {
1168 if(iUserCHNID!=-1)
1169 {
1170 if(SysFunction.bIsRingDerctor(iUserCHNID))
1171 {
1172 if (SysFunction.bIsStopRing(iUserCHNID))
1173 {
1174 }
1175
1176 }
1177 if(SysFunction.bClearVoiceFromUser(iUserCHNID))
1178 {}
1179 if(SysFunction.bIsInitDailBuf(iUserCHNID))
1180 {}
1181 URS[iUserCHNID].ConnTrID = -1;
1182 URS[iUserCHNID].ConnUrID = -1;
1183 URS[iUserCHNID].ST = USER_STATE.USR_ONHOOK;
1184
1185 }
1186 }
1187
1188 /**//// <summary>
1189 /// 释放中继信道资源
1190 /// </summary>
1191 /// <param name="iTrunkCHNID"></param>
1192 public void ReaseceTrunckCHN(int iTrunkCHNID)
1193 {
1194 bool bISCHK = (iTrunkCHNID == -1 && (SysFunction.iRaleyStetes(((byte)(iTrunkCHNID / 30)), ((byte)(iTrunkCHNID % 30))) == (int)RelayStates.ISUP_CH_FREE));
1195 if(!bISCHK)
1196 {
1197 int iUserCHNID = SysFunction.iLinkUserCHNID(iTrunkCHNID);
1198 if(iUserCHNID>-1)
1199 {
1200 if (SysFunction.ClearCHN(iTrunkCHNID))
1201 { }
1202 }
1203
1204 int iVoiceID = SysFunction.iVoicePlayForTrunk(iTrunkCHNID);
1205 if (iVoiceID > -1)
1206 {
1207 SysFunction.bIsClearTrunkVoiceLink(iTrunkCHNID);
1208 }
1209
1210 SysFunction.bIsInitDtmfByTrunkID(iTrunkCHNID);
1211
1212 TST[iTrunkCHNID].ST = TRUNK_ST.TRK_FREE;
1213 TST[iTrunkCHNID].DialNum = string.Empty;
1214 TST[iTrunkCHNID].ConnTrID = -1;
1215 TST[iTrunkCHNID].ConnUrID = -1;
1216
1217 SysFunction.SetRelayStates(iTrunkCHNID, (int)RelayStates.ISUP_CH_FREE);
1218 }
1219 }
1220 /**//// <summary>
1221 /// 释放资源
1222 /// </summary>
1223 public void ReacurseTrunk()
1224 {
1225 iTunkTotal = SysFunction.iTrkTotal();
1226 for (int i = 0; i < iTunkTotal; i++)
1227 {
1228 ReaseceTrunckCHN(i);
1229 }
1230 iUserTotal = SysFunction.iUserTotal();
1231 for (int i = 0; i < iUserTotal; i++)
1232 {
1233 ReaseceUserCHN(i);
1234 }
1235
1236 }
1237
1238 #endregion
1239
1240 private void button1_Click(object sender, EventArgs e)
1241 {
1242 ReacurseTrunk();
1243 }
1244 }
1245}
好了,经过贴了那么长的代码.整个项目都已经弄好了.下一篇会吧整个项目贴出来让大家下载.
H.Wong
-2010