clsOpenSIPSAccount.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using MySql.Data.MySqlClient;
  7. using HNWD.Pregrant.Model;
  8. namespace HNWD.Pregrant.DataAccess
  9. {
  10. public class clsOpenSIPSAccount
  11. {
  12. private MySqlConnection DBconn;
  13. private MySqlCommand DBcmd;
  14. private MySqlDataAdapter DBda;
  15. private MySqlCommandBuilder DBcb;
  16. private bool ConnectFlag = false;
  17. private string SIPSerIP = string.Empty;
  18. private string webPath = string.Empty;
  19. public clsOpenSIPSAccount(string Path)
  20. {
  21. webPath = Path;
  22. }
  23. public string GetSIPSerIP
  24. {
  25. get
  26. {
  27. if(this.SIPSerIP == "")
  28. {
  29. this.OpenSIPs_ConnectDefault();
  30. }
  31. return this.SIPSerIP;
  32. }
  33. }
  34. public bool OpenSIPs_ConnectDefault()
  35. {
  36. bool Res = false;
  37. clsDataBaseRW tempDataBaseReader = new clsDataBaseRW(this.webPath);
  38. WD_PartInfoDataAccess wd_PartInfoDataAccess = WD_PartInfoDataAccess.GetInstance();
  39. wd_PartInfoDataAccess.Query();
  40. if (wd_PartInfoDataAccess.ext.bSuccess && wd_PartInfoDataAccess.ext.Rows > 0)
  41. {
  42. Res = OpenSIPs_Connect(wd_PartInfoDataAccess.ext.messageDataList[0].SIPSEV_IP,wd_PartInfoDataAccess.ext.messageDataList[0].SIPSEV_MYSQLUSERNAME, wd_PartInfoDataAccess.ext.messageDataList[0].SIPSEV_MYSQLPASSWORD);
  43. }
  44. return Res;
  45. }
  46. public String GetSipAccount(string SIP_DeviceType, string SIP_DeviceID)
  47. {
  48. String TempSiPAccount = "";
  49. switch (SIP_DeviceType.Trim())
  50. {
  51. case "1": //'护士主机: 设备类型+八位DeviceID+"0"
  52. TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0";
  53. break;
  54. case "2": // '医生主机: 设备类型+八位DeviceID+"0"
  55. TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0";
  56. break;
  57. case "3": //'门口机: 设备类型+八位DeviceID+"0"
  58. TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0";
  59. break;
  60. case "4": //'病床分机: 设备类型+八位病人ID+"0"
  61. TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0";
  62. break;
  63. case "7": //'护士腕表: 设备类型+八位护士ID+"0"
  64. TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0";
  65. break;
  66. case "8": //'护士腕表: 设备类型+八位护士ID+"0"
  67. TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0";
  68. break;
  69. case "9": //'病人腕表: 设备类型+八位病人ID+"1~9"
  70. TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0";
  71. break;
  72. case "10": //'病人手机
  73. TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0";
  74. break;
  75. }
  76. return TempSiPAccount;
  77. }
  78. public bool OpenSIPs_Connect(string Server = "", string UserName = "", string Password = "")
  79. {
  80. bool Res = false;
  81. string connStr = string.Empty;
  82. if (this.ConnectFlag)
  83. {
  84. return this.ConnectFlag;
  85. }
  86. try
  87. {
  88. connStr = string.Format("server={0};user id={1}; password={2}; database=opensips; pooling=false", Server, UserName, Password);
  89. this.DBconn = new MySqlConnection(connStr);
  90. this.DBconn.Open();
  91. Res = true;
  92. this.ConnectFlag = true;
  93. }
  94. catch (Exception ex)
  95. {
  96. }
  97. return Res;
  98. }
  99. public void OpenSIPs_Close()
  100. {
  101. this.DBcb = null;
  102. this.DBda = null;
  103. this.DBconn.Close();
  104. this.DBconn = null;
  105. }
  106. public bool OpenSIPs_AccountCheck(string SipName, bool Rult)
  107. {
  108. Int32 i;
  109. bool Res = false;
  110. this.OpenSIPs_Connect();
  111. if (this.ConnectFlag)
  112. {
  113. try
  114. {
  115. this.DBcmd = new MySqlCommand("select * from subscriber where username='" + SipName + "'", DBconn);
  116. i = Convert.ToInt32(DBcmd.ExecuteScalar());
  117. if (i > 0)
  118. {
  119. Res = true;
  120. Rult = true;
  121. }
  122. else
  123. {
  124. Res = true;
  125. Rult = false;
  126. }
  127. }
  128. catch (Exception ex)
  129. {
  130. }
  131. }
  132. else
  133. {
  134. Res = false;
  135. }
  136. return Res;
  137. }
  138. public bool OpenSIPs_AccountAdd(string SipName, string SipPassword, string SipDomain = "")
  139. {
  140. bool Res = false;
  141. Int64 i;
  142. string strSQL = "";
  143. this.OpenSIPs_Connect();
  144. if(this.ConnectFlag)
  145. {
  146. DBcmd = new MySqlCommand("select * from subscriber where username='" + SipName + "'", DBconn);
  147. i = Convert.ToInt64(DBcmd.ExecuteScalar());
  148. if(i>0)
  149. {
  150. Res = false;
  151. }
  152. else
  153. {
  154. strSQL = "INSERT Into subscriber(username,password,domain,email_address) VALUES('" + SipName + "','" + SipPassword + "','" + SipDomain + "','" + SipName + "')";
  155. DBcmd = new MySqlCommand(strSQL, DBconn);
  156. i = DBcmd.ExecuteNonQuery();
  157. if( i > 0)
  158. {
  159. }
  160. Res = true;
  161. }
  162. }
  163. return Res;
  164. }
  165. public bool OpenSIPs_AccountDel(string SipName)
  166. {
  167. bool Res = false;
  168. Int64 i = 0;
  169. this.OpenSIPs_Connect();
  170. if (ConnectFlag)
  171. {
  172. try
  173. {
  174. DBcmd = new MySqlCommand("delete from subscriber where username='" + SipName + "'", DBconn);
  175. i = DBcmd.ExecuteNonQuery();
  176. if (i > 0)
  177. {
  178. Res = true;
  179. }
  180. }
  181. catch (Exception ex)
  182. {
  183. }
  184. }
  185. return Res;
  186. }
  187. public bool OpenSIPs_AccountOnline(string SipName)
  188. {
  189. bool Res = false;
  190. Int64 i = 0;
  191. this.OpenSIPs_Connect();
  192. if (this.ConnectFlag)
  193. {
  194. try
  195. {
  196. DBcmd = new MySqlCommand("select * from location where username='" + SipName + "'", DBconn);
  197. i = Convert.ToInt64(DBcmd.ExecuteScalar());
  198. if (i > 0)
  199. {
  200. Res = true;
  201. }
  202. }
  203. catch (Exception ex)
  204. {
  205. }
  206. }
  207. return Res;
  208. }
  209. }
  210. }