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