Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            SipAccount MySipAccount = new SipAccount(frmMain.m_SqlHelper);
            string     strError     = "";

            m_sttSipAccount.Name    = txtUserName.Text.Trim();
            m_sttSipAccount.Pwd     = txtUserPwd.Text.Trim();
            m_sttSipAccount.Domain  = txtDomain.Text.Trim();
            m_sttSipAccount.Default = true;
            int  index   = txtServer.Text.IndexOf(":");
            bool success = false;

            if (index > 0)
            {
                m_sttSipAccount.Server = txtServer.Text.Substring(0, index);
                m_sttSipAccount.Port   = Int32.Parse(txtServer.Text.Substring(index + 1));
            }
            else
            {
                m_sttSipAccount.Server = txtServer.Text.Trim();
                m_sttSipAccount.Port   = 5060;
            }

            if (m_sttSipAccount.ID == 0)
            {
                int ID = MySipAccount.Insert(ref m_sttSipAccount, ref strError);
                if (ID <= 0)
                {
                    lbStatus.Text      = strError;
                    lbStatus.ForeColor = Color.Red;
                    //MessageBox.Show(strError, "错误");
                }
                else
                {
                    success = true;
                }
            }
            else
            {
                success = MySipAccount.Update(ref m_sttSipAccount, ref strError);
                if (!success)
                {
                    lbStatus.Text      = strError;
                    lbStatus.ForeColor = Color.Red;
                    //MessageBox.Show(strError, "错误");
                }
            }
            if (success)
            {
                lbStatus.Text      = "保存成功";
                lbStatus.ForeColor = Color.Green;
                frmMain.HandleMessage(frmMain.MessageType.MT_SIP_ACCOUNT_MODIFY);
            }
        }
Exemplo n.º 2
0
 public void Save(SIPAccount account)
 {
     if (_accounts.Any(d => d.SIPUsername == account.SIPUsername || d.SIPDomain == account.SIPDomain))
     {
         SipAccount.Update(account);
     }
     else
     {
         SipAccount.Add(account);
         _accounts.Add(account);
     }
 }