private void btnBind_Click(object sender, EventArgs e) { if (m_client == null) { m_client = new esmesim.smpp.SMPPClient(); m_client.ConnectionLost += new esmesim.smpp.ConnectionLostEventHandler(delegate() { MessageBox.Show(this, "Connection with the server has been lost!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); SetInitialStatus(false); }); m_client.NewMessage += new esmesim.smpp.NewMessageEventHandler(delegate(string from, string to, string content) { m_inbox.Add(new MessageGridModel(from, to, content)); }); } if (m_client.Bound) { m_client.Unbind(); } else { ushort port; if (!ushort.TryParse(txtPort.Text, out port)) { MessageBox.Show(this, "Server port is invalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } m_client.SystemId = txtUser.Text; m_client.Password = txtPass.Text; m_client.SystemType = txtSystemType.Text; m_client.Settings.EnableGSM7bitPacking = chk7bitPacking.Checked; m_client.Settings.DeliverDataCoding = GetSelectedDataCoding(cboDataCoding); m_client.Settings.ServerDefaultEncoding = GetSelectedDataCoding(cboServerDataCoding); m_client.Addresses.Clear(); foreach (string s in txtAddress.Text.Split(',')) { m_client.Addresses.Add(s); } try { m_client.Bind((esmesim.smpp.BindType)cboMode.SelectedItem, txtServer.Text, port); this.BringToFront(); //TODO new Thread(KeepAliveThread //TODO session.SetDataCoding((DataCoding)cboDataCoding.SelectedItem, (DataCoding)cboServerDataCoding.SelectedItem, chk7bitPacking.Checked); } catch (esmesim.smpp.BindException ex) { MessageBox.Show(this, "Bind error: " + ex.Result, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } SetInitialStatus(m_client.Bound); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (m_client != null) { if (m_client.Bound) { m_client.Unbind(); } m_client.Dispose(); m_client = null; } ushort port; if (ushort.TryParse(txtPort.Text, out port)) { Settings.Default.ServerPort = port; } Settings.Default.User = txtUser.Text; Settings.Default.Password = txtPass.Text; Settings.Default.ServerAddress = txtServer.Text; Settings.Default.BindMode = (BindType)cboMode.SelectedItem; Settings.Default.AddressRange = txtAddress.Text; Settings.Default.SystemType = txtSystemType.Text; Settings.Default.LastPhoneNumber = txtTo.Text; Settings.Default.DataCoding = GetSelectedDataCoding(cboDataCoding); Settings.Default.ServerDataCoding = GetSelectedDataCoding(cboServerDataCoding); Settings.Default.Gsm7bitPacking = chk7bitPacking.Checked; Settings.Default.Save(); }