using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using MySql.Data.MySqlClient; using HNWD.Pregrant.Model; namespace HNWD.Pregrant.DataAccess { public class clsOpenSIPSAccount { private MySqlConnection DBconn; private MySqlCommand DBcmd; private MySqlDataAdapter DBda; private MySqlCommandBuilder DBcb; private bool ConnectFlag = false; private string SIPSerIP = string.Empty; private string webPath = string.Empty; public clsOpenSIPSAccount(string Path) { webPath = Path; } public string GetSIPSerIP { get { if(this.SIPSerIP == "") { this.OpenSIPs_ConnectDefault(); } return this.SIPSerIP; } } public bool OpenSIPs_ConnectDefault() { bool Res = false; clsDataBaseRW tempDataBaseReader = new clsDataBaseRW(this.webPath); WD_PartInfoDataAccess wd_PartInfoDataAccess = WD_PartInfoDataAccess.GetInstance(); wd_PartInfoDataAccess.Query(); if (wd_PartInfoDataAccess.ext.bSuccess && wd_PartInfoDataAccess.ext.Rows > 0) { Res = OpenSIPs_Connect(wd_PartInfoDataAccess.ext.messageDataList[0].SIPSEV_IP,wd_PartInfoDataAccess.ext.messageDataList[0].SIPSEV_MYSQLUSERNAME, wd_PartInfoDataAccess.ext.messageDataList[0].SIPSEV_MYSQLPASSWORD); } return Res; } public String GetSipAccount(string SIP_DeviceType, string SIP_DeviceID) { String TempSiPAccount = ""; switch (SIP_DeviceType.Trim()) { case "1": //'护士主机: 设备类型+八位DeviceID+"0" TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0"; break; case "2": // '医生主机: 设备类型+八位DeviceID+"0" TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0"; break; case "3": //'门口机: 设备类型+八位DeviceID+"0" TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0"; break; case "4": //'病床分机: 设备类型+八位病人ID+"0" TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0"; break; case "7": //'护士腕表: 设备类型+八位护士ID+"0" TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0"; break; case "8": //'护士腕表: 设备类型+八位护士ID+"0" TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0"; break; case "9": //'病人腕表: 设备类型+八位病人ID+"1~9" TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0"; break; case "10": //'病人手机 TempSiPAccount = SIP_DeviceType + SIP_DeviceID.PadLeft(8, '0') + "0"; break; } return TempSiPAccount; } public bool OpenSIPs_Connect(string Server = "", string UserName = "", string Password = "") { bool Res = false; string connStr = string.Empty; if (this.ConnectFlag) { return this.ConnectFlag; } try { connStr = string.Format("server={0};user id={1}; password={2}; database=opensips; pooling=false", Server, UserName, Password); this.DBconn = new MySqlConnection(connStr); this.DBconn.Open(); Res = true; this.ConnectFlag = true; } catch (Exception ex) { } return Res; } public void OpenSIPs_Close() { this.DBcb = null; this.DBda = null; this.DBconn.Close(); this.DBconn = null; } public bool OpenSIPs_AccountCheck(string SipName, bool Rult) { Int32 i; bool Res = false; this.OpenSIPs_Connect(); if (this.ConnectFlag) { try { this.DBcmd = new MySqlCommand("select * from subscriber where username='" + SipName + "'", DBconn); i = Convert.ToInt32(DBcmd.ExecuteScalar()); if (i > 0) { Res = true; Rult = true; } else { Res = true; Rult = false; } } catch (Exception ex) { } } else { Res = false; } return Res; } public bool OpenSIPs_AccountAdd(string SipName, string SipPassword, string SipDomain = "") { bool Res = false; Int64 i; string strSQL = ""; this.OpenSIPs_Connect(); if(this.ConnectFlag) { DBcmd = new MySqlCommand("select * from subscriber where username='" + SipName + "'", DBconn); i = Convert.ToInt64(DBcmd.ExecuteScalar()); if(i>0) { Res = false; } else { strSQL = "INSERT Into subscriber(username,password,domain,email_address) VALUES('" + SipName + "','" + SipPassword + "','" + SipDomain + "','" + SipName + "')"; DBcmd = new MySqlCommand(strSQL, DBconn); i = DBcmd.ExecuteNonQuery(); if( i > 0) { } Res = true; } } return Res; } public bool OpenSIPs_AccountDel(string SipName) { bool Res = false; Int64 i = 0; this.OpenSIPs_Connect(); if (ConnectFlag) { try { DBcmd = new MySqlCommand("delete from subscriber where username='" + SipName + "'", DBconn); i = DBcmd.ExecuteNonQuery(); if (i > 0) { Res = true; } } catch (Exception ex) { } } return Res; } public bool OpenSIPs_AccountOnline(string SipName) { bool Res = false; Int64 i = 0; this.OpenSIPs_Connect(); if (this.ConnectFlag) { try { DBcmd = new MySqlCommand("select * from location where username='" + SipName + "'", DBconn); i = Convert.ToInt64(DBcmd.ExecuteScalar()); if (i > 0) { Res = true; } } catch (Exception ex) { } } return Res; } } }