Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            SimpleConnStr bassConnStr = new SimpleConnStr();
            bassConnStr.UserID     = txtUser.Text;
            bassConnStr.DataSource = txtTNSName.Text;
            bassConnStr.Password   = txtPassword.Text;
            bassConnStr.encode();

            XmlDocument mXml = new XmlDocument();
            mXml.Load(mFileLoc);

            XmlNode node = null;
            node = mXml.SelectSingleNode(string.Format(XPATH_FMT, KEY_DBCONN));
            node.Attributes[TAG_VALUE].Value = EncryptionUtil.Encryption.Encrypt(bassConnStr.ConnStr);
            mXml.Save(mFileLoc);

            // Reads UTF8 file
            StreamReader fileStream = new StreamReader(mFileLoc);
            string fileContent      = fileStream.ReadToEnd();
            fileStream.Close();

            // Now writes the content in ANSI
            StreamWriter ansiWriter = new StreamWriter(mFileLoc, false, Encoding.GetEncoding(1250));
            ansiWriter.Write(fileContent);
            ansiWriter.Close();

            MessageBox.Show("Successfully Save.", "DBConnection Setting", MessageBoxButtons.OK);
        }
Exemplo n.º 2
0
        private void tsbtnConnect_Click(object sender, EventArgs e)
        {
            Cursor.Current   = Cursors.WaitCursor;
            bool bassConnect = false;

            try
            {
                SimpleConnStr bassConnStr = new SimpleConnStr();
                bassConnStr.UserID     = txtUser.Text;
                bassConnStr.DataSource = txtTNSName.Text;
                bassConnStr.Password   = txtPassword.Text;
                bassConnStr.encode();
                bassConnStr.test();
                bassConnect = true;

                MessageBox.Show(string.Format("Successful connect [{0}] to database.", bassConnStr.UserID), "DBConnection Setting", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch (Exception ex)
            {
                bassConnect = false;
                MessageBox.Show(ex.Message, "DBConnection Setting", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }